Skip to content

Commit 47617a8

Browse files
committed
Split DeclEffectSpecifiers into AccessorEffectSpecifiers and FunctionEffectSpecifiers.
Solve TODOs in `EffectfulPropertiesTests.swift`
1 parent eff37e3 commit 47617a8

23 files changed

+753
-350
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,31 @@ public let COMMON_NODES: [Node] = [
8383
]
8484
),
8585

86-
// decl-effect-specifiers -> (async | reasync)? (throws | rethrows)?
86+
// accessor-effect-specifiers -> (async)? (throws)?
8787
Node(
88-
name: "DeclEffectSpecifiers",
88+
name: "AccessorEffectSpecifiers",
89+
nameForDiagnostics: "accessor specifiers",
90+
kind: "Syntax",
91+
traits: [
92+
"EffectSpecifiers"
93+
],
94+
children: [
95+
Child(
96+
name: "AsyncSpecifier",
97+
kind: .token(choices: [.keyword(text: "async")]),
98+
isOptional: true
99+
),
100+
Child(
101+
name: "ThrowsSpecifier",
102+
kind: .token(choices: [.keyword(text: "throws")]),
103+
isOptional: true
104+
),
105+
]
106+
),
107+
108+
// funtion-effect-specifiers -> (async | reasync)? (throws | rethrows)?
109+
Node(
110+
name: "FunctionEffectSpecifiers",
89111
nameForDiagnostics: "effect specifiers",
90112
kind: "Syntax",
91113
traits: [

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public let DECL_NODES: [Node] = [
9696
),
9797
Child(
9898
name: "EffectSpecifiers",
99-
kind: .node(kind: "DeclEffectSpecifiers"),
99+
kind: .node(kind: "AccessorEffectSpecifiers"),
100100
isOptional: true
101101
),
102102
Child(
@@ -842,7 +842,7 @@ public let DECL_NODES: [Node] = [
842842
),
843843

844844
// function-signature ->
845-
// '(' parameter-list? ')' decl-effect-specifiers? return-clause?
845+
// '(' parameter-list? ')' function-effect-specifiers? return-clause?
846846
Node(
847847
name: "FunctionSignature",
848848
nameForDiagnostics: "function signature",
@@ -854,7 +854,7 @@ public let DECL_NODES: [Node] = [
854854
),
855855
Child(
856856
name: "EffectSpecifiers",
857-
kind: .node(kind: "DeclEffectSpecifiers"),
857+
kind: .node(kind: "FunctionEffectSpecifiers"),
858858
isOptional: true
859859
),
860860
Child(

Sources/SwiftParser/Declarations.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ extension Parser {
11981198
parser.parseFunctionParameter()
11991199
}
12001200

1201-
var effectSpecifiers = self.parseDeclEffectSpecifiers()
1201+
var effectSpecifiers = self.parseFunctionEffectSpecifiers()
12021202

12031203
var output: RawReturnClauseSyntax?
12041204

@@ -1264,7 +1264,7 @@ extension Parser {
12641264
parser.parseFunctionParameter()
12651265
}
12661266

1267-
var misplacedEffectSpecifiers: RawDeclEffectSpecifiersSyntax?
1267+
var misplacedEffectSpecifiers: RawFunctionEffectSpecifiersSyntax?
12681268
let result = self.parseFunctionReturnClause(effectSpecifiers: &misplacedEffectSpecifiers, allowNamedOpaqueResultType: true)
12691269

12701270
// Parse a 'where' clause if present.
@@ -1519,7 +1519,7 @@ extension Parser {
15191519
parameter = nil
15201520
}
15211521

1522-
let effectSpecifiers = self.parseDeclEffectSpecifiers()
1522+
let effectSpecifiers = self.parseAccessorEffectSpecifiers()
15231523

15241524
let body = self.parseOptionalCodeBlock()
15251525
return RawAccessorDeclSyntax(

Sources/SwiftParser/Specifiers.swift

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extension RawEffectSpecifiersTrait {
173173
}
174174
}
175175

176-
extension RawDeclEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
176+
extension RawFunctionEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
177177
enum MisspelledAsyncSpecifiers: TokenSpecSet {
178178
case await
179179

@@ -331,6 +331,86 @@ extension RawTypeEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
331331
}
332332
}
333333

334+
extension RawAccessorEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
335+
enum MisspelledAsyncSpecifiers: TokenSpecSet {
336+
case await
337+
case reasync
338+
339+
init?(lexeme: Lexer.Lexeme) {
340+
switch PrepareForKeywordMatch(lexeme) {
341+
case TokenSpec(.await, allowAtStartOfLine: false): self = .await
342+
case TokenSpec(.reasync): self = .reasync
343+
default: return nil
344+
}
345+
}
346+
347+
var spec: TokenSpec {
348+
switch self {
349+
case .await: return TokenSpec(.await, allowAtStartOfLine: false)
350+
case .reasync: return .keyword(.reasync)
351+
}
352+
}
353+
}
354+
355+
enum CorrectAsyncTokenKinds: TokenSpecSet {
356+
case async
357+
358+
init?(lexeme: Lexer.Lexeme) {
359+
switch PrepareForKeywordMatch(lexeme) {
360+
case TokenSpec(.async): self = .async
361+
default: return nil
362+
}
363+
}
364+
365+
var spec: TokenSpec {
366+
switch self {
367+
case .async: return .keyword(.async)
368+
}
369+
}
370+
}
371+
372+
enum MisspelledThrowsTokenKinds: TokenSpecSet {
373+
case `rethrows`
374+
case `try`
375+
case `throw`
376+
377+
init?(lexeme: Lexer.Lexeme) {
378+
switch PrepareForKeywordMatch(lexeme) {
379+
case TokenSpec(.rethrows): self = .rethrows
380+
case TokenSpec(.try, allowAtStartOfLine: false): self = .try
381+
case TokenSpec(.throw, allowAtStartOfLine: false): self = .throw
382+
default: return nil
383+
}
384+
}
385+
386+
var spec: TokenSpec {
387+
switch self {
388+
case .rethrows: return .keyword(.rethrows)
389+
case .try: return TokenSpec(.try, allowAtStartOfLine: false)
390+
case .throw: return TokenSpec(.throw, allowAtStartOfLine: false)
391+
}
392+
}
393+
}
394+
395+
enum CorrectThrowsTokenKinds: TokenSpecSet {
396+
case `throws`
397+
398+
init?(lexeme: Lexer.Lexeme) {
399+
switch PrepareForKeywordMatch(lexeme) {
400+
case TokenSpec(.throws): self = .throws
401+
default: return nil
402+
}
403+
}
404+
405+
var spec: TokenSpec {
406+
switch self {
407+
case .throws: return .keyword(.throws)
408+
}
409+
}
410+
}
411+
412+
}
413+
334414
extension TokenConsumer {
335415
mutating func at<SpecSet1: TokenSpecSet, SpecSet2: TokenSpecSet>(anyIn specSet1: SpecSet1.Type, or specSet2: SpecSet2.Type) -> (TokenSpec, TokenConsumptionHandle)? {
336416
if let (spec, handle) = self.at(anyIn: specSet1) {
@@ -423,8 +503,12 @@ extension Parser {
423503
return parseEffectSpecifiers(RawTypeEffectSpecifiersSyntax.self)
424504
}
425505

426-
mutating func parseDeclEffectSpecifiers() -> RawDeclEffectSpecifiersSyntax? {
427-
return parseEffectSpecifiers(RawDeclEffectSpecifiersSyntax.self)
506+
mutating func parseFunctionEffectSpecifiers() -> RawFunctionEffectSpecifiersSyntax? {
507+
return parseEffectSpecifiers(RawFunctionEffectSpecifiersSyntax.self)
508+
}
509+
510+
mutating func parseAccessorEffectSpecifiers() -> RawAccessorEffectSpecifiersSyntax? {
511+
return parseEffectSpecifiers(RawAccessorEffectSpecifiersSyntax.self)
428512
}
429513

430514
/// Consume any misplaced effect specifiers and return them in as unexpected tokens.

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
385385
return .visitChildren
386386
}
387387

388+
public override func visit(_ node: AccessorEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
389+
return handleEffectSpecifiers(node)
390+
}
391+
388392
public override func visit(_ node: AssociatedtypeDeclSyntax) -> SyntaxVisitorContinueKind {
389393
if shouldSkip(node) {
390394
return .skipChildren
@@ -538,7 +542,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
538542
return .visitChildren
539543
}
540544

541-
public override func visit(_ node: DeclEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
545+
public override func visit(_ node: FunctionEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
542546
return handleEffectSpecifiers(node)
543547
}
544548

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ extension SyntaxKind {
2121
return "token"
2222
case .accessorDecl:
2323
return "accessor"
24+
case .accessorEffectSpecifiers:
25+
return "accessor specifiers"
2426
case .actorDecl:
2527
return "actor"
2628
case .arrayElement:
@@ -105,8 +107,6 @@ extension SyntaxKind {
105107
return "@convention(...) arguments"
106108
case .conventionWitnessMethodAttributeArguments:
107109
return "@convention(...) arguments for witness methods"
108-
case .declEffectSpecifiers:
109-
return "effect specifiers"
110110
case .declModifier:
111111
return "modifier"
112112
case .declName:
@@ -179,6 +179,8 @@ extension SyntaxKind {
179179
return "function call"
180180
case .functionDecl:
181181
return "function"
182+
case .functionEffectSpecifiers:
183+
return "effect specifiers"
182184
case .functionParameterList:
183185
return "parameter list"
184186
case .functionParameter:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
284284
### Miscellaneous Syntax
285285

286286
- <doc:SwiftSyntax/AccessorBlockSyntax>
287+
- <doc:SwiftSyntax/AccessorEffectSpecifiersSyntax>
287288
- <doc:SwiftSyntax/AccessorParameterSyntax>
288289
- <doc:SwiftSyntax/AttributeSyntax>
289290
- <doc:SwiftSyntax/AvailabilityConditionSyntax>
@@ -299,7 +300,6 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
299300
- <doc:SwiftSyntax/ConformanceRequirementSyntax>
300301
- <doc:SwiftSyntax/ConventionAttributeArgumentsSyntax>
301302
- <doc:SwiftSyntax/ConventionWitnessMethodAttributeArgumentsSyntax>
302-
- <doc:SwiftSyntax/DeclEffectSpecifiersSyntax>
303303
- <doc:SwiftSyntax/DeclModifierDetailSyntax>
304304
- <doc:SwiftSyntax/DeclNameArgumentsSyntax>
305305
- <doc:SwiftSyntax/DeclNameSyntax>
@@ -311,6 +311,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
311311
- <doc:SwiftSyntax/EnumCaseParameterClauseSyntax>
312312
- <doc:SwiftSyntax/ExposeAttributeArgumentsSyntax>
313313
- <doc:SwiftSyntax/ExpressionSegmentSyntax>
314+
- <doc:SwiftSyntax/FunctionEffectSpecifiersSyntax>
314315
- <doc:SwiftSyntax/FunctionSignatureSyntax>
315316
- <doc:SwiftSyntax/GenericArgumentClauseSyntax>
316317
- <doc:SwiftSyntax/GenericParameterClauseSyntax>

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
8585
visitAnyPost(node._syntaxNode)
8686
}
8787

88+
override open func visit(_ node: AccessorEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
89+
return visitAny(node._syntaxNode)
90+
}
91+
92+
override open func visitPost(_ node: AccessorEffectSpecifiersSyntax) {
93+
visitAnyPost(node._syntaxNode)
94+
}
95+
8896
override open func visit(_ node: AccessorListSyntax) -> SyntaxVisitorContinueKind {
8997
return visitAny(node._syntaxNode)
9098
}
@@ -565,14 +573,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
565573
visitAnyPost(node._syntaxNode)
566574
}
567575

568-
override open func visit(_ node: DeclEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
569-
return visitAny(node._syntaxNode)
570-
}
571-
572-
override open func visitPost(_ node: DeclEffectSpecifiersSyntax) {
573-
visitAnyPost(node._syntaxNode)
574-
}
575-
576576
override open func visit(_ node: DeclModifierDetailSyntax) -> SyntaxVisitorContinueKind {
577577
return visitAny(node._syntaxNode)
578578
}
@@ -957,6 +957,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
957957
visitAnyPost(node._syntaxNode)
958958
}
959959

960+
override open func visit(_ node: FunctionEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
961+
return visitAny(node._syntaxNode)
962+
}
963+
964+
override open func visitPost(_ node: FunctionEffectSpecifiersSyntax) {
965+
visitAnyPost(node._syntaxNode)
966+
}
967+
960968
override open func visit(_ node: FunctionParameterListSyntax) -> SyntaxVisitorContinueKind {
961969
return visitAny(node._syntaxNode)
962970
}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ extension Syntax {
737737
.node(AccessPathSyntax.self),
738738
.node(AccessorBlockSyntax.self),
739739
.node(AccessorDeclSyntax.self),
740+
.node(AccessorEffectSpecifiersSyntax.self),
740741
.node(AccessorListSyntax.self),
741742
.node(AccessorParameterSyntax.self),
742743
.node(ActorDeclSyntax.self),
@@ -797,7 +798,6 @@ extension Syntax {
797798
.node(ContinueStmtSyntax.self),
798799
.node(ConventionAttributeArgumentsSyntax.self),
799800
.node(ConventionWitnessMethodAttributeArgumentsSyntax.self),
800-
.node(DeclEffectSpecifiersSyntax.self),
801801
.node(DeclModifierDetailSyntax.self),
802802
.node(DeclModifierSyntax.self),
803803
.node(DeclNameArgumentListSyntax.self),
@@ -846,6 +846,7 @@ extension Syntax {
846846
.node(ForgetStmtSyntax.self),
847847
.node(FunctionCallExprSyntax.self),
848848
.node(FunctionDeclSyntax.self),
849+
.node(FunctionEffectSpecifiersSyntax.self),
849850
.node(FunctionParameterListSyntax.self),
850851
.node(FunctionParameterSyntax.self),
851852
.node(FunctionSignatureSyntax.self),

Sources/SwiftSyntax/generated/SyntaxCollections.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,8 +2387,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {
23872387

23882388
public let _syntaxNode: Syntax
23892389

2390-
@_spi(RawSyntax)
2391-
public var layoutView: RawSyntaxLayoutView {
2390+
private var layoutView: RawSyntaxLayoutView {
23922391
data.raw.layoutView!
23932392
}
23942393

@@ -2420,7 +2419,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {
24202419

24212420
/// The number of elements, `present` or `missing`, in this collection.
24222421
public var count: Int {
2423-
return raw.layoutView!.children.count
2422+
return layoutView.children.count
24242423
}
24252424

24262425
/// Creates a new `ClosureParameterListSyntax` by replacing the underlying layout with
@@ -4689,8 +4688,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {
46894688

46904689
public let _syntaxNode: Syntax
46914690

4692-
@_spi(RawSyntax)
4693-
public var layoutView: RawSyntaxLayoutView {
4691+
private var layoutView: RawSyntaxLayoutView {
46944692
data.raw.layoutView!
46954693
}
46964694

@@ -4722,7 +4720,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {
47224720

47234721
/// The number of elements, `present` or `missing`, in this collection.
47244722
public var count: Int {
4725-
return raw.layoutView!.children.count
4723+
return layoutView.children.count
47264724
}
47274725

47284726
/// Creates a new `EnumCaseParameterListSyntax` by replacing the underlying layout with

0 commit comments

Comments
 (0)