Skip to content

Follow up of #2564 #2567

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
Mar 26, 2024
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
30 changes: 3 additions & 27 deletions CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,42 +542,17 @@ public let TYPE_NODES: [Node] = [
elementChoices: [.lifetimeSpecifierArgument]
),

Node(
kind: .lifetimeSpecifierArguments,
base: .syntax,
experimentalFeature: .nonescapableTypes,
nameForDiagnostics: nil,
documentation: """
An optional argument passed to a type parameter.

### Example
`borrow(data)` in `func foo(data: Array<Item>) -> borrow(data) ComplexReferenceType`
""",
children: [
Child(
name: "arguments",
kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments"),
documentation: """
The function parameters that the lifetime of the annotated type depends on.
"""
)
]
),

Node(
kind: .lifetimeTypeSpecifier,
base: .syntax,
experimentalFeature: .nonescapableTypes,
nameForDiagnostics: "lifetime specifier",
documentation: "A specifier that specifies function parameter on whose lifetime a type depends",
traits: [
"Parenthesized"
],
children: [
Child(
name: "dependsOnKeyword",
kind: .token(choices: [.keyword(.dependsOn)]),
documentation: "The specifier token that's attached to the type."
documentation: "lifetime dependence specifier on the return type"
),
Child(
name: "leftParen",
Expand All @@ -586,11 +561,12 @@ public let TYPE_NODES: [Node] = [
Child(
name: "scopedKeyword",
kind: .token(choices: [.keyword(.scoped)]),
documentation: "lifetime of return value is scoped to the lifetime of the original value",
isOptional: true
),
Child(
name: "arguments",
kind: .node(kind: .lifetimeSpecifierArguments)
kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments")
),
Child(
name: "rightParen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ class ValidateSyntaxNodes: XCTestCase {
node: .yieldedExpressionsClause,
message: "could conform to trait 'Parenthesized' but does not"
),
ValidationFailure(node: .lifetimeTypeSpecifier, message: "could conform to trait 'Parenthesized' but does not"),
]
)
}
Expand Down
29 changes: 12 additions & 17 deletions Sources/SwiftParser/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -901,25 +901,23 @@ extension Parser.Lookahead {

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

guard let leftParen = self.consume(if: .leftParen) else {
// If there is no left paren, add an entirely missing detail. Otherwise, we start to consume the following type
// name as a token inside the detail, which leads to confusing recovery results.
let arguments = RawLifetimeSpecifierArgumentsSyntax(
arguments: RawLifetimeSpecifierArgumentListSyntax(
elements: [
RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena)
],
arena: self.arena
),
let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(
elements: [
RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena)
],
arena: self.arena
)
let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(
dependsOnKeyword: specifier,
unexpectedBeforeDependsOnKeyword,
dependsOnKeyword: dependsOnKeyword,
leftParen: missingToken(.leftParen),
scopedKeyword: nil,
arguments: arguments,
arguments: lifetimeSpecifierArgumentList,
rightParen: missingToken(.rightParen),
arena: self.arena
)
Expand Down Expand Up @@ -947,15 +945,12 @@ extension Parser {
} while keepGoing != nil && self.hasProgressed(&loopProgress)
let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(elements: arguments, arena: self.arena)
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
let argumentsSyntax = RawLifetimeSpecifierArgumentsSyntax(
arguments: lifetimeSpecifierArgumentList,
arena: self.arena
)
let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(
dependsOnKeyword: specifier,
unexpectedBeforeDependsOnKeyword,
dependsOnKeyword: dependsOnKeyword,
leftParen: leftParen,
scopedKeyword: scoped,
arguments: argumentsSyntax,
arguments: lifetimeSpecifierArgumentList,
unexpectedBeforeRightParen,
rightParen: rightParen,
arena: self.arena
Expand All @@ -981,7 +976,7 @@ extension Parser {
SPECIFIER_PARSING: while canHaveParameterSpecifier {
if let (_, specifierHandle) = self.at(anyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) {
specifiers.append(parseSimpleTypeSpecifier(specifierHandle: specifierHandle))
} else if self.at(TokenSpec(.dependsOn)) {
} else if self.at(.keyword(.dependsOn)) {
if self.experimentalFeatures.contains(.nonescapableTypes) {
specifiers.append(parseLifetimeTypeSpecifier())
} else {
Expand Down
6 changes: 0 additions & 6 deletions Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2009,12 +2009,6 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
return "trailingComma"
case \LifetimeSpecifierArgumentSyntax.unexpectedAfterTrailingComma:
return "unexpectedAfterTrailingComma"
case \LifetimeSpecifierArgumentsSyntax.unexpectedBeforeArguments:
return "unexpectedBeforeArguments"
case \LifetimeSpecifierArgumentsSyntax.arguments:
return "arguments"
case \LifetimeSpecifierArgumentsSyntax.unexpectedAfterArguments:
return "unexpectedAfterArguments"
case \LifetimeTypeSpecifierSyntax.unexpectedBeforeDependsOnKeyword:
return "unexpectedBeforeDependsOnKeyword"
case \LifetimeTypeSpecifierSyntax.dependsOnKeyword:
Expand Down
14 changes: 0 additions & 14 deletions Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1374,20 +1374,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
visitAnyPost(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) {
visitAnyPost(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,6 @@ extension Syntax {
.node(LayoutRequirementSyntax.self),
.node(LifetimeSpecifierArgumentListSyntax.self),
.node(LifetimeSpecifierArgumentSyntax.self),
.node(LifetimeSpecifierArgumentsSyntax.self),
.node(LifetimeTypeSpecifierSyntax.self),
.node(MacroDeclSyntax.self),
.node(MacroExpansionDeclSyntax.self),
Expand Down
6 changes: 0 additions & 6 deletions Sources/SwiftSyntax/generated/SyntaxEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ public enum SyntaxEnum: Sendable {
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax)
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax)
case macroDecl(MacroDeclSyntax)
case macroExpansionDecl(MacroExpansionDeclSyntax)
Expand Down Expand Up @@ -651,8 +647,6 @@ public extension Syntax {
return .lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax(self)!)
case .lifetimeSpecifierArgument:
return .lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax(self)!)
case .lifetimeSpecifierArguments:
return .lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax(self)!)
case .lifetimeTypeSpecifier:
return .lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax(self)!)
case .macroDecl:
Expand Down
6 changes: 0 additions & 6 deletions Sources/SwiftSyntax/generated/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ public enum SyntaxKind: Sendable {
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeSpecifierArguments
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeTypeSpecifier
case macroDecl
case macroExpansionDecl
Expand Down Expand Up @@ -776,8 +772,6 @@ public enum SyntaxKind: Sendable {
return LifetimeSpecifierArgumentListSyntax.self
case .lifetimeSpecifierArgument:
return LifetimeSpecifierArgumentSyntax.self
case .lifetimeSpecifierArguments:
return LifetimeSpecifierArgumentsSyntax.self
case .lifetimeTypeSpecifier:
return LifetimeTypeSpecifierSyntax.self
case .macroDecl:
Expand Down
16 changes: 0 additions & 16 deletions Sources/SwiftSyntax/generated/SyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1225,16 +1225,6 @@ open class SyntaxRewriter {
return visitChildren(node)
}

/// Visit a `LifetimeSpecifierArgumentsSyntax`.
/// - Parameter node: the node that is being visited
/// - Returns: the rewritten node
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> LifetimeSpecifierArgumentsSyntax {
return visitChildren(node)
}

/// Visit a `LifetimeTypeSpecifierSyntax`.
/// - Parameter node: the node that is being visited
/// - Returns: the rewritten node
Expand Down Expand Up @@ -2820,10 +2810,6 @@ open class SyntaxRewriter {
return {
self.visitImpl($0, LifetimeSpecifierArgumentSyntax.self, self.visit)
}
case .lifetimeSpecifierArguments:
return {
self.visitImpl($0, LifetimeSpecifierArgumentsSyntax.self, self.visit)
}
case .lifetimeTypeSpecifier:
return {
self.visitImpl($0, LifetimeTypeSpecifierSyntax.self, self.visit)
Expand Down Expand Up @@ -3642,8 +3628,6 @@ open class SyntaxRewriter {
return visitImpl(node, LifetimeSpecifierArgumentListSyntax.self, visit)
case .lifetimeSpecifierArgument:
return visitImpl(node, LifetimeSpecifierArgumentSyntax.self, visit)
case .lifetimeSpecifierArguments:
return visitImpl(node, LifetimeSpecifierArgumentsSyntax.self, visit)
case .lifetimeTypeSpecifier:
return visitImpl(node, LifetimeTypeSpecifierSyntax.self, visit)
case .macroDecl:
Expand Down
2 changes: 0 additions & 2 deletions Sources/SwiftSyntax/generated/SyntaxTraits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,6 @@ extension LabeledSpecializeArgumentSyntax: WithTrailingCommaSyntax {}

extension LifetimeSpecifierArgumentSyntax: WithTrailingCommaSyntax {}

extension LifetimeTypeSpecifierSyntax: ParenthesizedSyntax {}

extension MacroDeclSyntax: NamedDeclSyntax, WithAttributesSyntax, WithGenericParametersSyntax, WithModifiersSyntax {}

extension MacroExpansionDeclSyntax: FreestandingMacroExpansionSyntax, WithAttributesSyntax, WithModifiersSyntax {}
Expand Down
24 changes: 0 additions & 24 deletions Sources/SwiftSyntax/generated/SyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2019,24 +2019,6 @@ open class SyntaxVisitor {
open func visitPost(_ node: LifetimeSpecifierArgumentSyntax) {
}

/// Visiting `LifetimeSpecifierArgumentsSyntax` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: how should we continue visiting.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> SyntaxVisitorContinueKind {
return .visitChildren
}

/// The function called after visiting `LifetimeSpecifierArgumentsSyntax` and its descendants.
/// - node: the node we just finished visiting.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) {
}

/// Visiting `LifetimeTypeSpecifierSyntax` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: how should we continue visiting.
Expand Down Expand Up @@ -4220,10 +4202,6 @@ open class SyntaxVisitor {
return {
self.visitImpl(&$0, LifetimeSpecifierArgumentSyntax.self, self.visit, self.visitPost)
}
case .lifetimeSpecifierArguments:
return {
self.visitImpl(&$0, LifetimeSpecifierArgumentsSyntax.self, self.visit, self.visitPost)
}
case .lifetimeTypeSpecifier:
return {
self.visitImpl(&$0, LifetimeTypeSpecifierSyntax.self, self.visit, self.visitPost)
Expand Down Expand Up @@ -5046,8 +5024,6 @@ open class SyntaxVisitor {
visitImpl(&node, LifetimeSpecifierArgumentListSyntax.self, visit, visitPost)
case .lifetimeSpecifierArgument:
visitImpl(&node, LifetimeSpecifierArgumentSyntax.self, visit, visitPost)
case .lifetimeSpecifierArguments:
visitImpl(&node, LifetimeSpecifierArgumentsSyntax.self, visit, visitPost)
case .lifetimeTypeSpecifier:
visitImpl(&node, LifetimeTypeSpecifierSyntax.self, visit, visitPost)
case .macroDecl:
Expand Down
67 changes: 3 additions & 64 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1049,67 +1049,6 @@ public struct RawLifetimeSpecifierArgumentSyntax: RawSyntaxNodeProtocol {
}
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
@_spi(RawSyntax)
public struct RawLifetimeSpecifierArgumentsSyntax: RawSyntaxNodeProtocol {
@_spi(RawSyntax)
public var layoutView: RawSyntaxLayoutView {
return raw.layoutView!
}

public static func isKindOf(_ raw: RawSyntax) -> Bool {
return raw.kind == .lifetimeSpecifierArguments
}

public var raw: RawSyntax

init(raw: RawSyntax) {
precondition(Self.isKindOf(raw))
self.raw = raw
}

private init(unchecked raw: RawSyntax) {
self.raw = raw
}

public init?(_ other: some RawSyntaxNodeProtocol) {
guard Self.isKindOf(other.raw) else {
return nil
}
self.init(unchecked: other.raw)
}

public init(
_ unexpectedBeforeArguments: RawUnexpectedNodesSyntax? = nil,
arguments: RawLifetimeSpecifierArgumentListSyntax,
_ unexpectedAfterArguments: RawUnexpectedNodesSyntax? = nil,
arena: __shared SyntaxArena
) {
let raw = RawSyntax.makeLayout(
kind: .lifetimeSpecifierArguments, uninitializedCount: 3, arena: arena) { layout in
layout.initialize(repeating: nil)
layout[0] = unexpectedBeforeArguments?.raw
layout[1] = arguments.raw
layout[2] = unexpectedAfterArguments?.raw
}
self.init(unchecked: raw)
}

public var unexpectedBeforeArguments: RawUnexpectedNodesSyntax? {
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
}

public var arguments: RawLifetimeSpecifierArgumentListSyntax {
layoutView.children[1].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))!
}

public var unexpectedAfterArguments: RawUnexpectedNodesSyntax? {
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
}
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
Expand Down Expand Up @@ -1150,7 +1089,7 @@ public struct RawLifetimeTypeSpecifierSyntax: RawSyntaxNodeProtocol {
_ unexpectedBetweenLeftParenAndScopedKeyword: RawUnexpectedNodesSyntax? = nil,
scopedKeyword: RawTokenSyntax?,
_ unexpectedBetweenScopedKeywordAndArguments: RawUnexpectedNodesSyntax? = nil,
arguments: RawLifetimeSpecifierArgumentsSyntax,
arguments: RawLifetimeSpecifierArgumentListSyntax,
_ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil,
rightParen: RawTokenSyntax,
_ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil,
Expand Down Expand Up @@ -1202,8 +1141,8 @@ public struct RawLifetimeTypeSpecifierSyntax: RawSyntaxNodeProtocol {
layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:))
}

public var arguments: RawLifetimeSpecifierArgumentsSyntax {
layoutView.children[7].map(RawLifetimeSpecifierArgumentsSyntax.init(raw:))!
public var arguments: RawLifetimeSpecifierArgumentListSyntax {
layoutView.children[7].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))!
}

public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? {
Expand Down
Loading