Skip to content

remove SwiftSyntax support for _forget, the old spelling of discard #2053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("fileprivate", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("final"),
KeywordSpec("for", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("_forget"), // NOTE: support for deprecated _forget
KeywordSpec("discard"),
KeywordSpec("forward"),
KeywordSpec("func", isLexerClassified: true, requiresTrailingSpace: true),
Expand Down
5 changes: 1 addition & 4 deletions CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,7 @@ public let STMT_NODES: [Node] = [
children: [
Child(
name: "DiscardKeyword",
kind: .token(choices: [
.keyword(text: "_forget"), // NOTE: support for deprecated _forget
.keyword(text: "discard"),
])
kind: .token(choices: [.keyword(text: "discard")])
),
Child(
name: "Expression",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,6 @@ class ValidateSyntaxNodes: XCTestCase {
failures,
expectedFailures: [
// MARK: Only one non-deprecated keyword
ValidationFailure(
node: .discardStmt,
message: "child 'discardKeyword' only has keywords as its token choices and should thus end with 'Specifier'"
// DiscardKeyword can be 'discard' or '_forget' and '_forget' is deprecated
),
ValidationFailure(
node: .consumeExpr,
message: "child 'consumeKeyword' only has keywords as its token choices and should thus end with 'Specifier'"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension Parser {
return label(self.parseContinueStatement(continueHandle: handle), with: optLabel)
case (.fallthrough, let handle)?:
return label(self.parseFallThroughStatement(fallthroughHandle: handle), with: optLabel)
case (._forget, let handle)?, (.discard, let handle)?: // NOTE: support for deprecated _forget
case (.discard, let handle)?:
return label(self.parseDiscardStatement(discardHandle: handle), with: optLabel)
case (.return, let handle)?:
return label(self.parseReturnStatement(returnHandle: handle), with: optLabel)
Expand Down Expand Up @@ -859,7 +859,7 @@ extension Parser.Lookahead {
// yield statement of some singular expression.
return !self.peek().isAtStartOfLine
}
case ._forget?, .discard?: // NOTE: support for deprecated _forget
case .discard?:
let next = peek()
// The thing to be discarded must be on the same line as `discard`.
if next.isAtStartOfLine {
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftParser/TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ enum AccessorModifier: TokenSpecSet {
}

enum CanBeStatementStart: TokenSpecSet {
case _forget // NOTE: support for deprecated _forget
case `break`
case `continue`
case `defer`
Expand All @@ -72,7 +71,6 @@ enum CanBeStatementStart: TokenSpecSet {

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(._forget): self = ._forget
case TokenSpec(.break): self = .break
case TokenSpec(.continue): self = .continue
case TokenSpec(.defer): self = .defer
Expand All @@ -94,7 +92,6 @@ enum CanBeStatementStart: TokenSpecSet {

var spec: TokenSpec {
switch self {
case ._forget: return TokenSpec(._forget, recoveryPrecedence: .stmtKeyword)
case .break: return .keyword(.break)
case .continue: return .keyword(.continue)
case .defer: return .keyword(.defer)
Expand Down
41 changes: 0 additions & 41 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1165,47 +1165,6 @@ extension DifferentiableAttributeArgumentsSyntax {
}
}

extension DiscardStmtSyntax {
@_spi(Diagnostics)
public enum DiscardKeywordOptions: TokenSpecSet {
case _forget
case discard

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(._forget):
self = ._forget
case TokenSpec(.discard):
self = .discard
default:
return nil
}
}

var spec: TokenSpec {
switch self {
case ._forget:
return .keyword(._forget)
case .discard:
return .keyword(.discard)
}
}

/// Returns a token that satisfies the `TokenSpec` of this case.
///
/// If the token kind of this spec has variable text, e.g. for an identifier, this returns a token with empty text.
@_spi(Diagnostics)
public var tokenSyntax: TokenSyntax {
switch self {
case ._forget:
return .keyword(._forget)
case .discard:
return .keyword(.discard)
}
}
}
}

extension DocumentationAttributeArgumentSyntax {
@_spi(Diagnostics)
public enum LabelOptions: TokenSpecSet {
Expand Down
4 changes: 0 additions & 4 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public enum Keyword: UInt8, Hashable {
case `fileprivate`
case final
case `for`
case _forget
case discard
case forward
case `func`
Expand Down Expand Up @@ -434,8 +433,6 @@ public enum Keyword: UInt8, Hashable {
self = .`default`
case "dynamic":
self = .dynamic
case "_forget":
self = ._forget
case "discard":
self = .discard
case "forward":
Expand Down Expand Up @@ -865,7 +862,6 @@ public enum Keyword: UInt8, Hashable {
"fileprivate",
"final",
"for",
"_forget",
"discard",
"forward",
"func",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
case .discardStmt:
assert(layout.count == 5)
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("_forget"), .keyword("discard")]))
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("discard")]))
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
assertNoError(kind, 3, verify(layout[3], as: RawExprSyntax.self))
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public struct DeferStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {

/// ### Children
///
/// - `discardKeyword`: (`'_forget'` | `'discard'`)
/// - `discardKeyword`: `'discard'`
/// - `expression`: ``ExprSyntax``
public struct DiscardStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
public let _syntaxNode: Syntax
Expand All @@ -412,7 +412,7 @@ public struct DiscardStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
public init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeDiscardKeyword: UnexpectedNodesSyntax? = nil,
discardKeyword: TokenSyntax,
discardKeyword: TokenSyntax = .keyword(.discard),
_ unexpectedBetweenDiscardKeywordAndExpression: UnexpectedNodesSyntax? = nil,
expression: some ExprSyntaxProtocol,
_ unexpectedAfterExpression: UnexpectedNodesSyntax? = nil,
Expand Down
11 changes: 0 additions & 11 deletions Tests/SwiftParserTest/StatementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,6 @@ final class StatementTests: ParserTestCase {
}

func testDiscard() {
// ensure the old spelling '_forget' can be parsed for now.
assertParse(
"""
_forget self
""",
substructure: DiscardStmtSyntax(
discardKeyword: .keyword(._forget),
expression: DeclReferenceExprSyntax(baseName: .keyword(.`self`))
)
)

assertParse(
"""
discard self
Expand Down