From 456719218cbca3c4890668913b92d3b030dcca3b Mon Sep 17 00:00:00 2001 From: Becca Royal-Gordon Date: Mon, 4 Nov 2024 18:03:29 -0800 Subject: [PATCH 1/4] [NFC-ish] Factor out InitSignature Introduce and factor out a type that represents a list of children for which an initializer ought to exist. This changes some `@available(renamed:)` values, but nothing that should change diagnostics or behavior. --- .../Sources/SyntaxSupport/InitSignature.swift | 32 +++ ...s.swift => InitSignature+Extensions.swift} | 42 +++- .../RenamedChildrenCompatibilityFile.swift | 139 +++++------ .../swiftsyntax/SyntaxNodesFile.swift | 6 +- .../BuildableNodesFile.swift | 2 +- ...amedChildrenBuilderCompatibilityFile.swift | 4 +- .../RenamedChildrenCompatibility.swift | 232 +++++++++--------- 7 files changed, 264 insertions(+), 193 deletions(-) create mode 100644 CodeGeneration/Sources/SyntaxSupport/InitSignature.swift rename CodeGeneration/Sources/generate-swift-syntax/{LayoutNode+Extensions.swift => InitSignature+Extensions.swift} (86%) diff --git a/CodeGeneration/Sources/SyntaxSupport/InitSignature.swift b/CodeGeneration/Sources/SyntaxSupport/InitSignature.swift new file mode 100644 index 00000000000..e93ac4ed12a --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/InitSignature.swift @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +/// Represents an initializer that should be generated. +public struct InitSignature { + /// The list of children which shoudl be given parameters and initialized by the initializer. + public var children: [Child] + + /// Create an initializer with an arbitrary array of children. + public init(children: [Child]) { + self.children = children + } + + /// Create an initializer for the (non-deprecated) children of a given layout node. + public init(_ layoutNode: LayoutNode) { + self.init(children: layoutNode.children) + } + + /// Create an initializer for the (non-deprecated) children of a given trait. + public init(_ trait: Trait) { + self.init(children: trait.children) + } +} diff --git a/CodeGeneration/Sources/generate-swift-syntax/LayoutNode+Extensions.swift b/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift similarity index 86% rename from CodeGeneration/Sources/generate-swift-syntax/LayoutNode+Extensions.swift rename to CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift index cb802c0b5e7..bc6a85563a9 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/LayoutNode+Extensions.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift @@ -15,7 +15,19 @@ import SwiftSyntaxBuilder import SyntaxSupport import Utils -extension LayoutNode { +extension InitSignature { + var compoundName: String { + let renamedArguments = children.map { child in + if child.isUnexpectedNodes { + return "_:" + } else { + return "\(child.labelDeclName):" + } + }.joined(separator: "") + + return "init(leadingTrivia:\(renamedArguments)trailingTrivia:)" + } + func generateInitializerDeclHeader(useDeprecatedChildName: Bool = false) -> SyntaxNodeString { if children.isEmpty { return "public init()" @@ -210,3 +222,31 @@ fileprivate func convertFromSyntaxProtocolToSyntaxType( } return ExprSyntax("\(childName.declNameOrVarCallName)") } + +extension InitSignature { + /// Generates arguments to pass this initializer's parameters through to the + /// non-deprecated initializer. This will generate nested initializer calls for + /// any children with a compound `newerChildPath`. + func makeArgumentsToInitializeNewestChildren() -> [LabeledExprSyntax] { + return children.map { child in + let deprecatedName: TokenSyntax + + if let deprecatedVarName = child.deprecatedVarName { + deprecatedName = deprecatedVarName + } else { + deprecatedName = child.varDeclName + } + + let argValue = ExprSyntax(DeclReferenceExprSyntax(baseName: deprecatedName)) + + if child.isUnexpectedNodes { + return LabeledExprSyntax(expression: argValue) + } + return LabeledExprSyntax( + label: child.labelDeclName, + colon: .colonToken(), + expression: argValue + ) + } + } +} diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift index 455f4d18602..532d212d02e 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift @@ -20,86 +20,81 @@ let renamedChildrenCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copy try ExtensionDeclSyntax("extension \(layoutNode.type.syntaxBaseName)") { for child in layoutNode.children { if let deprecatedVarName = child.deprecatedVarName { - let childType: TypeSyntax = - child.kind.isNodeChoicesEmpty ? child.syntaxNodeKind.syntaxType : child.syntaxChoicesType - let type = child.isOptional ? TypeSyntax("\(childType)?") : childType - - DeclSyntax( - """ - @available(*, deprecated, renamed: "\(child.identifier)") - public var \(deprecatedVarName): \(type) { - get { - return \(child.baseCallName) - } - set { - \(child.baseCallName) = newValue - } - } - """ - ) - if let childNode = SYNTAX_NODE_MAP[child.syntaxNodeKind]?.collectionNode, - !child.isUnexpectedNodes, - case .collection( - kind: _, - collectionElementName: let collectionElementName, - defaultsToEmpty: _, - deprecatedCollectionElementName: let deprecatedCollectionElementName - ) = child.kind, - let deprecatedCollectionElementName - { - let childEltType = childNode.collectionElementType.syntaxBaseName - - DeclSyntax( - """ - @available(*, deprecated, renamed: "add\(raw: collectionElementName)") - public func add\(raw: deprecatedCollectionElementName)(_ element: \(childEltType)) -> \(layoutNode.kind.syntaxType) { - return add\(raw: collectionElementName)(element) - } - """ - ) + makeCompatibilityVar(for: child, deprecatedVarName: deprecatedVarName) + if let addMethod = makeCompatibilityAddMethod(for: child) { + addMethod } } } - let deprecatedNames = layoutNode.children - .filter { !$0.isUnexpectedNodes && $0.hasDeprecatedName } - .map { $0.identifier.description } - .joined(separator: ", ") + let renamedName = InitSignature(layoutNode).compoundName + makeCompatibilityInit(for: InitSignature(layoutNode), renamedName: renamedName) + } + } +} + +func makeCompatibilityVar(for child: Child, deprecatedVarName: TokenSyntax) -> DeclSyntax { + let childType: TypeSyntax = + child.kind.isNodeChoicesEmpty ? child.syntaxNodeKind.syntaxType : child.syntaxChoicesType + let type = child.isOptional ? TypeSyntax("\(childType)?") : childType - let renamedArguments = - layoutNode.children.map { child in - if child.isUnexpectedNodes { - return "_:" - } else { - return "\(child.labelDeclName):" - } - }.joined(separator: "") + return DeclSyntax( + """ + @available(*, deprecated, renamed: "\(child.identifier)") + public var \(deprecatedVarName): \(type) { + get { + return \(child.baseCallName) + } + set { + \(child.baseCallName) = newValue + } + } + """ + ) +} - let renamedName = "\(layoutNode.type.syntaxBaseName)(leadingTrivia:\(renamedArguments)trailingTrivia:)" +func makeCompatibilityAddMethod(for child: Child) -> DeclSyntax? { + if let childNode = SYNTAX_NODE_MAP[child.syntaxNodeKind]?.collectionNode, + !child.isUnexpectedNodes, + case .collection( + kind: _, + collectionElementName: let collectionElementName, + defaultsToEmpty: _, + deprecatedCollectionElementName: let deprecatedCollectionElementName + ) = child.kind, + let deprecatedCollectionElementName + { + let childEltType = childNode.collectionElementType.syntaxBaseName - try! InitializerDeclSyntax( - """ - @available(*, deprecated, renamed: \(literal: renamedName)) - @_disfavoredOverload - \(layoutNode.generateInitializerDeclHeader(useDeprecatedChildName: true)) - """ - ) { - FunctionCallExprSyntax(callee: ExprSyntax("self.init")) { - LabeledExprSyntax(label: "leadingTrivia", expression: ExprSyntax("leadingTrivia")) - for child in layoutNode.children { - if child.isUnexpectedNodes { - LabeledExprSyntax(expression: ExprSyntax("\(child.deprecatedVarName ?? child.baseCallName)")) - } else { - LabeledExprSyntax( - label: child.labelDeclName, - colon: .colonToken(), - expression: DeclReferenceExprSyntax(baseName: child.deprecatedVarName ?? child.baseCallName) - ) - } - } - LabeledExprSyntax(label: "trailingTrivia", expression: ExprSyntax("trailingTrivia")) - } + return DeclSyntax( + """ + @available(*, deprecated, renamed: "add\(raw: collectionElementName)") + public func add\(raw: deprecatedCollectionElementName)(_ element: \(childEltType)) -> Self { + return add\(raw: collectionElementName)(element) + } + """ + ) + } + + return nil +} + +func makeCompatibilityInit(for signature: InitSignature, renamedName: String) -> InitializerDeclSyntax { + try! InitializerDeclSyntax( + """ + @available(*, deprecated, renamed: \(literal: renamedName)) + @_disfavoredOverload + \(signature.generateInitializerDeclHeader(useDeprecatedChildName: true)) + """ + ) { + FunctionCallExprSyntax(callee: ExprSyntax("self.init")) { + LabeledExprSyntax(label: "leadingTrivia", expression: ExprSyntax("leadingTrivia")) + + for argExpr in signature.makeArgumentsToInitializeNewestChildren() { + argExpr } + + LabeledExprSyntax(label: "trailingTrivia", expression: ExprSyntax("trailingTrivia")) } } } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift index 79770fa77eb..214ca0ce2c6 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift @@ -52,10 +52,12 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax { """ ) + let initSignature = InitSignature(node) + try! InitializerDeclSyntax( """ - \(node.generateInitializerDocComment())\ - \(node.generateInitializerDeclHeader()) + \(initSignature.generateInitializerDocComment())\ + \(initSignature.generateInitializerDeclHeader()) """ ) { let parameters = ClosureParameterListSyntax { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift index 79e25e94cb9..de35ac4c8d4 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift @@ -29,7 +29,7 @@ let buildableNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { for node in SYNTAX_NODES.compactMap(\.layoutNode) { let type = node.type - if let convenienceInit = try! node.createConvenienceBuilderInitializer() { + if let convenienceInit = try! InitSignature(node).createConvenienceBuilderInitializer() { DeclSyntax( """ extension \(type.syntaxBaseName) { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift index 6fa8f8b5921..641d51fd2be 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift @@ -27,7 +27,9 @@ let renamedChildrenBuilderCompatibilityFile = try! SourceFileSyntax(leadingTrivi ) for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ $0.children.hasDeprecatedChild }) { - if let convenienceInit = try layoutNode.createConvenienceBuilderInitializer(useDeprecatedChildName: true) { + if let convenienceInit = try InitSignature(layoutNode).createConvenienceBuilderInitializer( + useDeprecatedChildName: true + ) { let deprecatedNames = layoutNode.children .filter { !$0.isUnexpectedNodes && $0.hasDeprecatedName } .compactMap { $0.identifier.description } diff --git a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift index d0bf6ef9322..1ba94a98dcb 100644 --- a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift @@ -63,7 +63,7 @@ extension AccessorDeclSyntax { } } - @available(*, deprecated, renamed: "AccessorDeclSyntax(leadingTrivia:_:attributes:_:modifier:_:accessorSpecifier:_:parameters:_:effectSpecifiers:_:body:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifier:_:accessorSpecifier:_:parameters:_:effectSpecifiers:_:body:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -133,7 +133,7 @@ extension ActorDeclSyntax { } } - @available(*, deprecated, renamed: "ActorDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:actorKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:actorKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -241,7 +241,7 @@ extension ArrayExprSyntax { } } - @available(*, deprecated, renamed: "ArrayExprSyntax(leadingTrivia:_:leftSquare:_:elements:_:rightSquare:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftSquare:_:elements:_:rightSquare:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -339,7 +339,7 @@ extension ArrayTypeSyntax { } } - @available(*, deprecated, renamed: "ArrayTypeSyntax(leadingTrivia:_:leftSquare:_:element:_:rightSquare:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftSquare:_:element:_:rightSquare:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -397,7 +397,7 @@ extension ArrowExprSyntax { } } - @available(*, deprecated, renamed: "ArrowExprSyntax(leadingTrivia:_:effectSpecifiers:_:arrow:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:effectSpecifiers:_:arrow:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -481,7 +481,7 @@ extension AsExprSyntax { } } - @available(*, deprecated, renamed: "AsExprSyntax(leadingTrivia:_:expression:_:asKeyword:_:questionOrExclamationMark:_:type:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:expression:_:asKeyword:_:questionOrExclamationMark:_:type:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -543,7 +543,7 @@ extension AssignmentExprSyntax { } } - @available(*, deprecated, renamed: "AssignmentExprSyntax(leadingTrivia:_:equal:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:equal:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -593,7 +593,7 @@ extension AssociatedTypeDeclSyntax { } } - @available(*, deprecated, renamed: "AssociatedTypeDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:associatedtypeKeyword:_:name:_:inheritanceClause:_:initializer:_:genericWhereClause:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:associatedtypeKeyword:_:name:_:inheritanceClause:_:initializer:_:genericWhereClause:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -697,7 +697,7 @@ extension AttributeSyntax { } } - @available(*, deprecated, renamed: "AttributeSyntax(leadingTrivia:_:atSign:_:attributeName:_:leftParen:_:arguments:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:atSign:_:attributeName:_:leftParen:_:arguments:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -763,7 +763,7 @@ extension AvailabilityArgumentSyntax { } } - @available(*, deprecated, renamed: "AvailabilityArgumentSyntax(leadingTrivia:_:argument:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:argument:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -817,7 +817,7 @@ extension AvailabilityConditionSyntax { } } - @available(*, deprecated, renamed: "AvailabilityConditionSyntax(leadingTrivia:_:availabilityKeyword:_:leftParen:_:availabilityArguments:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:availabilityKeyword:_:leftParen:_:availabilityArguments:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -870,7 +870,7 @@ extension BackDeployedAttributeArgumentsSyntax { } @available(*, deprecated, renamed: "addPlatform") - public func addAvailability(_ element: PlatformVersionItemSyntax) -> BackDeployedAttributeArgumentsSyntax { + public func addAvailability(_ element: PlatformVersionItemSyntax) -> Self { return addPlatform(element) } @@ -884,7 +884,7 @@ extension BackDeployedAttributeArgumentsSyntax { } } - @available(*, deprecated, renamed: "BackDeployedAttributeArgumentsSyntax(leadingTrivia:_:beforeLabel:_:colon:_:platforms:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:beforeLabel:_:colon:_:platforms:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -942,7 +942,7 @@ extension BinaryOperatorExprSyntax { } } - @available(*, deprecated, renamed: "BinaryOperatorExprSyntax(leadingTrivia:_:operator:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:operator:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -992,7 +992,7 @@ extension BooleanLiteralExprSyntax { } } - @available(*, deprecated, renamed: "BooleanLiteralExprSyntax(leadingTrivia:_:literal:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:literal:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1042,7 +1042,7 @@ extension _CanImportVersionInfoSyntax { } } - @available(*, deprecated, renamed: "_CanImportVersionInfoSyntax(leadingTrivia:_:comma:_:label:_:colon:_:version:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:comma:_:label:_:colon:_:version:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1104,7 +1104,7 @@ extension ClassDeclSyntax { } } - @available(*, deprecated, renamed: "ClassDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:classKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:classKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1182,7 +1182,7 @@ extension ClosureParameterClauseSyntax { } } - @available(*, deprecated, renamed: "ClosureParameterClauseSyntax(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1290,7 +1290,7 @@ extension ClosureSignatureSyntax { } } - @available(*, deprecated, renamed: "ClosureSignatureSyntax(leadingTrivia:_:attributes:_:capture:_:parameterClause:_:effectSpecifiers:_:returnClause:_:inKeyword:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:capture:_:parameterClause:_:effectSpecifiers:_:returnClause:_:inKeyword:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1390,7 +1390,7 @@ extension ConformanceRequirementSyntax { } } - @available(*, deprecated, renamed: "ConformanceRequirementSyntax(leadingTrivia:_:leftType:_:colon:_:rightType:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftType:_:colon:_:rightType:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1448,7 +1448,7 @@ extension ConsumeExprSyntax { } } - @available(*, deprecated, renamed: "ConsumeExprSyntax(leadingTrivia:_:consumeKeyword:_:expression:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:consumeKeyword:_:expression:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1522,7 +1522,7 @@ extension DeclReferenceExprSyntax { } } - @available(*, deprecated, renamed: "DeclReferenceExprSyntax(leadingTrivia:_:baseName:_:argumentNames:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:baseName:_:argumentNames:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1606,7 +1606,7 @@ extension DerivativeAttributeArgumentsSyntax { } } - @available(*, deprecated, renamed: "DerivativeAttributeArgumentsSyntax(leadingTrivia:_:ofLabel:_:colon:_:originalDeclName:_:period:_:accessorSpecifier:_:comma:_:arguments:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:ofLabel:_:colon:_:originalDeclName:_:period:_:accessorSpecifier:_:comma:_:arguments:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1710,7 +1710,7 @@ extension DictionaryElementSyntax { } } - @available(*, deprecated, renamed: "DictionaryElementSyntax(leadingTrivia:_:key:_:colon:_:value:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:key:_:colon:_:value:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1842,7 +1842,7 @@ extension DictionaryTypeSyntax { } } - @available(*, deprecated, renamed: "DictionaryTypeSyntax(leadingTrivia:_:leftSquare:_:key:_:colon:_:value:_:rightSquare:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftSquare:_:key:_:colon:_:value:_:rightSquare:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1908,7 +1908,7 @@ extension DifferentiabilityArgumentSyntax { } } - @available(*, deprecated, renamed: "DifferentiabilityArgumentSyntax(leadingTrivia:_:argument:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:argument:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -1962,7 +1962,7 @@ extension DifferentiabilityArgumentsSyntax { } } - @available(*, deprecated, renamed: "DifferentiabilityArgumentsSyntax(leadingTrivia:_:leftParen:_:arguments:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:arguments:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2020,7 +2020,7 @@ extension DifferentiabilityWithRespectToArgumentSyntax { } } - @available(*, deprecated, renamed: "DifferentiabilityWithRespectToArgumentSyntax(leadingTrivia:_:wrtLabel:_:colon:_:arguments:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:wrtLabel:_:colon:_:arguments:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2158,7 +2158,7 @@ extension DifferentiableAttributeArgumentsSyntax { } } - @available(*, deprecated, renamed: "DifferentiableAttributeArgumentsSyntax(leadingTrivia:_:kindSpecifier:_:kindSpecifierComma:_:arguments:_:argumentsComma:_:genericWhereClause:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:kindSpecifier:_:kindSpecifierComma:_:arguments:_:argumentsComma:_:genericWhereClause:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2224,7 +2224,7 @@ extension DynamicReplacementAttributeArgumentsSyntax { } } - @available(*, deprecated, renamed: "DynamicReplacementAttributeArgumentsSyntax(leadingTrivia:_:forLabel:_:colon:_:declName:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:forLabel:_:colon:_:declName:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2282,7 +2282,7 @@ extension EditorPlaceholderDeclSyntax { } } - @available(*, deprecated, renamed: "EditorPlaceholderDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:placeholder:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:placeholder:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2340,7 +2340,7 @@ extension EditorPlaceholderExprSyntax { } } - @available(*, deprecated, renamed: "EditorPlaceholderExprSyntax(leadingTrivia:_:placeholder:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:placeholder:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2410,7 +2410,7 @@ extension EnumCaseElementSyntax { } } - @available(*, deprecated, renamed: "EnumCaseElementSyntax(leadingTrivia:_:name:_:parameterClause:_:rawValue:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:name:_:parameterClause:_:rawValue:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2472,7 +2472,7 @@ extension EnumCaseParameterClauseSyntax { } } - @available(*, deprecated, renamed: "EnumCaseParameterClauseSyntax(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2530,7 +2530,7 @@ extension EnumCaseParameterSyntax { } } - @available(*, deprecated, renamed: "EnumCaseParameterSyntax(leadingTrivia:_:modifiers:_:firstName:_:secondName:_:colon:_:type:_:defaultValue:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:modifiers:_:firstName:_:secondName:_:colon:_:type:_:defaultValue:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2624,7 +2624,7 @@ extension EnumDeclSyntax { } } - @available(*, deprecated, renamed: "EnumDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:enumKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:enumKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2702,7 +2702,7 @@ extension ExpressionSegmentSyntax { } } - @available(*, deprecated, renamed: "ExpressionSegmentSyntax(leadingTrivia:_:backslash:_:pounds:_:leftParen:_:expressions:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:backslash:_:pounds:_:leftParen:_:expressions:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2768,7 +2768,7 @@ extension FloatLiteralExprSyntax { } } - @available(*, deprecated, renamed: "FloatLiteralExprSyntax(leadingTrivia:_:literal:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:literal:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2818,7 +2818,7 @@ extension ForStmtSyntax { } } - @available(*, deprecated, renamed: "ForStmtSyntax(leadingTrivia:_:forKeyword:_:tryKeyword:_:awaitKeyword:_:caseKeyword:_:pattern:_:typeAnnotation:_:inKeyword:_:sequence:_:whereClause:_:body:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:forKeyword:_:tryKeyword:_:awaitKeyword:_:caseKeyword:_:pattern:_:typeAnnotation:_:inKeyword:_:sequence:_:whereClause:_:body:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2904,7 +2904,7 @@ extension FunctionCallExprSyntax { } } - @available(*, deprecated, renamed: "FunctionCallExprSyntax(leadingTrivia:_:calledExpression:_:leftParen:_:arguments:_:rightParen:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:calledExpression:_:leftParen:_:arguments:_:rightParen:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -2974,7 +2974,7 @@ extension FunctionDeclSyntax { } } - @available(*, deprecated, renamed: "FunctionDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:funcKeyword:_:name:_:genericParameterClause:_:signature:_:genericWhereClause:_:body:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:funcKeyword:_:name:_:genericParameterClause:_:signature:_:genericWhereClause:_:body:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3052,7 +3052,7 @@ extension FunctionParameterClauseSyntax { } } - @available(*, deprecated, renamed: "FunctionParameterClauseSyntax(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3110,7 +3110,7 @@ extension FunctionParameterSyntax { } } - @available(*, deprecated, renamed: "FunctionParameterSyntax(leadingTrivia:_:attributes:_:modifiers:_:firstName:_:secondName:_:colon:_:type:_:ellipsis:_:defaultValue:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:firstName:_:secondName:_:colon:_:type:_:ellipsis:_:defaultValue:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3222,7 +3222,7 @@ extension FunctionSignatureSyntax { } } - @available(*, deprecated, renamed: "FunctionSignatureSyntax(leadingTrivia:_:parameterClause:_:effectSpecifiers:_:returnClause:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:parameterClause:_:effectSpecifiers:_:returnClause:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3271,7 +3271,7 @@ extension FunctionTypeSyntax { } @available(*, deprecated, renamed: "addParameter") - public func addArgument(_ element: TupleTypeElementSyntax) -> FunctionTypeSyntax { + public func addArgument(_ element: TupleTypeElementSyntax) -> Self { return addParameter(element) } @@ -3315,7 +3315,7 @@ extension FunctionTypeSyntax { } } - @available(*, deprecated, renamed: "FunctionTypeSyntax(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:effectSpecifiers:_:returnClause:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:parameters:_:rightParen:_:effectSpecifiers:_:returnClause:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3411,7 +3411,7 @@ extension GenericArgumentClauseSyntax { } } - @available(*, deprecated, renamed: "GenericArgumentClauseSyntax(leadingTrivia:_:leftAngle:_:arguments:_:rightAngle:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftAngle:_:arguments:_:rightAngle:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3469,7 +3469,7 @@ extension GenericArgumentSyntax { } } - @available(*, deprecated, renamed: "GenericArgumentSyntax(leadingTrivia:_:argument:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:argument:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3534,7 +3534,7 @@ extension GenericParameterClauseSyntax { } @available(*, deprecated, renamed: "addParameter") - public func addGenericParameter(_ element: GenericParameterSyntax) -> GenericParameterClauseSyntax { + public func addGenericParameter(_ element: GenericParameterSyntax) -> Self { return addParameter(element) } @@ -3578,7 +3578,7 @@ extension GenericParameterClauseSyntax { } } - @available(*, deprecated, renamed: "GenericParameterClauseSyntax(leadingTrivia:_:leftAngle:_:parameters:_:genericWhereClause:_:rightAngle:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftAngle:_:parameters:_:genericWhereClause:_:rightAngle:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3640,7 +3640,7 @@ extension GenericParameterSyntax { } } - @available(*, deprecated, renamed: "GenericParameterSyntax(leadingTrivia:_:attributes:_:specifier:_:name:_:colon:_:inheritedType:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:specifier:_:name:_:colon:_:inheritedType:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3710,7 +3710,7 @@ extension GenericRequirementSyntax { } } - @available(*, deprecated, renamed: "GenericRequirementSyntax(leadingTrivia:_:requirement:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:requirement:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3764,7 +3764,7 @@ extension GenericWhereClauseSyntax { } } - @available(*, deprecated, renamed: "GenericWhereClauseSyntax(leadingTrivia:_:whereKeyword:_:requirements:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:whereKeyword:_:requirements:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3818,7 +3818,7 @@ extension ImplementsAttributeArgumentsSyntax { } } - @available(*, deprecated, renamed: "ImplementsAttributeArgumentsSyntax(leadingTrivia:_:type:_:comma:_:declName:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:type:_:comma:_:declName:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3896,7 +3896,7 @@ extension ImportDeclSyntax { } } - @available(*, deprecated, renamed: "ImportDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:importKeyword:_:importKindSpecifier:_:path:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:importKeyword:_:importKindSpecifier:_:path:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -3962,7 +3962,7 @@ extension ImportPathComponentSyntax { } } - @available(*, deprecated, renamed: "ImportPathComponentSyntax(leadingTrivia:_:name:_:trailingPeriod:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:name:_:trailingPeriod:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4016,7 +4016,7 @@ extension InfixOperatorExprSyntax { } } - @available(*, deprecated, renamed: "InfixOperatorExprSyntax(leadingTrivia:_:leftOperand:_:operator:_:rightOperand:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftOperand:_:operator:_:rightOperand:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4074,7 +4074,7 @@ extension InheritanceClauseSyntax { } } - @available(*, deprecated, renamed: "InheritanceClauseSyntax(leadingTrivia:_:colon:_:inheritedTypes:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:colon:_:inheritedTypes:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4128,7 +4128,7 @@ extension InheritedTypeSyntax { } } - @available(*, deprecated, renamed: "InheritedTypeSyntax(leadingTrivia:_:type:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:type:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4182,7 +4182,7 @@ extension IntegerLiteralExprSyntax { } } - @available(*, deprecated, renamed: "IntegerLiteralExprSyntax(leadingTrivia:_:literal:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:literal:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4252,7 +4252,7 @@ extension IsExprSyntax { } } - @available(*, deprecated, renamed: "IsExprSyntax(leadingTrivia:_:expression:_:isKeyword:_:type:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:expression:_:isKeyword:_:type:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4350,7 +4350,7 @@ extension KeyPathSubscriptComponentSyntax { } } - @available(*, deprecated, renamed: "KeyPathSubscriptComponentSyntax(leadingTrivia:_:leftSquare:_:arguments:_:rightSquare:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftSquare:_:arguments:_:rightSquare:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4428,7 +4428,7 @@ extension LabeledStmtSyntax { } } - @available(*, deprecated, renamed: "LabeledStmtSyntax(leadingTrivia:_:label:_:colon:_:statement:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:label:_:colon:_:statement:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4516,7 +4516,7 @@ extension LayoutRequirementSyntax { } } - @available(*, deprecated, renamed: "LayoutRequirementSyntax(leadingTrivia:_:type:_:colon:_:layoutSpecifier:_:leftParen:_:size:_:comma:_:alignment:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:type:_:colon:_:layoutSpecifier:_:leftParen:_:size:_:comma:_:alignment:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4594,7 +4594,7 @@ extension MacroDeclSyntax { } } - @available(*, deprecated, renamed: "MacroDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:macroKeyword:_:name:_:genericParameterClause:_:signature:_:definition:_:genericWhereClause:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:macroKeyword:_:name:_:genericParameterClause:_:signature:_:definition:_:genericWhereClause:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4742,7 +4742,7 @@ extension MacroExpansionDeclSyntax { } } - @available(*, deprecated, renamed: "MacroExpansionDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:pound:_:macroName:_:genericArgumentClause:_:leftParen:_:arguments:_:rightParen:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:pound:_:macroName:_:genericArgumentClause:_:leftParen:_:arguments:_:rightParen:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4898,7 +4898,7 @@ extension MacroExpansionExprSyntax { } } - @available(*, deprecated, renamed: "MacroExpansionExprSyntax(leadingTrivia:_:pound:_:macroName:_:genericArgumentClause:_:leftParen:_:arguments:_:rightParen:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:pound:_:macroName:_:genericArgumentClause:_:leftParen:_:arguments:_:rightParen:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -4976,7 +4976,7 @@ extension MemberAccessExprSyntax { } } - @available(*, deprecated, renamed: "MemberAccessExprSyntax(leadingTrivia:_:base:_:period:_:declName:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:base:_:period:_:declName:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5034,7 +5034,7 @@ extension MetatypeTypeSyntax { } } - @available(*, deprecated, renamed: "MetatypeTypeSyntax(leadingTrivia:_:baseType:_:period:_:metatypeSpecifier:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:baseType:_:period:_:metatypeSpecifier:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5112,7 +5112,7 @@ extension NamedOpaqueReturnTypeSyntax { } } - @available(*, deprecated, renamed: "NamedOpaqueReturnTypeSyntax(leadingTrivia:_:genericParameterClause:_:type:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:genericParameterClause:_:type:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5196,7 +5196,7 @@ extension OperatorDeclSyntax { } } - @available(*, deprecated, renamed: "OperatorDeclSyntax(leadingTrivia:_:fixitySpecifier:_:operatorKeyword:_:name:_:operatorPrecedenceAndTypes:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:fixitySpecifier:_:operatorKeyword:_:name:_:operatorPrecedenceAndTypes:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5258,7 +5258,7 @@ extension OptionalBindingConditionSyntax { } } - @available(*, deprecated, renamed: "OptionalBindingConditionSyntax(leadingTrivia:_:bindingSpecifier:_:pattern:_:typeAnnotation:_:initializer:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:bindingSpecifier:_:pattern:_:typeAnnotation:_:initializer:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5320,7 +5320,7 @@ extension PackElementExprSyntax { } } - @available(*, deprecated, renamed: "PackElementExprSyntax(leadingTrivia:_:eachKeyword:_:pack:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:eachKeyword:_:pack:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5374,7 +5374,7 @@ extension PackElementTypeSyntax { } } - @available(*, deprecated, renamed: "PackElementTypeSyntax(leadingTrivia:_:eachKeyword:_:pack:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:eachKeyword:_:pack:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5428,7 +5428,7 @@ extension PackExpansionExprSyntax { } } - @available(*, deprecated, renamed: "PackExpansionExprSyntax(leadingTrivia:_:repeatKeyword:_:repetitionPattern:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:repeatKeyword:_:repetitionPattern:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5482,7 +5482,7 @@ extension PackExpansionTypeSyntax { } } - @available(*, deprecated, renamed: "PackExpansionTypeSyntax(leadingTrivia:_:repeatKeyword:_:repetitionPattern:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:repeatKeyword:_:repetitionPattern:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5536,7 +5536,7 @@ extension PatternBindingSyntax { } } - @available(*, deprecated, renamed: "PatternBindingSyntax(leadingTrivia:_:pattern:_:typeAnnotation:_:initializer:_:accessorBlock:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:pattern:_:typeAnnotation:_:initializer:_:accessorBlock:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5602,7 +5602,7 @@ extension PlatformVersionItemSyntax { } } - @available(*, deprecated, renamed: "PlatformVersionItemSyntax(leadingTrivia:_:platformVersion:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:platformVersion:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5656,7 +5656,7 @@ extension PostfixOperatorExprSyntax { } } - @available(*, deprecated, renamed: "PostfixOperatorExprSyntax(leadingTrivia:_:expression:_:operator:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:expression:_:operator:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5780,7 +5780,7 @@ extension PoundSourceLocationArgumentsSyntax { } } - @available(*, deprecated, renamed: "PoundSourceLocationArgumentsSyntax(leadingTrivia:_:fileLabel:_:fileColon:_:fileName:_:comma:_:lineLabel:_:lineColon:_:lineNumber:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:fileLabel:_:fileColon:_:fileName:_:comma:_:lineLabel:_:lineColon:_:lineNumber:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5854,7 +5854,7 @@ extension PoundSourceLocationSyntax { } } - @available(*, deprecated, renamed: "PoundSourceLocationSyntax(leadingTrivia:_:poundSourceLocation:_:leftParen:_:arguments:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:poundSourceLocation:_:leftParen:_:arguments:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -5946,7 +5946,7 @@ extension PrecedenceGroupAssignmentSyntax { } } - @available(*, deprecated, renamed: "PrecedenceGroupAssignmentSyntax(leadingTrivia:_:assignmentLabel:_:colon:_:value:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:assignmentLabel:_:colon:_:value:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6004,7 +6004,7 @@ extension PrecedenceGroupAssociativitySyntax { } } - @available(*, deprecated, renamed: "PrecedenceGroupAssociativitySyntax(leadingTrivia:_:associativityLabel:_:colon:_:value:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:associativityLabel:_:colon:_:value:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6062,7 +6062,7 @@ extension PrecedenceGroupDeclSyntax { } } - @available(*, deprecated, renamed: "PrecedenceGroupDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:precedencegroupKeyword:_:name:_:leftBrace:_:groupAttributes:_:rightBrace:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:precedencegroupKeyword:_:name:_:leftBrace:_:groupAttributes:_:rightBrace:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6166,7 +6166,7 @@ extension PrecedenceGroupRelationSyntax { } } - @available(*, deprecated, renamed: "PrecedenceGroupRelationSyntax(leadingTrivia:_:higherThanOrLowerThanLabel:_:colon:_:precedenceGroups:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:higherThanOrLowerThanLabel:_:colon:_:precedenceGroups:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6244,7 +6244,7 @@ extension PrefixOperatorExprSyntax { } } - @available(*, deprecated, renamed: "PrefixOperatorExprSyntax(leadingTrivia:_:operator:_:expression:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:operator:_:expression:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6338,7 +6338,7 @@ extension PrimaryAssociatedTypeClauseSyntax { } } - @available(*, deprecated, renamed: "PrimaryAssociatedTypeClauseSyntax(leadingTrivia:_:leftAngle:_:primaryAssociatedTypes:_:rightAngle:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftAngle:_:primaryAssociatedTypes:_:rightAngle:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6396,7 +6396,7 @@ extension ProtocolDeclSyntax { } } - @available(*, deprecated, renamed: "ProtocolDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:protocolKeyword:_:name:_:primaryAssociatedTypeClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:protocolKeyword:_:name:_:primaryAssociatedTypeClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6514,7 +6514,7 @@ extension RegexLiteralExprSyntax { } } - @available(*, deprecated, renamed: "RegexLiteralExprSyntax(leadingTrivia:_:openingPounds:_:openingSlash:_:regex:_:closingSlash:_:closingPounds:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:openingPounds:_:openingSlash:_:regex:_:closingSlash:_:closingPounds:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6580,7 +6580,7 @@ extension ReturnClauseSyntax { } } - @available(*, deprecated, renamed: "ReturnClauseSyntax(leadingTrivia:_:arrow:_:type:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:arrow:_:type:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6674,7 +6674,7 @@ extension SameTypeRequirementSyntax { } } - @available(*, deprecated, renamed: "SameTypeRequirementSyntax(leadingTrivia:_:leftType:_:equal:_:rightType:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftType:_:equal:_:rightType:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6732,7 +6732,7 @@ extension SomeOrAnyTypeSyntax { } } - @available(*, deprecated, renamed: "SomeOrAnyTypeSyntax(leadingTrivia:_:someOrAnySpecifier:_:constraint:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:someOrAnySpecifier:_:constraint:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6786,7 +6786,7 @@ extension SourceFileSyntax { } } - @available(*, deprecated, renamed: "SourceFileSyntax(leadingTrivia:_:shebang:_:statements:_:endOfFileToken:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:shebang:_:statements:_:endOfFileToken:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6865,7 +6865,7 @@ extension SpecializeAvailabilityArgumentSyntax { } @available(*, deprecated, renamed: "addAvailabilityArgument") - public func addAvailability(_ element: AvailabilityArgumentSyntax) -> SpecializeAvailabilityArgumentSyntax { + public func addAvailability(_ element: AvailabilityArgumentSyntax) -> Self { return addAvailabilityArgument(element) } @@ -6879,7 +6879,7 @@ extension SpecializeAvailabilityArgumentSyntax { } } - @available(*, deprecated, renamed: "SpecializeAvailabilityArgumentSyntax(leadingTrivia:_:availabilityLabel:_:colon:_:availabilityArguments:_:semicolon:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:availabilityLabel:_:colon:_:availabilityArguments:_:semicolon:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -6971,7 +6971,7 @@ extension SpecializeTargetFunctionArgumentSyntax { } } - @available(*, deprecated, renamed: "SpecializeTargetFunctionArgumentSyntax(leadingTrivia:_:targetLabel:_:colon:_:declName:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:targetLabel:_:colon:_:declName:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7103,7 +7103,7 @@ extension StringLiteralExprSyntax { } } - @available(*, deprecated, renamed: "StringLiteralExprSyntax(leadingTrivia:_:openingPounds:_:openingQuote:_:segments:_:closingQuote:_:closingPounds:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:openingPounds:_:openingQuote:_:segments:_:closingQuote:_:closingPounds:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7169,7 +7169,7 @@ extension StructDeclSyntax { } } - @available(*, deprecated, renamed: "StructDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:structKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:structKeyword:_:name:_:genericParameterClause:_:inheritanceClause:_:genericWhereClause:_:memberBlock:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7287,7 +7287,7 @@ extension SubscriptCallExprSyntax { } } - @available(*, deprecated, renamed: "SubscriptCallExprSyntax(leadingTrivia:_:calledExpression:_:leftSquare:_:arguments:_:rightSquare:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:calledExpression:_:leftSquare:_:arguments:_:rightSquare:_:trailingClosure:_:additionalTrailingClosures:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7407,7 +7407,7 @@ extension SubscriptDeclSyntax { } } - @available(*, deprecated, renamed: "SubscriptDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:subscriptKeyword:_:genericParameterClause:_:parameterClause:_:returnClause:_:genericWhereClause:_:accessorBlock:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:subscriptKeyword:_:genericParameterClause:_:parameterClause:_:returnClause:_:genericWhereClause:_:accessorBlock:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7485,7 +7485,7 @@ extension SuppressedTypeSyntax { } } - @available(*, deprecated, renamed: "SuppressedTypeSyntax(leadingTrivia:_:withoutTilde:_:type:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:withoutTilde:_:type:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7539,7 +7539,7 @@ extension SwitchCaseSyntax { } } - @available(*, deprecated, renamed: "SwitchCaseSyntax(leadingTrivia:_:attribute:_:label:_:statements:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attribute:_:label:_:statements:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7597,7 +7597,7 @@ extension SwitchExprSyntax { } } - @available(*, deprecated, renamed: "SwitchExprSyntax(leadingTrivia:_:switchKeyword:_:subject:_:leftBrace:_:cases:_:rightBrace:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:switchKeyword:_:subject:_:leftBrace:_:cases:_:rightBrace:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7733,7 +7733,7 @@ extension TernaryExprSyntax { } } - @available(*, deprecated, renamed: "TernaryExprSyntax(leadingTrivia:_:condition:_:questionMark:_:thenExpression:_:colon:_:elseExpression:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:condition:_:questionMark:_:thenExpression:_:colon:_:elseExpression:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7799,7 +7799,7 @@ extension TupleExprSyntax { } } - @available(*, deprecated, renamed: "TupleExprSyntax(leadingTrivia:_:leftParen:_:elements:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:elements:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7877,7 +7877,7 @@ extension TuplePatternElementSyntax { } } - @available(*, deprecated, renamed: "TuplePatternElementSyntax(leadingTrivia:_:label:_:colon:_:pattern:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:label:_:colon:_:pattern:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -7959,7 +7959,7 @@ extension TupleTypeElementSyntax { } } - @available(*, deprecated, renamed: "TupleTypeElementSyntax(leadingTrivia:_:inoutKeyword:_:firstName:_:secondName:_:colon:_:type:_:ellipsis:_:trailingComma:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:inoutKeyword:_:firstName:_:secondName:_:colon:_:type:_:ellipsis:_:trailingComma:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8033,7 +8033,7 @@ extension TypeAliasDeclSyntax { } } - @available(*, deprecated, renamed: "TypeAliasDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:typealiasKeyword:_:name:_:genericParameterClause:_:initializer:_:genericWhereClause:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:typealiasKeyword:_:name:_:genericParameterClause:_:initializer:_:genericWhereClause:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8107,7 +8107,7 @@ extension UnresolvedAsExprSyntax { } } - @available(*, deprecated, renamed: "UnresolvedAsExprSyntax(leadingTrivia:_:asKeyword:_:questionOrExclamationMark:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:asKeyword:_:questionOrExclamationMark:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8161,7 +8161,7 @@ extension UnresolvedIsExprSyntax { } } - @available(*, deprecated, renamed: "UnresolvedIsExprSyntax(leadingTrivia:_:isKeyword:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:isKeyword:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8231,7 +8231,7 @@ extension UnresolvedTernaryExprSyntax { } } - @available(*, deprecated, renamed: "UnresolvedTernaryExprSyntax(leadingTrivia:_:questionMark:_:thenExpression:_:colon:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:questionMark:_:thenExpression:_:colon:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8309,7 +8309,7 @@ extension ValueBindingPatternSyntax { } } - @available(*, deprecated, renamed: "ValueBindingPatternSyntax(leadingTrivia:_:bindingSpecifier:_:pattern:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:bindingSpecifier:_:pattern:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8363,7 +8363,7 @@ extension VariableDeclSyntax { } } - @available(*, deprecated, renamed: "VariableDeclSyntax(leadingTrivia:_:attributes:_:modifiers:_:bindingSpecifier:_:bindings:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:attributes:_:modifiers:_:bindingSpecifier:_:bindings:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8425,7 +8425,7 @@ extension WhereClauseSyntax { } } - @available(*, deprecated, renamed: "WhereClauseSyntax(leadingTrivia:_:whereKeyword:_:condition:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:whereKeyword:_:condition:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8479,7 +8479,7 @@ extension YieldStmtSyntax { } } - @available(*, deprecated, renamed: "YieldStmtSyntax(leadingTrivia:_:yieldKeyword:_:yieldedExpressions:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:yieldKeyword:_:yieldedExpressions:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, @@ -8533,7 +8533,7 @@ extension YieldedExpressionsClauseSyntax { } } - @available(*, deprecated, renamed: "YieldedExpressionsClauseSyntax(leadingTrivia:_:leftParen:_:elements:_:rightParen:_:trailingTrivia:)") + @available(*, deprecated, renamed: "init(leadingTrivia:_:leftParen:_:elements:_:rightParen:_:trailingTrivia:)") @_disfavoredOverload public init( leadingTrivia: Trivia? = nil, From ced0712e22b2929d9635ede719858be9e56b5d3b Mon Sep 17 00:00:00 2001 From: Becca Royal-Gordon Date: Mon, 4 Nov 2024 18:06:42 -0800 Subject: [PATCH 2/4] [NFC-ish] Factor out CompatibilityLayer A new CompatibilityLayer type computes information about deprecated vars and inits, presenting it in a new way: by creating additional `Child` objects with the deprecated information, plus sufficient info to map it back to the current name. This causes minor non-functional changes to the bodies of compatibility builder inits, but otherwise has no real effect in this commit. However, this new setup with separate `Child` nodes for deprecated children and a global table of information about them prepares us for further changes. --- .../Sources/SyntaxSupport/Child.swift | 93 +++++++++-- .../SyntaxSupport/CompatibilityLayer.swift | 132 +++++++++++++++ .../Sources/SyntaxSupport/Node.swift | 64 ++----- .../Sources/SyntaxSupport/SyntaxNodes.swift | 2 + .../InitSignature+Extensions.swift | 158 +++++++++++++----- .../RenamedChildrenCompatibilityFile.swift | 33 ++-- ...amedChildrenBuilderCompatibilityFile.swift | 34 ++-- .../RenamedChildrenBuilderCompatibility.swift | 82 ++++----- 8 files changed, 413 insertions(+), 185 deletions(-) create mode 100644 CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift diff --git a/CodeGeneration/Sources/SyntaxSupport/Child.swift b/CodeGeneration/Sources/SyntaxSupport/Child.swift index d893117a399..db4328cf821 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Child.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Child.swift @@ -150,7 +150,7 @@ public class Child: NodeChoiceConvertible { /// For any other kind of child nodes, accessing this property crashes. public var syntaxChoicesType: TypeSyntax { precondition(kind.isNodeChoices, "Cannot get `syntaxChoicesType` for node that doesn’t have nodeChoices") - return "\(raw: name.withFirstCharacterUppercased)" + return "\(raw: newestName.withFirstCharacterUppercased)" } /// If this child only has tokens, the type that the generated `TokenSpecSet` should get. @@ -158,15 +158,7 @@ public class Child: NodeChoiceConvertible { /// For any other kind of child nodes, accessing this property crashes. public var tokenSpecSetType: TypeSyntax { precondition(kind.isToken, "Cannot get `tokenSpecSetType` for node that isn’t a token") - return "\(raw: name.withFirstCharacterUppercased)Options" - } - - /// The deprecated name of this child that's suitable to be used for variable or enum case names. - public var deprecatedVarName: TokenSyntax? { - guard let deprecatedName = deprecatedName else { - return nil - } - return .identifier(lowercaseFirstWord(name: deprecatedName)) + return "\(raw: newestName.withFirstCharacterUppercased)Options" } /// Determines if this child has a deprecated name @@ -174,6 +166,27 @@ public class Child: NodeChoiceConvertible { return deprecatedName != nil } + /// If this child is actually part of another child's history, links back + /// to the newest (that is, most current/non-deprecated) version of the + /// child. Nil if this is the newest version of the child. + public let newestChild: Child? + + /// True if this child was created by a `Child.Refactoring`. Such children + /// are part of the compatibility layer and are therefore deprecated. + public var isHistorical: Bool { + newestChild != nil + } + + /// Replaces the nodes in `newerChildPath` with their own `newerChildPath`s, + /// if any, to form a child path enitrely of non-historical nodes. + static private func makeNewestChild(from newerChild: Child?) -> Child? { + return newerChild?.newestChild ?? newerChild + } + + private var newestName: String { + return newestChild?.name ?? name + } + /// If the child ends with "token" in the kind, it's considered a token node. /// Grab the existing reference to that token from the global list. public var tokenKind: Token? { @@ -244,11 +257,6 @@ public class Child: NodeChoiceConvertible { return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .newline) } - /// If a classification is passed, it specifies the color identifiers in - /// that subtree should inherit for syntax coloring. Must be a member of - /// ``SyntaxClassification``. - /// If `forceClassification` is also set to true, all child nodes (not only - /// identifiers) inherit the syntax classification. init( name: String, deprecatedName: String? = nil, @@ -256,7 +264,8 @@ public class Child: NodeChoiceConvertible { experimentalFeature: ExperimentalFeature? = nil, nameForDiagnostics: String? = nil, documentation: String? = nil, - isOptional: Bool = false + isOptional: Bool = false, + newerChild: Child? = nil ) { precondition(name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase") precondition( @@ -265,6 +274,7 @@ public class Child: NodeChoiceConvertible { ) self.name = name self.deprecatedName = deprecatedName + self.newestChild = Self.makeNewestChild(from: newerChild) self.kind = kind self.experimentalFeature = experimentalFeature self.nameForDiagnostics = nameForDiagnostics @@ -272,4 +282,55 @@ public class Child: NodeChoiceConvertible { self.documentationAbstract = String(documentation?.split(whereSeparator: \.isNewline).first ?? "") self.isOptional = isOptional } + + /// Create a node that is a copy of the last node in `newerChildPath`, but + /// with modifications. + init(renamingTo replacementName: String? = nil, newerChild other: Child) { + self.name = replacementName ?? other.name + self.deprecatedName = nil + self.newestChild = Self.makeNewestChild(from: other) + self.kind = other.kind + self.experimentalFeature = other.experimentalFeature + self.nameForDiagnostics = other.nameForDiagnostics + self.documentationSummary = other.documentationSummary + self.documentationAbstract = other.documentationAbstract + self.isOptional = other.isOptional + } + + /// Create a child for the unexpected nodes between two children (either or + /// both of which may be `nil`). + convenience init(forUnexpectedBetween earlier: Child?, and later: Child?, newerChild: Child? = nil) { + let name = + switch (earlier, later) { + case (nil, let later?): + "unexpectedBefore\(later.name.withFirstCharacterUppercased)" + case (let earlier?, nil): + "unexpectedAfter\(earlier.name.withFirstCharacterUppercased)" + case (let earlier?, let later?): + "unexpectedBetween\(earlier.name.withFirstCharacterUppercased)And\(later.name.withFirstCharacterUppercased)" + case (nil, nil): + fatalError("unexpected node has no siblings?") + } + + self.init( + name: name, + deprecatedName: nil, // deprecation of unexpected nodes is handled in CompatibilityLayer + kind: .collection(kind: .unexpectedNodes, collectionElementName: name.withFirstCharacterUppercased), + experimentalFeature: earlier?.experimentalFeature ?? later?.experimentalFeature, + nameForDiagnostics: nil, + documentation: nil, + isOptional: true, + newerChild: newerChild + ) + } +} + +extension Child: Hashable { + public static func == (lhs: Child, rhs: Child) -> Bool { + lhs === rhs + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(ObjectIdentifier(self)) + } } diff --git a/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift b/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift new file mode 100644 index 00000000000..abfd0950392 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +/// Computes and caches information about properties and initializers that ought to be generated for the compatibility layer. +public struct CompatibilityLayer { + /// Deprecated members that the compatibility layer needs for each node. + private var deprecatedMembersByNode: [SyntaxNodeKind: DeprecatedMemberInfo] = [:] + + /// Cache for `replacementChild(for:)`. Ensures that we don't create two different replacement children even + /// if we refactor the same child twice, so we can reliably equate and hash `Child` objects by object identity. + private var cachedReplacementChildren: [Child: Child?] = [:] + + /// Returns the deprecated members that the compatibility layer needs for `node`. + public func deprecatedMembers(for node: LayoutNode) -> DeprecatedMemberInfo { + return deprecatedMembersByNode[node.kind] ?? DeprecatedMemberInfo() + } + + internal init(nodes: [Node]) { + // This instance will be stored in a global that's used from multiple threads simultaneously, so it won't be safe + // to mutate once the initializer returns. We therefore do all the work to populate its tables up front, rather + // than computing it lazily on demand. + for node in nodes { + computeMembers(for: node) + } + } + + private mutating func replacementChild(for newerChild: Child) -> Child? { + func make() -> Child? { + guard let deprecatedName = newerChild.deprecatedName else { + return nil + } + + return Child(renamingTo: deprecatedName, newerChild: newerChild) + } + + // Make sure we return the same instance even if we're called twice. + if cachedReplacementChildren[newerChild] == nil { + cachedReplacementChildren[newerChild] = make() + } + return cachedReplacementChildren[newerChild]! + } + + private mutating func computeMembers(for node: Node) { + guard deprecatedMembersByNode[node.syntaxNodeKind] == nil, let layoutNode = node.layoutNode else { + return + } + + // The results that will ultimately be saved into the DeprecatedMemberInfo. + var vars: [Child] = [] + var initSignatures: [InitSignature] = [] + + // Temporary working state. + var children = layoutNode.children + var knownVars = Set(children) + + func firstIndexOfChild(named targetName: String) -> Int { + guard let i = children.firstIndex(where: { $0.name == targetName }) else { + fatalError( + "couldn't find '\(targetName)' in current children of \(node.syntaxNodeKind.rawValue): \(String(reflecting: children.map(\.name)))" + ) + } + return i + } + + var unexpectedChildrenWithNewNames: Set = [] + + // First pass: Apply the changes explicitly specified in the change set. + for i in children.indices { + let currentName = children[i].name + guard let replacementChild = replacementChild(for: children[i]) else { + continue + } + children[i] = replacementChild + + // Mark adjacent unexpected node children whose names have changed too. + if currentName != replacementChild.name { + unexpectedChildrenWithNewNames.insert(children[i - 1]) + unexpectedChildrenWithNewNames.insert(children[i + 1]) + } + } + + // Second pass: Update unexpected node children adjacent to those changes whose names have probably changed. + for unexpectedChild in unexpectedChildrenWithNewNames { + precondition(unexpectedChild.isUnexpectedNodes) + let i = firstIndexOfChild(named: unexpectedChild.name) + + let earlier = children[checked: i - 1] + let later = children[checked: i + 1] + precondition(!(earlier?.isUnexpectedNodes ?? false) && !(later?.isUnexpectedNodes ?? false)) + + let newChild = Child(forUnexpectedBetween: earlier, and: later, newerChild: unexpectedChild) + precondition(newChild.name != unexpectedChild.name) + precondition(!children.contains { $0.name == newChild.name }) + + children[i] = newChild + } + + // Third pass: Append newly-created children to vars. We do this now so that changes from the first two passes are properly interleaved, preserving source order. + vars += children.filter { knownVars.insert($0).inserted } + + initSignatures.append(InitSignature(children: children)) + + deprecatedMembersByNode[node.syntaxNodeKind] = DeprecatedMemberInfo(vars: vars, inits: initSignatures) + } +} + +/// Describes the deprecated members of a given type that the compatibility layer ought to provide. +public struct DeprecatedMemberInfo { + /// Properties that are needed in the compatibility layer, in the order they ought to appear in the generated file. + public var vars: [Child] = [] + + /// Initializer signatures that are needed in the compatibility layer, in the order they ought to appear in the generated file. + public var inits: [InitSignature] = [] +} + +extension Array { + /// Returns `nil` if `i` is out of bounds, or the indicated element otherwise. + fileprivate subscript(checked i: Index) -> Element? { + get { + return indices.contains(i) ? self[i] : nil + } + } +} diff --git a/CodeGeneration/Sources/SyntaxSupport/Node.swift b/CodeGeneration/Sources/SyntaxSupport/Node.swift index 3205f0425f7..b9825edb08e 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Node.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Node.swift @@ -135,59 +135,8 @@ public class Node: NodeChoiceConvertible { self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) self.parserFunction = parserFunction - let childrenWithUnexpected: [Child] - if children.isEmpty { - childrenWithUnexpected = [ - Child( - name: "unexpected", - kind: .collection(kind: .unexpectedNodes, collectionElementName: "Unexpected"), - isOptional: true - ) - ] - } else { - // Add implicitly generated UnexpectedNodes children between - // any two defined children - childrenWithUnexpected = - children.enumerated().flatMap { (i, child) -> [Child] in - let childName = child.name.withFirstCharacterUppercased - - let unexpectedName: String - let unexpectedDeprecatedName: String? - - if i == 0 { - unexpectedName = "unexpectedBefore\(childName)" - unexpectedDeprecatedName = child.deprecatedName.map { "unexpectedBefore\($0.withFirstCharacterUppercased)" } - } else { - unexpectedName = "unexpectedBetween\(children[i - 1].name.withFirstCharacterUppercased)And\(childName)" - if let deprecatedName = children[i - 1].deprecatedName?.withFirstCharacterUppercased { - unexpectedDeprecatedName = - "unexpectedBetween\(deprecatedName)And\(child.deprecatedName?.withFirstCharacterUppercased ?? childName)" - } else if let deprecatedName = child.deprecatedName?.withFirstCharacterUppercased { - unexpectedDeprecatedName = - "unexpectedBetween\(children[i - 1].name.withFirstCharacterUppercased)And\(deprecatedName)" - } else { - unexpectedDeprecatedName = nil - } - } - let unexpectedBefore = Child( - name: unexpectedName, - deprecatedName: unexpectedDeprecatedName, - kind: .collection(kind: .unexpectedNodes, collectionElementName: unexpectedName), - isOptional: true - ) - return [unexpectedBefore, child] - } + [ - Child( - name: "unexpectedAfter\(children.last!.name.withFirstCharacterUppercased)", - deprecatedName: children.last!.deprecatedName.map { "unexpectedAfter\($0.withFirstCharacterUppercased)" }, - kind: .collection( - kind: .unexpectedNodes, - collectionElementName: "UnexpectedAfter\(children.last!.name.withFirstCharacterUppercased)" - ), - isOptional: true - ) - ] - } + let childrenWithUnexpected = kind.isBase ? children : interleaveUnexpectedChildren(children) + self.data = .layout(children: childrenWithUnexpected, traits: traits) } @@ -425,3 +374,12 @@ fileprivate extension Child { } } } + +fileprivate func interleaveUnexpectedChildren(_ children: [Child]) -> [Child] { + let liftedChildren = children.lazy.map(Optional.some) + let pairedChildren = zip([nil] + liftedChildren, liftedChildren + [nil]) + + return pairedChildren.flatMap { earlier, later in + [earlier, Child(forUnexpectedBetween: earlier, and: later)].compactMap { $0 } + } +} diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift index 3987c07cbfc..ee3a5c68fad 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift @@ -35,3 +35,5 @@ public let SYNTAX_NODE_MAP: [SyntaxNodeKind: Node] = Dictionary( ) public let NON_BASE_SYNTAX_NODES = SYNTAX_NODES.filter { !$0.kind.isBase } + +public let SYNTAX_COMPATIBILITY_LAYER = CompatibilityLayer(nodes: SYNTAX_NODES) diff --git a/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift b/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift index bc6a85563a9..287b987538b 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift @@ -28,7 +28,7 @@ extension InitSignature { return "init(leadingTrivia:\(renamedArguments)trailingTrivia:)" } - func generateInitializerDeclHeader(useDeprecatedChildName: Bool = false) -> SyntaxNodeString { + func generateInitializerDeclHeader() -> SyntaxNodeString { if children.isEmpty { return "public init()" } @@ -51,13 +51,7 @@ extension InitSignature { } } - let parameterName: TokenSyntax - - if useDeprecatedChildName, let deprecatedVarName = child.deprecatedVarName { - parameterName = deprecatedVarName - } else { - parameterName = child.labelDeclName - } + let parameterName = child.labelDeclName return FunctionParameterSyntax( leadingTrivia: .newline, @@ -108,7 +102,7 @@ extension InitSignature { } /// Create a builder-based convenience initializer, if needed. - func createConvenienceBuilderInitializer(useDeprecatedChildName: Bool = false) throws -> InitializerDeclSyntax? { + func createConvenienceBuilderInitializer() throws -> InitializerDeclSyntax? { // Only create the convenience initializer if at least one parameter // is different than in the default initializer generated above. var shouldCreateInitializer = false @@ -123,13 +117,7 @@ extension InitSignature { for child in children { /// The expression that is used to call the default initializer defined above. let produceExpr: ExprSyntax - let childName: TokenSyntax - - if useDeprecatedChildName, let deprecatedVarName = child.deprecatedVarName { - childName = deprecatedVarName - } else { - childName = child.identifier - } + let childName = child.identifier if child.buildableType.isBuilderInitializable { // Allow initializing certain syntax collections with result builders @@ -155,10 +143,7 @@ extension InitSignature { ) ) } else { - produceExpr = convertFromSyntaxProtocolToSyntaxType( - child: child, - useDeprecatedChildName: useDeprecatedChildName - ) + produceExpr = convertFromSyntaxProtocolToSyntaxType(child: child) normalParameters.append( FunctionParameterSyntax( firstName: childName.nonVarCallNameOrLabelDeclName, @@ -207,15 +192,9 @@ extension InitSignature { } fileprivate func convertFromSyntaxProtocolToSyntaxType( - child: Child, - useDeprecatedChildName: Bool = false + child: Child ) -> ExprSyntax { - let childName: TokenSyntax - if useDeprecatedChildName, let deprecatedVarName = child.deprecatedVarName { - childName = deprecatedVarName - } else { - childName = child.identifier - } + let childName = child.identifier if child.buildableType.isBaseType && !child.kind.isNodeChoices { return ExprSyntax("\(child.buildableType.syntaxBaseName)(fromProtocol: \(childName.declNameOrVarCallName))") @@ -224,29 +203,116 @@ fileprivate func convertFromSyntaxProtocolToSyntaxType( } extension InitSignature { - /// Generates arguments to pass this initializer's parameters through to the - /// non-deprecated initializer. This will generate nested initializer calls for + /// Interprets `self` as an initializer parameter list and generates arguments to + /// call the non-deprecated initializer. This will generate nested initializer calls for /// any children with a compound `newerChildPath`. func makeArgumentsToInitializeNewestChildren() -> [LabeledExprSyntax] { - return children.map { child in - let deprecatedName: TokenSyntax + var root: [InitParameterMapping] = [] - if let deprecatedVarName = child.deprecatedVarName { - deprecatedName = deprecatedVarName - } else { - deprecatedName = child.varDeclName - } + for child in children { + InitParameterMapping.addChild(child, to: &root) + } + + return root.map { $0.makeArgumentExpr() } + } +} - let argValue = ExprSyntax(DeclReferenceExprSyntax(baseName: deprecatedName)) +/// Represents the means by which a newest child, possibly at a nested position, is created from +/// one or more historical children. +/// +/// For example, consider a couple of nodes with some child history: +/// ``` +/// Node( +/// kind: .nestedNodeExtractedLater, +/// children: [ +/// Child(name: "x", ...), +/// Child(name: "y", ...), +/// ] +/// ), +/// Node( +/// kind: .longstandingNode, +/// children: [ +/// Child(name: "a", ...), +/// Child(name: "nested", kind: .node(.nestedNodeExtractedLater), ...), +/// ], +/// childHistory: [ +/// [ +/// "a": .renamed(from: "b"), +/// "nested": .extracted +/// ] +/// ] +/// ) +/// ``` +/// +/// These will end up being represented by `InitParameterMapping`s that look something like +/// this (with string literals standing in for the object references): +/// +/// ```swift +/// [ +/// InitParameterMapping( +/// newerChild: "child for current LongstandingNode.a", +/// argument: .decl("child for historical LongstandingNode.b") +/// ), +/// InitParameterMapping( +/// newerChild: "child for current LongstandingNode.nested", +/// argument: .nestedInit( +/// [ +/// InitParameterMapping( +/// newerChild: "child for current NestedNodeExtractedLater.x", +/// argument: .decl("child for historical LongstandingNode.x") +/// ), +/// InitParameterMapping( +/// newerChild: "child for current NestedNodeExtractedLater.y", +/// argument: .decl("child for historical LongstandingNode.y") +/// ) +/// ] +/// ) +/// ) +/// ] +/// ``` +/// +/// Which matches the structure of the `self.init` arguments we must generate to call from the +/// compatibility `LongstandingNodeSyntax.init(b:x:y:)` to the current +/// `LongstandingNodeSyntax.init(a:nested:)`: +/// +/// ```swift +/// self.init( +/// a: b, +/// nested: NestedNodeExtractedLaterSyntax( +/// x: x, +/// y: y +/// ) +/// ) +/// ``` +private struct InitParameterMapping { + var newerChild: Child + var argument: Argument - if child.isUnexpectedNodes { - return LabeledExprSyntax(expression: argValue) - } - return LabeledExprSyntax( - label: child.labelDeclName, - colon: .colonToken(), - expression: argValue + enum Argument { + case decl(olderChild: Child) + } + + static func addChild(_ olderChild: Child, to mappings: inout [InitParameterMapping]) { + mappings.append( + InitParameterMapping( + newerChild: olderChild.newestChild ?? olderChild, + argument: .decl(olderChild: olderChild) ) - } + ) + } +} + +extension InitParameterMapping { + func makeArgumentExpr() -> LabeledExprSyntax { + let argValue = + switch argument { + case .decl(olderChild: let olderChild): + ExprSyntax(DeclReferenceExprSyntax(baseName: olderChild.baseCallName)) + } + + return LabeledExprSyntax( + label: newerChild.isUnexpectedNodes ? nil : newerChild.name, + expression: argValue + ) } } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift index 532d212d02e..a5a38da365f 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift @@ -17,36 +17,43 @@ import Utils let renamedChildrenCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copyrightHeader) { for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ $0.children.hasDeprecatedChild }) { + var deprecatedMembers = SYNTAX_COMPATIBILITY_LAYER.deprecatedMembers(for: layoutNode) + try ExtensionDeclSyntax("extension \(layoutNode.type.syntaxBaseName)") { - for child in layoutNode.children { - if let deprecatedVarName = child.deprecatedVarName { - makeCompatibilityVar(for: child, deprecatedVarName: deprecatedVarName) - if let addMethod = makeCompatibilityAddMethod(for: child) { - addMethod - } + for child in deprecatedMembers.vars { + makeCompatibilityVar(for: child) + if let addMethod = makeCompatibilityAddMethod(for: child) { + addMethod } } let renamedName = InitSignature(layoutNode).compoundName - makeCompatibilityInit(for: InitSignature(layoutNode), renamedName: renamedName) + for signature in deprecatedMembers.inits { + makeCompatibilityInit(for: signature, renamedName: renamedName) + } } } } -func makeCompatibilityVar(for child: Child, deprecatedVarName: TokenSyntax) -> DeclSyntax { +func makeCompatibilityVar(for child: Child) -> DeclSyntax { let childType: TypeSyntax = child.kind.isNodeChoicesEmpty ? child.syntaxNodeKind.syntaxType : child.syntaxChoicesType let type = child.isOptional ? TypeSyntax("\(childType)?") : childType + // Form the access chain for the current name. + let childPath = child.newestChild ?? child + let childPathString = childPath.name + let childAccess = ExprSyntax(DeclReferenceExprSyntax(baseName: childPath.baseCallName)) + return DeclSyntax( """ - @available(*, deprecated, renamed: "\(child.identifier)") - public var \(deprecatedVarName): \(type) { + @available(*, deprecated, renamed: \(literal: childPathString)) + public var \(child.identifier): \(type) { get { - return \(child.baseCallName) + return \(childAccess) } set { - \(child.baseCallName) = newValue + \(childAccess) = newValue } } """ @@ -84,7 +91,7 @@ func makeCompatibilityInit(for signature: InitSignature, renamedName: String) -> """ @available(*, deprecated, renamed: \(literal: renamedName)) @_disfavoredOverload - \(signature.generateInitializerDeclHeader(useDeprecatedChildName: true)) + \(signature.generateInitializerDeclHeader()) """ ) { FunctionCallExprSyntax(callee: ExprSyntax("self.init")) { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift index 641d51fd2be..261118895d6 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift @@ -27,23 +27,25 @@ let renamedChildrenBuilderCompatibilityFile = try! SourceFileSyntax(leadingTrivi ) for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ $0.children.hasDeprecatedChild }) { - if let convenienceInit = try InitSignature(layoutNode).createConvenienceBuilderInitializer( - useDeprecatedChildName: true - ) { - let deprecatedNames = layoutNode.children - .filter { !$0.isUnexpectedNodes && $0.hasDeprecatedName } - .compactMap { $0.identifier.description } - .joined(separator: ", ") + let deprecatedMembers = SYNTAX_COMPATIBILITY_LAYER.deprecatedMembers(for: layoutNode) - DeclSyntax( - """ - extension \(layoutNode.type.syntaxBaseName) { - @available(*, deprecated, message: "Use an initializer with \(raw: deprecatedNames) argument(s).") - @_disfavoredOverload - \(convenienceInit) - } - """ - ) + for signature in deprecatedMembers.inits { + if let convenienceInit = try signature.createConvenienceBuilderInitializer() { + let deprecatedNames = layoutNode.children + .filter { !$0.isUnexpectedNodes && !signature.children.contains($0) } + .compactMap { $0.identifier.description } + .joined(separator: ", ") + + DeclSyntax( + """ + extension \(layoutNode.type.syntaxBaseName) { + @available(*, deprecated, message: "Use an initializer with \(raw: deprecatedNames) argument(s).") + @_disfavoredOverload + \(convenienceInit) + } + """ + ) + } } } } diff --git a/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift b/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift index aca9424c147..7cfa6227fb2 100644 --- a/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift +++ b/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift @@ -46,9 +46,9 @@ extension AccessorDeclSyntax { unexpectedBetweenAttributesAndModifier, modifier: modifier, unexpectedBetweenModifierAndAccessorKind, - accessorSpecifier: accessorKind, + accessorKind: accessorKind, unexpectedBetweenAccessorKindAndParameter, - parameters: parameter, + parameter: parameter, unexpectedBetweenParameterAndEffectSpecifiers, effectSpecifiers: effectSpecifiers, unexpectedBetweenEffectSpecifiersAndBody, @@ -95,7 +95,7 @@ extension ActorDeclSyntax { unexpectedBetweenModifiersAndActorKeyword, actorKeyword: actorKeyword, unexpectedBetweenActorKeywordAndIdentifier, - name: identifier, + identifier: identifier, unexpectedBetweenIdentifierAndGenericParameterClause, genericParameterClause: genericParameterClause, unexpectedBetweenGenericParameterClauseAndInheritanceClause, @@ -128,11 +128,11 @@ extension ArrayExprSyntax { try self.init( leadingTrivia: leadingTrivia, unexpectedBeforeLeftSquareBracket, - leftSquare: leftSquareBracket, + leftSquareBracket: leftSquareBracket, unexpectedBetweenLeftSquareBracketAndElements, elements: elementsBuilder(), unexpectedBetweenElementsAndRightSquareBracket, - rightSquare: rightSquareBracket, + rightSquareBracket: rightSquareBracket, unexpectedAfterRightSquareBracket, trailingTrivia: trailingTrivia ) @@ -173,7 +173,7 @@ extension ClassDeclSyntax { unexpectedBetweenModifiersAndClassKeyword, classKeyword: classKeyword, unexpectedBetweenClassKeywordAndIdentifier, - name: identifier, + identifier: identifier, unexpectedBetweenIdentifierAndGenericParameterClause, genericParameterClause: genericParameterClause, unexpectedBetweenGenericParameterClauseAndInheritanceClause, @@ -222,9 +222,9 @@ extension EnumDeclSyntax { unexpectedBetweenModifiersAndEnumKeyword, enumKeyword: enumKeyword, unexpectedBetweenEnumKeywordAndIdentifier, - name: identifier, + identifier: identifier, unexpectedBetweenIdentifierAndGenericParameters, - genericParameterClause: genericParameters, + genericParameters: genericParameters, unexpectedBetweenGenericParametersAndInheritanceClause, inheritanceClause: inheritanceClause, unexpectedBetweenInheritanceClauseAndGenericWhereClause, @@ -261,7 +261,7 @@ extension ExpressionSegmentSyntax { unexpectedBeforeBackslash, backslash: backslash, unexpectedBetweenBackslashAndDelimiter, - pounds: delimiter, + delimiter: delimiter, unexpectedBetweenDelimiterAndLeftParen, leftParen: leftParen, unexpectedBetweenLeftParenAndExpressions, @@ -320,7 +320,7 @@ extension ForStmtSyntax { unexpectedBetweenTypeAnnotationAndInKeyword, inKeyword: inKeyword, unexpectedBetweenInKeywordAndSequenceExpr, - sequence: ExprSyntax(fromProtocol: sequenceExpr), + sequenceExpr: ExprSyntax(fromProtocol: sequenceExpr), unexpectedBetweenSequenceExprAndWhereClause, whereClause: whereClause, unexpectedBetweenWhereClauseAndBody, @@ -359,7 +359,7 @@ extension FunctionCallExprSyntax { unexpectedBetweenCalledExpressionAndLeftParen, leftParen: leftParen, unexpectedBetweenLeftParenAndArgumentList, - arguments: argumentListBuilder(), + argumentList: argumentListBuilder(), unexpectedBetweenArgumentListAndRightParen, rightParen: rightParen, unexpectedBetweenRightParenAndTrailingClosure, @@ -406,7 +406,7 @@ extension FunctionDeclSyntax { unexpectedBetweenModifiersAndFuncKeyword, funcKeyword: funcKeyword, unexpectedBetweenFuncKeywordAndIdentifier, - name: identifier, + identifier: identifier, unexpectedBetweenIdentifierAndGenericParameterClause, genericParameterClause: genericParameterClause, unexpectedBetweenGenericParameterClauseAndSignature, @@ -443,7 +443,7 @@ extension FunctionParameterClauseSyntax { unexpectedBeforeLeftParen, leftParen: leftParen, unexpectedBetweenLeftParenAndParameterList, - parameters: parameterListBuilder(), + parameterList: parameterListBuilder(), unexpectedBetweenParameterListAndRightParen, rightParen: rightParen, unexpectedAfterRightParen, @@ -470,11 +470,11 @@ extension GenericArgumentClauseSyntax { try self.init( leadingTrivia: leadingTrivia, unexpectedBeforeLeftAngleBracket, - leftAngle: leftAngleBracket, + leftAngleBracket: leftAngleBracket, unexpectedBetweenLeftAngleBracketAndArguments, arguments: argumentsBuilder(), unexpectedBetweenArgumentsAndRightAngleBracket, - rightAngle: rightAngleBracket, + rightAngleBracket: rightAngleBracket, unexpectedAfterRightAngleBracket, trailingTrivia: trailingTrivia ) @@ -501,13 +501,13 @@ extension GenericParameterClauseSyntax { try self.init( leadingTrivia: leadingTrivia, unexpectedBeforeLeftAngleBracket, - leftAngle: leftAngleBracket, + leftAngleBracket: leftAngleBracket, unexpectedBetweenLeftAngleBracketAndGenericParameterList, - parameters: genericParameterListBuilder(), + genericParameterList: genericParameterListBuilder(), unexpectedBetweenGenericParameterListAndGenericWhereClause, genericWhereClause: genericWhereClause, unexpectedBetweenGenericWhereClauseAndRightAngleBracket, - rightAngle: rightAngleBracket, + rightAngleBracket: rightAngleBracket, unexpectedAfterRightAngleBracket, trailingTrivia: trailingTrivia ) @@ -532,7 +532,7 @@ extension GenericWhereClauseSyntax { unexpectedBeforeWhereKeyword, whereKeyword: whereKeyword, unexpectedBetweenWhereKeywordAndRequirementList, - requirements: requirementListBuilder(), + requirementList: requirementListBuilder(), unexpectedAfterRequirementList, trailingTrivia: trailingTrivia ) @@ -557,7 +557,7 @@ extension InheritanceClauseSyntax { unexpectedBeforeColon, colon: colon, unexpectedBetweenColonAndInheritedTypeCollection, - inheritedTypes: inheritedTypeCollectionBuilder(), + inheritedTypeCollection: inheritedTypeCollectionBuilder(), unexpectedAfterInheritedTypeCollection, trailingTrivia: trailingTrivia ) @@ -582,11 +582,11 @@ extension KeyPathSubscriptComponentSyntax { try self.init( leadingTrivia: leadingTrivia, unexpectedBeforeLeftBracket, - leftSquare: leftBracket, + leftBracket: leftBracket, unexpectedBetweenLeftBracketAndArgumentList, - arguments: argumentListBuilder(), + argumentList: argumentListBuilder(), unexpectedBetweenArgumentListAndRightBracket, - rightSquare: rightBracket, + rightBracket: rightBracket, unexpectedAfterRightBracket, trailingTrivia: trailingTrivia ) @@ -629,15 +629,15 @@ extension MacroExpansionDeclSyntax { unexpectedBetweenAttributesAndModifiers, modifiers: modifiers, unexpectedBetweenModifiersAndPoundToken, - pound: poundToken, + poundToken: poundToken, unexpectedBetweenPoundTokenAndMacro, - macroName: macro, + macro: macro, unexpectedBetweenMacroAndGenericArguments, - genericArgumentClause: genericArguments, + genericArguments: genericArguments, unexpectedBetweenGenericArgumentsAndLeftParen, leftParen: leftParen, unexpectedBetweenLeftParenAndArgumentList, - arguments: argumentListBuilder(), + argumentList: argumentListBuilder(), unexpectedBetweenArgumentListAndRightParen, rightParen: rightParen, unexpectedBetweenRightParenAndTrailingClosure, @@ -678,15 +678,15 @@ extension MacroExpansionExprSyntax { try self.init( leadingTrivia: leadingTrivia, unexpectedBeforePoundToken, - pound: poundToken, + poundToken: poundToken, unexpectedBetweenPoundTokenAndMacro, - macroName: macro, + macro: macro, unexpectedBetweenMacroAndGenericArguments, - genericArgumentClause: genericArguments, + genericArguments: genericArguments, unexpectedBetweenGenericArgumentsAndLeftParen, leftParen: leftParen, unexpectedBetweenLeftParenAndArgumentList, - arguments: argumentListBuilder(), + argumentList: argumentListBuilder(), unexpectedBetweenArgumentListAndRightParen, rightParen: rightParen, unexpectedBetweenRightParenAndTrailingClosure, @@ -733,7 +733,7 @@ extension ProtocolDeclSyntax { unexpectedBetweenModifiersAndProtocolKeyword, protocolKeyword: protocolKeyword, unexpectedBetweenProtocolKeywordAndIdentifier, - name: identifier, + identifier: identifier, unexpectedBetweenIdentifierAndPrimaryAssociatedTypeClause, primaryAssociatedTypeClause: primaryAssociatedTypeClause, unexpectedBetweenPrimaryAssociatedTypeClauseAndInheritanceClause, @@ -770,7 +770,7 @@ extension SourceFileSyntax { unexpectedBetweenShebangAndStatements, statements: statementsBuilder(), unexpectedBetweenStatementsAndEofToken, - endOfFileToken: eofToken, + eofToken: eofToken, unexpectedAfterEofToken, trailingTrivia: trailingTrivia ) @@ -811,7 +811,7 @@ extension StructDeclSyntax { unexpectedBetweenModifiersAndStructKeyword, structKeyword: structKeyword, unexpectedBetweenStructKeywordAndIdentifier, - name: identifier, + identifier: identifier, unexpectedBetweenIdentifierAndGenericParameterClause, genericParameterClause: genericParameterClause, unexpectedBetweenGenericParameterClauseAndInheritanceClause, @@ -852,11 +852,11 @@ extension SubscriptCallExprSyntax { unexpectedBeforeCalledExpression, calledExpression: ExprSyntax(fromProtocol: calledExpression), unexpectedBetweenCalledExpressionAndLeftBracket, - leftSquare: leftBracket, + leftBracket: leftBracket, unexpectedBetweenLeftBracketAndArgumentList, - arguments: argumentListBuilder(), + argumentList: argumentListBuilder(), unexpectedBetweenArgumentListAndRightBracket, - rightSquare: rightBracket, + rightBracket: rightBracket, unexpectedBetweenRightBracketAndTrailingClosure, trailingClosure: trailingClosure, unexpectedBetweenTrailingClosureAndAdditionalTrailingClosures, @@ -885,7 +885,7 @@ extension SwitchCaseSyntax { try self.init( leadingTrivia: leadingTrivia, unexpectedBeforeUnknownAttr, - attribute: unknownAttr, + unknownAttr: unknownAttr, unexpectedBetweenUnknownAttrAndLabel, label: label, unexpectedBetweenLabelAndStatements, @@ -920,7 +920,7 @@ extension SwitchExprSyntax { unexpectedBeforeSwitchKeyword, switchKeyword: switchKeyword, unexpectedBetweenSwitchKeywordAndExpression, - subject: ExprSyntax(fromProtocol: expression), + expression: ExprSyntax(fromProtocol: expression), unexpectedBetweenExpressionAndLeftBrace, leftBrace: leftBrace, unexpectedBetweenLeftBraceAndCases, @@ -953,7 +953,7 @@ extension TupleExprSyntax { unexpectedBeforeLeftParen, leftParen: leftParen, unexpectedBetweenLeftParenAndElementList, - elements: elementListBuilder(), + elementList: elementListBuilder(), unexpectedBetweenElementListAndRightParen, rightParen: rightParen, unexpectedAfterRightParen, @@ -986,7 +986,7 @@ extension VariableDeclSyntax { unexpectedBetweenAttributesAndModifiers, modifiers: modifiers, unexpectedBetweenModifiersAndBindingKeyword, - bindingSpecifier: bindingKeyword, + bindingKeyword: bindingKeyword, unexpectedBetweenBindingKeywordAndBindings, bindings: bindingsBuilder(), unexpectedAfterBindings, From f77ca446d5651a9de5d882c8257a8367a568e8a9 Mon Sep 17 00:00:00 2001 From: Becca Royal-Gordon Date: Mon, 4 Nov 2024 18:13:54 -0800 Subject: [PATCH 3/4] [NFC] Change deprecated child representation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce a much more sophisticated way of describing past revisions to a node’s children. This allows: • Multiple past changes (for instance, a property that has been renamed more than once). • The ability to represent the order of multiple changes and group together simultaneous changes. • Multiple kinds of changes, including changes that introduce more than one member. Note that this commit does not use any of these new capabilities; it just ports existing behavior to the new representation. --- .../SyntaxSupport/AttributeNodes.swift | 118 +++++-- .../SyntaxSupport/AvailabilityNodes.swift | 6 +- .../Sources/SyntaxSupport/Child.swift | 147 ++++++--- .../SyntaxSupport/CompatibilityLayer.swift | 102 +++--- .../Sources/SyntaxSupport/DeclNodes.swift | 236 +++++++++++--- .../Sources/SyntaxSupport/ExprNodes.swift | 292 +++++++++++++----- .../Sources/SyntaxSupport/GenericNodes.swift | 64 +++- .../SyntaxSupport/GrammarGenerator.swift | 2 +- .../Sources/SyntaxSupport/Node.swift | 23 +- .../Sources/SyntaxSupport/PatternNodes.swift | 16 +- .../Sources/SyntaxSupport/StmtNodes.swift | 74 +++-- .../Sources/SyntaxSupport/Traits.swift | 22 +- .../Sources/SyntaxSupport/TypeNodes.swift | 90 ++++-- .../ChildNodeChoices.swift | 2 +- .../InitSignature+Extensions.swift | 77 ++++- .../templates/Array+Child.swift | 19 -- .../swiftsyntax/RawSyntaxValidationFile.swift | 2 +- .../RenamedChildrenCompatibilityFile.swift | 11 +- ...amedChildrenBuilderCompatibilityFile.swift | 2 +- .../ValidateSyntaxNodes.swift | 4 +- 20 files changed, 971 insertions(+), 338 deletions(-) delete mode 100644 CodeGeneration/Sources/generate-swift-syntax/templates/Array+Child.swift diff --git a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift index b7a9dbe5bea..28e4baf5045 100644 --- a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift @@ -41,7 +41,6 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "atSign", - deprecatedName: "atSignToken", kind: .token(choices: [.token(.atSign)]), documentation: "The `@` sign." ), @@ -59,7 +58,6 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "argument", kind: .nodeChoices(choices: [ Child( name: "argumentList", @@ -156,6 +154,12 @@ public let ATTRIBUTE_NODES: [Node] = [ documentation: "If the attribute takes arguments, the closing parenthesis.", isOptional: true ), + ], + childHistory: [ + [ + "atSign": .renamed(from: "atSignToken"), + "arguments": .renamed(from: "argument"), + ] ] ), @@ -167,7 +171,6 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "availabilityLabel", - deprecatedName: "label", kind: .token(choices: [.keyword(.availability)]), nameForDiagnostics: "label", documentation: "The label of the argument" @@ -179,7 +182,6 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "availabilityArguments", - deprecatedName: "availabilityList", kind: .collection( kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument", @@ -190,6 +192,12 @@ public let ATTRIBUTE_NODES: [Node] = [ name: "semicolon", kind: .token(choices: [.token(.semicolon)]) ), + ], + childHistory: [ + [ + "availabilityLabel": .renamed(from: "label"), + "availabilityArguments": .renamed(from: "availabilityList"), + ] ] ), @@ -202,7 +210,6 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "platformVersion", - deprecatedName: "availabilityVersionRestriction", kind: .node(kind: .platformVersion), documentation: "The platform/version pair, e.g. `iOS 10.1`" ), @@ -212,6 +219,11 @@ public let ATTRIBUTE_NODES: [Node] = [ documentation: "A trailing comma if the argument is followed by another argument", isOptional: true ), + ], + childHistory: [ + [ + "platformVersion": .renamed(from: "availabilityVersionRestriction") + ] ] ), @@ -240,7 +252,6 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "platforms", - deprecatedName: "versionList", kind: .collection( kind: .platformVersionItemList, collectionElementName: "Platform", @@ -248,6 +259,11 @@ public let ATTRIBUTE_NODES: [Node] = [ ), documentation: "The list of OS versions in which the declaration became ABI stable." ), + ], + childHistory: [ + [ + "platforms": .renamed(from: "versionList") + ] ] ), @@ -340,7 +356,6 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "accessorSpecifier", - deprecatedName: "accessorKind", kind: .token(choices: [.keyword(.get), .keyword(.set)]), documentation: "The accessor name.", isOptional: true @@ -352,10 +367,15 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "diffParams", kind: .node(kind: .differentiabilityWithRespectToArgument), isOptional: true ), + ], + childHistory: [ + [ + "accessorSpecifier": .renamed(from: "accessorKind"), + "arguments": .renamed(from: "diffParams"), + ] ] ), @@ -378,7 +398,6 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "argument", - deprecatedName: "parameter", kind: .token(choices: [.token(.identifier), .token(.integerLiteral), .keyword(.self)]) ), Child( @@ -386,6 +405,11 @@ public let ATTRIBUTE_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "argument": .renamed(from: "parameter") + ] ] ), @@ -407,21 +431,31 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "parameters", - kind: .nodeChoices(choices: [ - Child( - name: "argument", - deprecatedName: "parameter", - kind: .node(kind: .differentiabilityArgument) - ), - Child( - name: "argumentList", - deprecatedName: "parameterList", - kind: .node(kind: .differentiabilityArguments) - ), - ]), + kind: .nodeChoices( + choices: [ + Child( + name: "argument", + kind: .node(kind: .differentiabilityArgument) + ), + Child( + name: "argumentList", + kind: .node(kind: .differentiabilityArguments) + ), + ], + childHistory: [ + [ + "argument": .renamed(from: "parameter"), + "argumentList": .renamed(from: "parameterList"), + ] + ] + ), nameForDiagnostics: "arguments" ), + ], + childHistory: [ + [ + "arguments": .renamed(from: "parameters") + ] ] ), @@ -437,7 +471,6 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "differentiabilityParameters", kind: .collection(kind: .differentiabilityArgumentList, collectionElementName: "Argument"), documentation: "The parameters for differentiation." ), @@ -445,6 +478,11 @@ public let ATTRIBUTE_NODES: [Node] = [ name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "arguments": .renamed(from: "differentiabilityParameters") + ] ] ), @@ -457,40 +495,44 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "kindSpecifier", - deprecatedName: "diffKind", kind: .token(choices: [.keyword(._forward), .keyword(.reverse), .keyword(._linear)]), documentation: "The differentiability kind, if it exists.", isOptional: true ), Child( name: "kindSpecifierComma", - deprecatedName: "diffKindComma", kind: .token(choices: [.token(.comma)]), documentation: "The comma following the differentiability kind, if it exists.", isOptional: true ), Child( name: "arguments", - deprecatedName: "diffParams", kind: .node(kind: .differentiabilityWithRespectToArgument), documentation: "The differentiability arguments, if any exists.", isOptional: true ), Child( name: "argumentsComma", - deprecatedName: "diffParamsComma", kind: .token(choices: [.token(.comma)]), documentation: "The comma following the differentiability arguments clause, if it exists.", isOptional: true ), Child( name: "genericWhereClause", - deprecatedName: "whereClause", kind: .node(kind: .genericWhereClause), documentation: "A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.", isOptional: true ), + ], + childHistory: [ + [ + "kindSpecifier": .renamed(from: "diffKind"), + "kindSpecifierComma": .renamed(from: "diffKindComma"), + "arguments": .renamed(from: "diffParams"), + "argumentsComma": .renamed(from: "diffParamsComma"), + "genericWhereClause": .renamed(from: "whereClause"), + ] ] ), @@ -564,9 +606,13 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "declName", - deprecatedName: "declname", kind: .node(kind: .declReferenceExpr) ), + ], + childHistory: [ + [ + "declName": .renamed(from: "declname") + ] ] ), @@ -621,11 +667,15 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "declName", - deprecatedName: "declname", kind: .node(kind: .declReferenceExpr), nameForDiagnostics: "declaration name", documentation: "The value for this argument" ), + ], + childHistory: [ + [ + "declName": .renamed(from: "declname") + ] ] ), @@ -776,7 +826,6 @@ public let ATTRIBUTE_NODES: [Node] = [ children: [ Child( name: "targetLabel", - deprecatedName: "label", kind: .token(choices: [.keyword(.target)]), nameForDiagnostics: "label", documentation: "The label of the argument" @@ -788,7 +837,6 @@ public let ATTRIBUTE_NODES: [Node] = [ ), Child( name: "declName", - deprecatedName: "declname", kind: .node(kind: .declReferenceExpr), nameForDiagnostics: "declaration name", documentation: "The value for this argument" @@ -799,6 +847,12 @@ public let ATTRIBUTE_NODES: [Node] = [ documentation: "A trailing comma if this argument is followed by another one", isOptional: true ), + ], + childHistory: [ + [ + "targetLabel": .renamed(from: "label"), + "declName": .renamed(from: "declname"), + ] ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift index f7d12324a79..7e644aca816 100644 --- a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift @@ -21,7 +21,6 @@ public let AVAILABILITY_NODES: [Node] = [ children: [ Child( name: "argument", - deprecatedName: "entry", kind: .nodeChoices(choices: [ Child( name: "token", @@ -48,6 +47,11 @@ public let AVAILABILITY_NODES: [Node] = [ documentation: "A trailing comma if the argument is followed by another argument.", isOptional: true ), + ], + childHistory: [ + [ + "argument": .renamed(from: "entry") + ] ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/Child.swift b/CodeGeneration/Sources/SyntaxSupport/Child.swift index db4328cf821..e486ef1598b 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Child.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Child.swift @@ -40,7 +40,8 @@ public enum ChildKind { /// The child always contains a node of the given `kind`. case node(kind: SyntaxNodeKind) /// The child always contains a node that matches one of the `choices`. - case nodeChoices(choices: [Child]) + case nodeChoices(choices: [Child], childHistory: Child.History = []) + // FIXME: We don't appear to have ever generated compatibility layers for children of node choices! /// The child is a collection of `kind`. case collection( kind: SyntaxNodeKind, @@ -70,7 +71,7 @@ public enum ChildKind { } public var isNodeChoicesEmpty: Bool { - if case .nodeChoices(let nodeChoices) = self { + if case .nodeChoices(let nodeChoices, _) = self { return nodeChoices.isEmpty } else { return true @@ -86,11 +87,6 @@ public class Child: NodeChoiceConvertible { /// The first character of the name is always uppercase. public let name: String - /// If the child has been renamed, its old, now deprecated, name. - /// - /// This is used to generate deprecated compatibility layers. - public let deprecatedName: String? - /// The kind of the child (node, token, collection, ...) public let kind: ChildKind @@ -161,30 +157,73 @@ public class Child: NodeChoiceConvertible { return "\(raw: newestName.withFirstCharacterUppercased)Options" } - /// Determines if this child has a deprecated name - public var hasDeprecatedName: Bool { - return deprecatedName != nil - } - - /// If this child is actually part of another child's history, links back - /// to the newest (that is, most current/non-deprecated) version of the - /// child. Nil if this is the newest version of the child. - public let newestChild: Child? + /// If this child is deprecated, describes the sequence of accesses necessary + /// to reach the equivalent value using non-deprecated children; if the child + /// is not deprecated, this array is empty. + /// + /// Think of the elements of this array like components in a key path: + /// `newestChildPath[0]` is a child of the same node `self` is a child of, + /// `newestChildPath[1]` is a child of the node in `newestChildPath[0]`, + /// `newestChildPath[2]` is a child of the node in `newestChildPath[1]`, + /// and so on. To access the current value of this child, you must access each child + /// in the path *in sequence* on the node returned by the last access. + /// + /// ``` + /// // Suppose the `newestChildPath` of `fooBar` looks like: + /// // + /// // [ Child(name: "foo", ...), Child(name: "bar", ...) ] + /// // + /// // A compatibility property might look like this: + /// var fooBar: BarSyntax { + /// get { + /// return self.foo.bar + /// } + /// set { + /// self.foo.bar = newValue + /// } + /// } + /// ``` + /// + /// If the child has only ever had `Refactoring.renamed(from:)`, there will + /// only be one element in the path; if `Refactoring.extracted` is involved, + /// there may be many elements. + /// + /// - Invariant: `newestChildPath.first`, if present, is always a sibling of `self`. + /// - Invariant: `newestChildPath.last`, if present, always has the same `kind` as `self`. + /// - Invariant: All elements in `newestChildPath` are not historical. + /// - Note: This array does *not* record all of the previous versions + /// of the child. That information is not directly available anywhere. + public let newestChildPath: [Child] /// True if this child was created by a `Child.Refactoring`. Such children /// are part of the compatibility layer and are therefore deprecated. public var isHistorical: Bool { - newestChild != nil + !newestChildPath.isEmpty } /// Replaces the nodes in `newerChildPath` with their own `newerChildPath`s, /// if any, to form a child path enitrely of non-historical nodes. - static private func makeNewestChild(from newerChild: Child?) -> Child? { - return newerChild?.newestChild ?? newerChild + static private func makeNewestChildPath(from newerChildPath: [Child]) -> [Child] { + var result: [Child] = [] + + // Push the children onto the stack in reverse order so they end up in the right place once they're resolved. + var workStack = Array(newerChildPath.reversed()) + + while let elem = workStack.popLast() { + if elem.isHistorical { + // There's an even newer version. Start working on that. + workStack.append(contentsOf: elem.newestChildPath.reversed()) + } else { + // We've reached the current version of the child. + result.append(elem) + } + } + + return result } private var newestName: String { - return newestChild?.name ?? name + return newestChildPath.last?.name ?? name } /// If the child ends with "token" in the kind, it's considered a token node. @@ -237,7 +276,7 @@ public class Child: NodeChoiceConvertible { /// it has no node choices. public var hasBaseType: Bool { switch kind { - case .nodeChoices(let choices): + case .nodeChoices(let choices, _): return choices.isEmpty case .node(let kind): return kind.isBase @@ -259,22 +298,16 @@ public class Child: NodeChoiceConvertible { init( name: String, - deprecatedName: String? = nil, kind: ChildKind, experimentalFeature: ExperimentalFeature? = nil, nameForDiagnostics: String? = nil, documentation: String? = nil, isOptional: Bool = false, - newerChild: Child? = nil + newerChildPath: [Child] = [] ) { precondition(name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase") - precondition( - deprecatedName?.first?.isLowercase ?? true, - "The first letter of a child’s deprecatedName should be lowercase" - ) self.name = name - self.deprecatedName = deprecatedName - self.newestChild = Self.makeNewestChild(from: newerChild) + self.newestChildPath = Self.makeNewestChildPath(from: newerChildPath) self.kind = kind self.experimentalFeature = experimentalFeature self.nameForDiagnostics = nameForDiagnostics @@ -285,10 +318,11 @@ public class Child: NodeChoiceConvertible { /// Create a node that is a copy of the last node in `newerChildPath`, but /// with modifications. - init(renamingTo replacementName: String? = nil, newerChild other: Child) { + init(renamingTo replacementName: String? = nil, newerChildPath: [Child]) { + let other = newerChildPath.last! + self.name = replacementName ?? other.name - self.deprecatedName = nil - self.newestChild = Self.makeNewestChild(from: other) + self.newestChildPath = Self.makeNewestChildPath(from: newerChildPath) self.kind = other.kind self.experimentalFeature = other.experimentalFeature self.nameForDiagnostics = other.nameForDiagnostics @@ -299,7 +333,7 @@ public class Child: NodeChoiceConvertible { /// Create a child for the unexpected nodes between two children (either or /// both of which may be `nil`). - convenience init(forUnexpectedBetween earlier: Child?, and later: Child?, newerChild: Child? = nil) { + convenience init(forUnexpectedBetween earlier: Child?, and later: Child?, newerChildPath: [Child] = []) { let name = switch (earlier, later) { case (nil, let later?): @@ -314,13 +348,12 @@ public class Child: NodeChoiceConvertible { self.init( name: name, - deprecatedName: nil, // deprecation of unexpected nodes is handled in CompatibilityLayer kind: .collection(kind: .unexpectedNodes, collectionElementName: name.withFirstCharacterUppercased), experimentalFeature: earlier?.experimentalFeature ?? later?.experimentalFeature, nameForDiagnostics: nil, documentation: nil, isOptional: true, - newerChild: newerChild + newerChildPath: newerChildPath ) } } @@ -334,3 +367,47 @@ extension Child: Hashable { hasher.combine(ObjectIdentifier(self)) } } + +extension Child { + /// A set of changes to the children that were all made simultaneously. The + /// key is the *new* name of the child; any names in the value are old names. + public typealias ChangeSet = KeyValuePairs + + /// A history of change sets applied to a group of children, ordered from + /// most recent set of changes to most distant. + /// + /// The first element is the newest set of changes; the last element is the oldest set + /// of changes. The change sets are applied on top of one another; for + /// example, this node has a child that was originally named `foo`, then + /// `bar`, and now `baz`: + /// + /// ```swift + /// Node( + /// ... + /// children: [ + /// Child(name: "baz", ...), + /// ], + /// childHistory: [ + /// // The key here is "baz", the current name + /// [ "baz": .renamed(from: "bar") ], + /// // The key here is "bar", the name before the previous change set + /// [ "bar": .renamed(from: "foo") ], + /// } + /// } + /// ``` + public typealias History = [ChangeSet] + + /// Specifies a historical change to a given child, and is able to generate + /// replacement children to substitute for it in deprecated compatibility + /// layers. + public enum Refactoring { + /// This child was renamed at some point in the past, so a deprecated alias + /// should be provided. The associated value is the *old*, now-deprecated name. + case renamed(from: String) + + /// Several adjacent children were extracted into a separate node at some + /// point in the past, so deprecated aliases that flatten the other node's + /// children into this node should be provided. + case extracted + } +} diff --git a/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift b/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift index abfd0950392..da626d96a3d 100644 --- a/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift +++ b/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift @@ -15,9 +15,9 @@ public struct CompatibilityLayer { /// Deprecated members that the compatibility layer needs for each node. private var deprecatedMembersByNode: [SyntaxNodeKind: DeprecatedMemberInfo] = [:] - /// Cache for `replacementChild(for:)`. Ensures that we don't create two different replacement children even + /// Cache for `replacementChildren(for:by:)`. Ensures that we don't create two different replacement children even /// if we refactor the same child twice, so we can reliably equate and hash `Child` objects by object identity. - private var cachedReplacementChildren: [Child: Child?] = [:] + private var cachedReplacementChildren: [Child: [Child]] = [:] /// Returns the deprecated members that the compatibility layer needs for `node`. public func deprecatedMembers(for node: LayoutNode) -> DeprecatedMemberInfo { @@ -33,13 +33,37 @@ public struct CompatibilityLayer { } } - private mutating func replacementChild(for newerChild: Child) -> Child? { - func make() -> Child? { - guard let deprecatedName = newerChild.deprecatedName else { - return nil + /// Returns the child or children that would have existed in place of this + /// child before this refactoring was applied. + private mutating func replacementChildren(for newerChild: Child, by refactoring: Child.Refactoring) -> [Child] { + func make() -> [Child] { + switch refactoring { + case .renamed(from: let deprecatedName): + return [ + Child( + renamingTo: deprecatedName, + newerChildPath: [newerChild] + ) + ] + + case .extracted: + let extractedNode = SYNTAX_NODE_MAP[newerChild.syntaxNodeKind]! + computeMembers(for: extractedNode) + + var newerGrandchildren = extractedNode.layoutNode!.children[...] + + // Drop the leading and trailing unexpected nodes--these will be newly introduced. + if newerGrandchildren.first?.isUnexpectedNodes ?? false { + newerGrandchildren.removeFirst() + } + if newerGrandchildren.last?.isUnexpectedNodes ?? false { + newerGrandchildren.removeLast() + } + + return newerGrandchildren.map { newerGrandchild in + Child(newerChildPath: [newerChild, newerGrandchild]) + } } - - return Child(renamingTo: deprecatedName, newerChild: newerChild) } // Make sure we return the same instance even if we're called twice. @@ -49,6 +73,7 @@ public struct CompatibilityLayer { return cachedReplacementChildren[newerChild]! } + /// Compute and cache compatibility layer information for the given node, unless it is already present. private mutating func computeMembers(for node: Node) { guard deprecatedMembersByNode[node.syntaxNodeKind] == nil, let layoutNode = node.layoutNode else { return @@ -58,7 +83,7 @@ public struct CompatibilityLayer { var vars: [Child] = [] var initSignatures: [InitSignature] = [] - // Temporary working state. + // Temporary working state for the loop. var children = layoutNode.children var knownVars = Set(children) @@ -71,43 +96,46 @@ public struct CompatibilityLayer { return i } - var unexpectedChildrenWithNewNames: Set = [] + for changeSet in layoutNode.childHistory { + var unexpectedChildrenWithNewNames: Set = [] - // First pass: Apply the changes explicitly specified in the change set. - for i in children.indices { - let currentName = children[i].name - guard let replacementChild = replacementChild(for: children[i]) else { - continue - } - children[i] = replacementChild + // First pass: Apply the changes explicitly specified in the change set. + for (currentName, refactoring) in changeSet { + let i = firstIndexOfChild(named: currentName) - // Mark adjacent unexpected node children whose names have changed too. - if currentName != replacementChild.name { - unexpectedChildrenWithNewNames.insert(children[i - 1]) - unexpectedChildrenWithNewNames.insert(children[i + 1]) + let replacementChildren = replacementChildren(for: children[i], by: refactoring) + children.replaceSubrange(i...i, with: replacementChildren) + + // Mark adjacent unexpected node children whose names have changed too. + if currentName != replacementChildren.first?.name { + unexpectedChildrenWithNewNames.insert(children[i - 1]) + } + if currentName != replacementChildren.last?.name { + unexpectedChildrenWithNewNames.insert(children[i + replacementChildren.count]) + } } - } - // Second pass: Update unexpected node children adjacent to those changes whose names have probably changed. - for unexpectedChild in unexpectedChildrenWithNewNames { - precondition(unexpectedChild.isUnexpectedNodes) - let i = firstIndexOfChild(named: unexpectedChild.name) + // Second pass: Update unexpected node children adjacent to those changes whose names have probably changed. + for unexpectedChild in unexpectedChildrenWithNewNames { + precondition(unexpectedChild.isUnexpectedNodes) + let i = firstIndexOfChild(named: unexpectedChild.name) - let earlier = children[checked: i - 1] - let later = children[checked: i + 1] - precondition(!(earlier?.isUnexpectedNodes ?? false) && !(later?.isUnexpectedNodes ?? false)) + let earlier = children[checked: i - 1] + let later = children[checked: i + 1] + precondition(!(earlier?.isUnexpectedNodes ?? false) && !(later?.isUnexpectedNodes ?? false)) - let newChild = Child(forUnexpectedBetween: earlier, and: later, newerChild: unexpectedChild) - precondition(newChild.name != unexpectedChild.name) - precondition(!children.contains { $0.name == newChild.name }) + let newChild = Child(forUnexpectedBetween: earlier, and: later, newerChildPath: [unexpectedChild]) + precondition(newChild.name != unexpectedChild.name) + precondition(!children.contains { $0.name == newChild.name }) - children[i] = newChild - } + children[i] = newChild + } - // Third pass: Append newly-created children to vars. We do this now so that changes from the first two passes are properly interleaved, preserving source order. - vars += children.filter { knownVars.insert($0).inserted } + // Third pass: Append newly-created children to vars. We do this now so that changes from the first two passes are properly interleaved, preserving source order. + vars += children.filter { knownVars.insert($0).inserted } - initSignatures.append(InitSignature(children: children)) + initSignatures.append(InitSignature(children: children)) + } deprecatedMembersByNode[node.syntaxNodeKind] = DeprecatedMemberInfo(vars: vars, inits: initSignatures) } diff --git a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift index e7dd69217a8..0dea2d63426 100644 --- a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift @@ -28,10 +28,14 @@ public let DECL_NODES: [Node] = [ ), Child( name: "trailingPeriod", - deprecatedName: "trailingDot", kind: .token(choices: [.token(.period)]), isOptional: true ), + ], + childHistory: [ + [ + "trailingPeriod": .renamed(from: "trailingDot") + ] ] ), @@ -100,7 +104,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "accessorSpecifier", - deprecatedName: "accessorKind", kind: .token(choices: [ .keyword(.get), .keyword(.set), @@ -121,7 +124,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "parameters", - deprecatedName: "parameter", kind: .node(kind: .accessorParameters), nameForDiagnostics: "parameter", isOptional: true @@ -136,6 +138,12 @@ public let DECL_NODES: [Node] = [ kind: .node(kind: .codeBlock), isOptional: true ), + ], + childHistory: [ + [ + "accessorSpecifier": .renamed(from: "accessorKind"), + "parameters": .renamed(from: "parameter"), + ] ] ), @@ -200,7 +208,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "The name of the actor. If the name matches a reserved keyword use backticks to escape it." ), @@ -229,6 +236,11 @@ public let DECL_NODES: [Node] = [ name: "memberBlock", kind: .node(kind: .memberBlock) ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -288,7 +300,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "The name of this associated type." ), @@ -313,6 +324,11 @@ public let DECL_NODES: [Node] = [ documentation: "The `where` clause that applies to the generic parameters of this associated type declaration.", isOptional: true ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -372,7 +388,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "The name of the class." ), @@ -403,6 +418,11 @@ public let DECL_NODES: [Node] = [ documentation: "The members of the class declaration. As class extension declarations may declare additional members, the contents of this member block isn't guaranteed to be a complete list of members for this type." ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -585,12 +605,16 @@ public let DECL_NODES: [Node] = [ ), Child( name: "placeholder", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: """ The actual editor placeholder that starts with `<#` and ends with `#>`. """ ), + ], + childHistory: [ + [ + "placeholder": .renamed(from: "identifier") + ] ] ), @@ -609,7 +633,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "parameters", - deprecatedName: "parameterList", kind: .collection(kind: .enumCaseParameterList, collectionElementName: "Parameter"), nameForDiagnostics: "parameters", documentation: "The actual parameters." @@ -619,6 +642,11 @@ public let DECL_NODES: [Node] = [ kind: .token(choices: [.token(.rightParen)]), documentation: "The ')' to close the parameter clause." ), + ], + childHistory: [ + [ + "parameters": .renamed(from: "parameterList") + ] ] ), @@ -665,7 +693,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "defaultValue", - deprecatedName: "defaultArgument", kind: .node(kind: .initializerClause), nameForDiagnostics: "default value", documentation: "If the parameter has a default value, the initializer clause describing the default value.", @@ -677,6 +704,11 @@ public let DECL_NODES: [Node] = [ documentation: "If the parameter is followed by another parameter, the comma separating them.", isOptional: true ), + ], + childHistory: [ + [ + "defaultValue": .renamed(from: "defaultArgument") + ] ] ), @@ -737,13 +769,11 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "The name of this case." ), Child( name: "parameterClause", - deprecatedName: "associatedValue", kind: .node(kind: .enumCaseParameterClause), nameForDiagnostics: "associated values", documentation: "The set of associated values of the case.", @@ -761,6 +791,12 @@ public let DECL_NODES: [Node] = [ documentation: "The trailing comma of this element, if the case has multiple elements.", isOptional: true ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier"), + "parameterClause": .renamed(from: "associatedValue"), + ] ] ), @@ -796,14 +832,12 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "Declares the name of this enum. If the name matches a reserved keyword use backticks to escape it." ), Child( name: "genericParameterClause", - deprecatedName: "genericParameters", kind: .node(kind: .genericParameterClause), nameForDiagnostics: "generic parameter clause", documentation: "The generic parameters, if any, for this enum declaration.", @@ -829,6 +863,12 @@ public let DECL_NODES: [Node] = [ documentation: "The cases and other members associated with this enum declaration. Because enum extension declarations may declare additional members the contents of this member block isn't guaranteed to be a complete list of members for this type." ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier"), + "genericParameterClause": .renamed(from: "genericParameters"), + ] ] ), @@ -963,7 +1003,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [ .token(.identifier), .token(.binaryOperator), @@ -1001,6 +1040,11 @@ public let DECL_NODES: [Node] = [ documentation: "The function's body.", isOptional: true ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -1075,7 +1119,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "defaultValue", - deprecatedName: "defaultArgument", kind: .node(kind: .initializerClause), nameForDiagnostics: "default value", documentation: "If the parameter has a default value, the expression describing the default value.", @@ -1087,6 +1130,11 @@ public let DECL_NODES: [Node] = [ documentation: "If the parameter is followed by another parameter, the comma separating them.", isOptional: true ), + ], + childHistory: [ + [ + "defaultValue": .renamed(from: "defaultArgument") + ] ] ), @@ -1098,7 +1146,6 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "parameterClause", - deprecatedName: "input", kind: .node(kind: .functionParameterClause), documentation: "The parameters of the function." ), @@ -1110,11 +1157,16 @@ public let DECL_NODES: [Node] = [ ), Child( name: "returnClause", - deprecatedName: "output", kind: .node(kind: .returnClause), documentation: "The return type of the function.", isOptional: true ), + ], + childHistory: [ + [ + "parameterClause": .renamed(from: "input"), + "returnClause": .renamed(from: "output"), + ] ] ), @@ -1218,13 +1270,11 @@ public let DECL_NODES: [Node] = [ ), Child( name: "importKeyword", - deprecatedName: "importTok", kind: .token(choices: [.keyword(.import)]), documentation: "The `import` keyword for this declaration." ), Child( name: "importKindSpecifier", - deprecatedName: "importKind", kind: .token(choices: [ .keyword(.typealias), .keyword(.struct), @@ -1248,6 +1298,12 @@ public let DECL_NODES: [Node] = [ kind: .collection(kind: .importPathComponentList, collectionElementName: "PathComponent"), documentation: "The path to the module, submodule or symbol being imported." ), + ], + childHistory: [ + [ + "importKeyword": .renamed(from: "importTok"), + "importKindSpecifier": .renamed(from: "importKind"), + ] ] ), @@ -1268,7 +1324,6 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "type", - deprecatedName: "typeName", kind: .node(kind: .type) ), Child( @@ -1276,6 +1331,11 @@ public let DECL_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "type": .renamed(from: "typeName") + ] ] ), @@ -1401,7 +1461,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]) ), Child( @@ -1430,6 +1489,11 @@ public let DECL_NODES: [Node] = [ "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.", isOptional: true ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -1456,18 +1520,15 @@ public let DECL_NODES: [Node] = [ ), Child( name: "pound", - deprecatedName: "poundToken", kind: .token(choices: [.token(.pound)]), documentation: "The `#` sign." ), Child( name: "macroName", - deprecatedName: "macro", kind: .token(choices: [.token(.identifier)]) ), Child( name: "genericArgumentClause", - deprecatedName: "genericArguments", kind: .node(kind: .genericArgumentClause), isOptional: true ), @@ -1478,7 +1539,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "argumentList", kind: .collection(kind: .labeledExprList, collectionElementName: "Argument") ), Child( @@ -1499,6 +1559,14 @@ public let DECL_NODES: [Node] = [ defaultsToEmpty: true ) ), + ], + childHistory: [ + [ + "pound": .renamed(from: "poundToken"), + "macroName": .renamed(from: "macro"), + "genericArgumentClause": .renamed(from: "genericArguments"), + "arguments": .renamed(from: "argumentList"), + ] ] ), @@ -1569,7 +1637,6 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "fixitySpecifier", - deprecatedName: "fixity", kind: .token(choices: [.keyword(.prefix), .keyword(.postfix), .keyword(.infix)]), nameForDiagnostics: "fixity", documentation: "The fixity applied to the 'operator' declaration." @@ -1580,7 +1647,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.binaryOperator), .token(.prefixOperator), .token(.postfixOperator)]) ), Child( @@ -1589,6 +1655,12 @@ public let DECL_NODES: [Node] = [ documentation: "Optionally specify a precedence group and designated types.", isOptional: true ), + ], + childHistory: [ + [ + "fixitySpecifier": .renamed(from: "fixity"), + "name": .renamed(from: "identifier"), + ] ] ), @@ -1631,7 +1703,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "parameters", - deprecatedName: "parameterList", kind: .collection(kind: .functionParameterList, collectionElementName: "Parameter"), nameForDiagnostics: "parameters" ), @@ -1639,6 +1710,11 @@ public let DECL_NODES: [Node] = [ name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "parameters": .renamed(from: "parameterList") + ] ] ), @@ -1698,7 +1774,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "accessorBlock", - deprecatedName: "accessor", kind: .node(kind: .accessorBlock), documentation: """ If the variable is computed, the accessors that get (and optionally set) the value. @@ -1710,6 +1785,11 @@ public let DECL_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "accessorBlock": .renamed(from: "accessor") + ] ] ), @@ -1720,12 +1800,10 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "fileLabel", - deprecatedName: "fileArgLabel", kind: .token(choices: [.keyword(.file)]) ), Child( name: "fileColon", - deprecatedName: "fileArgColon", kind: .token(choices: [.token(.colon)]) ), Child( @@ -1739,12 +1817,10 @@ public let DECL_NODES: [Node] = [ ), Child( name: "lineLabel", - deprecatedName: "lineArgLabel", kind: .token(choices: [.keyword(.line)]) ), Child( name: "lineColon", - deprecatedName: "lineArgColon", kind: .token(choices: [.token(.colon)]) ), Child( @@ -1752,6 +1828,14 @@ public let DECL_NODES: [Node] = [ kind: .token(choices: [.token(.integerLiteral)]), nameForDiagnostics: "line number" ), + ], + childHistory: [ + [ + "fileLabel": .renamed(from: "fileArgLabel"), + "fileColon": .renamed(from: "fileArgColon"), + "lineLabel": .renamed(from: "lineArgLabel"), + "lineColon": .renamed(from: "lineArgColon"), + ] ] ), @@ -1773,7 +1857,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "args", kind: .node(kind: .poundSourceLocationArguments), nameForDiagnostics: "arguments", isOptional: true @@ -1782,6 +1865,11 @@ public let DECL_NODES: [Node] = [ name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "arguments": .renamed(from: "args") + ] ] ), @@ -1793,7 +1881,6 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "assignmentLabel", - deprecatedName: "assignmentKeyword", kind: .token(choices: [.keyword(.assignment)]) ), Child( @@ -1802,11 +1889,16 @@ public let DECL_NODES: [Node] = [ ), Child( name: "value", - deprecatedName: "flag", kind: .token(choices: [.keyword(.true), .keyword(.false)]), documentation: "When true, an operator in the corresponding precedence group uses the same grouping rules during optional chaining as the assignment operators from the standard library. Otherwise, operators in the precedence group follows the same optional chaining rules as operators that don't perform assignment." ), + ], + childHistory: [ + [ + "assignmentLabel": .renamed(from: "assignmentKeyword"), + "value": .renamed(from: "flag"), + ] ] ), @@ -1819,7 +1911,6 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "associativityLabel", - deprecatedName: "associativityKeyword", kind: .token(choices: [.keyword(.associativity)]) ), Child( @@ -1832,6 +1923,11 @@ public let DECL_NODES: [Node] = [ documentation: "Operators that are `left`-associative group left-to-right. Operators that are `right`-associative group right-to-left. Operators that are specified with an associativity of `none` don't associate at all" ), + ], + childHistory: [ + [ + "associativityLabel": .renamed(from: "associativityKeyword") + ] ] ), Node( @@ -1871,7 +1967,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "The name of this precedence group." ), @@ -1888,6 +1983,11 @@ public let DECL_NODES: [Node] = [ name: "rightBrace", kind: .token(choices: [.token(.rightBrace)]) ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -1925,7 +2025,6 @@ public let DECL_NODES: [Node] = [ children: [ Child( name: "higherThanOrLowerThanLabel", - deprecatedName: "higherThanOrLowerThan", kind: .token(choices: [.keyword(.higherThan), .keyword(.lowerThan)]), documentation: "The relation to specified other precedence groups." ), @@ -1935,10 +2034,15 @@ public let DECL_NODES: [Node] = [ ), Child( name: "precedenceGroups", - deprecatedName: "otherNames", kind: .collection(kind: .precedenceGroupNameList, collectionElementName: "OtherName"), documentation: "The name of other precedence group to which this precedence group relates." ), + ], + childHistory: [ + [ + "higherThanOrLowerThanLabel": .renamed(from: "higherThanOrLowerThan"), + "precedenceGroups": .renamed(from: "otherNames"), + ] ] ), @@ -1983,7 +2087,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "The name of the protocol." ), @@ -2013,6 +2116,11 @@ public let DECL_NODES: [Node] = [ kind: .node(kind: .memberBlock), documentation: "The members of the protocol declaration." ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -2028,11 +2136,15 @@ public let DECL_NODES: [Node] = [ ), Child( name: "type", - deprecatedName: "returnType", kind: .node(kind: .type), nameForDiagnostics: "return type", documentation: "The `return` type." ), + ], + childHistory: [ + [ + "type": .renamed(from: "returnType") + ] ] ), @@ -2055,9 +2167,13 @@ public let DECL_NODES: [Node] = [ ), Child( name: "endOfFileToken", - deprecatedName: "eofToken", kind: .token(choices: [.token(.endOfFile)]) ), + ], + childHistory: [ + [ + "endOfFileToken": .renamed(from: "eofToken") + ] ] ), @@ -2151,7 +2267,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]), documentation: "Declares the name of this struct. If the name matches a reserved keyword use backticks to escape it." @@ -2184,6 +2299,11 @@ public let DECL_NODES: [Node] = [ documentation: "The members of the struct declaration. Because struct extension declarations may declare additional members the contents of this member block isn't guaranteed to be a complete list of members for this type." ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -2220,12 +2340,10 @@ public let DECL_NODES: [Node] = [ ), Child( name: "parameterClause", - deprecatedName: "indices", kind: .node(kind: .functionParameterClause) ), Child( name: "returnClause", - deprecatedName: "result", kind: .node(kind: .returnClause) ), Child( @@ -2238,10 +2356,16 @@ public let DECL_NODES: [Node] = [ ), Child( name: "accessorBlock", - deprecatedName: "accessor", kind: .node(kind: .accessorBlock), isOptional: true ), + ], + childHistory: [ + [ + "parameterClause": .renamed(from: "indices"), + "returnClause": .renamed(from: "result"), + "accessorBlock": .renamed(from: "accessor"), + ] ] ), @@ -2256,9 +2380,13 @@ public let DECL_NODES: [Node] = [ ), Child( name: "inheritedTypes", - deprecatedName: "inheritedTypeCollection", kind: .collection(kind: .inheritedTypeList, collectionElementName: "InheritedType") ), + ], + childHistory: [ + [ + "inheritedTypes": .renamed(from: "inheritedTypeCollection") + ] ] ), @@ -2306,7 +2434,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "name", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]) ), Child( @@ -2328,6 +2455,11 @@ public let DECL_NODES: [Node] = [ "A `where` clause that places additional constraints on generic parameters like `where Element: Hashable`.", isOptional: true ), + ], + childHistory: [ + [ + "name": .renamed(from: "identifier") + ] ] ), @@ -2359,7 +2491,6 @@ public let DECL_NODES: [Node] = [ ), Child( name: "bindingSpecifier", - deprecatedName: "bindingKeyword", kind: .token(choices: [ .keyword(.let), .keyword(.var), .keyword(.inout), .keyword(._mutating), .keyword(._borrowing), .keyword(._consuming), @@ -2385,6 +2516,11 @@ public let DECL_NODES: [Node] = [ ``` """ ), + ], + childHistory: [ + [ + "bindingSpecifier": .renamed(from: "bindingKeyword") + ] ] ), ] diff --git a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift index c642bf81efb..e3446547120 100644 --- a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift @@ -48,7 +48,6 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "leftSquare", - deprecatedName: "leftSquareBracket", kind: .token(choices: [.token(.leftSquare)]) ), Child( @@ -57,9 +56,14 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "rightSquare", - deprecatedName: "rightSquareBracket", kind: .token(choices: [.token(.rightSquare)]) ), + ], + childHistory: [ + [ + "leftSquare": .renamed(from: "leftSquareBracket"), + "rightSquare": .renamed(from: "rightSquareBracket"), + ] ] ), @@ -86,9 +90,13 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "arrow", - deprecatedName: "arrowToken", kind: .token(choices: [.token(.arrow)]) ), + ], + childHistory: [ + [ + "arrow": .renamed(from: "arrowToken") + ] ] ), @@ -119,7 +127,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "asKeyword", - deprecatedName: "asTok", kind: .token(choices: [.keyword(.as)]) ), Child( @@ -129,9 +136,14 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "type", - deprecatedName: "typeName", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "asKeyword": .renamed(from: "asTok"), + "type": .renamed(from: "typeName"), + ] ] ), @@ -142,9 +154,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "equal", - deprecatedName: "assignToken", kind: .token(choices: [.token(.equal)]) ) + ], + childHistory: [ + [ + "equal": .renamed(from: "assignToken") + ] ] ), @@ -178,9 +194,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "operator", - deprecatedName: "operatorToken", kind: .token(choices: [.token(.binaryOperator)]) ) + ], + childHistory: [ + [ + "operator": .renamed(from: "operatorToken") + ] ] ), @@ -191,9 +211,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "literal", - deprecatedName: "booleanLiteral", kind: .token(choices: [.keyword(.true), .keyword(.false)]) ) + ], + childHistory: [ + [ + "literal": .renamed(from: "booleanLiteral") + ] ] ), @@ -261,9 +285,13 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "version", - deprecatedName: "versionTuple", kind: .node(kind: .versionTuple) ), + ], + childHistory: [ + [ + "version": .renamed(from: "versionTuple") + ] ] ), @@ -455,7 +483,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "parameters", - deprecatedName: "parameterList", kind: .collection(kind: .closureParameterList, collectionElementName: "Parameter"), nameForDiagnostics: "parameters", documentation: "The actual parameters." @@ -465,6 +492,11 @@ public let EXPR_NODES: [Node] = [ kind: .token(choices: [.token(.rightParen)]), documentation: "The ')' to close the parameter clause." ), + ], + childHistory: [ + [ + "parameters": .renamed(from: "parameterList") + ] ] ), @@ -559,18 +591,23 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "parameterClause", - deprecatedName: "input", - kind: .nodeChoices(choices: [ - Child( - name: "simpleInput", - kind: .node(kind: .closureShorthandParameterList) - ), - Child( - name: "parameterClause", - deprecatedName: "input", - kind: .node(kind: .closureParameterClause) - ), - ]), + kind: .nodeChoices( + choices: [ + Child( + name: "simpleInput", + kind: .node(kind: .closureShorthandParameterList) + ), + Child( + name: "parameterClause", + kind: .node(kind: .closureParameterClause) + ), + ], + childHistory: [ + [ + "parameterClause": .renamed(from: "input") + ] + ] + ), isOptional: true ), Child( @@ -580,15 +617,20 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "returnClause", - deprecatedName: "output", kind: .node(kind: .returnClause), isOptional: true ), Child( name: "inKeyword", - deprecatedName: "inTok", kind: .token(choices: [.keyword(.in)]) ), + ], + childHistory: [ + [ + "parameterClause": .renamed(from: "input"), + "returnClause": .renamed(from: "output"), + "inKeyword": .renamed(from: "inTok"), + ] ] ), @@ -656,7 +698,6 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "key", - deprecatedName: "keyExpression", kind: .node(kind: .expr), nameForDiagnostics: "key" ), @@ -666,7 +707,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "value", - deprecatedName: "valueExpression", kind: .node(kind: .expr), nameForDiagnostics: "value" ), @@ -675,6 +715,12 @@ public let EXPR_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "key": .renamed(from: "keyExpression"), + "value": .renamed(from: "valueExpression"), + ] ] ), @@ -792,9 +838,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "placeholder", - deprecatedName: "identifier", kind: .token(choices: [.token(.identifier)]) ) + ], + childHistory: [ + [ + "placeholder": .renamed(from: "identifier") + ] ] ), @@ -825,7 +875,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "pounds", - deprecatedName: "delimiter", kind: .token(choices: [.token(.rawStringPoundDelimiter)]), isOptional: true ), @@ -841,6 +890,11 @@ public let EXPR_NODES: [Node] = [ name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "pounds": .renamed(from: "delimiter") + ] ] ), @@ -851,9 +905,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "literal", - deprecatedName: "floatingDigits", kind: .token(choices: [.token(.floatLiteral)]) ) + ], + childHistory: [ + [ + "literal": .renamed(from: "floatingDigits") + ] ] ), @@ -890,7 +948,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "argumentList", kind: .collection(kind: .labeledExprList, collectionElementName: "Argument"), nameForDiagnostics: "arguments" ), @@ -914,6 +971,11 @@ public let EXPR_NODES: [Node] = [ ), nameForDiagnostics: "trailing closures" ), + ], + childHistory: [ + [ + "arguments": .renamed(from: "argumentList") + ] ] ), @@ -924,7 +986,6 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "baseName", - deprecatedName: "identifier", kind: .token(choices: [ .token(.identifier), .keyword(.self), @@ -939,10 +1000,15 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "argumentNames", - deprecatedName: "declNameArguments", kind: .node(kind: .declNameArguments), isOptional: true ), + ], + childHistory: [ + [ + "baseName": .renamed(from: "identifier"), + "argumentNames": .renamed(from: "declNameArguments"), + ] ] ), @@ -1025,13 +1091,17 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "operator", - deprecatedName: "operatorOperand", kind: .node(kind: .expr) ), Child( name: "rightOperand", kind: .node(kind: .expr) ), + ], + childHistory: [ + [ + "operator": .renamed(from: "operatorOperand") + ] ] ), @@ -1042,9 +1112,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "literal", - deprecatedName: "digits", kind: .token(choices: [.token(.integerLiteral)]) ) + ], + childHistory: [ + [ + "literal": .renamed(from: "digits") + ] ] ), @@ -1072,17 +1146,21 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "isKeyword", - deprecatedName: "isTok", kind: .token(choices: [.keyword(.is)]), documentation: "The `is` keyword for this expression." ), Child( name: "type", - deprecatedName: "typeName", kind: .node(kind: .type), documentation: "The type against which the expression will be checked to see if the expression can be cast to it." ), + ], + childHistory: [ + [ + "isKeyword": .renamed(from: "isTok"), + "type": .renamed(from: "typeName"), + ] ] ), @@ -1195,20 +1273,24 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "leftSquare", - deprecatedName: "leftBracket", kind: .token(choices: [.token(.leftSquare)]) ), Child( name: "arguments", - deprecatedName: "argumentList", kind: .collection(kind: .labeledExprList, collectionElementName: "Argument"), nameForDiagnostics: "arguments" ), Child( name: "rightSquare", - deprecatedName: "rightBracket", kind: .token(choices: [.token(.rightSquare)]) ), + ], + childHistory: [ + [ + "leftSquare": .renamed(from: "leftBracket"), + "arguments": .renamed(from: "argumentList"), + "rightSquare": .renamed(from: "rightBracket"), + ] ] ), @@ -1223,18 +1305,15 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "pound", - deprecatedName: "poundToken", kind: .token(choices: [.token(.pound)]), documentation: "The `#` sign." ), Child( name: "macroName", - deprecatedName: "macro", kind: .token(choices: [.token(.identifier)]) ), Child( name: "genericArgumentClause", - deprecatedName: "genericArguments", kind: .node(kind: .genericArgumentClause), isOptional: true ), @@ -1245,7 +1324,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "arguments", - deprecatedName: "argumentList", kind: .collection(kind: .labeledExprList, collectionElementName: "Argument") ), Child( @@ -1266,6 +1344,14 @@ public let EXPR_NODES: [Node] = [ defaultsToEmpty: true ) ), + ], + childHistory: [ + [ + "pound": .renamed(from: "poundToken"), + "macroName": .renamed(from: "macro"), + "genericArgumentClause": .renamed(from: "genericArguments"), + "arguments": .renamed(from: "argumentList"), + ] ] ), @@ -1284,7 +1370,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "period", - deprecatedName: "dot", kind: .token(choices: [.token(.period)]) ), Child( @@ -1293,6 +1378,11 @@ public let EXPR_NODES: [Node] = [ nameForDiagnostics: "name", documentation: "The name of the referenced function or a property." ), + ], + childHistory: [ + [ + "period": .renamed(from: "dot") + ] ] ), @@ -1303,13 +1393,17 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "consumeKeyword", - deprecatedName: "moveKeyword", kind: .token(choices: [.keyword(._move), .keyword(.consume)]) ), Child( name: "expression", kind: .node(kind: .expr) ), + ], + childHistory: [ + [ + "consumeKeyword": .renamed(from: "moveKeyword") + ] ] ), @@ -1397,9 +1491,13 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "pack", - deprecatedName: "packRefExpr", kind: .node(kind: .expr) ), + ], + childHistory: [ + [ + "pack": .renamed(from: "packRefExpr") + ] ] ), @@ -1415,9 +1513,13 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "repetitionPattern", - deprecatedName: "patternExpr", kind: .node(kind: .expr) ), + ], + childHistory: [ + [ + "repetitionPattern": .renamed(from: "patternExpr") + ] ] ), @@ -1449,9 +1551,13 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "operator", - deprecatedName: "operatorToken", kind: .token(choices: [.token(.postfixOperator)]) ), + ], + childHistory: [ + [ + "operator": .renamed(from: "operatorToken") + ] ] ), @@ -1475,14 +1581,18 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "operator", - deprecatedName: "operatorToken", kind: .token(choices: [.token(.prefixOperator)]) ), Child( name: "expression", - deprecatedName: "postfixExpression", kind: .node(kind: .expr) ), + ], + childHistory: [ + [ + "operator": .renamed(from: "operatorToken"), + "expression": .renamed(from: "postfixExpression"), + ] ] ), @@ -1498,17 +1608,14 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "openingSlash", - deprecatedName: "openSlash", kind: .token(choices: [.token(.regexSlash)]) ), Child( name: "regex", - deprecatedName: "regexPattern", kind: .token(choices: [.token(.regexLiteralPattern)]) ), Child( name: "closingSlash", - deprecatedName: "closeSlash", kind: .token(choices: [.token(.regexSlash)]) ), Child( @@ -1516,6 +1623,13 @@ public let EXPR_NODES: [Node] = [ kind: .token(choices: [.token(.regexPoundDelimiter)]), isOptional: true ), + ], + childHistory: [ + [ + "openingSlash": .renamed(from: "openSlash"), + "regex": .renamed(from: "regexPattern"), + "closingSlash": .renamed(from: "closeSlash"), + ] ] ), @@ -1572,13 +1686,11 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "openingPounds", - deprecatedName: "openDelimiter", kind: .token(choices: [.token(.rawStringPoundDelimiter)]), isOptional: true ), Child( name: "openingQuote", - deprecatedName: "openQuote", kind: .token(choices: [.token(.stringQuote), .token(.multilineStringQuote), .token(.singleQuote)]) ), Child( @@ -1587,15 +1699,21 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "closingQuote", - deprecatedName: "closeQuote", kind: .token(choices: [.token(.stringQuote), .token(.multilineStringQuote), .token(.singleQuote)]) ), Child( name: "closingPounds", - deprecatedName: "closeDelimiter", kind: .token(choices: [.token(.rawStringPoundDelimiter)]), isOptional: true ), + ], + childHistory: [ + [ + "openingPounds": .renamed(from: "openDelimiter"), + "openingQuote": .renamed(from: "openQuote"), + "closingQuote": .renamed(from: "closeQuote"), + "closingPounds": .renamed(from: "closeDelimiter"), + ] ] ), @@ -1667,18 +1785,15 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "leftSquare", - deprecatedName: "leftBracket", kind: .token(choices: [.token(.leftSquare)]) ), Child( name: "arguments", - deprecatedName: "argumentList", kind: .collection(kind: .labeledExprList, collectionElementName: "Argument"), nameForDiagnostics: "arguments" ), Child( name: "rightSquare", - deprecatedName: "rightBracket", kind: .token(choices: [.token(.rightSquare)]) ), Child( @@ -1696,6 +1811,13 @@ public let EXPR_NODES: [Node] = [ ), nameForDiagnostics: "trailing closures" ), + ], + childHistory: [ + [ + "leftSquare": .renamed(from: "leftBracket"), + "arguments": .renamed(from: "argumentList"), + "rightSquare": .renamed(from: "rightBracket"), + ] ] ), @@ -1747,7 +1869,6 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "attribute", - deprecatedName: "unknownAttr", kind: .node(kind: .attribute), documentation: "The `@unknown` attribute of a default label, if present.", isOptional: true @@ -1770,6 +1891,11 @@ public let EXPR_NODES: [Node] = [ name: "statements", kind: .collection(kind: .codeBlockItemList, collectionElementName: "Statement") ), + ], + childHistory: [ + [ + "attribute": .renamed(from: "unknownAttr") + ] ] ), @@ -1818,7 +1944,6 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "subject", - deprecatedName: "expression", kind: .node(kind: .expr), documentation: "The expression to switch over." ), @@ -1837,6 +1962,11 @@ public let EXPR_NODES: [Node] = [ kind: .token(choices: [.token(.rightBrace)]), documentation: "The brace closing the switch body." ), + ], + childHistory: [ + [ + "subject": .renamed(from: "expression") + ] ] ), @@ -1859,7 +1989,6 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "condition", - deprecatedName: "conditionExpression", kind: .node(kind: .expr), nameForDiagnostics: "condition" ), @@ -1869,21 +1998,26 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "thenExpression", - deprecatedName: "firstChoice", kind: .node(kind: .expr), nameForDiagnostics: "first choice" ), Child( name: "colon", - deprecatedName: "colonMark", kind: .token(choices: [.token(.colon)]) ), Child( name: "elseExpression", - deprecatedName: "secondChoice", kind: .node(kind: .expr), nameForDiagnostics: "second choice" ), + ], + childHistory: [ + [ + "condition": .renamed(from: "conditionExpression"), + "thenExpression": .renamed(from: "firstChoice"), + "colon": .renamed(from: "colonMark"), + "elseExpression": .renamed(from: "secondChoice"), + ] ] ), @@ -1985,13 +2119,17 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "elements", - deprecatedName: "elementList", kind: .collection(kind: .labeledExprList, collectionElementName: "Element") ), Child( name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "elements": .renamed(from: "elementList") + ] ] ), @@ -2020,7 +2158,6 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "asKeyword", - deprecatedName: "asTok", kind: .token(choices: [.keyword(.as)]) ), Child( @@ -2028,6 +2165,11 @@ public let EXPR_NODES: [Node] = [ kind: .token(choices: [.token(.postfixQuestionMark), .token(.exclamationMark)]), isOptional: true ), + ], + childHistory: [ + [ + "asKeyword": .renamed(from: "asTok") + ] ] ), @@ -2044,9 +2186,13 @@ public let EXPR_NODES: [Node] = [ children: [ Child( name: "isKeyword", - deprecatedName: "isTok", kind: .token(choices: [.keyword(.is)]) ) + ], + childHistory: [ + [ + "isKeyword": .renamed(from: "isTok") + ] ] ), @@ -2080,14 +2226,18 @@ public let EXPR_NODES: [Node] = [ ), Child( name: "thenExpression", - deprecatedName: "firstChoice", kind: .node(kind: .expr) ), Child( name: "colon", - deprecatedName: "colonMark", kind: .token(choices: [.token(.colon)]) ), + ], + childHistory: [ + [ + "thenExpression": .renamed(from: "firstChoice"), + "colon": .renamed(from: "colonMark"), + ] ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift index 84eb5148aab..99a37a8b352 100644 --- a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift @@ -18,7 +18,6 @@ public let GENERIC_NODES: [Node] = [ children: [ Child( name: "leftType", - deprecatedName: "leftTypeIdentifier", kind: .node(kind: .type) ), Child( @@ -27,9 +26,14 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "rightType", - deprecatedName: "rightTypeIdentifier", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "leftType": .renamed(from: "leftTypeIdentifier"), + "rightType": .renamed(from: "rightTypeIdentifier"), + ] ] ), @@ -42,13 +46,11 @@ public let GENERIC_NODES: [Node] = [ children: [ Child( name: "leftAngle", - deprecatedName: "leftAngleBracket", kind: .token(choices: [.token(.leftAngle)]), documentation: "The opening angle bracket (`<`) of the generic parameter clause." ), Child( name: "parameters", - deprecatedName: "genericParameterList", kind: .collection( kind: .genericParameterList, collectionElementName: "Parameter", @@ -65,10 +67,16 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "rightAngle", - deprecatedName: "rightAngleBracket", kind: .token(choices: [.token(.rightAngle)]), documentation: "The closing angle bracket (`>`) of the generic parameter clause." ), + ], + childHistory: [ + [ + "leftAngle": .renamed(from: "leftAngleBracket"), + "parameters": .renamed(from: "genericParameterList"), + "rightAngle": .renamed(from: "rightAngleBracket"), + ] ] ), @@ -94,7 +102,6 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "specifier", - deprecatedName: "eachKeyword", kind: .token(choices: [ .keyword(.each), .keyword(.let), @@ -123,6 +130,11 @@ public let GENERIC_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "specifier": .renamed(from: "eachKeyword") + ] ] ), @@ -143,7 +155,6 @@ public let GENERIC_NODES: [Node] = [ children: [ Child( name: "requirement", - deprecatedName: "body", kind: .nodeChoices(choices: [ Child( name: "sameTypeRequirement", @@ -164,6 +175,11 @@ public let GENERIC_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "requirement": .renamed(from: "body") + ] ] ), @@ -181,10 +197,14 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "requirements", - deprecatedName: "requirementList", kind: .collection(kind: .genericRequirementList, collectionElementName: "Requirement"), documentation: "The list of requirements in the clause." ), + ], + childHistory: [ + [ + "requirements": .renamed(from: "requirementList") + ] ] ), @@ -195,7 +215,6 @@ public let GENERIC_NODES: [Node] = [ children: [ Child( name: "type", - deprecatedName: "typeIdentifier", kind: .node(kind: .type), nameForDiagnostics: "constrained type" ), @@ -205,7 +224,6 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "layoutSpecifier", - deprecatedName: "layoutConstraint", kind: .token(choices: [ .keyword(._Trivial), .keyword(._TrivialAtMost), @@ -245,6 +263,12 @@ public let GENERIC_NODES: [Node] = [ kind: .token(choices: [.token(.rightParen)]), isOptional: true ), + ], + childHistory: [ + [ + "type": .renamed(from: "typeIdentifier"), + "layoutSpecifier": .renamed(from: "layoutConstraint"), + ] ] ), @@ -255,19 +279,23 @@ public let GENERIC_NODES: [Node] = [ children: [ Child( name: "leftAngle", - deprecatedName: "leftAngleBracket", kind: .token(choices: [.token(.leftAngle)]) ), Child( name: "primaryAssociatedTypes", - deprecatedName: "primaryAssociatedTypeList", kind: .collection(kind: .primaryAssociatedTypeList, collectionElementName: "PrimaryAssociatedType") ), Child( name: "rightAngle", - deprecatedName: "rightAngleBracket", kind: .token(choices: [.token(.rightAngle)]) ), + ], + childHistory: [ + [ + "leftAngle": .renamed(from: "leftAngleBracket"), + "primaryAssociatedTypes": .renamed(from: "primaryAssociatedTypeList"), + "rightAngle": .renamed(from: "rightAngleBracket"), + ] ] ), @@ -306,21 +334,25 @@ public let GENERIC_NODES: [Node] = [ children: [ Child( name: "leftType", - deprecatedName: "leftTypeIdentifier", kind: .node(kind: .type), nameForDiagnostics: "left-hand type" ), Child( name: "equal", - deprecatedName: "equalityToken", kind: .token(choices: [.token(.binaryOperator), .token(.prefixOperator), .token(.postfixOperator)]) ), Child( name: "rightType", - deprecatedName: "rightTypeIdentifier", kind: .node(kind: .type), nameForDiagnostics: "right-hand type" ), + ], + childHistory: [ + [ + "leftType": .renamed(from: "leftTypeIdentifier"), + "equal": .renamed(from: "equalityToken"), + "rightType": .renamed(from: "rightTypeIdentifier"), + ] ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift b/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift index 1bb0c28171d..ae84735dbf9 100644 --- a/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift +++ b/CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift @@ -38,7 +38,7 @@ struct GrammarGenerator { switch child.kind { case .node(let kind): return "\(kind.doccLink)\(optionality)" - case .nodeChoices(let choices): + case .nodeChoices(let choices, _): let choicesDescriptions = choices.map { grammar(for: $0) } return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)" case .collection(kind: let kind, _, _, _): diff --git a/CodeGeneration/Sources/SyntaxSupport/Node.swift b/CodeGeneration/Sources/SyntaxSupport/Node.swift index b9825edb08e..5c7aba135fa 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Node.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Node.swift @@ -23,7 +23,7 @@ import SwiftSyntax /// children are of the same type. public class Node: NodeChoiceConvertible { fileprivate enum Data { - case layout(children: [Child], traits: [String]) + case layout(children: [Child], childHistory: Child.History, traits: [String]) case collection(choices: [SyntaxNodeKind]) } @@ -123,7 +123,8 @@ public class Node: NodeChoiceConvertible { documentation: String? = nil, parserFunction: TokenSyntax? = nil, traits: [String] = [], - children: [Child] = [] + children: [Child] = [], + childHistory: Child.History = [] ) { precondition(base != .syntaxCollection) precondition(base.isBase, "unknown base kind '\(base)' for node '\(kind)'") @@ -137,7 +138,7 @@ public class Node: NodeChoiceConvertible { let childrenWithUnexpected = kind.isBase ? children : interleaveUnexpectedChildren(children) - self.data = .layout(children: childrenWithUnexpected, traits: traits) + self.data = .layout(children: childrenWithUnexpected, childHistory: childHistory, traits: traits) } /// A doc comment that lists all the nodes in which this node occurs as a child in. @@ -270,7 +271,7 @@ public struct LayoutNode { /// This includes unexpected children public var children: [Child] { switch node.data { - case .layout(children: let children, traits: _): + case .layout(children: let children, childHistory: _, traits: _): return children case .collection: preconditionFailure("NodeLayoutView must wrap a Node with data `.layout`") @@ -282,10 +283,20 @@ public struct LayoutNode { return children.filter { !$0.isUnexpectedNodes } } + /// The history of the layout node's children. + public var childHistory: Child.History { + switch node.data { + case .layout(children: _, childHistory: let childHistory, traits: _): + return childHistory + case .collection: + preconditionFailure("NodeLayoutView must wrap a Node with data `.layout`") + } + } + /// Traits that the node conforms to. public var traits: [String] { switch node.data { - case .layout(children: _, traits: let traits): + case .layout(children: _, childHistory: _, traits: let traits): return traits case .collection: preconditionFailure("NodeLayoutView must wrap a Node with data `.layout`") @@ -365,7 +376,7 @@ fileprivate extension Child { switch kind { case .node(let kind): return [kind] - case .nodeChoices(let choices): + case .nodeChoices(let choices, _): return choices.flatMap(\.kinds) case .collection(kind: let kind, _, _, _): return [kind] diff --git a/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift b/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift index 83d45dd71ec..dbb019dfebb 100644 --- a/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift @@ -109,7 +109,6 @@ public let PATTERN_NODES: [Node] = [ children: [ Child( name: "label", - deprecatedName: "labelName", kind: .token(choices: [.token(.identifier)]), nameForDiagnostics: "label", documentation: "The label of the pattern.", @@ -117,7 +116,6 @@ public let PATTERN_NODES: [Node] = [ ), Child( name: "colon", - deprecatedName: "labelColon", kind: .token(choices: [.token(.colon)]), documentation: "The colon separating label and pattern.", isOptional: true @@ -133,6 +131,12 @@ public let PATTERN_NODES: [Node] = [ documentation: "The comma separating elements.", isOptional: true ), + ], + childHistory: [ + [ + "label": .renamed(from: "labelName"), + "colon": .renamed(from: "labelColon"), + ] ] ), @@ -197,7 +201,6 @@ public let PATTERN_NODES: [Node] = [ children: [ Child( name: "bindingSpecifier", - deprecatedName: "bindingKeyword", kind: .token(choices: [ .keyword(.let), .keyword(.var), .keyword(.inout), .keyword(._mutating), .keyword(._borrowing), .keyword(._consuming), @@ -206,9 +209,14 @@ public let PATTERN_NODES: [Node] = [ ), Child( name: "pattern", - deprecatedName: "valuePattern", kind: .node(kind: .pattern) ), + ], + childHistory: [ + [ + "bindingSpecifier": .renamed(from: "bindingKeyword"), + "pattern": .renamed(from: "valuePattern"), + ] ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift index 8d641dc5218..a2eb4305ffd 100644 --- a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift @@ -26,13 +26,17 @@ public let STMT_NODES: [Node] = [ ), Child( name: "availabilityArguments", - deprecatedName: "availabilitySpec", kind: .collection(kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument") ), Child( name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "availabilityArguments": .renamed(from: "availabilitySpec") + ] ] ), @@ -300,7 +304,6 @@ public let STMT_NODES: [Node] = [ ), Child( name: "sequence", - deprecatedName: "sequenceExpr", kind: .node(kind: .expr) ), Child( @@ -313,6 +316,11 @@ public let STMT_NODES: [Node] = [ kind: .node(kind: .codeBlock), nameForDiagnostics: "body" ), + ], + childHistory: [ + [ + "sequence": .renamed(from: "sequenceExpr") + ] ] ), @@ -368,19 +376,23 @@ public let STMT_NODES: [Node] = [ children: [ Child( name: "label", - deprecatedName: "labelName", kind: .token(choices: [.token(.identifier)]), nameForDiagnostics: "label name" ), Child( name: "colon", - deprecatedName: "labelColon", kind: .token(choices: [.token(.colon)]) ), Child( name: "statement", kind: .node(kind: .stmt) ), + ], + childHistory: [ + [ + "label": .renamed(from: "labelName"), + "colon": .renamed(from: "labelColon"), + ] ] ), @@ -416,7 +428,6 @@ public let STMT_NODES: [Node] = [ children: [ Child( name: "bindingSpecifier", - deprecatedName: "bindingKeyword", kind: .token(choices: [ .keyword(.let), .keyword(.var), .keyword(.inout), .keyword(._mutating), .keyword(._borrowing), .keyword(._consuming), @@ -436,6 +447,11 @@ public let STMT_NODES: [Node] = [ kind: .node(kind: .initializerClause), isOptional: true ), + ], + childHistory: [ + [ + "bindingSpecifier": .renamed(from: "bindingKeyword") + ] ] ), @@ -512,9 +528,13 @@ public let STMT_NODES: [Node] = [ ), Child( name: "condition", - deprecatedName: "guardResult", kind: .node(kind: .expr) ), + ], + childHistory: [ + [ + "condition": .renamed(from: "guardResult") + ] ] ), @@ -552,13 +572,17 @@ public let STMT_NODES: [Node] = [ ), Child( name: "elements", - deprecatedName: "elementList", kind: .collection(kind: .yieldedExpressionList, collectionElementName: "Element") ), Child( name: "rightParen", kind: .token(choices: [.token(.rightParen)]) ), + ], + childHistory: [ + [ + "elements": .renamed(from: "elementList") + ] ] ), @@ -573,20 +597,30 @@ public let STMT_NODES: [Node] = [ ), Child( name: "yieldedExpressions", - deprecatedName: "yields", - kind: .nodeChoices(choices: [ - Child( - name: "multiple", - deprecatedName: "yieldList", - kind: .node(kind: .yieldedExpressionsClause) - ), - Child( - name: "single", - deprecatedName: "simpleYield", - kind: .node(kind: .expr) - ), - ]) + kind: .nodeChoices( + choices: [ + Child( + name: "multiple", + kind: .node(kind: .yieldedExpressionsClause) + ), + Child( + name: "single", + kind: .node(kind: .expr) + ), + ], + childHistory: [ + [ + "multiple": .renamed(from: "yieldList"), + "single": .renamed(from: "simpleYield"), + ] + ] + ) ), + ], + childHistory: [ + [ + "yieldedExpressions": .renamed(from: "yields") + ] ] ), diff --git a/CodeGeneration/Sources/SyntaxSupport/Traits.swift b/CodeGeneration/Sources/SyntaxSupport/Traits.swift index 8838ecb7ad5..3e0ba28c536 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Traits.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Traits.swift @@ -23,13 +23,20 @@ public class Trait { public let documentation: SwiftSyntax.Trivia public let children: [Child] - init(traitName: String, baseKind: SyntaxNodeKind? = nil, documentation: String? = nil, children: [Child]) { + init( + traitName: String, + baseKind: SyntaxNodeKind? = nil, + documentation: String? = nil, + children: [Child], + childHistory: Child.History = [] + ) { precondition(baseKind?.isBase != false, "`baseKind` must be a base syntax node kind") self.traitName = traitName self.baseKind = baseKind self.protocolName = .identifier("\(traitName)Syntax") self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) self.children = children + // FIXME: We don't appear to have ever generated compatibility layers for children of traits! } } @@ -83,14 +90,21 @@ public let TRAITS: [Trait] = [ Trait( traitName: "FreestandingMacroExpansion", children: [ - Child(name: "pound", deprecatedName: "poundToken", kind: .token(choices: [.token(.pound)])), - Child(name: "macroName", deprecatedName: "macro", kind: .token(choices: [.token(.identifier)])), + Child(name: "pound", kind: .token(choices: [.token(.pound)])), + Child(name: "macroName", kind: .token(choices: [.token(.identifier)])), Child(name: "genericArgumentClause", kind: .node(kind: .genericArgumentClause), isOptional: true), Child(name: "leftParen", kind: .token(choices: [.token(.leftParen)]), isOptional: true), - Child(name: "arguments", deprecatedName: "argumentList", kind: .node(kind: .labeledExprList)), + Child(name: "arguments", kind: .node(kind: .labeledExprList)), Child(name: "rightParen", kind: .token(choices: [.token(.rightParen)]), isOptional: true), Child(name: "trailingClosure", kind: .node(kind: .closureExpr), isOptional: true), Child(name: "additionalTrailingClosures", kind: .node(kind: .multipleTrailingClosureElementList)), + ], + childHistory: [ + [ + "pound": .renamed(from: "poundToken"), + "macroName": .renamed(from: "macro"), + "arguments": .renamed(from: "argumentList"), + ] ] ), Trait( diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index 527843d4e90..fb88fa18776 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -18,19 +18,23 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "leftSquare", - deprecatedName: "leftSquareBracket", kind: .token(choices: [.token(.leftSquare)]) ), Child( name: "element", - deprecatedName: "elementType", kind: .node(kind: .type) ), Child( name: "rightSquare", - deprecatedName: "rightSquareBracket", kind: .token(choices: [.token(.rightSquare)]) ), + ], + childHistory: [ + [ + "leftSquare": .renamed(from: "leftSquareBracket"), + "element": .renamed(from: "elementType"), + "rightSquare": .renamed(from: "rightSquareBracket"), + ] ] ), @@ -120,9 +124,13 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "constraint", - deprecatedName: "baseType", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "constraint": .renamed(from: "baseType") + ] ] ), @@ -133,12 +141,10 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "leftSquare", - deprecatedName: "leftSquareBracket", kind: .token(choices: [.token(.leftSquare)]) ), Child( name: "key", - deprecatedName: "keyType", kind: .node(kind: .type), nameForDiagnostics: "key type" ), @@ -148,15 +154,21 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "value", - deprecatedName: "valueType", kind: .node(kind: .type), nameForDiagnostics: "value type" ), Child( name: "rightSquare", - deprecatedName: "rightSquareBracket", kind: .token(choices: [.token(.rightSquare)]) ), + ], + childHistory: [ + [ + "leftSquare": .renamed(from: "leftSquareBracket"), + "key": .renamed(from: "keyType"), + "value": .renamed(from: "valueType"), + "rightSquare": .renamed(from: "rightSquareBracket"), + ] ] ), @@ -174,7 +186,6 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "parameters", - deprecatedName: "arguments", kind: .collection( kind: .tupleTypeElementList, collectionElementName: "Parameter", @@ -192,9 +203,14 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "returnClause", - deprecatedName: "output", kind: .node(kind: .returnClause) ), + ], + childHistory: [ + [ + "parameters": .renamed(from: "arguments"), + "returnClause": .renamed(from: "output"), + ] ] ), @@ -205,7 +221,6 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "leftAngle", - deprecatedName: "leftAngleBracket", kind: .token(choices: [.token(.leftAngle)]) ), Child( @@ -214,9 +229,14 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "rightAngle", - deprecatedName: "rightAngleBracket", kind: .token(choices: [.token(.rightAngle)]) ), + ], + childHistory: [ + [ + "leftAngle": .renamed(from: "leftAngleBracket"), + "rightAngle": .renamed(from: "rightAngleBracket"), + ] ] ), @@ -237,7 +257,6 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "argument", - deprecatedName: "argumentType", kind: .node(kind: .type) ), Child( @@ -245,6 +264,11 @@ public let TYPE_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "argument": .renamed(from: "argumentType") + ] ] ), @@ -307,9 +331,13 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "metatypeSpecifier", - deprecatedName: "typeOrProtocol", kind: .token(choices: [.keyword(.Type), .keyword(.Protocol)]) ), + ], + childHistory: [ + [ + "metatypeSpecifier": .renamed(from: "typeOrProtocol") + ] ] ), @@ -320,15 +348,19 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "genericParameterClause", - deprecatedName: "genericParameters", kind: .node(kind: .genericParameterClause), documentation: "The parameter clause that defines the generic parameters." ), Child( name: "type", - deprecatedName: "baseType", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "genericParameterClause": .renamed(from: "genericParameters"), + "type": .renamed(from: "baseType"), + ] ] ), @@ -359,9 +391,13 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "type", - deprecatedName: "patternType", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "type": .renamed(from: "patternType") + ] ] ), @@ -376,9 +412,13 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "repetitionPattern", - deprecatedName: "patternType", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "repetitionPattern": .renamed(from: "patternType") + ] ] ), @@ -393,9 +433,13 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "pack", - deprecatedName: "packType", kind: .node(kind: .type) ), + ], + childHistory: [ + [ + "pack": .renamed(from: "packType") + ] ] ), @@ -438,13 +482,11 @@ public let TYPE_NODES: [Node] = [ children: [ Child( name: "inoutKeyword", - deprecatedName: "inOut", kind: .token(choices: [.keyword(.inout)]), isOptional: true ), Child( name: "firstName", - deprecatedName: "name", kind: .token(choices: [.token(.identifier), .token(.wildcard)]), nameForDiagnostics: "name", isOptional: true @@ -474,6 +516,12 @@ public let TYPE_NODES: [Node] = [ kind: .token(choices: [.token(.comma)]), isOptional: true ), + ], + childHistory: [ + [ + "inoutKeyword": .renamed(from: "inOut"), + "firstName": .renamed(from: "name"), + ] ] ), diff --git a/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift b/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift index f69d43b06e0..cb60587520d 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/ChildNodeChoices.swift @@ -80,7 +80,7 @@ extension Node { if let node = self.layoutNode { return node.children.compactMap { child in switch child.kind { - case .nodeChoices(let choices): + case .nodeChoices(let choices, _): return ChildNodeChoices( name: child.syntaxChoicesType, choices: choices.map { ChildNodeChoices.Choice($0, forRaw: forRaw) } diff --git a/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift b/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift index 287b987538b..97a61847829 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/InitSignature+Extensions.swift @@ -205,7 +205,7 @@ fileprivate func convertFromSyntaxProtocolToSyntaxType( extension InitSignature { /// Interprets `self` as an initializer parameter list and generates arguments to /// call the non-deprecated initializer. This will generate nested initializer calls for - /// any children with a compound `newerChildPath`. + /// any children with a compound `newestChildPath`. func makeArgumentsToInitializeNewestChildren() -> [LabeledExprSyntax] { var root: [InitParameterMapping] = [] @@ -250,19 +250,19 @@ extension InitSignature { /// ```swift /// [ /// InitParameterMapping( -/// newerChild: "child for current LongstandingNode.a", +/// newestChild: "child for current LongstandingNode.a", /// argument: .decl("child for historical LongstandingNode.b") /// ), /// InitParameterMapping( -/// newerChild: "child for current LongstandingNode.nested", +/// newestChild: "child for current LongstandingNode.nested", /// argument: .nestedInit( /// [ /// InitParameterMapping( -/// newerChild: "child for current NestedNodeExtractedLater.x", +/// newestChild: "child for current NestedNodeExtractedLater.x", /// argument: .decl("child for historical LongstandingNode.x") /// ), /// InitParameterMapping( -/// newerChild: "child for current NestedNodeExtractedLater.y", +/// newestChild: "child for current NestedNodeExtractedLater.y", /// argument: .decl("child for historical LongstandingNode.y") /// ) /// ] @@ -285,20 +285,64 @@ extension InitSignature { /// ) /// ``` private struct InitParameterMapping { - var newerChild: Child + var newestChild: Child var argument: Argument enum Argument { case decl(olderChild: Child) + case nestedInit([InitParameterMapping]) } static func addChild(_ olderChild: Child, to mappings: inout [InitParameterMapping]) { - mappings.append( - InitParameterMapping( - newerChild: olderChild.newestChild ?? olderChild, - argument: .decl(olderChild: olderChild) + guard !olderChild.newestChildPath.isEmpty else { + // This child is not historical, so we can just pass it right through. + mappings.append( + InitParameterMapping( + newestChild: olderChild, + argument: .decl(olderChild: olderChild) + ) ) - ) + return + } + + addChild(olderChild, to: &mappings, at: olderChild.newestChildPath[...]) + } + + private static func addChild( + _ olderChild: Child, + to mappings: inout [InitParameterMapping], + at newestChildPath: ArraySlice + ) { + let targetNewestChild = newestChildPath.first! + + if newestChildPath.count == 1 { + // We've found the argument list this ought to be added to. + let newMapping = InitParameterMapping(newestChild: targetNewestChild, argument: .decl(olderChild: olderChild)) + mappings.append(newMapping) + return + } + + // We've found a parent of the argument list this ought to be added to. + var (i, nestedArgMappings) = findOrCreateNestedInit(for: targetNewestChild, in: &mappings) + addChild(olderChild, to: &nestedArgMappings, at: newestChildPath.dropFirst()) + mappings[i].argument = .nestedInit(nestedArgMappings) + } + + private static func findOrCreateNestedInit( + for newestChild: Child, + in mappings: inout [InitParameterMapping] + ) -> (index: Int, nestedArgMapping: [InitParameterMapping]) { + // If there isn't an existing mapping, we'll append a new one. + guard let i = mappings.firstIndex(where: { $0.newestChild == newestChild }) else { + mappings.append(InitParameterMapping(newestChild: newestChild, argument: .nestedInit([]))) + return (mappings.endIndex - 1, []) + } + + // We found an existing mapping for this child and its nested children. + guard case .nestedInit(let nestedArgs) = mappings[i].argument else { + fatalError("Can't nest parameter inside parameter!") + } + return (i, nestedArgs) } } @@ -308,10 +352,19 @@ extension InitParameterMapping { switch argument { case .decl(olderChild: let olderChild): ExprSyntax(DeclReferenceExprSyntax(baseName: olderChild.baseCallName)) + + case .nestedInit(let initArgs): + ExprSyntax( + FunctionCallExprSyntax(callee: TypeExprSyntax(type: newestChild.syntaxNodeKind.syntaxType)) { + for initArg in initArgs { + initArg.makeArgumentExpr() + } + } + ) } return LabeledExprSyntax( - label: newerChild.isUnexpectedNodes ? nil : newerChild.name, + label: newestChild.isUnexpectedNodes ? nil : newestChild.name, expression: argValue ) } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/Array+Child.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/Array+Child.swift deleted file mode 100644 index 3f13cf3f33c..00000000000 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/Array+Child.swift +++ /dev/null @@ -1,19 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 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 SyntaxSupport - -extension Array where Element == Child { - var hasDeprecatedChild: Bool { - return self.contains(where: { $0.hasDeprecatedName }) - } -} diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxValidationFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxValidationFile.swift index edd459d3c0f..4431bf6bcc6 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxValidationFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxValidationFile.swift @@ -204,7 +204,7 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead ExprSyntax("assert(layout.count == \(raw: node.children.count))") for (index, child) in node.children.enumerated() { switch child.kind { - case .nodeChoices(let choices): + case .nodeChoices(let choices, _): let verifiedChoices = ArrayExprSyntax { ArrayElementSyntax( leadingTrivia: .newline, diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift index a5a38da365f..edfbf01c425 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift @@ -16,7 +16,7 @@ import SyntaxSupport import Utils let renamedChildrenCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copyrightHeader) { - for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ $0.children.hasDeprecatedChild }) { + for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ !$0.childHistory.isEmpty }) { var deprecatedMembers = SYNTAX_COMPATIBILITY_LAYER.deprecatedMembers(for: layoutNode) try ExtensionDeclSyntax("extension \(layoutNode.type.syntaxBaseName)") { @@ -41,9 +41,12 @@ func makeCompatibilityVar(for child: Child) -> DeclSyntax { let type = child.isOptional ? TypeSyntax("\(childType)?") : childType // Form the access chain for the current name. - let childPath = child.newestChild ?? child - let childPathString = childPath.name - let childAccess = ExprSyntax(DeclReferenceExprSyntax(baseName: childPath.baseCallName)) + let childPath = child.newestChildPath + let childPathString = childPath.map(\.name).joined(separator: ".") + let childBase = ExprSyntax(DeclReferenceExprSyntax(baseName: childPath.first!.baseCallName)) + let childAccess = childPath.dropFirst().reduce(childBase) { base, child in + ExprSyntax(MemberAccessExprSyntax(base: base, name: child.baseCallName)) + } return DeclSyntax( """ diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift index 261118895d6..1785144c1d0 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift @@ -26,7 +26,7 @@ let renamedChildrenBuilderCompatibilityFile = try! SourceFileSyntax(leadingTrivi """ ) - for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ $0.children.hasDeprecatedChild }) { + for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ !$0.childHistory.isEmpty }) { let deprecatedMembers = SYNTAX_COMPATIBILITY_LAYER.deprecatedMembers(for: layoutNode) for signature in deprecatedMembers.inits { diff --git a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift index 8e071ea628f..c9f81c34a9b 100644 --- a/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift +++ b/CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift @@ -53,7 +53,7 @@ fileprivate extension ChildKind { switch (self, other) { case (.node(let kind), .node(kind: let otherKind)): return kind == otherKind - case (.nodeChoices(let choices), .nodeChoices(let otherChoices)): + case (.nodeChoices(let choices, _), .nodeChoices(let otherChoices, _)): return choices.count == otherChoices.count && zip(choices, otherChoices).allSatisfy { $0.hasSameType(as: $1) } case (.collection(kind: let kind, _, _, _), .collection(kind: let otherKind, _, _, _)): return kind == otherKind @@ -71,7 +71,7 @@ fileprivate extension ChildKind { var isCollection: Bool { switch self { case .node: return false - case .nodeChoices(let choices): return choices.contains(where: { $0.kind.isCollection }) + case .nodeChoices(let choices, _): return choices.contains(where: { $0.kind.isCollection }) case .collection: return true case .token: return false } From f1fcb10cd5b95fd675d69ec377cd2ef74de51e8b Mon Sep 17 00:00:00 2001 From: Becca Royal-Gordon Date: Mon, 4 Nov 2024 18:16:24 -0800 Subject: [PATCH 4/4] [NFC-ish] Support child history for traits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s always been possible to specify deprecated children, but nothing was actually done with the info until now. Turns some manaully-generated decls into automatically-generated ones, but doesn’t change anything user-facing. --- .../SyntaxSupport/CompatibilityLayer.swift | 72 +++++++++++++++---- .../Sources/SyntaxSupport/SyntaxNodes.swift | 2 +- .../Sources/SyntaxSupport/Traits.swift | 4 +- .../RenamedChildrenCompatibilityFile.swift | 15 ++++ .../SwiftSyntaxCompatibility.swift | 42 ----------- .../RenamedChildrenCompatibility.swift | 42 +++++++++++ 6 files changed, 121 insertions(+), 56 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift b/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift index da626d96a3d..f95f3143669 100644 --- a/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift +++ b/CodeGeneration/Sources/SyntaxSupport/CompatibilityLayer.swift @@ -15,6 +15,9 @@ public struct CompatibilityLayer { /// Deprecated members that the compatibility layer needs for each node. private var deprecatedMembersByNode: [SyntaxNodeKind: DeprecatedMemberInfo] = [:] + /// Deprecated members that the compatibility layer needs for each trait. + public var deprecatedMembersByTrait: [String: DeprecatedMemberInfo] = [:] + /// Cache for `replacementChildren(for:by:)`. Ensures that we don't create two different replacement children even /// if we refactor the same child twice, so we can reliably equate and hash `Child` objects by object identity. private var cachedReplacementChildren: [Child: [Child]] = [:] @@ -24,13 +27,21 @@ public struct CompatibilityLayer { return deprecatedMembersByNode[node.kind] ?? DeprecatedMemberInfo() } - internal init(nodes: [Node]) { + /// Returns the deprecated members that the compatibility layer needs for `trait`. + public func deprecatedMembers(for trait: Trait) -> DeprecatedMemberInfo { + return deprecatedMembersByTrait[trait.traitName] ?? DeprecatedMemberInfo() + } + + internal init(nodes: [Node], traits: [Trait]) { // This instance will be stored in a global that's used from multiple threads simultaneously, so it won't be safe // to mutate once the initializer returns. We therefore do all the work to populate its tables up front, rather // than computing it lazily on demand. for node in nodes { computeMembers(for: node) } + for trait in traits { + computeMembers(for: trait) + } } /// Returns the child or children that would have existed in place of this @@ -79,24 +90,56 @@ public struct CompatibilityLayer { return } + let result = computeMembersFor( + typeName: layoutNode.kind.rawValue, + initialChildren: layoutNode.children, + history: layoutNode.childHistory, + areRequirements: false + ) + + deprecatedMembersByNode[node.syntaxNodeKind] = result + } + + private mutating func computeMembers(for trait: Trait) { + guard deprecatedMembersByTrait[trait.traitName] == nil else { + return + } + + let result = computeMembersFor( + typeName: trait.traitName, + initialChildren: trait.children, + history: trait.childHistory, + areRequirements: true + ) + + deprecatedMembersByTrait[trait.traitName] = result + } + + /// Compute and cache compatibility layer information for the given children. + private mutating func computeMembersFor( + typeName: String, + initialChildren: [Child], + history: Child.History, + areRequirements: Bool + ) -> DeprecatedMemberInfo { // The results that will ultimately be saved into the DeprecatedMemberInfo. var vars: [Child] = [] var initSignatures: [InitSignature] = [] // Temporary working state for the loop. - var children = layoutNode.children + var children = initialChildren var knownVars = Set(children) func firstIndexOfChild(named targetName: String) -> Int { guard let i = children.firstIndex(where: { $0.name == targetName }) else { fatalError( - "couldn't find '\(targetName)' in current children of \(node.syntaxNodeKind.rawValue): \(String(reflecting: children.map(\.name)))" + "couldn't find '\(targetName)' in current children of \(typeName): \(String(reflecting: children.map(\.name)))" ) } return i } - for changeSet in layoutNode.childHistory { + for changeSet in history { var unexpectedChildrenWithNewNames: Set = [] // First pass: Apply the changes explicitly specified in the change set. @@ -106,12 +149,14 @@ public struct CompatibilityLayer { let replacementChildren = replacementChildren(for: children[i], by: refactoring) children.replaceSubrange(i...i, with: replacementChildren) - // Mark adjacent unexpected node children whose names have changed too. - if currentName != replacementChildren.first?.name { - unexpectedChildrenWithNewNames.insert(children[i - 1]) - } - if currentName != replacementChildren.last?.name { - unexpectedChildrenWithNewNames.insert(children[i + replacementChildren.count]) + if !areRequirements { + // Mark adjacent unexpected node children whose names have changed too. + if currentName != replacementChildren.first?.name { + unexpectedChildrenWithNewNames.insert(children[i - 1]) + } + if currentName != replacementChildren.last?.name { + unexpectedChildrenWithNewNames.insert(children[i + replacementChildren.count]) + } } } @@ -134,10 +179,13 @@ public struct CompatibilityLayer { // Third pass: Append newly-created children to vars. We do this now so that changes from the first two passes are properly interleaved, preserving source order. vars += children.filter { knownVars.insert($0).inserted } - initSignatures.append(InitSignature(children: children)) + // We don't create compatibility layers for protocol requirement inits. + if !areRequirements { + initSignatures.append(InitSignature(children: children)) + } } - deprecatedMembersByNode[node.syntaxNodeKind] = DeprecatedMemberInfo(vars: vars, inits: initSignatures) + return DeprecatedMemberInfo(vars: vars, inits: initSignatures) } } diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift index ee3a5c68fad..9aacf83125c 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodes.swift @@ -36,4 +36,4 @@ public let SYNTAX_NODE_MAP: [SyntaxNodeKind: Node] = Dictionary( public let NON_BASE_SYNTAX_NODES = SYNTAX_NODES.filter { !$0.kind.isBase } -public let SYNTAX_COMPATIBILITY_LAYER = CompatibilityLayer(nodes: SYNTAX_NODES) +public let SYNTAX_COMPATIBILITY_LAYER = CompatibilityLayer(nodes: SYNTAX_NODES, traits: TRAITS) diff --git a/CodeGeneration/Sources/SyntaxSupport/Traits.swift b/CodeGeneration/Sources/SyntaxSupport/Traits.swift index 3e0ba28c536..c9eb2828931 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Traits.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Traits.swift @@ -22,6 +22,7 @@ public class Trait { public let protocolName: TokenSyntax public let documentation: SwiftSyntax.Trivia public let children: [Child] + public let childHistory: Child.History init( traitName: String, @@ -36,7 +37,7 @@ public class Trait { self.protocolName = .identifier("\(traitName)Syntax") self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) self.children = children - // FIXME: We don't appear to have ever generated compatibility layers for children of traits! + self.childHistory = childHistory } } @@ -104,6 +105,7 @@ public let TRAITS: [Trait] = [ "pound": .renamed(from: "poundToken"), "macroName": .renamed(from: "macro"), "arguments": .renamed(from: "argumentList"), + "genericArgumentClause": .renamed(from: "genericArguments"), ] ] ), diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift index edfbf01c425..131b51bc1de 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift @@ -33,6 +33,21 @@ let renamedChildrenCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copy } } } + + for trait in TRAITS.filter({ !$0.childHistory.isEmpty }) { + var deprecatedMembers = SYNTAX_COMPATIBILITY_LAYER.deprecatedMembers(for: trait) + + try ExtensionDeclSyntax("extension \(trait.protocolName)") { + for child in deprecatedMembers.vars { + makeCompatibilityVar(for: child) + if let addMethod = makeCompatibilityAddMethod(for: child) { + addMethod + } + } + + // Not currently generating compatibility inits for traits. + } + } } func makeCompatibilityVar(for child: Child) -> DeclSyntax { diff --git a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift index b8e61931d62..c9903d9c2f6 100644 --- a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift +++ b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift @@ -350,48 +350,6 @@ extension FunctionEffectSpecifiersSyntax { } } -extension FreestandingMacroExpansionSyntax { - @available(*, deprecated, renamed: "pound") - public var poundToken: TokenSyntax { - get { - return pound - } - set { - pound = newValue - } - } - - @available(*, deprecated, renamed: "macroName") - public var macro: TokenSyntax { - get { - return macroName - } - set { - macroName = newValue - } - } - - @available(*, deprecated, renamed: "genericArgumentClause") - public var genericArguments: GenericArgumentClauseSyntax? { - get { - return genericArgumentClause - } - set { - genericArgumentClause = newValue - } - } - - @available(*, deprecated, renamed: "arguments") - public var argumentList: LabeledExprListSyntax { - get { - return arguments - } - set { - arguments = newValue - } - } -} - extension GenericRequirementSyntax { @available(*, deprecated, renamed: "Requirement") public typealias Body = Requirement diff --git a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift index 1ba94a98dcb..fb3cd840904 100644 --- a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift @@ -8559,3 +8559,45 @@ extension YieldedExpressionsClauseSyntax { ) } } + +extension FreestandingMacroExpansionSyntax { + @available(*, deprecated, renamed: "pound") + public var poundToken: TokenSyntax { + get { + return pound + } + set { + pound = newValue + } + } + + @available(*, deprecated, renamed: "macroName") + public var macro: TokenSyntax { + get { + return macroName + } + set { + macroName = newValue + } + } + + @available(*, deprecated, renamed: "genericArgumentClause") + public var genericArguments: GenericArgumentClauseSyntax? { + get { + return genericArgumentClause + } + set { + genericArgumentClause = newValue + } + } + + @available(*, deprecated, renamed: "arguments") + public var argumentList: LabeledExprListSyntax { + get { + return arguments + } + set { + arguments = newValue + } + } +}