diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6468ca3f23c..85d0b8b3449 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,6 +71,14 @@ We prefer to not squash commits when merging a PR because, especially for larger - During review, the commits can be reviewed individually, making each review chunk smaller - In case this PR introduced a bug that is identified later, it is possible to check if it resulted from the refactoring or the actual change, thereby making it easier find the lines that introduce the issue. +## Opening a PR + +To submit a PR you don't need permissions on this repo, instead you can fork the repo and create a PR through your forked version. + +For more information and instructions, read the GitHub docs on [forking a repo](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo). + +Once you've pushed your branch, you should see an option on this repository's page to create a PR from a branch in your fork. + ## Review and CI Testing After you opened your PR, a maintainer will review it and test your changes in CI (*Continuous Integration*) by adding a `@swift-ci Please test` comment on the pull request. Once your PR is approved and CI has passed, the maintainer will merge your pull request. diff --git a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift index 9a7098b04c4..b7a9dbe5bea 100644 --- a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift @@ -203,7 +203,8 @@ public let ATTRIBUTE_NODES: [Node] = [ Child( name: "platformVersion", deprecatedName: "availabilityVersionRestriction", - kind: .node(kind: .platformVersion) + kind: .node(kind: .platformVersion), + documentation: "The platform/version pair, e.g. `iOS 10.1`" ), Child( name: "trailingComma", @@ -292,15 +293,19 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "witnessMethodLabel", - kind: .token(choices: [.keyword(.witness_method)]) + kind: .token(choices: [.keyword(.witness_method)]), + documentation: #"The `witnessMethod` label."# ), Child( name: "colon", - kind: .token(choices: [.token(.colon)]) + kind: .token(choices: [.token(.colon)]), + documentation: #"The colon separating the `witnessMethod` label and the original protocol name."# + ), Child( name: "protocolName", - kind: .token(choices: [.token(.identifier)]) + kind: .token(choices: [.token(.identifier)]), + documentation: "The original protocol name." ), ] ), @@ -454,6 +459,7 @@ public let ATTRIBUTE_NODES: [Node] = [ name: "kindSpecifier", deprecatedName: "diffKind", kind: .token(choices: [.keyword(._forward), .keyword(.reverse), .keyword(._linear)]), + documentation: "The differentiability kind, if it exists.", isOptional: true ), Child( @@ -467,6 +473,7 @@ public let ATTRIBUTE_NODES: [Node] = [ name: "arguments", deprecatedName: "diffParams", kind: .node(kind: .differentiabilityWithRespectToArgument), + documentation: "The differentiability arguments, if any exists.", isOptional: true ), Child( @@ -675,11 +682,13 @@ public let ATTRIBUTE_NODES: [Node] = [ name: "name", kind: .node(kind: .token), nameForDiagnostics: "name", + documentation: "The identifier name for a nullary selection, if it exists.", isOptional: true ), Child( name: "colon", kind: .token(choices: [.token(.colon)]), + documentation: "The colon separating the label and the value or a colon representing an unlabeled argument", isOptional: true ), ] diff --git a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift index bbe76f8e776..1d75123631e 100644 --- a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift @@ -214,9 +214,8 @@ public let EXPR_NODES: [Node] = [ ), Node( - kind: .canImportExpr, + kind: ._canImportExpr, base: .expr, - deprecationMessage: "'canImport' directives are now represented as a `FunctionCallExpr`", nameForDiagnostics: "'canImport' expression", children: [ Child( @@ -233,7 +232,7 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "versionInfo", - kind: .node(kind: .canImportVersionInfo), + kind: .node(kind: ._canImportVersionInfo), isOptional: true ), Child( @@ -244,9 +243,8 @@ public let EXPR_NODES: [Node] = [ ), Node( - kind: .canImportVersionInfo, + kind: ._canImportVersionInfo, base: .expr, - deprecationMessage: "'canImport' directives are now represented as a `FunctionCallExpr`", nameForDiagnostics: nil, children: [ Child( diff --git a/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift b/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift index 895411bace0..d66fc645917 100644 --- a/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift +++ b/CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift @@ -43,8 +43,17 @@ public struct KeywordSpec { /// /// This is typically used to mark APIs as SPI when the keyword is part of an experimental language feature. public var apiAttributes: AttributeListSyntax { - guard isExperimental else { return "" } - return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .newline) + let attrList = AttributeListSyntax { + if isExperimental { + let experimentalSPI: AttributeListSyntax = """ + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + """ + experimentalSPI.with(\.trailingTrivia, .newline) + } + } + return attrList.with(\.trailingTrivia, attrList.isEmpty ? [] : .newline) } /// Initializes a new `KeywordSpec` instance. @@ -108,9 +117,7 @@ public enum Keyword: CaseIterable { case _Class case _compilerInitialized case _const - case _consume case _consuming - case _copy case _documentation case _dynamicReplacement case _effects @@ -121,7 +128,6 @@ public enum Keyword: CaseIterable { case _local case _modify case _move - case _mutate case _mutating case _NativeClass case _NativeRefCountedObject @@ -186,6 +192,7 @@ public enum Keyword: CaseIterable { case `default` case `defer` case `deinit` + case dependsOn case deprecated case derivative case didSet @@ -275,6 +282,7 @@ public enum Keyword: CaseIterable { case reverse case right case safe + case scoped case `self` case `Self` case Sendable @@ -343,12 +351,8 @@ 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: @@ -369,8 +373,6 @@ 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: @@ -499,6 +501,8 @@ 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: @@ -675,6 +679,8 @@ 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 ee3b3f5adfe..9c6dd5aa47d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Node.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Node.swift @@ -40,9 +40,6 @@ public class Node { /// The kind of node’s supertype. This kind must have `isBase == true` public let base: SyntaxNodeKind - /// If this syntax node has been deprecated, a message that describes the deprecation. - public let deprecationMessage: String? - /// The experimental feature the node is part of, or `nil` if this isn't /// for an experimental feature. public let experimentalFeature: ExperimentalFeature? @@ -109,9 +106,6 @@ public class Node { """ experimentalSPI.with(\.trailingTrivia, .newline) } - if let deprecationMessage { - "@available(*, deprecated, message: \(literal: deprecationMessage))" - } if forRaw { "@_spi(RawSyntax)" } @@ -133,7 +127,6 @@ public class Node { init( kind: SyntaxNodeKind, base: SyntaxNodeKind, - deprecationMessage: String? = nil, experimentalFeature: ExperimentalFeature? = nil, nameForDiagnostics: String?, documentation: String? = nil, @@ -146,7 +139,6 @@ public class Node { self.kind = kind self.base = base - self.deprecationMessage = deprecationMessage self.experimentalFeature = experimentalFeature self.nameForDiagnostics = nameForDiagnostics self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) @@ -241,7 +233,11 @@ 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.doccLink).``\($0.node.syntaxType)/\(childName)``" + if $0.node.isAvailableInDocc { + return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``" + } else { + return " - \($0.node.doccLink).`\($0.node.syntaxType)/\(childName)`" + } } else { return " - \($0.node.doccLink)" } @@ -265,7 +261,7 @@ public class Node { let list = SYNTAX_NODES - .filter { $0.base == self.kind && !$0.isExperimental } + .filter { $0.base == self.kind && !$0.isExperimental && !$0.kind.isDeprecated } .map { "- \($0.kind.doccLink)" } .joined(separator: "\n") @@ -288,7 +284,6 @@ public class Node { init( kind: SyntaxNodeKind, base: SyntaxNodeKind, - deprecationMessage: String? = nil, experimentalFeature: ExperimentalFeature? = nil, nameForDiagnostics: String?, documentation: String? = nil, @@ -298,7 +293,6 @@ public class Node { self.kind = kind precondition(base == .syntaxCollection) self.base = base - self.deprecationMessage = deprecationMessage self.experimentalFeature = experimentalFeature self.nameForDiagnostics = nameForDiagnostics self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) diff --git a/CodeGeneration/Sources/SyntaxSupport/String+Extensions.swift b/CodeGeneration/Sources/SyntaxSupport/String+Extensions.swift index 93884aa0e35..32d7b32809a 100644 --- a/CodeGeneration/Sources/SyntaxSupport/String+Extensions.swift +++ b/CodeGeneration/Sources/SyntaxSupport/String+Extensions.swift @@ -11,8 +11,18 @@ //===----------------------------------------------------------------------===// public extension StringProtocol { - var withFirstCharacterLowercased: String { prefix(1).lowercased() + dropFirst() } - var withFirstCharacterUppercased: String { prefix(1).uppercased() + dropFirst() } + var withFirstCharacterLowercased: String { + guard first?.isLetter ?? false else { + return String(first!) + dropFirst().withFirstCharacterLowercased + } + return prefix(1).lowercased() + dropFirst() + } + var withFirstCharacterUppercased: String { + guard first?.isLetter ?? false else { + return String(first!) + dropFirst().withFirstCharacterUppercased + } + return prefix(1).uppercased() + dropFirst() + } var backtickedIfNeeded: String { if Keyword.allCases.map(\.spec).contains(where: { $0.name == self && ($0.isLexerClassified || $0.name == "Type" || $0.name == "Protocol") @@ -23,3 +33,12 @@ public extension StringProtocol { } } } + +extension String { + public var droppingLeadingUnderscores: String { + if first == "_" { + return String(self.dropFirst()) + } + return self + } +} diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift index 5ea26147675..3c460095a91 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift @@ -20,6 +20,8 @@ import SwiftSyntaxBuilder public enum SyntaxNodeKind: String, CaseIterable { // Please keep this list sorted alphabetically + case _canImportExpr + case _canImportVersionInfo case accessorBlock case accessorDecl case accessorDeclList @@ -47,8 +49,6 @@ public enum SyntaxNodeKind: String, CaseIterable { case booleanLiteralExpr case borrowExpr case breakStmt - case canImportExpr - case canImportVersionInfo case catchClause case catchClauseList case catchItem @@ -355,14 +355,25 @@ public enum SyntaxNodeKind: String, CaseIterable { } } + /// Whether the node is public API and not underscored/deprecated and can thus be referenced in docc links. + public var isAvailableInDocc: Bool { + if let node = SYNTAX_NODE_MAP[self], node.isExperimental { + return false + } else if isDeprecated { + return false + } else { + return true + } + } + /// 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 { + if isAvailableInDocc { return "``\(syntaxType)``" + } else { + return "`\(syntaxType)`" } } @@ -405,6 +416,8 @@ public enum SyntaxNodeKind: String, CaseIterable { /// deprecated. public var deprecatedRawValue: String? { switch self { + case ._canImportExpr: return "canImportExpr" + case ._canImportVersionInfo: return "canImportVersionInfo" case .accessorDeclList: return "accessorList" case .accessorParameters: return "accessorParameter" case .associatedTypeDecl: return "associatedtypeDecl" @@ -475,4 +488,24 @@ public enum SyntaxNodeKind: String, CaseIterable { default: return nil } } + + public var deprecationMessage: String? { + switch self { + case ._canImportExpr: return "'canImport' directives are now represented as a `FunctionCallExpr`" + case ._canImportVersionInfo: return "'canImport' directives are now represented as a `FunctionCallExpr`" + default: return nil + } + } + + public var isDeprecated: Bool { + return rawValue.first == "_" + } + + var deprecationAttribute: AttributeSyntax? { + if let deprecationMessage = deprecationMessage { + AttributeSyntax("@available(*, deprecated, message: \(literal: deprecationMessage)") + } else { + AttributeSyntax(#"@available(*, deprecated, renamed: "\#(syntaxType)")"#) + } + } } diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift index f06a97fa329..3987c07cbfc 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift @@ -10,8 +10,8 @@ // //===----------------------------------------------------------------------===// -public let SYNTAX_NODES: [Node] = - (COMMON_NODES +private let unsortedSyntaxNodes: [Node] = + COMMON_NODES + EXPR_NODES + DECL_NODES + ATTRIBUTE_NODES @@ -19,7 +19,15 @@ public let SYNTAX_NODES: [Node] = + GENERIC_NODES + TYPE_NODES + PATTERN_NODES - + AVAILABILITY_NODES).sorted { $0.kind.syntaxType.description < $1.kind.syntaxType.description } + + AVAILABILITY_NODES + +public let SYNTAX_NODES: [Node] = + unsortedSyntaxNodes + .sorted { (lhs: Node, rhs: Node) -> Bool in + let lhsSortKey = lhs.kind.syntaxType.description.droppingLeadingUnderscores + let rhsSortKey = rhs.kind.syntaxType.description.droppingLeadingUnderscores + return lhsSortKey < rhsSortKey + } /// A lookup table of nodes indexed by their kind. public let SYNTAX_NODE_MAP: [SyntaxNodeKind: Node] = Dictionary( diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index f337aa226f3..f89ddb531d9 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -543,30 +543,30 @@ public let TYPE_NODES: [Node] = [ ), Node( - kind: .lifetimeSpecifierArguments, + kind: .lifetimeTypeSpecifier, 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" - ], + 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"), - documentation: """ - The function parameters that the lifetime of the annotated type depends on. - """ + kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments") ), Child( name: "rightParen", @@ -575,30 +575,6 @@ public let TYPE_NODES: [Node] = [ ] ), - 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, diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift index 18f72a77a4a..60d9aeb0c52 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift @@ -42,7 +42,10 @@ fileprivate extension Node { func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax { return SourceFileSyntax(leadingTrivia: copyrightHeader) { for node in SYNTAX_NODES - where node.kind.isBase && nodesStartingWith.contains(node.kind.syntaxType.description.first!) { + where node.kind.isBase + && nodesStartingWith.contains(node.kind.syntaxType.description.droppingLeadingUnderscores.first!) + && !node.kind.isDeprecated + { DeclSyntax( """ \(node.apiAttributes(forRaw: true))\ @@ -51,7 +54,8 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax { ) } - for node in SYNTAX_NODES where nodesStartingWith.contains(node.kind.syntaxType.description.first!) { + for node in SYNTAX_NODES + where nodesStartingWith.contains(node.kind.syntaxType.description.droppingLeadingUnderscores.first!) { try! StructDeclSyntax( """ \(node.apiAttributes(forRaw: true))\ diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift index ff1edd72331..02c1f9ce1b7 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift @@ -15,12 +15,19 @@ import SwiftSyntaxBuilder import SyntaxSupport import Utils +func deprecationAttribute(for syntaxKind: SyntaxNodeKind) -> AttributeSyntax { + if let deprecationMessage = syntaxKind.deprecationMessage { + return AttributeSyntax("@available(*, deprecated, message: \(literal: deprecationMessage))") + } + return AttributeSyntax(#"@available(*, deprecated, renamed: "\#(syntaxKind.syntaxType)")"#) +} + let renamedSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { for syntaxKind in SyntaxNodeKind.allCases.sorted(by: { $0.deprecatedRawValue ?? "" < $1.deprecatedRawValue ?? "" }) { if let deprecatedName = syntaxKind.deprecatedRawValue { DeclSyntax( """ - @available(*, deprecated, renamed: "\(syntaxKind.syntaxType)") + \(deprecationAttribute(for: syntaxKind)) public typealias \(raw: deprecatedName.withFirstCharacterUppercased)Syntax = \(syntaxKind.syntaxType) """ ) @@ -33,6 +40,7 @@ let renamedSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { if let deprecatedName = syntaxKind.deprecatedRawValue { DeclSyntax( """ + \(deprecationAttribute(for: syntaxKind)) static var \(raw: deprecatedName): Self { return .\(syntaxKind.varOrCaseName) } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift index 69c4282b85f..d81e1b11ca3 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift @@ -39,7 +39,7 @@ let nodesSections: String = { let baseTypes = ["\(baseKind.syntaxType)", "\(baseKind.syntaxType)Protocol", "Missing\(baseKind.syntaxType)"] let leafTypes = SYNTAX_NODES - .filter({ $0.base == baseKind && !$0.kind.isMissing && !$0.isExperimental }) + .filter({ $0.base == baseKind && !$0.kind.isMissing && !$0.isExperimental && !$0.kind.isDeprecated }) .map(\.kind.syntaxType.description) addSection(heading: heading, types: baseTypes + leafTypes) } @@ -56,7 +56,7 @@ let nodesSections: String = { } return [node.kind.syntaxType.description] + node.elementChoices - .filter { SYNTAX_NODE_MAP[$0] != nil && !SYNTAX_NODE_MAP[$0]!.isExperimental } + .filter { SYNTAX_NODE_MAP[$0] != nil && !SYNTAX_NODE_MAP[$0]!.isExperimental && !$0.isDeprecated } .map(\.syntaxType.description) .filter { !handledSyntaxTypes.contains($0) } }) @@ -64,14 +64,16 @@ let nodesSections: String = { addSection( heading: "Attributes", - types: ATTRIBUTE_NODES.filter({ !$0.isExperimental }).map(\.kind.syntaxType.description).sorted() + types: ATTRIBUTE_NODES.filter({ !$0.isExperimental && !$0.kind.isDeprecated }).map(\.kind.syntaxType.description) + .sorted() ) addSection( heading: "Miscellaneous Syntax", - types: SYNTAX_NODES.filter({ !$0.isExperimental }).map(\.kind.syntaxType.description).filter({ - !handledSyntaxTypes.contains($0) - }) + types: SYNTAX_NODES.filter({ !$0.isExperimental && !$0.kind.isDeprecated }).map(\.kind.syntaxType.description) + .filter({ + !handledSyntaxTypes.contains($0) + }) ) addSection(heading: "Traits", types: TRAITS.map { "\($0.protocolName)" }) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift index ca435890dbb..f983a49ed9f 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift @@ -22,7 +22,7 @@ import Utils func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax { SourceFileSyntax(leadingTrivia: copyrightHeader) { for node in SYNTAX_NODES.compactMap(\.layoutNode) - where nodesStartingWith.contains(node.kind.syntaxType.description.first!) { + where nodesStartingWith.contains(node.kind.syntaxType.description.droppingLeadingUnderscores.first!) { // We are actually handling this node now try! StructDeclSyntax( """ diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift index 799c8771413..e45b6c3b8b0 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift @@ -31,11 +31,32 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { """ ) { DeclSyntax("public let viewMode: SyntaxTreeViewMode") + DeclSyntax( + """ + /// The arena in which the parents of rewritten nodes should be allocated. + /// + /// The `SyntaxRewriter` subclass is responsible for generating the rewritten nodes. To incorporate them into the + /// tree, all of the rewritten node's parents also need to be re-created. This is the arena in which those + /// intermediate nodes should be allocated. + private let arena: SyntaxArena? + """ + ) DeclSyntax( """ public init(viewMode: SyntaxTreeViewMode = .sourceAccurate) { self.viewMode = viewMode + self.arena = nil + } + """ + ) + + DeclSyntax( + """ + @_spi(RawSyntax) + public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, arena: SyntaxArena? = nil) { + self.viewMode = viewMode + self.arena = arena } """ ) @@ -346,7 +367,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { // Sanity check, ensure the new children are the same length. precondition(newLayout.count == node.raw.layoutView!.children.count) - let arena = SyntaxArena() + let arena = self.arena ?? SyntaxArena() let newRaw = node.raw.layoutView!.replacingLayout(with: Array(newLayout), arena: arena) // 'withExtendedLifetime' to keep 'SyntaxArena's of them alive until here. return withExtendedLifetime(rewrittens) { diff --git a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift index 49028b06247..93046782bf3 100644 --- a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift +++ b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift @@ -136,7 +136,7 @@ class ValidateSyntaxNodes: XCTestCase { failures, expectedFailures: [ ValidationFailure( - node: .canImportVersionInfo, + node: ._canImportVersionInfo, message: "has base kind 'ExprSyntax' but type name doesn’t have 'ExprSyntax' suffix" ), ValidationFailure( @@ -535,7 +535,7 @@ class ValidateSyntaxNodes: XCTestCase { expectedFailures: [ ValidationFailure(node: .accessorParameters, message: "could conform to trait 'NamedDecl' but does not"), ValidationFailure(node: .availabilityCondition, message: "could conform to trait 'Parenthesized' but does not"), - ValidationFailure(node: .canImportExpr, message: "could conform to trait 'Parenthesized' but does not"), + ValidationFailure(node: ._canImportExpr, message: "could conform to trait 'Parenthesized' but does not"), ValidationFailure( node: .differentiabilityArguments, message: "could conform to trait 'Parenthesized' but does not" @@ -550,6 +550,7 @@ class ValidateSyntaxNodes: XCTestCase { node: .yieldedExpressionsClause, message: "could conform to trait 'Parenthesized' but does not" ), + ValidationFailure(node: .lifetimeTypeSpecifier, message: "could conform to trait 'Parenthesized' but does not"), ] ) } diff --git a/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift b/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift new file mode 100644 index 00000000000..01510a12726 --- /dev/null +++ b/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftSyntax +import SwiftSyntaxMacros + +public struct EnvironmentValueMacro: AccessorMacro { + public static func expansion( + of node: AttributeSyntax, + providingAccessorsOf declaration: some DeclSyntaxProtocol, + in context: some MacroExpansionContext + ) throws -> [AccessorDeclSyntax] { + guard + case let .argumentList(arguments) = node.arguments, + let argument = arguments.first + else { return [] } + + return [ + """ + get { self[\(argument.expression)] } + """, + """ + set { self[\(argument.expression)] = newValue } + """, + ] + } +} diff --git a/Examples/Sources/MacroExamples/Implementation/Plugin.swift b/Examples/Sources/MacroExamples/Implementation/Plugin.swift index e5960e80712..cd157e62baf 100644 --- a/Examples/Sources/MacroExamples/Implementation/Plugin.swift +++ b/Examples/Sources/MacroExamples/Implementation/Plugin.swift @@ -26,6 +26,7 @@ struct MyPlugin: CompilerPlugin { DefaultFatalErrorImplementationMacro.self, DictionaryStorageMacro.self, DictionaryStoragePropertyMacro.self, + EnvironmentValueMacro.self, EquatableExtensionMacro.self, FontLiteralMacro.self, FuncUniqueMacro.self, diff --git a/Examples/Sources/MacroExamples/Interface/AccessorMacros.swift b/Examples/Sources/MacroExamples/Interface/AccessorMacros.swift new file mode 100644 index 00000000000..17b6f16244e --- /dev/null +++ b/Examples/Sources/MacroExamples/Interface/AccessorMacros.swift @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#if canImport(SwiftUI) + +import SwiftUI + +// MARK: - EnvironmentValue Accessor + +/// Adds getter / setter to an attached environment value with specified EnvironmentKey +@attached(accessor) +public macro EnvironmentValue(for key: any EnvironmentKey.Type) = + #externalMacro(module: "MacroExamplesImplementation", type: "EnvironmentValueMacro") + +#endif diff --git a/Examples/Sources/MacroExamples/Playground/AccessorMacrosPlayground.swift b/Examples/Sources/MacroExamples/Playground/AccessorMacrosPlayground.swift new file mode 100644 index 00000000000..e100945a573 --- /dev/null +++ b/Examples/Sources/MacroExamples/Playground/AccessorMacrosPlayground.swift @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +// MARK: - EnvironmentValue Accessor + +import MacroExamplesInterface + +#if canImport(SwiftUI) + +import SwiftUI + +private struct MyEnvironmentKey: EnvironmentKey { + static let defaultValue: String = "Default value" +} + +extension EnvironmentValues { + @EnvironmentValue(for: MyEnvironmentKey.self) + var myCustomValue: String +} + +func runEnvironmentValueAccessorMacroPlayground() { + var environmentValues = EnvironmentValues() + print("Default myCustomValue: \(environmentValues.myCustomValue)") + environmentValues.myCustomValue = "New value" + print("New myCustomValue: \(environmentValues.myCustomValue)") +} + +#endif diff --git a/Examples/Sources/MacroExamples/Playground/main.swift b/Examples/Sources/MacroExamples/Playground/main.swift index d9af26d3e0e..674b9b9b745 100644 --- a/Examples/Sources/MacroExamples/Playground/main.swift +++ b/Examples/Sources/MacroExamples/Playground/main.swift @@ -47,3 +47,11 @@ runMemberMacrosPlayground() // MARK: - Peer Macros runPeerMacrosPlayground() + +// MARK: - Accessor Macros + +#if canImport(SwiftUI) + +runEnvironmentValueAccessorMacroPlayground() + +#endif diff --git a/Examples/Tests/MacroExamples/Implementation/Accessor/EnvironmentValueMacroTests.swift b/Examples/Tests/MacroExamples/Implementation/Accessor/EnvironmentValueMacroTests.swift new file mode 100644 index 00000000000..73749476ebb --- /dev/null +++ b/Examples/Tests/MacroExamples/Implementation/Accessor/EnvironmentValueMacroTests.swift @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import MacroExamplesImplementation +import SwiftSyntaxMacros +import SwiftSyntaxMacrosTestSupport +import XCTest + +final class EnvironmentValueMacroMacroTests: XCTestCase { + private let macros = ["EnvironmentValue": EnvironmentValueMacro.self] + + func testEnvironmentValue() { + assertMacroExpansion( + """ + extension EnvironmentValues { + @EnvironmentValue(for: MyEnvironmentKey.self) + var myCustomValue: String + } + """, + expandedSource: """ + extension EnvironmentValues { + var myCustomValue: String { + get { + self[MyEnvironmentKey.self] + } + set { + self[MyEnvironmentKey.self] = newValue + } + } + } + """, + macros: macros + ) + } +} diff --git a/Package.swift b/Package.swift index ffd4fabb57b..7de7c06d9bc 100644 --- a/Package.swift +++ b/Package.swift @@ -336,9 +336,6 @@ var rawSyntaxValidation: Bool { hasEnvironmentVariable("SWIFTSYNTAX_ENABLE_RAWSY /// See CONTRIBUTING.md for more information var alternateTokenIntrospection: Bool { hasEnvironmentVariable("SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION") } -/// Assume that swift-argument-parser is checked out next to swift-syntax and use that instead of fetching a remote dependency. -var useLocalDependencies: Bool { hasEnvironmentVariable("SWIFTCI_USE_LOCAL_DEPS") } - // MARK: - Compute custom build settings // These build settings apply to the target and the corresponding test target. diff --git a/Sources/SwiftBasicFormat/BasicFormat.swift b/Sources/SwiftBasicFormat/BasicFormat.swift index b1449e05650..e94bae99910 100644 --- a/Sources/SwiftBasicFormat/BasicFormat.swift +++ b/Sources/SwiftBasicFormat/BasicFormat.swift @@ -148,7 +148,7 @@ open class BasicFormat: SyntaxRewriter { return true case .ifConfigClauseList: return true - case .memberDeclList: + case .memberBlockItemList: return true case .switchCaseList: return true diff --git a/Sources/SwiftParser/Declarations.swift b/Sources/SwiftParser/Declarations.swift index 7900150be3a..d0f172b2ee9 100644 --- a/Sources/SwiftParser/Declarations.swift +++ b/Sources/SwiftParser/Declarations.swift @@ -711,7 +711,7 @@ extension Parser { extension Parser { mutating func parseMemberBlockItem() -> RawMemberBlockItemSyntax? { let startToken = self.currentToken - if let syntax = self.loadCurrentSyntaxNodeFromCache(for: .memberDeclListItem) { + if let syntax = self.loadCurrentSyntaxNodeFromCache(for: .memberBlockItem) { self.registerNodeForIncrementalParse(node: syntax.raw, startToken: startToken) return RawMemberBlockItemSyntax(syntax.raw) } @@ -1262,11 +1262,33 @@ extension Parser { let (unexpectedBeforeIntroducer, introducer) = self.eat(handle) let hasTryBeforeIntroducer = unexpectedBeforeIntroducer?.containsToken(where: { TokenSpec(.try) ~= $0 }) ?? false + var attrs = attrs var elements = [RawPatternBindingSyntax]() do { var keepGoing: RawTokenSyntax? = nil var loopProgress = LoopProgressCondition() repeat { + var unexpectedBeforePattern: RawUnexpectedNodesSyntax? + + if self.at(.atSign), attrs.attributes.isEmpty { + let recoveredAttributes = self.parseAttributeList() + unexpectedBeforePattern = RawUnexpectedNodesSyntax( + [recoveredAttributes], + arena: self.arena + ) + + /// Create a version of the same attribute with all tokens missing. + class TokenMissingMaker: SyntaxRewriter { + override func visit(_ token: TokenSyntax) -> TokenSyntax { + return .init(token.tokenKind, presence: .missing) + } + } + let tokenMissingMaker = TokenMissingMaker(arena: self.arena) + let missingAttributes = tokenMissingMaker.rewrite( + Syntax(raw: RawSyntax(recoveredAttributes), rawNodeArena: arena) + ).raw + attrs.attributes = missingAttributes.cast(RawAttributeListSyntax.self) + } var (pattern, typeAnnotation) = self.parseTypedPattern() @@ -1344,6 +1366,7 @@ extension Parser { keepGoing = self.consume(if: .comma) elements.append( RawPatternBindingSyntax( + unexpectedBeforePattern, pattern: pattern, typeAnnotation: typeAnnotation, initializer: initializer, diff --git a/Sources/SwiftParser/TokenPrecedence.swift b/Sources/SwiftParser/TokenPrecedence.swift index a7e66423ba2..f61d51c1902 100644 --- a/Sources/SwiftParser/TokenPrecedence.swift +++ b/Sources/SwiftParser/TokenPrecedence.swift @@ -233,7 +233,7 @@ enum TokenPrecedence: Comparable { .__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local, .inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume, ._resultDependsOnSelf, ._resultDependsOn, - .transferring, ._consume, ._copy, ._mutate, + .transferring, .dependsOn, .scoped, // Accessors .get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress, .mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify, diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index 1ba26ee569d..0c1102dabf2 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -900,33 +900,31 @@ extension Parser.Lookahead { } extension Parser { - private mutating func parseLifetimeTypeSpecifier( - specifierHandle: TokenConsumptionHandle - ) -> RawTypeSpecifierListSyntax.Element { - let specifier = self.eat(specifierHandle) + 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 arguments = RawLifetimeSpecifierArgumentsSyntax( - leftParen: missingToken(.leftParen), - arguments: RawLifetimeSpecifierArgumentListSyntax( - elements: [ - RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena) - ], - arena: self.arena - ), - rightParen: missingToken(.rightParen), + let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax( + elements: [ + RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena) + ], arena: self.arena ) let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax( - specifier: specifier, - arguments: arguments, + 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() @@ -947,18 +945,16 @@ extension Parser { } while keepGoing != nil && self.hasProgressed(&loopProgress) let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(elements: arguments, arena: self.arena) let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen) - let argumentsSyntax = RawLifetimeSpecifierArgumentsSyntax( + let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax( + unexpectedBeforeDependsOnKeyword, + dependsOnKeyword: dependsOnKeyword, leftParen: leftParen, + scopedKeyword: scoped, arguments: lifetimeSpecifierArgumentList, unexpectedBeforeRightParen, rightParen: rightParen, arena: self.arena ) - let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax( - specifier: specifier, - arguments: argumentsSyntax, - arena: self.arena - ) return .lifetimeTypeSpecifier(lifetimeSpecifier) } @@ -976,20 +972,18 @@ extension Parser { 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: + 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(specifierHandle: specifierHandle)) + specifiers.append(parseLifetimeTypeSpecifier()) } else { break SPECIFIER_PARSING } + } else { + break SPECIFIER_PARSING } } specifiers += misplacedSpecifiers.map { diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index 98c91c193d4..952b584e300 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -404,7 +404,7 @@ extension BooleanLiteralExprSyntax { } } -extension CanImportVersionInfoSyntax { +extension _CanImportVersionInfoSyntax { @_spi(Diagnostics) public enum LabelOptions: TokenSpecSet { case _version @@ -802,11 +802,15 @@ extension DeclModifierSyntax { case `private` case `public` case reasync + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _resultDependsOnSelf case required case `static` + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case transferring case unowned case weak @@ -2623,79 +2627,6 @@ extension LifetimeSpecifierArgumentSyntax { } } -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 { @@ -2980,11 +2911,17 @@ extension OptionalBindingConditionSyntax { case `let` case `var` case `inout` + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _mutating + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _borrowing + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _consuming init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { @@ -3405,9 +3342,13 @@ extension SimpleTypeSpecifierSyntax { case _const case borrowing case consuming + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case transferring + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _resultDependsOn init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { @@ -3952,11 +3893,17 @@ extension ValueBindingPatternSyntax { case `let` case `var` case `inout` + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _mutating + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _borrowing + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _consuming init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { @@ -4043,11 +3990,17 @@ extension VariableDeclSyntax { case `let` case `var` case `inout` + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _mutating + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _borrowing + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _consuming init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) { diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index e5fa61308da..a7579573dd0 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -262,7 +262,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { unexpectedTokenCondition: { EffectSpecifier(token: $0) != nil }, correctTokens: [effectSpecifiers?.asyncSpecifier, effectSpecifiers?.throwsClause?.throwsSpecifier], message: { EffectsSpecifierAfterArrow(effectsSpecifiersAfterArrow: $0) }, - moveFixIt: { MoveTokensInFrontOfFixIt(movedTokens: $0, inFrontOf: .arrow) }, + moveFixIt: { MoveNodesInFrontOfFixIt(movedNodes: $0, inFrontOf: .arrow) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } ) } @@ -324,7 +324,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { unexpectedTokenCondition: { AsyncEffectSpecifier(token: $0) != nil }, correctTokens: [node.asyncSpecifier], message: { AsyncMustPrecedeThrows(asyncKeywords: $0, throwsKeyword: throwsClause.throwsSpecifier) }, - moveFixIt: { MoveTokensInFrontOfFixIt(movedTokens: $0, inFrontOf: throwsClause.throwsSpecifier.tokenKind) }, + moveFixIt: { MoveNodesInFrontOfFixIt(movedNodes: $0, inFrontOf: throwsClause.throwsSpecifier.tokenKind) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } ) } @@ -2052,6 +2052,27 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { moveFixIt: { MoveTokensAfterFixIt(movedTokens: $0, after: .equal) }, removeRedundantFixIt: { RemoveRedundantFixIt(removeTokens: $0) } ) + + if node.attributes.isMissingAllTokens, + let unexpected = node.bindings.compactMap({ $0.unexpectedBeforePattern }).first, + unexpected.only?.is(AttributeListSyntax.self) ?? false + { + let fixIt = FixIt( + message: MoveNodesInFrontOfFixIt(movedNodes: [unexpected], inFrontOf: node.bindingSpecifier.tokenKind), + changes: [ + .makeMissing(unexpected), + .makePresent(node.attributes, trailingTrivia: .space), + ] + ) + + addDiagnostic( + unexpected, + .misplacedAttributeInVarDecl, + fixIts: [fixIt], + handledNodes: [node.attributes.id, unexpected.id] + ) + } + return .visitChildren } diff --git a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift index 4e11b4671d9..e7233d7610f 100644 --- a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift +++ b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift @@ -191,6 +191,9 @@ extension DiagnosticMessage where Self == StaticParserError { public static var maximumNestingLevelOverflow: Self { .init("parsing has exceeded the maximum nesting level") } + public static var misplacedAttributeInVarDecl: Self { + .init("misplaced attribute in variable declaration") + } public static var missingColonAndExprInTernaryExpr: Self { .init("expected ':' and expression after '? ...' in ternary expression") } @@ -710,15 +713,15 @@ public struct MoveTokensAfterFixIt: ParserFixIt { } } -public struct MoveTokensInFrontOfFixIt: ParserFixIt { - /// The token that should be moved - public let movedTokens: [TokenSyntax] +public struct MoveNodesInFrontOfFixIt: ParserFixIt { + /// The nodes that should be moved + public let movedNodes: [Node] - /// The token before which 'movedTokens' should be moved + /// The token before which `movedNodes` should be moved public let inFrontOf: TokenKind public var message: String { - "move \(nodesDescription(movedTokens, format: false)) in front of '\(inFrontOf.nameForDiagnostics)'" + "move \(nodesDescription(movedNodes, format: false)) in front of '\(inFrontOf.nameForDiagnostics)'" } } diff --git a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift index 8b2ccf9935c..4ecbb908412 100644 --- a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift @@ -61,7 +61,7 @@ extension SyntaxKind { return "'_borrow' expression" case .breakStmt: return "'break' statement" - case .canImportExpr: + case ._canImportExpr: return "'canImport' expression" case .catchClauseList: return "'catch' clause" diff --git a/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md b/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md index 3ffec83b129..b43846641b6 100644 --- a/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md +++ b/Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md @@ -102,8 +102,6 @@ These articles are intended for developers wishing to contribute to SwiftSyntax - - - -- -- - - - diff --git a/Sources/SwiftSyntax/Syntax.swift b/Sources/SwiftSyntax/Syntax.swift index 5763510ab8b..e4aee94a2b7 100644 --- a/Sources/SwiftSyntax/Syntax.swift +++ b/Sources/SwiftSyntax/Syntax.swift @@ -16,7 +16,11 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable { /// We need a heap indirection to store a syntax node's parent. We could use an indirect enum here but explicitly /// modelling it using a class allows us to re-use these heap-allocated objects in `SyntaxVisitor`. - final class Info: Sendable { + /// + /// - Note: `@unchecked Sendable` because `info` is mutable. In Swift 6 and above the variable can be declared as + /// `nonisolated(unsafe)` but that attribute doesn't exist in previous Swift versions and a checked Sendable + /// conformance generates a warning. + final class Info: @unchecked Sendable { // For root node. struct Root: Sendable { private var arena: RetainedSyntaxArena @@ -46,7 +50,11 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable { /// - Important: Must only be set to `nil` when `Syntax.Info` is used in a memory recycling pool /// (eg. in `SyntaxVisitor`). In that case the `Syntax.Info` is considered garbage memory that can be re-used /// later. `info` needs to be set to a real value when `Syntax.Info` is recycled from the memory recycling pool. + #if compiler(>=6.0) + nonisolated(unsafe) var info: InfoImpl! + #else var info: InfoImpl! + #endif } /// Reference to the node's parent or, if this node is the root of a tree, a reference to the `SyntaxArena` to keep diff --git a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift index a738f6b9979..b328be7cf7d 100644 --- a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift +++ b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift @@ -351,45 +351,45 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "label" case \BreakStmtSyntax.unexpectedAfterLabel: return "unexpectedAfterLabel" - case \CanImportExprSyntax.unexpectedBeforeCanImportKeyword: + case \_CanImportExprSyntax.unexpectedBeforeCanImportKeyword: return "unexpectedBeforeCanImportKeyword" - case \CanImportExprSyntax.canImportKeyword: + case \_CanImportExprSyntax.canImportKeyword: return "canImportKeyword" - case \CanImportExprSyntax.unexpectedBetweenCanImportKeywordAndLeftParen: + case \_CanImportExprSyntax.unexpectedBetweenCanImportKeywordAndLeftParen: return "unexpectedBetweenCanImportKeywordAndLeftParen" - case \CanImportExprSyntax.leftParen: + case \_CanImportExprSyntax.leftParen: return "leftParen" - case \CanImportExprSyntax.unexpectedBetweenLeftParenAndImportPath: + case \_CanImportExprSyntax.unexpectedBetweenLeftParenAndImportPath: return "unexpectedBetweenLeftParenAndImportPath" - case \CanImportExprSyntax.importPath: + case \_CanImportExprSyntax.importPath: return "importPath" - case \CanImportExprSyntax.unexpectedBetweenImportPathAndVersionInfo: + case \_CanImportExprSyntax.unexpectedBetweenImportPathAndVersionInfo: return "unexpectedBetweenImportPathAndVersionInfo" - case \CanImportExprSyntax.versionInfo: + case \_CanImportExprSyntax.versionInfo: return "versionInfo" - case \CanImportExprSyntax.unexpectedBetweenVersionInfoAndRightParen: + case \_CanImportExprSyntax.unexpectedBetweenVersionInfoAndRightParen: return "unexpectedBetweenVersionInfoAndRightParen" - case \CanImportExprSyntax.rightParen: + case \_CanImportExprSyntax.rightParen: return "rightParen" - case \CanImportExprSyntax.unexpectedAfterRightParen: + case \_CanImportExprSyntax.unexpectedAfterRightParen: return "unexpectedAfterRightParen" - case \CanImportVersionInfoSyntax.unexpectedBeforeComma: + case \_CanImportVersionInfoSyntax.unexpectedBeforeComma: return "unexpectedBeforeComma" - case \CanImportVersionInfoSyntax.comma: + case \_CanImportVersionInfoSyntax.comma: return "comma" - case \CanImportVersionInfoSyntax.unexpectedBetweenCommaAndLabel: + case \_CanImportVersionInfoSyntax.unexpectedBetweenCommaAndLabel: return "unexpectedBetweenCommaAndLabel" - case \CanImportVersionInfoSyntax.label: + case \_CanImportVersionInfoSyntax.label: return "label" - case \CanImportVersionInfoSyntax.unexpectedBetweenLabelAndColon: + case \_CanImportVersionInfoSyntax.unexpectedBetweenLabelAndColon: return "unexpectedBetweenLabelAndColon" - case \CanImportVersionInfoSyntax.colon: + case \_CanImportVersionInfoSyntax.colon: return "colon" - case \CanImportVersionInfoSyntax.unexpectedBetweenColonAndVersion: + case \_CanImportVersionInfoSyntax.unexpectedBetweenColonAndVersion: return "unexpectedBetweenColonAndVersion" - case \CanImportVersionInfoSyntax.version: + case \_CanImportVersionInfoSyntax.version: return "version" - case \CanImportVersionInfoSyntax.unexpectedAfterVersion: + case \_CanImportVersionInfoSyntax.unexpectedAfterVersion: return "unexpectedAfterVersion" case \CatchClauseSyntax.unexpectedBeforeCatchKeyword: return "unexpectedBeforeCatchKeyword" @@ -2009,30 +2009,28 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "trailingComma" case \LifetimeSpecifierArgumentSyntax.unexpectedAfterTrailingComma: return "unexpectedAfterTrailingComma" - case \LifetimeSpecifierArgumentsSyntax.unexpectedBeforeLeftParen: - return "unexpectedBeforeLeftParen" - case \LifetimeSpecifierArgumentsSyntax.leftParen: + case \LifetimeTypeSpecifierSyntax.unexpectedBeforeDependsOnKeyword: + return "unexpectedBeforeDependsOnKeyword" + case \LifetimeTypeSpecifierSyntax.dependsOnKeyword: + return "dependsOnKeyword" + case \LifetimeTypeSpecifierSyntax.unexpectedBetweenDependsOnKeywordAndLeftParen: + return "unexpectedBetweenDependsOnKeywordAndLeftParen" + case \LifetimeTypeSpecifierSyntax.leftParen: return "leftParen" - case \LifetimeSpecifierArgumentsSyntax.unexpectedBetweenLeftParenAndArguments: - return "unexpectedBetweenLeftParenAndArguments" - case \LifetimeSpecifierArgumentsSyntax.arguments: + case \LifetimeTypeSpecifierSyntax.unexpectedBetweenLeftParenAndScopedKeyword: + return "unexpectedBetweenLeftParenAndScopedKeyword" + case \LifetimeTypeSpecifierSyntax.scopedKeyword: + return "scopedKeyword" + case \LifetimeTypeSpecifierSyntax.unexpectedBetweenScopedKeywordAndArguments: + return "unexpectedBetweenScopedKeywordAndArguments" + case \LifetimeTypeSpecifierSyntax.arguments: return "arguments" - case \LifetimeSpecifierArgumentsSyntax.unexpectedBetweenArgumentsAndRightParen: + case \LifetimeTypeSpecifierSyntax.unexpectedBetweenArgumentsAndRightParen: return "unexpectedBetweenArgumentsAndRightParen" - case \LifetimeSpecifierArgumentsSyntax.rightParen: + case \LifetimeTypeSpecifierSyntax.rightParen: return "rightParen" - case \LifetimeSpecifierArgumentsSyntax.unexpectedAfterRightParen: + case \LifetimeTypeSpecifierSyntax.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: diff --git a/Sources/SwiftSyntax/generated/Keyword.swift b/Sources/SwiftSyntax/generated/Keyword.swift index c331f2f5716..29a0460c2e7 100644 --- a/Sources/SwiftSyntax/generated/Keyword.swift +++ b/Sources/SwiftSyntax/generated/Keyword.swift @@ -20,19 +20,19 @@ public enum Keyword: UInt8, Hashable, Sendable { case _alignment case _backDeploy case _borrow + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _borrowing case _BridgeObject case _cdecl case _Class case _compilerInitialized case _const + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) - case _consume - @_spi(ExperimentalLanguageFeatures) + #endif case _consuming - @_spi(ExperimentalLanguageFeatures) - case _copy case _documentation case _dynamicReplacement case _effects @@ -43,9 +43,9 @@ public enum Keyword: UInt8, Hashable, Sendable { case _local case _modify case _move + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) - case _mutate - @_spi(ExperimentalLanguageFeatures) + #endif case _mutating case _NativeClass case _NativeRefCountedObject @@ -110,6 +110,10 @@ 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 @@ -191,9 +195,13 @@ public enum Keyword: UInt8, Hashable, Sendable { case renamed case `repeat` case required + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _resultDependsOn + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case _resultDependsOnSelf case `rethrows` case retroactive @@ -201,6 +209,10 @@ public enum Keyword: UInt8, Hashable, Sendable { case reverse case right case safe + #if compiler(>=5.8) + @_spi(ExperimentalLanguageFeatures) + #endif + case scoped case `self` case `Self` case Sendable @@ -219,7 +231,9 @@ public enum Keyword: UInt8, Hashable, Sendable { case then case `throw` case `throws` + #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) + #endif case transferring case transpose case `true` @@ -343,8 +357,6 @@ public enum Keyword: UInt8, Hashable, Sendable { } case 5: switch text { - case "_copy": - self = ._copy case "_move": self = ._move case "_read": @@ -428,6 +440,8 @@ public enum Keyword: UInt8, Hashable, Sendable { self = .repeat case "return": self = .return + case "scoped": + self = .scoped case "static": self = .static case "struct": @@ -455,8 +469,6 @@ public enum Keyword: UInt8, Hashable, Sendable { self = ._linear case "_modify": self = ._modify - case "_mutate": - self = ._mutate case "consume": self = .consume case "default": @@ -494,8 +506,6 @@ public enum Keyword: UInt8, Hashable, Sendable { switch text { case "__shared": self = .__shared - case "_consume": - self = ._consume case "_effects": self = ._effects case "_forward": @@ -563,6 +573,8 @@ public enum Keyword: UInt8, Hashable, Sendable { self = .canImport case "consuming": self = .consuming + case "dependsOn": + self = .dependsOn case "extension": self = .extension case "lowerThan": @@ -826,9 +838,7 @@ public enum Keyword: UInt8, Hashable, Sendable { "_Class", "_compilerInitialized", "_const", - "_consume", "_consuming", - "_copy", "_documentation", "_dynamicReplacement", "_effects", @@ -839,7 +849,6 @@ public enum Keyword: UInt8, Hashable, Sendable { "_local", "_modify", "_move", - "_mutate", "_mutating", "_NativeClass", "_NativeRefCountedObject", @@ -904,6 +913,7 @@ public enum Keyword: UInt8, Hashable, Sendable { "default", "defer", "deinit", + "dependsOn", "deprecated", "derivative", "didSet", @@ -993,6 +1003,7 @@ public enum Keyword: UInt8, Hashable, Sendable { "reverse", "right", "safe", + "scoped", "self", "Self", "Sendable", diff --git a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift index 8046f48d3a2..c798061a9e6 100644 --- a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift @@ -1025,7 +1025,7 @@ extension BooleanLiteralExprSyntax { } } -extension CanImportVersionInfoSyntax { +extension _CanImportVersionInfoSyntax { @available(*, deprecated, renamed: "unexpectedBetweenColonAndVersion") public var unexpectedBetweenColonAndVersionTuple: UnexpectedNodesSyntax? { get { @@ -1056,7 +1056,7 @@ extension CanImportVersionInfoSyntax { } } - @available(*, deprecated, renamed: "CanImportVersionInfoSyntax(leadingTrivia:_:comma:_:label:_:colon:_:version:_:trailingTrivia:)") + @available(*, deprecated, renamed: "_CanImportVersionInfoSyntax(leadingTrivia:_:comma:_:label:_:colon:_:version:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, diff --git a/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift index 9fc7d663ee4..5af3045b1ed 100644 --- a/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift @@ -45,6 +45,12 @@ public typealias AvailabilityVersionRestrictionListEntrySyntax = PlatformVersion @available(*, deprecated, renamed: "BackDeployedAttributeArgumentsSyntax") public typealias BackDeployedAttributeSpecListSyntax = BackDeployedAttributeArgumentsSyntax +@available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") +public typealias CanImportExprSyntax = _CanImportExprSyntax + +@available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") +public typealias CanImportVersionInfoSyntax = _CanImportVersionInfoSyntax + @available(*, deprecated, renamed: "SwitchCaseItemSyntax") public typealias CaseItemSyntax = SwitchCaseItemSyntax @@ -214,270 +220,347 @@ public typealias YieldExprListElementSyntax = YieldedExpressionSyntax public typealias YieldListSyntax = YieldedExpressionsClauseSyntax public extension SyntaxKind { + @available(*, deprecated, renamed: "ImportPathComponentListSyntax") static var accessPath: Self { return .importPathComponentList } + @available(*, deprecated, renamed: "ImportPathComponentSyntax") static var accessPathComponent: Self { return .importPathComponent } + @available(*, deprecated, renamed: "AccessorDeclListSyntax") static var accessorList: Self { return .accessorDeclList } + @available(*, deprecated, renamed: "AccessorParametersSyntax") static var accessorParameter: Self { return .accessorParameters } + @available(*, deprecated, renamed: "AssociatedTypeDeclSyntax") static var associatedtypeDecl: Self { return .associatedTypeDecl } + @available(*, deprecated, renamed: "SpecializeAvailabilityArgumentSyntax") static var availabilityEntry: Self { return .specializeAvailabilityArgument } + @available(*, deprecated, renamed: "AvailabilityArgumentListSyntax") static var availabilitySpecList: Self { return .availabilityArgumentList } + @available(*, deprecated, renamed: "PlatformVersionSyntax") static var availabilityVersionRestriction: Self { return .platformVersion } + @available(*, deprecated, renamed: "PlatformVersionItemListSyntax") static var availabilityVersionRestrictionList: Self { return .platformVersionItemList } + @available(*, deprecated, renamed: "PlatformVersionItemSyntax") static var availabilityVersionRestrictionListEntry: Self { return .platformVersionItem } + @available(*, deprecated, renamed: "BackDeployedAttributeArgumentsSyntax") static var backDeployedAttributeSpecList: Self { return .backDeployedAttributeArguments } + @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") + static var canImportExpr: Self { + return ._canImportExpr + } + + @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") + static var canImportVersionInfo: Self { + return ._canImportVersionInfo + } + + @available(*, deprecated, renamed: "SwitchCaseItemSyntax") static var caseItem: Self { return .switchCaseItem } + @available(*, deprecated, renamed: "SwitchCaseItemListSyntax") static var caseItemList: Self { return .switchCaseItemList } + @available(*, deprecated, renamed: "ClosureCaptureSyntax") static var closureCaptureItem: Self { return .closureCapture } + @available(*, deprecated, renamed: "ClosureCaptureListSyntax") static var closureCaptureItemList: Self { return .closureCaptureList } + @available(*, deprecated, renamed: "ClosureCaptureSpecifierSyntax") static var closureCaptureItemSpecifier: Self { return .closureCaptureSpecifier } + @available(*, deprecated, renamed: "ClosureCaptureClauseSyntax") static var closureCaptureSignature: Self { return .closureCaptureClause } + @available(*, deprecated, renamed: "ClosureShorthandParameterSyntax") static var closureParam: Self { return .closureShorthandParameter } + @available(*, deprecated, renamed: "ClosureShorthandParameterListSyntax") static var closureParamList: Self { return .closureShorthandParameterList } + @available(*, deprecated, renamed: "SomeOrAnyTypeSyntax") static var constrainedSugarType: Self { return .someOrAnyType } + @available(*, deprecated, renamed: "DeinitializerEffectSpecifiersSyntax") static var deinitEffectSpecifiers: Self { return .deinitializerEffectSpecifiers } + @available(*, deprecated, renamed: "DerivativeAttributeArgumentsSyntax") static var derivativeRegistrationAttributeArguments: Self { return .derivativeAttributeArguments } + @available(*, deprecated, renamed: "DesignatedTypeSyntax") static var designatedTypeElement: Self { return .designatedType } + @available(*, deprecated, renamed: "DifferentiabilityArgumentSyntax") static var differentiabilityParam: Self { return .differentiabilityArgument } + @available(*, deprecated, renamed: "DifferentiabilityArgumentListSyntax") static var differentiabilityParamList: Self { return .differentiabilityArgumentList } + @available(*, deprecated, renamed: "DifferentiabilityArgumentsSyntax") static var differentiabilityParams: Self { return .differentiabilityArguments } + @available(*, deprecated, renamed: "DifferentiabilityWithRespectToArgumentSyntax") static var differentiabilityParamsClause: Self { return .differentiabilityWithRespectToArgument } + @available(*, deprecated, renamed: "DocumentationAttributeArgumentListSyntax") static var documentationAttributeArguments: Self { return .documentationAttributeArgumentList } + @available(*, deprecated, renamed: "DynamicReplacementAttributeArgumentsSyntax") static var dynamicReplacementArguments: Self { return .dynamicReplacementAttributeArguments } + @available(*, deprecated, renamed: "EffectsAttributeArgumentListSyntax") static var effectsArguments: Self { return .effectsAttributeArgumentList } + @available(*, deprecated, renamed: "EnumCaseParameterClauseSyntax") static var enumCaseAssociatedValue: Self { return .enumCaseParameterClause } + @available(*, deprecated, renamed: "FallThroughStmtSyntax") static var fallthroughStmt: Self { return .fallThroughStmt } + @available(*, deprecated, renamed: "ForStmtSyntax") static var forInStmt: Self { return .forStmt } + @available(*, deprecated, renamed: "ForceUnwrapExprSyntax") static var forcedValueExpr: Self { return .forceUnwrapExpr } + @available(*, deprecated, renamed: "DeclReferenceExprSyntax") static var identifierExpr: Self { return .declReferenceExpr } + @available(*, deprecated, renamed: "LabeledSpecializeArgumentSyntax") static var labeledSpecializeEntry: Self { return .labeledSpecializeArgument } + @available(*, deprecated, renamed: "MemberBlockSyntax") static var memberDeclBlock: Self { return .memberBlock } + @available(*, deprecated, renamed: "MemberBlockItemListSyntax") static var memberDeclList: Self { return .memberBlockItemList } + @available(*, deprecated, renamed: "MemberBlockItemSyntax") static var memberDeclListItem: Self { return .memberBlockItem } + @available(*, deprecated, renamed: "MemberTypeSyntax") static var memberTypeIdentifier: Self { return .memberType } + @available(*, deprecated, renamed: "DeclModifierListSyntax") static var modifierList: Self { return .declModifierList } + @available(*, deprecated, renamed: "ConsumeExprSyntax") static var moveExpr: Self { return .consumeExpr } + @available(*, deprecated, renamed: "ObjCSelectorPieceListSyntax") static var objCSelector: Self { return .objCSelectorPieceList } + @available(*, deprecated, renamed: "OriginallyDefinedInAttributeArgumentsSyntax") static var originallyDefinedInArguments: Self { return .originallyDefinedInAttributeArguments } + @available(*, deprecated, renamed: "PackElementTypeSyntax") static var packReferenceType: Self { return .packElementType } + @available(*, deprecated, renamed: "FunctionParameterClauseSyntax") static var parameterClause: Self { return .functionParameterClause } + @available(*, deprecated, renamed: "PostfixOperatorExprSyntax") static var postfixUnaryExpr: Self { return .postfixOperatorExpr } + @available(*, deprecated, renamed: "PoundSourceLocationArgumentsSyntax") static var poundSourceLocationArgs: Self { return .poundSourceLocationArguments } + @available(*, deprecated, renamed: "PrecedenceGroupNameSyntax") static var precedenceGroupNameElement: Self { return .precedenceGroupName } + @available(*, deprecated, renamed: "RepeatStmtSyntax") static var repeatWhileStmt: Self { return .repeatStmt } + @available(*, deprecated, renamed: "IdentifierTypeSyntax") static var simpleTypeIdentifier: Self { return .identifierType } + @available(*, deprecated, renamed: "SpecializeAttributeArgumentListSyntax") static var specializeAttributeSpecList: Self { return .specializeAttributeArgumentList } + @available(*, deprecated, renamed: "GenericSpecializationExprSyntax") static var specializeExpr: Self { return .genericSpecializationExpr } + @available(*, deprecated, renamed: "StringLiteralSegmentListSyntax") static var stringLiteralSegments: Self { return .stringLiteralSegmentList } + @available(*, deprecated, renamed: "SubscriptCallExprSyntax") static var subscriptExpr: Self { return .subscriptCallExpr } + @available(*, deprecated, renamed: "SuperExprSyntax") static var superRefExpr: Self { return .superExpr } + @available(*, deprecated, renamed: "SpecializeTargetFunctionArgumentSyntax") static var targetFunctionEntry: Self { return .specializeTargetFunctionArgument } + @available(*, deprecated, renamed: "LabeledExprSyntax") static var tupleExprElement: Self { return .labeledExpr } + @available(*, deprecated, renamed: "LabeledExprListSyntax") static var tupleExprElementList: Self { return .labeledExprList } + @available(*, deprecated, renamed: "InheritanceClauseSyntax") static var typeInheritanceClause: Self { return .inheritanceClause } + @available(*, deprecated, renamed: "SimpleTypeSpecifierSyntax") static var typeSpecifier: Self { return .simpleTypeSpecifier } + @available(*, deprecated, renamed: "TypeAliasDeclSyntax") static var typealiasDecl: Self { return .typeAliasDecl } + @available(*, deprecated, renamed: "UnavailableFromAsyncAttributeArgumentsSyntax") static var unavailableFromAsyncArguments: Self { return .unavailableFromAsyncAttributeArguments } + @available(*, deprecated, renamed: "PatternExprSyntax") static var unresolvedPatternExpr: Self { return .patternExpr } + @available(*, deprecated, renamed: "YieldedExpressionListSyntax") static var yieldExprList: Self { return .yieldedExpressionList } + @available(*, deprecated, renamed: "YieldedExpressionSyntax") static var yieldExprListElement: Self { return .yieldedExpression } + @available(*, deprecated, renamed: "YieldedExpressionsClauseSyntax") static var yieldList: Self { return .yieldedExpressionsClause } diff --git a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift index 17eb0b51b3e..694fee15c35 100644 --- a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift @@ -272,23 +272,19 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - override open func visit(_ node: CanImportExprSyntax) -> SyntaxVisitorContinueKind { + override open func visit(_ node: _CanImportExprSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - override open func visitPost(_ node: CanImportExprSyntax) { + override open func visitPost(_ node: _CanImportExprSyntax) { visitAnyPost(node._syntaxNode) } - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - override open func visit(_ node: CanImportVersionInfoSyntax) -> SyntaxVisitorContinueKind { + override open func visit(_ node: _CanImportVersionInfoSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - override open func visitPost(_ node: CanImportVersionInfoSyntax) { + override open func visitPost(_ node: _CanImportVersionInfoSyntax) { visitAnyPost(node._syntaxNode) } @@ -1374,20 +1370,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - override open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> SyntaxVisitorContinueKind { - return visitAny(node._syntaxNode) - } - - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - override open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) { - visitAnyPost(node._syntaxNode) - } - #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index 7ff75ce92c4..2c85459a2f5 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -464,8 +464,6 @@ public extension Syntax { /// - ``BinaryOperatorExprSyntax`` /// - ``BooleanLiteralExprSyntax`` /// - ``BorrowExprSyntax`` -/// - ``CanImportExprSyntax`` -/// - ``CanImportVersionInfoSyntax`` /// - ``ClosureExprSyntax`` /// - ``ConsumeExprSyntax`` /// - ``CopyExprSyntax`` @@ -544,7 +542,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable { public init?(_ node: some SyntaxProtocol) { switch node.raw.kind { - case .arrayExpr, .arrowExpr, .asExpr, .assignmentExpr, .awaitExpr, .binaryOperatorExpr, .booleanLiteralExpr, .borrowExpr, .canImportExpr, .canImportVersionInfo, .closureExpr, .consumeExpr, .copyExpr, .declReferenceExpr, .dictionaryExpr, .discardAssignmentExpr, .doExpr, .editorPlaceholderExpr, .floatLiteralExpr, .forceUnwrapExpr, .functionCallExpr, .genericSpecializationExpr, .ifExpr, .inOutExpr, .infixOperatorExpr, .integerLiteralExpr, .isExpr, .keyPathExpr, .macroExpansionExpr, .memberAccessExpr, .missingExpr, .nilLiteralExpr, .optionalChainingExpr, .packElementExpr, .packExpansionExpr, .patternExpr, .postfixIfConfigExpr, .postfixOperatorExpr, .prefixOperatorExpr, .regexLiteralExpr, .sequenceExpr, .simpleStringLiteralExpr, .stringLiteralExpr, .subscriptCallExpr, .superExpr, .switchExpr, .ternaryExpr, .tryExpr, .tupleExpr, .typeExpr, .unresolvedAsExpr, .unresolvedIsExpr, .unresolvedTernaryExpr: + case .arrayExpr, .arrowExpr, .asExpr, .assignmentExpr, .awaitExpr, .binaryOperatorExpr, .booleanLiteralExpr, .borrowExpr, ._canImportExpr, ._canImportVersionInfo, .closureExpr, .consumeExpr, .copyExpr, .declReferenceExpr, .dictionaryExpr, .discardAssignmentExpr, .doExpr, .editorPlaceholderExpr, .floatLiteralExpr, .forceUnwrapExpr, .functionCallExpr, .genericSpecializationExpr, .ifExpr, .inOutExpr, .infixOperatorExpr, .integerLiteralExpr, .isExpr, .keyPathExpr, .macroExpansionExpr, .memberAccessExpr, .missingExpr, .nilLiteralExpr, .optionalChainingExpr, .packElementExpr, .packExpansionExpr, .patternExpr, .postfixIfConfigExpr, .postfixOperatorExpr, .prefixOperatorExpr, .regexLiteralExpr, .sequenceExpr, .simpleStringLiteralExpr, .stringLiteralExpr, .subscriptCallExpr, .superExpr, .switchExpr, .ternaryExpr, .tryExpr, .tupleExpr, .typeExpr, .unresolvedAsExpr, .unresolvedIsExpr, .unresolvedTernaryExpr: self._syntaxNode = node._syntaxNode default: return nil @@ -577,8 +575,8 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable { .node(BinaryOperatorExprSyntax.self), .node(BooleanLiteralExprSyntax.self), .node(BorrowExprSyntax.self), - .node(CanImportExprSyntax.self), - .node(CanImportVersionInfoSyntax.self), + .node(_CanImportExprSyntax.self), + .node(_CanImportVersionInfoSyntax.self), .node(ClosureExprSyntax.self), .node(ConsumeExprSyntax.self), .node(CopyExprSyntax.self), @@ -1546,8 +1544,8 @@ extension Syntax { .node(BooleanLiteralExprSyntax.self), .node(BorrowExprSyntax.self), .node(BreakStmtSyntax.self), - .node(CanImportExprSyntax.self), - .node(CanImportVersionInfoSyntax.self), + .node(_CanImportExprSyntax.self), + .node(_CanImportVersionInfoSyntax.self), .node(CatchClauseListSyntax.self), .node(CatchClauseSyntax.self), .node(CatchItemListSyntax.self), @@ -1681,7 +1679,6 @@ extension Syntax { .node(LayoutRequirementSyntax.self), .node(LifetimeSpecifierArgumentListSyntax.self), .node(LifetimeSpecifierArgumentSyntax.self), - .node(LifetimeSpecifierArgumentsSyntax.self), .node(LifetimeTypeSpecifierSyntax.self), .node(MacroDeclSyntax.self), .node(MacroExpansionDeclSyntax.self), diff --git a/Sources/SwiftSyntax/generated/SyntaxEnum.swift b/Sources/SwiftSyntax/generated/SyntaxEnum.swift index cf24a56b678..5b339fbac50 100644 --- a/Sources/SwiftSyntax/generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/generated/SyntaxEnum.swift @@ -42,10 +42,8 @@ public enum SyntaxEnum: Sendable { case booleanLiteralExpr(BooleanLiteralExprSyntax) case borrowExpr(BorrowExprSyntax) case breakStmt(BreakStmtSyntax) - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - case canImportExpr(CanImportExprSyntax) - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - case canImportVersionInfo(CanImportVersionInfoSyntax) + case _canImportExpr(_CanImportExprSyntax) + case _canImportVersionInfo(_CanImportVersionInfoSyntax) case catchClauseList(CatchClauseListSyntax) case catchClause(CatchClauseSyntax) case catchItemList(CatchItemListSyntax) @@ -191,10 +189,6 @@ public enum SyntaxEnum: Sendable { #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif - case lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax) - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif case lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax) case macroDecl(MacroDeclSyntax) case macroExpansionDecl(MacroExpansionDeclSyntax) @@ -381,10 +375,10 @@ public extension Syntax { return .borrowExpr(BorrowExprSyntax(self)!) case .breakStmt: return .breakStmt(BreakStmtSyntax(self)!) - case .canImportExpr: - return .canImportExpr(CanImportExprSyntax(self)!) - case .canImportVersionInfo: - return .canImportVersionInfo(CanImportVersionInfoSyntax(self)!) + case ._canImportExpr: + return ._canImportExpr(_CanImportExprSyntax(self)!) + case ._canImportVersionInfo: + return ._canImportVersionInfo(_CanImportVersionInfoSyntax(self)!) case .catchClauseList: return .catchClauseList(CatchClauseListSyntax(self)!) case .catchClause: @@ -651,8 +645,6 @@ public extension Syntax { return .lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax(self)!) case .lifetimeSpecifierArgument: return .lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax(self)!) - case .lifetimeSpecifierArguments: - return .lifetimeSpecifierArguments(LifetimeSpecifierArgumentsSyntax(self)!) case .lifetimeTypeSpecifier: return .lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax(self)!) case .macroDecl: @@ -995,10 +987,8 @@ public enum ExprSyntaxEnum { case binaryOperatorExpr(BinaryOperatorExprSyntax) case booleanLiteralExpr(BooleanLiteralExprSyntax) case borrowExpr(BorrowExprSyntax) - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - case canImportExpr(CanImportExprSyntax) - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - case canImportVersionInfo(CanImportVersionInfoSyntax) + case _canImportExpr(_CanImportExprSyntax) + case _canImportVersionInfo(_CanImportVersionInfoSyntax) case closureExpr(ClosureExprSyntax) case consumeExpr(ConsumeExprSyntax) case copyExpr(CopyExprSyntax) @@ -1067,10 +1057,10 @@ public extension ExprSyntax { return .booleanLiteralExpr(BooleanLiteralExprSyntax(self)!) case .borrowExpr: return .borrowExpr(BorrowExprSyntax(self)!) - case .canImportExpr: - return .canImportExpr(CanImportExprSyntax(self)!) - case .canImportVersionInfo: - return .canImportVersionInfo(CanImportVersionInfoSyntax(self)!) + case ._canImportExpr: + return ._canImportExpr(_CanImportExprSyntax(self)!) + case ._canImportVersionInfo: + return ._canImportVersionInfo(_CanImportVersionInfoSyntax(self)!) case .closureExpr: return .closureExpr(ClosureExprSyntax(self)!) case .consumeExpr: diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index 3724843f407..b8e5d120a01 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -42,10 +42,8 @@ public enum SyntaxKind: Sendable { case booleanLiteralExpr case borrowExpr case breakStmt - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - case canImportExpr - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - case canImportVersionInfo + case _canImportExpr + case _canImportVersionInfo case catchClauseList case catchClause case catchItemList @@ -191,10 +189,6 @@ public enum SyntaxKind: Sendable { #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif - case lifetimeSpecifierArguments - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif case lifetimeTypeSpecifier case macroDecl case macroExpansionDecl @@ -506,10 +500,10 @@ public enum SyntaxKind: Sendable { return BorrowExprSyntax.self case .breakStmt: return BreakStmtSyntax.self - case .canImportExpr: - return CanImportExprSyntax.self - case .canImportVersionInfo: - return CanImportVersionInfoSyntax.self + case ._canImportExpr: + return _CanImportExprSyntax.self + case ._canImportVersionInfo: + return _CanImportVersionInfoSyntax.self case .catchClauseList: return CatchClauseListSyntax.self case .catchClause: @@ -776,8 +770,6 @@ public enum SyntaxKind: Sendable { return LifetimeSpecifierArgumentListSyntax.self case .lifetimeSpecifierArgument: return LifetimeSpecifierArgumentSyntax.self - case .lifetimeSpecifierArguments: - return LifetimeSpecifierArgumentsSyntax.self case .lifetimeTypeSpecifier: return LifetimeTypeSpecifierSyntax.self case .macroDecl: diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index e3b3b26d480..00adb9e48be 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -24,8 +24,22 @@ open class SyntaxRewriter { public let viewMode: SyntaxTreeViewMode + /// The arena in which the parents of rewritten nodes should be allocated. + /// + /// The `SyntaxRewriter` subclass is responsible for generating the rewritten nodes. To incorporate them into the + /// tree, all of the rewritten node's parents also need to be re-created. This is the arena in which those + /// intermediate nodes should be allocated. + private let arena: SyntaxArena? + public init(viewMode: SyntaxTreeViewMode = .sourceAccurate) { self.viewMode = viewMode + self.arena = nil + } + + @_spi(RawSyntax) + public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, arena: SyntaxArena? = nil) { + self.viewMode = viewMode + self.arena = arena } /// Rewrite `node`, keeping its parent unless `detach` is `true`. @@ -269,19 +283,17 @@ open class SyntaxRewriter { return StmtSyntax(visitChildren(node)) } - /// Visit a ``CanImportExprSyntax``. + /// Visit a `_CanImportExprSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - open func visit(_ node: CanImportExprSyntax) -> ExprSyntax { + open func visit(_ node: _CanImportExprSyntax) -> ExprSyntax { return ExprSyntax(visitChildren(node)) } - /// Visit a ``CanImportVersionInfoSyntax``. + /// Visit a `_CanImportVersionInfoSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - open func visit(_ node: CanImportVersionInfoSyntax) -> ExprSyntax { + open func visit(_ node: _CanImportVersionInfoSyntax) -> ExprSyntax { return ExprSyntax(visitChildren(node)) } @@ -1225,16 +1237,6 @@ open class SyntaxRewriter { return visitChildren(node) } - /// Visit a `LifetimeSpecifierArgumentsSyntax`. - /// - Parameter node: the node that is being visited - /// - Returns: the rewritten node - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> LifetimeSpecifierArgumentsSyntax { - return visitChildren(node) - } - /// Visit a `LifetimeTypeSpecifierSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -2280,13 +2282,13 @@ open class SyntaxRewriter { return { self.visitImpl($0, BreakStmtSyntax.self, self.visit) } - case .canImportExpr: + case ._canImportExpr: return { - self.visitImpl($0, CanImportExprSyntax.self, self.visit) + self.visitImpl($0, _CanImportExprSyntax.self, self.visit) } - case .canImportVersionInfo: + case ._canImportVersionInfo: return { - self.visitImpl($0, CanImportVersionInfoSyntax.self, self.visit) + self.visitImpl($0, _CanImportVersionInfoSyntax.self, self.visit) } case .catchClauseList: return { @@ -2820,10 +2822,6 @@ open class SyntaxRewriter { return { self.visitImpl($0, LifetimeSpecifierArgumentSyntax.self, self.visit) } - case .lifetimeSpecifierArguments: - return { - self.visitImpl($0, LifetimeSpecifierArgumentsSyntax.self, self.visit) - } case .lifetimeTypeSpecifier: return { self.visitImpl($0, LifetimeTypeSpecifierSyntax.self, self.visit) @@ -3372,10 +3370,10 @@ open class SyntaxRewriter { return visitImpl(node, BorrowExprSyntax.self, visit) case .breakStmt: return visitImpl(node, BreakStmtSyntax.self, visit) - case .canImportExpr: - return visitImpl(node, CanImportExprSyntax.self, visit) - case .canImportVersionInfo: - return visitImpl(node, CanImportVersionInfoSyntax.self, visit) + case ._canImportExpr: + return visitImpl(node, _CanImportExprSyntax.self, visit) + case ._canImportVersionInfo: + return visitImpl(node, _CanImportVersionInfoSyntax.self, visit) case .catchClauseList: return visitImpl(node, CatchClauseListSyntax.self, visit) case .catchClause: @@ -3642,8 +3640,6 @@ open class SyntaxRewriter { return visitImpl(node, LifetimeSpecifierArgumentListSyntax.self, visit) case .lifetimeSpecifierArgument: return visitImpl(node, LifetimeSpecifierArgumentSyntax.self, visit) - case .lifetimeSpecifierArguments: - return visitImpl(node, LifetimeSpecifierArgumentsSyntax.self, visit) case .lifetimeTypeSpecifier: return visitImpl(node, LifetimeTypeSpecifierSyntax.self, visit) case .macroDecl: @@ -3966,7 +3962,7 @@ open class SyntaxRewriter { // Sanity check, ensure the new children are the same length. precondition(newLayout.count == node.raw.layoutView!.children.count) - let arena = SyntaxArena() + let arena = self.arena ?? SyntaxArena() let newRaw = node.raw.layoutView!.replacingLayout(with: Array(newLayout), arena: arena) // 'withExtendedLifetime' to keep 'SyntaxArena's of them alive until here. return withExtendedLifetime(rewrittens) { diff --git a/Sources/SwiftSyntax/generated/SyntaxTraits.swift b/Sources/SwiftSyntax/generated/SyntaxTraits.swift index 83c8529f9a2..1034e136ffc 100644 --- a/Sources/SwiftSyntax/generated/SyntaxTraits.swift +++ b/Sources/SwiftSyntax/generated/SyntaxTraits.swift @@ -779,8 +779,6 @@ 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 80a4de49214..f0fe0479292 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -377,32 +377,28 @@ open class SyntaxVisitor { open func visitPost(_ node: BreakStmtSyntax) { } - /// Visiting ``CanImportExprSyntax`` specifically. + /// Visiting `_CanImportExprSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - open func visit(_ node: CanImportExprSyntax) -> SyntaxVisitorContinueKind { + open func visit(_ node: _CanImportExprSyntax) -> SyntaxVisitorContinueKind { return .visitChildren } - /// The function called after visiting ``CanImportExprSyntax`` and its descendants. + /// The function called after visiting `_CanImportExprSyntax` and its descendants. /// - node: the node we just finished visiting. - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - open func visitPost(_ node: CanImportExprSyntax) { + open func visitPost(_ node: _CanImportExprSyntax) { } - /// Visiting ``CanImportVersionInfoSyntax`` specifically. + /// Visiting `_CanImportVersionInfoSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - open func visit(_ node: CanImportVersionInfoSyntax) -> SyntaxVisitorContinueKind { + open func visit(_ node: _CanImportVersionInfoSyntax) -> SyntaxVisitorContinueKind { return .visitChildren } - /// The function called after visiting ``CanImportVersionInfoSyntax`` and its descendants. + /// The function called after visiting `_CanImportVersionInfoSyntax` and its descendants. /// - node: the node we just finished visiting. - @available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") - open func visitPost(_ node: CanImportVersionInfoSyntax) { + open func visitPost(_ node: _CanImportVersionInfoSyntax) { } /// Visiting ``CatchClauseListSyntax`` specifically. @@ -2019,24 +2015,6 @@ open class SyntaxVisitor { open func visitPost(_ node: LifetimeSpecifierArgumentSyntax) { } - /// Visiting `LifetimeSpecifierArgumentsSyntax` specifically. - /// - Parameter node: the node we are visiting. - /// - Returns: how should we continue visiting. - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - open func visit(_ node: LifetimeSpecifierArgumentsSyntax) -> SyntaxVisitorContinueKind { - return .visitChildren - } - - /// The function called after visiting `LifetimeSpecifierArgumentsSyntax` and its descendants. - /// - node: the node we just finished visiting. - #if compiler(>=5.8) - @_spi(ExperimentalLanguageFeatures) - #endif - open func visitPost(_ node: LifetimeSpecifierArgumentsSyntax) { - } - /// Visiting `LifetimeTypeSpecifierSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -3680,13 +3658,13 @@ open class SyntaxVisitor { return { self.visitImpl(&$0, BreakStmtSyntax.self, self.visit, self.visitPost) } - case .canImportExpr: + case ._canImportExpr: return { - self.visitImpl(&$0, CanImportExprSyntax.self, self.visit, self.visitPost) + self.visitImpl(&$0, _CanImportExprSyntax.self, self.visit, self.visitPost) } - case .canImportVersionInfo: + case ._canImportVersionInfo: return { - self.visitImpl(&$0, CanImportVersionInfoSyntax.self, self.visit, self.visitPost) + self.visitImpl(&$0, _CanImportVersionInfoSyntax.self, self.visit, self.visitPost) } case .catchClauseList: return { @@ -4220,10 +4198,6 @@ open class SyntaxVisitor { return { self.visitImpl(&$0, LifetimeSpecifierArgumentSyntax.self, self.visit, self.visitPost) } - case .lifetimeSpecifierArguments: - return { - self.visitImpl(&$0, LifetimeSpecifierArgumentsSyntax.self, self.visit, self.visitPost) - } case .lifetimeTypeSpecifier: return { self.visitImpl(&$0, LifetimeTypeSpecifierSyntax.self, self.visit, self.visitPost) @@ -4776,10 +4750,10 @@ open class SyntaxVisitor { visitImpl(&node, BorrowExprSyntax.self, visit, visitPost) case .breakStmt: visitImpl(&node, BreakStmtSyntax.self, visit, visitPost) - case .canImportExpr: - visitImpl(&node, CanImportExprSyntax.self, visit, visitPost) - case .canImportVersionInfo: - visitImpl(&node, CanImportVersionInfoSyntax.self, visit, visitPost) + case ._canImportExpr: + visitImpl(&node, _CanImportExprSyntax.self, visit, visitPost) + case ._canImportVersionInfo: + visitImpl(&node, _CanImportVersionInfoSyntax.self, visit, visitPost) case .catchClauseList: visitImpl(&node, CatchClauseListSyntax.self, visit, visitPost) case .catchClause: @@ -5046,8 +5020,6 @@ open class SyntaxVisitor { visitImpl(&node, LifetimeSpecifierArgumentListSyntax.self, visit, visitPost) case .lifetimeSpecifierArgument: visitImpl(&node, LifetimeSpecifierArgumentSyntax.self, visit, visitPost) - case .lifetimeSpecifierArguments: - visitImpl(&node, LifetimeSpecifierArgumentsSyntax.self, visit, visitPost) case .lifetimeTypeSpecifier: visitImpl(&node, LifetimeTypeSpecifierSyntax.self, visit, visitPost) case .macroDecl: diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesC.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesC.swift index 0f4a38e0889..ba466a6adff 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesC.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesC.swift @@ -12,15 +12,15 @@ // //===----------------------------------------------------------------------===// -@available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") @_spi(RawSyntax) -public struct RawCanImportExprSyntax: RawExprSyntaxNodeProtocol { +@_spi(RawSyntax) +public struct Raw_CanImportExprSyntax: RawExprSyntaxNodeProtocol { @_spi(RawSyntax) public var layoutView: RawSyntaxLayoutView { return raw.layoutView! } public static func isKindOf(_ raw: RawSyntax) -> Bool { - return raw.kind == .canImportExpr + return raw.kind == ._canImportExpr } public var raw: RawSyntax @@ -49,14 +49,14 @@ public struct RawCanImportExprSyntax: RawExprSyntaxNodeProtocol { _ unexpectedBetweenLeftParenAndImportPath: RawUnexpectedNodesSyntax? = nil, importPath: RawTokenSyntax, _ unexpectedBetweenImportPathAndVersionInfo: RawUnexpectedNodesSyntax? = nil, - versionInfo: RawCanImportVersionInfoSyntax?, + versionInfo: Raw_CanImportVersionInfoSyntax?, _ unexpectedBetweenVersionInfoAndRightParen: RawUnexpectedNodesSyntax? = nil, rightParen: RawTokenSyntax, _ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil, arena: __shared SyntaxArena ) { let raw = RawSyntax.makeLayout( - kind: .canImportExpr, uninitializedCount: 11, arena: arena) { layout in + kind: ._canImportExpr, uninitializedCount: 11, arena: arena) { layout in layout.initialize(repeating: nil) layout[0] = unexpectedBeforeCanImportKeyword?.raw layout[1] = canImportKeyword.raw @@ -101,8 +101,8 @@ public struct RawCanImportExprSyntax: RawExprSyntaxNodeProtocol { layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var versionInfo: RawCanImportVersionInfoSyntax? { - layoutView.children[7].map(RawCanImportVersionInfoSyntax.init(raw:)) + public var versionInfo: Raw_CanImportVersionInfoSyntax? { + layoutView.children[7].map(Raw_CanImportVersionInfoSyntax.init(raw:)) } public var unexpectedBetweenVersionInfoAndRightParen: RawUnexpectedNodesSyntax? { @@ -118,15 +118,15 @@ public struct RawCanImportExprSyntax: RawExprSyntaxNodeProtocol { } } -@available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") @_spi(RawSyntax) -public struct RawCanImportVersionInfoSyntax: RawExprSyntaxNodeProtocol { +@_spi(RawSyntax) +public struct Raw_CanImportVersionInfoSyntax: RawExprSyntaxNodeProtocol { @_spi(RawSyntax) public var layoutView: RawSyntaxLayoutView { return raw.layoutView! } public static func isKindOf(_ raw: RawSyntax) -> Bool { - return raw.kind == .canImportVersionInfo + return raw.kind == ._canImportVersionInfo } public var raw: RawSyntax @@ -160,7 +160,7 @@ public struct RawCanImportVersionInfoSyntax: RawExprSyntaxNodeProtocol { arena: __shared SyntaxArena ) { let raw = RawSyntax.makeLayout( - kind: .canImportVersionInfo, uninitializedCount: 9, arena: arena) { layout in + kind: ._canImportVersionInfo, uninitializedCount: 9, arena: arena) { layout in layout.initialize(repeating: nil) layout[0] = unexpectedBeforeComma?.raw layout[1] = comma.raw diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesEF.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesEF.swift index 3b65d5be404..0ac329a0a14 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesEF.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesEF.swift @@ -988,7 +988,7 @@ public struct RawExprSyntax: RawExprSyntaxNodeProtocol { public static func isKindOf(_ raw: RawSyntax) -> Bool { switch raw.kind { - case .arrayExpr, .arrowExpr, .asExpr, .assignmentExpr, .awaitExpr, .binaryOperatorExpr, .booleanLiteralExpr, .borrowExpr, .canImportExpr, .canImportVersionInfo, .closureExpr, .consumeExpr, .copyExpr, .declReferenceExpr, .dictionaryExpr, .discardAssignmentExpr, .doExpr, .editorPlaceholderExpr, .floatLiteralExpr, .forceUnwrapExpr, .functionCallExpr, .genericSpecializationExpr, .ifExpr, .inOutExpr, .infixOperatorExpr, .integerLiteralExpr, .isExpr, .keyPathExpr, .macroExpansionExpr, .memberAccessExpr, .missingExpr, .nilLiteralExpr, .optionalChainingExpr, .packElementExpr, .packExpansionExpr, .patternExpr, .postfixIfConfigExpr, .postfixOperatorExpr, .prefixOperatorExpr, .regexLiteralExpr, .sequenceExpr, .simpleStringLiteralExpr, .stringLiteralExpr, .subscriptCallExpr, .superExpr, .switchExpr, .ternaryExpr, .tryExpr, .tupleExpr, .typeExpr, .unresolvedAsExpr, .unresolvedIsExpr, .unresolvedTernaryExpr: + case .arrayExpr, .arrowExpr, .asExpr, .assignmentExpr, .awaitExpr, .binaryOperatorExpr, .booleanLiteralExpr, .borrowExpr, ._canImportExpr, ._canImportVersionInfo, .closureExpr, .consumeExpr, .copyExpr, .declReferenceExpr, .dictionaryExpr, .discardAssignmentExpr, .doExpr, .editorPlaceholderExpr, .floatLiteralExpr, .forceUnwrapExpr, .functionCallExpr, .genericSpecializationExpr, .ifExpr, .inOutExpr, .infixOperatorExpr, .integerLiteralExpr, .isExpr, .keyPathExpr, .macroExpansionExpr, .memberAccessExpr, .missingExpr, .nilLiteralExpr, .optionalChainingExpr, .packElementExpr, .packExpansionExpr, .patternExpr, .postfixIfConfigExpr, .postfixOperatorExpr, .prefixOperatorExpr, .regexLiteralExpr, .sequenceExpr, .simpleStringLiteralExpr, .stringLiteralExpr, .subscriptCallExpr, .superExpr, .switchExpr, .ternaryExpr, .tryExpr, .tupleExpr, .typeExpr, .unresolvedAsExpr, .unresolvedIsExpr, .unresolvedTernaryExpr: return true default: return false diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift index d5e9ab34c9d..18adc64115b 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift @@ -1053,14 +1053,14 @@ public struct RawLifetimeSpecifierArgumentSyntax: RawSyntaxNodeProtocol { @_spi(ExperimentalLanguageFeatures) #endif @_spi(RawSyntax) -public struct RawLifetimeSpecifierArgumentsSyntax: RawSyntaxNodeProtocol { +public struct RawLifetimeTypeSpecifierSyntax: RawSyntaxNodeProtocol { @_spi(RawSyntax) public var layoutView: RawSyntaxLayoutView { return raw.layoutView! } public static func isKindOf(_ raw: RawSyntax) -> Bool { - return raw.kind == .lifetimeSpecifierArguments + return raw.kind == .lifetimeTypeSpecifier } public var raw: RawSyntax @@ -1082,9 +1082,13 @@ public struct RawLifetimeSpecifierArgumentsSyntax: RawSyntaxNodeProtocol { } public init( - _ unexpectedBeforeLeftParen: RawUnexpectedNodesSyntax? = nil, + _ unexpectedBeforeDependsOnKeyword: RawUnexpectedNodesSyntax? = nil, + dependsOnKeyword: RawTokenSyntax, + _ unexpectedBetweenDependsOnKeywordAndLeftParen: RawUnexpectedNodesSyntax? = nil, leftParen: RawTokenSyntax, - _ unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? = nil, + _ unexpectedBetweenLeftParenAndScopedKeyword: RawUnexpectedNodesSyntax? = nil, + scopedKeyword: RawTokenSyntax?, + _ unexpectedBetweenScopedKeywordAndArguments: RawUnexpectedNodesSyntax? = nil, arguments: RawLifetimeSpecifierArgumentListSyntax, _ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil, rightParen: RawTokenSyntax, @@ -1092,118 +1096,65 @@ public struct RawLifetimeSpecifierArgumentsSyntax: RawSyntaxNodeProtocol { arena: __shared SyntaxArena ) { let raw = RawSyntax.makeLayout( - kind: .lifetimeSpecifierArguments, uninitializedCount: 7, arena: arena) { layout in + kind: .lifetimeTypeSpecifier, uninitializedCount: 11, 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 + 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 unexpectedBeforeLeftParen: RawUnexpectedNodesSyntax? { + public var unexpectedBeforeDependsOnKeyword: RawUnexpectedNodesSyntax? { layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var leftParen: RawTokenSyntax { + public var dependsOnKeyword: RawTokenSyntax { layoutView.children[1].map(RawTokenSyntax.init(raw:))! } - public var unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? { + public var unexpectedBetweenDependsOnKeywordAndLeftParen: RawUnexpectedNodesSyntax? { layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var arguments: RawLifetimeSpecifierArgumentListSyntax { - layoutView.children[3].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))! + public var leftParen: RawTokenSyntax { + layoutView.children[3].map(RawTokenSyntax.init(raw:))! } - public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? { + public var unexpectedBetweenLeftParenAndScopedKeyword: RawUnexpectedNodesSyntax? { layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var rightParen: RawTokenSyntax { - layoutView.children[5].map(RawTokenSyntax.init(raw:))! + public var scopedKeyword: RawTokenSyntax? { + layoutView.children[5].map(RawTokenSyntax.init(raw:)) } - public var unexpectedAfterRightParen: RawUnexpectedNodesSyntax? { + public var unexpectedBetweenScopedKeywordAndArguments: 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 arguments: RawLifetimeSpecifierArgumentListSyntax { + layoutView.children[7].map(RawLifetimeSpecifierArgumentListSyntax.init(raw:))! } - public var unexpectedBetweenSpecifierAndArguments: RawUnexpectedNodesSyntax? { - layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? { + layoutView.children[8].map(RawUnexpectedNodesSyntax.init(raw:)) } - public var arguments: RawLifetimeSpecifierArgumentsSyntax { - layoutView.children[3].map(RawLifetimeSpecifierArgumentsSyntax.init(raw:))! + public var rightParen: RawTokenSyntax { + layoutView.children[9].map(RawTokenSyntax.init(raw:))! } - public var unexpectedAfterArguments: RawUnexpectedNodesSyntax? { - layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) + public var unexpectedAfterRightParen: RawUnexpectedNodesSyntax? { + layoutView.children[10].map(RawUnexpectedNodesSyntax.init(raw:)) } } diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index 8d22721337f..208750e3257 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -464,7 +464,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.identifier)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) - case .canImportExpr: + case ._canImportExpr: assert(layout.count == 11) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.keyword("canImport")])) @@ -473,11 +473,11 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 5, verify(layout[5], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.identifier)])) assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 7, verify(layout[7], as: RawCanImportVersionInfoSyntax?.self)) + assertNoError(kind, 7, verify(layout[7], as: Raw_CanImportVersionInfoSyntax?.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 .canImportVersionInfo: + case ._canImportVersionInfo: assert(layout.count == 9) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.comma)])) @@ -1725,27 +1725,19 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { 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) + assert(layout.count == 11) 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, 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: RawLifetimeSpecifierArgumentsSyntax.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)) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift index 7f0b314579f..212b4d2e43f 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift @@ -12,21 +12,20 @@ // //===----------------------------------------------------------------------===// -// MARK: - CanImportExprSyntax +// MARK: - _CanImportExprSyntax /// ### Children /// /// - `canImportKeyword`: `canImport` /// - `leftParen`: `(` /// - `importPath`: `` -/// - `versionInfo`: ``CanImportVersionInfoSyntax``? +/// - `versionInfo`: `_CanImportVersionInfoSyntax`? /// - `rightParen`: `)` -@available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") -public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxNodeProtocol { +public struct _CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxNodeProtocol { public let _syntaxNode: Syntax public init?(_ node: some SyntaxProtocol) { - guard node.raw.kind == .canImportExpr else { + guard node.raw.kind == ._canImportExpr else { return nil } self._syntaxNode = node._syntaxNode @@ -44,7 +43,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr _ unexpectedBetweenLeftParenAndImportPath: UnexpectedNodesSyntax? = nil, importPath: TokenSyntax, _ unexpectedBetweenImportPathAndVersionInfo: UnexpectedNodesSyntax? = nil, - versionInfo: CanImportVersionInfoSyntax? = nil, + versionInfo: _CanImportVersionInfoSyntax? = nil, _ unexpectedBetweenVersionInfoAndRightParen: UnexpectedNodesSyntax? = nil, rightParen: TokenSyntax = .rightParenToken(), _ unexpectedAfterRightParen: UnexpectedNodesSyntax? = nil, @@ -80,7 +79,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr unexpectedAfterRightParen?.raw ] let raw = RawSyntax.makeLayout( - kind: SyntaxKind.canImportExpr, + kind: SyntaxKind._canImportExpr, from: layout, arena: arena, leadingTrivia: leadingTrivia, @@ -96,7 +95,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -108,7 +107,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -117,7 +116,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -129,7 +128,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 3)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -138,7 +137,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -150,7 +149,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 5)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -159,16 +158,16 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 6)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } - public var versionInfo: CanImportVersionInfoSyntax? { + public var versionInfo: _CanImportVersionInfoSyntax? { get { - return Syntax(self).child(at: 7)?.cast(CanImportVersionInfoSyntax.self) + return Syntax(self).child(at: 7)?.cast(_CanImportVersionInfoSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 7, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 7, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -177,7 +176,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 8)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 8, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 8, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -189,7 +188,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 9)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 9, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 9, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -198,7 +197,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr return Syntax(self).child(at: 10)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 10, with: Syntax(value), arena: SyntaxArena()).cast(CanImportExprSyntax.self) + self = Syntax(self).replacingChild(at: 10, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportExprSyntax.self) } } @@ -219,7 +218,7 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr } } -// MARK: - CanImportVersionInfoSyntax +// MARK: - _CanImportVersionInfoSyntax /// ### Children /// @@ -230,13 +229,12 @@ public struct CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExpr /// /// ### Contained in /// -/// - ``CanImportExprSyntax``.``CanImportExprSyntax/versionInfo`` -@available(*, deprecated, message: "'canImport' directives are now represented as a `FunctionCallExpr`") -public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxNodeProtocol { +/// - `_CanImportExprSyntax`.`_CanImportExprSyntax/versionInfo` +public struct _CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxNodeProtocol { public let _syntaxNode: Syntax public init?(_ node: some SyntaxProtocol) { - guard node.raw.kind == .canImportVersionInfo else { + guard node.raw.kind == ._canImportVersionInfo else { return nil } self._syntaxNode = node._syntaxNode @@ -284,7 +282,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L unexpectedAfterVersion?.raw ] let raw = RawSyntax.makeLayout( - kind: SyntaxKind.canImportVersionInfo, + kind: SyntaxKind._canImportVersionInfo, from: layout, arena: arena, leadingTrivia: leadingTrivia, @@ -300,7 +298,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -312,7 +310,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 1)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -321,7 +319,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -335,7 +333,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 3)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -344,7 +342,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -356,7 +354,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 5)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -365,7 +363,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 6)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -374,7 +372,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 7)!.cast(VersionTupleSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 7, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 7, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -383,7 +381,7 @@ public struct CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _L return Syntax(self).child(at: 8)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 8, with: Syntax(value), arena: SyntaxArena()).cast(CanImportVersionInfoSyntax.self) + self = Syntax(self).replacingChild(at: 8, with: Syntax(value), arena: SyntaxArena()).cast(_CanImportVersionInfoSyntax.self) } } @@ -4524,6 +4522,9 @@ public struct ConventionWitnessMethodAttributeArgumentsSyntax: SyntaxProtocol, S /// - 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. + /// - witnessMethodLabel: The `witnessMethod` label. + /// - colon: The colon separating the `witnessMethod` label and the original protocol name. + /// - protocolName: The original protocol name. /// - 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, @@ -4578,6 +4579,8 @@ public struct ConventionWitnessMethodAttributeArgumentsSyntax: SyntaxProtocol, S } } + /// The `witnessMethod` label. + /// /// ### Tokens /// /// For syntax trees generated by the parser, this is guaranteed to be `witness_method`. @@ -4599,6 +4602,8 @@ public struct ConventionWitnessMethodAttributeArgumentsSyntax: SyntaxProtocol, S } } + /// The colon separating the `witnessMethod` label and the original protocol name. + /// /// ### Tokens /// /// For syntax trees generated by the parser, this is guaranteed to be `:`. @@ -4620,6 +4625,8 @@ public struct ConventionWitnessMethodAttributeArgumentsSyntax: SyntaxProtocol, S } } + /// The original protocol name. + /// /// ### Tokens /// /// For syntax trees generated by the parser, this is guaranteed to be ``. diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift index ce9c9bac45f..09173a3c496 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift @@ -2817,7 +2817,9 @@ public struct DifferentiableAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHash /// - 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. + /// - kindSpecifier: The differentiability kind, if it exists. /// - kindSpecifierComma: The comma following the differentiability kind, if it exists. + /// - arguments: The differentiability arguments, if any exists. /// - argumentsComma: The comma following the differentiability arguments clause, if it exists. /// - genericWhereClause: A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`. /// - 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. @@ -2886,6 +2888,8 @@ public struct DifferentiableAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHash } } + /// The differentiability kind, if it exists. + /// /// ### Tokens /// /// For syntax trees generated by the parser, this is guaranteed to be one of the following kinds: @@ -2933,6 +2937,7 @@ public struct DifferentiableAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHash } } + /// The differentiability arguments, if any exists. public var arguments: DifferentiabilityWithRespectToArgumentSyntax? { get { return Syntax(self).child(at: 5)?.cast(DifferentiabilityWithRespectToArgumentSyntax.self) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index 605ea5af339..9db4ef199ab 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -1790,28 +1790,31 @@ public struct LifetimeSpecifierArgumentSyntax: SyntaxProtocol, SyntaxHashable, _ } } -// MARK: - LifetimeSpecifierArgumentsSyntax +// MARK: - LifetimeTypeSpecifierSyntax -/// An optional argument passed to a type parameter. -/// -/// ### Example -/// `borrow(data)` in `func foo(data: Array) -> borrow(data) ComplexReferenceType` +/// A specifier that specifies function parameter on whose lifetime a type depends /// /// - Experiment: 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 LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { +public struct LifetimeTypeSpecifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { public let _syntaxNode: Syntax public init?(_ node: some SyntaxProtocol) { - guard node.raw.kind == .lifetimeSpecifierArguments else { + guard node.raw.kind == .lifetimeTypeSpecifier else { return nil } self._syntaxNode = node._syntaxNode @@ -1819,13 +1822,18 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, /// - 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. + /// - 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, - _ unexpectedBeforeLeftParen: UnexpectedNodesSyntax? = nil, + _ unexpectedBeforeDependsOnKeyword: UnexpectedNodesSyntax? = nil, + dependsOnKeyword: TokenSyntax = .keyword(.dependsOn), + _ unexpectedBetweenDependsOnKeywordAndLeftParen: UnexpectedNodesSyntax? = nil, leftParen: TokenSyntax = .leftParenToken(), - _ unexpectedBetweenLeftParenAndArguments: UnexpectedNodesSyntax? = nil, + _ unexpectedBetweenLeftParenAndScopedKeyword: UnexpectedNodesSyntax? = nil, + scopedKeyword: TokenSyntax? = nil, + _ unexpectedBetweenScopedKeywordAndArguments: UnexpectedNodesSyntax? = nil, arguments: LifetimeSpecifierArgumentListSyntax, _ unexpectedBetweenArgumentsAndRightParen: UnexpectedNodesSyntax? = nil, rightParen: TokenSyntax = .rightParenToken(), @@ -1836,25 +1844,33 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, // 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, + unexpectedBeforeDependsOnKeyword, + dependsOnKeyword, + unexpectedBetweenDependsOnKeywordAndLeftParen, leftParen, - unexpectedBetweenLeftParenAndArguments, + unexpectedBetweenLeftParenAndScopedKeyword, + scopedKeyword, + unexpectedBetweenScopedKeywordAndArguments, arguments, unexpectedBetweenArgumentsAndRightParen, rightParen, unexpectedAfterRightParen ))) { (arena, _) in let layout: [RawSyntax?] = [ - unexpectedBeforeLeftParen?.raw, + unexpectedBeforeDependsOnKeyword?.raw, + dependsOnKeyword.raw, + unexpectedBetweenDependsOnKeywordAndLeftParen?.raw, leftParen.raw, - unexpectedBetweenLeftParenAndArguments?.raw, + unexpectedBetweenLeftParenAndScopedKeyword?.raw, + scopedKeyword?.raw, + unexpectedBetweenScopedKeywordAndArguments?.raw, arguments.raw, unexpectedBetweenArgumentsAndRightParen?.raw, rightParen.raw, unexpectedAfterRightParen?.raw ] let raw = RawSyntax.makeLayout( - kind: SyntaxKind.lifetimeSpecifierArguments, + kind: SyntaxKind.lifetimeTypeSpecifier, from: layout, arena: arena, leadingTrivia: leadingTrivia, @@ -1865,43 +1881,88 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, } } - public var unexpectedBeforeLeftParen: UnexpectedNodesSyntax? { + 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(LifetimeSpecifierArgumentsSyntax.self) + 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 `(`. - public var leftParen: TokenSyntax { + /// 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(LifetimeSpecifierArgumentsSyntax.self) + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) } } - public var unexpectedBetweenLeftParenAndArguments: UnexpectedNodesSyntax? { + 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(LifetimeSpecifierArgumentsSyntax.self) + 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) } } - /// 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) + return Syntax(self).child(at: 7)!.cast(LifetimeSpecifierArgumentListSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + self = Syntax(self).replacingChild(at: 7, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) } } @@ -1913,10 +1974,10 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, /// - 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 { + public func addArguments(_ element: LifetimeSpecifierArgumentSyntax) -> LifetimeTypeSpecifierSyntax { var collection: RawSyntax let arena = SyntaxArena() - if let col = raw.layoutView!.children[3] { + if let col = raw.layoutView!.children[7] { collection = col.layoutView!.appending(element.raw, arena: arena) } else { collection = RawSyntax.makeLayout(kind: SyntaxKind.lifetimeSpecifierArgumentList, @@ -1924,20 +1985,20 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, } return Syntax(self) .replacingChild( - at: 3, + at: 7, with: collection, rawNodeArena: arena, allocationArena: arena ) - .cast(LifetimeSpecifierArgumentsSyntax.self) + .cast(LifetimeTypeSpecifierSyntax.self) } public var unexpectedBetweenArgumentsAndRightParen: UnexpectedNodesSyntax? { get { - return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) + return Syntax(self).child(at: 8)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + self = Syntax(self).replacingChild(at: 8, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) } } @@ -1946,27 +2007,31 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, /// 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) + return Syntax(self).child(at: 9)!.cast(TokenSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + self = Syntax(self).replacingChild(at: 9, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) } } public var unexpectedAfterRightParen: UnexpectedNodesSyntax? { get { - return Syntax(self).child(at: 6)?.cast(UnexpectedNodesSyntax.self) + return Syntax(self).child(at: 10)?.cast(UnexpectedNodesSyntax.self) } set(value) { - self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeSpecifierArgumentsSyntax.self) + self = Syntax(self).replacingChild(at: 10, with: Syntax(value), arena: SyntaxArena()).cast(LifetimeTypeSpecifierSyntax.self) } } public static var structure: SyntaxNodeStructure { return .layout([ - \Self.unexpectedBeforeLeftParen, + \Self.unexpectedBeforeDependsOnKeyword, + \Self.dependsOnKeyword, + \Self.unexpectedBetweenDependsOnKeywordAndLeftParen, \Self.leftParen, - \Self.unexpectedBetweenLeftParenAndArguments, + \Self.unexpectedBetweenLeftParenAndScopedKeyword, + \Self.scopedKeyword, + \Self.unexpectedBetweenScopedKeywordAndArguments, \Self.arguments, \Self.unexpectedBetweenArgumentsAndRightParen, \Self.rightParen, @@ -1975,140 +2040,6 @@ public struct LifetimeSpecifierArgumentsSyntax: SyntaxProtocol, SyntaxHashable, } } -// 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/SyntaxNodesOP.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift index 1403ee2ea3f..d27d33ced51 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift @@ -36,6 +36,8 @@ public struct ObjCSelectorPieceSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynt /// - 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. + /// - name: The identifier name for a nullary selection, if it exists. + /// - colon: The colon separating the label and the value or a colon representing an unlabeled argument /// - 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, @@ -84,6 +86,7 @@ public struct ObjCSelectorPieceSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynt } } + /// The identifier name for a nullary selection, if it exists. public var name: TokenSyntax? { get { return Syntax(self).child(at: 1)?.cast(TokenSyntax.self) @@ -102,6 +105,8 @@ public struct ObjCSelectorPieceSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynt } } + /// The colon separating the label and the value or a colon representing an unlabeled argument + /// /// ### Tokens /// /// For syntax trees generated by the parser, this is guaranteed to be `:`. @@ -2101,6 +2106,7 @@ public struct PlatformVersionItemSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// - 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. + /// - platformVersion: The platform/version pair, e.g. `iOS 10.1` /// - trailingComma: A trailing comma if the argument is followed by another argument /// - 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( @@ -2150,6 +2156,7 @@ public struct PlatformVersionItemSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy } } + /// The platform/version pair, e.g. `iOS 10.1` public var platformVersion: PlatformVersionSyntax { get { return Syntax(self).child(at: 1)!.cast(PlatformVersionSyntax.self) diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index e9e1eb7a67a..dbe1704d601 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -3796,7 +3796,7 @@ public struct VersionComponentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta /// ### Contained in /// /// - ``AvailabilityLabeledArgumentSyntax``.``AvailabilityLabeledArgumentSyntax/value`` -/// - ``CanImportVersionInfoSyntax``.``CanImportVersionInfoSyntax/version`` +/// - `_CanImportVersionInfoSyntax`.`_CanImportVersionInfoSyntax/version` /// - ``PlatformVersionSyntax``.``PlatformVersionSyntax/version`` public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { public let _syntaxNode: Syntax diff --git a/Tests/SwiftParserTest/AttributeTests.swift b/Tests/SwiftParserTest/AttributeTests.swift index c1da7778ff2..c514b029498 100644 --- a/Tests/SwiftParserTest/AttributeTests.swift +++ b/Tests/SwiftParserTest/AttributeTests.swift @@ -1022,4 +1022,26 @@ final class AttributeTests: ParserTestCase { ] ) } + + func testMisplacedAttributeInVariableDecl() { + assertParse( + """ + struct A { + var 1️⃣@State name: String + } + """, + diagnostics: [ + DiagnosticSpec( + message: "misplaced attribute in variable declaration", + fixIts: ["move attributes in front of 'var'"] + ) + ], + fixedSource: + """ + struct A { + @State var name: String + } + """ + ) + } } diff --git a/Tests/SwiftParserTest/DeclarationTests.swift b/Tests/SwiftParserTest/DeclarationTests.swift index 30ed2f2e096..4223ea7ab2d 100644 --- a/Tests/SwiftParserTest/DeclarationTests.swift +++ b/Tests/SwiftParserTest/DeclarationTests.swift @@ -3286,7 +3286,7 @@ final class DeclarationTests: ParserTestCase { func testInitializerWithReturnType() { assertParse( - "init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array) -> _borrow(a) Self", + "init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array) -> dependsOn(a) Self", experimentalFeatures: .nonescapableTypes ) @@ -3308,4 +3308,21 @@ final class DeclarationTests: ParserTestCase { experimentalFeatures: .transferringArgsAndResults ) } + + func testMisplacedAttributeInVarDeclWithMultipleBindings() { + assertParse( + """ + let a = "a", 1️⃣@foo b = "b" + """, + diagnostics: [ + DiagnosticSpec( + message: "misplaced attribute in variable declaration", + fixIts: ["move attributes in front of 'let'"] + ) + ], + fixedSource: """ + @foo let a = "a", b = "b" + """ + ) + } } diff --git a/Tests/SwiftParserTest/IncrementalParsingTests.swift b/Tests/SwiftParserTest/IncrementalParsingTests.swift index 679ace162d3..8bda2652e4e 100644 --- a/Tests/SwiftParserTest/IncrementalParsingTests.swift +++ b/Tests/SwiftParserTest/IncrementalParsingTests.swift @@ -23,7 +23,7 @@ class IncrementalParsingTests: ParserTestCase { struct A⏩️⏸️A⏪️ { func f() { """, reusedNodes: [ - ReusedNodeSpec("func f() {", kind: .memberDeclListItem) + ReusedNodeSpec("func f() {", kind: .memberBlockItem) ] ) } @@ -191,10 +191,10 @@ class IncrementalParsingTests: ParserTestCase { } """, reusedNodes: [ - ReusedNodeSpec("let a: Int", kind: .memberDeclListItem), - ReusedNodeSpec("let b: Int", kind: .memberDeclListItem), - ReusedNodeSpec("let c: Int", kind: .memberDeclListItem), - ReusedNodeSpec("let g: Int", kind: .memberDeclListItem), + ReusedNodeSpec("let a: Int", kind: .memberBlockItem), + ReusedNodeSpec("let b: Int", kind: .memberBlockItem), + ReusedNodeSpec("let c: Int", kind: .memberBlockItem), + ReusedNodeSpec("let g: Int", kind: .memberBlockItem), ] ) } diff --git a/Tests/SwiftParserTest/TypeTests.swift b/Tests/SwiftParserTest/TypeTests.swift index 936ef5f817a..5e5f503c5c3 100644 --- a/Tests/SwiftParserTest/TypeTests.swift +++ b/Tests/SwiftParserTest/TypeTests.swift @@ -331,12 +331,12 @@ final class TypeTests: ParserTestCase { } func testLifetimeSpecifier() { - assertParse("func foo() -> _borrow(x) X", experimentalFeatures: [.nonescapableTypes]) + assertParse("func foo() -> dependsOn(x) X", experimentalFeatures: [.nonescapableTypes]) - assertParse("func foo() -> _borrow(x, y) X", experimentalFeatures: [.nonescapableTypes]) + assertParse("func foo() -> dependsOn(x, y) X", experimentalFeatures: [.nonescapableTypes]) assertParse( - "func foo() -> _borrow(1️⃣) X", + "func foo() -> dependsOn(1️⃣) X", diagnostics: [ DiagnosticSpec( locationMarker: "1️⃣", @@ -344,12 +344,12 @@ final class TypeTests: ParserTestCase { fixIts: ["insert parameter reference"] ) ], - fixedSource: "func foo() -> _borrow(<#identifier#>) X", + fixedSource: "func foo() -> dependsOn(<#identifier#>) X", experimentalFeatures: [.nonescapableTypes] ) assertParse( - "func foo() -> _borrow(x,1️⃣) X", + "func foo() -> dependsOn(x,1️⃣) X", diagnostics: [ DiagnosticSpec( locationMarker: "1️⃣", @@ -357,20 +357,16 @@ final class TypeTests: ParserTestCase { fixIts: ["insert parameter reference"] ) ], - fixedSource: "func foo() -> _borrow(x, <#identifier#>) X", + fixedSource: "func foo() -> dependsOn(x, <#identifier#>) X", experimentalFeatures: [.nonescapableTypes] ) - assertParse("func foo() -> _borrow(x) _borrow(y) X", experimentalFeatures: [.nonescapableTypes]) + assertParse("func foo() -> dependsOn(x) dependsOn(scoped 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() -> dependsOn(scoped x) X", experimentalFeatures: [.nonescapableTypes]) assertParse( - "func foo() -> _borrow 1️⃣X", + "func foo() -> dependsOn 1️⃣X", diagnostics: [ DiagnosticSpec( locationMarker: "1️⃣", @@ -378,12 +374,12 @@ final class TypeTests: ParserTestCase { fixIts: ["insert '(', parameter reference, and ')'"] ) ], - fixedSource: "func foo() -> _borrow (<#identifier#>) X", + fixedSource: "func foo() -> dependsOn (<#identifier#>) X", experimentalFeatures: [.nonescapableTypes] ) assertParse( - "func foo() -> _borrow(1️⃣*) X", + "func foo() -> dependsOn(1️⃣*) X", diagnostics: [ DiagnosticSpec( locationMarker: "1️⃣", @@ -392,16 +388,16 @@ final class TypeTests: ParserTestCase { ), DiagnosticSpec(locationMarker: "1️⃣", message: "unexpected code '*' in lifetime specifier"), ], - fixedSource: "func foo() -> _borrow(<#identifier#>*) X", + fixedSource: "func foo() -> dependsOn(<#identifier#>*) X", experimentalFeatures: [.nonescapableTypes] ) - assertParse("func foo() -> _borrow(0) X", diagnostics: [], experimentalFeatures: [.nonescapableTypes]) + assertParse("func foo() -> dependsOn(0) X", diagnostics: [], experimentalFeatures: [.nonescapableTypes]) - assertParse("func foo() -> _borrow(self) X", experimentalFeatures: [.nonescapableTypes]) + assertParse("func foo() -> dependsOn(self) X", experimentalFeatures: [.nonescapableTypes]) assertParse( - "func foo() -> _borrow1️⃣(0)2️⃣ X", + "func foo() -> dependsOn1️⃣(0)2️⃣ X", diagnostics: [ DiagnosticSpec( locationMarker: "1️⃣", @@ -415,14 +411,14 @@ final class TypeTests: ParserTestCase { ), ], fixedSource: """ - func foo() -> _borrow + func foo() -> dependsOn (0) X """ ) assertParse( - "func foo() -> _borrow(1️⃣-1) X", + "func foo() -> dependsOn(1️⃣-1) X", diagnostics: [ DiagnosticSpec( message: "expected parameter reference in lifetime specifier", @@ -430,7 +426,7 @@ final class TypeTests: ParserTestCase { ), DiagnosticSpec(message: "unexpected code '-1' in lifetime specifier"), ], - fixedSource: "func foo() -> _borrow(<#identifier#>-1) X", + fixedSource: "func foo() -> dependsOn(<#identifier#>-1) X", experimentalFeatures: [.nonescapableTypes] ) }