Skip to content

Commit 3f80354

Browse files
authored
Merge pull request #2596 from jckarter/enable-borrowing-switch-frontend
Enable `borrowingSwitch` syntax.
2 parents 770e0e3 + f69234e commit 3f80354

File tree

8 files changed

+15
-67
lines changed

8 files changed

+15
-67
lines changed

CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public enum ExperimentalFeature: String, CaseIterable {
1818
case doExpressions
1919
case nonescapableTypes
2020
case transferringArgsAndResults
21-
case borrowingSwitch
2221
case trailingComma
2322

2423
/// The name of the feature, which is used in the doc comment.
@@ -34,8 +33,6 @@ public enum ExperimentalFeature: String, CaseIterable {
3433
return "NonEscableTypes"
3534
case .transferringArgsAndResults:
3635
return "TransferringArgsAndResults"
37-
case .borrowingSwitch:
38-
return "borrowing pattern matching"
3936
case .trailingComma:
4037
return "trailing comma"
4138
}

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public struct KeywordSpec {
1919
/// The experimental feature the keyword is part of, or `nil` if this isn't
2020
/// for an experimental feature.
2121
public let experimentalFeature: ExperimentalFeature?
22-
public let experimentalFeature2: ExperimentalFeature?
2322

2423
/// Indicates if the token kind is switched from being an identifier to a keyword in the lexer.
2524
public let isLexerClassified: Bool
@@ -69,26 +68,6 @@ public struct KeywordSpec {
6968
) {
7069
self.name = name
7170
self.experimentalFeature = experimentalFeature
72-
self.experimentalFeature2 = nil
73-
self.isLexerClassified = isLexerClassified
74-
}
75-
76-
/// Initializes a new `KeywordSpec` instance.
77-
///
78-
/// - Parameters:
79-
/// - name: A name of the keyword.
80-
/// - experimentalFeature: The experimental feature the keyword is part of, or `nil` if this isn't for an experimental feature.
81-
/// - or: A second experimental feature the keyword is also part of, or `nil` if this isn't for an experimental feature.
82-
/// - isLexerClassified: Indicates if the token kind is switched from being an identifier to a keyword in the lexer.
83-
init(
84-
_ name: String,
85-
experimentalFeature: ExperimentalFeature,
86-
or experimentalFeature2: ExperimentalFeature,
87-
isLexerClassified: Bool = false
88-
) {
89-
self.name = name
90-
self.experimentalFeature = experimentalFeature
91-
self.experimentalFeature2 = experimentalFeature2
9271
self.isLexerClassified = isLexerClassified
9372
}
9473
}
@@ -340,7 +319,7 @@ public enum Keyword: CaseIterable {
340319
case ._borrow:
341320
return KeywordSpec("_borrow")
342321
case ._borrowing:
343-
return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch)
322+
return KeywordSpec("_borrowing")
344323
case ._BridgeObject:
345324
return KeywordSpec("_BridgeObject")
346325
case ._cdecl:

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ import Utils
1717

1818
func tokenCaseMatch(
1919
_ caseName: TokenSyntax,
20-
experimentalFeature: ExperimentalFeature?,
21-
experimentalFeature2: ExperimentalFeature?
20+
experimentalFeature: ExperimentalFeature?
2221
) -> SwitchCaseSyntax {
2322
var whereClause = ""
2423
if let feature = experimentalFeature {
2524
whereClause += "where experimentalFeatures.contains(.\(feature.token))"
26-
if let feature2 = experimentalFeature2 {
27-
whereClause += " || experimentalFeatures.contains(.\(feature2.token))"
28-
}
2925
}
3026
return "case TokenSpec(.\(caseName))\(raw: whereClause): self = .\(caseName)"
3127
}
@@ -74,14 +70,12 @@ let parserTokenSpecSetFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
7470
case .keyword(let keyword):
7571
tokenCaseMatch(
7672
keyword.spec.varOrCaseName,
77-
experimentalFeature: keyword.spec.experimentalFeature,
78-
experimentalFeature2: keyword.spec.experimentalFeature2
73+
experimentalFeature: keyword.spec.experimentalFeature
7974
)
8075
case .token(let token):
8176
tokenCaseMatch(
8277
token.spec.varOrCaseName,
83-
experimentalFeature: token.spec.experimentalFeature,
84-
experimentalFeature2: nil
78+
experimentalFeature: token.spec.experimentalFeature
8579
)
8680
}
8781
}

Sources/SwiftParser/Patterns.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ extension Parser.Lookahead {
272272
// TODO: the other ownership modifiers (borrowing/consuming/mutating) more
273273
// than likely need to be made contextual as well before finalizing their
274274
// grammar.
275-
case ._borrowing where experimentalFeatures.contains(.borrowingSwitch),
276-
.borrowing where experimentalFeatures.contains(.borrowingSwitch):
275+
case ._borrowing, .borrowing:
277276
return peek(isAt: TokenSpec(.identifier, allowAtStartOfLine: false))
278277
default:
279278
// Other keywords can be parsed unconditionally.

Sources/SwiftParser/generated/ExperimentalFeatures.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ extension Parser.ExperimentalFeatures {
3939
/// Whether to enable the parsing of TransferringArgsAndResults.
4040
public static let transferringArgsAndResults = Self (rawValue: 1 << 4)
4141

42-
/// Whether to enable the parsing of borrowing pattern matching.
43-
public static let borrowingSwitch = Self (rawValue: 1 << 5)
44-
4542
/// Whether to enable the parsing of trailing comma.
46-
public static let trailingComma = Self (rawValue: 1 << 6)
43+
public static let trailingComma = Self (rawValue: 1 << 5)
4744
}

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,9 +2915,6 @@ extension OptionalBindingConditionSyntax {
29152915
@_spi(ExperimentalLanguageFeatures)
29162916
#endif
29172917
case _mutating
2918-
#if compiler(>=5.8)
2919-
@_spi(ExperimentalLanguageFeatures)
2920-
#endif
29212918
case _borrowing
29222919
#if compiler(>=5.8)
29232920
@_spi(ExperimentalLanguageFeatures)
@@ -2934,7 +2931,7 @@ extension OptionalBindingConditionSyntax {
29342931
self = .inout
29352932
case TokenSpec(._mutating) where experimentalFeatures.contains(.referenceBindings):
29362933
self = ._mutating
2937-
case TokenSpec(._borrowing) where experimentalFeatures.contains(.referenceBindings) || experimentalFeatures.contains(.borrowingSwitch):
2934+
case TokenSpec(._borrowing):
29382935
self = ._borrowing
29392936
case TokenSpec(._consuming) where experimentalFeatures.contains(.referenceBindings):
29402937
self = ._consuming
@@ -3897,9 +3894,6 @@ extension ValueBindingPatternSyntax {
38973894
@_spi(ExperimentalLanguageFeatures)
38983895
#endif
38993896
case _mutating
3900-
#if compiler(>=5.8)
3901-
@_spi(ExperimentalLanguageFeatures)
3902-
#endif
39033897
case _borrowing
39043898
#if compiler(>=5.8)
39053899
@_spi(ExperimentalLanguageFeatures)
@@ -3917,7 +3911,7 @@ extension ValueBindingPatternSyntax {
39173911
self = .inout
39183912
case TokenSpec(._mutating) where experimentalFeatures.contains(.referenceBindings):
39193913
self = ._mutating
3920-
case TokenSpec(._borrowing) where experimentalFeatures.contains(.referenceBindings) || experimentalFeatures.contains(.borrowingSwitch):
3914+
case TokenSpec(._borrowing):
39213915
self = ._borrowing
39223916
case TokenSpec(._consuming) where experimentalFeatures.contains(.referenceBindings):
39233917
self = ._consuming
@@ -4003,9 +3997,6 @@ extension VariableDeclSyntax {
40033997
@_spi(ExperimentalLanguageFeatures)
40043998
#endif
40053999
case _mutating
4006-
#if compiler(>=5.8)
4007-
@_spi(ExperimentalLanguageFeatures)
4008-
#endif
40094000
case _borrowing
40104001
#if compiler(>=5.8)
40114002
@_spi(ExperimentalLanguageFeatures)
@@ -4022,7 +4013,7 @@ extension VariableDeclSyntax {
40224013
self = .inout
40234014
case TokenSpec(._mutating) where experimentalFeatures.contains(.referenceBindings):
40244015
self = ._mutating
4025-
case TokenSpec(._borrowing) where experimentalFeatures.contains(.referenceBindings) || experimentalFeatures.contains(.borrowingSwitch):
4016+
case TokenSpec(._borrowing):
40264017
self = ._borrowing
40274018
case TokenSpec(._consuming) where experimentalFeatures.contains(.referenceBindings):
40284019
self = ._consuming

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
2020
case _alignment
2121
case _backDeploy
2222
case _borrow
23-
#if compiler(>=5.8)
24-
@_spi(ExperimentalLanguageFeatures)
25-
#endif
2623
case _borrowing
2724
case _BridgeObject
2825
case _cdecl

Tests/SwiftParserTest/translated/MatchingPatternsTests.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ final class MatchingPatternsTests: ParserTestCase {
616616
break
617617
}
618618
""",
619-
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing"))),
620-
experimentalFeatures: .borrowingSwitch
619+
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing")))
621620
)
622621

623622
assertParse(
@@ -627,8 +626,7 @@ final class MatchingPatternsTests: ParserTestCase {
627626
break
628627
}
629628
""",
630-
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing"))),
631-
experimentalFeatures: .borrowingSwitch
629+
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing")))
632630
)
633631

634632
assertParse(
@@ -692,8 +690,7 @@ final class MatchingPatternsTests: ParserTestCase {
692690
bindingSpecifier: .keyword(.let),
693691
pattern: PatternSyntax(IdentifierPatternSyntax(identifier: .identifier("borrowing")))
694692
)
695-
),
696-
experimentalFeatures: .borrowingSwitch
693+
)
697694
)
698695
assertParse(
699696
"""
@@ -702,8 +699,7 @@ final class MatchingPatternsTests: ParserTestCase {
702699
break
703700
}
704701
""",
705-
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing"))),
706-
experimentalFeatures: .borrowingSwitch
702+
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing")))
707703
)
708704
assertParse(
709705
"""
@@ -717,8 +713,7 @@ final class MatchingPatternsTests: ParserTestCase {
717713
bindingSpecifier: .keyword(.let),
718714
pattern: PatternSyntax(IdentifierPatternSyntax(identifier: .identifier("borrowing")))
719715
)
720-
),
721-
experimentalFeatures: .borrowingSwitch
716+
)
722717
)
723718
assertParse(
724719
"""
@@ -727,8 +722,7 @@ final class MatchingPatternsTests: ParserTestCase {
727722
break
728723
}
729724
""",
730-
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing"))),
731-
experimentalFeatures: .borrowingSwitch
725+
substructure: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("borrowing")))
732726
)
733727
}
734728
}

0 commit comments

Comments
 (0)