Skip to content

[CoroutineAccessors] Add read and modify. #2853

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

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public let DECL_NODES: [Node] = [
.keyword(.mutableAddressWithOwner),
.keyword(.mutableAddressWithNativeOwner),
.keyword(._read),
.keyword(.read),
.keyword(._modify),
.keyword(.modify),
.keyword(.`init`),
])
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ExperimentalFeature: String, CaseIterable {
case doExpressions
case nonescapableTypes
case trailingComma
case coroutineAccessors

/// The name of the feature, which is used in the doc comment.
public var featureName: String {
Expand All @@ -32,6 +33,8 @@ public enum ExperimentalFeature: String, CaseIterable {
return "NonEscableTypes"
case .trailingComma:
return "trailing comma"
case .coroutineAccessors:
return "CoroutineAccessors"
}
}

Expand Down
6 changes: 6 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public enum Keyword: CaseIterable {
case macro
case message
case metadata
case modify
case module
case mutableAddressWithNativeOwner
case mutableAddressWithOwner
Expand Down Expand Up @@ -245,6 +246,7 @@ public enum Keyword: CaseIterable {
case `Protocol`
case `protocol`
case `public`
case read
case reasync
case renamed
case `repeat`
Expand Down Expand Up @@ -576,6 +578,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("message")
case .metadata:
return KeywordSpec("metadata")
case .modify:
return KeywordSpec("modify", experimentalFeature: .coroutineAccessors)
case .module:
return KeywordSpec("module")
case .mutableAddressWithNativeOwner:
Expand Down Expand Up @@ -628,6 +632,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("protocol", isLexerClassified: true)
case .public:
return KeywordSpec("public", isLexerClassified: true)
case .read:
return KeywordSpec("read")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should read also be behind an experimental feature, like modify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed.

case .reasync:
return KeywordSpec("reasync")
case .renamed:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ enum TokenPrecedence: Comparable {
.dependsOn, .scoped, .sending,
// Accessors
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify,
// Misc
.import:
self = .declKeyword
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftParser/generated/ExperimentalFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ extension Parser.ExperimentalFeatures {

/// Whether to enable the parsing of trailing comma.
public static let trailingComma = Self (rawValue: 1 << 4)

/// Whether to enable the parsing of CoroutineAccessors.
public static let coroutineAccessors = Self (rawValue: 1 << 5)
}
21 changes: 21 additions & 0 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ extension AccessorDeclSyntax {
case mutableAddressWithOwner
case mutableAddressWithNativeOwner
case _read
case read
case _modify
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case modify
case `init`

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
Expand All @@ -59,8 +64,12 @@ extension AccessorDeclSyntax {
self = .mutableAddressWithNativeOwner
case TokenSpec(._read):
self = ._read
case TokenSpec(.read):
self = .read
case TokenSpec(._modify):
self = ._modify
case TokenSpec(.modify) where experimentalFeatures.contains(.coroutineAccessors):
self = .modify
case TokenSpec(.`init`):
self = .`init`
default:
Expand Down Expand Up @@ -92,8 +101,12 @@ extension AccessorDeclSyntax {
self = .mutableAddressWithNativeOwner
case TokenSpec(._read):
self = ._read
case TokenSpec(.read):
self = .read
case TokenSpec(._modify):
self = ._modify
case TokenSpec(.modify):
self = .modify
case TokenSpec(.`init`):
self = .`init`
default:
Expand Down Expand Up @@ -125,8 +138,12 @@ extension AccessorDeclSyntax {
return .keyword(.mutableAddressWithNativeOwner)
case ._read:
return .keyword(._read)
case .read:
return .keyword(.read)
case ._modify:
return .keyword(._modify)
case .modify:
return .keyword(.modify)
case .`init`:
return .keyword(.`init`)
}
Expand Down Expand Up @@ -160,8 +177,12 @@ extension AccessorDeclSyntax {
return .keyword(.mutableAddressWithNativeOwner)
case ._read:
return .keyword(._read)
case .read:
return .keyword(.read)
case ._modify:
return .keyword(._modify)
case .modify:
return .keyword(.modify)
case .`init`:
return .keyword(.`init`)
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ public enum Keyword: UInt8, Hashable, Sendable {
case macro
case message
case metadata
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case modify
case module
case mutableAddressWithNativeOwner
case mutableAddressWithOwner
Expand Down Expand Up @@ -188,6 +192,7 @@ public enum Keyword: UInt8, Hashable, Sendable {
case `Protocol`
case `protocol`
case `public`
case read
case reasync
case renamed
case `repeat`
Expand Down Expand Up @@ -322,6 +327,8 @@ public enum Keyword: UInt8, Hashable, Sendable {
self = .objc
case "open":
self = .open
case "read":
self = .read
case "safe":
self = .safe
case "self":
Expand Down Expand Up @@ -416,6 +423,8 @@ public enum Keyword: UInt8, Hashable, Sendable {
self = .inline
case "linear":
self = .linear
case "modify":
self = .modify
case "module":
self = .module
case "prefix":
Expand Down Expand Up @@ -946,6 +955,7 @@ public enum Keyword: UInt8, Hashable, Sendable {
"macro",
"message",
"metadata",
"modify",
"module",
"mutableAddressWithNativeOwner",
"mutableAddressWithOwner",
Expand Down Expand Up @@ -973,6 +983,7 @@ public enum Keyword: UInt8, Hashable, Sendable {
"Protocol",
"protocol",
"public",
"read",
"reasync",
"renamed",
"repeat",
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
.keyword("mutableAddressWithOwner"),
.keyword("mutableAddressWithNativeOwner"),
.keyword("_read"),
.keyword("read"),
.keyword("_modify"),
.keyword("modify"),
.keyword("init")
]))
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
///
/// - `attributes`: ``AttributeListSyntax``
/// - `modifier`: ``DeclModifierSyntax``?
/// - `accessorSpecifier`: (`get` | `set` | `didSet` | `willSet` | `unsafeAddress` | `addressWithOwner` | `addressWithNativeOwner` | `unsafeMutableAddress` | `mutableAddressWithOwner` | `mutableAddressWithNativeOwner` | `_read` | `_modify` | `init`)
/// - `accessorSpecifier`: (`get` | `set` | `didSet` | `willSet` | `unsafeAddress` | `addressWithOwner` | `addressWithNativeOwner` | `unsafeMutableAddress` | `mutableAddressWithOwner` | `mutableAddressWithNativeOwner` | `_read` | `read` | `_modify` | `modify` | `init`)
/// - `parameters`: ``AccessorParametersSyntax``?
/// - `effectSpecifiers`: ``AccessorEffectSpecifiersSyntax``?
/// - `body`: ``CodeBlockSyntax``?
Expand Down Expand Up @@ -418,7 +418,9 @@ public struct AccessorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclS
/// - `mutableAddressWithOwner`
/// - `mutableAddressWithNativeOwner`
/// - `_read`
/// - `read`
/// - `_modify`
/// - `modify`
/// - `init`
public var accessorSpecifier: TokenSyntax {
get {
Expand Down
16 changes: 16 additions & 0 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3334,4 +3334,20 @@ final class DeclarationTests: ParserTestCase {
)
)
}

func testCoroutineAccessors() {
assertParse(
"""
var i_rm: Int {
read {
yield _i
}
modify {
yield &_i
}
}
""",
experimentalFeatures: .coroutineAccessors
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test case that read and modify are not parsed when the .coroutineAccessors experimental features is not specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep--added one for each.

}