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/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/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/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 3db67234b1e..5ea26147675 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 @@ -285,6 +289,9 @@ public enum SyntaxNodeKind: String, CaseIterable { case typeEffectSpecifiers case typeExpr case typeInitializerClause + case typeSpecifier + case lifetimeSpecifierArguments + case typeSpecifierList case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments case unexpectedNodes @@ -299,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 @@ -348,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 { @@ -405,8 +423,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" @@ -440,6 +458,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" @@ -451,8 +470,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 69ac54c8660..93a2598645d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -43,27 +43,19 @@ public let TYPE_NODES: [Node] = [ ], 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), - ]), - isOptional: true + name: "specifiers", + 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." ), ] ), @@ -503,4 +495,133 @@ public let TYPE_NODES: [Node] = [ ] ), + Node( + 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) -> 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) -> 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( + 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: [.simpleTypeSpecifier, .lifetimeTypeSpecifier] + ), ] 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/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/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/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..8afa15e6f29 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`(_ 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`(_ 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(_ syntaxType: S.Type) -> S { return self.as(S.self)! } @@ -53,9 +57,10 @@ 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)\ public func `is`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> Bool { return self.as(syntaxType) != nil } @@ -64,9 +69,10 @@ 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) } @@ -75,10 +81,11 @@ 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) { return self.as(\(syntaxNodeKind.syntaxType).self)! } 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/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 1b8741b750e..f3e4d1eef1f 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 +- 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 ## 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 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 + ## API-Incompatible Changes - `MacroDefinition` used for expanding macros: diff --git a/Sources/SwiftParser/Parameters.swift b/Sources/SwiftParser/Parameters.swift index 7b780febdc8..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: TypeSpecifier.self) { + while canHaveParameterSpecifier, let specifier = self.consume(ifAnyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) { misplacedSpecifiers.append(specifier) } } 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/Patterns.swift b/Sources/SwiftParser/Patterns.swift index c606f0875ba..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: TypeSpecifier.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/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 197906a265f..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. @@ -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 ) @@ -469,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: SimpleTypeSpecifierSyntax.SpecifierOptions.self) { misplacedSpecifiers.append(specifier) } @@ -624,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: SimpleTypeSpecifierSyntax.SpecifierOptions.self) != nil || self.at(.keyword(.isolated)) || self.at(.keyword(._const)), self.hasProgressed(&specifierProgress) { self.consumeAnyToken() @@ -891,35 +890,118 @@ 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) - } - // 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) + 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 extraneousSpecifiers: [RawTokenSyntax] = [] - while canHaveParameterSpecifier, - let extraSpecifier = self.consume(ifAnyIn: AttributedTypeSyntax.SpecifierOptions.self) - { - if specifier == nil { - specifier = extraSpecifier - } else { - extraneousSpecifiers.append(extraSpecifier) + 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 + )? { + typealias SimpleOrLifetimeSpecifier = EitherTokenSpecSet + 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 + } } } - let unexpectedBeforeAttributeList = RawUnexpectedNodesSyntax(extraneousSpecifiers, arena: self.arena) + specifiers += misplacedSpecifiers.map { + .simpleTypeSpecifier( + RawSimpleTypeSpecifierSyntax( + specifier: missingToken($0.tokenKind, text: $0.tokenText), + arena: arena + ) + ) + } + let attributes: RawAttributeListSyntax? if self.at(.atSign) { - return (specifier, unexpectedBeforeAttributeList, self.parseTypeAttributeListPresent()) + attributes = self.parseTypeAttributeListPresent() + } else { + attributes = nil + } + + 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 (specifier, unexpectedBeforeAttributeList, self.emptyCollection(RawAttributeListSyntax.self)) + 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..98c91c193d4 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: @@ -177,106 +221,25 @@ extension AsExprSyntax { } } -extension AttributedTypeSyntax { +extension AvailabilityConditionSyntax { @_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 + public enum AvailabilityKeywordOptions: TokenSpecSet { + case poundAvailable + case poundUnavailable 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 + case TokenSpec(.poundAvailable): + self = .poundAvailable + case TokenSpec(.poundUnavailable): + self = .poundUnavailable 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 { - case poundAvailable - case poundUnavailable - - init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { - switch PrepareForKeywordMatch(lexeme) { + public init?(token: TokenSyntax) { + switch token { case TokenSpec(.poundAvailable): self = .poundAvailable case TokenSpec(.poundUnavailable): @@ -336,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: @@ -389,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: @@ -430,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: @@ -471,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: @@ -512,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: @@ -553,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: @@ -594,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: @@ -635,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: @@ -676,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: @@ -824,37 +892,118 @@ extension DeclModifierSyntax { } } - var spec: TokenSpec { - switch self { - case .__consuming: - return .keyword(.__consuming) - case .__setter_access: - return .keyword(.__setter_access) - case ._const: - return .keyword(._const) - case ._local: - return .keyword(._local) - case .actor: - return .keyword(.actor) - case .async: - return .keyword(.async) - case .borrowing: - return .keyword(.borrowing) - case .class: - return .keyword(.class) - case .consuming: - return .keyword(.consuming) - case .convenience: - return .keyword(.convenience) - case .distributed: - return .keyword(.distributed) - case .dynamic: - return .keyword(.dynamic) - case .fileprivate: - return .keyword(.fileprivate) - case .final: - return .keyword(.final) - case .indirect: + 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: + return .keyword(.__consuming) + case .__setter_access: + return .keyword(.__setter_access) + case ._const: + return .keyword(._const) + case ._local: + return .keyword(._local) + case .actor: + return .keyword(.actor) + case .async: + return .keyword(.async) + case .borrowing: + return .keyword(.borrowing) + case .class: + return .keyword(.class) + case .consuming: + return .keyword(.consuming) + case .convenience: + return .keyword(.convenience) + case .distributed: + return .keyword(.distributed) + case .dynamic: + return .keyword(.dynamic) + case .fileprivate: + return .keyword(.fileprivate) + case .final: + return .keyword(.final) + case .indirect: return .keyword(.indirect) case .infix: return .keyword(.infix) @@ -1026,6 +1175,31 @@ 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(.deinit): + self = .deinit + case TokenSpec(.subscript): + self = .subscript + 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: @@ -1095,6 +1269,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: @@ -1139,6 +1324,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: @@ -1187,6 +1385,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: @@ -1232,6 +1443,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: @@ -1273,6 +1495,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: @@ -1314,6 +1547,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: @@ -1361,6 +1605,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: @@ -1410,6 +1669,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: @@ -1451,6 +1721,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: @@ -1492,6 +1773,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: @@ -1542,6 +1834,23 @@ extension IdentifierPatternSyntax { } } + public init?(token: TokenSyntax) { + switch token { + case TokenSpec(.identifier): + self = .identifier + case TokenSpec(.self): + self = .self + case TokenSpec(.`init`): + self = .`init` + case TokenSpec(.deinit): + self = .deinit + case TokenSpec(.subscript): + self = .subscript + default: + return nil + } + } + var spec: TokenSpec { switch self { case .identifier: @@ -1601,18 +1910,33 @@ extension IdentifierTypeSyntax { } } - var spec: TokenSpec { - switch self { - case .identifier: - return .identifier - case .Self: - return .keyword(.Self) - case .Any: - return .keyword(.Any) - case .wildcard: - return .wildcard - } - } + 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: + return .identifier + case .Self: + return .keyword(.Self) + case .Any: + return .keyword(.Any) + case .wildcard: + return .wildcard + } + } /// Returns a token that satisfies the `TokenSpec` of this case. /// @@ -1653,6 +1977,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: @@ -1719,6 +2056,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: @@ -1794,6 +2156,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: @@ -1843,6 +2220,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: @@ -1884,6 +2272,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: @@ -1925,6 +2324,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: @@ -1978,6 +2388,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: @@ -2056,6 +2485,31 @@ extension LayoutRequirementSyntax { } } + public init?(token: TokenSyntax) { + switch token { + 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 + } + } + var spec: TokenSpec { switch self { case ._Trivial: @@ -2108,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 { @@ -2125,6 +2713,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: @@ -2166,6 +2765,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: @@ -2207,6 +2817,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: @@ -2251,6 +2872,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: @@ -2299,6 +2933,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: @@ -2359,6 +3006,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: @@ -2416,6 +3082,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: @@ -2447,8 +3124,21 @@ extension PrecedenceGroupAssociativitySyntax { case right case none - init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { - switch PrepareForKeywordMatch(lexeme) { + init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(.left): + self = .left + case TokenSpec(.right): + self = .right + case TokenSpec(.none): + self = .none + default: + return nil + } + } + + public init?(token: TokenSyntax) { + switch token { case TokenSpec(.left): self = .left case TokenSpec(.right): @@ -2505,6 +3195,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: @@ -2549,6 +3250,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: @@ -2594,6 +3308,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: @@ -2635,6 +3360,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: @@ -2659,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 { @@ -2676,6 +3529,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: @@ -2720,6 +3584,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: @@ -2768,6 +3645,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: @@ -2813,6 +3703,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: @@ -2854,6 +3755,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: @@ -2895,6 +3807,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: @@ -2936,6 +3859,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: @@ -2977,6 +3911,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 +3978,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 +4069,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 b1c87db62a2..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: { TypeSpecifier(token: $0) != nil }, - correctTokens: [node.type.as(AttributedTypeSyntax.self)?.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: { TypeSpecifier(token: $0) != nil }, - correctTokens: [node.type.as(AttributedTypeSyntax.self)?.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 17ef8a8a6d2..3ffec83b129 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 - - - +- +- - - - diff --git a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift index a6db529039c..7a53e412650 100644 --- a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift +++ b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift @@ -37,6 +37,76 @@ 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 = [.simpleTypeSpecifier(SimpleTypeSpecifierSyntax(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 { + if case .simpleTypeSpecifier(let simpleSpecifier) = specifiers.first { + return simpleSpecifier.specifier + } + return nil + } + set { + if let newValue { + specifiers = [.simpleTypeSpecifier(SimpleTypeSpecifierSyntax(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..a738f6b9979 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: @@ -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: 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 7aa92b754b0..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) } @@ -2148,6 +2212,14 @@ 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: UnavailableFromAsyncAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index b4084ddc80b..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. /// @@ -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), @@ -1779,6 +1784,7 @@ extension Syntax { .node(TypeEffectSpecifiersSyntax.self), .node(TypeExprSyntax.self), .node(TypeInitializerClauseSyntax.self), + .node(TypeSpecifierListSyntax.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..9fa31afe38a 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`` `*` @@ -1650,6 +1673,125 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable { public static let syntaxKind = SyntaxKind.tupleTypeElementList } +/// ### Children +/// +/// (``SimpleTypeSpecifierSyntax`` | `LifetimeTypeSpecifierSyntax`) `*` +/// +/// ### Contained in +/// +/// - ``AttributedTypeSyntax``.``AttributedTypeSyntax/specifiers`` +public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { + 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 + + 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..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) @@ -281,6 +298,7 @@ public enum SyntaxEnum: Sendable { case typeEffectSpecifiers(TypeEffectSpecifiersSyntax) case typeExpr(TypeExprSyntax) case typeInitializerClause(TypeInitializerClauseSyntax) + case typeSpecifierList(TypeSpecifierListSyntax) case unavailableFromAsyncAttributeArguments(UnavailableFromAsyncAttributeArgumentsSyntax) case underscorePrivateAttributeArguments(UnderscorePrivateAttributeArgumentsSyntax) case unexpectedNodes(UnexpectedNodesSyntax) @@ -627,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: @@ -753,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: @@ -827,6 +855,8 @@ public extension Syntax { return .typeExpr(TypeExprSyntax(self)!) case .typeInitializerClause: return .typeInitializerClause(TypeInitializerClauseSyntax(self)!) + case .typeSpecifierList: + return .typeSpecifierList(TypeSpecifierListSyntax(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..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 @@ -281,6 +298,7 @@ public enum SyntaxKind: Sendable { case typeEffectSpecifiers case typeExpr case typeInitializerClause + case typeSpecifierList case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments case unexpectedNodes @@ -364,6 +382,8 @@ public enum SyntaxKind: Sendable { return true case .labeledExprList: return true + case .lifetimeSpecifierArgumentList: + return true case .memberBlockItemList: return true case .multipleTrailingClosureElementList: @@ -394,6 +414,8 @@ public enum SyntaxKind: Sendable { return true case .tupleTypeElementList: return true + case .typeSpecifierList: + return true case .unexpectedNodes: return true case .versionComponentList: @@ -748,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: @@ -874,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: @@ -948,6 +980,8 @@ public enum SyntaxKind: Sendable { return TypeExprSyntax.self case .typeInitializerClause: return TypeInitializerClauseSyntax.self + case .typeSpecifierList: + return TypeSpecifierListSyntax.self case .unavailableFromAsyncAttributeArguments: return UnavailableFromAsyncAttributeArgumentsSyntax.self case .underscorePrivateAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index cd4a81d4f28..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,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 @@ -1791,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) @@ -1906,6 +1953,13 @@ 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 ``UnavailableFromAsyncAttributeArgumentsSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -2756,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) @@ -3008,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) @@ -3156,6 +3230,10 @@ open class SyntaxRewriter { return { self.visitImpl($0, TypeInitializerClauseSyntax.self, self.visit) } + case .typeSpecifierList: + return { + self.visitImpl($0, TypeSpecifierListSyntax.self, self.visit) + } case .unavailableFromAsyncAttributeArguments: return { self.visitImpl($0, UnavailableFromAsyncAttributeArgumentsSyntax.self, self.visit) @@ -3558,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: @@ -3684,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: @@ -3758,6 +3846,8 @@ 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 .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 995dd8881d7..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,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. @@ -2968,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) @@ -2978,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) @@ -3166,6 +3250,18 @@ 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 ``UnavailableFromAsyncAttributeArgumentsSyntax`` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -4084,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) @@ -4336,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) @@ -4484,6 +4600,10 @@ 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 .unavailableFromAsyncAttributeArguments: return { self.visitImpl($0, UnavailableFromAsyncAttributeArgumentsSyntax.self, self.visit, self.visitPost) @@ -4889,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: @@ -5015,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: @@ -5089,6 +5219,8 @@ 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 .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/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 e1c93d0e7f5..699833eb983 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift @@ -1408,6 +1408,86 @@ 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! + } + + 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: [Element], 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: [RawSyntax] { + layoutView.children.map { + RawSyntax(raw: $0!) + } + } +} + @_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..8d22721337f 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)) @@ -1724,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)) @@ -2272,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)) @@ -2619,6 +2656,12 @@ 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() { + assertAnyHasNoError(kind, index, [ + verify(element, as: RawSimpleTypeSpecifierSyntax.self), + verify(element, as: RawLifetimeTypeSpecifierSyntax.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..88645b6cba8 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 { @@ -3272,12 +3272,15 @@ 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, - _ 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 +3291,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 +3320,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 +3329,44 @@ 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? { + /// 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(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: Syntax) -> 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) } @@ -3356,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) @@ -3401,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) @@ -3421,9 +3442,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/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index 6c0c35c2565..605ea5af339 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) -> borrow(data) ComplexReferenceType` +/// +/// - Experiment: Requires experimental feature `nonescapableTypes`. +/// +/// ### Children +/// +/// - `parameter`: (`` | `self` | ``) +/// - `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: + /// - `` + /// - `self` + /// - `` + 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) -> 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/SwiftSyntaxBuilder/generated/ResultBuilders.swift b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift index a881f9ed0d4..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 @@ -668,6 +684,30 @@ public extension TupleTypeElementListSyntax { } } +// MARK: - TypeSpecifierListBuilder + +@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 { + 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..a06caabf286 100644 --- a/Tests/SwiftParserTest/TypeTests.swift +++ b/Tests/SwiftParserTest/TypeTests.swift @@ -320,4 +320,99 @@ final class TypeTests: ParserTestCase { "[() throws(PosixError) -> Void]()" ) } + + func testMultipleTypeSpecifiers() { + 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] + ) + } } 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) {}" ) }