Skip to content

Commit 90e19e9

Browse files
committed
remove SwiftSyntax support for _forget, the old spelling of discard
resolves rdar://112549258
1 parent 91b4481 commit 90e19e9

File tree

11 files changed

+13
-81
lines changed

11 files changed

+13
-81
lines changed

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public let KEYWORDS: [KeywordSpec] = [
155155
KeywordSpec("fileprivate", isLexerClassified: true, requiresTrailingSpace: true),
156156
KeywordSpec("final"),
157157
KeywordSpec("for", isLexerClassified: true, requiresTrailingSpace: true),
158-
KeywordSpec("_forget"), // NOTE: support for deprecated _forget
159158
KeywordSpec("discard"),
160159
KeywordSpec("forward"),
161160
KeywordSpec("func", isLexerClassified: true, requiresTrailingSpace: true),

CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,7 @@ public let STMT_NODES: [Node] = [
339339
children: [
340340
Child(
341341
name: "DiscardKeyword",
342-
kind: .token(choices: [
343-
.keyword(text: "_forget"), // NOTE: support for deprecated _forget
344-
.keyword(text: "discard"),
345-
])
342+
kind: .token(choices: [.keyword(text: "discard")])
346343
),
347344
Child(
348345
name: "Expression",

CodeGeneration/Sources/generate-swiftsyntax/LayoutNode+Extensions.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ extension LayoutNode {
8484
}
8585

8686
let formattedParams = """
87-
- Parameters:
88-
- leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. \
89-
If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
90-
\(children.compactMap(generateParamDocComment).joined(separator: "\n"))
91-
- trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. \
92-
If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
93-
""".removingEmptyLines
87+
- Parameters:
88+
- leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. \
89+
If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
90+
\(children.compactMap(generateParamDocComment).joined(separator: "\n"))
91+
- trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. \
92+
If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
93+
""".removingEmptyLines
9494

9595
return docCommentTrivia(from: formattedParams)
9696
}

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ class ValidateSyntaxNodes: XCTestCase {
380380
failures,
381381
expectedFailures: [
382382
// MARK: Only one non-deprecated keyword
383-
ValidationFailure(
384-
node: .discardStmt,
385-
message: "child 'DiscardKeyword' only has keywords as its token choices and should thus end with 'Specifier'"
386-
// DiscardKeyword can be 'discard' or '_forget' and '_forget' is deprecated
387-
),
388383
ValidationFailure(
389384
node: .consumeExpr,
390385
message: "child 'ConsumeKeyword' only has keywords as its token choices and should thus end with 'Specifier'"

Sources/SwiftParser/Statements.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extension Parser {
9393
return label(self.parseContinueStatement(continueHandle: handle), with: optLabel)
9494
case (.fallthrough, let handle)?:
9595
return label(self.parseFallThroughStatement(fallthroughHandle: handle), with: optLabel)
96-
case (._forget, let handle)?, (.discard, let handle)?: // NOTE: support for deprecated _forget
96+
case (.discard, let handle)?:
9797
return label(self.parseDiscardStatement(discardHandle: handle), with: optLabel)
9898
case (.return, let handle)?:
9999
return label(self.parseReturnStatement(returnHandle: handle), with: optLabel)
@@ -859,7 +859,7 @@ extension Parser.Lookahead {
859859
// yield statement of some singular expression.
860860
return !self.peek().isAtStartOfLine
861861
}
862-
case ._forget?, .discard?: // NOTE: support for deprecated _forget
862+
case .discard?:
863863
let next = peek()
864864
// The thing to be discarded must be on the same line as `discard`.
865865
if next.isAtStartOfLine {

Sources/SwiftParser/TokenSpecSet.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ enum AccessorModifier: TokenSpecSet {
5353
}
5454

5555
enum CanBeStatementStart: TokenSpecSet {
56-
case _forget // NOTE: support for deprecated _forget
5756
case `break`
5857
case `continue`
5958
case `defer`
@@ -72,7 +71,6 @@ enum CanBeStatementStart: TokenSpecSet {
7271

7372
init?(lexeme: Lexer.Lexeme) {
7473
switch PrepareForKeywordMatch(lexeme) {
75-
case TokenSpec(._forget): self = ._forget
7674
case TokenSpec(.break): self = .break
7775
case TokenSpec(.continue): self = .continue
7876
case TokenSpec(.defer): self = .defer
@@ -94,7 +92,6 @@ enum CanBeStatementStart: TokenSpecSet {
9492

9593
var spec: TokenSpec {
9694
switch self {
97-
case ._forget: return TokenSpec(._forget, recoveryPrecedence: .stmtKeyword)
9895
case .break: return .keyword(.break)
9996
case .continue: return .keyword(.continue)
10097
case .defer: return .keyword(.defer)

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,47 +1165,6 @@ extension DifferentiableAttributeArgumentsSyntax {
11651165
}
11661166
}
11671167

1168-
extension DiscardStmtSyntax {
1169-
@_spi(Diagnostics)
1170-
public enum DiscardKeywordOptions: TokenSpecSet {
1171-
case _forget
1172-
case discard
1173-
1174-
init?(lexeme: Lexer.Lexeme) {
1175-
switch PrepareForKeywordMatch(lexeme) {
1176-
case TokenSpec(._forget):
1177-
self = ._forget
1178-
case TokenSpec(.discard):
1179-
self = .discard
1180-
default:
1181-
return nil
1182-
}
1183-
}
1184-
1185-
var spec: TokenSpec {
1186-
switch self {
1187-
case ._forget:
1188-
return .keyword(._forget)
1189-
case .discard:
1190-
return .keyword(.discard)
1191-
}
1192-
}
1193-
1194-
/// Returns a token that satisfies the `TokenSpec` of this case.
1195-
///
1196-
/// If the token kind of this spec has variable text, e.g. for an identifier, this returns a token with empty text.
1197-
@_spi(Diagnostics)
1198-
public var tokenSyntax: TokenSyntax {
1199-
switch self {
1200-
case ._forget:
1201-
return .keyword(._forget)
1202-
case .discard:
1203-
return .keyword(.discard)
1204-
}
1205-
}
1206-
}
1207-
}
1208-
12091168
extension DocumentationAttributeArgumentSyntax {
12101169
@_spi(Diagnostics)
12111170
public enum LabelOptions: TokenSpecSet {

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public enum Keyword: UInt8, Hashable {
116116
case `fileprivate`
117117
case final
118118
case `for`
119-
case _forget
120119
case discard
121120
case forward
122121
case `func`
@@ -434,8 +433,6 @@ public enum Keyword: UInt8, Hashable {
434433
self = .`default`
435434
case "dynamic":
436435
self = .dynamic
437-
case "_forget":
438-
self = ._forget
439436
case "discard":
440437
self = .discard
441438
case "forward":
@@ -865,7 +862,6 @@ public enum Keyword: UInt8, Hashable {
865862
"fileprivate",
866863
"final",
867864
"for",
868-
"_forget",
869865
"discard",
870866
"forward",
871867
"func",

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
983983
case .discardStmt:
984984
assert(layout.count == 5)
985985
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
986-
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("_forget"), .keyword("discard")]))
986+
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("discard")]))
987987
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
988988
assertNoError(kind, 3, verify(layout[3], as: RawExprSyntax.self))
989989
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public struct DeferStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
385385

386386
/// ### Children
387387
///
388-
/// - `discardKeyword`: (`'_forget'` | `'discard'`)
388+
/// - `discardKeyword`: `'discard'`
389389
/// - `expression`: ``ExprSyntax``
390390
public struct DiscardStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
391391
public let _syntaxNode: Syntax
@@ -412,7 +412,7 @@ public struct DiscardStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
412412
public init(
413413
leadingTrivia: Trivia? = nil,
414414
_ unexpectedBeforeDiscardKeyword: UnexpectedNodesSyntax? = nil,
415-
discardKeyword: TokenSyntax,
415+
discardKeyword: TokenSyntax = .keyword(.discard),
416416
_ unexpectedBetweenDiscardKeywordAndExpression: UnexpectedNodesSyntax? = nil,
417417
expression: some ExprSyntaxProtocol,
418418
_ unexpectedAfterExpression: UnexpectedNodesSyntax? = nil,

Tests/SwiftParserTest/StatementTests.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,6 @@ final class StatementTests: ParserTestCase {
561561
}
562562

563563
func testDiscard() {
564-
// ensure the old spelling '_forget' can be parsed for now.
565-
assertParse(
566-
"""
567-
_forget self
568-
""",
569-
substructure: DiscardStmtSyntax(
570-
discardKeyword: .keyword(._forget),
571-
expression: DeclReferenceExprSyntax(baseName: .keyword(.`self`))
572-
)
573-
)
574-
575564
assertParse(
576565
"""
577566
discard self

0 commit comments

Comments
 (0)