Skip to content

Commit d216b0c

Browse files
committed
Merge pull request #2567 from apple/followup
Follow up of #2564
1 parent 9f55f4f commit d216b0c

14 files changed

+56
-308
lines changed

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -542,42 +542,17 @@ public let TYPE_NODES: [Node] = [
542542
elementChoices: [.lifetimeSpecifierArgument]
543543
),
544544

545-
Node(
546-
kind: .lifetimeSpecifierArguments,
547-
base: .syntax,
548-
experimentalFeature: .nonescapableTypes,
549-
nameForDiagnostics: nil,
550-
documentation: """
551-
An optional argument passed to a type parameter.
552-
553-
### Example
554-
`borrow(data)` in `func foo(data: Array<Item>) -> borrow(data) ComplexReferenceType`
555-
""",
556-
children: [
557-
Child(
558-
name: "arguments",
559-
kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments"),
560-
documentation: """
561-
The function parameters that the lifetime of the annotated type depends on.
562-
"""
563-
)
564-
]
565-
),
566-
567545
Node(
568546
kind: .lifetimeTypeSpecifier,
569547
base: .syntax,
570548
experimentalFeature: .nonescapableTypes,
571549
nameForDiagnostics: "lifetime specifier",
572550
documentation: "A specifier that specifies function parameter on whose lifetime a type depends",
573-
traits: [
574-
"Parenthesized"
575-
],
576551
children: [
577552
Child(
578553
name: "dependsOnKeyword",
579554
kind: .token(choices: [.keyword(.dependsOn)]),
580-
documentation: "The specifier token that's attached to the type."
555+
documentation: "lifetime dependence specifier on the return type"
581556
),
582557
Child(
583558
name: "leftParen",
@@ -586,11 +561,12 @@ public let TYPE_NODES: [Node] = [
586561
Child(
587562
name: "scopedKeyword",
588563
kind: .token(choices: [.keyword(.scoped)]),
564+
documentation: "lifetime of return value is scoped to the lifetime of the original value",
589565
isOptional: true
590566
),
591567
Child(
592568
name: "arguments",
593-
kind: .node(kind: .lifetimeSpecifierArguments)
569+
kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments")
594570
),
595571
Child(
596572
name: "rightParen",

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class ValidateSyntaxNodes: XCTestCase {
550550
node: .yieldedExpressionsClause,
551551
message: "could conform to trait 'Parenthesized' but does not"
552552
),
553+
ValidationFailure(node: .lifetimeTypeSpecifier, message: "could conform to trait 'Parenthesized' but does not"),
553554
]
554555
)
555556
}

Sources/SwiftParser/Types.swift

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -901,25 +901,23 @@ extension Parser.Lookahead {
901901

902902
extension Parser {
903903
private mutating func parseLifetimeTypeSpecifier() -> RawTypeSpecifierListSyntax.Element {
904-
let specifier = self.eat(TokenSpec(.dependsOn))
904+
let (unexpectedBeforeDependsOnKeyword, dependsOnKeyword) = self.expect(.keyword(.dependsOn))
905905

906906
guard let leftParen = self.consume(if: .leftParen) else {
907907
// If there is no left paren, add an entirely missing detail. Otherwise, we start to consume the following type
908908
// name as a token inside the detail, which leads to confusing recovery results.
909-
let arguments = RawLifetimeSpecifierArgumentsSyntax(
910-
arguments: RawLifetimeSpecifierArgumentListSyntax(
911-
elements: [
912-
RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena)
913-
],
914-
arena: self.arena
915-
),
909+
let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(
910+
elements: [
911+
RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena)
912+
],
916913
arena: self.arena
917914
)
918915
let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(
919-
dependsOnKeyword: specifier,
916+
unexpectedBeforeDependsOnKeyword,
917+
dependsOnKeyword: dependsOnKeyword,
920918
leftParen: missingToken(.leftParen),
921919
scopedKeyword: nil,
922-
arguments: arguments,
920+
arguments: lifetimeSpecifierArgumentList,
923921
rightParen: missingToken(.rightParen),
924922
arena: self.arena
925923
)
@@ -947,15 +945,12 @@ extension Parser {
947945
} while keepGoing != nil && self.hasProgressed(&loopProgress)
948946
let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(elements: arguments, arena: self.arena)
949947
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
950-
let argumentsSyntax = RawLifetimeSpecifierArgumentsSyntax(
951-
arguments: lifetimeSpecifierArgumentList,
952-
arena: self.arena
953-
)
954948
let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(
955-
dependsOnKeyword: specifier,
949+
unexpectedBeforeDependsOnKeyword,
950+
dependsOnKeyword: dependsOnKeyword,
956951
leftParen: leftParen,
957952
scopedKeyword: scoped,
958-
arguments: argumentsSyntax,
953+
arguments: lifetimeSpecifierArgumentList,
959954
unexpectedBeforeRightParen,
960955
rightParen: rightParen,
961956
arena: self.arena
@@ -981,7 +976,7 @@ extension Parser {
981976
SPECIFIER_PARSING: while canHaveParameterSpecifier {
982977
if let (_, specifierHandle) = self.at(anyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) {
983978
specifiers.append(parseSimpleTypeSpecifier(specifierHandle: specifierHandle))
984-
} else if self.at(TokenSpec(.dependsOn)) {
979+
} else if self.at(.keyword(.dependsOn)) {
985980
if self.experimentalFeatures.contains(.nonescapableTypes) {
986981
specifiers.append(parseLifetimeTypeSpecifier())
987982
} else {

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,12 +2009,6 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
20092009
return "trailingComma"
20102010
case \LifetimeSpecifierArgumentSyntax.unexpectedAfterTrailingComma:
20112011
return "unexpectedAfterTrailingComma"
2012-
case \LifetimeSpecifierArgumentsSyntax.unexpectedBeforeArguments:
2013-
return "unexpectedBeforeArguments"
2014-
case \LifetimeSpecifierArgumentsSyntax.arguments:
2015-
return "arguments"
2016-
case \LifetimeSpecifierArgumentsSyntax.unexpectedAfterArguments:
2017-
return "unexpectedAfterArguments"
20182012
case \LifetimeTypeSpecifierSyntax.unexpectedBeforeDependsOnKeyword:
20192013
return "unexpectedBeforeDependsOnKeyword"
20202014
case \LifetimeTypeSpecifierSyntax.dependsOnKeyword:

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,20 +1374,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
13741374
visitAnyPost(node._syntaxNode)
13751375
}
13761376

1377-
#if compiler(>=5.8)
1378-
@_spi(ExperimentalLanguageFeatures)
1379-
#endif
1380-
override open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> SyntaxVisitorContinueKind {
1381-
return visitAny(node._syntaxNode)
1382-
}
1383-
1384-
#if compiler(>=5.8)
1385-
@_spi(ExperimentalLanguageFeatures)
1386-
#endif
1387-
override open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) {
1388-
visitAnyPost(node._syntaxNode)
1389-
}
1390-
13911377
#if compiler(>=5.8)
13921378
@_spi(ExperimentalLanguageFeatures)
13931379
#endif

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,6 @@ extension Syntax {
16811681
.node(LayoutRequirementSyntax.self),
16821682
.node(LifetimeSpecifierArgumentListSyntax.self),
16831683
.node(LifetimeSpecifierArgumentSyntax.self),
1684-
.node(LifetimeSpecifierArgumentsSyntax.self),
16851684
.node(LifetimeTypeSpecifierSyntax.self),
16861685
.node(MacroDeclSyntax.self),
16871686
.node(MacroExpansionDeclSyntax.self),

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ public enum SyntaxEnum: Sendable {
191191
#if compiler(>=5.8)
192192
@_spi(ExperimentalLanguageFeatures)
193193
#endif
194-
case lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax)
195-
#if compiler(>=5.8)
196-
@_spi(ExperimentalLanguageFeatures)
197-
#endif
198194
case lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax)
199195
case macroDecl(MacroDeclSyntax)
200196
case macroExpansionDecl(MacroExpansionDeclSyntax)
@@ -651,8 +647,6 @@ public extension Syntax {
651647
return .lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax(self)!)
652648
case .lifetimeSpecifierArgument:
653649
return .lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax(self)!)
654-
case .lifetimeSpecifierArguments:
655-
return .lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax(self)!)
656650
case .lifetimeTypeSpecifier:
657651
return .lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax(self)!)
658652
case .macroDecl:

Sources/SwiftSyntax/generated/SyntaxKind.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ public enum SyntaxKind: Sendable {
191191
#if compiler(>=5.8)
192192
@_spi(ExperimentalLanguageFeatures)
193193
#endif
194-
case lifetimeSpecifierArguments
195-
#if compiler(>=5.8)
196-
@_spi(ExperimentalLanguageFeatures)
197-
#endif
198194
case lifetimeTypeSpecifier
199195
case macroDecl
200196
case macroExpansionDecl
@@ -776,8 +772,6 @@ public enum SyntaxKind: Sendable {
776772
return LifetimeSpecifierArgumentListSyntax.self
777773
case .lifetimeSpecifierArgument:
778774
return LifetimeSpecifierArgumentSyntax.self
779-
case .lifetimeSpecifierArguments:
780-
return LifetimeSpecifierArgumentsSyntax.self
781775
case .lifetimeTypeSpecifier:
782776
return LifetimeTypeSpecifierSyntax.self
783777
case .macroDecl:

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,16 +1225,6 @@ open class SyntaxRewriter {
12251225
return visitChildren(node)
12261226
}
12271227

1228-
/// Visit a `LifetimeSpecifierArgumentsSyntax`.
1229-
/// - Parameter node: the node that is being visited
1230-
/// - Returns: the rewritten node
1231-
#if compiler(>=5.8)
1232-
@_spi(ExperimentalLanguageFeatures)
1233-
#endif
1234-
open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> LifetimeSpecifierArgumentsSyntax {
1235-
return visitChildren(node)
1236-
}
1237-
12381228
/// Visit a `LifetimeTypeSpecifierSyntax`.
12391229
/// - Parameter node: the node that is being visited
12401230
/// - Returns: the rewritten node
@@ -2820,10 +2810,6 @@ open class SyntaxRewriter {
28202810
return {
28212811
self.visitImpl($0, LifetimeSpecifierArgumentSyntax.self, self.visit)
28222812
}
2823-
case .lifetimeSpecifierArguments:
2824-
return {
2825-
self.visitImpl($0, LifetimeSpecifierArgumentsSyntax.self, self.visit)
2826-
}
28272813
case .lifetimeTypeSpecifier:
28282814
return {
28292815
self.visitImpl($0, LifetimeTypeSpecifierSyntax.self, self.visit)
@@ -3642,8 +3628,6 @@ open class SyntaxRewriter {
36423628
return visitImpl(node, LifetimeSpecifierArgumentListSyntax.self, visit)
36433629
case .lifetimeSpecifierArgument:
36443630
return visitImpl(node, LifetimeSpecifierArgumentSyntax.self, visit)
3645-
case .lifetimeSpecifierArguments:
3646-
return visitImpl(node, LifetimeSpecifierArgumentsSyntax.self, visit)
36473631
case .lifetimeTypeSpecifier:
36483632
return visitImpl(node, LifetimeTypeSpecifierSyntax.self, visit)
36493633
case .macroDecl:

Sources/SwiftSyntax/generated/SyntaxTraits.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,6 @@ extension LabeledSpecializeArgumentSyntax: WithTrailingCommaSyntax {}
779779

780780
extension LifetimeSpecifierArgumentSyntax: WithTrailingCommaSyntax {}
781781

782-
extension LifetimeTypeSpecifierSyntax: ParenthesizedSyntax {}
783-
784782
extension MacroDeclSyntax: NamedDeclSyntax, WithAttributesSyntax, WithGenericParametersSyntax, WithModifiersSyntax {}
785783

786784
extension MacroExpansionDeclSyntax: FreestandingMacroExpansionSyntax, WithAttributesSyntax, WithModifiersSyntax {}

Sources/SwiftSyntax/generated/SyntaxVisitor.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,24 +2019,6 @@ open class SyntaxVisitor {
20192019
open func visitPost(_ node: LifetimeSpecifierArgumentSyntax) {
20202020
}
20212021

2022-
/// Visiting `LifetimeSpecifierArgumentsSyntax` specifically.
2023-
/// - Parameter node: the node we are visiting.
2024-
/// - Returns: how should we continue visiting.
2025-
#if compiler(>=5.8)
2026-
@_spi(ExperimentalLanguageFeatures)
2027-
#endif
2028-
open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> SyntaxVisitorContinueKind {
2029-
return .visitChildren
2030-
}
2031-
2032-
/// The function called after visiting `LifetimeSpecifierArgumentsSyntax` and its descendants.
2033-
/// - node: the node we just finished visiting.
2034-
#if compiler(>=5.8)
2035-
@_spi(ExperimentalLanguageFeatures)
2036-
#endif
2037-
open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) {
2038-
}
2039-
20402022
/// Visiting `LifetimeTypeSpecifierSyntax` specifically.
20412023
/// - Parameter node: the node we are visiting.
20422024
/// - Returns: how should we continue visiting.
@@ -4220,10 +4202,6 @@ open class SyntaxVisitor {
42204202
return {
42214203
self.visitImpl(&$0, LifetimeSpecifierArgumentSyntax.self, self.visit, self.visitPost)
42224204
}
4223-
case .lifetimeSpecifierArguments:
4224-
return {
4225-
self.visitImpl(&$0, LifetimeSpecifierArgumentsSyntax.self, self.visit, self.visitPost)
4226-
}
42274205
case .lifetimeTypeSpecifier:
42284206
return {
42294207
self.visitImpl(&$0, LifetimeTypeSpecifierSyntax.self, self.visit, self.visitPost)
@@ -5046,8 +5024,6 @@ open class SyntaxVisitor {
50465024
visitImpl(&node, LifetimeSpecifierArgumentListSyntax.self, visit, visitPost)
50475025
case .lifetimeSpecifierArgument:
50485026
visitImpl(&node, LifetimeSpecifierArgumentSyntax.self, visit, visitPost)
5049-
case .lifetimeSpecifierArguments:
5050-
visitImpl(&node, LifetimeSpecifierArgumentsSyntax.self, visit, visitPost)
50515027
case .lifetimeTypeSpecifier:
50525028
visitImpl(&node, LifetimeTypeSpecifierSyntax.self, visit, visitPost)
50535029
case .macroDecl:

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,67 +1049,6 @@ public struct RawLifetimeSpecifierArgumentSyntax: RawSyntaxNodeProtocol {
10491049
}
10501050
}
10511051

1052-
#if compiler(>=5.8)
1053-
@_spi(ExperimentalLanguageFeatures)
1054-
#endif
1055-
@_spi(RawSyntax)
1056-
public struct RawLifetimeSpecifierArgumentsSyntax: RawSyntaxNodeProtocol {
1057-
@_spi(RawSyntax)
1058-
public var layoutView: RawSyntaxLayoutView {
1059-
return raw.layoutView!
1060-
}
1061-
1062-
public static func isKindOf(_ raw: RawSyntax) -> Bool {
1063-
return raw.kind == .lifetimeSpecifierArguments
1064-
}
1065-
1066-
public var raw: RawSyntax
1067-
1068-
init(raw: RawSyntax) {
1069-
precondition(Self.isKindOf(raw))
1070-
self.raw = raw
1071-
}
1072-
1073-
private init(unchecked raw: RawSyntax) {
1074-
self.raw = raw
1075-
}
1076-
1077-
public init?(_ other: some RawSyntaxNodeProtocol) {
1078-
guard Self.isKindOf(other.raw) else {
1079-
return nil
1080-
}
1081-
self.init(unchecked: other.raw)
1082-
}
1083-
1084-
public init(
1085-
_ unexpectedBeforeArguments: RawUnexpectedNodesSyntax? = nil,
1086-
arguments: RawLifetimeSpecifierArgumentListSyntax,
1087-
_ unexpectedAfterArguments: RawUnexpectedNodesSyntax? = nil,
1088-
arena: __shared SyntaxArena
1089-
) {
1090-
let raw = RawSyntax.makeLayout(
1091-
kind: .lifetimeSpecifierArguments, uninitializedCount: 3, arena: arena) { layout in
1092-
layout.initialize(repeating: nil)
1093-
layout[0] = unexpectedBeforeArguments?.raw
1094-
layout[1] = arguments.raw
1095-
layout[2] = unexpectedAfterArguments?.raw
1096-
}
1097-
self.init(unchecked: raw)
1098-
}
1099-
1100-
public var unexpectedBeforeArguments: RawUnexpectedNodesSyntax? {
1101-
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
1102-
}
1103-
1104-
public var arguments: RawLifetimeSpecifierArgumentListSyntax {
1105-
layoutView.children[1].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))!
1106-
}
1107-
1108-
public var unexpectedAfterArguments: RawUnexpectedNodesSyntax? {
1109-
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
1110-
}
1111-
}
1112-
11131052
#if compiler(>=5.8)
11141053
@_spi(ExperimentalLanguageFeatures)
11151054
#endif
@@ -1150,7 +1089,7 @@ public struct RawLifetimeTypeSpecifierSyntax: RawSyntaxNodeProtocol {
11501089
_ unexpectedBetweenLeftParenAndScopedKeyword: RawUnexpectedNodesSyntax? = nil,
11511090
scopedKeyword: RawTokenSyntax?,
11521091
_ unexpectedBetweenScopedKeywordAndArguments: RawUnexpectedNodesSyntax? = nil,
1153-
arguments: RawLifetimeSpecifierArgumentsSyntax,
1092+
arguments: RawLifetimeSpecifierArgumentListSyntax,
11541093
_ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil,
11551094
rightParen: RawTokenSyntax,
11561095
_ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil,
@@ -1202,8 +1141,8 @@ public struct RawLifetimeTypeSpecifierSyntax: RawSyntaxNodeProtocol {
12021141
layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:))
12031142
}
12041143

1205-
public var arguments: RawLifetimeSpecifierArgumentsSyntax {
1206-
layoutView.children[7].map(RawLifetimeSpecifierArgumentsSyntax.init(raw:))!
1144+
public var arguments: RawLifetimeSpecifierArgumentListSyntax {
1145+
layoutView.children[7].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))!
12071146
}
12081147

12091148
public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? {

0 commit comments

Comments
 (0)