Skip to content

Commit 9cd04e2

Browse files
committed
Add representation and parser support for the @isolated type attribute
1 parent 865e3ba commit 9cd04e2

22 files changed

+303
-3
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public let ATTRIBUTE_NODES: [Node] = [
141141
name: "documentationArguments",
142142
kind: .node(kind: .documentationAttributeArgumentList)
143143
),
144+
Child(
145+
name: "isolatedArguments",
146+
kind: .node(kind: .isolatedAttributeArguments)
147+
),
144148
]),
145149
documentation: """
146150
The arguments of the attribute.
@@ -611,6 +615,19 @@ public let ATTRIBUTE_NODES: [Node] = [
611615
]
612616
),
613617

618+
Node(
619+
kind: .isolatedAttributeArguments,
620+
base: .syntax,
621+
nameForDiagnostics: "@isolated arguments",
622+
documentation: "The arguments of the '@isolated' attribute",
623+
children: [
624+
Child(
625+
name: "isolationKind",
626+
kind: .node(kind: .token)
627+
),
628+
]
629+
),
630+
614631
Node(
615632
kind: .labeledSpecializeArgument,
616633
base: .syntax,

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
171171
case integerLiteralExpr
172172
case isExpr
173173
case isTypePattern
174+
case isolatedAttributeArguments
174175
case keyPathComponent
175176
case keyPathComponentList
176177
case keyPathExpr

Sources/SwiftParser/Attributes.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,17 @@ extension Parser {
848848
}
849849
}
850850

851+
extension Parser {
852+
mutating func parseIsolatedAttributeArguments() -> RawIsolatedAttributeArgumentsSyntax {
853+
let (unexpectedBeforeIsolationKind, label) = self.expect(.identifier)
854+
return RawIsolatedAttributeArgumentsSyntax(
855+
unexpectedBeforeIsolationKind,
856+
isolationKind: label,
857+
/*unexpectedAfterIsolationKind*/ nil,
858+
arena: self.arena)
859+
}
860+
}
861+
851862
extension Parser {
852863
mutating func parseBackDeployedAttributeArguments() -> RawBackDeployedAttributeArgumentsSyntax {
853864
let (unexpectedBeforeLabel, label) = self.expect(.keyword(.before))

Sources/SwiftParser/Lookahead.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ extension Parser.Lookahead {
171171
return
172172
}
173173
}
174+
if case .isolated = attr {
175+
guard
176+
self.consume(if: .leftParen) != nil,
177+
self.consume(if: .identifier) != nil,
178+
self.consume(if: .rightParen) != nil
179+
else {
180+
return
181+
}
182+
}
174183
return
175184
}
176185

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ enum TokenPrecedence: Comparable {
252252
.Sendable,
253253
.retroactive,
254254
.unchecked:
255+
// Note that .isolated is preferred as a decl keyword
255256
self = .exprKeyword
256257

257258
case // `DeclarationAttributeWithSpecialSyntax`

Sources/SwiftParser/TokenSpecSet.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ enum TypeAttribute: TokenSpecSet {
643643
case retroactive
644644
case Sendable
645645
case unchecked
646+
case isolated
646647

647648
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
648649
switch PrepareForKeywordMatch(lexeme) {
@@ -660,6 +661,7 @@ enum TypeAttribute: TokenSpecSet {
660661
case TokenSpec(.Sendable): self = .Sendable
661662
case TokenSpec(.retroactive): self = .retroactive
662663
case TokenSpec(.unchecked): self = .unchecked
664+
case TokenSpec(.isolated): self = .isolated
663665
default: return nil
664666
}
665667
}
@@ -680,6 +682,7 @@ enum TypeAttribute: TokenSpecSet {
680682
case .retroactive: return .keyword(.retroactive)
681683
case .Sendable: return .keyword(.Sendable)
682684
case .unchecked: return .keyword(.unchecked)
685+
case .isolated: return .keyword(.isolated)
683686
}
684687
}
685688
}

Sources/SwiftParser/Types.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,10 @@ extension Parser {
937937
return parseAttribute(argumentMode: .required) { parser in
938938
return .opaqueReturnTypeOfAttributeArguments(parser.parseOpaqueReturnTypeOfAttributeArguments())
939939
}
940+
case .isolated:
941+
return parseAttribute(argumentMode: .required) { parser in
942+
return .isolatedArguments(parser.parseIsolatedAttributeArguments())
943+
}
940944
case nil: // Custom attribute
941945
return parseAttribute(argumentMode: .customAttribute) { parser in
942946
let arguments = parser.parseArgumentListElements(pattern: .none)

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ extension SyntaxKind {
231231
return "'is'"
232232
case .isTypePattern:
233233
return "'is' pattern"
234+
case .isolatedAttributeArguments:
235+
return "@isolated arguments"
234236
case .keyPathComponent:
235237
return "key path component"
236238
case .keyPathExpr:

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
326326
- <doc:SwiftSyntax/EffectsAttributeArgumentListSyntax>
327327
- <doc:SwiftSyntax/ExposeAttributeArgumentsSyntax>
328328
- <doc:SwiftSyntax/ImplementsAttributeArgumentsSyntax>
329+
- <doc:SwiftSyntax/IsolatedAttributeArgumentsSyntax>
329330
- <doc:SwiftSyntax/LabeledSpecializeArgumentSyntax>
330331
- <doc:SwiftSyntax/ObjCSelectorPieceListSyntax>
331332
- <doc:SwiftSyntax/ObjCSelectorPieceSyntax>

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
18611861
return "type"
18621862
case \IsTypePatternSyntax.unexpectedAfterType:
18631863
return "unexpectedAfterType"
1864+
case \IsolatedAttributeArgumentsSyntax.unexpectedBeforeIsolationKind:
1865+
return "unexpectedBeforeIsolationKind"
1866+
case \IsolatedAttributeArgumentsSyntax.isolationKind:
1867+
return "isolationKind"
1868+
case \IsolatedAttributeArgumentsSyntax.unexpectedAfterIsolationKind:
1869+
return "unexpectedAfterIsolationKind"
18641870
case \KeyPathComponentSyntax.unexpectedBeforePeriod:
18651871
return "unexpectedBeforePeriod"
18661872
case \KeyPathComponentSyntax.period:

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
12541254
visitAnyPost(node._syntaxNode)
12551255
}
12561256

1257+
override open func visit(_ node: IsolatedAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind {
1258+
return visitAny(node._syntaxNode)
1259+
}
1260+
1261+
override open func visitPost(_ node: IsolatedAttributeArgumentsSyntax) {
1262+
visitAnyPost(node._syntaxNode)
1263+
}
1264+
12571265
override open func visit(_ node: KeyPathComponentListSyntax) -> SyntaxVisitorContinueKind {
12581266
return visitAny(node._syntaxNode)
12591267
}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,7 @@ extension Syntax {
16681668
.node(IntegerLiteralExprSyntax.self),
16691669
.node(IsExprSyntax.self),
16701670
.node(IsTypePatternSyntax.self),
1671+
.node(IsolatedAttributeArgumentsSyntax.self),
16711672
.node(KeyPathComponentListSyntax.self),
16721673
.node(KeyPathComponentSyntax.self),
16731674
.node(KeyPathExprSyntax.self),

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public enum SyntaxEnum: Sendable {
167167
case integerLiteralExpr(IntegerLiteralExprSyntax)
168168
case isExpr(IsExprSyntax)
169169
case isTypePattern(IsTypePatternSyntax)
170+
case isolatedAttributeArguments(IsolatedAttributeArgumentsSyntax)
170171
case keyPathComponentList(KeyPathComponentListSyntax)
171172
case keyPathComponent(KeyPathComponentSyntax)
172173
case keyPathExpr(KeyPathExprSyntax)
@@ -605,6 +606,8 @@ public extension Syntax {
605606
return .isExpr(IsExprSyntax(self)!)
606607
case .isTypePattern:
607608
return .isTypePattern(IsTypePatternSyntax(self)!)
609+
case .isolatedAttributeArguments:
610+
return .isolatedAttributeArguments(IsolatedAttributeArgumentsSyntax(self)!)
608611
case .keyPathComponentList:
609612
return .keyPathComponentList(KeyPathComponentListSyntax(self)!)
610613
case .keyPathComponent:

Sources/SwiftSyntax/generated/SyntaxKind.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public enum SyntaxKind: Sendable {
167167
case integerLiteralExpr
168168
case isExpr
169169
case isTypePattern
170+
case isolatedAttributeArguments
170171
case keyPathComponentList
171172
case keyPathComponent
172173
case keyPathExpr
@@ -726,6 +727,8 @@ public enum SyntaxKind: Sendable {
726727
return IsExprSyntax.self
727728
case .isTypePattern:
728729
return IsTypePatternSyntax.self
730+
case .isolatedAttributeArguments:
731+
return IsolatedAttributeArgumentsSyntax.self
729732
case .keyPathComponentList:
730733
return KeyPathComponentListSyntax.self
731734
case .keyPathComponent:

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,13 @@ open class SyntaxRewriter {
11261126
return PatternSyntax(visitChildren(node))
11271127
}
11281128

1129+
/// Visit a ``IsolatedAttributeArgumentsSyntax``.
1130+
/// - Parameter node: the node that is being visited
1131+
/// - Returns: the rewritten node
1132+
open func visit(_ node: IsolatedAttributeArgumentsSyntax) -> IsolatedAttributeArgumentsSyntax {
1133+
return visitChildren(node)
1134+
}
1135+
11291136
/// Visit a ``KeyPathComponentListSyntax``.
11301137
/// - Parameter node: the node that is being visited
11311138
/// - Returns: the rewritten node
@@ -2712,6 +2719,10 @@ open class SyntaxRewriter {
27122719
return {
27132720
self.visitImpl($0, IsTypePatternSyntax.self, self.visit)
27142721
}
2722+
case .isolatedAttributeArguments:
2723+
return {
2724+
self.visitImpl($0, IsolatedAttributeArgumentsSyntax.self, self.visit)
2725+
}
27152726
case .keyPathComponentList:
27162727
return {
27172728
self.visitImpl($0, KeyPathComponentListSyntax.self, self.visit)
@@ -3536,6 +3547,8 @@ open class SyntaxRewriter {
35363547
return visitImpl(node, IsExprSyntax.self, visit)
35373548
case .isTypePattern:
35383549
return visitImpl(node, IsTypePatternSyntax.self, visit)
3550+
case .isolatedAttributeArguments:
3551+
return visitImpl(node, IsolatedAttributeArgumentsSyntax.self, visit)
35393552
case .keyPathComponentList:
35403553
return visitImpl(node, KeyPathComponentListSyntax.self, visit)
35413554
case .keyPathComponent:

Sources/SwiftSyntax/generated/SyntaxVisitor.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,18 @@ open class SyntaxVisitor {
18281828
open func visitPost(_ node: IsTypePatternSyntax) {
18291829
}
18301830

1831+
/// Visiting ``IsolatedAttributeArgumentsSyntax`` specifically.
1832+
/// - Parameter node: the node we are visiting.
1833+
/// - Returns: how should we continue visiting.
1834+
open func visit(_ node: IsolatedAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind {
1835+
return .visitChildren
1836+
}
1837+
1838+
/// The function called after visiting ``IsolatedAttributeArgumentsSyntax`` and its descendants.
1839+
/// - node: the node we just finished visiting.
1840+
open func visitPost(_ node: IsolatedAttributeArgumentsSyntax) {
1841+
}
1842+
18311843
/// Visiting ``KeyPathComponentListSyntax`` specifically.
18321844
/// - Parameter node: the node we are visiting.
18331845
/// - Returns: how should we continue visiting.
@@ -4040,6 +4052,10 @@ open class SyntaxVisitor {
40404052
return {
40414053
self.visitImpl($0, IsTypePatternSyntax.self, self.visit, self.visitPost)
40424054
}
4055+
case .isolatedAttributeArguments:
4056+
return {
4057+
self.visitImpl($0, IsolatedAttributeArgumentsSyntax.self, self.visit, self.visitPost)
4058+
}
40434059
case .keyPathComponentList:
40444060
return {
40454061
self.visitImpl($0, KeyPathComponentListSyntax.self, self.visit, self.visitPost)
@@ -4867,6 +4883,8 @@ open class SyntaxVisitor {
48674883
visitImpl(node, IsExprSyntax.self, visit, visitPost)
48684884
case .isTypePattern:
48694885
visitImpl(node, IsTypePatternSyntax.self, visit, visitPost)
4886+
case .isolatedAttributeArguments:
4887+
visitImpl(node, IsolatedAttributeArgumentsSyntax.self, visit, visitPost)
48704888
case .keyPathComponentList:
48714889
visitImpl(node, KeyPathComponentListSyntax.self, visit, visitPost)
48724890
case .keyPathComponent:

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,10 @@ public struct RawAttributeSyntax: RawSyntaxNodeProtocol {
13251325
case `unavailableFromAsyncArguments`(RawUnavailableFromAsyncAttributeArgumentsSyntax)
13261326
case `effectsArguments`(RawEffectsAttributeArgumentListSyntax)
13271327
case `documentationArguments`(RawDocumentationAttributeArgumentListSyntax)
1328+
case `isolatedArguments`(RawIsolatedAttributeArgumentsSyntax)
13281329

13291330
public static func isKindOf(_ raw: RawSyntax) -> Bool {
1330-
return RawLabeledExprListSyntax.isKindOf(raw) || RawTokenSyntax.isKindOf(raw) || RawStringLiteralExprSyntax.isKindOf(raw) || RawAvailabilityArgumentListSyntax.isKindOf(raw) || RawSpecializeAttributeArgumentListSyntax.isKindOf(raw) || RawObjCSelectorPieceListSyntax.isKindOf(raw) || RawImplementsAttributeArgumentsSyntax.isKindOf(raw) || RawDifferentiableAttributeArgumentsSyntax.isKindOf(raw) || RawDerivativeAttributeArgumentsSyntax.isKindOf(raw) || RawBackDeployedAttributeArgumentsSyntax.isKindOf(raw) || RawConventionAttributeArgumentsSyntax.isKindOf(raw) || RawConventionWitnessMethodAttributeArgumentsSyntax.isKindOf(raw) || RawOpaqueReturnTypeOfAttributeArgumentsSyntax.isKindOf(raw) || RawExposeAttributeArgumentsSyntax.isKindOf(raw) || RawOriginallyDefinedInAttributeArgumentsSyntax.isKindOf(raw) || RawUnderscorePrivateAttributeArgumentsSyntax.isKindOf(raw) || RawDynamicReplacementAttributeArgumentsSyntax.isKindOf(raw) || RawUnavailableFromAsyncAttributeArgumentsSyntax.isKindOf(raw) || RawEffectsAttributeArgumentListSyntax.isKindOf(raw) || RawDocumentationAttributeArgumentListSyntax.isKindOf(raw)
1331+
return RawLabeledExprListSyntax.isKindOf(raw) || RawTokenSyntax.isKindOf(raw) || RawStringLiteralExprSyntax.isKindOf(raw) || RawAvailabilityArgumentListSyntax.isKindOf(raw) || RawSpecializeAttributeArgumentListSyntax.isKindOf(raw) || RawObjCSelectorPieceListSyntax.isKindOf(raw) || RawImplementsAttributeArgumentsSyntax.isKindOf(raw) || RawDifferentiableAttributeArgumentsSyntax.isKindOf(raw) || RawDerivativeAttributeArgumentsSyntax.isKindOf(raw) || RawBackDeployedAttributeArgumentsSyntax.isKindOf(raw) || RawConventionAttributeArgumentsSyntax.isKindOf(raw) || RawConventionWitnessMethodAttributeArgumentsSyntax.isKindOf(raw) || RawOpaqueReturnTypeOfAttributeArgumentsSyntax.isKindOf(raw) || RawExposeAttributeArgumentsSyntax.isKindOf(raw) || RawOriginallyDefinedInAttributeArgumentsSyntax.isKindOf(raw) || RawUnderscorePrivateAttributeArgumentsSyntax.isKindOf(raw) || RawDynamicReplacementAttributeArgumentsSyntax.isKindOf(raw) || RawUnavailableFromAsyncAttributeArgumentsSyntax.isKindOf(raw) || RawEffectsAttributeArgumentListSyntax.isKindOf(raw) || RawDocumentationAttributeArgumentListSyntax.isKindOf(raw) || RawIsolatedAttributeArgumentsSyntax.isKindOf(raw)
13311332
}
13321333

13331334
public var raw: RawSyntax {
@@ -1372,6 +1373,8 @@ public struct RawAttributeSyntax: RawSyntaxNodeProtocol {
13721373
return node.raw
13731374
case .documentationArguments(let node):
13741375
return node.raw
1376+
case .isolatedArguments(let node):
1377+
return node.raw
13751378
}
13761379
}
13771380

@@ -1456,6 +1459,10 @@ public struct RawAttributeSyntax: RawSyntaxNodeProtocol {
14561459
self = .documentationArguments(node)
14571460
return
14581461
}
1462+
if let node = RawIsolatedAttributeArgumentsSyntax(other) {
1463+
self = .isolatedArguments(node)
1464+
return
1465+
}
14591466
return nil
14601467
}
14611468
}

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesGHI.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,3 +2525,61 @@ public struct RawIsTypePatternSyntax: RawPatternSyntaxNodeProtocol {
25252525
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
25262526
}
25272527
}
2528+
2529+
@_spi(RawSyntax)
2530+
public struct RawIsolatedAttributeArgumentsSyntax: RawSyntaxNodeProtocol {
2531+
@_spi(RawSyntax)
2532+
public var layoutView: RawSyntaxLayoutView {
2533+
return raw.layoutView!
2534+
}
2535+
2536+
public static func isKindOf(_ raw: RawSyntax) -> Bool {
2537+
return raw.kind == .isolatedAttributeArguments
2538+
}
2539+
2540+
public var raw: RawSyntax
2541+
2542+
init(raw: RawSyntax) {
2543+
precondition(Self.isKindOf(raw))
2544+
self.raw = raw
2545+
}
2546+
2547+
private init(unchecked raw: RawSyntax) {
2548+
self.raw = raw
2549+
}
2550+
2551+
public init?(_ other: some RawSyntaxNodeProtocol) {
2552+
guard Self.isKindOf(other.raw) else {
2553+
return nil
2554+
}
2555+
self.init(unchecked: other.raw)
2556+
}
2557+
2558+
public init(
2559+
_ unexpectedBeforeIsolationKind: RawUnexpectedNodesSyntax? = nil,
2560+
isolationKind: RawTokenSyntax,
2561+
_ unexpectedAfterIsolationKind: RawUnexpectedNodesSyntax? = nil,
2562+
arena: __shared SyntaxArena
2563+
) {
2564+
let raw = RawSyntax.makeLayout(
2565+
kind: .isolatedAttributeArguments, uninitializedCount: 3, arena: arena) { layout in
2566+
layout.initialize(repeating: nil)
2567+
layout[0] = unexpectedBeforeIsolationKind?.raw
2568+
layout[1] = isolationKind.raw
2569+
layout[2] = unexpectedAfterIsolationKind?.raw
2570+
}
2571+
self.init(unchecked: raw)
2572+
}
2573+
2574+
public var unexpectedBeforeIsolationKind: RawUnexpectedNodesSyntax? {
2575+
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
2576+
}
2577+
2578+
public var isolationKind: RawTokenSyntax {
2579+
layoutView.children[1].map(RawTokenSyntax.init(raw:))!
2580+
}
2581+
2582+
public var unexpectedAfterIsolationKind: RawUnexpectedNodesSyntax? {
2583+
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
2584+
}
2585+
}

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,11 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
16111611
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
16121612
assertNoError(kind, 3, verify(layout[3], as: RawTypeSyntax.self))
16131613
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))
1614+
case .isolatedAttributeArguments:
1615+
assert(layout.count == 3)
1616+
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
1617+
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self))
1618+
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
16141619
case .keyPathComponentList:
16151620
for (index, element) in layout.enumerated() {
16161621
assertNoError(kind, index, verify(element, as: RawKeyPathComponentSyntax.self))

0 commit comments

Comments
 (0)