Skip to content

Add support for SE-0460 @specialized #3082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public let ATTRIBUTE_NODES: [Node] = [
// Special arguments for keyword decl name e.g. 'subscript(_:)', and availability arguments.
kind: .node(kind: .specializeAttributeArgumentList)
),
Child(
name: "specializedArguments",
// Special arguments for generic where clause.
kind: .node(kind: .specializedAttributeArgument)
),
Child(
name: "objCName",
// Special arguments for Objective-C names. e.g. 'methodNameWithArg1:Arg2:'
Expand Down Expand Up @@ -717,6 +722,19 @@ public let ATTRIBUTE_NODES: [Node] = [
]
),

Node(
kind: .specializedAttributeArgument,
base: .syntax,
nameForDiagnostics: "argument to '@specialized",
documentation: "The generic where clause for the `@specialized` attribute",
children: [
Child(
name: "genericWhereClause",
kind: .node(kind: .genericWhereClause)
)
]
),

Node(
kind: .specializeTargetFunctionArgument,
base: .syntax,
Expand Down
3 changes: 3 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public enum Keyword: CaseIterable {
case _PackageDescription
case _read
case _RefCountedObject
case specialized
case _specialize
case _spi_available
case _Trivial
Expand Down Expand Up @@ -340,6 +341,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("_read")
case ._RefCountedObject:
return KeywordSpec("_RefCountedObject")
case .specialized:
return KeywordSpec("specialized")
case ._specialize:
return KeywordSpec("_specialize")
case ._spi_available:
Expand Down
2 changes: 2 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon
case simpleStringLiteralSegmentList
case someOrAnyType
case sourceFile
case specializedAttributeArgument
case specializeAttributeArgumentList
case specializeAvailabilityArgument
case specializeTargetFunctionArgument
Expand Down Expand Up @@ -454,6 +455,7 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon
case .someOrAnyType: return "constrainedSugarType"
case .simpleTypeSpecifier: return "typeSpecifier"
case .specializeAttributeArgumentList: return "specializeAttributeSpecList"
case .specializedAttributeArgument: return "specializedAttribute"
case .specializeAvailabilityArgument: return "availabilityEntry"
case .specializeTargetFunctionArgument: return "targetFunctionEntry"
case .stringLiteralSegmentList: return "stringLiteralSegments"
Expand Down
12 changes: 12 additions & 0 deletions Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension Parser {
case _effects
case _implements
case _originallyDefinedIn
case specialized
case _specialize
case _spi_available
case `rethrows`
Expand All @@ -63,6 +64,7 @@ extension Parser {
case TokenSpec(._effects): self = ._effects
case TokenSpec(._implements): self = ._implements
case TokenSpec(._originallyDefinedIn): self = ._originallyDefinedIn
case TokenSpec(.specialized): self = .specialized
case TokenSpec(._specialize): self = ._specialize
case TokenSpec(._spi_available): self = ._spi_available
case TokenSpec(.`rethrows`): self = .rethrows
Expand All @@ -89,6 +91,7 @@ extension Parser {
case ._effects: return .keyword(._effects)
case ._implements: return .keyword(._implements)
case ._originallyDefinedIn: return .keyword(._originallyDefinedIn)
case .specialized: return .keyword(.specialized)
case ._specialize: return .keyword(._specialize)
case ._spi_available: return .keyword(._spi_available)
case .`rethrows`: return .keyword(.rethrows)
Expand Down Expand Up @@ -254,6 +257,10 @@ extension Parser {
return parseAttribute(argumentMode: .optional) { parser in
return (nil, .objCName(parser.parseObjectiveCSelector()))
}
case .specialized:
return parseAttribute(argumentMode: .required) { parser in
return (nil, .specializedArguments(parser.parseSpecializedAttributeArgument()))
}
case ._specialize:
return parseAttribute(argumentMode: .required) { parser in
return (nil, .specializeArguments(parser.parseSpecializeAttributeArgumentList()))
Expand Down Expand Up @@ -645,6 +652,11 @@ extension Parser {
}

extension Parser {
mutating func parseSpecializedAttributeArgument() -> RawSpecializedAttributeArgumentSyntax {
let whereClause = self.parseGenericWhereClause()
return RawSpecializedAttributeArgumentSyntax(genericWhereClause: whereClause, arena: self.arena)
}

mutating func parseSpecializeAttributeArgumentList() -> RawSpecializeAttributeArgumentListSyntax {
var elements = [RawSpecializeAttributeArgumentListSyntax.Element]()
// Parse optional "exported" and "kind" labeled parameters.
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ enum TokenPrecedence: Comparable {
._effects,
._implements,
._originallyDefinedIn,
.specialized,
._specialize,
._spi_available,
.abi,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxEnum.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxKind.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxVisitor.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading