Skip to content

Split DeclEffectSpecifiers into AccessorEffectSpecifiers and FunctionEffectSpecifiers #1454

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
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
26 changes: 24 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,31 @@ public let COMMON_NODES: [Node] = [
]
),

// decl-effect-specifiers -> (async | reasync)? (throws | rethrows)?
// accessor-effect-specifiers -> (async)? (throws)?
Node(
name: "DeclEffectSpecifiers",
name: "AccessorEffectSpecifiers",
nameForDiagnostics: "accessor specifiers",
kind: "Syntax",
traits: [
"EffectSpecifiers"
],
children: [
Child(
name: "AsyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
isOptional: true
),
Child(
name: "ThrowsSpecifier",
kind: .token(choices: [.keyword(text: "throws")]),
isOptional: true
),
]
),

// funtion-effect-specifiers -> (async | reasync)? (throws | rethrows)?
Node(
name: "FunctionEffectSpecifiers",
nameForDiagnostics: "effect specifiers",
kind: "Syntax",
traits: [
Expand Down
6 changes: 3 additions & 3 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public let DECL_NODES: [Node] = [
),
Child(
name: "EffectSpecifiers",
kind: .node(kind: "DeclEffectSpecifiers"),
kind: .node(kind: "AccessorEffectSpecifiers"),
isOptional: true
),
Child(
Expand Down Expand Up @@ -842,7 +842,7 @@ public let DECL_NODES: [Node] = [
),

// function-signature ->
// '(' parameter-list? ')' decl-effect-specifiers? return-clause?
// '(' parameter-list? ')' function-effect-specifiers? return-clause?
Node(
name: "FunctionSignature",
nameForDiagnostics: "function signature",
Expand All @@ -854,7 +854,7 @@ public let DECL_NODES: [Node] = [
),
Child(
name: "EffectSpecifiers",
kind: .node(kind: "DeclEffectSpecifiers"),
kind: .node(kind: "FunctionEffectSpecifiers"),
isOptional: true
),
Child(
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ extension Parser {
parser.parseFunctionParameter()
}

var effectSpecifiers = self.parseDeclEffectSpecifiers()
var effectSpecifiers = self.parseFunctionEffectSpecifiers()

var output: RawReturnClauseSyntax?

Expand Down Expand Up @@ -1264,7 +1264,7 @@ extension Parser {
parser.parseFunctionParameter()
}

var misplacedEffectSpecifiers: RawDeclEffectSpecifiersSyntax?
var misplacedEffectSpecifiers: RawFunctionEffectSpecifiersSyntax?
let result = self.parseFunctionReturnClause(effectSpecifiers: &misplacedEffectSpecifiers, allowNamedOpaqueResultType: true)

// Parse a 'where' clause if present.
Expand Down Expand Up @@ -1519,7 +1519,7 @@ extension Parser {
parameter = nil
}

let effectSpecifiers = self.parseDeclEffectSpecifiers()
let effectSpecifiers = self.parseAccessorEffectSpecifiers()

let body = self.parseOptionalCodeBlock()
return RawAccessorDeclSyntax(
Expand Down
90 changes: 87 additions & 3 deletions Sources/SwiftParser/Specifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ extension RawEffectSpecifiersTrait {
}
}

extension RawDeclEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
extension RawFunctionEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
enum MisspelledAsyncSpecifiers: TokenSpecSet {
case await

Expand Down Expand Up @@ -331,6 +331,86 @@ extension RawTypeEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
}
}

extension RawAccessorEffectSpecifiersSyntax: RawEffectSpecifiersTrait {
enum MisspelledAsyncSpecifiers: TokenSpecSet {
case await
case reasync

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.await, allowAtStartOfLine: false): self = .await
case TokenSpec(.reasync): self = .reasync
default: return nil
}
}

var spec: TokenSpec {
switch self {
case .await: return TokenSpec(.await, allowAtStartOfLine: false)
case .reasync: return .keyword(.reasync)
}
}
}

enum CorrectAsyncTokenKinds: TokenSpecSet {
case async

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.async): self = .async
default: return nil
}
}

var spec: TokenSpec {
switch self {
case .async: return .keyword(.async)
}
}
}

enum MisspelledThrowsTokenKinds: TokenSpecSet {
case `rethrows`
case `try`
case `throw`

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.rethrows): self = .rethrows
case TokenSpec(.try, allowAtStartOfLine: false): self = .try
case TokenSpec(.throw, allowAtStartOfLine: false): self = .throw
default: return nil
}
}

var spec: TokenSpec {
switch self {
case .rethrows: return .keyword(.rethrows)
case .try: return TokenSpec(.try, allowAtStartOfLine: false)
case .throw: return TokenSpec(.throw, allowAtStartOfLine: false)
}
}
}

enum CorrectThrowsTokenKinds: TokenSpecSet {
case `throws`

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.throws): self = .throws
default: return nil
}
}

var spec: TokenSpec {
switch self {
case .throws: return .keyword(.throws)
}
}
}

}

extension TokenConsumer {
mutating func at<SpecSet1: TokenSpecSet, SpecSet2: TokenSpecSet>(anyIn specSet1: SpecSet1.Type, or specSet2: SpecSet2.Type) -> (TokenSpec, TokenConsumptionHandle)? {
if let (spec, handle) = self.at(anyIn: specSet1) {
Expand Down Expand Up @@ -423,8 +503,12 @@ extension Parser {
return parseEffectSpecifiers(RawTypeEffectSpecifiersSyntax.self)
}

mutating func parseDeclEffectSpecifiers() -> RawDeclEffectSpecifiersSyntax? {
return parseEffectSpecifiers(RawDeclEffectSpecifiersSyntax.self)
mutating func parseFunctionEffectSpecifiers() -> RawFunctionEffectSpecifiersSyntax? {
return parseEffectSpecifiers(RawFunctionEffectSpecifiersSyntax.self)
}

mutating func parseAccessorEffectSpecifiers() -> RawAccessorEffectSpecifiersSyntax? {
return parseEffectSpecifiers(RawAccessorEffectSpecifiersSyntax.self)
}

/// Consume any misplaced effect specifiers and return them in as unexpected tokens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
return .visitChildren
}

public override func visit(_ node: AccessorEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
return handleEffectSpecifiers(node)
}

public override func visit(_ node: AssociatedtypeDeclSyntax) -> SyntaxVisitorContinueKind {
if shouldSkip(node) {
return .skipChildren
Expand Down Expand Up @@ -538,7 +542,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
return .visitChildren
}

public override func visit(_ node: DeclEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
public override func visit(_ node: FunctionEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
return handleEffectSpecifiers(node)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ extension SyntaxKind {
return "token"
case .accessorDecl:
return "accessor"
case .accessorEffectSpecifiers:
return "accessor specifiers"
case .actorDecl:
return "actor"
case .arrayElement:
Expand Down Expand Up @@ -105,8 +107,6 @@ extension SyntaxKind {
return "@convention(...) arguments"
case .conventionWitnessMethodAttributeArguments:
return "@convention(...) arguments for witness methods"
case .declEffectSpecifiers:
return "effect specifiers"
case .declModifier:
return "modifier"
case .declName:
Expand Down Expand Up @@ -179,6 +179,8 @@ extension SyntaxKind {
return "function call"
case .functionDecl:
return "function"
case .functionEffectSpecifiers:
return "effect specifiers"
case .functionParameterList:
return "parameter list"
case .functionParameter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
### Miscellaneous Syntax

- <doc:SwiftSyntax/AccessorBlockSyntax>
- <doc:SwiftSyntax/AccessorEffectSpecifiersSyntax>
- <doc:SwiftSyntax/AccessorParameterSyntax>
- <doc:SwiftSyntax/AttributeSyntax>
- <doc:SwiftSyntax/AvailabilityConditionSyntax>
Expand All @@ -299,7 +300,6 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
- <doc:SwiftSyntax/ConformanceRequirementSyntax>
- <doc:SwiftSyntax/ConventionAttributeArgumentsSyntax>
- <doc:SwiftSyntax/ConventionWitnessMethodAttributeArgumentsSyntax>
- <doc:SwiftSyntax/DeclEffectSpecifiersSyntax>
- <doc:SwiftSyntax/DeclModifierDetailSyntax>
- <doc:SwiftSyntax/DeclNameArgumentsSyntax>
- <doc:SwiftSyntax/DeclNameSyntax>
Expand All @@ -311,6 +311,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
- <doc:SwiftSyntax/EnumCaseParameterClauseSyntax>
- <doc:SwiftSyntax/ExposeAttributeArgumentsSyntax>
- <doc:SwiftSyntax/ExpressionSegmentSyntax>
- <doc:SwiftSyntax/FunctionEffectSpecifiersSyntax>
- <doc:SwiftSyntax/FunctionSignatureSyntax>
- <doc:SwiftSyntax/GenericArgumentClauseSyntax>
- <doc:SwiftSyntax/GenericParameterClauseSyntax>
Expand Down
24 changes: 16 additions & 8 deletions Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: AccessorEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

override open func visitPost(_ node: AccessorEffectSpecifiersSyntax) {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: AccessorListSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}
Expand Down Expand Up @@ -565,14 +573,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: DeclEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

override open func visitPost(_ node: DeclEffectSpecifiersSyntax) {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: DeclModifierDetailSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}
Expand Down Expand Up @@ -957,6 +957,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: FunctionEffectSpecifiersSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

override open func visitPost(_ node: FunctionEffectSpecifiersSyntax) {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: FunctionParameterListSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ extension Syntax {
.node(AccessPathSyntax.self),
.node(AccessorBlockSyntax.self),
.node(AccessorDeclSyntax.self),
.node(AccessorEffectSpecifiersSyntax.self),
.node(AccessorListSyntax.self),
.node(AccessorParameterSyntax.self),
.node(ActorDeclSyntax.self),
Expand Down Expand Up @@ -797,7 +798,6 @@ extension Syntax {
.node(ContinueStmtSyntax.self),
.node(ConventionAttributeArgumentsSyntax.self),
.node(ConventionWitnessMethodAttributeArgumentsSyntax.self),
.node(DeclEffectSpecifiersSyntax.self),
.node(DeclModifierDetailSyntax.self),
.node(DeclModifierSyntax.self),
.node(DeclNameArgumentListSyntax.self),
Expand Down Expand Up @@ -846,6 +846,7 @@ extension Syntax {
.node(ForgetStmtSyntax.self),
.node(FunctionCallExprSyntax.self),
.node(FunctionDeclSyntax.self),
.node(FunctionEffectSpecifiersSyntax.self),
.node(FunctionParameterListSyntax.self),
.node(FunctionParameterSyntax.self),
.node(FunctionSignatureSyntax.self),
Expand Down
10 changes: 4 additions & 6 deletions Sources/SwiftSyntax/generated/SyntaxCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2387,8 +2387,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {

public let _syntaxNode: Syntax

@_spi(RawSyntax)
public var layoutView: RawSyntaxLayoutView {
private var layoutView: RawSyntaxLayoutView {
data.raw.layoutView!
}

Expand Down Expand Up @@ -2420,7 +2419,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {

/// The number of elements, `present` or `missing`, in this collection.
public var count: Int {
return raw.layoutView!.children.count
return layoutView.children.count
}

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

public let _syntaxNode: Syntax

@_spi(RawSyntax)
public var layoutView: RawSyntaxLayoutView {
private var layoutView: RawSyntaxLayoutView {
data.raw.layoutView!
}

Expand Down Expand Up @@ -4722,7 +4720,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {

/// The number of elements, `present` or `missing`, in this collection.
public var count: Int {
return raw.layoutView!.children.count
return layoutView.children.count
}

/// Creates a new `EnumCaseParameterListSyntax` by replacing the underlying layout with
Expand Down
Loading