Skip to content

Commit 7eca32c

Browse files
authored
Merge pull request #3112 from DougGregor/parse-unsafe-nonisolated-conformance
Parse @unsafe nonisolated conformance
2 parents e8c3dcf + ec9139e commit 7eca32c

File tree

15 files changed

+128
-37
lines changed

15 files changed

+128
-37
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public enum ChildKind {
4747
kind: SyntaxNodeKind,
4848
collectionElementName: String? = nil,
4949
defaultsToEmpty: Bool = false,
50-
deprecatedCollectionElementName: String? = nil
50+
deprecatedCollectionElementName: String? = nil,
51+
generateDeprecatedAddFunction: Bool = true
5152
)
5253
/// The child is a token that matches one of the given `choices`.
5354
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
@@ -132,7 +133,7 @@ public class Child: NodeChoiceConvertible {
132133
return kind
133134
case .nodeChoices:
134135
return .syntax
135-
case .collection(kind: let kind, _, _, _):
136+
case .collection(kind: let kind, _, _, _, _):
136137
return kind
137138
case .token:
138139
return .token
@@ -268,7 +269,7 @@ public class Child: NodeChoiceConvertible {
268269
/// Whether this child has syntax kind `UnexpectedNodes`.
269270
public var isUnexpectedNodes: Bool {
270271
switch kind {
271-
case .collection(kind: .unexpectedNodes, _, _, _):
272+
case .collection(kind: .unexpectedNodes, _, _, _, _):
272273
return true
273274
default:
274275
return false
@@ -283,7 +284,7 @@ public class Child: NodeChoiceConvertible {
283284
return choices.isEmpty
284285
case .node(let kind):
285286
return kind.isBase
286-
case .collection(kind: let kind, _, _, _):
287+
case .collection(kind: let kind, _, _, _, _):
287288
return kind.isBase
288289
case .token:
289290
return false

CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct GrammarGenerator {
4141
case .nodeChoices(let choices, _):
4242
let choicesDescriptions = choices.map { grammar(for: $0) }
4343
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
44-
case .collection(kind: let kind, _, _, _):
44+
case .collection(kind: let kind, _, _, _, _):
4545
return "\(kind.doccLink)\(optionality)"
4646
case .token(let choices, _, _):
4747
if choices.count == 1 {

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ fileprivate extension Child {
391391
return [kind]
392392
case .nodeChoices(let choices, _):
393393
return choices.flatMap(\.kinds)
394-
case .collection(kind: let kind, _, _, _):
394+
case .collection(kind: let kind, _, _, _, _):
395395
return [kind]
396396
case .token:
397397
return [.token]

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public let TYPE_NODES: [Node] = [
5757
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
5858
documentation: "A list of attributes that can be attached to the type, such as `@escaping`."
5959
),
60+
Child(
61+
name: "lateSpecifiers",
62+
kind: .collection(
63+
kind: .typeSpecifierList,
64+
collectionElementName: "Specifier",
65+
defaultsToEmpty: true,
66+
generateDeprecatedAddFunction: false
67+
),
68+
documentation:
69+
"A list of specifiers that can be attached to the type after the attributes, such as 'nonisolated'."
70+
),
6071
Child(
6172
name: "baseType",
6273
kind: .node(kind: .type),

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension Child {
3333
buildableKind = .node(kind: kind)
3434
case .nodeChoices:
3535
buildableKind = .node(kind: .syntax)
36-
case .collection(kind: let kind, _, _, _):
36+
case .collection(kind: let kind, _, _, _, _):
3737
buildableKind = .node(kind: kind)
3838
case .token:
3939
buildableKind = .token(self.tokenKind!)
@@ -65,7 +65,7 @@ extension Child {
6565
return ExprSyntax("nil")
6666
}
6767
}
68-
if case .collection(_, _, defaultsToEmpty: true, _) = kind {
68+
if case .collection(_, _, defaultsToEmpty: true, _, _) = kind {
6969
return ExprSyntax("[]")
7070
}
7171
guard let token = token, isToken else {

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func makeCompatibilityAddMethod(for child: Child) -> DeclSyntax? {
8585
kind: _,
8686
collectionElementName: let collectionElementName?,
8787
defaultsToEmpty: _,
88-
deprecatedCollectionElementName: let deprecatedCollectionElementName?
88+
deprecatedCollectionElementName: let deprecatedCollectionElementName?,
89+
generateDeprecatedAddFunction: _
8990
) = child.kind
9091
{
9192
let childEltType = childNode.collectionElementType.syntaxBaseName

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
176176
// If needed, this could be added in the future, but for now withUnexpected should be sufficient.
177177
if let childNode = SYNTAX_NODE_MAP[child.syntaxNodeKind]?.collectionNode,
178178
!child.isUnexpectedNodes,
179-
case .collection(_, collectionElementName: let childElt?, _, _) = child.kind
179+
case .collection(_, collectionElementName: let childElt?, _, _, generateDeprecatedAddFunction: true) = child
180+
.kind
180181
{
181182
let childEltType = childNode.collectionElementType.syntaxBaseName
182183

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ fileprivate extension ChildKind {
5555
return kind == otherKind
5656
case (.nodeChoices(let choices, _), .nodeChoices(let otherChoices, _)):
5757
return choices.count == otherChoices.count && zip(choices, otherChoices).allSatisfy { $0.hasSameType(as: $1) }
58-
case (.collection(kind: let kind, _, _, _), .collection(kind: let otherKind, _, _, _)):
58+
case (.collection(kind: let kind, _, _, _, _), .collection(kind: let otherKind, _, _, _, _)):
5959
return kind == otherKind
6060
case (.token(let choices, _, _), .token(let otherChoices, _, _)):
6161
return choices == otherChoices
62-
case (.node(let kind), .collection(kind: let otherKind, _, _, _)):
62+
case (.node(let kind), .collection(kind: let otherKind, _, _, _, _)):
6363
return kind == otherKind
64-
case (.collection(kind: let kind, _, _, _), .node(let otherKind)):
64+
case (.collection(kind: let kind, _, _, _, _), .node(let otherKind)):
6565
return kind == otherKind
6666
default:
6767
return false

Sources/SwiftParser/Types.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extension Parser {
100100
RawAttributedTypeSyntax(
101101
specifiers: specifiersAndAttributes.specifiers,
102102
attributes: specifiersAndAttributes.attributes,
103+
lateSpecifiers: specifiersAndAttributes.lateSpecifiers,
103104
baseType: base,
104105
arena: self.arena
105106
)
@@ -1221,7 +1222,8 @@ extension Parser {
12211222
misplacedSpecifiers: [RawTokenSyntax] = []
12221223
) -> (
12231224
specifiers: RawTypeSpecifierListSyntax,
1224-
attributes: RawAttributeListSyntax
1225+
attributes: RawAttributeListSyntax,
1226+
lateSpecifiers: RawTypeSpecifierListSyntax
12251227
)? {
12261228
var specifiers: [RawTypeSpecifierListSyntax.Element] = []
12271229
SPECIFIER_PARSING: while canHaveParameterSpecifier {
@@ -1260,7 +1262,15 @@ extension Parser {
12601262
attributes = nil
12611263
}
12621264

1263-
guard !specifiers.isEmpty || attributes != nil else {
1265+
// Only handle `nonisolated` as a late specifier.
1266+
var lateSpecifiers: [RawTypeSpecifierListSyntax.Element] = []
1267+
if self.at(.keyword(.nonisolated)) && !(self.peek(isAt: .leftParen) && self.peek().isAtStartOfLine)
1268+
&& canHaveParameterSpecifier
1269+
{
1270+
lateSpecifiers.append(parseNonisolatedTypeSpecifier())
1271+
}
1272+
1273+
guard !specifiers.isEmpty || attributes != nil || !lateSpecifiers.isEmpty else {
12641274
// No specifiers or attributes on this type
12651275
return nil
12661276
}
@@ -1271,9 +1281,17 @@ extension Parser {
12711281
specifierList = RawTypeSpecifierListSyntax(elements: specifiers, arena: arena)
12721282
}
12731283

1284+
let lateSpecifierList: RawTypeSpecifierListSyntax
1285+
if lateSpecifiers.isEmpty {
1286+
lateSpecifierList = self.emptyCollection(RawTypeSpecifierListSyntax.self)
1287+
} else {
1288+
lateSpecifierList = RawTypeSpecifierListSyntax(elements: lateSpecifiers, arena: arena)
1289+
}
1290+
12741291
return (
12751292
specifierList,
1276-
attributes ?? self.emptyCollection(RawAttributeListSyntax.self)
1293+
attributes ?? self.emptyCollection(RawAttributeListSyntax.self),
1294+
lateSpecifierList
12771295
)
12781296
}
12791297

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/SyntaxCollections.swift

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift

Lines changed: 20 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift

Lines changed: 38 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)