diff --git a/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift b/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift index b1f35ef6433..8f7bbe157aa 100644 --- a/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift +++ b/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift @@ -167,7 +167,6 @@ public enum Keyword: CaseIterable { case `default` case `defer` case `deinit` - case dependsOn case deprecated case derivative case didSet @@ -257,7 +256,6 @@ public enum Keyword: CaseIterable { case reverse case right case safe - case scoped case `self` case sending case `Self` @@ -476,8 +474,6 @@ public enum Keyword: CaseIterable { return KeywordSpec("defer", isLexerClassified: true) case .deinit: return KeywordSpec("deinit", isLexerClassified: true) - case .dependsOn: - return KeywordSpec("dependsOn", experimentalFeature: .nonescapableTypes) case .deprecated: return KeywordSpec("deprecated") case .derivative: @@ -654,8 +650,6 @@ public enum Keyword: CaseIterable { return KeywordSpec("right") case .safe: return KeywordSpec("safe") - case .scoped: - return KeywordSpec("scoped", experimentalFeature: .nonescapableTypes) case .self: return KeywordSpec("self", isLexerClassified: true) case .Self: diff --git a/CodeGeneration/Sources/SyntaxSupport/Node.swift b/CodeGeneration/Sources/SyntaxSupport/Node.swift index 3205f0425f7..6c4c973400d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Node.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Node.swift @@ -55,6 +55,8 @@ public class Node: NodeChoiceConvertible { /// function that should be invoked to create this node. public let parserFunction: TokenSyntax? + public let disableSameTypeForUniqueChoice: Bool + public var syntaxNodeKind: SyntaxNodeKind { self.kind } @@ -121,6 +123,7 @@ public class Node: NodeChoiceConvertible { experimentalFeature: ExperimentalFeature? = nil, nameForDiagnostics: String?, documentation: String? = nil, + disableSameTypeForUniqueChoice: Bool = false, parserFunction: TokenSyntax? = nil, traits: [String] = [], children: [Child] = [] @@ -133,6 +136,7 @@ public class Node: NodeChoiceConvertible { self.experimentalFeature = experimentalFeature self.nameForDiagnostics = nameForDiagnostics self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) + self.disableSameTypeForUniqueChoice = disableSameTypeForUniqueChoice self.parserFunction = parserFunction let childrenWithUnexpected: [Child] @@ -278,6 +282,7 @@ public class Node: NodeChoiceConvertible { experimentalFeature: ExperimentalFeature? = nil, nameForDiagnostics: String?, documentation: String? = nil, + disableSameTypeForUniqueChoice: Bool = false, parserFunction: TokenSyntax? = nil, elementChoices: [SyntaxNodeKind] ) { @@ -287,6 +292,7 @@ public class Node: NodeChoiceConvertible { self.experimentalFeature = experimentalFeature self.nameForDiagnostics = nameForDiagnostics self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) + self.disableSameTypeForUniqueChoice = disableSameTypeForUniqueChoice self.parserFunction = parserFunction assert(!elementChoices.isEmpty) diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift index aca5c52aa86..3e338f260ab 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift @@ -182,9 +182,6 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon case labeledSpecializeArgument case labeledStmt case layoutRequirement - case lifetimeSpecifierArgument - case lifetimeSpecifierArgumentList - case lifetimeTypeSpecifier case macroDecl case macroExpansionDecl case macroExpansionExpr @@ -290,7 +287,6 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon case typeExpr case typeInitializerClause case typeSpecifier - case lifetimeSpecifierArguments case typeSpecifierList case unavailableFromAsyncAttributeArguments case underscorePrivateAttributeArguments diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index 527843d4e90..ebf58538c1c 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -500,81 +500,6 @@ 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: .lifetimeTypeSpecifier, - base: .syntax, - experimentalFeature: .nonescapableTypes, - nameForDiagnostics: "lifetime specifier", - documentation: "A specifier that specifies function parameter on whose lifetime a type depends", - children: [ - Child( - name: "dependsOnKeyword", - kind: .token(choices: [.keyword(.dependsOn)]), - documentation: "lifetime dependence specifier on the return type" - ), - Child( - name: "leftParen", - kind: .token(choices: [.token(.leftParen)]) - ), - Child( - name: "scopedKeyword", - kind: .token(choices: [.keyword(.scoped)]), - documentation: "lifetime of return value is scoped to the lifetime of the original value", - isOptional: true - ), - Child( - name: "arguments", - kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments") - ), - Child( - name: "rightParen", - kind: .token(choices: [.token(.rightParen)]) - ), - ] - ), - Node( kind: .simpleTypeSpecifier, base: .syntax, @@ -602,6 +527,7 @@ public let TYPE_NODES: [Node] = [ kind: .typeSpecifierList, base: .syntaxCollection, nameForDiagnostics: nil, - elementChoices: [.simpleTypeSpecifier, .lifetimeTypeSpecifier] + disableSameTypeForUniqueChoice: true, + elementChoices: [.simpleTypeSpecifier] ), ] diff --git a/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift b/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift index f69d43b06e0..1bdd3667b1a 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift @@ -89,7 +89,9 @@ extension Node { return nil } } - } else if let node = self.collectionNode, node.elementChoices.count > 1 { + } else if let node = self.collectionNode, node.elementChoices.count == 1, !node.disableSameTypeForUniqueChoice { + return [] + } else if let node = self.collectionNode, node.elementChoices.count >= 1 { return [ ChildNodeChoices( name: "Element", diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift index cdc29c9cad5..7bf6aa441a0 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift @@ -116,7 +116,9 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax { } if let node = node.collectionNode { - let element = node.elementChoices.only != nil ? node.elementChoices.only!.raw.syntaxType : "Element" + let element = + node.elementChoices.only != nil && !node.disableSameTypeForUniqueChoice + ? node.elementChoices.only!.raw.syntaxType : "Element" DeclSyntax( """ public init(elements: [\(element)], arena: __shared SyntaxArena) { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift index cfa32fde2c2..09abfe590d4 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift @@ -31,8 +31,8 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { public struct \(node.kind.syntaxType): SyntaxCollection, SyntaxHashable """ ) { - if let onlyElement = node.elementChoices.only { - DeclSyntax("public typealias Element = \(onlyElement.syntaxType)") + if node.elementChoices.only != nil && !node.disableSameTypeForUniqueChoice { + DeclSyntax("public typealias Element = \(node.elementChoices.only!.syntaxType)") } else { for childNodeChoices in node.node.childrenNodeChoices() { childNodeChoices.enumDecl diff --git a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift index 8e071ea628f..07c2afbe0cb 100644 --- a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift +++ b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift @@ -550,7 +550,6 @@ class ValidateSyntaxNodes: XCTestCase { node: .yieldedExpressionsClause, message: "could conform to trait 'Parenthesized' but does not" ), - ValidationFailure(node: .lifetimeTypeSpecifier, message: "could conform to trait 'Parenthesized' but does not"), ] ) } diff --git a/Sources/SwiftParser/Declarations.swift b/Sources/SwiftParser/Declarations.swift index 6d8845d52a0..c5083b7fbb0 100644 --- a/Sources/SwiftParser/Declarations.swift +++ b/Sources/SwiftParser/Declarations.swift @@ -995,7 +995,7 @@ extension Parser { } // Parse the signature. - let signature = self.parseFunctionSignature() + let signature = self.parseFunctionSignature(allowOutput: false) let whereClause: RawGenericWhereClauseSyntax? if self.at(.keyword(.where)) { @@ -1159,7 +1159,7 @@ extension Parser { ) } - mutating func parseFunctionSignature() -> RawFunctionSignatureSyntax { + mutating func parseFunctionSignature(allowOutput: Bool = true) -> RawFunctionSignatureSyntax { let parameterClause = self.parseParameterClause(RawFunctionParameterClauseSyntax.self) { parser in parser.parseFunctionParameter() } @@ -1179,10 +1179,19 @@ extension Parser { returnClause = nil } + var unexpectedAfterReturnClause: RawUnexpectedNodesSyntax? + if !allowOutput, + let unexpectedOutput = returnClause + { + returnClause = nil + unexpectedAfterReturnClause = RawUnexpectedNodesSyntax([unexpectedOutput], arena: self.arena) + } + return RawFunctionSignatureSyntax( parameterClause: parameterClause, effectSpecifiers: effectSpecifiers, returnClause: returnClause, + unexpectedAfterReturnClause, arena: self.arena ) } diff --git a/Sources/SwiftParser/TokenPrecedence.swift b/Sources/SwiftParser/TokenPrecedence.swift index 1cc318aedfa..6844f6fdecd 100644 --- a/Sources/SwiftParser/TokenPrecedence.swift +++ b/Sources/SwiftParser/TokenPrecedence.swift @@ -236,7 +236,7 @@ enum TokenPrecedence: Comparable { .convenience, .override, .package, .open, .__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local, .inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume, - .dependsOn, .scoped, .sending, + .sending, // Accessors .get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress, .mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify, diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index 402282ca141..d936f27f6b8 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -874,64 +874,6 @@ extension Parser.Lookahead { } extension Parser { - private mutating func parseLifetimeTypeSpecifier() -> RawTypeSpecifierListSyntax.Element { - let (unexpectedBeforeDependsOnKeyword, dependsOnKeyword) = self.expect(.keyword(.dependsOn)) - - guard let leftParen = self.consume(if: .leftParen) else { - // If there is no left paren, add an entirely missing detail. Otherwise, we start to consume the following type - // name as a token inside the detail, which leads to confusing recovery results. - let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax( - elements: [ - RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena) - ], - arena: self.arena - ) - let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax( - unexpectedBeforeDependsOnKeyword, - dependsOnKeyword: dependsOnKeyword, - leftParen: missingToken(.leftParen), - scopedKeyword: nil, - arguments: lifetimeSpecifierArgumentList, - rightParen: missingToken(.rightParen), - arena: self.arena - ) - return .lifetimeTypeSpecifier(lifetimeSpecifier) - } - - let scoped = self.consume(if: .keyword(.scoped)) - 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 lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax( - unexpectedBeforeDependsOnKeyword, - dependsOnKeyword: dependsOnKeyword, - leftParen: leftParen, - scopedKeyword: scoped, - arguments: lifetimeSpecifierArgumentList, - unexpectedBeforeRightParen, - rightParen: rightParen, - arena: self.arena - ) - return .lifetimeTypeSpecifier(lifetimeSpecifier) - } - private mutating func parseSimpleTypeSpecifier( specifierHandle: TokenConsumptionHandle ) -> RawTypeSpecifierListSyntax.Element { @@ -949,12 +891,6 @@ extension Parser { SPECIFIER_PARSING: while canHaveParameterSpecifier { if let (_, specifierHandle) = self.at(anyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) { specifiers.append(parseSimpleTypeSpecifier(specifierHandle: specifierHandle)) - } else if self.at(.keyword(.dependsOn)) { - if self.experimentalFeatures.contains(.nonescapableTypes) { - specifiers.append(parseLifetimeTypeSpecifier()) - } else { - break SPECIFIER_PARSING - } } else { break SPECIFIER_PARSING } diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index 0ddbdbd54c0..026ff16340c 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -2679,67 +2679,6 @@ 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 MemberTypeSyntax { @_spi(Diagnostics) public enum NameOptions: TokenSpecSet { diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index 13030c5143e..563e21109c4 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -1273,6 +1273,14 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { ) } + if let unexpectedOutput = node.signature.unexpectedAfterReturnClause { + addDiagnostic( + unexpectedOutput, + .initializerCannotHaveResultType, + handledNodes: [unexpectedOutput.id] + ) + } + return .visitChildren } diff --git a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift index f1a21255bb5..0a44f67ca8b 100644 --- a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift +++ b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift @@ -176,6 +176,9 @@ extension DiagnosticMessage where Self == StaticParserError { public static var initializerCannotHaveName: Self { .init("initializers cannot have a name") } + public static var initializerCannotHaveResultType: Self { + .init("initializers cannot have a result type") + } public static var invalidFlagAfterPrecedenceGroupAssignment: Self { .init("expected 'true' or 'false' after 'assignment'") } diff --git a/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift b/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift index 505c90e0a3f..0d6ddbf49ab 100644 --- a/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift +++ b/Sources/SwiftParserDiagnostics/SyntaxExtensions.swift @@ -211,7 +211,6 @@ extension TypeSpecifierListSyntax { return self.compactMap { specifier in switch specifier { case .simpleTypeSpecifier(let specifier): return specifier.specifier - case .lifetimeTypeSpecifier: return nil #if RESILIENT_LIBRARIES @unknown default: fatalError() diff --git a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift index 1d7488f2861..f2d9e8e9687 100644 --- a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift @@ -224,8 +224,6 @@ 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 4006f445c54..e6b578ee0e2 100644 --- a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift @@ -251,8 +251,6 @@ extension SyntaxKind { return "labeled statement" case .layoutRequirement: return "layout requirement" - case .lifetimeTypeSpecifier: - return "lifetime specifier" case .macroDecl: return "macro" case .macroExpansionDecl: diff --git a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift index 31a6ac2cac5..39464603358 100644 --- a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift +++ b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift @@ -1995,38 +1995,6 @@ 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 \LifetimeTypeSpecifierSyntax.unexpectedBeforeDependsOnKeyword: - return "unexpectedBeforeDependsOnKeyword" - case \LifetimeTypeSpecifierSyntax.dependsOnKeyword: - return "dependsOnKeyword" - case \LifetimeTypeSpecifierSyntax.unexpectedBetweenDependsOnKeywordAndLeftParen: - return "unexpectedBetweenDependsOnKeywordAndLeftParen" - case \LifetimeTypeSpecifierSyntax.leftParen: - return "leftParen" - case \LifetimeTypeSpecifierSyntax.unexpectedBetweenLeftParenAndScopedKeyword: - return "unexpectedBetweenLeftParenAndScopedKeyword" - case \LifetimeTypeSpecifierSyntax.scopedKeyword: - return "scopedKeyword" - case \LifetimeTypeSpecifierSyntax.unexpectedBetweenScopedKeywordAndArguments: - return "unexpectedBetweenScopedKeywordAndArguments" - case \LifetimeTypeSpecifierSyntax.arguments: - return "arguments" - case \LifetimeTypeSpecifierSyntax.unexpectedBetweenArgumentsAndRightParen: - return "unexpectedBetweenArgumentsAndRightParen" - case \LifetimeTypeSpecifierSyntax.rightParen: - return "rightParen" - case \LifetimeTypeSpecifierSyntax.unexpectedAfterRightParen: - return "unexpectedAfterRightParen" case \MacroDeclSyntax.unexpectedBeforeAttributes: return "unexpectedBeforeAttributes" case \MacroDeclSyntax.attributes: diff --git a/Sources/SwiftSyntax/generated/Keyword.swift b/Sources/SwiftSyntax/generated/Keyword.swift index 2ce15cdf90c..aaecae03b8b 100644 --- a/Sources/SwiftSyntax/generated/Keyword.swift +++ b/Sources/SwiftSyntax/generated/Keyword.swift @@ -107,10 +107,6 @@ public enum Keyword: UInt8, Hashable, Sendable { case `default` case `defer` case `deinit` - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - case dependsOn case deprecated case derivative case didSet @@ -206,10 +202,6 @@ public enum Keyword: UInt8, Hashable, Sendable { case reverse case right case safe - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - case scoped case `self` case sending case `Self` @@ -438,8 +430,6 @@ public enum Keyword: UInt8, Hashable, Sendable { self = .repeat case "return": self = .return - case "scoped": - self = .scoped case "static": self = .static case "struct": @@ -573,8 +563,6 @@ public enum Keyword: UInt8, Hashable, Sendable { self = .canImport case "consuming": self = .consuming - case "dependsOn": - self = .dependsOn case "extension": self = .extension case "lowerThan": @@ -907,7 +895,6 @@ public enum Keyword: UInt8, Hashable, Sendable { "default", "defer", "deinit", - "dependsOn", "deprecated", "derivative", "didSet", @@ -997,7 +984,6 @@ public enum Keyword: UInt8, Hashable, Sendable { "reverse", "right", "safe", - "scoped", "self", "sending", "Self", diff --git a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift index 6b4a238d8cf..d7b2e83a095 100644 --- a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift @@ -1342,48 +1342,6 @@ 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: 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) } diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index 4341ca1bc2f..edd2fc1be64 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -1677,9 +1677,6 @@ extension Syntax { .node(LabeledSpecializeArgumentSyntax.self), .node(LabeledStmtSyntax.self), .node(LayoutRequirementSyntax.self), - .node(LifetimeSpecifierArgumentListSyntax.self), - .node(LifetimeSpecifierArgumentSyntax.self), - .node(LifetimeTypeSpecifierSyntax.self), .node(MacroDeclSyntax.self), .node(MacroExpansionDeclSyntax.self), .node(MacroExpansionExprSyntax.self), diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index 096d0512165..ee33ad340aa 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -884,29 +884,6 @@ public struct LabeledExprListSyntax: SyntaxCollection, SyntaxHashable { public static let syntaxKind = SyntaxKind.labeledExprList } -/// - Note: 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`` `*` @@ -1675,7 +1652,7 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable { /// ### Children /// -/// (``SimpleTypeSpecifierSyntax`` | `LifetimeTypeSpecifierSyntax`) `*` +/// ``SimpleTypeSpecifierSyntax`` `*` /// /// ### Contained in /// @@ -1684,19 +1661,11 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { public enum Element: SyntaxChildChoices, SyntaxHashable { /// A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming` case simpleTypeSpecifier(SimpleTypeSpecifierSyntax) - /// A specifier that specifies function parameter on whose lifetime a type depends - /// - Note: Requires experimental feature `nonescapableTypes`. - #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 } } @@ -1704,26 +1673,16 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { self = .simpleTypeSpecifier(node) } - /// - Note: Requires experimental feature `nonescapableTypes`. - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - public init(_ node: LifetimeTypeSpecifierSyntax) { - self = .lifetimeTypeSpecifier(node) - } - public init?(_ node: __shared some SyntaxProtocol) { if let node = node.as(SimpleTypeSpecifierSyntax.self) { self = .simpleTypeSpecifier(node) - } else if let node = node.as(LifetimeTypeSpecifierSyntax.self) { - self = .lifetimeTypeSpecifier(node) } else { return nil } } public static var structure: SyntaxNodeStructure { - return .choices([.node(SimpleTypeSpecifierSyntax.self), .node(LifetimeTypeSpecifierSyntax.self)]) + return .choices([.node(SimpleTypeSpecifierSyntax.self)]) } /// Checks if the current syntax node can be cast to ``SimpleTypeSpecifierSyntax``. @@ -1747,40 +1706,6 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable { 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. - /// - Note: Requires experimental feature `nonescapableTypes`. - #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. - /// - Note: Requires experimental feature `nonescapableTypes`. - #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. - /// - Note: Requires experimental feature `nonescapableTypes`. - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - public func cast(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> LifetimeTypeSpecifierSyntax { - return self.as(LifetimeTypeSpecifierSyntax.self)! - } } public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntax/generated/SyntaxEnum.swift b/Sources/SwiftSyntax/generated/SyntaxEnum.swift index fef31916caa..a5a2e5026f7 100644 --- a/Sources/SwiftSyntax/generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/generated/SyntaxEnum.swift @@ -178,18 +178,6 @@ 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 lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax) case macroDecl(MacroDeclSyntax) case macroExpansionDecl(MacroExpansionDeclSyntax) case macroExpansionExpr(MacroExpansionExprSyntax) @@ -641,12 +629,6 @@ 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 .lifetimeTypeSpecifier: - return .lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax(self)!) case .macroDecl: return .macroDecl(MacroDeclSyntax(self)!) case .macroExpansionDecl: diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index e8efa17158f..495a1bfd30a 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -178,18 +178,6 @@ 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 lifetimeTypeSpecifier case macroDecl case macroExpansionDecl case macroExpansionExpr @@ -378,8 +366,6 @@ public enum SyntaxKind: Sendable { return true case .labeledExprList: return true - case .lifetimeSpecifierArgumentList: - return true case .memberBlockItemList: return true case .multipleTrailingClosureElementList: @@ -766,12 +752,6 @@ public enum SyntaxKind: Sendable { return LabeledStmtSyntax.self case .layoutRequirement: return LayoutRequirementSyntax.self - case .lifetimeSpecifierArgumentList: - return LifetimeSpecifierArgumentListSyntax.self - case .lifetimeSpecifierArgument: - return LifetimeSpecifierArgumentSyntax.self - case .lifetimeTypeSpecifier: - return LifetimeTypeSpecifierSyntax.self case .macroDecl: return MacroDeclSyntax.self case .macroExpansionDecl: diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index 81aa2100d67..549c3329b60 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -1229,36 +1229,6 @@ open class SyntaxRewriter { return visitChildren(node._syntaxNode).cast(LayoutRequirementSyntax.self) } - /// 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._syntaxNode).cast(LifetimeSpecifierArgumentListSyntax.self) - } - - /// 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._syntaxNode).cast(LifetimeSpecifierArgumentSyntax.self) - } - - /// 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._syntaxNode).cast(LifetimeTypeSpecifierSyntax.self) - } - /// Visit a ``MacroDeclSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -2831,18 +2801,6 @@ 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 .lifetimeTypeSpecifier: - return { - self.visitImpl(&$0, LifetimeTypeSpecifierSyntax.self, self.visit) - } case .macroDecl: return { self.visitImpl(&$0, MacroDeclSyntax.self, self.visit) @@ -3653,12 +3611,6 @@ 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 .lifetimeTypeSpecifier: - return visitImpl(&node, LifetimeTypeSpecifierSyntax.self, visit) case .macroDecl: return visitImpl(&node, MacroDeclSyntax.self, visit) case .macroExpansionDecl: diff --git a/Sources/SwiftSyntax/generated/SyntaxTraits.swift b/Sources/SwiftSyntax/generated/SyntaxTraits.swift index 68f8ad515c9..f3e788b21c6 100644 --- a/Sources/SwiftSyntax/generated/SyntaxTraits.swift +++ b/Sources/SwiftSyntax/generated/SyntaxTraits.swift @@ -777,8 +777,6 @@ extension LabeledExprSyntax: WithTrailingCommaSyntax {} extension LabeledSpecializeArgumentSyntax: WithTrailingCommaSyntax {} -extension LifetimeSpecifierArgumentSyntax: WithTrailingCommaSyntax {} - 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 145c8775d43..7ce7ffbc635 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -1964,60 +1964,6 @@ 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 `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. @@ -4175,18 +4121,6 @@ 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 .lifetimeTypeSpecifier: - return { - self.visitImpl(&$0, LifetimeTypeSpecifierSyntax.self, self.visit, self.visitPost) - } case .macroDecl: return { self.visitImpl(&$0, MacroDeclSyntax.self, self.visit, self.visitPost) @@ -5001,12 +4935,6 @@ 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 .lifetimeTypeSpecifier: - visitImpl(&node, LifetimeTypeSpecifierSyntax.self, visit, visitPost) case .macroDecl: visitImpl(&node, MacroDeclSyntax.self, visit, visitPost) case .macroExpansionDecl: diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift index ea8497a3da5..5810fbb2f68 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift @@ -919,241 +919,6 @@ 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 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( - _ unexpectedBeforeDependsOnKeyword: RawUnexpectedNodesSyntax? = nil, - dependsOnKeyword: RawTokenSyntax, - _ unexpectedBetweenDependsOnKeywordAndLeftParen: RawUnexpectedNodesSyntax? = nil, - leftParen: RawTokenSyntax, - _ unexpectedBetweenLeftParenAndScopedKeyword: RawUnexpectedNodesSyntax? = nil, - scopedKeyword: RawTokenSyntax?, - _ unexpectedBetweenScopedKeywordAndArguments: RawUnexpectedNodesSyntax? = nil, - arguments: RawLifetimeSpecifierArgumentListSyntax, - _ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil, - rightParen: RawTokenSyntax, - _ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil, - arena: __shared SyntaxArena - ) { - let raw = RawSyntax.makeLayout( - kind: .lifetimeTypeSpecifier, uninitializedCount: 11, arena: arena) { layout in - layout.initialize(repeating: nil) - layout[0] = unexpectedBeforeDependsOnKeyword?.raw - layout[1] = dependsOnKeyword.raw - layout[2] = unexpectedBetweenDependsOnKeywordAndLeftParen?.raw - layout[3] = leftParen.raw - layout[4] = unexpectedBetweenLeftParenAndScopedKeyword?.raw - layout[5] = scopedKeyword?.raw - layout[6] = unexpectedBetweenScopedKeywordAndArguments?.raw - layout[7] = arguments.raw - layout[8] = unexpectedBetweenArgumentsAndRightParen?.raw - layout[9] = rightParen.raw - layout[10] = unexpectedAfterRightParen?.raw - } - self.init(unchecked: raw) - } - - public var unexpectedBeforeDependsOnKeyword: RawUnexpectedNodesSyntax? { - layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) - } - - public var dependsOnKeyword: RawTokenSyntax { - layoutView.children[1].map(RawTokenSyntax.init(raw:))! - } - - public var unexpectedBetweenDependsOnKeywordAndLeftParen: RawUnexpectedNodesSyntax? { - layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) - } - - public var leftParen: RawTokenSyntax { - layoutView.children[3].map(RawTokenSyntax.init(raw:))! - } - - public var unexpectedBetweenLeftParenAndScopedKeyword: RawUnexpectedNodesSyntax? { - layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) - } - - public var scopedKeyword: RawTokenSyntax? { - layoutView.children[5].map(RawTokenSyntax.init(raw:)) - } - - public var unexpectedBetweenScopedKeywordAndArguments: RawUnexpectedNodesSyntax? { - layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:)) - } - - public var arguments: RawLifetimeSpecifierArgumentListSyntax { - layoutView.children[7].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))! - } - - public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? { - layoutView.children[8].map(RawUnexpectedNodesSyntax.init(raw:)) - } - - public var rightParen: RawTokenSyntax { - layoutView.children[9].map(RawTokenSyntax.init(raw:))! - } - - public var unexpectedAfterRightParen: RawUnexpectedNodesSyntax? { - layoutView.children[10].map(RawUnexpectedNodesSyntax.init(raw:)) - } -} - @_spi(RawSyntax) public struct RawMacroDeclSyntax: RawDeclSyntaxNodeProtocol { @_spi(RawSyntax) diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift index 4a2489c4ba0..0c0e3f7d421 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift @@ -1413,31 +1413,21 @@ public struct RawTypeSpecifierListSyntax: RawSyntaxNodeProtocol { public enum Element: RawSyntaxNodeProtocol { /// A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming` case simpleTypeSpecifier(RawSimpleTypeSpecifierSyntax) - /// A specifier that specifies function parameter on whose lifetime a type depends - /// - Note: Requires experimental feature `nonescapableTypes`. - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - case lifetimeTypeSpecifier(RawLifetimeTypeSpecifierSyntax) public static func isKindOf(_ raw: RawSyntax) -> Bool { - RawSimpleTypeSpecifierSyntax.isKindOf(raw) || RawLifetimeTypeSpecifierSyntax.isKindOf(raw) + RawSimpleTypeSpecifierSyntax.isKindOf(raw) } public var raw: RawSyntax { switch self { case .simpleTypeSpecifier(let node): return node.raw - case .lifetimeTypeSpecifier(let node): - return node.raw } } public init?(_ node: __shared some RawSyntaxNodeProtocol) { if let node = node.as(RawSimpleTypeSpecifierSyntax.self) { self = .simpleTypeSpecifier(node) - } else if let node = node.as(RawLifetimeTypeSpecifierSyntax.self) { - self = .lifetimeTypeSpecifier(node) } else { return nil } @@ -1485,9 +1475,9 @@ public struct RawTypeSpecifierListSyntax: RawSyntaxNodeProtocol { self.init(unchecked: raw) } - public var elements: [RawSyntax] { + public var elements: [RawSimpleTypeSpecifierSyntax] { layoutView.children.map { - RawSyntax(raw: $0!) + RawSimpleTypeSpecifierSyntax(raw: $0!) } } } diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index a5430c16f4a..cee0713132a 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -1713,30 +1713,6 @@ 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 .lifetimeTypeSpecifier: - assert(layout.count == 11) - assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("dependsOn")])) - assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.leftParen)])) - assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 5, verify(layout[5], as: RawTokenSyntax?.self, tokenChoices: [.keyword("scoped")])) - assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 7, verify(layout[7], as: RawLifetimeSpecifierArgumentListSyntax.self)) - assertNoError(kind, 8, verify(layout[8], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 9, verify(layout[9], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.rightParen)])) - assertNoError(kind, 10, verify(layout[10], as: RawUnexpectedNodesSyntax?.self)) case .macroDecl: assert(layout.count == 17) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) @@ -2648,9 +2624,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { 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)]) + assertNoError(kind, index, verify(element, as: RawSimpleTypeSpecifierSyntax.self)) } case .unavailableFromAsyncAttributeArguments: assert(layout.count == 7) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index f6519df7524..bf9d0ae2fdd 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -3255,7 +3255,7 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp /// - returns: A copy of the receiver with the provided `Specifier` /// appended to its `specifiers` collection. @available(*, deprecated, message: "Use node.specifiers.append(newElement) instead") - public func addSpecifier(_ element: Syntax) -> AttributedTypeSyntax { + public func addSpecifier(_ element: SimpleTypeSpecifierSyntax) -> AttributedTypeSyntax { var collection: RawSyntax let arena = SyntaxArena() if let col = raw.layoutView!.children[1] { diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index 9f48aab9adf..27ffa1c8ffd 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -1612,386 +1612,6 @@ 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` -/// -/// - Note: 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: __shared 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 let structure: SyntaxNodeStructure = .layout([ - \Self.unexpectedBeforeParameter, - \Self.parameter, - \Self.unexpectedBetweenParameterAndTrailingComma, - \Self.trailingComma, - \Self.unexpectedAfterTrailingComma - ]) -} - -// MARK: - LifetimeTypeSpecifierSyntax - -/// A specifier that specifies function parameter on whose lifetime a type depends -/// -/// - Note: Requires experimental feature `nonescapableTypes`. -/// -/// ### Children -/// -/// - `dependsOnKeyword`: `dependsOn` -/// - `leftParen`: `(` -/// - `scopedKeyword`: `scoped`? -/// - `arguments`: `LifetimeSpecifierArgumentListSyntax` -/// - `rightParen`: `)` -/// -/// ### Contained in -/// -/// - ``TypeSpecifierListSyntax`` -#if compiler(>=5.8) -@_spi(ExperimentalLanguageFeatures) -#endif -public struct LifetimeTypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { - public let _syntaxNode: Syntax - - public init?(_ node: __shared 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. - /// - dependsOnKeyword: lifetime dependence specifier on the return type - /// - scopedKeyword: lifetime of return value is scoped to the lifetime of the original value - /// - 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, - _ unexpectedBeforeDependsOnKeyword: UnexpectedNodesSyntax? = nil, - dependsOnKeyword: TokenSyntax = .keyword(.dependsOn), - _ unexpectedBetweenDependsOnKeywordAndLeftParen: UnexpectedNodesSyntax? = nil, - leftParen: TokenSyntax = .leftParenToken(), - _ unexpectedBetweenLeftParenAndScopedKeyword: UnexpectedNodesSyntax? = nil, - scopedKeyword: TokenSyntax? = nil, - _ unexpectedBetweenScopedKeywordAndArguments: 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(), ( - unexpectedBeforeDependsOnKeyword, - dependsOnKeyword, - unexpectedBetweenDependsOnKeywordAndLeftParen, - leftParen, - unexpectedBetweenLeftParenAndScopedKeyword, - scopedKeyword, - unexpectedBetweenScopedKeywordAndArguments, - arguments, - unexpectedBetweenArgumentsAndRightParen, - rightParen, - unexpectedAfterRightParen - ))) { (arena, _) in - let layout: [RawSyntax?] = [ - unexpectedBeforeDependsOnKeyword?.raw, - dependsOnKeyword.raw, - unexpectedBetweenDependsOnKeywordAndLeftParen?.raw, - leftParen.raw, - unexpectedBetweenLeftParenAndScopedKeyword?.raw, - scopedKeyword?.raw, - unexpectedBetweenScopedKeywordAndArguments?.raw, - arguments.raw, - unexpectedBetweenArgumentsAndRightParen?.raw, - rightParen.raw, - unexpectedAfterRightParen?.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 unexpectedBeforeDependsOnKeyword: 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) - } - } - - /// lifetime dependence specifier on the return type - /// - /// ### Tokens - /// - /// For syntax trees generated by the parser, this is guaranteed to be `dependsOn`. - public var dependsOnKeyword: 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 unexpectedBetweenDependsOnKeywordAndLeftParen: 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) - } - } - - /// ### Tokens - /// - /// For syntax trees generated by the parser, this is guaranteed to be `(`. - public var leftParen: 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(LifetimeTypeSpecifierSyntax.self) - } - } - - public var unexpectedBetweenLeftParenAndScopedKeyword: 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) - } - } - - /// lifetime of return value is scoped to the lifetime of the original value - /// - /// ### Tokens - /// - /// For syntax trees generated by the parser, this is guaranteed to be `scoped`. - public var scopedKeyword: 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(LifetimeTypeSpecifierSyntax.self) - } - } - - public var unexpectedBetweenScopedKeywordAndArguments: 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(LifetimeTypeSpecifierSyntax.self) - } - } - - public var arguments: LifetimeSpecifierArgumentListSyntax { - get { - return Syntax(self).child(at: 7)!.cast(LifetimeSpecifierArgumentListSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 7, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.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) -> LifetimeTypeSpecifierSyntax { - var collection: RawSyntax - let arena = SyntaxArena() - if let col = raw.layoutView!.children[7] { - 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: 7, - with: collection, - rawNodeArena: arena, - allocationArena: arena - ) - .cast(LifetimeTypeSpecifierSyntax.self) - } - - public var unexpectedBetweenArgumentsAndRightParen: UnexpectedNodesSyntax? { - get { - return Syntax(self).child(at: 8)?.cast(UnexpectedNodesSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 8, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) - } - } - - /// ### Tokens - /// - /// For syntax trees generated by the parser, this is guaranteed to be `)`. - public var rightParen: TokenSyntax { - get { - return Syntax(self).child(at: 9)!.cast(TokenSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 9, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) - } - } - - public var unexpectedAfterRightParen: UnexpectedNodesSyntax? { - get { - return Syntax(self).child(at: 10)?.cast(UnexpectedNodesSyntax.self) - } - set(value) { - self = Syntax(self).replacingChild(at: 10, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) - } - } - - public static let structure: SyntaxNodeStructure = .layout([ - \Self.unexpectedBeforeDependsOnKeyword, - \Self.dependsOnKeyword, - \Self.unexpectedBetweenDependsOnKeywordAndLeftParen, - \Self.leftParen, - \Self.unexpectedBetweenLeftParenAndScopedKeyword, - \Self.scopedKeyword, - \Self.unexpectedBetweenScopedKeywordAndArguments, - \Self.arguments, - \Self.unexpectedBetweenArgumentsAndRightParen, - \Self.rightParen, - \Self.unexpectedAfterRightParen - ]) -} - // MARK: - MacroDeclSyntax /// ### Children diff --git a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift index abc2a1a100c..1b0f229ae86 100644 --- a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift +++ b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift @@ -429,22 +429,6 @@ extension LabeledExprListSyntax { } } -// MARK: - LifetimeSpecifierArgumentListBuilder - -#if compiler(>=5.8) -@_spi(ExperimentalLanguageFeatures) -#endif -@resultBuilder -public struct LifetimeSpecifierArgumentListBuilder: ListBuilder { - public typealias FinalResult = LifetimeSpecifierArgumentListSyntax -} - -extension LifetimeSpecifierArgumentListSyntax { - public init(@LifetimeSpecifierArgumentListBuilder itemsBuilder: () throws -> LifetimeSpecifierArgumentListSyntax) rethrows { - self = try itemsBuilder() - } -} - // MARK: - MemberBlockItemListBuilder @resultBuilder @@ -689,17 +673,6 @@ extension TupleTypeElementListSyntax { @resultBuilder public struct TypeSpecifierListBuilder: ListBuilder { public typealias FinalResult = TypeSpecifierListSyntax - - public static func buildExpression(_ expression: SimpleTypeSpecifierSyntax) -> Component { - buildExpression(.init(expression)) - } - - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - public static func buildExpression(_ expression: LifetimeTypeSpecifierSyntax) -> Component { - buildExpression(.init(expression)) - } } extension TypeSpecifierListSyntax { diff --git a/Tests/SwiftParserTest/AttributeTests.swift b/Tests/SwiftParserTest/AttributeTests.swift index 882839b06ce..620e18d7767 100644 --- a/Tests/SwiftParserTest/AttributeTests.swift +++ b/Tests/SwiftParserTest/AttributeTests.swift @@ -1053,4 +1053,19 @@ final class AttributeTests: ParserTestCase { """ ) } + + func testLifetimeAttribute() { + assertParse( + """ + @lifetime(ne) + func foo(_ ne: NE) -> NE { ne } + """ + ) + assertParse( + """ + @lifetime(neOut: neIn) + func foo(_ neOut: inout NE, _ neIn: NE) { neOut = neIn } + """ + ) + } } diff --git a/Tests/SwiftParserTest/DeclarationTests.swift b/Tests/SwiftParserTest/DeclarationTests.swift index 345ca2739e9..e4061b666e7 100644 --- a/Tests/SwiftParserTest/DeclarationTests.swift +++ b/Tests/SwiftParserTest/DeclarationTests.swift @@ -3271,13 +3271,13 @@ final class DeclarationTests: ParserTestCase { } func testInitializerWithReturnType() { + // Not actually valid, needs to be diagnosed during type checking assertParse( - "init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array) -> dependsOn(a) Self", - experimentalFeatures: .nonescapableTypes + "public init() 1️⃣-> Int", + diagnostics: [ + DiagnosticSpec(message: "initializers cannot have a result type") + ] ) - - // Not actually valid, needs to be diagnosed during type checking - assertParse("public init() -> Int") } func testSendingTypeSpecifier() { diff --git a/Tests/SwiftParserTest/TypeTests.swift b/Tests/SwiftParserTest/TypeTests.swift index 0e8bd40d38f..8b1b419f3f2 100644 --- a/Tests/SwiftParserTest/TypeTests.swift +++ b/Tests/SwiftParserTest/TypeTests.swift @@ -433,104 +433,4 @@ final class TypeTests: ParserTestCase { assertParse("func foo2(_ a: borrowing _const String) {}") } - func testLifetimeSpecifier() { - assertParse("func foo() -> dependsOn(x) X", experimentalFeatures: [.nonescapableTypes]) - - assertParse("func foo() -> dependsOn(x, y) X", experimentalFeatures: [.nonescapableTypes]) - - assertParse( - "func foo() -> dependsOn(1️⃣) X", - diagnostics: [ - DiagnosticSpec( - locationMarker: "1️⃣", - message: "expected parameter reference in lifetime specifier", - fixIts: ["insert parameter reference"] - ) - ], - fixedSource: "func foo() -> dependsOn(<#identifier#>) X", - experimentalFeatures: [.nonescapableTypes] - ) - - assertParse( - "func foo() -> dependsOn(x,1️⃣) X", - diagnostics: [ - DiagnosticSpec( - locationMarker: "1️⃣", - message: "expected parameter reference in lifetime specifier", - fixIts: ["insert parameter reference"] - ) - ], - fixedSource: "func foo() -> dependsOn(x, <#identifier#>) X", - experimentalFeatures: [.nonescapableTypes] - ) - - assertParse("func foo() -> dependsOn(x) dependsOn(scoped y) X", experimentalFeatures: [.nonescapableTypes]) - - assertParse("func foo() -> dependsOn(scoped x) X", experimentalFeatures: [.nonescapableTypes]) - - assertParse( - "func foo() -> dependsOn1️⃣ X", - diagnostics: [ - DiagnosticSpec( - locationMarker: "1️⃣", - message: "expected '(', parameter reference, and ')' in lifetime specifier", - fixIts: ["insert '(', parameter reference, and ')'"] - ) - ], - fixedSource: "func foo() -> dependsOn(<#identifier#>) X", - experimentalFeatures: [.nonescapableTypes] - ) - - assertParse( - "func foo() -> dependsOn(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() -> dependsOn(<#identifier#>*) X", - experimentalFeatures: [.nonescapableTypes] - ) - - assertParse("func foo() -> dependsOn(0) X", diagnostics: [], experimentalFeatures: [.nonescapableTypes]) - - assertParse("func foo() -> dependsOn(self) X", experimentalFeatures: [.nonescapableTypes]) - - assertParse( - "func foo() -> dependsOn1️⃣(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() -> dependsOn - (0) - X - """ - ) - - assertParse( - "func foo() -> dependsOn(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() -> dependsOn(<#identifier#>-1) X", - experimentalFeatures: [.nonescapableTypes] - ) - } } diff --git a/Tests/SwiftParserTest/translated/InitDeinitTests.swift b/Tests/SwiftParserTest/translated/InitDeinitTests.swift index b06771b3e07..ff9aa549eaf 100644 --- a/Tests/SwiftParserTest/translated/InitDeinitTests.swift +++ b/Tests/SwiftParserTest/translated/InitDeinitTests.swift @@ -104,7 +104,10 @@ final class InitDeinitTests: ParserTestCase { struct FooStructConstructorD { init() 1️⃣-> FooStructConstructorD { } } - """ + """, + diagnostics: [ + DiagnosticSpec(message: "initializers cannot have a result type") + ] ) } @@ -422,7 +425,10 @@ final class InitDeinitTests: ParserTestCase { assertParse( """ init(_ foo: T) 1️⃣-> Int where T: Comparable {} - """ + """, + diagnostics: [ + DiagnosticSpec(message: "initializers cannot have a result type") + ] ) }