From 927ed65730b4630b2ae428d1478156a0bae3f28f Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Tue, 18 Mar 2025 13:30:19 -0700 Subject: [PATCH 1/3] Remove ValueGenerics feature from swift-syntax --- .../SyntaxSupport/ExperimentalFeatures.swift | 5 -- .../Sources/SyntaxSupport/GenericNodes.swift | 6 +- .../Sources/SyntaxSupport/TypeNodes.swift | 3 +- Sources/SwiftParser/Types.swift | 6 -- .../generated/ExperimentalFeatures.swift | 11 +--- .../generated/raw/RawSyntaxNodesGHI.swift | 4 -- .../generated/raw/RawSyntaxNodesQRS.swift | 8 --- .../syntaxNodes/SyntaxNodesGHI.swift | 10 ---- .../syntaxNodes/SyntaxNodesQRS.swift | 20 ------- .../SwiftParserTest/ValueGenericsTests.swift | 57 +++++++------------ 10 files changed, 25 insertions(+), 105 deletions(-) diff --git a/CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift b/CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift index affe9c1b03f..bdc09c1f462 100644 --- a/CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift +++ b/CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift @@ -19,7 +19,6 @@ public enum ExperimentalFeature: String, CaseIterable { case nonescapableTypes case trailingComma case coroutineAccessors - case valueGenerics case abiAttribute case keypathWithMethodMembers case oldOwnershipOperatorSpellings @@ -40,8 +39,6 @@ public enum ExperimentalFeature: String, CaseIterable { return "TrailingComma" case .coroutineAccessors: return "CoroutineAccessors" - case .valueGenerics: - return "ValueGenerics" case .abiAttribute: return "ABIAttribute" case .keypathWithMethodMembers: @@ -68,8 +65,6 @@ public enum ExperimentalFeature: String, CaseIterable { return "trailing commas" case .coroutineAccessors: return "coroutine accessors" - case .valueGenerics: - return "value generics" case .abiAttribute: return "@abi attribute" case .keypathWithMethodMembers: diff --git a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift index a54368b8dd6..c6254e9ebd1 100644 --- a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift @@ -341,8 +341,7 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "expr", - kind: .node(kind: .expr), - experimentalFeature: .valueGenerics + kind: .node(kind: .expr) ), ]), nameForDiagnostics: "left-hand type", @@ -362,8 +361,7 @@ public let GENERIC_NODES: [Node] = [ ), Child( name: "expr", - kind: .node(kind: .expr), - experimentalFeature: .valueGenerics + kind: .node(kind: .expr) ), ]), nameForDiagnostics: "right-hand type", diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift index 1dfac971f8b..9b9aa3c6e1e 100644 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -264,8 +264,7 @@ public let TYPE_NODES: [Node] = [ ), Child( name: "expr", - kind: .node(kind: .expr), - experimentalFeature: .valueGenerics + kind: .node(kind: .expr) ), ]), documentation: diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index 4a672a1c734..3797dd33b64 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -1233,12 +1233,6 @@ extension Parser { extension Parser { mutating func parseValueType() -> RawExprSyntax? { - // If the 'ValueGenerics' experimental feature hasn't been added, then don't - // attempt to parse values as types. - guard self.experimentalFeatures.contains(.valueGenerics) else { - return nil - } - // Eat any '-' preceding integer literals. var minusSign: RawTokenSyntax? = nil if self.atContextualPunctuator("-"), diff --git a/Sources/SwiftParser/generated/ExperimentalFeatures.swift b/Sources/SwiftParser/generated/ExperimentalFeatures.swift index e31d3628ee3..d4412cabff8 100644 --- a/Sources/SwiftParser/generated/ExperimentalFeatures.swift +++ b/Sources/SwiftParser/generated/ExperimentalFeatures.swift @@ -43,17 +43,14 @@ extension Parser.ExperimentalFeatures { /// Whether to enable the parsing of coroutine accessors. public static let coroutineAccessors = Self (rawValue: 1 << 5) - /// Whether to enable the parsing of value generics. - public static let valueGenerics = Self (rawValue: 1 << 6) - /// Whether to enable the parsing of @abi attribute. - public static let abiAttribute = Self (rawValue: 1 << 7) + public static let abiAttribute = Self (rawValue: 1 << 6) /// Whether to enable the parsing of keypaths with method members. - public static let keypathWithMethodMembers = Self (rawValue: 1 << 8) + public static let keypathWithMethodMembers = Self (rawValue: 1 << 7) /// Whether to enable the parsing of `_move` and `_borrow` as ownership operators. - public static let oldOwnershipOperatorSpellings = Self (rawValue: 1 << 9) + public static let oldOwnershipOperatorSpellings = Self (rawValue: 1 << 8) /// Whether to enable the parsing of sugar type for InlineArray. public static let inlineArrayTypeSugar = Self (rawValue: 1 << 10) @@ -74,8 +71,6 @@ extension Parser.ExperimentalFeatures { self = .trailingComma case "CoroutineAccessors": self = .coroutineAccessors - case "ValueGenerics": - self = .valueGenerics case "ABIAttribute": self = .abiAttribute case "KeypathWithMethodMembers": diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesGHI.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesGHI.swift index e9a35bc50ac..dfe5fc4d0e6 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesGHI.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesGHI.swift @@ -149,8 +149,6 @@ public struct RawGenericArgumentListSyntax: RawSyntaxNodeProtocol { public struct RawGenericArgumentSyntax: RawSyntaxNodeProtocol { public enum Argument: RawSyntaxNodeProtocol { case type(RawTypeSyntax) - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) case expr(RawExprSyntax) public static func isKindOf(_ raw: RawSyntax) -> Bool { @@ -180,8 +178,6 @@ public struct RawGenericArgumentSyntax: RawSyntaxNodeProtocol { self = .type(RawTypeSyntax(type)) } - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public init(expr: some RawExprSyntaxNodeProtocol) { self = .expr(RawExprSyntax(expr)) } diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift index fdfa430ff8e..e4313ae32a7 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift @@ -360,8 +360,6 @@ public struct RawReturnStmtSyntax: RawStmtSyntaxNodeProtocol { public struct RawSameTypeRequirementSyntax: RawSyntaxNodeProtocol { public enum LeftType: RawSyntaxNodeProtocol { case type(RawTypeSyntax) - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) case expr(RawExprSyntax) public static func isKindOf(_ raw: RawSyntax) -> Bool { @@ -391,8 +389,6 @@ public struct RawSameTypeRequirementSyntax: RawSyntaxNodeProtocol { self = .type(RawTypeSyntax(type)) } - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public init(expr: some RawExprSyntaxNodeProtocol) { self = .expr(RawExprSyntax(expr)) } @@ -400,8 +396,6 @@ public struct RawSameTypeRequirementSyntax: RawSyntaxNodeProtocol { public enum RightType: RawSyntaxNodeProtocol { case type(RawTypeSyntax) - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) case expr(RawExprSyntax) public static func isKindOf(_ raw: RawSyntax) -> Bool { @@ -431,8 +425,6 @@ public struct RawSameTypeRequirementSyntax: RawSyntaxNodeProtocol { self = .type(RawTypeSyntax(type)) } - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public init(expr: some RawExprSyntaxNodeProtocol) { self = .expr(RawExprSyntax(expr)) } diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift index b8daf36f8cf..d28ff8b926b 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift @@ -209,8 +209,6 @@ public struct GenericArgumentClauseSyntax: SyntaxProtocol, SyntaxHashable, _Leaf public struct GenericArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { public enum Argument: SyntaxChildChoices, SyntaxHashable { case type(TypeSyntax) - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) case expr(ExprSyntax) public var _syntaxNode: Syntax { @@ -226,8 +224,6 @@ public struct GenericArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntax self = .type(TypeSyntax(node)) } - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public init(_ node: some ExprSyntaxProtocol) { self = .expr(ExprSyntax(node)) } @@ -271,8 +267,6 @@ public struct GenericArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntax /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. /// /// - Returns: `true` if the node can be cast, `false` otherwise. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func `is`(_ syntaxType: (some ExprSyntaxProtocol).Type) -> Bool { return self.as(syntaxType) != nil } @@ -280,8 +274,6 @@ public struct GenericArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntax /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. /// /// - Returns: An instance of the specialized type, or `nil` if the cast fails. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func `as`(_ syntaxType: S.Type) -> S? { return S.init(self) } @@ -290,8 +282,6 @@ public struct GenericArgumentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntax /// /// - Returns: An instance of the specialized type. /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func cast(_ syntaxType: S.Type) -> S { return self.as(S.self)! } diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift index 14d229cf2d3..2ca36e3f4a8 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift @@ -657,8 +657,6 @@ public struct ReturnStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSyn public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { public enum LeftType: SyntaxChildChoices, SyntaxHashable { case type(TypeSyntax) - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) case expr(ExprSyntax) public var _syntaxNode: Syntax { @@ -674,8 +672,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy self = .type(TypeSyntax(node)) } - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public init(_ node: some ExprSyntaxProtocol) { self = .expr(ExprSyntax(node)) } @@ -719,8 +715,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. /// /// - Returns: `true` if the node can be cast, `false` otherwise. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func `is`(_ syntaxType: (some ExprSyntaxProtocol).Type) -> Bool { return self.as(syntaxType) != nil } @@ -728,8 +722,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. /// /// - Returns: An instance of the specialized type, or `nil` if the cast fails. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func `as`(_ syntaxType: S.Type) -> S? { return S.init(self) } @@ -738,8 +730,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// /// - Returns: An instance of the specialized type. /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func cast(_ syntaxType: S.Type) -> S { return self.as(S.self)! } @@ -747,8 +737,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy public enum RightType: SyntaxChildChoices, SyntaxHashable { case type(TypeSyntax) - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) case expr(ExprSyntax) public var _syntaxNode: Syntax { @@ -764,8 +752,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy self = .type(TypeSyntax(node)) } - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public init(_ node: some ExprSyntaxProtocol) { self = .expr(ExprSyntax(node)) } @@ -809,8 +795,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// Checks if the current syntax node can be cast to the type conforming to the ``ExprSyntaxProtocol`` protocol. /// /// - Returns: `true` if the node can be cast, `false` otherwise. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func `is`(_ syntaxType: (some ExprSyntaxProtocol).Type) -> Bool { return self.as(syntaxType) != nil } @@ -818,8 +802,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// Attempts to cast the current syntax node to the type conforming to the ``ExprSyntaxProtocol`` protocol. /// /// - Returns: An instance of the specialized type, or `nil` if the cast fails. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func `as`(_ syntaxType: S.Type) -> S? { return S.init(self) } @@ -828,8 +810,6 @@ public struct SameTypeRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy /// /// - Returns: An instance of the specialized type. /// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast. - /// - Note: Requires experimental feature `valueGenerics`. - @_spi(ExperimentalLanguageFeatures) public func cast(_ syntaxType: S.Type) -> S { return self.as(S.self)! } diff --git a/Tests/SwiftParserTest/ValueGenericsTests.swift b/Tests/SwiftParserTest/ValueGenericsTests.swift index cc0620b06d5..7ff15a96dc9 100644 --- a/Tests/SwiftParserTest/ValueGenericsTests.swift +++ b/Tests/SwiftParserTest/ValueGenericsTests.swift @@ -121,64 +121,55 @@ final class ValueGenericsTests: ParserTestCase { ], fixedSource: """ let x: <#type#> = 123 - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x: Generic<123> - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x: Generic<-123> - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x = Generic<123>.self - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x = Generic<-123>.self - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x = Generic<123, Int>.self - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x = Generic<-123, Int>.self - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x = Generic.self - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ let x: Generic.self - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( @@ -193,36 +184,31 @@ final class ValueGenericsTests: ParserTestCase { ], fixedSource: """ typealias One = <#type#>1 - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ extension Vector where N == 123 {} - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ extension Vector where 123 == N {} - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ extension Vector where N == -123 {} - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( """ extension Vector where -123 == N {} - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( @@ -240,8 +226,7 @@ final class ValueGenericsTests: ParserTestCase { ], fixedSource: """ extension Vector where N: <#type#> 123 {} - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( @@ -259,8 +244,7 @@ final class ValueGenericsTests: ParserTestCase { ], fixedSource: """ extension Vector where N: <#type#> -123 {} - """, - experimentalFeatures: .valueGenerics + """ ) assertParse( @@ -274,8 +258,7 @@ final class ValueGenericsTests: ParserTestCase { DiagnosticSpec( message: "unexpected code ': N' in extension" ), - ], - experimentalFeatures: .valueGenerics + ] ) assertParse( @@ -289,8 +272,7 @@ final class ValueGenericsTests: ParserTestCase { DiagnosticSpec( message: "unexpected code ': N' in extension" ), - ], - experimentalFeatures: .valueGenerics + ] ) assertParse( @@ -302,8 +284,7 @@ final class ValueGenericsTests: ParserTestCase { ), DiagnosticSpec(message: "unexpected code '-1' in tuple type"), ], - fixedSource: "func foo() -> (<#type#>-1) X", - experimentalFeatures: [.valueGenerics] + fixedSource: "func foo() -> (<#type#>-1) X" ) } } From 13bfb9cd49cfe0fb76e6f4fc60e1f25890eaf0fd Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 26 Mar 2025 09:44:36 -0700 Subject: [PATCH 2/3] Remove more value generics in tests --- Tests/SwiftParserTest/ExpressionTypeTests.swift | 2 +- Tests/SwiftParserTest/TypeTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/SwiftParserTest/ExpressionTypeTests.swift b/Tests/SwiftParserTest/ExpressionTypeTests.swift index b274e41d6d9..5def6ec1241 100644 --- a/Tests/SwiftParserTest/ExpressionTypeTests.swift +++ b/Tests/SwiftParserTest/ExpressionTypeTests.swift @@ -138,7 +138,7 @@ final class ExpressionTypeTests: ParserTestCase { { ExprSyntax.parse(from: &$0) }, substructure: IdentifierTypeSyntax(name: .identifier("X")), substructureAfterMarker: "1️⃣", - experimentalFeatures: [.inlineArrayTypeSugar, .valueGenerics], + experimentalFeatures: [.inlineArrayTypeSugar], line: line ) } diff --git a/Tests/SwiftParserTest/TypeTests.swift b/Tests/SwiftParserTest/TypeTests.swift index a903e440205..588c1be8beb 100644 --- a/Tests/SwiftParserTest/TypeTests.swift +++ b/Tests/SwiftParserTest/TypeTests.swift @@ -541,7 +541,7 @@ final class TypeTests: ParserTestCase { final class InlineArrayTypeTests: ParserTestCase { override var experimentalFeatures: Parser.ExperimentalFeatures { - [.inlineArrayTypeSugar, .valueGenerics] + [.inlineArrayTypeSugar] } func testBasic() { From 3112311fd074b51920c0078742675f1617a6fc70 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 26 Mar 2025 10:59:35 -0700 Subject: [PATCH 3/3] Update ExperimentalFeatures.swift --- Sources/SwiftParser/generated/ExperimentalFeatures.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftParser/generated/ExperimentalFeatures.swift b/Sources/SwiftParser/generated/ExperimentalFeatures.swift index d4412cabff8..77c5206bb99 100644 --- a/Sources/SwiftParser/generated/ExperimentalFeatures.swift +++ b/Sources/SwiftParser/generated/ExperimentalFeatures.swift @@ -53,7 +53,7 @@ extension Parser.ExperimentalFeatures { public static let oldOwnershipOperatorSpellings = Self (rawValue: 1 << 8) /// Whether to enable the parsing of sugar type for InlineArray. - public static let inlineArrayTypeSugar = Self (rawValue: 1 << 10) + public static let inlineArrayTypeSugar = Self (rawValue: 1 << 9) /// Creates a new value representing the experimental feature with the /// given name, or returns nil if the name is not recognized.