From e51d85110ad23eba7bf70982c4909ef97ffb1196 Mon Sep 17 00:00:00 2001 From: Alex Hoppen <ahoppen@apple.com> Date: Sun, 21 Jan 2024 19:22:38 -0800 Subject: [PATCH 1/4] Allow multiple type specifiers on a type Having multiple type specifiers on a type is valid in the C++ parser but not in the Swift parser. rdar://118125715 --- .../SyntaxSupport/SyntaxNodeKind.swift | 2 + .../Sources/SyntaxSupport/TypeNodes.swift | 35 +++- Release Notes/600.md | 8 + Sources/SwiftParser/Parser.swift | 13 ++ Sources/SwiftParser/Types.swift | 62 +++--- .../generated/Parser+TokenSpecSet.swift | 184 +++++++++--------- .../ParseDiagnosticsGenerator.swift | 4 +- .../generated/SwiftSyntax.md | 2 + .../SwiftSyntaxCompatibility.swift | 67 +++++++ .../generated/ChildNameForKeyPath.swift | 18 +- .../generated/SyntaxAnyVisitor.swift | 16 ++ .../generated/SyntaxBaseNodes.swift | 2 + .../generated/SyntaxCollections.swift | 22 +++ .../SwiftSyntax/generated/SyntaxEnum.swift | 6 + .../SwiftSyntax/generated/SyntaxKind.swift | 8 + .../generated/SyntaxRewriter.swift | 26 +++ .../SwiftSyntax/generated/SyntaxVisitor.swift | 36 ++++ .../generated/raw/RawSyntaxNodesAB.swift | 20 +- .../generated/raw/RawSyntaxNodesTUVWXYZ.swift | 108 ++++++++++ .../generated/raw/RawSyntaxValidation.swift | 31 +-- .../generated/syntaxNodes/SyntaxNodesAB.swift | 73 ++++--- .../syntaxNodes/SyntaxNodesTUVWXYZ.swift | 92 +++++++++ .../generated/ResultBuilders.swift | 13 ++ Tests/SwiftParserTest/TypeTests.swift | 5 + .../translated/InvalidTests.swift | 25 +-- 25 files changed, 678 insertions(+), 200 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift index 3db67234b1e..6351e30f97a 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift @@ -285,6 +285,8 @@ public enum SyntaxNodeKind: String, CaseIterable { case typeEffectSpecifiers case typeExpr case typeInitializerClause + case typeSpecifier + case typeSpecifierList case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments case unexpectedNodes diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index 69ac54c8660..623ee20e563 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -35,12 +35,10 @@ public let TYPE_NODES: [Node] = [ ), Node( - kind: .attributedType, - base: .type, - nameForDiagnostics: "type", - traits: [ - "WithAttributes" - ], + kind: .typeSpecifier, + base: .syntax, + nameForDiagnostics: nil, + documentation: "A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming`", children: [ Child( name: "specifier", @@ -54,8 +52,29 @@ public let TYPE_NODES: [Node] = [ .keyword(.consuming), .keyword(.transferring), .keyword(._resultDependsOn), - ]), - isOptional: true + ]) + ) + ] + ), + + Node( + kind: .typeSpecifierList, + base: .syntaxCollection, + nameForDiagnostics: nil, + elementChoices: [.typeSpecifier] + ), + + Node( + kind: .attributedType, + base: .type, + nameForDiagnostics: "type", + traits: [ + "WithAttributes" + ], + children: [ + Child( + name: "specifiers", + kind: .collection(kind: .typeSpecifierList, collectionElementName: "Specifier", defaultsToEmpty: true) ), Child( name: "attributes", diff --git a/Release Notes/600.md b/Release Notes/600.md index 1b8741b750e..46f025353e5 100644 --- a/Release Notes/600.md +++ b/Release Notes/600.md @@ -62,6 +62,10 @@ - Description: `IncrementalEdit` used to store the range that was replaced and the length of the replacement but not the replacement bytes by itself. `IncrementalEdit` now has a `replacement` property that contains the replacement bytes. - Pull Request: https://github.com/apple/swift-syntax/pull/2527 +- `TypeSpecifierListSyntax` and `TypeSpecifierSyntax` + - Description: `AttributedTypeSyntax` can now contain multiple specifiers and these types are used to model the list of specifiers. + - Pull request: https://github.com/apple/swift-syntax/pull/2433 + ## API Behavior Changes ## Deprecations @@ -87,6 +91,10 @@ - Description: `EditorPlaceholderDeclSyntax` and `EditorPlaceholderExprSyntax` are now deprecated and placeholders are instead parsed as identifiers within a `MissingDeclSyntax` or `DeclReferenceExprSyntax`. - Pull request: https://github.com/apple/swift-syntax/pull/2237 +- `AttributedTypeSyntax.specifier` has renamed and changed to be a collection + - Description: Types can have multiple specifiers now and the syntax tree has been modified to reflect that. + - Pull request: https://github.com/apple/swift-syntax/pull/2433 + ## API-Incompatible Changes - `MacroDefinition` used for expanding macros: diff --git a/Sources/SwiftParser/Parser.swift b/Sources/SwiftParser/Parser.swift index a1d7ea15b0f..6b060c0abbe 100644 --- a/Sources/SwiftParser/Parser.swift +++ b/Sources/SwiftParser/Parser.swift @@ -178,6 +178,19 @@ public struct Parser { return _emptyRawAttributeListSyntax! } + var _emptyRawTypeSpecifierListSyntax: RawTypeSpecifierListSyntax? + + /// Create an empty collection of the given type. + /// + /// These empty collections are only created once and the same node is returned + /// on subsequent calls, reducing memory usage. + mutating func emptyCollection(_: RawTypeSpecifierListSyntax.Type) -> RawTypeSpecifierListSyntax { + if _emptyRawTypeSpecifierListSyntax == nil { + _emptyRawTypeSpecifierListSyntax = RawTypeSpecifierListSyntax(elements: [], arena: self.arena) + } + return _emptyRawTypeSpecifierListSyntax! + } + /// The delegated initializer for the parser. /// /// - Parameters diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index 197906a265f..3080d8b1be1 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -31,7 +31,7 @@ extension Parser { } mutating func parseTypeScalar(misplacedSpecifiers: [RawTokenSyntax] = []) -> RawTypeSyntax { - let (specifier, unexpectedBeforeAttrList, attrList) = self.parseTypeAttributeList(misplacedSpecifiers: misplacedSpecifiers) + let specifiersAndAttributes = self.parseTypeAttributeList(misplacedSpecifiers: misplacedSpecifiers) var base = RawTypeSyntax(self.parseSimpleOrCompositionType()) if self.withLookahead({ $0.atFunctionTypeArrow() }) { var effectSpecifiers = self.parseTypeEffectSpecifiers() @@ -88,12 +88,11 @@ extension Parser { ) } - if unexpectedBeforeAttrList != nil || specifier != nil || !attrList.isEmpty { + if let specifiersAndAttributes { return RawTypeSyntax( RawAttributedTypeSyntax( - specifier: specifier, - unexpectedBeforeAttrList, - attributes: attrList, + specifiers: specifiersAndAttributes.specifiers, + attributes: specifiersAndAttributes.attributes, baseType: base, arena: self.arena ) @@ -891,35 +890,44 @@ extension Parser.Lookahead { } extension Parser { - mutating func parseTypeAttributeList(misplacedSpecifiers: [RawTokenSyntax] = []) -> ( - specifier: RawTokenSyntax?, unexpectedBeforeAttributes: RawUnexpectedNodesSyntax?, attributes: RawAttributeListSyntax - ) { - var specifier: RawTokenSyntax? = nil - if canHaveParameterSpecifier { - specifier = self.consume(ifAnyIn: TypeSpecifier.self) + mutating func parseTypeAttributeList( + misplacedSpecifiers: [RawTokenSyntax] = [] + ) -> ( + specifiers: RawTypeSpecifierListSyntax, + attributes: RawAttributeListSyntax + )? { + var specifiers: [RawTypeSpecifierSyntax] = [] + while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) { + specifiers.append(RawTypeSpecifierSyntax(specifier: specifier, arena: arena)) } - // We can only stick one specifier on this type. Let's pick the first one - if specifier == nil, let misplacedSpecifier = misplacedSpecifiers.first { - specifier = missingToken(misplacedSpecifier.tokenKind, text: misplacedSpecifier.tokenText) - } - var extraneousSpecifiers: [RawTokenSyntax] = [] - - while canHaveParameterSpecifier, - let extraSpecifier = self.consume(ifAnyIn: AttributedTypeSyntax.SpecifierOptions.self) - { - if specifier == nil { - specifier = extraSpecifier - } else { - extraneousSpecifiers.append(extraSpecifier) + if !misplacedSpecifiers.isEmpty { + specifiers += misplacedSpecifiers.map { + RawTypeSpecifierSyntax(specifier: missingToken($0.tokenKind, text: $0.tokenText), arena: arena) } } - let unexpectedBeforeAttributeList = RawUnexpectedNodesSyntax(extraneousSpecifiers, arena: self.arena) + let attributes: RawAttributeListSyntax? if self.at(.atSign) { - return (specifier, unexpectedBeforeAttributeList, self.parseTypeAttributeListPresent()) + attributes = self.parseTypeAttributeListPresent() + } else { + attributes = nil } - return (specifier, unexpectedBeforeAttributeList, self.emptyCollection(RawAttributeListSyntax.self)) + guard !specifiers.isEmpty || attributes != nil else { + // No specifiers or attributes on this type + return nil + } + let specifierList: RawTypeSpecifierListSyntax + if specifiers.isEmpty { + specifierList = self.emptyCollection(RawTypeSpecifierListSyntax.self) + } else { + specifierList = RawTypeSpecifierListSyntax(elements: specifiers, arena: arena) + } + + return ( + specifierList, + attributes ?? self.emptyCollection(RawAttributeListSyntax.self) + ) } mutating func parseTypeAttributeListPresent() -> RawAttributeListSyntax { diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index b53eae5e8c0..393e3df7c02 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -177,98 +177,6 @@ extension AsExprSyntax { } } -extension AttributedTypeSyntax { - @_spi(Diagnostics) - public enum SpecifierOptions: TokenSpecSet { - case `inout` - case __shared - case __owned - case isolated - case _const - case borrowing - case consuming - @_spi(ExperimentalLanguageFeatures) - case transferring - @_spi(ExperimentalLanguageFeatures) - case _resultDependsOn - - init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { - switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.inout): - self = .inout - case TokenSpec(.__shared): - self = .__shared - case TokenSpec(.__owned): - self = .__owned - case TokenSpec(.isolated): - self = .isolated - case TokenSpec(._const): - self = ._const - case TokenSpec(.borrowing): - self = .borrowing - case TokenSpec(.consuming): - self = .consuming - case TokenSpec(.transferring) where experimentalFeatures.contains(.transferringArgsAndResults): - self = .transferring - case TokenSpec(._resultDependsOn) where experimentalFeatures.contains(.nonescapableTypes): - self = ._resultDependsOn - default: - return nil - } - } - - var spec: TokenSpec { - switch self { - case .inout: - return .keyword(.inout) - case .__shared: - return .keyword(.__shared) - case .__owned: - return .keyword(.__owned) - case .isolated: - return .keyword(.isolated) - case ._const: - return .keyword(._const) - case .borrowing: - return .keyword(.borrowing) - case .consuming: - return .keyword(.consuming) - case .transferring: - return .keyword(.transferring) - case ._resultDependsOn: - return .keyword(._resultDependsOn) - } - } - - /// 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 .inout: - return .keyword(.inout) - case .__shared: - return .keyword(.__shared) - case .__owned: - return .keyword(.__owned) - case .isolated: - return .keyword(.isolated) - case ._const: - return .keyword(._const) - case .borrowing: - return .keyword(.borrowing) - case .consuming: - return .keyword(.consuming) - case .transferring: - return .keyword(.transferring) - case ._resultDependsOn: - return .keyword(._resultDependsOn) - } - } - } -} - extension AvailabilityConditionSyntax { @_spi(Diagnostics) public enum AvailabilityKeywordOptions: TokenSpecSet { @@ -2960,6 +2868,98 @@ extension TupleTypeElementSyntax { } } +extension TypeSpecifierSyntax { + @_spi(Diagnostics) + public enum SpecifierOptions: TokenSpecSet { + case `inout` + case __shared + case __owned + case isolated + case _const + case borrowing + case consuming + @_spi(ExperimentalLanguageFeatures) + case transferring + @_spi(ExperimentalLanguageFeatures) + case _resultDependsOn + + init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(.inout): + self = .inout + case TokenSpec(.__shared): + self = .__shared + case TokenSpec(.__owned): + self = .__owned + case TokenSpec(.isolated): + self = .isolated + case TokenSpec(._const): + self = ._const + case TokenSpec(.borrowing): + self = .borrowing + case TokenSpec(.consuming): + self = .consuming + case TokenSpec(.transferring) where experimentalFeatures.contains(.transferringArgsAndResults): + self = .transferring + case TokenSpec(._resultDependsOn) where experimentalFeatures.contains(.nonescapableTypes): + self = ._resultDependsOn + default: + return nil + } + } + + var spec: TokenSpec { + switch self { + case .inout: + return .keyword(.inout) + case .__shared: + return .keyword(.__shared) + case .__owned: + return .keyword(.__owned) + case .isolated: + return .keyword(.isolated) + case ._const: + return .keyword(._const) + case .borrowing: + return .keyword(.borrowing) + case .consuming: + return .keyword(.consuming) + case .transferring: + return .keyword(.transferring) + case ._resultDependsOn: + return .keyword(._resultDependsOn) + } + } + + /// 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 .inout: + return .keyword(.inout) + case .__shared: + return .keyword(.__shared) + case .__owned: + return .keyword(.__owned) + case .isolated: + return .keyword(.isolated) + case ._const: + return .keyword(._const) + case .borrowing: + return .keyword(.borrowing) + case .consuming: + return .keyword(.consuming) + case .transferring: + return .keyword(.transferring) + case ._resultDependsOn: + return .keyword(._resultDependsOn) + } + } + } +} + extension UnresolvedAsExprSyntax { @_spi(Diagnostics) public enum QuestionOrExclamationMarkOptions: TokenSpecSet { diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index b1c87db62a2..8b2df4d2dbf 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -946,7 +946,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { exchangeTokens( unexpected: node.unexpectedBetweenModifiersAndFirstName, unexpectedTokenCondition: { TypeSpecifier(token: $0) != nil }, - correctTokens: [node.type.as(AttributedTypeSyntax.self)?.specifier], + correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.map(\.specifier) ?? [], message: { SpecifierOnParameterName(misplacedSpecifiers: $0) }, moveFixIt: { MoveTokensInFrontOfTypeFixIt(movedTokens: $0) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } @@ -1743,7 +1743,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { exchangeTokens( unexpected: node.unexpectedBetweenInoutKeywordAndFirstName, unexpectedTokenCondition: { TypeSpecifier(token: $0) != nil }, - correctTokens: [node.type.as(AttributedTypeSyntax.self)?.specifier], + correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.map(\.specifier) ?? [], message: { SpecifierOnParameterName(misplacedSpecifiers: $0) }, moveFixIt: { MoveTokensInFrontOfTypeFixIt(movedTokens: $0) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } diff --git a/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md b/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md index 17ef8a8a6d2..333d66b07df 100644 --- a/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md +++ b/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md @@ -301,6 +301,8 @@ These articles are intended for developers wishing to contribute to SwiftSyntax - <doc:SwiftSyntax/TuplePatternElementSyntax> - <doc:SwiftSyntax/TupleTypeElementListSyntax> - <doc:SwiftSyntax/TupleTypeElementSyntax> +- <doc:SwiftSyntax/TypeSpecifierListSyntax> +- <doc:SwiftSyntax/TypeSpecifierSyntax> - <doc:SwiftSyntax/UnexpectedNodesSyntax> - <doc:SwiftSyntax/VersionComponentListSyntax> - <doc:SwiftSyntax/VersionComponentSyntax> diff --git a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift index a6db529039c..9df3bc3900f 100644 --- a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift +++ b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift @@ -37,6 +37,73 @@ public extension AccessorEffectSpecifiersSyntax { } } +extension AttributedTypeSyntax { + @available(*, deprecated, message: "Use initializer that takes a list of specifiers instead") + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforeSpecifier: UnexpectedNodesSyntax? = nil, + specifier: TokenSyntax? = nil, + _ unexpectedBetweenSpecifierAndAttributes: UnexpectedNodesSyntax? = nil, + attributes: AttributeListSyntax = [], + _ unexpectedBetweenAttributesAndBaseType: UnexpectedNodesSyntax? = nil, + baseType: some TypeSyntaxProtocol, + _ unexpectedAfterBaseType: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + ) { + let specifiers: TypeSpecifierListSyntax + if let specifier { + specifiers = [TypeSpecifierSyntax(specifier: specifier)] + } else { + specifiers = [] + } + self.init( + leadingTrivia: leadingTrivia, + unexpectedBeforeSpecifier, + specifiers: specifiers, + unexpectedBetweenSpecifierAndAttributes, + attributes: attributes, + unexpectedBetweenAttributesAndBaseType, + baseType: baseType, + unexpectedAfterBaseType, + trailingTrivia: trailingTrivia + ) + } + + @available(*, deprecated, renamed: "unexpectedBeforeSpecifiers") + public var unexpectedBeforeSpecifier: UnexpectedNodesSyntax? { + get { + self.unexpectedBeforeSpecifiers + } + set { + self.unexpectedBeforeSpecifiers = newValue + } + } + + @available(*, deprecated, message: "Access the specifiers list instead") + public var specifier: TokenSyntax? { + get { + specifiers.first?.specifier + } + set { + if let newValue { + specifiers = [TypeSpecifierSyntax(specifier: newValue)] + } else { + specifiers = [] + } + } + } + + @available(*, deprecated, renamed: "unexpectedBetweenSpecifiersAndAttributes") + public var unexpectedBetweenSpecifierAndAttributes: UnexpectedNodesSyntax? { + get { + self.unexpectedBetweenSpecifiersAndAttributes + } + set { + self.unexpectedBetweenSpecifiersAndAttributes = newValue + } + } +} + extension AttributeSyntax { @available(*, deprecated, renamed: "Arguments") public typealias Argument = Arguments diff --git a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift index 3c05651bd4c..f967ed48b2e 100644 --- a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift +++ b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift @@ -239,12 +239,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "rightParen" case \AttributeSyntax.unexpectedAfterRightParen: return "unexpectedAfterRightParen" - case \AttributedTypeSyntax.unexpectedBeforeSpecifier: - return "unexpectedBeforeSpecifier" - case \AttributedTypeSyntax.specifier: - return "specifier" - case \AttributedTypeSyntax.unexpectedBetweenSpecifierAndAttributes: - return "unexpectedBetweenSpecifierAndAttributes" + case \AttributedTypeSyntax.unexpectedBeforeSpecifiers: + return "unexpectedBeforeSpecifiers" + case \AttributedTypeSyntax.specifiers: + return "specifiers" + case \AttributedTypeSyntax.unexpectedBetweenSpecifiersAndAttributes: + return "unexpectedBetweenSpecifiersAndAttributes" case \AttributedTypeSyntax.attributes: return "attributes" case \AttributedTypeSyntax.unexpectedBetweenAttributesAndBaseType: @@ -3289,6 +3289,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "value" case \TypeInitializerClauseSyntax.unexpectedAfterValue: return "unexpectedAfterValue" + case \TypeSpecifierSyntax.unexpectedBeforeSpecifier: + return "unexpectedBeforeSpecifier" + case \TypeSpecifierSyntax.specifier: + return "specifier" + case \TypeSpecifierSyntax.unexpectedAfterSpecifier: + return "unexpectedAfterSpecifier" case \UnavailableFromAsyncAttributeArgumentsSyntax.unexpectedBeforeMessageLabel: return "unexpectedBeforeMessageLabel" case \UnavailableFromAsyncAttributeArgumentsSyntax.messageLabel: diff --git a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift index 7aa92b754b0..9562943c922 100644 --- a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift @@ -2148,6 +2148,22 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } + override open func visit(_ node: TypeSpecifierListSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + override open func visitPost(_ node: TypeSpecifierListSyntax) { + visitAnyPost(node._syntaxNode) + } + + override open func visit(_ node: TypeSpecifierSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + override open func visitPost(_ node: TypeSpecifierSyntax) { + visitAnyPost(node._syntaxNode) + } + override open func visit(_ node: UnavailableFromAsyncAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index b4084ddc80b..fed0fd88348 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -1779,6 +1779,8 @@ extension Syntax { .node(TypeEffectSpecifiersSyntax.self), .node(TypeExprSyntax.self), .node(TypeInitializerClauseSyntax.self), + .node(TypeSpecifierListSyntax.self), + .node(TypeSpecifierSyntax.self), .node(UnavailableFromAsyncAttributeArgumentsSyntax.self), .node(UnderscorePrivateAttributeArgumentsSyntax.self), .node(UnexpectedNodesSyntax.self), diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index 7d698b3194b..fba627d097a 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -1650,6 +1650,28 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable { public static let syntaxKind = SyntaxKind.tupleTypeElementList } +/// ### Children +/// +/// ``TypeSpecifierSyntax`` `*` +/// +/// ### Contained in +/// +/// - ``AttributedTypeSyntax``.``AttributedTypeSyntax/specifiers`` +public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { + public typealias Element = TypeSpecifierSyntax + + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .typeSpecifierList else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + public static let syntaxKind = SyntaxKind.typeSpecifierList +} + /// A collection of syntax nodes that occurred in the source code but could not be used to form a valid syntax tree. /// /// ### Children diff --git a/Sources/SwiftSyntax/generated/SyntaxEnum.swift b/Sources/SwiftSyntax/generated/SyntaxEnum.swift index 408b25f9e60..87594f87c16 100644 --- a/Sources/SwiftSyntax/generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/generated/SyntaxEnum.swift @@ -281,6 +281,8 @@ public enum SyntaxEnum: Sendable { case typeEffectSpecifiers(TypeEffectSpecifiersSyntax) case typeExpr(TypeExprSyntax) case typeInitializerClause(TypeInitializerClauseSyntax) + case typeSpecifierList(TypeSpecifierListSyntax) + case typeSpecifier(TypeSpecifierSyntax) case unavailableFromAsyncAttributeArguments(UnavailableFromAsyncAttributeArgumentsSyntax) case underscorePrivateAttributeArguments(UnderscorePrivateAttributeArgumentsSyntax) case unexpectedNodes(UnexpectedNodesSyntax) @@ -827,6 +829,10 @@ public extension Syntax { return .typeExpr(TypeExprSyntax(self)!) case .typeInitializerClause: return .typeInitializerClause(TypeInitializerClauseSyntax(self)!) + case .typeSpecifierList: + return .typeSpecifierList(TypeSpecifierListSyntax(self)!) + case .typeSpecifier: + return .typeSpecifier(TypeSpecifierSyntax(self)!) case .unavailableFromAsyncAttributeArguments: return .unavailableFromAsyncAttributeArguments(UnavailableFromAsyncAttributeArgumentsSyntax(self)!) case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index 8588c2a632c..794255d0a4b 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -281,6 +281,8 @@ public enum SyntaxKind: Sendable { case typeEffectSpecifiers case typeExpr case typeInitializerClause + case typeSpecifierList + case typeSpecifier case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments case unexpectedNodes @@ -394,6 +396,8 @@ public enum SyntaxKind: Sendable { return true case .tupleTypeElementList: return true + case .typeSpecifierList: + return true case .unexpectedNodes: return true case .versionComponentList: @@ -948,6 +952,10 @@ public enum SyntaxKind: Sendable { return TypeExprSyntax.self case .typeInitializerClause: return TypeInitializerClauseSyntax.self + case .typeSpecifierList: + return TypeSpecifierListSyntax.self + case .typeSpecifier: + return TypeSpecifierSyntax.self case .unavailableFromAsyncAttributeArguments: return UnavailableFromAsyncAttributeArgumentsSyntax.self case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index cd4a81d4f28..d2236ad5347 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -1906,6 +1906,20 @@ open class SyntaxRewriter { return visitChildren(node) } + /// Visit a ``TypeSpecifierListSyntax``. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + open func visit(_ node: TypeSpecifierListSyntax) -> TypeSpecifierListSyntax { + return visitChildren(node) + } + + /// Visit a ``TypeSpecifierSyntax``. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + open func visit(_ node: TypeSpecifierSyntax) -> TypeSpecifierSyntax { + return visitChildren(node) + } + /// Visit a ``UnavailableFromAsyncAttributeArgumentsSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -3156,6 +3170,14 @@ open class SyntaxRewriter { return { self.visitImpl($0, TypeInitializerClauseSyntax.self, self.visit) } + case .typeSpecifierList: + return { + self.visitImpl($0, TypeSpecifierListSyntax.self, self.visit) + } + case .typeSpecifier: + return { + self.visitImpl($0, TypeSpecifierSyntax.self, self.visit) + } case .unavailableFromAsyncAttributeArguments: return { self.visitImpl($0, UnavailableFromAsyncAttributeArgumentsSyntax.self, self.visit) @@ -3758,6 +3780,10 @@ open class SyntaxRewriter { return visitImpl(node, TypeExprSyntax.self, visit) case .typeInitializerClause: return visitImpl(node, TypeInitializerClauseSyntax.self, visit) + case .typeSpecifierList: + return visitImpl(node, TypeSpecifierListSyntax.self, visit) + case .typeSpecifier: + return visitImpl(node, TypeSpecifierSyntax.self, visit) case .unavailableFromAsyncAttributeArguments: return visitImpl(node, UnavailableFromAsyncAttributeArgumentsSyntax.self, visit) case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift index 995dd8881d7..528ef393627 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -3166,6 +3166,30 @@ open class SyntaxVisitor { open func visitPost(_ node: TypeInitializerClauseSyntax) { } + /// Visiting ``TypeSpecifierListSyntax`` specifically. + /// - Parameter node: the node we are visiting. + /// - Returns: how should we continue visiting. + open func visit(_ node: TypeSpecifierListSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``TypeSpecifierListSyntax`` and its descendants. + /// - node: the node we just finished visiting. + open func visitPost(_ node: TypeSpecifierListSyntax) { + } + + /// Visiting ``TypeSpecifierSyntax`` specifically. + /// - Parameter node: the node we are visiting. + /// - Returns: how should we continue visiting. + open func visit(_ node: TypeSpecifierSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``TypeSpecifierSyntax`` and its descendants. + /// - node: the node we just finished visiting. + open func visitPost(_ node: TypeSpecifierSyntax) { + } + /// Visiting ``UnavailableFromAsyncAttributeArgumentsSyntax`` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -4484,6 +4508,14 @@ open class SyntaxVisitor { return { self.visitImpl($0, TypeInitializerClauseSyntax.self, self.visit, self.visitPost) } + case .typeSpecifierList: + return { + self.visitImpl($0, TypeSpecifierListSyntax.self, self.visit, self.visitPost) + } + case .typeSpecifier: + return { + self.visitImpl($0, TypeSpecifierSyntax.self, self.visit, self.visitPost) + } case .unavailableFromAsyncAttributeArguments: return { self.visitImpl($0, UnavailableFromAsyncAttributeArgumentsSyntax.self, self.visit, self.visitPost) @@ -5089,6 +5121,10 @@ open class SyntaxVisitor { visitImpl(node, TypeExprSyntax.self, visit, visitPost) case .typeInitializerClause: visitImpl(node, TypeInitializerClauseSyntax.self, visit, visitPost) + case .typeSpecifierList: + visitImpl(node, TypeSpecifierListSyntax.self, visit, visitPost) + case .typeSpecifier: + visitImpl(node, TypeSpecifierSyntax.self, visit, visitPost) case .unavailableFromAsyncAttributeArguments: visitImpl(node, UnavailableFromAsyncAttributeArgumentsSyntax.self, visit, visitPost) case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift index 0ac0e20d275..1eaad4b50e4 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift @@ -1594,9 +1594,9 @@ public struct RawAttributedTypeSyntax: RawTypeSyntaxNodeProtocol { } public init( - _ unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? = nil, - specifier: RawTokenSyntax?, - _ unexpectedBetweenSpecifierAndAttributes: RawUnexpectedNodesSyntax? = nil, + _ unexpectedBeforeSpecifiers: RawUnexpectedNodesSyntax? = nil, + specifiers: RawTypeSpecifierListSyntax, + _ unexpectedBetweenSpecifiersAndAttributes: RawUnexpectedNodesSyntax? = nil, attributes: RawAttributeListSyntax, _ unexpectedBetweenAttributesAndBaseType: RawUnexpectedNodesSyntax? = nil, baseType: RawTypeSyntax, @@ -1606,9 +1606,9 @@ public struct RawAttributedTypeSyntax: RawTypeSyntaxNodeProtocol { let raw = RawSyntax.makeLayout( kind: .attributedType, uninitializedCount: 7, arena: arena) { layout in layout.initialize(repeating: nil) - layout[0] = unexpectedBeforeSpecifier?.raw - layout[1] = specifier?.raw - layout[2] = unexpectedBetweenSpecifierAndAttributes?.raw + layout[0] = unexpectedBeforeSpecifiers?.raw + layout[1] = specifiers.raw + layout[2] = unexpectedBetweenSpecifiersAndAttributes?.raw layout[3] = attributes.raw layout[4] = unexpectedBetweenAttributesAndBaseType?.raw layout[5] = baseType.raw @@ -1617,15 +1617,15 @@ public struct RawAttributedTypeSyntax: RawTypeSyntaxNodeProtocol { self.init(unchecked: raw) } - public var unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? { + public var unexpectedBeforeSpecifiers: RawUnexpectedNodesSyntax? { layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var specifier: RawTokenSyntax? { - layoutView.children[1].map(RawTokenSyntax.init(raw:)) + public var specifiers: RawTypeSpecifierListSyntax { + layoutView.children[1].map(RawTypeSpecifierListSyntax.init(raw:))! } - public var unexpectedBetweenSpecifierAndAttributes: RawUnexpectedNodesSyntax? { + public var unexpectedBetweenSpecifiersAndAttributes: RawUnexpectedNodesSyntax? { layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift index e1c93d0e7f5..67a1eab6807 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift @@ -1408,6 +1408,114 @@ public struct RawTypeInitializerClauseSyntax: RawSyntaxNodeProtocol { } } +@_spi(RawSyntax) +public struct RawTypeSpecifierListSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .typeSpecifierList + } + + 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(elements: [RawTypeSpecifierSyntax], arena: __shared SyntaxArena) { + let raw = RawSyntax.makeLayout( + kind: .typeSpecifierList, uninitializedCount: elements.count, arena: arena) { layout in + guard var ptr = layout.baseAddress else { + return + } + for elem in elements { + ptr.initialize(to: elem.raw) + ptr += 1 + } + } + self.init(unchecked: raw) + } + + public var elements: [RawTypeSpecifierSyntax] { + layoutView.children.map { + RawTypeSpecifierSyntax(raw: $0!) + } + } +} + +@_spi(RawSyntax) +public struct RawTypeSpecifierSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .typeSpecifier + } + + 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( + _ unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? = nil, + specifier: RawTokenSyntax, + _ unexpectedAfterSpecifier: RawUnexpectedNodesSyntax? = nil, + arena: __shared SyntaxArena + ) { + let raw = RawSyntax.makeLayout( + kind: .typeSpecifier, uninitializedCount: 3, arena: arena) { layout in + layout.initialize(repeating: nil) + layout[0] = unexpectedBeforeSpecifier?.raw + layout[1] = specifier.raw + layout[2] = unexpectedAfterSpecifier?.raw + } + self.init(unchecked: raw) + } + + public var unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? { + layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var specifier: RawTokenSyntax { + layoutView.children[1].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedAfterSpecifier: RawUnexpectedNodesSyntax? { + layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + } +} + @_spi(RawSyntax) public struct RawTypeSyntax: RawTypeSyntaxNodeProtocol { @_spi(RawSyntax) diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index 3f7f0d0f5c3..9b74eb0d3f1 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -379,17 +379,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .attributedType: assert(layout.count == 7) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax?.self, tokenChoices: [ - .keyword("inout"), - .keyword("__shared"), - .keyword("__owned"), - .keyword("isolated"), - .keyword("_const"), - .keyword("borrowing"), - .keyword("consuming"), - .keyword("transferring"), - .keyword("_resultDependsOn") - ])) + assertNoError(kind, 1, verify(layout[1], as: RawTypeSpecifierListSyntax.self)) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawAttributeListSyntax.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -2619,6 +2609,25 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTypeSyntax.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) + case .typeSpecifierList: + for (index, element) in layout.enumerated() { + assertNoError(kind, index, verify(element, as: RawTypeSpecifierSyntax.self)) + } + case .typeSpecifier: + assert(layout.count == 3) + assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ + .keyword("inout"), + .keyword("__shared"), + .keyword("__owned"), + .keyword("isolated"), + .keyword("_const"), + .keyword("borrowing"), + .keyword("consuming"), + .keyword("transferring"), + .keyword("_resultDependsOn") + ])) + assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) case .unavailableFromAsyncAttributeArguments: assert(layout.count == 7) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index 775bd6b94ee..a04d5a7bc55 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -3257,7 +3257,7 @@ public struct AttributeSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodePr /// ### Children /// -/// - `specifier`: (`inout` | `__shared` | `__owned` | `isolated` | `_const` | `borrowing` | `consuming` | `transferring` | `_resultDependsOn`)? +/// - `specifiers`: ``TypeSpecifierListSyntax`` /// - `attributes`: ``AttributeListSyntax`` /// - `baseType`: ``TypeSyntax`` public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTypeSyntaxNodeProtocol { @@ -3275,9 +3275,9 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. public init( leadingTrivia: Trivia? = nil, - _ unexpectedBeforeSpecifier: UnexpectedNodesSyntax? = nil, - specifier: TokenSyntax? = nil, - _ unexpectedBetweenSpecifierAndAttributes: UnexpectedNodesSyntax? = nil, + _ unexpectedBeforeSpecifiers: UnexpectedNodesSyntax? = nil, + specifiers: TypeSpecifierListSyntax = [], + _ unexpectedBetweenSpecifiersAndAttributes: UnexpectedNodesSyntax? = nil, attributes: AttributeListSyntax = [], _ unexpectedBetweenAttributesAndBaseType: UnexpectedNodesSyntax? = nil, baseType: some TypeSyntaxProtocol, @@ -3288,18 +3288,18 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp // Extend the lifetime of all parameters so their arenas don't get destroyed // before they can be added as children of the new arena. self = withExtendedLifetime((SyntaxArena(), ( - unexpectedBeforeSpecifier, - specifier, - unexpectedBetweenSpecifierAndAttributes, + unexpectedBeforeSpecifiers, + specifiers, + unexpectedBetweenSpecifiersAndAttributes, attributes, unexpectedBetweenAttributesAndBaseType, baseType, unexpectedAfterBaseType ))) { (arena, _) in let layout: [RawSyntax?] = [ - unexpectedBeforeSpecifier?.raw, - specifier?.raw, - unexpectedBetweenSpecifierAndAttributes?.raw, + unexpectedBeforeSpecifiers?.raw, + specifiers.raw, + unexpectedBetweenSpecifiersAndAttributes?.raw, attributes.raw, unexpectedBetweenAttributesAndBaseType?.raw, baseType.raw, @@ -3317,7 +3317,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp } } - public var unexpectedBeforeSpecifier: UnexpectedNodesSyntax? { + public var unexpectedBeforeSpecifiers: UnexpectedNodesSyntax? { get { return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) } @@ -3326,28 +3326,43 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp } } - /// ### Tokens - /// - /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: - /// - `inout` - /// - `__shared` - /// - `__owned` - /// - `isolated` - /// - `_const` - /// - `borrowing` - /// - `consuming` - /// - `transferring` - /// - `_resultDependsOn` - public var specifier: TokenSyntax? { + public var specifiers: TypeSpecifierListSyntax { get { - return Syntax(self).child(at: 1)?.cast(TokenSyntax.self) + return Syntax(self).child(at: 1)!.cast(TypeSpecifierListSyntax.self) } set(value) { self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(AttributedTypeSyntax.self) } } - public var unexpectedBetweenSpecifierAndAttributes: UnexpectedNodesSyntax? { + /// Adds the provided `element` to the node's `specifiers` + /// collection. + /// + /// - param element: The new `Specifier` to add to the node's + /// `specifiers` collection. + /// - returns: A copy of the receiver with the provided `Specifier` + /// appended to its `specifiers` collection. + @available(*, deprecated, message: "Use node.specifiers.append(newElement) instead") + public func addSpecifier(_ element: TypeSpecifierSyntax) -> AttributedTypeSyntax { + var collection: RawSyntax + let arena = SyntaxArena() + if let col = raw.layoutView!.children[1] { + collection = col.layoutView!.appending(element.raw, arena: arena) + } else { + collection = RawSyntax.makeLayout(kind: SyntaxKind.typeSpecifierList, + from: [element.raw], arena: arena) + } + return Syntax(self) + .replacingChild( + at: 1, + with: collection, + rawNodeArena: arena, + allocationArena: arena + ) + .cast(AttributedTypeSyntax.self) + } + + public var unexpectedBetweenSpecifiersAndAttributes: UnexpectedNodesSyntax? { get { return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) } @@ -3421,9 +3436,9 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp public static var structure: SyntaxNodeStructure { return .layout([ - \Self.unexpectedBeforeSpecifier, - \Self.specifier, - \Self.unexpectedBetweenSpecifierAndAttributes, + \Self.unexpectedBeforeSpecifiers, + \Self.specifiers, + \Self.unexpectedBetweenSpecifiersAndAttributes, \Self.attributes, \Self.unexpectedBetweenAttributesAndBaseType, \Self.baseType, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index e9e1eb7a67a..811b8eba2fd 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -2588,6 +2588,98 @@ public struct TypeInitializerClauseSyntax: SyntaxProtocol, SyntaxHashable, _Leaf } } +// MARK: - TypeSpecifierSyntax + +/// A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming` +/// +/// ### Children +/// +/// - `specifier`: (`inout` | `__shared` | `__owned` | `isolated` | `_const` | `borrowing` | `consuming` | `transferring` | `_resultDependsOn`) +/// +/// ### Contained in +/// +/// - ``TypeSpecifierListSyntax`` +public struct TypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .typeSpecifier else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + /// - Parameters: + /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforeSpecifier: UnexpectedNodesSyntax? = nil, + specifier: TokenSyntax, + _ unexpectedAfterSpecifier: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + + ) { + // Extend the lifetime of all parameters so their arenas don't get destroyed + // before they can be added as children of the new arena. + self = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeSpecifier, specifier, unexpectedAfterSpecifier))) { (arena, _) in + let layout: [RawSyntax?] = [unexpectedBeforeSpecifier?.raw, specifier.raw, unexpectedAfterSpecifier?.raw] + let raw = RawSyntax.makeLayout( + kind: SyntaxKind.typeSpecifier, + from: layout, + arena: arena, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia + + ) + return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) + } + } + + public var unexpectedBeforeSpecifier: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(TypeSpecifierSyntax.self) + } + } + + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: + /// - `inout` + /// - `__shared` + /// - `__owned` + /// - `isolated` + /// - `_const` + /// - `borrowing` + /// - `consuming` + /// - `transferring` + /// - `_resultDependsOn` + public var specifier: TokenSyntax { + get { + return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(TypeSpecifierSyntax.self) + } + } + + public var unexpectedAfterSpecifier: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(TypeSpecifierSyntax.self) + } + } + + public static var structure: SyntaxNodeStructure { + return .layout([\Self.unexpectedBeforeSpecifier, \Self.specifier, \Self.unexpectedAfterSpecifier]) + } +} + // MARK: - UnavailableFromAsyncAttributeArgumentsSyntax /// The arguments for the '@_unavailableFromAsync' attribute diff --git a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift index a881f9ed0d4..7287117a327 100644 --- a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift +++ b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift @@ -668,6 +668,19 @@ public extension TupleTypeElementListSyntax { } } +// MARK: - TypeSpecifierListBuilder + +@resultBuilder +public struct TypeSpecifierListBuilder: ListBuilder { + public typealias FinalResult = TypeSpecifierListSyntax +} + +public extension TypeSpecifierListSyntax { + init(@TypeSpecifierListBuilder itemsBuilder: () throws -> TypeSpecifierListSyntax) rethrows { + self = try itemsBuilder() + } +} + // MARK: - UnexpectedNodesBuilder @resultBuilder diff --git a/Tests/SwiftParserTest/TypeTests.swift b/Tests/SwiftParserTest/TypeTests.swift index 99eee98e49d..db1ccb066c5 100644 --- a/Tests/SwiftParserTest/TypeTests.swift +++ b/Tests/SwiftParserTest/TypeTests.swift @@ -320,4 +320,9 @@ final class TypeTests: ParserTestCase { "[() throws(PosixError) -> Void]()" ) } + + func testMultipleTypeSpecifiers() { + assertParse("func foo1(_ a: _const borrowing String) {}") + assertParse("func foo2(_ a: borrowing _const String) {}") + } } diff --git a/Tests/SwiftParserTest/translated/InvalidTests.swift b/Tests/SwiftParserTest/translated/InvalidTests.swift index ac546ab6d90..bc03c8f92f6 100644 --- a/Tests/SwiftParserTest/translated/InvalidTests.swift +++ b/Tests/SwiftParserTest/translated/InvalidTests.swift @@ -359,15 +359,10 @@ final class InvalidTests: ParserTestCase { } func testInvalid16a() { - // https://github.com/apple/swift/issues/43591 - // Two inout crash compiler assertParse( """ func f1_43591(a : inout 1️⃣inout Int) {} - """, - diagnostics: [ - DiagnosticSpec(message: "unexpected 'inout' keyword in type") - ] + """ ) } @@ -379,7 +374,7 @@ final class InvalidTests: ParserTestCase { diagnostics: [ DiagnosticSpec(message: "'inout inout' before a parameter name is not allowed", fixIts: ["move 'inout inout' in front of type"]) ], - fixedSource: "func f2_43591(b: inout Int) {}" + fixedSource: "func f2_43591(b: inout inout Int) {}" ) } @@ -400,10 +395,10 @@ final class InvalidTests: ParserTestCase { func f4_43591(1️⃣inout x: inout String) {} """, diagnostics: [ - DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["remove redundant 'inout'"]) + DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["move 'inout' in front of type"]) ], fixedSource: """ - func f4_43591(x: inout String) {} + func f4_43591(x: inout inout String) {} """ ) } @@ -414,10 +409,10 @@ final class InvalidTests: ParserTestCase { func f5_43591(1️⃣inout i: inout Int) {} """, diagnostics: [ - DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["remove redundant 'inout'"]) + DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["move 'inout' in front of type"]) ], fixedSource: """ - func f5_43591(i: inout Int) {} + func f5_43591(i: inout inout Int) {} """ ) } @@ -456,10 +451,10 @@ final class InvalidTests: ParserTestCase { func f4_43591(1️⃣inout x: inout String) {} """, diagnostics: [ - DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["remove redundant 'inout'"]) + DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["move 'inout' in front of type"]) ], fixedSource: """ - func f4_43591(x: inout String) {} + func f4_43591(x: inout inout String) {} """ ) } @@ -470,9 +465,9 @@ final class InvalidTests: ParserTestCase { func f5_43591(1️⃣inout i: inout Int) {} """, diagnostics: [ - DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["remove redundant 'inout'"]) + DiagnosticSpec(message: "'inout' before a parameter name is not allowed", fixIts: ["move 'inout' in front of type"]) ], - fixedSource: "func f5_43591(i: inout Int) {}" + fixedSource: "func f5_43591(i: inout inout Int) {}" ) } From b32df0ee1af3989b466286f59fce285f8ec57d6f Mon Sep 17 00:00:00 2001 From: Alex Hoppen <ahoppen@apple.com> Date: Sun, 21 Jan 2024 19:21:27 -0800 Subject: [PATCH 2/4] Replace the manually maintained `TokenSpecSet` `TypeSpecifier` by the generated `TypeSpecifierSyntax.SpecifierOptions` The two `TokenSpecSet`s had already diverged. Instead of manually maintaining the `TypeSpecifier` spec set, we should allow all keywors specified in the syntax tree definition. --- .../Sources/SyntaxSupport/Child.swift | 9 + .../Sources/SyntaxSupport/TypeNodes.swift | 69 +- .../swiftparser/ParserTokenSpecSetFile.swift | 11 + Sources/SwiftParser/Parameters.swift | 2 +- Sources/SwiftParser/Patterns.swift | 2 +- Sources/SwiftParser/TokenSpecSet.swift | 46 - Sources/SwiftParser/Types.swift | 4 +- .../generated/Parser+TokenSpecSet.swift | 845 +++++++++++++++++- .../ParseDiagnosticsGenerator.swift | 4 +- .../generated/syntaxNodes/SyntaxNodesAB.swift | 6 + .../syntaxNodes/SyntaxNodesTUVWXYZ.swift | 3 + 11 files changed, 914 insertions(+), 87 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/Child.swift b/CodeGeneration/Sources/SyntaxSupport/Child.swift index 6cc585241a9..45afefc632c 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Child.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Child.swift @@ -24,6 +24,15 @@ public enum TokenChoice: Equatable { case .token: return false } } + + public var varOrCaseName: TokenSyntax { + switch self { + case .keyword(let keyword): + return keyword.spec.varOrCaseName + case .token(let token): + return token.spec.varOrCaseName + } + } } public enum ChildKind { diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index 623ee20e563..4bf658fe5f3 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -34,36 +34,6 @@ public let TYPE_NODES: [Node] = [ ] ), - Node( - kind: .typeSpecifier, - base: .syntax, - nameForDiagnostics: nil, - documentation: "A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming`", - children: [ - Child( - name: "specifier", - kind: .token(choices: [ - .keyword(.inout), - .keyword(.__shared), - .keyword(.__owned), - .keyword(.isolated), - .keyword(._const), - .keyword(.borrowing), - .keyword(.consuming), - .keyword(.transferring), - .keyword(._resultDependsOn), - ]) - ) - ] - ), - - Node( - kind: .typeSpecifierList, - base: .syntaxCollection, - nameForDiagnostics: nil, - elementChoices: [.typeSpecifier] - ), - Node( kind: .attributedType, base: .type, @@ -74,15 +44,18 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "specifiers", - kind: .collection(kind: .typeSpecifierList, collectionElementName: "Specifier", defaultsToEmpty: true) + kind: .collection(kind: .typeSpecifierList, collectionElementName: "Specifier", defaultsToEmpty: true), + documentation: "A list of specifiers that can be attached to the type, such as `inout`, `isolated`, or `consuming`." ), Child( name: "attributes", - kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true) + kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true), + documentation: "A list of attributes that can be attached to the type, such as `@escaping`." ), Child( name: "baseType", - kind: .node(kind: .type) + kind: .node(kind: .type), + documentation: "The type to with the specifiers and attributes are applied." ), ] ), @@ -522,4 +495,34 @@ public let TYPE_NODES: [Node] = [ ] ), + Node( + kind: .typeSpecifier, + base: .syntax, + nameForDiagnostics: nil, + documentation: "A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming`", + children: [ + Child( + name: "specifier", + kind: .token(choices: [ + .keyword(.inout), + .keyword(.__shared), + .keyword(.__owned), + .keyword(.isolated), + .keyword(._const), + .keyword(.borrowing), + .keyword(.consuming), + .keyword(.transferring), + .keyword(._resultDependsOn), + ]), + documentation: "The specifier token that's attached to the type." + ) + ] + ), + + Node( + kind: .typeSpecifierList, + base: .syntaxCollection, + nameForDiagnostics: nil, + elementChoices: [.typeSpecifier] + ), ] diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift index 25d13500507..3856c25ad6a 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift @@ -83,6 +83,17 @@ let parserTokenSpecSetFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } } + try InitializerDeclSyntax("public init?(token: TokenSyntax)") { + try SwitchExprSyntax("switch token") { + for choice in choices { + SwitchCaseSyntax( + "case TokenSpec(.\(choice.varOrCaseName)): self = .\(choice.varOrCaseName)" + ) + } + SwitchCaseSyntax("default: return nil") + } + } + try VariableDeclSyntax("var spec: TokenSpec") { try SwitchExprSyntax("switch self") { for choice in choices { diff --git a/Sources/SwiftParser/Parameters.swift b/Sources/SwiftParser/Parameters.swift index 7b780febdc8..4273a99d906 100644 --- a/Sources/SwiftParser/Parameters.swift +++ b/Sources/SwiftParser/Parameters.swift @@ -261,7 +261,7 @@ extension Parser { mutating func parseMisplacedSpecifiers() -> [RawTokenSyntax] { var misplacedSpecifiers: [RawTokenSyntax] = [] if self.withLookahead({ !$0.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: false) }) { - while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: TypeSpecifier.self) { + while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) { misplacedSpecifiers.append(specifier) } } diff --git a/Sources/SwiftParser/Patterns.swift b/Sources/SwiftParser/Patterns.swift index c606f0875ba..e5378632257 100644 --- a/Sources/SwiftParser/Patterns.swift +++ b/Sources/SwiftParser/Patterns.swift @@ -340,7 +340,7 @@ extension Parser.Lookahead { mutating func startsParameterName(isClosure: Bool, allowMisplacedSpecifierRecovery: Bool) -> Bool { if allowMisplacedSpecifierRecovery { while canHaveParameterSpecifier, - self.consume(ifAnyIn: TypeSpecifier.self) != nil + self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) != nil {} } diff --git a/Sources/SwiftParser/TokenSpecSet.swift b/Sources/SwiftParser/TokenSpecSet.swift index d2889a539c9..408b05bc82b 100644 --- a/Sources/SwiftParser/TokenSpecSet.swift +++ b/Sources/SwiftParser/TokenSpecSet.swift @@ -691,52 +691,6 @@ enum TypeAttribute: TokenSpecSet { } } -@_spi(Diagnostics) -public enum TypeSpecifier: TokenSpecSet { - case `inout` - case owned - case shared - case borrowing - case consuming - case transferring - - init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { - switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.inout): self = .inout - case TokenSpec(.__owned): self = .owned - case TokenSpec(.__shared): self = .shared - case TokenSpec(.consuming): self = .consuming - case TokenSpec(.borrowing): self = .borrowing - case TokenSpec(.transferring): self = .transferring - default: return nil - } - } - - @_spi(Diagnostics) - public init?(token: TokenSyntax) { - switch token { - case TokenSpec(.inout): self = .inout - case TokenSpec(.__owned): self = .owned - case TokenSpec(.__shared): self = .shared - case TokenSpec(.consuming): self = .shared - case TokenSpec(.borrowing): self = .shared - case TokenSpec(.transferring): self = .transferring - default: return nil - } - } - - var spec: TokenSpec { - switch self { - case .inout: return .keyword(.inout) - case .owned: return .keyword(.__owned) - case .shared: return .keyword(.__shared) - case .borrowing: return .keyword(.borrowing) - case .consuming: return .keyword(.consuming) - case .transferring: return .keyword(.transferring) - } - } -} - // MARK: Expression start enum ExpressionModifierKeyword: TokenSpecSet { diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index 3080d8b1be1..b62267ec515 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -468,7 +468,7 @@ extension Parser { var misplacedSpecifiers: [RawTokenSyntax] = [] if self.withLookahead({ $0.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: true) }) { while canHaveParameterSpecifier, - let specifier = self.consume(ifAnyIn: TypeSpecifier.self) + let specifier = self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) { misplacedSpecifiers.append(specifier) } @@ -623,7 +623,7 @@ extension Parser.Lookahead { var specifierProgress = LoopProgressCondition() // TODO: Can we model isolated/_const so that they're specified in both canParse* and parse*? while canHaveParameterSpecifier, - self.at(anyIn: TypeSpecifier.self) != nil || self.at(.keyword(.isolated)) || self.at(.keyword(._const)), + self.at(anyIn: TypeSpecifierSyntax.SpecifierOptions.self) != nil || self.at(.keyword(.isolated)) || self.at(.keyword(._const)), self.hasProgressed(&specifierProgress) { self.consumeAnyToken() diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index 393e3df7c02..2f060d0b1a5 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -68,6 +68,39 @@ extension AccessorDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.get): + self = .get + case TokenSpec(.set): + self = .set + case TokenSpec(.didSet): + self = .didSet + case TokenSpec(.willSet): + self = .willSet + case TokenSpec(.unsafeAddress): + self = .unsafeAddress + case TokenSpec(.addressWithOwner): + self = .addressWithOwner + case TokenSpec(.addressWithNativeOwner): + self = .addressWithNativeOwner + case TokenSpec(.unsafeMutableAddress): + self = .unsafeMutableAddress + case TokenSpec(.mutableAddressWithOwner): + self = .mutableAddressWithOwner + case TokenSpec(.mutableAddressWithNativeOwner): + self = .mutableAddressWithNativeOwner + case TokenSpec(._read): + self = ._read + case TokenSpec(._modify): + self = ._modify + case TokenSpec(.`init`): + self = .`init` + default: + return nil + } + } + var spec: TokenSpec { switch self { case .get: @@ -153,6 +186,17 @@ extension AsExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.postfixQuestionMark): + self = .postfixQuestionMark + case TokenSpec(.exclamationMark): + self = .exclamationMark + default: + return nil + } + } + var spec: TokenSpec { switch self { case .postfixQuestionMark: @@ -194,6 +238,17 @@ extension AvailabilityConditionSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.poundAvailable): + self = .poundAvailable + case TokenSpec(.poundUnavailable): + self = .poundUnavailable + default: + return nil + } + } + var spec: TokenSpec { switch self { case .poundAvailable: @@ -244,6 +299,23 @@ extension AvailabilityLabeledArgumentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.message): + self = .message + case TokenSpec(.renamed): + self = .renamed + case TokenSpec(.introduced): + self = .introduced + case TokenSpec(.obsoleted): + self = .obsoleted + case TokenSpec(.deprecated): + self = .deprecated + default: + return nil + } + } + var spec: TokenSpec { switch self { case .message: @@ -297,6 +369,17 @@ extension BooleanLiteralExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.true): + self = .true + case TokenSpec(.false): + self = .false + default: + return nil + } + } + var spec: TokenSpec { switch self { case .true: @@ -338,6 +421,17 @@ extension CanImportVersionInfoSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(._version): + self = ._version + case TokenSpec(._underlyingVersion): + self = ._underlyingVersion + default: + return nil + } + } + var spec: TokenSpec { switch self { case ._version: @@ -379,6 +473,17 @@ extension ClosureCaptureSpecifierSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.weak): + self = .weak + case TokenSpec(.unowned): + self = .unowned + default: + return nil + } + } + var spec: TokenSpec { switch self { case .weak: @@ -420,6 +525,17 @@ extension ClosureCaptureSpecifierSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.safe): + self = .safe + case TokenSpec(.unsafe): + self = .unsafe + default: + return nil + } + } + var spec: TokenSpec { switch self { case .safe: @@ -461,6 +577,17 @@ extension ClosureParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -502,6 +629,17 @@ extension ClosureParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -543,6 +681,17 @@ extension ClosureShorthandParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -584,6 +733,17 @@ extension ConsumeExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(._move): + self = ._move + case TokenSpec(.consume): + self = .consume + default: + return nil + } + } + var spec: TokenSpec { switch self { case ._move: @@ -732,6 +892,87 @@ extension DeclModifierSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.__consuming): + self = .__consuming + case TokenSpec(.__setter_access): + self = .__setter_access + case TokenSpec(._const): + self = ._const + case TokenSpec(._local): + self = ._local + case TokenSpec(.actor): + self = .actor + case TokenSpec(.async): + self = .async + case TokenSpec(.borrowing): + self = .borrowing + case TokenSpec(.class): + self = .class + case TokenSpec(.consuming): + self = .consuming + case TokenSpec(.convenience): + self = .convenience + case TokenSpec(.distributed): + self = .distributed + case TokenSpec(.dynamic): + self = .dynamic + case TokenSpec(.fileprivate): + self = .fileprivate + case TokenSpec(.final): + self = .final + case TokenSpec(.indirect): + self = .indirect + case TokenSpec(.infix): + self = .infix + case TokenSpec(.internal): + self = .internal + case TokenSpec(.isolated): + self = .isolated + case TokenSpec(.lazy): + self = .lazy + case TokenSpec(.mutating): + self = .mutating + case TokenSpec(.nonisolated): + self = .nonisolated + case TokenSpec(.nonmutating): + self = .nonmutating + case TokenSpec(.open): + self = .open + case TokenSpec(.optional): + self = .optional + case TokenSpec(.override): + self = .override + case TokenSpec(.package): + self = .package + case TokenSpec(.postfix): + self = .postfix + case TokenSpec(.prefix): + self = .prefix + case TokenSpec(.private): + self = .private + case TokenSpec(.public): + self = .public + case TokenSpec(.reasync): + self = .reasync + case TokenSpec(._resultDependsOnSelf): + self = ._resultDependsOnSelf + case TokenSpec(.required): + self = .required + case TokenSpec(.static): + self = .static + case TokenSpec(.transferring): + self = .transferring + case TokenSpec(.unowned): + self = .unowned + case TokenSpec(.weak): + self = .weak + default: + return nil + } + } + var spec: TokenSpec { switch self { case .__consuming: @@ -934,6 +1175,27 @@ extension DeclReferenceExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.self): + self = .self + case TokenSpec(.Self): + self = .Self + case TokenSpec(.`init`): + self = .`init` + case TokenSpec(.dollarIdentifier): + self = .dollarIdentifier + case TokenSpec(.binaryOperator): + self = .binaryOperator + case TokenSpec(.integerLiteral): + self = .integerLiteral + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1003,6 +1265,17 @@ extension DerivativeAttributeArgumentsSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.get): + self = .get + case TokenSpec(.set): + self = .set + default: + return nil + } + } + var spec: TokenSpec { switch self { case .get: @@ -1047,6 +1320,19 @@ extension DifferentiabilityArgumentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.integerLiteral): + self = .integerLiteral + case TokenSpec(.self): + self = .self + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1095,6 +1381,19 @@ extension DifferentiableAttributeArgumentsSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(._forward): + self = ._forward + case TokenSpec(.reverse): + self = .reverse + case TokenSpec(._linear): + self = ._linear + default: + return nil + } + } + var spec: TokenSpec { switch self { case ._forward: @@ -1140,6 +1439,17 @@ extension DocumentationAttributeArgumentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.visibility): + self = .visibility + case TokenSpec(.metadata): + self = .metadata + default: + return nil + } + } + var spec: TokenSpec { switch self { case .visibility: @@ -1181,6 +1491,17 @@ extension EnumCaseParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1222,6 +1543,17 @@ extension EnumCaseParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1269,6 +1601,21 @@ extension FunctionDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.binaryOperator): + self = .binaryOperator + case TokenSpec(.prefixOperator): + self = .prefixOperator + case TokenSpec(.postfixOperator): + self = .postfixOperator + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1318,6 +1665,17 @@ extension FunctionEffectSpecifiersSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.async): + self = .async + case TokenSpec(.reasync): + self = .reasync + default: + return nil + } + } + var spec: TokenSpec { switch self { case .async: @@ -1359,6 +1717,17 @@ extension FunctionParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1400,6 +1769,17 @@ extension FunctionParameterSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1450,6 +1830,19 @@ extension IdentifierPatternSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.self): + self = .self + case TokenSpec(.`init`): + self = .`init` + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1509,6 +1902,21 @@ extension IdentifierTypeSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.Self): + self = .Self + case TokenSpec(.Any): + self = .Any + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1561,6 +1969,19 @@ extension IfConfigClauseSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.poundIf): + self = .poundIf + case TokenSpec(.poundElseif): + self = .poundElseif + case TokenSpec(.poundElse): + self = .poundElse + default: + return nil + } + } + var spec: TokenSpec { switch self { case .poundIf: @@ -1627,6 +2048,31 @@ extension ImportDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.typealias): + self = .typealias + case TokenSpec(.struct): + self = .struct + case TokenSpec(.class): + self = .class + case TokenSpec(.enum): + self = .enum + case TokenSpec(.protocol): + self = .protocol + case TokenSpec(.var): + self = .var + case TokenSpec(.let): + self = .let + case TokenSpec(.func): + self = .func + case TokenSpec(.inout): + self = .inout + default: + return nil + } + } + var spec: TokenSpec { switch self { case .typealias: @@ -1702,6 +2148,21 @@ extension ImportPathComponentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.binaryOperator): + self = .binaryOperator + case TokenSpec(.prefixOperator): + self = .prefixOperator + case TokenSpec(.postfixOperator): + self = .postfixOperator + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1751,6 +2212,17 @@ extension InitializerDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.postfixQuestionMark): + self = .postfixQuestionMark + case TokenSpec(.exclamationMark): + self = .exclamationMark + default: + return nil + } + } + var spec: TokenSpec { switch self { case .postfixQuestionMark: @@ -1792,6 +2264,17 @@ extension KeyPathOptionalComponentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.postfixQuestionMark): + self = .postfixQuestionMark + case TokenSpec(.exclamationMark): + self = .exclamationMark + default: + return nil + } + } + var spec: TokenSpec { switch self { case .postfixQuestionMark: @@ -1833,6 +2316,17 @@ extension LabeledExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1886,6 +2380,25 @@ extension LabeledSpecializeArgumentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.target): + self = .target + case TokenSpec(.availability): + self = .availability + case TokenSpec(.exported): + self = .exported + case TokenSpec(.kind): + self = .kind + case TokenSpec(.spi): + self = .spi + case TokenSpec(.spiModule): + self = .spiModule + default: + return nil + } + } + var spec: TokenSpec { switch self { case .target: @@ -1939,8 +2452,33 @@ extension LayoutRequirementSyntax { case _BridgeObject case _TrivialStride - init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { - switch PrepareForKeywordMatch(lexeme) { + init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(._Trivial): + self = ._Trivial + case TokenSpec(._TrivialAtMost): + self = ._TrivialAtMost + case TokenSpec(._UnknownLayout): + self = ._UnknownLayout + case TokenSpec(._RefCountedObject): + self = ._RefCountedObject + case TokenSpec(._NativeRefCountedObject): + self = ._NativeRefCountedObject + case TokenSpec(._Class): + self = ._Class + case TokenSpec(._NativeClass): + self = ._NativeClass + case TokenSpec(._BridgeObject): + self = ._BridgeObject + case TokenSpec(._TrivialStride): + self = ._TrivialStride + default: + return nil + } + } + + public init?(token: TokenSyntax) { + switch token { case TokenSpec(._Trivial): self = ._Trivial case TokenSpec(._TrivialAtMost): @@ -2033,6 +2571,17 @@ extension MemberTypeSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.self): + self = .self + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -2074,6 +2623,17 @@ extension MetatypeTypeSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.Type): + self = .Type + case TokenSpec(.Protocol): + self = .Protocol + default: + return nil + } + } + var spec: TokenSpec { switch self { case .Type: @@ -2115,6 +2675,17 @@ extension MultipleTrailingClosureElementSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -2159,6 +2730,19 @@ extension OperatorDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.prefix): + self = .prefix + case TokenSpec(.postfix): + self = .postfix + case TokenSpec(.infix): + self = .infix + default: + return nil + } + } + var spec: TokenSpec { switch self { case .prefix: @@ -2207,6 +2791,19 @@ extension OperatorDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.binaryOperator): + self = .binaryOperator + case TokenSpec(.prefixOperator): + self = .prefixOperator + case TokenSpec(.postfixOperator): + self = .postfixOperator + default: + return nil + } + } + var spec: TokenSpec { switch self { case .binaryOperator: @@ -2267,6 +2864,25 @@ extension OptionalBindingConditionSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.let): + self = .let + case TokenSpec(.var): + self = .var + case TokenSpec(.inout): + self = .inout + case TokenSpec(._mutating): + self = ._mutating + case TokenSpec(._borrowing): + self = ._borrowing + case TokenSpec(._consuming): + self = ._consuming + default: + return nil + } + } + var spec: TokenSpec { switch self { case .let: @@ -2324,6 +2940,17 @@ extension PrecedenceGroupAssignmentSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.true): + self = .true + case TokenSpec(.false): + self = .false + default: + return nil + } + } + var spec: TokenSpec { switch self { case .true: @@ -2368,6 +2995,19 @@ extension PrecedenceGroupAssociativitySyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.left): + self = .left + case TokenSpec(.right): + self = .right + case TokenSpec(.none): + self = .none + default: + return nil + } + } + var spec: TokenSpec { switch self { case .left: @@ -2413,6 +3053,17 @@ extension PrecedenceGroupRelationSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.higherThan): + self = .higherThan + case TokenSpec(.lowerThan): + self = .lowerThan + default: + return nil + } + } + var spec: TokenSpec { switch self { case .higherThan: @@ -2457,6 +3108,19 @@ extension SameTypeRequirementSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.binaryOperator): + self = .binaryOperator + case TokenSpec(.prefixOperator): + self = .prefixOperator + case TokenSpec(.postfixOperator): + self = .postfixOperator + default: + return nil + } + } + var spec: TokenSpec { switch self { case .binaryOperator: @@ -2502,6 +3166,17 @@ extension SimpleStringLiteralExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.stringQuote): + self = .stringQuote + case TokenSpec(.multilineStringQuote): + self = .multilineStringQuote + default: + return nil + } + } + var spec: TokenSpec { switch self { case .stringQuote: @@ -2543,6 +3218,17 @@ extension SimpleStringLiteralExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.stringQuote): + self = .stringQuote + case TokenSpec(.multilineStringQuote): + self = .multilineStringQuote + default: + return nil + } + } + var spec: TokenSpec { switch self { case .stringQuote: @@ -2584,6 +3270,17 @@ extension SomeOrAnyTypeSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.some): + self = .some + case TokenSpec(.any): + self = .any + default: + return nil + } + } + var spec: TokenSpec { switch self { case .some: @@ -2628,6 +3325,19 @@ extension StringLiteralExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.stringQuote): + self = .stringQuote + case TokenSpec(.multilineStringQuote): + self = .multilineStringQuote + case TokenSpec(.singleQuote): + self = .singleQuote + default: + return nil + } + } + var spec: TokenSpec { switch self { case .stringQuote: @@ -2676,6 +3386,19 @@ extension StringLiteralExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.stringQuote): + self = .stringQuote + case TokenSpec(.multilineStringQuote): + self = .multilineStringQuote + case TokenSpec(.singleQuote): + self = .singleQuote + default: + return nil + } + } + var spec: TokenSpec { switch self { case .stringQuote: @@ -2721,6 +3444,17 @@ extension ThrowsClauseSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.throws): + self = .throws + case TokenSpec(.rethrows): + self = .rethrows + default: + return nil + } + } + var spec: TokenSpec { switch self { case .throws: @@ -2762,6 +3496,17 @@ extension TryExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.postfixQuestionMark): + self = .postfixQuestionMark + case TokenSpec(.exclamationMark): + self = .exclamationMark + default: + return nil + } + } + var spec: TokenSpec { switch self { case .postfixQuestionMark: @@ -2803,6 +3548,17 @@ extension TupleTypeElementSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -2844,6 +3600,17 @@ extension TupleTypeElementSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.wildcard): + self = .wildcard + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -2908,6 +3675,31 @@ extension TypeSpecifierSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.inout): + self = .inout + case TokenSpec(.__shared): + self = .__shared + case TokenSpec(.__owned): + self = .__owned + case TokenSpec(.isolated): + self = .isolated + case TokenSpec(._const): + self = ._const + case TokenSpec(.borrowing): + self = .borrowing + case TokenSpec(.consuming): + self = .consuming + case TokenSpec(.transferring): + self = .transferring + case TokenSpec(._resultDependsOn): + self = ._resultDependsOn + default: + return nil + } + } + var spec: TokenSpec { switch self { case .inout: @@ -2977,6 +3769,17 @@ extension UnresolvedAsExprSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.postfixQuestionMark): + self = .postfixQuestionMark + case TokenSpec(.exclamationMark): + self = .exclamationMark + default: + return nil + } + } + var spec: TokenSpec { switch self { case .postfixQuestionMark: @@ -3033,6 +3836,25 @@ extension ValueBindingPatternSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.let): + self = .let + case TokenSpec(.var): + self = .var + case TokenSpec(.inout): + self = .inout + case TokenSpec(._mutating): + self = ._mutating + case TokenSpec(._borrowing): + self = ._borrowing + case TokenSpec(._consuming): + self = ._consuming + default: + return nil + } + } + var spec: TokenSpec { switch self { case .let: @@ -3105,6 +3927,25 @@ extension VariableDeclSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.let): + self = .let + case TokenSpec(.var): + self = .var + case TokenSpec(.inout): + self = .inout + case TokenSpec(._mutating): + self = ._mutating + case TokenSpec(._borrowing): + self = ._borrowing + case TokenSpec(._consuming): + self = ._consuming + default: + return nil + } + } + var spec: TokenSpec { switch self { case .let: diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index 8b2df4d2dbf..0c4bf7db258 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -945,7 +945,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { } exchangeTokens( unexpected: node.unexpectedBetweenModifiersAndFirstName, - unexpectedTokenCondition: { TypeSpecifier(token: $0) != nil }, + unexpectedTokenCondition: { TypeSpecifierSyntax.SpecifierOptions(token: $0) != nil }, correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.map(\.specifier) ?? [], message: { SpecifierOnParameterName(misplacedSpecifiers: $0) }, moveFixIt: { MoveTokensInFrontOfTypeFixIt(movedTokens: $0) }, @@ -1742,7 +1742,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { } exchangeTokens( unexpected: node.unexpectedBetweenInoutKeywordAndFirstName, - unexpectedTokenCondition: { TypeSpecifier(token: $0) != nil }, + unexpectedTokenCondition: { TypeSpecifierSyntax.SpecifierOptions(token: $0) != nil }, correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.map(\.specifier) ?? [], message: { SpecifierOnParameterName(misplacedSpecifiers: $0) }, moveFixIt: { MoveTokensInFrontOfTypeFixIt(movedTokens: $0) }, diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index a04d5a7bc55..7b8a09d0d6e 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -3272,6 +3272,9 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp /// - Parameters: /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - specifiers: A list of specifiers that can be attached to the type, such as `inout`, `isolated`, or `consuming`. + /// - attributes: A list of attributes that can be attached to the type, such as `@escaping`. + /// - baseType: The type to with the specifiers and attributes are applied. /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. public init( leadingTrivia: Trivia? = nil, @@ -3326,6 +3329,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp } } + /// A list of specifiers that can be attached to the type, such as `inout`, `isolated`, or `consuming`. public var specifiers: TypeSpecifierListSyntax { get { return Syntax(self).child(at: 1)!.cast(TypeSpecifierListSyntax.self) @@ -3371,6 +3375,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp } } + /// A list of attributes that can be attached to the type, such as `@escaping`. public var attributes: AttributeListSyntax { get { return Syntax(self).child(at: 3)!.cast(AttributeListSyntax.self) @@ -3416,6 +3421,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp } } + /// The type to with the specifiers and attributes are applied. public var baseType: TypeSyntax { get { return Syntax(self).child(at: 5)!.cast(TypeSyntax.self) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index 811b8eba2fd..14530f55935 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -2611,6 +2611,7 @@ public struct TypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo /// - Parameters: /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - specifier: The specifier token that's attached to the type. /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. public init( leadingTrivia: Trivia? = nil, @@ -2645,6 +2646,8 @@ public struct TypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo } } + /// The specifier token that's attached to the type. + /// /// ### Tokens /// /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: From ea71e1eb2373b059322db8ae4092f8051f650511 Mon Sep 17 00:00:00 2001 From: Alex Hoppen <ahoppen@apple.com> Date: Thu, 29 Feb 2024 19:27:49 -0800 Subject: [PATCH 3/4] Support parsing of lifetime dependence specifiers --- .../Sources/SyntaxSupport/KeywordSpec.swift | 21 +- .../SyntaxSupport/SyntaxNodeKind.swift | 20 +- .../Sources/SyntaxSupport/TypeNodes.swift | 103 +++- .../swiftsyntax/SwiftSyntaxDoccIndex.swift | 2 +- .../swiftsyntax/SyntaxCollectionsFile.swift | 9 +- .../swiftsyntax/SyntaxNodeCasting.swift | 7 + .../ResultBuildersFile.swift | 5 +- Release Notes/600.md | 6 +- Sources/SwiftParser/Parameters.swift | 2 +- Sources/SwiftParser/Patterns.swift | 2 +- .../SwiftParserCompatibility.swift | 2 + Sources/SwiftParser/TokenPrecedence.swift | 2 +- Sources/SwiftParser/Types.swift | 94 +++- .../generated/Parser+TokenSpecSet.swift | 376 +++++++++----- .../ParseDiagnosticsGenerator.swift | 8 +- .../SyntaxExtensions.swift | 13 +- .../generated/ChildNameForDiagnostics.swift | 2 + .../SyntaxKindNameForDiagnostics.swift | 4 + .../generated/SwiftSyntax.md | 2 +- .../SwiftSyntaxCompatibility.swift | 9 +- .../generated/ChildNameForKeyPath.swift | 46 +- Sources/SwiftSyntax/generated/Keyword.swift | 15 + .../generated/RenamedNodesCompatibility.swift | 7 + .../generated/SyntaxAnyVisitor.swift | 72 ++- .../generated/SyntaxBaseNodes.swift | 6 +- .../generated/SyntaxCollections.swift | 124 ++++- .../SwiftSyntax/generated/SyntaxEnum.swift | 30 +- .../SwiftSyntax/generated/SyntaxKind.swift | 32 +- .../generated/SyntaxRewriter.swift | 90 +++- .../SwiftSyntax/generated/SyntaxTraits.swift | 4 + .../SwiftSyntax/generated/SyntaxVisitor.swift | 132 ++++- .../generated/raw/RawSyntaxNodesJKLMN.swift | 284 +++++++++++ .../generated/raw/RawSyntaxNodesQRS.swift | 58 +++ .../generated/raw/RawSyntaxNodesTUVWXYZ.swift | 94 ++-- .../generated/raw/RawSyntaxValidation.swift | 66 ++- .../generated/syntaxNodes/SyntaxNodesAB.swift | 2 +- .../syntaxNodes/SyntaxNodesJKLMN.swift | 457 ++++++++++++++++++ .../syntaxNodes/SyntaxNodesQRS.swift | 95 ++++ .../syntaxNodes/SyntaxNodesTUVWXYZ.swift | 95 ---- .../generated/ResultBuilders.swift | 31 +- Tests/SwiftParserTest/TypeTests.swift | 90 ++++ 41 files changed, 2129 insertions(+), 390 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift b/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift index 659554e7808..895411bace0 100644 --- a/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift +++ b/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift @@ -108,7 +108,9 @@ public enum Keyword: CaseIterable { case _Class case _compilerInitialized case _const + case _consume case _consuming + case _copy case _documentation case _dynamicReplacement case _effects @@ -119,6 +121,7 @@ public enum Keyword: CaseIterable { case _local case _modify case _move + case _mutate case _mutating case _NativeClass case _NativeRefCountedObject @@ -328,6 +331,8 @@ public enum Keyword: CaseIterable { return KeywordSpec("_backDeploy") case ._borrow: return KeywordSpec("_borrow") + case ._borrowing: + return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch) case ._BridgeObject: return KeywordSpec("_BridgeObject") case ._cdecl: @@ -338,6 +343,12 @@ public enum Keyword: CaseIterable { return KeywordSpec("_compilerInitialized") case ._const: return KeywordSpec("_const") + case ._consume: + return KeywordSpec("_consume", experimentalFeature: .nonescapableTypes) + case ._consuming: + return KeywordSpec("_consuming", experimentalFeature: .referenceBindings) + case ._copy: + return KeywordSpec("_copy", experimentalFeature: .nonescapableTypes) case ._documentation: return KeywordSpec("_documentation") case ._dynamicReplacement: @@ -358,6 +369,10 @@ public enum Keyword: CaseIterable { return KeywordSpec("_modify") case ._move: return KeywordSpec("_move") + case ._mutate: + return KeywordSpec("_mutate", experimentalFeature: .nonescapableTypes) + case ._mutating: + return KeywordSpec("_mutating", experimentalFeature: .referenceBindings) case ._NativeClass: return KeywordSpec("_NativeClass") case ._NativeRefCountedObject: @@ -743,12 +758,6 @@ public enum Keyword: CaseIterable { return KeywordSpec("wrt") case .yield: return KeywordSpec("yield") - case ._borrowing: - return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch) - case ._consuming: - return KeywordSpec("_consuming", experimentalFeature: .referenceBindings) - case ._mutating: - return KeywordSpec("_mutating", experimentalFeature: .referenceBindings) } } } diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift index 6351e30f97a..1d36a8ed80d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift @@ -99,8 +99,8 @@ public enum SyntaxNodeKind: String, CaseIterable { case dictionaryExpr case dictionaryType case differentiabilityArgument - case differentiabilityArguments case differentiabilityArgumentList + case differentiabilityArguments case differentiabilityWithRespectToArgument case differentiableAttributeArguments case discardAssignmentExpr @@ -182,6 +182,9 @@ public enum SyntaxNodeKind: String, CaseIterable { case labeledSpecializeArgument case labeledStmt case layoutRequirement + case lifetimeSpecifierArgument + case lifetimeSpecifierArgumentList + case lifetimeTypeSpecifier case macroDecl case macroExpansionDecl case macroExpansionExpr @@ -244,14 +247,15 @@ public enum SyntaxNodeKind: String, CaseIterable { case returnStmt case sameTypeRequirement case sequenceExpr + case simpleTypeSpecifier + case simpleStringLiteralExpr + case simpleStringLiteralSegmentList case someOrAnyType case sourceFile case specializeAttributeArgumentList case specializeAvailabilityArgument case specializeTargetFunctionArgument case stmt - case simpleStringLiteralExpr - case simpleStringLiteralSegmentList case stringLiteralExpr case stringLiteralSegmentList case stringSegment @@ -286,6 +290,7 @@ public enum SyntaxNodeKind: String, CaseIterable { case typeExpr case typeInitializerClause case typeSpecifier + case lifetimeSpecifierArguments case typeSpecifierList case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments @@ -301,10 +306,10 @@ public enum SyntaxNodeKind: String, CaseIterable { case whereClause case whileStmt case wildcardPattern - case yieldStmt case yieldedExpression - case yieldedExpressionsClause case yieldedExpressionList + case yieldedExpressionsClause + case yieldStmt // Nodes that have special handling throughout the codebase @@ -407,8 +412,8 @@ public enum SyntaxNodeKind: String, CaseIterable { case .derivativeAttributeArguments: return "derivativeRegistrationAttributeArguments" case .designatedType: return "designatedTypeElement" case .differentiabilityArgument: return "differentiabilityParam" - case .differentiabilityArguments: return "differentiabilityParams" case .differentiabilityArgumentList: return "differentiabilityParamList" + case .differentiabilityArguments: return "differentiabilityParams" case .differentiabilityWithRespectToArgument: return "differentiabilityParamsClause" case .documentationAttributeArgumentList: return "documentationAttributeArguments" case .dynamicReplacementAttributeArguments: return "dynamicReplacementArguments" @@ -442,6 +447,7 @@ public enum SyntaxNodeKind: String, CaseIterable { case .precedenceGroupName: return "precedenceGroupNameElement" case .repeatStmt: return "repeatWhileStmt" case .someOrAnyType: return "constrainedSugarType" + case .simpleTypeSpecifier: return "typeSpecifier" case .specializeAttributeArgumentList: return "specializeAttributeSpecList" case .specializeAvailabilityArgument: return "availabilityEntry" case .specializeTargetFunctionArgument: return "targetFunctionEntry" @@ -453,8 +459,8 @@ public enum SyntaxNodeKind: String, CaseIterable { case .typeAliasDecl: return "typealiasDecl" case .unavailableFromAsyncAttributeArguments: return "unavailableFromAsyncArguments" case .yieldedExpression: return "yieldExprListElement" - case .yieldedExpressionsClause: return "yieldList" case .yieldedExpressionList: return "yieldExprList" + case .yieldedExpressionsClause: return "yieldList" default: return nil } } diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index 4bf658fe5f3..93a2598645d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -496,9 +496,108 @@ public let TYPE_NODES: [Node] = [ ), Node( - kind: .typeSpecifier, + kind: .lifetimeSpecifierArgument, base: .syntax, + experimentalFeature: .nonescapableTypes, nameForDiagnostics: nil, + documentation: """ + A single argument that can be added to a lifetime specifier like `borrow`, `mutate`, `consume` or `copy`. + + ### Example + `data` in `func foo(data: Array<Item>) -> borrow(data) ComplexReferenceType` + """, + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "parameter", + kind: .token(choices: [.token(.identifier), .keyword(.self), .token(.integerLiteral)]), + nameForDiagnostics: "parameter reference", + documentation: """ + The parameter on which the lifetime of this type depends. + + This can be an identifier referring to an external parameter name, an integer literal to refer to an unnamed + parameter or `self` if the type's lifetime depends on the object the method is called on. + """ + ), + Child( + name: "trailingComma", + kind: .token(choices: [.token(.comma)]), + isOptional: true + ), + ] + ), + + Node( + kind: .lifetimeSpecifierArgumentList, + base: .syntaxCollection, + experimentalFeature: .nonescapableTypes, + nameForDiagnostics: nil, + 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` + """, + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "leftParen", + kind: .token(choices: [.token(.leftParen)]) + ), + Child( + name: "arguments", + kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments"), + documentation: """ + The function parameters that the lifetime of the annotated type depends on. + """ + ), + Child( + name: "rightParen", + kind: .token(choices: [.token(.rightParen)]) + ), + ] + ), + + Node( + kind: .lifetimeTypeSpecifier, + base: .syntax, + experimentalFeature: .nonescapableTypes, + nameForDiagnostics: "lifetime specifier", + documentation: "A specifier that specifies function parameter on whose lifetime a type depends", + children: [ + Child( + name: "specifier", + kind: .token(choices: [ + .keyword(._copy), + .keyword(._consume), + .keyword(._borrow), + .keyword(._mutate), + ]), + documentation: "The specifier token that's attached to the type." + ), + Child( + name: "arguments", + kind: .node(kind: .lifetimeSpecifierArguments) + ), + ] + ), + + Node( + kind: .simpleTypeSpecifier, + base: .syntax, + nameForDiagnostics: "type specifier", documentation: "A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming`", children: [ Child( @@ -523,6 +622,6 @@ public let TYPE_NODES: [Node] = [ kind: .typeSpecifierList, base: .syntaxCollection, nameForDiagnostics: nil, - elementChoices: [.typeSpecifier] + elementChoices: [.simpleTypeSpecifier, .lifetimeTypeSpecifier] ), ] diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift index a605d75c92c..65699262d7e 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift @@ -53,7 +53,7 @@ let nodesSections: String = { } return [node.kind.syntaxType.description] + node.elementChoices - .filter { SYNTAX_NODE_MAP[$0] != nil } + .filter { SYNTAX_NODE_MAP[$0] != nil && !SYNTAX_NODE_MAP[$0]!.isExperimental } .map(\.syntaxType.description) .filter { !handledSyntaxTypes.contains($0) } }) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift index 8609fac7d56..5234dc0ef5f 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift @@ -41,7 +41,12 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { ) { for choiceName in node.elementChoices { let choice = SYNTAX_NODE_MAP[choiceName]! - DeclSyntax("case `\(choice.varOrCaseName)`(\(choice.kind.syntaxType))") + DeclSyntax( + """ + \(choice.apiAttributes())\ + case `\(choice.varOrCaseName)`(\(choice.kind.syntaxType)) + """ + ) } try VariableDeclSyntax("public var _syntaxNode: Syntax") { @@ -60,6 +65,7 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { if choiceNode.kind.isBase { DeclSyntax( """ + \(choiceNode.apiAttributes())\ public init(_ node: some \(choiceNode.kind.protocolType)) { self = .\(choiceNode.varOrCaseName)(\(choiceNode.kind.syntaxType)(node)) } @@ -69,6 +75,7 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } else { DeclSyntax( """ + \(choiceNode.apiAttributes())\ public init(_ node: \(choiceNode.kind.syntaxType)) { self = .\(choiceNode.varOrCaseName)(node) } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift index 7f0b43a78fa..a74f0468d90 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift @@ -16,12 +16,14 @@ import SyntaxSupport @MemberBlockItemListBuilder func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlockItemListSyntax { + let apiAttributes = SYNTAX_NODE_MAP[syntaxNodeKind]?.apiAttributes() ?? [] if syntaxNodeKind.isBase { DeclSyntax( """ /// Checks if the current syntax node can be cast to the type conforming to the ``\(syntaxNodeKind.protocolType)`` protocol. /// /// - Returns: `true` if the node can be cast, `false` otherwise. + \(apiAttributes)\ public func `is`<S: \(syntaxNodeKind.protocolType)>(_ syntaxType: S.Type) -> Bool { return self.as(syntaxType) != nil } @@ -33,6 +35,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock /// Attempts to cast the current syntax node to the type conforming to the ``\(syntaxNodeKind.protocolType)`` protocol. /// /// - Returns: An instance of the specialized type, or `nil` if the cast fails. + \(apiAttributes)\ public func `as`<S: \(syntaxNodeKind.protocolType)>(_ syntaxType: S.Type) -> S? { return S.init(self) } @@ -45,6 +48,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock /// /// - Returns: An instance of the specialized type. /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + \(apiAttributes)\ public func cast<S: \(syntaxNodeKind.protocolType)>(_ syntaxType: S.Type) -> S { return self.as(S.self)! } @@ -56,6 +60,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock /// Checks if the current syntax node can be cast to ``\(syntaxNodeKind.syntaxType)``. /// /// - Returns: `true` if the node can be cast, `false` otherwise. + \(apiAttributes)\ public func `is`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> Bool { return self.as(syntaxType) != nil } @@ -67,6 +72,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock /// Attempts to cast the current syntax node to ``\(syntaxNodeKind.syntaxType)``. /// /// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``, or `nil` if the cast fails. + \(apiAttributes)\ public func `as`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType)? { return \(syntaxNodeKind.syntaxType).init(self) } @@ -79,6 +85,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock /// /// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``. /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + \(apiAttributes)\ public func cast(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType) { return self.as(\(syntaxNodeKind.syntaxType).self)! } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift index 9ed907d4e58..1b02de4dc5f 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift @@ -19,9 +19,9 @@ let resultBuildersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { DeclSyntax( """ #if swift(>=6) - public import SwiftSyntax + @_spi(ExperimentalLanguageFeatures) public import SwiftSyntax #else - import SwiftSyntax + @_spi(ExperimentalLanguageFeatures) import SwiftSyntax #endif """ ) @@ -48,6 +48,7 @@ let resultBuildersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { for elementChoice in node.elementChoices { DeclSyntax( """ + \(SYNTAX_NODE_MAP[elementChoice]?.apiAttributes() ?? [])\ public static func buildExpression(_ expression: \(elementChoice.syntaxType)) -> Component { buildExpression(.init(expression)) } diff --git a/Release Notes/600.md b/Release Notes/600.md index 46f025353e5..f3e4d1eef1f 100644 --- a/Release Notes/600.md +++ b/Release Notes/600.md @@ -62,8 +62,8 @@ - Description: `IncrementalEdit` used to store the range that was replaced and the length of the replacement but not the replacement bytes by itself. `IncrementalEdit` now has a `replacement` property that contains the replacement bytes. - Pull Request: https://github.com/apple/swift-syntax/pull/2527 -- `TypeSpecifierListSyntax` and `TypeSpecifierSyntax` - - Description: `AttributedTypeSyntax` can now contain multiple specifiers and these types are used to model the list of specifiers. +- Type specifiers + - Description: `AttributedTypeSyntax` can now contain multiple specifiers and these types are used to model the list of specifiers. Additionally, type specifiers can now contain arguments, like `borrow(data)`. To facilitate this, the following new types were introduces: `LifetimeSpecifierArgumentListSyntax`, `LifetimeSpecifierArgumentSyntax`, `LifetimeSpecifierArgumentsSyntax`, `LifetimeTypeSpecifierSyntax`, `SimpleTypeSpecifierSyntax`, `TypeSpecifierListSyntax` - Pull request: https://github.com/apple/swift-syntax/pull/2433 ## API Behavior Changes @@ -91,7 +91,7 @@ - Description: `EditorPlaceholderDeclSyntax` and `EditorPlaceholderExprSyntax` are now deprecated and placeholders are instead parsed as identifiers within a `MissingDeclSyntax` or `DeclReferenceExprSyntax`. - Pull request: https://github.com/apple/swift-syntax/pull/2237 -- `AttributedTypeSyntax.specifier` has renamed and changed to be a collection +- `AttributedTypeSyntax.specifier` has renamed to `specifiers` and changed to be a collection - Description: Types can have multiple specifiers now and the syntax tree has been modified to reflect that. - Pull request: https://github.com/apple/swift-syntax/pull/2433 diff --git a/Sources/SwiftParser/Parameters.swift b/Sources/SwiftParser/Parameters.swift index 4273a99d906..e46147cf618 100644 --- a/Sources/SwiftParser/Parameters.swift +++ b/Sources/SwiftParser/Parameters.swift @@ -261,7 +261,7 @@ extension Parser { mutating func parseMisplacedSpecifiers() -> [RawTokenSyntax] { var misplacedSpecifiers: [RawTokenSyntax] = [] if self.withLookahead({ !$0.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: false) }) { - while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) { + while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) { misplacedSpecifiers.append(specifier) } } diff --git a/Sources/SwiftParser/Patterns.swift b/Sources/SwiftParser/Patterns.swift index e5378632257..f1c3fb1bd8b 100644 --- a/Sources/SwiftParser/Patterns.swift +++ b/Sources/SwiftParser/Patterns.swift @@ -340,7 +340,7 @@ extension Parser.Lookahead { mutating func startsParameterName(isClosure: Bool, allowMisplacedSpecifierRecovery: Bool) -> Bool { if allowMisplacedSpecifierRecovery { while canHaveParameterSpecifier, - self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) != nil + self.consume(ifAnyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) != nil {} } diff --git a/Sources/SwiftParser/SwiftParserCompatibility.swift b/Sources/SwiftParser/SwiftParserCompatibility.swift index 24c966d245e..28b52807e26 100644 --- a/Sources/SwiftParser/SwiftParserCompatibility.swift +++ b/Sources/SwiftParser/SwiftParserCompatibility.swift @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +import SwiftSyntax + // This file provides compatibility aliases to keep dependents of SwiftSyntax building. // All users of the declarations in this file should transition away from them ASAP. diff --git a/Sources/SwiftParser/TokenPrecedence.swift b/Sources/SwiftParser/TokenPrecedence.swift index 8abc79f73b5..1f425886d47 100644 --- a/Sources/SwiftParser/TokenPrecedence.swift +++ b/Sources/SwiftParser/TokenPrecedence.swift @@ -231,7 +231,7 @@ enum TokenPrecedence: Comparable { .__consuming, .final, .required, .optional, .lazy, .dynamic, .infix, .postfix, .prefix, .mutating, .nonmutating, .convenience, .override, .package, .open, .__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local, .inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume, ._resultDependsOnSelf, ._resultDependsOn, - .transferring, + .transferring, ._consume, ._copy, ._mutate, // Accessors .get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress, .mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify, diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index b62267ec515..a0e64823ae8 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -@_spi(RawSyntax) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftSyntax extension Parser { /// Parse a type. @@ -468,7 +468,7 @@ extension Parser { var misplacedSpecifiers: [RawTokenSyntax] = [] if self.withLookahead({ $0.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: true) }) { while canHaveParameterSpecifier, - let specifier = self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) + let specifier = self.consume(ifAnyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) { misplacedSpecifiers.append(specifier) } @@ -623,7 +623,7 @@ extension Parser.Lookahead { var specifierProgress = LoopProgressCondition() // TODO: Can we model isolated/_const so that they're specified in both canParse* and parse*? while canHaveParameterSpecifier, - self.at(anyIn: TypeSpecifierSyntax.SpecifierOptions.self) != nil || self.at(.keyword(.isolated)) || self.at(.keyword(._const)), + self.at(anyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) != nil || self.at(.keyword(.isolated)) || self.at(.keyword(._const)), self.hasProgressed(&specifierProgress) { self.consumeAnyToken() @@ -890,21 +890,95 @@ extension Parser.Lookahead { } extension Parser { + private mutating func parseLifetimeTypeSpecifier( + specifierHandle: TokenConsumptionHandle + ) -> RawTypeSpecifierListSyntax.Element { + let specifier = self.eat(specifierHandle) + + 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( + leftParen: missingToken(.leftParen), + arguments: RawLifetimeSpecifierArgumentListSyntax( + elements: [ + RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena) + ], + arena: self.arena + ), + rightParen: missingToken(.rightParen), + arena: self.arena + ) + let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(specifier: specifier, arguments: arguments, arena: self.arena) + return .lifetimeTypeSpecifier(lifetimeSpecifier) + } + + var keepGoing: RawTokenSyntax? + var arguments: [RawLifetimeSpecifierArgumentSyntax] = [] + var loopProgress = LoopProgressCondition() + repeat { + let (unexpectedBeforeParameter, parameter) = self.expect( + anyIn: LifetimeSpecifierArgumentSyntax.ParameterOptions.self, + default: .identifier + ) + keepGoing = self.consume(if: .comma) + arguments.append( + RawLifetimeSpecifierArgumentSyntax( + unexpectedBeforeParameter, + parameter: parameter, + trailingComma: keepGoing, + arena: arena + ) + ) + } while keepGoing != nil && self.hasProgressed(&loopProgress) + let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(elements: arguments, arena: self.arena) + let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen) + let argumentsSyntax = RawLifetimeSpecifierArgumentsSyntax( + leftParen: leftParen, + arguments: lifetimeSpecifierArgumentList, + unexpectedBeforeRightParen, + rightParen: rightParen, + arena: self.arena + ) + let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(specifier: specifier, arguments: argumentsSyntax, arena: self.arena) + return .lifetimeTypeSpecifier(lifetimeSpecifier) + } + + private mutating func parseSimpleTypeSpecifier( + specifierHandle: TokenConsumptionHandle + ) -> RawTypeSpecifierListSyntax.Element { + let specifier = self.eat(specifierHandle) + let simpleSpecifier = RawSimpleTypeSpecifierSyntax(specifier: specifier, arena: arena) + return .simpleTypeSpecifier(simpleSpecifier) + } + mutating func parseTypeAttributeList( misplacedSpecifiers: [RawTokenSyntax] = [] ) -> ( specifiers: RawTypeSpecifierListSyntax, attributes: RawAttributeListSyntax )? { - var specifiers: [RawTypeSpecifierSyntax] = [] - while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: TypeSpecifierSyntax.SpecifierOptions.self) { - specifiers.append(RawTypeSpecifierSyntax(specifier: specifier, arena: arena)) - } - if !misplacedSpecifiers.isEmpty { - specifiers += misplacedSpecifiers.map { - RawTypeSpecifierSyntax(specifier: missingToken($0.tokenKind, text: $0.tokenText), arena: arena) + typealias SimpleOrLifetimeSpecifier = EitherTokenSpecSet<SimpleTypeSpecifierSyntax.SpecifierOptions, LifetimeTypeSpecifierSyntax.SpecifierOptions> + var specifiers: [RawTypeSpecifierListSyntax.Element] = [] + SPECIFIER_PARSING: while canHaveParameterSpecifier, let (specifierSpec, specifierHandle) = self.at(anyIn: SimpleOrLifetimeSpecifier.self) { + switch specifierSpec { + case .lhs: specifiers.append(parseSimpleTypeSpecifier(specifierHandle: specifierHandle)) + case .rhs: + if self.experimentalFeatures.contains(.nonescapableTypes) { + specifiers.append(parseLifetimeTypeSpecifier(specifierHandle: specifierHandle)) + } else { + break SPECIFIER_PARSING + } } } + specifiers += misplacedSpecifiers.map { + .simpleTypeSpecifier( + RawSimpleTypeSpecifierSyntax( + specifier: missingToken($0.tokenKind, text: $0.tokenText), + arena: arena + ) + ) + } let attributes: RawAttributeListSyntax? if self.at(.atSign) { diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index 2f060d0b1a5..98c91c193d4 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -1185,6 +1185,10 @@ extension DeclReferenceExprSyntax { self = .Self case TokenSpec(.`init`): self = .`init` + case TokenSpec(.deinit): + self = .deinit + case TokenSpec(.subscript): + self = .subscript case TokenSpec(.dollarIdentifier): self = .dollarIdentifier case TokenSpec(.binaryOperator): @@ -1838,6 +1842,10 @@ extension IdentifierPatternSyntax { self = .self case TokenSpec(.`init`): self = .`init` + case TokenSpec(.deinit): + self = .deinit + case TokenSpec(.subscript): + self = .subscript default: return nil } @@ -2554,6 +2562,140 @@ extension LayoutRequirementSyntax { } } +extension LifetimeSpecifierArgumentSyntax { + @_spi(Diagnostics) + public enum ParameterOptions: TokenSpecSet { + case identifier + case `self` + case integerLiteral + + init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.self): + self = .self + case TokenSpec(.integerLiteral): + self = .integerLiteral + default: + return nil + } + } + + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.self): + self = .self + case TokenSpec(.integerLiteral): + self = .integerLiteral + default: + return nil + } + } + + var spec: TokenSpec { + switch self { + case .identifier: + return .identifier + case .self: + return .keyword(.self) + case .integerLiteral: + return .integerLiteral + } + } + + /// 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 .identifier: + return .identifier("") + case .self: + return .keyword(.self) + case .integerLiteral: + return .integerLiteral("") + } + } + } +} + +extension LifetimeTypeSpecifierSyntax { + @_spi(Diagnostics) + public enum SpecifierOptions: TokenSpecSet { + @_spi(ExperimentalLanguageFeatures) + case _copy + @_spi(ExperimentalLanguageFeatures) + case _consume + case _borrow + @_spi(ExperimentalLanguageFeatures) + case _mutate + + init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(._copy) where experimentalFeatures.contains(.nonescapableTypes): + self = ._copy + case TokenSpec(._consume) where experimentalFeatures.contains(.nonescapableTypes): + self = ._consume + case TokenSpec(._borrow): + self = ._borrow + case TokenSpec(._mutate) where experimentalFeatures.contains(.nonescapableTypes): + self = ._mutate + default: + return nil + } + } + + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(._copy): + self = ._copy + case TokenSpec(._consume): + self = ._consume + case TokenSpec(._borrow): + self = ._borrow + case TokenSpec(._mutate): + self = ._mutate + default: + return nil + } + } + + var spec: TokenSpec { + switch self { + case ._copy: + return .keyword(._copy) + case ._consume: + return .keyword(._consume) + case ._borrow: + return .keyword(._borrow) + case ._mutate: + return .keyword(._mutate) + } + } + + /// 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 ._copy: + return .keyword(._copy) + case ._consume: + return .keyword(._consume) + case ._borrow: + return .keyword(._borrow) + case ._mutate: + return .keyword(._mutate) + } + } + } +} + extension MemberTypeSyntax { @_spi(Diagnostics) public enum NameOptions: TokenSpecSet { @@ -3253,6 +3395,123 @@ extension SimpleStringLiteralExprSyntax { } } +extension SimpleTypeSpecifierSyntax { + @_spi(Diagnostics) + public enum SpecifierOptions: TokenSpecSet { + case `inout` + case __shared + case __owned + case isolated + case _const + case borrowing + case consuming + @_spi(ExperimentalLanguageFeatures) + case transferring + @_spi(ExperimentalLanguageFeatures) + case _resultDependsOn + + init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(.inout): + self = .inout + case TokenSpec(.__shared): + self = .__shared + case TokenSpec(.__owned): + self = .__owned + case TokenSpec(.isolated): + self = .isolated + case TokenSpec(._const): + self = ._const + case TokenSpec(.borrowing): + self = .borrowing + case TokenSpec(.consuming): + self = .consuming + case TokenSpec(.transferring) where experimentalFeatures.contains(.transferringArgsAndResults): + self = .transferring + case TokenSpec(._resultDependsOn) where experimentalFeatures.contains(.nonescapableTypes): + self = ._resultDependsOn + default: + return nil + } + } + + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.inout): + self = .inout + case TokenSpec(.__shared): + self = .__shared + case TokenSpec(.__owned): + self = .__owned + case TokenSpec(.isolated): + self = .isolated + case TokenSpec(._const): + self = ._const + case TokenSpec(.borrowing): + self = .borrowing + case TokenSpec(.consuming): + self = .consuming + case TokenSpec(.transferring): + self = .transferring + case TokenSpec(._resultDependsOn): + self = ._resultDependsOn + default: + return nil + } + } + + var spec: TokenSpec { + switch self { + case .inout: + return .keyword(.inout) + case .__shared: + return .keyword(.__shared) + case .__owned: + return .keyword(.__owned) + case .isolated: + return .keyword(.isolated) + case ._const: + return .keyword(._const) + case .borrowing: + return .keyword(.borrowing) + case .consuming: + return .keyword(.consuming) + case .transferring: + return .keyword(.transferring) + case ._resultDependsOn: + return .keyword(._resultDependsOn) + } + } + + /// 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 .inout: + return .keyword(.inout) + case .__shared: + return .keyword(.__shared) + case .__owned: + return .keyword(.__owned) + case .isolated: + return .keyword(.isolated) + case ._const: + return .keyword(._const) + case .borrowing: + return .keyword(.borrowing) + case .consuming: + return .keyword(.consuming) + case .transferring: + return .keyword(.transferring) + case ._resultDependsOn: + return .keyword(._resultDependsOn) + } + } + } +} + extension SomeOrAnyTypeSyntax { @_spi(Diagnostics) public enum SomeOrAnySpecifierOptions: TokenSpecSet { @@ -3635,123 +3894,6 @@ extension TupleTypeElementSyntax { } } -extension TypeSpecifierSyntax { - @_spi(Diagnostics) - public enum SpecifierOptions: TokenSpecSet { - case `inout` - case __shared - case __owned - case isolated - case _const - case borrowing - case consuming - @_spi(ExperimentalLanguageFeatures) - case transferring - @_spi(ExperimentalLanguageFeatures) - case _resultDependsOn - - init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { - switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.inout): - self = .inout - case TokenSpec(.__shared): - self = .__shared - case TokenSpec(.__owned): - self = .__owned - case TokenSpec(.isolated): - self = .isolated - case TokenSpec(._const): - self = ._const - case TokenSpec(.borrowing): - self = .borrowing - case TokenSpec(.consuming): - self = .consuming - case TokenSpec(.transferring) where experimentalFeatures.contains(.transferringArgsAndResults): - self = .transferring - case TokenSpec(._resultDependsOn) where experimentalFeatures.contains(.nonescapableTypes): - self = ._resultDependsOn - default: - return nil - } - } - - public init?(token: TokenSyntax) { - switch token { - case TokenSpec(.inout): - self = .inout - case TokenSpec(.__shared): - self = .__shared - case TokenSpec(.__owned): - self = .__owned - case TokenSpec(.isolated): - self = .isolated - case TokenSpec(._const): - self = ._const - case TokenSpec(.borrowing): - self = .borrowing - case TokenSpec(.consuming): - self = .consuming - case TokenSpec(.transferring): - self = .transferring - case TokenSpec(._resultDependsOn): - self = ._resultDependsOn - default: - return nil - } - } - - var spec: TokenSpec { - switch self { - case .inout: - return .keyword(.inout) - case .__shared: - return .keyword(.__shared) - case .__owned: - return .keyword(.__owned) - case .isolated: - return .keyword(.isolated) - case ._const: - return .keyword(._const) - case .borrowing: - return .keyword(.borrowing) - case .consuming: - return .keyword(.consuming) - case .transferring: - return .keyword(.transferring) - case ._resultDependsOn: - return .keyword(._resultDependsOn) - } - } - - /// 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 .inout: - return .keyword(.inout) - case .__shared: - return .keyword(.__shared) - case .__owned: - return .keyword(.__owned) - case .isolated: - return .keyword(.isolated) - case ._const: - return .keyword(._const) - case .borrowing: - return .keyword(.borrowing) - case .consuming: - return .keyword(.consuming) - case .transferring: - return .keyword(.transferring) - case ._resultDependsOn: - return .keyword(._resultDependsOn) - } - } - } -} - extension UnresolvedAsExprSyntax { @_spi(Diagnostics) public enum QuestionOrExclamationMarkOptions: TokenSpecSet { diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index 0c4bf7db258..5db948f941a 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -945,8 +945,8 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { } exchangeTokens( unexpected: node.unexpectedBetweenModifiersAndFirstName, - unexpectedTokenCondition: { TypeSpecifierSyntax.SpecifierOptions(token: $0) != nil }, - correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.map(\.specifier) ?? [], + unexpectedTokenCondition: { SimpleTypeSpecifierSyntax.SpecifierOptions(token: $0) != nil }, + correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.simpleSpecifiers ?? [], message: { SpecifierOnParameterName(misplacedSpecifiers: $0) }, moveFixIt: { MoveTokensInFrontOfTypeFixIt(movedTokens: $0) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } @@ -1742,8 +1742,8 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { } exchangeTokens( unexpected: node.unexpectedBetweenInoutKeywordAndFirstName, - unexpectedTokenCondition: { TypeSpecifierSyntax.SpecifierOptions(token: $0) != nil }, - correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.map(\.specifier) ?? [], + unexpectedTokenCondition: { SimpleTypeSpecifierSyntax.SpecifierOptions(token: $0) != nil }, + correctTokens: node.type.as(AttributedTypeSyntax.self)?.specifiers.simpleSpecifiers ?? [], message: { SpecifierOnParameterName(misplacedSpecifiers: $0) }, moveFixIt: { MoveTokensInFrontOfTypeFixIt(movedTokens: $0) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } diff --git a/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift b/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift index 0cd79b898ad..c1a464dc0e8 100644 --- a/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift +++ b/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift @@ -12,7 +12,7 @@ import SwiftBasicFormat @_spi(Diagnostics) import SwiftParser -@_spi(RawSyntax) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftSyntax extension UnexpectedNodesSyntax { func presentTokens(satisfying isIncluded: (TokenSyntax) -> Bool) -> [TokenSyntax] { @@ -209,3 +209,14 @@ extension TokenSyntax { return presence == .present } } + +extension TypeSpecifierListSyntax { + var simpleSpecifiers: [TokenSyntax] { + return self.compactMap { specifier in + switch specifier { + case .simpleTypeSpecifier(let specifier): return specifier.specifier + case .lifetimeTypeSpecifier: return nil + } + } + } +} diff --git a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift index 887bd24fb40..56066b8547f 100644 --- a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift @@ -220,6 +220,8 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? { return "size" case \LayoutRequirementSyntax.alignment: return "alignment" + case \LifetimeSpecifierArgumentSyntax.parameter: + return "parameter reference" case \MacroDeclSyntax.attributes: return "attributes" case \MacroDeclSyntax.modifiers: diff --git a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift index 02aa8637e61..8b2ccf9935c 100644 --- a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift @@ -247,6 +247,8 @@ extension SyntaxKind { return "labeled statement" case .layoutRequirement: return "layout requirement" + case .lifetimeTypeSpecifier: + return "lifetime specifier" case .macroDecl: return "macro" case .macroExpansionDecl: @@ -333,6 +335,8 @@ extension SyntaxKind { return "same type requirement" case .simpleStringLiteralExpr: return "simple string literal" + case .simpleTypeSpecifier: + return "type specifier" case .someOrAnyType: return "type" case .sourceFile: diff --git a/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md b/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md index 333d66b07df..3ffec83b129 100644 --- a/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md +++ b/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md @@ -302,7 +302,7 @@ These articles are intended for developers wishing to contribute to SwiftSyntax - <doc:SwiftSyntax/TupleTypeElementListSyntax> - <doc:SwiftSyntax/TupleTypeElementSyntax> - <doc:SwiftSyntax/TypeSpecifierListSyntax> -- <doc:SwiftSyntax/TypeSpecifierSyntax> +- <doc:SwiftSyntax/SimpleTypeSpecifierSyntax> - <doc:SwiftSyntax/UnexpectedNodesSyntax> - <doc:SwiftSyntax/VersionComponentListSyntax> - <doc:SwiftSyntax/VersionComponentSyntax> diff --git a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift index 9df3bc3900f..7a53e412650 100644 --- a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift +++ b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift @@ -52,7 +52,7 @@ extension AttributedTypeSyntax { ) { let specifiers: TypeSpecifierListSyntax if let specifier { - specifiers = [TypeSpecifierSyntax(specifier: specifier)] + specifiers = [.simpleTypeSpecifier(SimpleTypeSpecifierSyntax(specifier: specifier))] } else { specifiers = [] } @@ -82,11 +82,14 @@ extension AttributedTypeSyntax { @available(*, deprecated, message: "Access the specifiers list instead") public var specifier: TokenSyntax? { get { - specifiers.first?.specifier + if case .simpleTypeSpecifier(let simpleSpecifier) = specifiers.first { + return simpleSpecifier.specifier + } + return nil } set { if let newValue { - specifiers = [TypeSpecifierSyntax(specifier: newValue)] + specifiers = [.simpleTypeSpecifier(SimpleTypeSpecifierSyntax(specifier: newValue))] } else { specifiers = [] } diff --git a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift index f967ed48b2e..a738f6b9979 100644 --- a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift +++ b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift @@ -1999,6 +1999,40 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "rightParen" case \LayoutRequirementSyntax.unexpectedAfterRightParen: return "unexpectedAfterRightParen" + case \LifetimeSpecifierArgumentSyntax.unexpectedBeforeParameter: + return "unexpectedBeforeParameter" + case \LifetimeSpecifierArgumentSyntax.parameter: + return "parameter" + case \LifetimeSpecifierArgumentSyntax.unexpectedBetweenParameterAndTrailingComma: + return "unexpectedBetweenParameterAndTrailingComma" + case \LifetimeSpecifierArgumentSyntax.trailingComma: + return "trailingComma" + case \LifetimeSpecifierArgumentSyntax.unexpectedAfterTrailingComma: + return "unexpectedAfterTrailingComma" + case \LifetimeSpecifierArgumentsSyntax.unexpectedBeforeLeftParen: + return "unexpectedBeforeLeftParen" + case \LifetimeSpecifierArgumentsSyntax.leftParen: + return "leftParen" + case \LifetimeSpecifierArgumentsSyntax.unexpectedBetweenLeftParenAndArguments: + return "unexpectedBetweenLeftParenAndArguments" + case \LifetimeSpecifierArgumentsSyntax.arguments: + return "arguments" + case \LifetimeSpecifierArgumentsSyntax.unexpectedBetweenArgumentsAndRightParen: + return "unexpectedBetweenArgumentsAndRightParen" + case \LifetimeSpecifierArgumentsSyntax.rightParen: + return "rightParen" + case \LifetimeSpecifierArgumentsSyntax.unexpectedAfterRightParen: + return "unexpectedAfterRightParen" + case \LifetimeTypeSpecifierSyntax.unexpectedBeforeSpecifier: + return "unexpectedBeforeSpecifier" + case \LifetimeTypeSpecifierSyntax.specifier: + return "specifier" + case \LifetimeTypeSpecifierSyntax.unexpectedBetweenSpecifierAndArguments: + return "unexpectedBetweenSpecifierAndArguments" + case \LifetimeTypeSpecifierSyntax.arguments: + return "arguments" + case \LifetimeTypeSpecifierSyntax.unexpectedAfterArguments: + return "unexpectedAfterArguments" case \MacroDeclSyntax.unexpectedBeforeAttributes: return "unexpectedBeforeAttributes" case \MacroDeclSyntax.attributes: @@ -2787,6 +2821,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "closingQuote" case \SimpleStringLiteralExprSyntax.unexpectedAfterClosingQuote: return "unexpectedAfterClosingQuote" + case \SimpleTypeSpecifierSyntax.unexpectedBeforeSpecifier: + return "unexpectedBeforeSpecifier" + case \SimpleTypeSpecifierSyntax.specifier: + return "specifier" + case \SimpleTypeSpecifierSyntax.unexpectedAfterSpecifier: + return "unexpectedAfterSpecifier" case \SomeOrAnyTypeSyntax.unexpectedBeforeSomeOrAnySpecifier: return "unexpectedBeforeSomeOrAnySpecifier" case \SomeOrAnyTypeSyntax.someOrAnySpecifier: @@ -3289,12 +3329,6 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "value" case \TypeInitializerClauseSyntax.unexpectedAfterValue: return "unexpectedAfterValue" - case \TypeSpecifierSyntax.unexpectedBeforeSpecifier: - return "unexpectedBeforeSpecifier" - case \TypeSpecifierSyntax.specifier: - return "specifier" - case \TypeSpecifierSyntax.unexpectedAfterSpecifier: - return "unexpectedAfterSpecifier" case \UnavailableFromAsyncAttributeArgumentsSyntax.unexpectedBeforeMessageLabel: return "unexpectedBeforeMessageLabel" case \UnavailableFromAsyncAttributeArgumentsSyntax.messageLabel: diff --git a/Sources/SwiftSyntax/generated/Keyword.swift b/Sources/SwiftSyntax/generated/Keyword.swift index a12bb43fe23..c331f2f5716 100644 --- a/Sources/SwiftSyntax/generated/Keyword.swift +++ b/Sources/SwiftSyntax/generated/Keyword.swift @@ -28,7 +28,11 @@ public enum Keyword: UInt8, Hashable, Sendable { case _compilerInitialized case _const @_spi(ExperimentalLanguageFeatures) + case _consume + @_spi(ExperimentalLanguageFeatures) case _consuming + @_spi(ExperimentalLanguageFeatures) + case _copy case _documentation case _dynamicReplacement case _effects @@ -40,6 +44,8 @@ public enum Keyword: UInt8, Hashable, Sendable { case _modify case _move @_spi(ExperimentalLanguageFeatures) + case _mutate + @_spi(ExperimentalLanguageFeatures) case _mutating case _NativeClass case _NativeRefCountedObject @@ -337,6 +343,8 @@ public enum Keyword: UInt8, Hashable, Sendable { } case 5: switch text { + case "_copy": + self = ._copy case "_move": self = ._move case "_read": @@ -447,6 +455,8 @@ public enum Keyword: UInt8, Hashable, Sendable { self = ._linear case "_modify": self = ._modify + case "_mutate": + self = ._mutate case "consume": self = .consume case "default": @@ -484,6 +494,8 @@ public enum Keyword: UInt8, Hashable, Sendable { switch text { case "__shared": self = .__shared + case "_consume": + self = ._consume case "_effects": self = ._effects case "_forward": @@ -814,7 +826,9 @@ public enum Keyword: UInt8, Hashable, Sendable { "_Class", "_compilerInitialized", "_const", + "_consume", "_consuming", + "_copy", "_documentation", "_dynamicReplacement", "_effects", @@ -825,6 +839,7 @@ public enum Keyword: UInt8, Hashable, Sendable { "_local", "_modify", "_move", + "_mutate", "_mutating", "_NativeClass", "_NativeRefCountedObject", diff --git a/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift index 1d28a95519a..9fc7d663ee4 100644 --- a/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift @@ -192,6 +192,9 @@ public typealias TupleExprElementListSyntax = LabeledExprListSyntax @available(*, deprecated, renamed: "InheritanceClauseSyntax") public typealias TypeInheritanceClauseSyntax = InheritanceClauseSyntax +@available(*, deprecated, renamed: "SimpleTypeSpecifierSyntax") +public typealias TypeSpecifierSyntax = SimpleTypeSpecifierSyntax + @available(*, deprecated, renamed: "TypeAliasDeclSyntax") public typealias TypealiasDeclSyntax = TypeAliasDeclSyntax @@ -451,6 +454,10 @@ public extension SyntaxKind { return .inheritanceClause } + static var typeSpecifier: Self { + return .simpleTypeSpecifier + } + static var typealiasDecl: Self { return .typeAliasDecl } diff --git a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift index 9562943c922..5581f94333a 100644 --- a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift @@ -1342,6 +1342,62 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + override open func visit(_ node: LifetimeSpecifierArgumentListSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + override open func visitPost(_ node: LifetimeSpecifierArgumentListSyntax) { + visitAnyPost(node._syntaxNode) + } + + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + override open func visit(_ node: LifetimeSpecifierArgumentSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + override open func visitPost(_ node: LifetimeSpecifierArgumentSyntax) { + 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 + override open func visit(_ node: LifetimeTypeSpecifierSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + override open func visitPost(_ node: LifetimeTypeSpecifierSyntax) { + visitAnyPost(node._syntaxNode) + } + override open func visit(_ node: MacroDeclSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } @@ -1846,6 +1902,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } + override open func visit(_ node: SimpleTypeSpecifierSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + override open func visitPost(_ node: SimpleTypeSpecifierSyntax) { + visitAnyPost(node._syntaxNode) + } + override open func visit(_ node: SomeOrAnyTypeSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } @@ -2156,14 +2220,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } - override open func visit(_ node: TypeSpecifierSyntax) -> SyntaxVisitorContinueKind { - return visitAny(node._syntaxNode) - } - - override open func visitPost(_ node: TypeSpecifierSyntax) { - visitAnyPost(node._syntaxNode) - } - override open func visit(_ node: UnavailableFromAsyncAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index fed0fd88348..6c2b3b334b4 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -1679,6 +1679,10 @@ extension Syntax { .node(LabeledSpecializeArgumentSyntax.self), .node(LabeledStmtSyntax.self), .node(LayoutRequirementSyntax.self), + .node(LifetimeSpecifierArgumentListSyntax.self), + .node(LifetimeSpecifierArgumentSyntax.self), + .node(LifetimeSpecifierArgumentsSyntax.self), + .node(LifetimeTypeSpecifierSyntax.self), .node(MacroDeclSyntax.self), .node(MacroExpansionDeclSyntax.self), .node(MacroExpansionExprSyntax.self), @@ -1742,6 +1746,7 @@ extension Syntax { .node(SequenceExprSyntax.self), .node(SimpleStringLiteralExprSyntax.self), .node(SimpleStringLiteralSegmentListSyntax.self), + .node(SimpleTypeSpecifierSyntax.self), .node(SomeOrAnyTypeSyntax.self), .node(SourceFileSyntax.self), .node(SpecializeAttributeArgumentListSyntax.self), @@ -1780,7 +1785,6 @@ extension Syntax { .node(TypeExprSyntax.self), .node(TypeInitializerClauseSyntax.self), .node(TypeSpecifierListSyntax.self), - .node(TypeSpecifierSyntax.self), .node(UnavailableFromAsyncAttributeArgumentsSyntax.self), .node(UnderscorePrivateAttributeArgumentsSyntax.self), .node(UnexpectedNodesSyntax.self), diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index fba627d097a..fa38f8446a2 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -876,6 +876,29 @@ public struct LabeledExprListSyntax: SyntaxCollection, SyntaxHashable { public static let syntaxKind = SyntaxKind.labeledExprList } +/// - Experiment: Requires experimental feature `nonescapableTypes`. +/// +/// ### Children +/// +/// ``LifetimeSpecifierArgumentSyntax`` `*` +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +public struct LifetimeSpecifierArgumentListSyntax: SyntaxCollection, SyntaxHashable { + public typealias Element = LifetimeSpecifierArgumentSyntax + + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .lifetimeSpecifierArgumentList else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + public static let syntaxKind = SyntaxKind.lifetimeSpecifierArgumentList +} + /// ### Children /// /// ``MemberBlockItemSyntax`` `*` @@ -1652,13 +1675,110 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable { /// ### Children /// -/// ``TypeSpecifierSyntax`` `*` +/// (``SimpleTypeSpecifierSyntax`` | ``LifetimeTypeSpecifierSyntax``) `*` /// /// ### Contained in /// /// - ``AttributedTypeSyntax``.``AttributedTypeSyntax/specifiers`` public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { - public typealias Element = TypeSpecifierSyntax + public enum Element: SyntaxChildChoices, SyntaxHashable { + case `simpleTypeSpecifier`(SimpleTypeSpecifierSyntax) + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case `lifetimeTypeSpecifier`(LifetimeTypeSpecifierSyntax) + + public var _syntaxNode: Syntax { + switch self { + case .simpleTypeSpecifier(let node): + return node._syntaxNode + case .lifetimeTypeSpecifier(let node): + return node._syntaxNode + } + } + + public init(_ node: SimpleTypeSpecifierSyntax) { + self = .simpleTypeSpecifier(node) + } + + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + public init(_ node: LifetimeTypeSpecifierSyntax) { + self = .lifetimeTypeSpecifier(node) + } + + public init?(_ node: some SyntaxProtocol) { + if let node = node.as(SimpleTypeSpecifierSyntax.self) { + self = .simpleTypeSpecifier(node) + return + } + if let node = node.as(LifetimeTypeSpecifierSyntax.self) { + self = .lifetimeTypeSpecifier(node) + return + } + return nil + } + + public static var structure: SyntaxNodeStructure { + return .choices([ + .node(SimpleTypeSpecifierSyntax.self), + .node(LifetimeTypeSpecifierSyntax.self)]) + } + + /// Checks if the current syntax node can be cast to ``SimpleTypeSpecifierSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + public func `is`(_ syntaxType: SimpleTypeSpecifierSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``SimpleTypeSpecifierSyntax``. + /// + /// - Returns: An instance of ``SimpleTypeSpecifierSyntax``, or `nil` if the cast fails. + public func `as`(_ syntaxType: SimpleTypeSpecifierSyntax.Type) -> SimpleTypeSpecifierSyntax? { + return SimpleTypeSpecifierSyntax.init(self) + } + + /// Force-casts the current syntax node to ``SimpleTypeSpecifierSyntax``. + /// + /// - Returns: An instance of ``SimpleTypeSpecifierSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + public func cast(_ syntaxType: SimpleTypeSpecifierSyntax.Type) -> SimpleTypeSpecifierSyntax { + return self.as(SimpleTypeSpecifierSyntax.self)! + } + + /// Checks if the current syntax node can be cast to ``LifetimeTypeSpecifierSyntax``. + /// + /// - Returns: `true` if the node can be cast, `false` otherwise. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + public func `is`(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> Bool { + return self.as(syntaxType) != nil + } + + /// Attempts to cast the current syntax node to ``LifetimeTypeSpecifierSyntax``. + /// + /// - Returns: An instance of ``LifetimeTypeSpecifierSyntax``, or `nil` if the cast fails. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + public func `as`(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> LifetimeTypeSpecifierSyntax? { + return LifetimeTypeSpecifierSyntax.init(self) + } + + /// Force-casts the current syntax node to ``LifetimeTypeSpecifierSyntax``. + /// + /// - Returns: An instance of ``LifetimeTypeSpecifierSyntax``. + /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + public func cast(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> LifetimeTypeSpecifierSyntax { + return self.as(LifetimeTypeSpecifierSyntax.self)! + } + } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/SyntaxEnum.swift b/Sources/SwiftSyntax/generated/SyntaxEnum.swift index 87594f87c16..ddffa06852c 100644 --- a/Sources/SwiftSyntax/generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/generated/SyntaxEnum.swift @@ -178,6 +178,22 @@ public enum SyntaxEnum: Sendable { case labeledSpecializeArgument(LabeledSpecializeArgumentSyntax) case labeledStmt(LabeledStmtSyntax) case layoutRequirement(LayoutRequirementSyntax) + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax) + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax) + #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) case macroExpansionExpr(MacroExpansionExprSyntax) @@ -241,6 +257,7 @@ public enum SyntaxEnum: Sendable { case sequenceExpr(SequenceExprSyntax) case simpleStringLiteralExpr(SimpleStringLiteralExprSyntax) case simpleStringLiteralSegmentList(SimpleStringLiteralSegmentListSyntax) + case simpleTypeSpecifier(SimpleTypeSpecifierSyntax) case someOrAnyType(SomeOrAnyTypeSyntax) case sourceFile(SourceFileSyntax) case specializeAttributeArgumentList(SpecializeAttributeArgumentListSyntax) @@ -282,7 +299,6 @@ public enum SyntaxEnum: Sendable { case typeExpr(TypeExprSyntax) case typeInitializerClause(TypeInitializerClauseSyntax) case typeSpecifierList(TypeSpecifierListSyntax) - case typeSpecifier(TypeSpecifierSyntax) case unavailableFromAsyncAttributeArguments(UnavailableFromAsyncAttributeArgumentsSyntax) case underscorePrivateAttributeArguments(UnderscorePrivateAttributeArgumentsSyntax) case unexpectedNodes(UnexpectedNodesSyntax) @@ -629,6 +645,14 @@ public extension Syntax { return .labeledStmt(LabeledStmtSyntax(self)!) case .layoutRequirement: return .layoutRequirement(LayoutRequirementSyntax(self)!) + case .lifetimeSpecifierArgumentList: + return .lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax(self)!) + case .lifetimeSpecifierArgument: + return .lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax(self)!) + case .lifetimeSpecifierArguments: + return .lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax(self)!) + case .lifetimeTypeSpecifier: + return .lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax(self)!) case .macroDecl: return .macroDecl(MacroDeclSyntax(self)!) case .macroExpansionDecl: @@ -755,6 +779,8 @@ public extension Syntax { return .simpleStringLiteralExpr(SimpleStringLiteralExprSyntax(self)!) case .simpleStringLiteralSegmentList: return .simpleStringLiteralSegmentList(SimpleStringLiteralSegmentListSyntax(self)!) + case .simpleTypeSpecifier: + return .simpleTypeSpecifier(SimpleTypeSpecifierSyntax(self)!) case .someOrAnyType: return .someOrAnyType(SomeOrAnyTypeSyntax(self)!) case .sourceFile: @@ -831,8 +857,6 @@ public extension Syntax { return .typeInitializerClause(TypeInitializerClauseSyntax(self)!) case .typeSpecifierList: return .typeSpecifierList(TypeSpecifierListSyntax(self)!) - case .typeSpecifier: - return .typeSpecifier(TypeSpecifierSyntax(self)!) case .unavailableFromAsyncAttributeArguments: return .unavailableFromAsyncAttributeArguments(UnavailableFromAsyncAttributeArgumentsSyntax(self)!) case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index 794255d0a4b..103e0304705 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -178,6 +178,22 @@ public enum SyntaxKind: Sendable { case labeledSpecializeArgument case labeledStmt case layoutRequirement + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case lifetimeSpecifierArgumentList + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case lifetimeSpecifierArgument + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case lifetimeSpecifierArguments + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case lifetimeTypeSpecifier case macroDecl case macroExpansionDecl case macroExpansionExpr @@ -241,6 +257,7 @@ public enum SyntaxKind: Sendable { case sequenceExpr case simpleStringLiteralExpr case simpleStringLiteralSegmentList + case simpleTypeSpecifier case someOrAnyType case sourceFile case specializeAttributeArgumentList @@ -282,7 +299,6 @@ public enum SyntaxKind: Sendable { case typeExpr case typeInitializerClause case typeSpecifierList - case typeSpecifier case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments case unexpectedNodes @@ -366,6 +382,8 @@ public enum SyntaxKind: Sendable { return true case .labeledExprList: return true + case .lifetimeSpecifierArgumentList: + return true case .memberBlockItemList: return true case .multipleTrailingClosureElementList: @@ -752,6 +770,14 @@ public enum SyntaxKind: Sendable { return LabeledStmtSyntax.self case .layoutRequirement: return LayoutRequirementSyntax.self + case .lifetimeSpecifierArgumentList: + return LifetimeSpecifierArgumentListSyntax.self + case .lifetimeSpecifierArgument: + return LifetimeSpecifierArgumentSyntax.self + case .lifetimeSpecifierArguments: + return LifetimeSpecifierArgumentsSyntax.self + case .lifetimeTypeSpecifier: + return LifetimeTypeSpecifierSyntax.self case .macroDecl: return MacroDeclSyntax.self case .macroExpansionDecl: @@ -878,6 +904,8 @@ public enum SyntaxKind: Sendable { return SimpleStringLiteralExprSyntax.self case .simpleStringLiteralSegmentList: return SimpleStringLiteralSegmentListSyntax.self + case .simpleTypeSpecifier: + return SimpleTypeSpecifierSyntax.self case .someOrAnyType: return SomeOrAnyTypeSyntax.self case .sourceFile: @@ -954,8 +982,6 @@ public enum SyntaxKind: Sendable { return TypeInitializerClauseSyntax.self case .typeSpecifierList: return TypeSpecifierListSyntax.self - case .typeSpecifier: - return TypeSpecifierSyntax.self case .unavailableFromAsyncAttributeArguments: return UnavailableFromAsyncAttributeArgumentsSyntax.self case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index d2236ad5347..7074d7d78dd 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -1203,6 +1203,46 @@ open class SyntaxRewriter { return visitChildren(node) } + /// Visit a ``LifetimeSpecifierArgumentListSyntax``. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + open func visit(_ node: LifetimeSpecifierArgumentListSyntax) -> LifetimeSpecifierArgumentListSyntax { + return visitChildren(node) + } + + /// Visit a ``LifetimeSpecifierArgumentSyntax``. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + open func visit(_ node: LifetimeSpecifierArgumentSyntax) -> LifetimeSpecifierArgumentSyntax { + 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 + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + open func visit(_ node: LifetimeTypeSpecifierSyntax) -> LifetimeTypeSpecifierSyntax { + return visitChildren(node) + } + /// Visit a ``MacroDeclSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -1644,6 +1684,13 @@ open class SyntaxRewriter { return visitChildren(node) } + /// Visit a ``SimpleTypeSpecifierSyntax``. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + open func visit(_ node: SimpleTypeSpecifierSyntax) -> SimpleTypeSpecifierSyntax { + return visitChildren(node) + } + /// Visit a ``SomeOrAnyTypeSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -1913,13 +1960,6 @@ open class SyntaxRewriter { return visitChildren(node) } - /// Visit a ``TypeSpecifierSyntax``. - /// - Parameter node: the node that is being visited - /// - Returns: the rewritten node - open func visit(_ node: TypeSpecifierSyntax) -> TypeSpecifierSyntax { - return visitChildren(node) - } - /// Visit a ``UnavailableFromAsyncAttributeArgumentsSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -2770,6 +2810,22 @@ open class SyntaxRewriter { return { self.visitImpl($0, LayoutRequirementSyntax.self, self.visit) } + case .lifetimeSpecifierArgumentList: + return { + self.visitImpl($0, LifetimeSpecifierArgumentListSyntax.self, self.visit) + } + case .lifetimeSpecifierArgument: + 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) + } case .macroDecl: return { self.visitImpl($0, MacroDeclSyntax.self, self.visit) @@ -3022,6 +3078,10 @@ open class SyntaxRewriter { return { self.visitImpl($0, SimpleStringLiteralSegmentListSyntax.self, self.visit) } + case .simpleTypeSpecifier: + return { + self.visitImpl($0, SimpleTypeSpecifierSyntax.self, self.visit) + } case .someOrAnyType: return { self.visitImpl($0, SomeOrAnyTypeSyntax.self, self.visit) @@ -3174,10 +3234,6 @@ open class SyntaxRewriter { return { self.visitImpl($0, TypeSpecifierListSyntax.self, self.visit) } - case .typeSpecifier: - return { - self.visitImpl($0, TypeSpecifierSyntax.self, self.visit) - } case .unavailableFromAsyncAttributeArguments: return { self.visitImpl($0, UnavailableFromAsyncAttributeArgumentsSyntax.self, self.visit) @@ -3580,6 +3636,14 @@ open class SyntaxRewriter { return visitImpl(node, LabeledStmtSyntax.self, visit) case .layoutRequirement: return visitImpl(node, LayoutRequirementSyntax.self, visit) + case .lifetimeSpecifierArgumentList: + 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: return visitImpl(node, MacroDeclSyntax.self, visit) case .macroExpansionDecl: @@ -3706,6 +3770,8 @@ open class SyntaxRewriter { return visitImpl(node, SimpleStringLiteralExprSyntax.self, visit) case .simpleStringLiteralSegmentList: return visitImpl(node, SimpleStringLiteralSegmentListSyntax.self, visit) + case .simpleTypeSpecifier: + return visitImpl(node, SimpleTypeSpecifierSyntax.self, visit) case .someOrAnyType: return visitImpl(node, SomeOrAnyTypeSyntax.self, visit) case .sourceFile: @@ -3782,8 +3848,6 @@ open class SyntaxRewriter { return visitImpl(node, TypeInitializerClauseSyntax.self, visit) case .typeSpecifierList: return visitImpl(node, TypeSpecifierListSyntax.self, visit) - case .typeSpecifier: - return visitImpl(node, TypeSpecifierSyntax.self, visit) case .unavailableFromAsyncAttributeArguments: return visitImpl(node, UnavailableFromAsyncAttributeArgumentsSyntax.self, visit) case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxTraits.swift b/Sources/SwiftSyntax/generated/SyntaxTraits.swift index 141fb95c423..ca1492597d0 100644 --- a/Sources/SwiftSyntax/generated/SyntaxTraits.swift +++ b/Sources/SwiftSyntax/generated/SyntaxTraits.swift @@ -761,6 +761,10 @@ extension LabeledExprSyntax: WithTrailingCommaSyntax {} extension LabeledSpecializeArgumentSyntax: WithTrailingCommaSyntax {} +extension LifetimeSpecifierArgumentSyntax: WithTrailingCommaSyntax {} + +extension LifetimeSpecifierArgumentsSyntax: ParenthesizedSyntax {} + extension MacroDeclSyntax: NamedDeclSyntax, WithAttributesSyntax, WithGenericParametersSyntax, WithModifiersSyntax {} extension MacroExpansionDeclSyntax: FreestandingMacroExpansionSyntax, WithAttributesSyntax, WithModifiersSyntax {} diff --git a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift index 528ef393627..52fc9d029ef 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -1960,6 +1960,78 @@ open class SyntaxVisitor { open func visitPost(_ node: LayoutRequirementSyntax) { } + /// Visiting ``LifetimeSpecifierArgumentListSyntax`` 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: LifetimeSpecifierArgumentListSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``LifetimeSpecifierArgumentListSyntax`` and its descendants. + /// - node: the node we just finished visiting. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + open func visitPost(_ node: LifetimeSpecifierArgumentListSyntax) { + } + + /// Visiting ``LifetimeSpecifierArgumentSyntax`` 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: LifetimeSpecifierArgumentSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``LifetimeSpecifierArgumentSyntax`` and its descendants. + /// - node: the node we just finished visiting. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + 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. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + open func visit(_ node: LifetimeTypeSpecifierSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``LifetimeTypeSpecifierSyntax`` and its descendants. + /// - node: the node we just finished visiting. + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + open func visitPost(_ node: LifetimeTypeSpecifierSyntax) { + } + /// Visiting ``MacroDeclSyntax`` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -2716,6 +2788,18 @@ open class SyntaxVisitor { open func visitPost(_ node: SimpleStringLiteralSegmentListSyntax) { } + /// Visiting ``SimpleTypeSpecifierSyntax`` specifically. + /// - Parameter node: the node we are visiting. + /// - Returns: how should we continue visiting. + open func visit(_ node: SimpleTypeSpecifierSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``SimpleTypeSpecifierSyntax`` and its descendants. + /// - node: the node we just finished visiting. + open func visitPost(_ node: SimpleTypeSpecifierSyntax) { + } + /// Visiting ``SomeOrAnyTypeSyntax`` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -3178,18 +3262,6 @@ open class SyntaxVisitor { open func visitPost(_ node: TypeSpecifierListSyntax) { } - /// Visiting ``TypeSpecifierSyntax`` specifically. - /// - Parameter node: the node we are visiting. - /// - Returns: how should we continue visiting. - open func visit(_ node: TypeSpecifierSyntax) -> SyntaxVisitorContinueKind { - return .visitChildren - } - - /// The function called after visiting ``TypeSpecifierSyntax`` and its descendants. - /// - node: the node we just finished visiting. - open func visitPost(_ node: TypeSpecifierSyntax) { - } - /// Visiting ``UnavailableFromAsyncAttributeArgumentsSyntax`` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -4108,6 +4180,22 @@ open class SyntaxVisitor { return { self.visitImpl($0, LayoutRequirementSyntax.self, self.visit, self.visitPost) } + case .lifetimeSpecifierArgumentList: + return { + self.visitImpl($0, LifetimeSpecifierArgumentListSyntax.self, self.visit, self.visitPost) + } + case .lifetimeSpecifierArgument: + 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) + } case .macroDecl: return { self.visitImpl($0, MacroDeclSyntax.self, self.visit, self.visitPost) @@ -4360,6 +4448,10 @@ open class SyntaxVisitor { return { self.visitImpl($0, SimpleStringLiteralSegmentListSyntax.self, self.visit, self.visitPost) } + case .simpleTypeSpecifier: + return { + self.visitImpl($0, SimpleTypeSpecifierSyntax.self, self.visit, self.visitPost) + } case .someOrAnyType: return { self.visitImpl($0, SomeOrAnyTypeSyntax.self, self.visit, self.visitPost) @@ -4512,10 +4604,6 @@ open class SyntaxVisitor { return { self.visitImpl($0, TypeSpecifierListSyntax.self, self.visit, self.visitPost) } - case .typeSpecifier: - return { - self.visitImpl($0, TypeSpecifierSyntax.self, self.visit, self.visitPost) - } case .unavailableFromAsyncAttributeArguments: return { self.visitImpl($0, UnavailableFromAsyncAttributeArgumentsSyntax.self, self.visit, self.visitPost) @@ -4921,6 +5009,14 @@ open class SyntaxVisitor { visitImpl(node, LabeledStmtSyntax.self, visit, visitPost) case .layoutRequirement: visitImpl(node, LayoutRequirementSyntax.self, visit, visitPost) + case .lifetimeSpecifierArgumentList: + 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: visitImpl(node, MacroDeclSyntax.self, visit, visitPost) case .macroExpansionDecl: @@ -5047,6 +5143,8 @@ open class SyntaxVisitor { visitImpl(node, SimpleStringLiteralExprSyntax.self, visit, visitPost) case .simpleStringLiteralSegmentList: visitImpl(node, SimpleStringLiteralSegmentListSyntax.self, visit, visitPost) + case .simpleTypeSpecifier: + visitImpl(node, SimpleTypeSpecifierSyntax.self, visit, visitPost) case .someOrAnyType: visitImpl(node, SomeOrAnyTypeSyntax.self, visit, visitPost) case .sourceFile: @@ -5123,8 +5221,6 @@ open class SyntaxVisitor { visitImpl(node, TypeInitializerClauseSyntax.self, visit, visitPost) case .typeSpecifierList: visitImpl(node, TypeSpecifierListSyntax.self, visit, visitPost) - case .typeSpecifier: - visitImpl(node, TypeSpecifierSyntax.self, visit, visitPost) case .unavailableFromAsyncAttributeArguments: visitImpl(node, UnavailableFromAsyncAttributeArgumentsSyntax.self, visit, visitPost) case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift index ed262df2bda..d5e9ab34c9d 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift @@ -923,6 +923,290 @@ public struct RawLayoutRequirementSyntax: RawSyntaxNodeProtocol { } } +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +@_spi(RawSyntax) +public struct RawLifetimeSpecifierArgumentListSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .lifetimeSpecifierArgumentList + } + + 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(elements: [RawLifetimeSpecifierArgumentSyntax], arena: __shared SyntaxArena) { + let raw = RawSyntax.makeLayout( + kind: .lifetimeSpecifierArgumentList, uninitializedCount: elements.count, arena: arena) { layout in + guard var ptr = layout.baseAddress else { + return + } + for elem in elements { + ptr.initialize(to: elem.raw) + ptr += 1 + } + } + self.init(unchecked: raw) + } + + public var elements: [RawLifetimeSpecifierArgumentSyntax] { + layoutView.children.map { + RawLifetimeSpecifierArgumentSyntax(raw: $0!) + } + } +} + +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +@_spi(RawSyntax) +public struct RawLifetimeSpecifierArgumentSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .lifetimeSpecifierArgument + } + + 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( + _ unexpectedBeforeParameter: RawUnexpectedNodesSyntax? = nil, + parameter: RawTokenSyntax, + _ unexpectedBetweenParameterAndTrailingComma: RawUnexpectedNodesSyntax? = nil, + trailingComma: RawTokenSyntax?, + _ unexpectedAfterTrailingComma: RawUnexpectedNodesSyntax? = nil, + arena: __shared SyntaxArena + ) { + let raw = RawSyntax.makeLayout( + kind: .lifetimeSpecifierArgument, uninitializedCount: 5, arena: arena) { layout in + layout.initialize(repeating: nil) + layout[0] = unexpectedBeforeParameter?.raw + layout[1] = parameter.raw + layout[2] = unexpectedBetweenParameterAndTrailingComma?.raw + layout[3] = trailingComma?.raw + layout[4] = unexpectedAfterTrailingComma?.raw + } + self.init(unchecked: raw) + } + + public var unexpectedBeforeParameter: RawUnexpectedNodesSyntax? { + layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var parameter: RawTokenSyntax { + layoutView.children[1].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedBetweenParameterAndTrailingComma: RawUnexpectedNodesSyntax? { + layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var trailingComma: RawTokenSyntax? { + layoutView.children[3].map(RawTokenSyntax.init(raw:)) + } + + public var unexpectedAfterTrailingComma: RawUnexpectedNodesSyntax? { + layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) + } +} + +#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( + _ unexpectedBeforeLeftParen: RawUnexpectedNodesSyntax? = nil, + leftParen: RawTokenSyntax, + _ unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? = nil, + arguments: RawLifetimeSpecifierArgumentListSyntax, + _ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil, + rightParen: RawTokenSyntax, + _ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil, + arena: __shared SyntaxArena + ) { + let raw = RawSyntax.makeLayout( + kind: .lifetimeSpecifierArguments, uninitializedCount: 7, arena: arena) { layout in + layout.initialize(repeating: nil) + layout[0] = unexpectedBeforeLeftParen?.raw + layout[1] = leftParen.raw + layout[2] = unexpectedBetweenLeftParenAndArguments?.raw + layout[3] = arguments.raw + layout[4] = unexpectedBetweenArgumentsAndRightParen?.raw + layout[5] = rightParen.raw + layout[6] = unexpectedAfterRightParen?.raw + } + self.init(unchecked: raw) + } + + public var unexpectedBeforeLeftParen: RawUnexpectedNodesSyntax? { + layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var leftParen: RawTokenSyntax { + layoutView.children[1].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? { + layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var arguments: RawLifetimeSpecifierArgumentListSyntax { + layoutView.children[3].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))! + } + + public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? { + layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var rightParen: RawTokenSyntax { + layoutView.children[5].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedAfterRightParen: RawUnexpectedNodesSyntax? { + layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:)) + } +} + +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +@_spi(RawSyntax) +public struct RawLifetimeTypeSpecifierSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .lifetimeTypeSpecifier + } + + 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( + _ unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? = nil, + specifier: RawTokenSyntax, + _ unexpectedBetweenSpecifierAndArguments: RawUnexpectedNodesSyntax? = nil, + arguments: RawLifetimeSpecifierArgumentsSyntax, + _ unexpectedAfterArguments: RawUnexpectedNodesSyntax? = nil, + arena: __shared SyntaxArena + ) { + let raw = RawSyntax.makeLayout( + kind: .lifetimeTypeSpecifier, uninitializedCount: 5, arena: arena) { layout in + layout.initialize(repeating: nil) + layout[0] = unexpectedBeforeSpecifier?.raw + layout[1] = specifier.raw + layout[2] = unexpectedBetweenSpecifierAndArguments?.raw + layout[3] = arguments.raw + layout[4] = unexpectedAfterArguments?.raw + } + self.init(unchecked: raw) + } + + public var unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? { + layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var specifier: RawTokenSyntax { + layoutView.children[1].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedBetweenSpecifierAndArguments: RawUnexpectedNodesSyntax? { + layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var arguments: RawLifetimeSpecifierArgumentsSyntax { + layoutView.children[3].map(RawLifetimeSpecifierArgumentsSyntax.init(raw:))! + } + + public var unexpectedAfterArguments: RawUnexpectedNodesSyntax? { + layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) + } +} + @_spi(RawSyntax) public struct RawMacroDeclSyntax: RawDeclSyntaxNodeProtocol { @_spi(RawSyntax) diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift index 3ab1677a46e..37afa2bd9b7 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift @@ -627,6 +627,64 @@ public struct RawSimpleStringLiteralSegmentListSyntax: RawSyntaxNodeProtocol { } } +@_spi(RawSyntax) +public struct RawSimpleTypeSpecifierSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .simpleTypeSpecifier + } + + 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( + _ unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? = nil, + specifier: RawTokenSyntax, + _ unexpectedAfterSpecifier: RawUnexpectedNodesSyntax? = nil, + arena: __shared SyntaxArena + ) { + let raw = RawSyntax.makeLayout( + kind: .simpleTypeSpecifier, uninitializedCount: 3, arena: arena) { layout in + layout.initialize(repeating: nil) + layout[0] = unexpectedBeforeSpecifier?.raw + layout[1] = specifier.raw + layout[2] = unexpectedAfterSpecifier?.raw + } + self.init(unchecked: raw) + } + + public var unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? { + layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var specifier: RawTokenSyntax { + layoutView.children[1].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedAfterSpecifier: RawUnexpectedNodesSyntax? { + layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + } +} + @_spi(RawSyntax) public struct RawSomeOrAnyTypeSyntax: RawTypeSyntaxNodeProtocol { @_spi(RawSyntax) diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift index 67a1eab6807..699833eb983 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift @@ -1410,6 +1410,36 @@ public struct RawTypeInitializerClauseSyntax: RawSyntaxNodeProtocol { @_spi(RawSyntax) public struct RawTypeSpecifierListSyntax: RawSyntaxNodeProtocol { + public enum Element: RawSyntaxNodeProtocol { + case `simpleTypeSpecifier`(RawSimpleTypeSpecifierSyntax) + case `lifetimeTypeSpecifier`(RawLifetimeTypeSpecifierSyntax) + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return RawSimpleTypeSpecifierSyntax.isKindOf(raw) || RawLifetimeTypeSpecifierSyntax.isKindOf(raw) + } + + public var raw: RawSyntax { + switch self { + case .simpleTypeSpecifier(let node): + return node.raw + case .lifetimeTypeSpecifier(let node): + return node.raw + } + } + + public init?(_ other: some RawSyntaxNodeProtocol) { + if let node = RawSimpleTypeSpecifierSyntax(other) { + self = .simpleTypeSpecifier(node) + return + } + if let node = RawLifetimeTypeSpecifierSyntax(other) { + self = .lifetimeTypeSpecifier(node) + return + } + return nil + } + } + @_spi(RawSyntax) public var layoutView: RawSyntaxLayoutView { return raw.layoutView! @@ -1437,7 +1467,7 @@ public struct RawTypeSpecifierListSyntax: RawSyntaxNodeProtocol { self.init(unchecked: other.raw) } - public init(elements: [RawTypeSpecifierSyntax], arena: __shared SyntaxArena) { + public init(elements: [Element], arena: __shared SyntaxArena) { let raw = RawSyntax.makeLayout( kind: .typeSpecifierList, uninitializedCount: elements.count, arena: arena) { layout in guard var ptr = layout.baseAddress else { @@ -1451,68 +1481,10 @@ public struct RawTypeSpecifierListSyntax: RawSyntaxNodeProtocol { self.init(unchecked: raw) } - public var elements: [RawTypeSpecifierSyntax] { + public var elements: [RawSyntax] { layoutView.children.map { - RawTypeSpecifierSyntax(raw: $0!) - } - } -} - -@_spi(RawSyntax) -public struct RawTypeSpecifierSyntax: RawSyntaxNodeProtocol { - @_spi(RawSyntax) - public var layoutView: RawSyntaxLayoutView { - return raw.layoutView! - } - - public static func isKindOf(_ raw: RawSyntax) -> Bool { - return raw.kind == .typeSpecifier - } - - 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( - _ unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? = nil, - specifier: RawTokenSyntax, - _ unexpectedAfterSpecifier: RawUnexpectedNodesSyntax? = nil, - arena: __shared SyntaxArena - ) { - let raw = RawSyntax.makeLayout( - kind: .typeSpecifier, uninitializedCount: 3, arena: arena) { layout in - layout.initialize(repeating: nil) - layout[0] = unexpectedBeforeSpecifier?.raw - layout[1] = specifier.raw - layout[2] = unexpectedAfterSpecifier?.raw + RawSyntax(raw: $0!) } - self.init(unchecked: raw) - } - - public var unexpectedBeforeSpecifier: RawUnexpectedNodesSyntax? { - layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) - } - - public var specifier: RawTokenSyntax { - layoutView.children[1].map(RawTokenSyntax.init(raw:))! - } - - public var unexpectedAfterSpecifier: RawUnexpectedNodesSyntax? { - layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } } diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index 9b74eb0d3f1..8d22721337f 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -1714,6 +1714,38 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 14, verify(layout[14], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 15, verify(layout[15], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.rightParen)])) assertNoError(kind, 16, verify(layout[16], as: RawUnexpectedNodesSyntax?.self)) + case .lifetimeSpecifierArgumentList: + for (index, element) in layout.enumerated() { + assertNoError(kind, index, verify(element, as: RawLifetimeSpecifierArgumentSyntax.self)) + } + case .lifetimeSpecifierArgument: + assert(layout.count == 5) + assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.identifier), .keyword("self"), .tokenKind(.integerLiteral)])) + assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.comma)])) + assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) + case .lifetimeSpecifierArguments: + assert(layout.count == 7) + assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.leftParen)])) + assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawLifetimeSpecifierArgumentListSyntax.self)) + assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 5, verify(layout[5], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.rightParen)])) + assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) + case .lifetimeTypeSpecifier: + assert(layout.count == 5) + assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ + .keyword("_copy"), + .keyword("_consume"), + .keyword("_borrow"), + .keyword("_mutate") + ])) + assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawLifetimeSpecifierArgumentsSyntax.self)) + assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) case .macroDecl: assert(layout.count == 17) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) @@ -2262,6 +2294,21 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { for (index, element) in layout.enumerated() { assertNoError(kind, index, verify(element, as: RawStringSegmentSyntax.self)) } + case .simpleTypeSpecifier: + assert(layout.count == 3) + assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ + .keyword("inout"), + .keyword("__shared"), + .keyword("__owned"), + .keyword("isolated"), + .keyword("_const"), + .keyword("borrowing"), + .keyword("consuming"), + .keyword("transferring"), + .keyword("_resultDependsOn") + ])) + assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) case .someOrAnyType: assert(layout.count == 5) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) @@ -2611,23 +2658,10 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) case .typeSpecifierList: for (index, element) in layout.enumerated() { - assertNoError(kind, index, verify(element, as: RawTypeSpecifierSyntax.self)) + assertAnyHasNoError(kind, index, [ + verify(element, as: RawSimpleTypeSpecifierSyntax.self), + verify(element, as: RawLifetimeTypeSpecifierSyntax.self)]) } - case .typeSpecifier: - assert(layout.count == 3) - assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ - .keyword("inout"), - .keyword("__shared"), - .keyword("__owned"), - .keyword("isolated"), - .keyword("_const"), - .keyword("borrowing"), - .keyword("consuming"), - .keyword("transferring"), - .keyword("_resultDependsOn") - ])) - assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) case .unavailableFromAsyncAttributeArguments: assert(layout.count == 7) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index 7b8a09d0d6e..88645b6cba8 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -3347,7 +3347,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp /// - returns: A copy of the receiver with the provided `Specifier` /// appended to its `specifiers` collection. @available(*, deprecated, message: "Use node.specifiers.append(newElement) instead") - public func addSpecifier(_ element: TypeSpecifierSyntax) -> AttributedTypeSyntax { + public func addSpecifier(_ element: Syntax) -> AttributedTypeSyntax { var collection: RawSyntax let arena = SyntaxArena() if let col = raw.layoutView!.children[1] { diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index 6c0c35c2565..fcdb4e26fc3 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -1652,6 +1652,463 @@ public struct LayoutRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynt } } +// MARK: - LifetimeSpecifierArgumentSyntax + +/// A single argument that can be added to a lifetime specifier like `borrow`, `mutate`, `consume` or `copy`. +/// +/// ### Example +/// `data` in `func foo(data: Array<Item>) -> borrow(data) ComplexReferenceType` +/// +/// - Experiment: Requires experimental feature `nonescapableTypes`. +/// +/// ### Children +/// +/// - `parameter`: (`<identifier>` | `self` | `<integerLiteral>`) +/// - `trailingComma`: `,`? +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +public struct LifetimeSpecifierArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .lifetimeSpecifierArgument else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + /// - Parameters: + /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - parameter: The parameter on which the lifetime of this type depends. + /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforeParameter: UnexpectedNodesSyntax? = nil, + parameter: TokenSyntax, + _ unexpectedBetweenParameterAndTrailingComma: UnexpectedNodesSyntax? = nil, + trailingComma: TokenSyntax? = nil, + _ unexpectedAfterTrailingComma: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + + ) { + // Extend the lifetime of all parameters so their arenas don't get destroyed + // before they can be added as children of the new arena. + self = withExtendedLifetime((SyntaxArena(), ( + unexpectedBeforeParameter, + parameter, + unexpectedBetweenParameterAndTrailingComma, + trailingComma, + unexpectedAfterTrailingComma + ))) { (arena, _) in + let layout: [RawSyntax?] = [ + unexpectedBeforeParameter?.raw, + parameter.raw, + unexpectedBetweenParameterAndTrailingComma?.raw, + trailingComma?.raw, + unexpectedAfterTrailingComma?.raw + ] + let raw = RawSyntax.makeLayout( + kind: SyntaxKind.lifetimeSpecifierArgument, + from: layout, + arena: arena, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia + + ) + return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) + } + } + + public var unexpectedBeforeParameter: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentSyntax.self) + } + } + + /// The parameter on which the lifetime of this type depends. + /// + /// This can be an identifier referring to an external parameter name, an integer literal to refer to an unnamed + /// parameter or `self` if the type's lifetime depends on the object the method is called on. + /// + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: + /// - `<identifier>` + /// - `self` + /// - `<integerLiteral>` + public var parameter: TokenSyntax { + get { + return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentSyntax.self) + } + } + + public var unexpectedBetweenParameterAndTrailingComma: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentSyntax.self) + } + } + + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be `,`. + public var trailingComma: TokenSyntax? { + get { + return Syntax(self).child(at: 3)?.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentSyntax.self) + } + } + + public var unexpectedAfterTrailingComma: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentSyntax.self) + } + } + + public static var structure: SyntaxNodeStructure { + return .layout([ + \Self.unexpectedBeforeParameter, + \Self.parameter, + \Self.unexpectedBetweenParameterAndTrailingComma, + \Self.trailingComma, + \Self.unexpectedAfterTrailingComma + ]) + } +} + +// MARK: - LifetimeSpecifierArgumentsSyntax + +/// An optional argument passed to a type parameter. +/// +/// ### Example +/// `borrow(data)` in `func foo(data: Array<Item>) -> borrow(data) ComplexReferenceType` +/// +/// - Experiment: Requires experimental feature `nonescapableTypes`. +/// +/// ### Children +/// +/// - `leftParen`: `(` +/// - `arguments`: ``LifetimeSpecifierArgumentListSyntax`` +/// - `rightParen`: `)` +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .lifetimeSpecifierArguments else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + /// - Parameters: + /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - arguments: The function parameters that the lifetime of the annotated type depends on. + /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforeLeftParen: UnexpectedNodesSyntax? = nil, + leftParen: TokenSyntax = .leftParenToken(), + _ unexpectedBetweenLeftParenAndArguments: UnexpectedNodesSyntax? = nil, + arguments: LifetimeSpecifierArgumentListSyntax, + _ unexpectedBetweenArgumentsAndRightParen: UnexpectedNodesSyntax? = nil, + rightParen: TokenSyntax = .rightParenToken(), + _ unexpectedAfterRightParen: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + + ) { + // Extend the lifetime of all parameters so their arenas don't get destroyed + // before they can be added as children of the new arena. + self = withExtendedLifetime((SyntaxArena(), ( + unexpectedBeforeLeftParen, + leftParen, + unexpectedBetweenLeftParenAndArguments, + arguments, + unexpectedBetweenArgumentsAndRightParen, + rightParen, + unexpectedAfterRightParen + ))) { (arena, _) in + let layout: [RawSyntax?] = [ + unexpectedBeforeLeftParen?.raw, + leftParen.raw, + unexpectedBetweenLeftParenAndArguments?.raw, + arguments.raw, + unexpectedBetweenArgumentsAndRightParen?.raw, + rightParen.raw, + unexpectedAfterRightParen?.raw + ] + let raw = RawSyntax.makeLayout( + kind: SyntaxKind.lifetimeSpecifierArguments, + from: layout, + arena: arena, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia + + ) + return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) + } + } + + public var unexpectedBeforeLeftParen: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be `(`. + public var leftParen: TokenSyntax { + get { + return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + public var unexpectedBetweenLeftParenAndArguments: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + /// The function parameters that the lifetime of the annotated type depends on. + public var arguments: LifetimeSpecifierArgumentListSyntax { + get { + return Syntax(self).child(at: 3)!.cast(LifetimeSpecifierArgumentListSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + /// Adds the provided `element` to the node's `arguments` + /// collection. + /// + /// - param element: The new `Arguments` to add to the node's + /// `arguments` collection. + /// - returns: A copy of the receiver with the provided `Arguments` + /// appended to its `arguments` collection. + @available(*, deprecated, message: "Use node.arguments.append(newElement) instead") + public func addArguments(_ element: LifetimeSpecifierArgumentSyntax) -> LifetimeSpecifierArgumentsSyntax { + var collection: RawSyntax + let arena = SyntaxArena() + if let col = raw.layoutView!.children[3] { + collection = col.layoutView!.appending(element.raw, arena: arena) + } else { + collection = RawSyntax.makeLayout(kind: SyntaxKind.lifetimeSpecifierArgumentList, + from: [element.raw], arena: arena) + } + return Syntax(self) + .replacingChild( + at: 3, + with: collection, + rawNodeArena: arena, + allocationArena: arena + ) + .cast(LifetimeSpecifierArgumentsSyntax.self) + } + + public var unexpectedBetweenArgumentsAndRightParen: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be `)`. + public var rightParen: TokenSyntax { + get { + return Syntax(self).child(at: 5)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + public var unexpectedAfterRightParen: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 6)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + } + } + + public static var structure: SyntaxNodeStructure { + return .layout([ + \Self.unexpectedBeforeLeftParen, + \Self.leftParen, + \Self.unexpectedBetweenLeftParenAndArguments, + \Self.arguments, + \Self.unexpectedBetweenArgumentsAndRightParen, + \Self.rightParen, + \Self.unexpectedAfterRightParen + ]) + } +} + +// MARK: - LifetimeTypeSpecifierSyntax + +/// A specifier that specifies function parameter on whose lifetime a type depends +/// +/// - Experiment: Requires experimental feature `nonescapableTypes`. +/// +/// ### Children +/// +/// - `specifier`: (`_copy` | `_consume` | `_borrow` | `_mutate`) +/// - `arguments`: ``LifetimeSpecifierArgumentsSyntax`` +/// +/// ### Contained in +/// +/// - ``TypeSpecifierListSyntax`` +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +public struct LifetimeTypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .lifetimeTypeSpecifier else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + /// - Parameters: + /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - specifier: The specifier token that's attached to the type. + /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforeSpecifier: UnexpectedNodesSyntax? = nil, + specifier: TokenSyntax, + _ unexpectedBetweenSpecifierAndArguments: UnexpectedNodesSyntax? = nil, + arguments: LifetimeSpecifierArgumentsSyntax, + _ unexpectedAfterArguments: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + + ) { + // Extend the lifetime of all parameters so their arenas don't get destroyed + // before they can be added as children of the new arena. + self = withExtendedLifetime((SyntaxArena(), ( + unexpectedBeforeSpecifier, + specifier, + unexpectedBetweenSpecifierAndArguments, + arguments, + unexpectedAfterArguments + ))) { (arena, _) in + let layout: [RawSyntax?] = [ + unexpectedBeforeSpecifier?.raw, + specifier.raw, + unexpectedBetweenSpecifierAndArguments?.raw, + arguments.raw, + unexpectedAfterArguments?.raw + ] + let raw = RawSyntax.makeLayout( + kind: SyntaxKind.lifetimeTypeSpecifier, + from: layout, + arena: arena, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia + + ) + return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) + } + } + + public var unexpectedBeforeSpecifier: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) + } + } + + /// The specifier token that's attached to the type. + /// + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: + /// - `_copy` + /// - `_consume` + /// - `_borrow` + /// - `_mutate` + public var specifier: TokenSyntax { + get { + return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) + } + } + + public var unexpectedBetweenSpecifierAndArguments: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) + } + } + + public var arguments: LifetimeSpecifierArgumentsSyntax { + get { + return Syntax(self).child(at: 3)!.cast(LifetimeSpecifierArgumentsSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) + } + } + + public var unexpectedAfterArguments: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) + } + } + + public static var structure: SyntaxNodeStructure { + return .layout([ + \Self.unexpectedBeforeSpecifier, + \Self.specifier, + \Self.unexpectedBetweenSpecifierAndArguments, + \Self.arguments, + \Self.unexpectedAfterArguments + ]) + } +} + // MARK: - MacroDeclSyntax /// ### Children diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift index bf00274d194..c58d6442104 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift @@ -1084,6 +1084,101 @@ public struct SimpleStringLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable, } } +// MARK: - SimpleTypeSpecifierSyntax + +/// A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming` +/// +/// ### Children +/// +/// - `specifier`: (`inout` | `__shared` | `__owned` | `isolated` | `_const` | `borrowing` | `consuming` | `transferring` | `_resultDependsOn`) +/// +/// ### Contained in +/// +/// - ``TypeSpecifierListSyntax`` +public struct SimpleTypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { + public let _syntaxNode: Syntax + + public init?(_ node: some SyntaxProtocol) { + guard node.raw.kind == .simpleTypeSpecifier else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + /// - Parameters: + /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - specifier: The specifier token that's attached to the type. + /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforeSpecifier: UnexpectedNodesSyntax? = nil, + specifier: TokenSyntax, + _ unexpectedAfterSpecifier: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + + ) { + // Extend the lifetime of all parameters so their arenas don't get destroyed + // before they can be added as children of the new arena. + self = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeSpecifier, specifier, unexpectedAfterSpecifier))) { (arena, _) in + let layout: [RawSyntax?] = [unexpectedBeforeSpecifier?.raw, specifier.raw, unexpectedAfterSpecifier?.raw] + let raw = RawSyntax.makeLayout( + kind: SyntaxKind.simpleTypeSpecifier, + from: layout, + arena: arena, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia + + ) + return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) + } + } + + public var unexpectedBeforeSpecifier: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(SimpleTypeSpecifierSyntax.self) + } + } + + /// The specifier token that's attached to the type. + /// + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: + /// - `inout` + /// - `__shared` + /// - `__owned` + /// - `isolated` + /// - `_const` + /// - `borrowing` + /// - `consuming` + /// - `transferring` + /// - `_resultDependsOn` + public var specifier: TokenSyntax { + get { + return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(SimpleTypeSpecifierSyntax.self) + } + } + + public var unexpectedAfterSpecifier: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(SimpleTypeSpecifierSyntax.self) + } + } + + public static var structure: SyntaxNodeStructure { + return .layout([\Self.unexpectedBeforeSpecifier, \Self.specifier, \Self.unexpectedAfterSpecifier]) + } +} + // MARK: - SomeOrAnyTypeSyntax /// ### Children diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index 14530f55935..e9e1eb7a67a 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -2588,101 +2588,6 @@ public struct TypeInitializerClauseSyntax: SyntaxProtocol, SyntaxHashable, _Leaf } } -// MARK: - TypeSpecifierSyntax - -/// A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming` -/// -/// ### Children -/// -/// - `specifier`: (`inout` | `__shared` | `__owned` | `isolated` | `_const` | `borrowing` | `consuming` | `transferring` | `_resultDependsOn`) -/// -/// ### Contained in -/// -/// - ``TypeSpecifierListSyntax`` -public struct TypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { - public let _syntaxNode: Syntax - - public init?(_ node: some SyntaxProtocol) { - guard node.raw.kind == .typeSpecifier else { - return nil - } - self._syntaxNode = node._syntaxNode - } - - /// - Parameters: - /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. - /// - specifier: The specifier token that's attached to the type. - /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. - public init( - leadingTrivia: Trivia? = nil, - _ unexpectedBeforeSpecifier: UnexpectedNodesSyntax? = nil, - specifier: TokenSyntax, - _ unexpectedAfterSpecifier: UnexpectedNodesSyntax? = nil, - trailingTrivia: Trivia? = nil - - ) { - // Extend the lifetime of all parameters so their arenas don't get destroyed - // before they can be added as children of the new arena. - self = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeSpecifier, specifier, unexpectedAfterSpecifier))) { (arena, _) in - let layout: [RawSyntax?] = [unexpectedBeforeSpecifier?.raw, specifier.raw, unexpectedAfterSpecifier?.raw] - let raw = RawSyntax.makeLayout( - kind: SyntaxKind.typeSpecifier, - from: layout, - arena: arena, - leadingTrivia: leadingTrivia, - trailingTrivia: trailingTrivia - - ) - return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) - } - } - - public var unexpectedBeforeSpecifier: UnexpectedNodesSyntax? { - get { - return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(TypeSpecifierSyntax.self) - } - } - - /// The specifier token that's attached to the type. - /// - /// ### Tokens - /// - /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: - /// - `inout` - /// - `__shared` - /// - `__owned` - /// - `isolated` - /// - `_const` - /// - `borrowing` - /// - `consuming` - /// - `transferring` - /// - `_resultDependsOn` - public var specifier: TokenSyntax { - get { - return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(TypeSpecifierSyntax.self) - } - } - - public var unexpectedAfterSpecifier: UnexpectedNodesSyntax? { - get { - return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(TypeSpecifierSyntax.self) - } - } - - public static var structure: SyntaxNodeStructure { - return .layout([\Self.unexpectedBeforeSpecifier, \Self.specifier, \Self.unexpectedAfterSpecifier]) - } -} - // MARK: - UnavailableFromAsyncAttributeArgumentsSyntax /// The arguments for the '@_unavailableFromAsync' attribute diff --git a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift index 7287117a327..6a48ae96427 100644 --- a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift +++ b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if swift(>=6) -public import SwiftSyntax +@_spi(ExperimentalLanguageFeatures) public import SwiftSyntax #else -import SwiftSyntax +@_spi(ExperimentalLanguageFeatures) import SwiftSyntax #endif // MARK: - AccessorDeclListBuilder @@ -429,6 +429,22 @@ public extension LabeledExprListSyntax { } } +// MARK: - LifetimeSpecifierArgumentListBuilder + +@resultBuilder +#if compiler(>=5.8) +@_spi(ExperimentalLanguageFeatures) +#endif +public struct LifetimeSpecifierArgumentListBuilder: ListBuilder { + public typealias FinalResult = LifetimeSpecifierArgumentListSyntax +} + +public extension LifetimeSpecifierArgumentListSyntax { + init(@LifetimeSpecifierArgumentListBuilder itemsBuilder: () throws -> LifetimeSpecifierArgumentListSyntax) rethrows { + self = try itemsBuilder() + } +} + // MARK: - MemberBlockItemListBuilder @resultBuilder @@ -673,6 +689,17 @@ public extension TupleTypeElementListSyntax { @resultBuilder public struct TypeSpecifierListBuilder: ListBuilder { public typealias FinalResult = TypeSpecifierListSyntax + + public static func buildExpression(_ expression: SimpleTypeSpecifierSyntax) -> Component { + buildExpression(.init(expression)) + } + + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + public static func buildExpression(_ expression: LifetimeTypeSpecifierSyntax) -> Component { + buildExpression(.init(expression)) + } } public extension TypeSpecifierListSyntax { diff --git a/Tests/SwiftParserTest/TypeTests.swift b/Tests/SwiftParserTest/TypeTests.swift index db1ccb066c5..a06caabf286 100644 --- a/Tests/SwiftParserTest/TypeTests.swift +++ b/Tests/SwiftParserTest/TypeTests.swift @@ -325,4 +325,94 @@ final class TypeTests: ParserTestCase { assertParse("func foo1(_ a: _const borrowing String) {}") assertParse("func foo2(_ a: borrowing _const String) {}") } + + func testLifetimeSpecifier() { + assertParse("func foo() -> _borrow(x) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse("func foo() -> _borrow(x, y) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse( + "func foo() -> _borrow(1️⃣) X", + diagnostics: [ + DiagnosticSpec(locationMarker: "1️⃣", message: "expected parameter reference in lifetime specifier", fixIts: ["insert parameter reference"]) + ], + fixedSource: "func foo() -> _borrow(<#identifier#>) X", + experimentalFeatures: [.nonescapableTypes] + ) + + assertParse( + "func foo() -> _borrow(x,1️⃣) X", + diagnostics: [ + DiagnosticSpec(locationMarker: "1️⃣", message: "expected parameter reference in lifetime specifier", fixIts: ["insert parameter reference"]) + ], + fixedSource: "func foo() -> _borrow(x, <#identifier#>) X", + experimentalFeatures: [.nonescapableTypes] + ) + + assertParse("func foo() -> _borrow(x) _borrow(y) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse("func foo() -> _mutate(x) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse("func foo() -> _copy(x) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse("func foo() -> _consume(x) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse( + "func foo() -> _borrow 1️⃣X", + diagnostics: [ + DiagnosticSpec( + locationMarker: "1️⃣", + message: "expected '(', parameter reference, and ')' in lifetime specifier", + fixIts: ["insert '(', parameter reference, and ')'"] + ) + ], + fixedSource: "func foo() -> _borrow (<#identifier#>) X", + experimentalFeatures: [.nonescapableTypes] + ) + + assertParse( + "func foo() -> _borrow(1️⃣*) X", + diagnostics: [ + DiagnosticSpec(locationMarker: "1️⃣", message: "expected parameter reference in lifetime specifier", fixIts: ["insert parameter reference"]), + DiagnosticSpec(locationMarker: "1️⃣", message: "unexpected code '*' in lifetime specifier"), + ], + fixedSource: "func foo() -> _borrow(<#identifier#>*) X", + experimentalFeatures: [.nonescapableTypes] + ) + + assertParse("func foo() -> _borrow(0) X", diagnostics: [], experimentalFeatures: [.nonescapableTypes]) + + assertParse("func foo() -> _borrow(self) X", experimentalFeatures: [.nonescapableTypes]) + + assertParse( + "func foo() -> _borrow1️⃣(0)2️⃣ X", + diagnostics: [ + DiagnosticSpec( + locationMarker: "1️⃣", + message: "consecutive statements on a line must be separated by newline or ';'", + fixIts: ["insert newline", "insert ';'"] + ), + DiagnosticSpec( + locationMarker: "2️⃣", + message: "consecutive statements on a line must be separated by newline or ';'", + fixIts: ["insert newline", "insert ';'"] + ), + ], + fixedSource: """ + func foo() -> _borrow + (0) + X + """ + ) + + assertParse( + "func foo() -> _borrow(1️⃣-1) X", + diagnostics: [ + DiagnosticSpec(message: "expected parameter reference in lifetime specifier", fixIts: ["insert parameter reference"]), + DiagnosticSpec(message: "unexpected code '-1' in lifetime specifier"), + ], + fixedSource: "func foo() -> _borrow(<#identifier#>-1) X", + experimentalFeatures: [.nonescapableTypes] + ) + } } From 3df63e8c81669f6bae7002ad98d7819b24b6f8ea Mon Sep 17 00:00:00 2001 From: Alex Hoppen <ahoppen@apple.com> Date: Tue, 12 Mar 2024 13:01:59 -0700 Subject: [PATCH 4/4] Render references to experimental syntax nodes in code font instead of as docc links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docc doesn’t like references to SPI types because they are not part of the public API. --- .../SyntaxSupport/GrammarGenerator.swift | 4 ++-- .../Sources/SyntaxSupport/Node.swift | 14 ++++------- .../SyntaxSupport/SyntaxNodeKind.swift | 11 +++++++++ .../swiftsyntax/SyntaxBaseNodesFile.swift | 16 ++++++------- .../swiftsyntax/SyntaxNodeCasting.swift | 10 ++++---- .../swiftsyntax/SyntaxRewriterFile.swift | 4 ++-- .../swiftsyntax/SyntaxVisitorFile.swift | 4 ++-- .../generated/SyntaxBaseNodes.swift | 10 ++++---- .../generated/SyntaxCollections.swift | 14 +++++------ .../generated/SyntaxRewriter.swift | 12 +++++----- .../SwiftSyntax/generated/SyntaxVisitor.swift | 24 +++++++++---------- .../syntaxNodes/SyntaxNodesJKLMN.swift | 4 ++-- 12 files changed, 67 insertions(+), 60 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift b/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift index deeadde1d6f..aa7e4924e70 100644 --- a/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift +++ b/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift @@ -37,12 +37,12 @@ struct GrammarGenerator { let optionality = child.isOptional ? "?" : "" switch child.kind { case .node(let kind): - return "``\(kind.syntaxType)``\(optionality)" + return "\(kind.doccLink)\(optionality)" case .nodeChoices(let choices): let choicesDescriptions = choices.map { grammar(for: $0) } return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)" case .collection(kind: let kind, _, _, _): - return "``\(kind.syntaxType)``\(optionality)" + return "\(kind.doccLink)\(optionality)" case .token(let choices, _, _): if choices.count == 1 { return "\(grammar(for: choices.first!))\(optionality)" diff --git a/CodeGeneration/Sources/SyntaxSupport/Node.swift b/CodeGeneration/Sources/SyntaxSupport/Node.swift index 8dec2860a96..5fec1d979a0 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Node.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Node.swift @@ -224,9 +224,9 @@ public class Node { // This will repeat the syntax type before and after the dot, which is // a little unfortunate, but it's the only way I found to get docc to // generate a fully-qualified type + member. - return " - ``\($0.node.syntaxType)``.``\($0.node.syntaxType)/\(childName)``" + return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``" } else { - return " - ``\($0.node.syntaxType)``" + return " - \($0.node.doccLink)" } } .joined(separator: "\n") @@ -249,7 +249,7 @@ public class Node { let list = SYNTAX_NODES .filter { $0.base == self.kind && !$0.isExperimental } - .map { "- ``\($0.kind.syntaxType)``" } + .map { "- \($0.kind.doccLink)" } .joined(separator: "\n") guard !list.isEmpty else { @@ -392,9 +392,9 @@ public struct CollectionNode { public var grammar: SwiftSyntax.Trivia { let grammar: String if let onlyElement = elementChoices.only { - grammar = "``\(onlyElement.syntaxType)`` `*`" + grammar = "\(onlyElement.doccLink) `*`" } else { - grammar = "(\(elementChoices.map { "``\($0.syntaxType)``" }.joined(separator: " | "))) `*`" + grammar = "(\(elementChoices.map { "\($0.doccLink)" }.joined(separator: " | "))) `*`" } return .docCommentTrivia( @@ -421,7 +421,3 @@ fileprivate extension Child { } } } - -fileprivate extension Node { - -} diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift index 1d36a8ed80d..5ea26147675 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift @@ -355,6 +355,17 @@ public enum SyntaxNodeKind: String, CaseIterable { } } + /// If this node is non-experimental a docc link wrapped in two backticks. + /// + /// For experimental nodes, the node's type name in code font. + public var doccLink: String { + if let node = SYNTAX_NODE_MAP[self], node.isExperimental { + return "`\(syntaxType)`" + } else { + return "``\(syntaxType)``" + } + } + /// For base nodes, the name of the corresponding protocol to which all the /// concrete nodes that have this base kind, conform. public var protocolType: TypeSyntax { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift index 534cbc2e883..37a7f3f8beb 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift @@ -25,9 +25,9 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { """ // MARK: - \(node.kind.syntaxType) - /// Protocol to which all ``\(node.kind.syntaxType)`` nodes conform. + /// Protocol to which all \(raw: node.kind.doccLink) nodes conform. /// - /// Extension point to add common methods to all ``\(node.kind.syntaxType)`` nodes. + /// Extension point to add common methods to all \(raw: node.kind.doccLink) nodes. /// /// - Warning: Do not conform to this protocol yourself. \(node.apiAttributes())\ @@ -77,7 +77,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { return self.as(S.self)! } - /// Checks if the current syntax node can be upcast to its base node type (``\#(node.kind.syntaxType)``). + /// Checks if the current syntax node can be upcast to its base node type (\#(raw: node.kind.doccLink)). /// /// - Returns: `true` since the node can always be upcast to its base node. @available(*, deprecated, message: "This cast will always succeed") @@ -85,7 +85,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { return true } - /// Attempts to upcast the current syntax node to its base node type (``\#(node.kind.syntaxType)``). + /// Attempts to upcast the current syntax node to its base node type (\#(raw: node.kind.doccLink)). /// /// - Returns: The base node created from the current syntax node, as the node can always be upcast to its base type. @available(*, deprecated, message: "Use `\#(node.kind.syntaxType).init` for upcasting") @@ -93,7 +93,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { return \#(node.kind.syntaxType)(self) } - /// Force-upcast the current syntax node to its base node type (``\#(node.kind.syntaxType)``). + /// Force-upcast the current syntax node to its base node type (\#(raw: node.kind.doccLink)). /// /// - Returns: The base node created from the current syntax node, as the node can always be upcast to its base type. @available(*, deprecated, message: "Use `\#(node.kind.syntaxType).init` for upcasting") @@ -182,7 +182,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { DeclSyntax( """ - /// Create a ``\(node.kind.syntaxType)`` node from a specialized syntax node. + /// Create a \(raw: node.kind.doccLink) node from a specialized syntax node. public init(_ syntax: some \(node.kind.protocolType)) { // We know this cast is going to succeed. Go through init(_: SyntaxData) // to do a sanity check and verify the kind matches in debug builds and get @@ -194,7 +194,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { DeclSyntax( """ - /// Create a ``\(node.kind.syntaxType)`` node from a specialized optional syntax node. + /// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node. public init?(_ syntax: (some \(node.kind.protocolType))?) { guard let syntax = syntax else { return nil } self.init(syntax) @@ -215,7 +215,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { DeclSyntax( """ - /// Create a ``\(node.kind.syntaxType)`` node from a specialized optional syntax node. + /// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node. public init?(fromProtocol syntax: \(node.kind.protocolType)?) { guard let syntax = syntax else { return nil } self.init(fromProtocol: syntax) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift index a74f0468d90..8afa15e6f29 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodeCasting.swift @@ -57,7 +57,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock } else { DeclSyntax( """ - /// Checks if the current syntax node can be cast to ``\(syntaxNodeKind.syntaxType)``. + /// Checks if the current syntax node can be cast to \(raw: syntaxNodeKind.doccLink). /// /// - Returns: `true` if the node can be cast, `false` otherwise. \(apiAttributes)\ @@ -69,9 +69,9 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock DeclSyntax( """ - /// Attempts to cast the current syntax node to ``\(syntaxNodeKind.syntaxType)``. + /// Attempts to cast the current syntax node to \(raw: syntaxNodeKind.doccLink). /// - /// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``, or `nil` if the cast fails. + /// - Returns: An instance of \(raw: syntaxNodeKind.doccLink), or `nil` if the cast fails. \(apiAttributes)\ public func `as`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType)? { return \(syntaxNodeKind.syntaxType).init(self) @@ -81,9 +81,9 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock DeclSyntax( """ - /// Force-casts the current syntax node to ``\(syntaxNodeKind.syntaxType)``. + /// Force-casts the current syntax node to \(raw: syntaxNodeKind.doccLink). /// - /// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``. + /// - Returns: An instance of \(raw: syntaxNodeKind.doccLink). /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. \(apiAttributes)\ public func cast(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType) { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift index 3be6a1bb08c..3b6cada55c6 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift @@ -122,7 +122,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { if (node.base == .syntax || node.base == .syntaxCollection) && node.kind != .missing { DeclSyntax( """ - /// Visit a ``\(node.kind.syntaxType)``. + /// Visit a \(raw: node.kind.doccLink). /// - Parameter node: the node that is being visited /// - Returns: the rewritten node \(node.apiAttributes())\ @@ -134,7 +134,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } else { DeclSyntax( """ - /// Visit a ``\(node.kind.syntaxType)``. + /// Visit a \(raw: node.kind.doccLink). /// - Parameter node: the node that is being visited /// - Returns: the rewritten node \(node.apiAttributes())\ diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxVisitorFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxVisitorFile.swift index 9ddcc036e0c..06d0811fd5f 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxVisitorFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxVisitorFile.swift @@ -53,7 +53,7 @@ let syntaxVisitorFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { for node in SYNTAX_NODES where !node.kind.isBase { DeclSyntax( """ - /// Visiting ``\(node.kind.syntaxType)`` specifically. + /// Visiting \(raw: node.kind.doccLink) specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. \(node.apiAttributes())\ @@ -65,7 +65,7 @@ let syntaxVisitorFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { DeclSyntax( """ - /// The function called after visiting ``\(node.kind.syntaxType)`` and its descendants. + /// The function called after visiting \(raw: node.kind.doccLink) and its descendants. /// - node: the node we just finished visiting. \(node.apiAttributes())\ open func visitPost(_ node: \(node.kind.syntaxType)) {} diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index 6c2b3b334b4..7ff75ce92c4 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -14,7 +14,7 @@ // MARK: - DeclSyntax -/// Protocol to which all ``DeclSyntax`` nodes conform. +/// Protocol to which all ``DeclSyntax`` nodes conform. /// /// Extension point to add common methods to all ``DeclSyntax`` nodes. /// @@ -315,7 +315,7 @@ public extension _LeafDeclSyntaxNodeProtocol { // MARK: - ExprSyntax -/// Protocol to which all ``ExprSyntax`` nodes conform. +/// Protocol to which all ``ExprSyntax`` nodes conform. /// /// Extension point to add common methods to all ``ExprSyntax`` nodes. /// @@ -673,7 +673,7 @@ public extension _LeafExprSyntaxNodeProtocol { // MARK: - PatternSyntax -/// Protocol to which all ``PatternSyntax`` nodes conform. +/// Protocol to which all ``PatternSyntax`` nodes conform. /// /// Extension point to add common methods to all ``PatternSyntax`` nodes. /// @@ -940,7 +940,7 @@ public extension _LeafPatternSyntaxNodeProtocol { // MARK: - StmtSyntax -/// Protocol to which all ``StmtSyntax`` nodes conform. +/// Protocol to which all ``StmtSyntax`` nodes conform. /// /// Extension point to add common methods to all ``StmtSyntax`` nodes. /// @@ -1226,7 +1226,7 @@ public extension _LeafStmtSyntaxNodeProtocol { // MARK: - TypeSyntax -/// Protocol to which all ``TypeSyntax`` nodes conform. +/// Protocol to which all ``TypeSyntax`` nodes conform. /// /// Extension point to add common methods to all ``TypeSyntax`` nodes. /// diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index fa38f8446a2..9fa31afe38a 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -880,7 +880,7 @@ public struct LabeledExprListSyntax: SyntaxCollection, SyntaxHashable { /// /// ### Children /// -/// ``LifetimeSpecifierArgumentSyntax`` `*` +/// `LifetimeSpecifierArgumentSyntax` `*` #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif @@ -1675,7 +1675,7 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable { /// ### Children /// -/// (``SimpleTypeSpecifierSyntax`` | ``LifetimeTypeSpecifierSyntax``) `*` +/// (``SimpleTypeSpecifierSyntax`` | `LifetimeTypeSpecifierSyntax`) `*` /// /// ### Contained in /// @@ -1748,7 +1748,7 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { return self.as(SimpleTypeSpecifierSyntax.self)! } - /// Checks if the current syntax node can be cast to ``LifetimeTypeSpecifierSyntax``. + /// Checks if the current syntax node can be cast to `LifetimeTypeSpecifierSyntax`. /// /// - Returns: `true` if the node can be cast, `false` otherwise. #if compiler(>=5.8) @@ -1758,9 +1758,9 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { return self.as(syntaxType) != nil } - /// Attempts to cast the current syntax node to ``LifetimeTypeSpecifierSyntax``. + /// Attempts to cast the current syntax node to `LifetimeTypeSpecifierSyntax`. /// - /// - Returns: An instance of ``LifetimeTypeSpecifierSyntax``, or `nil` if the cast fails. + /// - Returns: An instance of `LifetimeTypeSpecifierSyntax`, or `nil` if the cast fails. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif @@ -1768,9 +1768,9 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { return LifetimeTypeSpecifierSyntax.init(self) } - /// Force-casts the current syntax node to ``LifetimeTypeSpecifierSyntax``. + /// Force-casts the current syntax node to `LifetimeTypeSpecifierSyntax`. /// - /// - Returns: An instance of ``LifetimeTypeSpecifierSyntax``. + /// - Returns: An instance of `LifetimeTypeSpecifierSyntax`. /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index 7074d7d78dd..e9f55427e02 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -668,7 +668,7 @@ open class SyntaxRewriter { return StmtSyntax(visitChildren(node)) } - /// Visit a ``DoExprSyntax``. + /// Visit a `DoExprSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node #if compiler(>=5.8) @@ -1203,7 +1203,7 @@ open class SyntaxRewriter { return visitChildren(node) } - /// Visit a ``LifetimeSpecifierArgumentListSyntax``. + /// Visit a `LifetimeSpecifierArgumentListSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node #if compiler(>=5.8) @@ -1213,7 +1213,7 @@ open class SyntaxRewriter { return visitChildren(node) } - /// Visit a ``LifetimeSpecifierArgumentSyntax``. + /// Visit a `LifetimeSpecifierArgumentSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node #if compiler(>=5.8) @@ -1223,7 +1223,7 @@ open class SyntaxRewriter { return visitChildren(node) } - /// Visit a ``LifetimeSpecifierArgumentsSyntax``. + /// Visit a `LifetimeSpecifierArgumentsSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node #if compiler(>=5.8) @@ -1233,7 +1233,7 @@ open class SyntaxRewriter { return visitChildren(node) } - /// Visit a ``LifetimeTypeSpecifierSyntax``. + /// Visit a `LifetimeTypeSpecifierSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node #if compiler(>=5.8) @@ -1838,7 +1838,7 @@ open class SyntaxRewriter { return ExprSyntax(visitChildren(node)) } - /// Visit a ``ThenStmtSyntax``. + /// Visit a `ThenStmtSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node #if compiler(>=5.8) diff --git a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift index 52fc9d029ef..3b40df48540 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -1042,7 +1042,7 @@ open class SyntaxVisitor { open func visitPost(_ node: DiscardStmtSyntax) { } - /// Visiting ``DoExprSyntax`` specifically. + /// Visiting `DoExprSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. #if compiler(>=5.8) @@ -1052,7 +1052,7 @@ open class SyntaxVisitor { return .visitChildren } - /// The function called after visiting ``DoExprSyntax`` and its descendants. + /// The function called after visiting `DoExprSyntax` and its descendants. /// - node: the node we just finished visiting. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) @@ -1960,7 +1960,7 @@ open class SyntaxVisitor { open func visitPost(_ node: LayoutRequirementSyntax) { } - /// Visiting ``LifetimeSpecifierArgumentListSyntax`` specifically. + /// Visiting `LifetimeSpecifierArgumentListSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. #if compiler(>=5.8) @@ -1970,7 +1970,7 @@ open class SyntaxVisitor { return .visitChildren } - /// The function called after visiting ``LifetimeSpecifierArgumentListSyntax`` and its descendants. + /// The function called after visiting `LifetimeSpecifierArgumentListSyntax` and its descendants. /// - node: the node we just finished visiting. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) @@ -1978,7 +1978,7 @@ open class SyntaxVisitor { open func visitPost(_ node: LifetimeSpecifierArgumentListSyntax) { } - /// Visiting ``LifetimeSpecifierArgumentSyntax`` specifically. + /// Visiting `LifetimeSpecifierArgumentSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. #if compiler(>=5.8) @@ -1988,7 +1988,7 @@ open class SyntaxVisitor { return .visitChildren } - /// The function called after visiting ``LifetimeSpecifierArgumentSyntax`` and its descendants. + /// The function called after visiting `LifetimeSpecifierArgumentSyntax` and its descendants. /// - node: the node we just finished visiting. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) @@ -1996,7 +1996,7 @@ open class SyntaxVisitor { open func visitPost(_ node: LifetimeSpecifierArgumentSyntax) { } - /// Visiting ``LifetimeSpecifierArgumentsSyntax`` specifically. + /// Visiting `LifetimeSpecifierArgumentsSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. #if compiler(>=5.8) @@ -2006,7 +2006,7 @@ open class SyntaxVisitor { return .visitChildren } - /// The function called after visiting ``LifetimeSpecifierArgumentsSyntax`` and its descendants. + /// The function called after visiting `LifetimeSpecifierArgumentsSyntax` and its descendants. /// - node: the node we just finished visiting. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) @@ -2014,7 +2014,7 @@ open class SyntaxVisitor { open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) { } - /// Visiting ``LifetimeTypeSpecifierSyntax`` specifically. + /// Visiting `LifetimeTypeSpecifierSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. #if compiler(>=5.8) @@ -2024,7 +2024,7 @@ open class SyntaxVisitor { return .visitChildren } - /// The function called after visiting ``LifetimeTypeSpecifierSyntax`` and its descendants. + /// The function called after visiting `LifetimeTypeSpecifierSyntax` and its descendants. /// - node: the node we just finished visiting. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) @@ -3052,7 +3052,7 @@ open class SyntaxVisitor { open func visitPost(_ node: TernaryExprSyntax) { } - /// Visiting ``ThenStmtSyntax`` specifically. + /// Visiting `ThenStmtSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. #if compiler(>=5.8) @@ -3062,7 +3062,7 @@ open class SyntaxVisitor { return .visitChildren } - /// The function called after visiting ``ThenStmtSyntax`` and its descendants. + /// The function called after visiting `ThenStmtSyntax` and its descendants. /// - node: the node we just finished visiting. #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index fcdb4e26fc3..605ea5af339 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -1802,7 +1802,7 @@ public struct LifetimeSpecifierArgumentSyntax: SyntaxProtocol, SyntaxHashable, _ /// ### Children /// /// - `leftParen`: `(` -/// - `arguments`: ``LifetimeSpecifierArgumentListSyntax`` +/// - `arguments`: `LifetimeSpecifierArgumentListSyntax` /// - `rightParen`: `)` #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) @@ -1984,7 +1984,7 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, /// ### Children /// /// - `specifier`: (`_copy` | `_consume` | `_borrow` | `_mutate`) -/// - `arguments`: ``LifetimeSpecifierArgumentsSyntax`` +/// - `arguments`: `LifetimeSpecifierArgumentsSyntax` /// /// ### Contained in ///