Skip to content

Commit d892c27

Browse files
committed
[CoroutineAccessors] Added modify.
1 parent 7443dab commit d892c27

File tree

8 files changed

+61
-2
lines changed

8 files changed

+61
-2
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public let DECL_NODES: [Node] = [
114114
.keyword(.mutableAddressWithNativeOwner),
115115
.keyword(._read),
116116
.keyword(._modify),
117+
.keyword(.modify),
117118
.keyword(.`init`),
118119
])
119120
),

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public enum Keyword: CaseIterable {
218218
case macro
219219
case message
220220
case metadata
221+
case modify
221222
case module
222223
case mutableAddressWithNativeOwner
223224
case mutableAddressWithOwner
@@ -576,6 +577,8 @@ public enum Keyword: CaseIterable {
576577
return KeywordSpec("message")
577578
case .metadata:
578579
return KeywordSpec("metadata")
580+
case .modify:
581+
return KeywordSpec("modify", experimentalFeature: .coroutineAccessors)
579582
case .module:
580583
return KeywordSpec("module")
581584
case .mutableAddressWithNativeOwner:

Sources/SwiftParser/TokenPrecedence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ enum TokenPrecedence: Comparable {
239239
.dependsOn, .scoped, .sending,
240240
// Accessors
241241
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
242-
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify,
242+
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify, .modify,
243243
// Misc
244244
.import:
245245
self = .declKeyword

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ extension AccessorDeclSyntax {
3333
case mutableAddressWithNativeOwner
3434
case _read
3535
case _modify
36+
#if compiler(>=5.8)
37+
@_spi(ExperimentalLanguageFeatures)
38+
#endif
39+
case modify
3640
case `init`
3741

3842
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
@@ -61,6 +65,8 @@ extension AccessorDeclSyntax {
6165
self = ._read
6266
case TokenSpec(._modify):
6367
self = ._modify
68+
case TokenSpec(.modify) where experimentalFeatures.contains(.coroutineAccessors):
69+
self = .modify
6470
case TokenSpec(.`init`):
6571
self = .`init`
6672
default:
@@ -94,6 +100,8 @@ extension AccessorDeclSyntax {
94100
self = ._read
95101
case TokenSpec(._modify):
96102
self = ._modify
103+
case TokenSpec(.modify):
104+
self = .modify
97105
case TokenSpec(.`init`):
98106
self = .`init`
99107
default:
@@ -127,6 +135,8 @@ extension AccessorDeclSyntax {
127135
return .keyword(._read)
128136
case ._modify:
129137
return .keyword(._modify)
138+
case .modify:
139+
return .keyword(.modify)
130140
case .`init`:
131141
return .keyword(.`init`)
132142
}
@@ -162,6 +172,8 @@ extension AccessorDeclSyntax {
162172
return .keyword(._read)
163173
case ._modify:
164174
return .keyword(._modify)
175+
case .modify:
176+
return .keyword(.modify)
165177
case .`init`:
166178
return .keyword(.`init`)
167179
}

Sources/SwiftSyntax/generated/Keyword.swift

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public enum Keyword: UInt8, Hashable, Sendable {
161161
case macro
162162
case message
163163
case metadata
164+
#if compiler(>=5.8)
165+
@_spi(ExperimentalLanguageFeatures)
166+
#endif
167+
case modify
164168
case module
165169
case mutableAddressWithNativeOwner
166170
case mutableAddressWithOwner
@@ -416,6 +420,8 @@ public enum Keyword: UInt8, Hashable, Sendable {
416420
self = .inline
417421
case "linear":
418422
self = .linear
423+
case "modify":
424+
self = .modify
419425
case "module":
420426
self = .module
421427
case "prefix":
@@ -946,6 +952,7 @@ public enum Keyword: UInt8, Hashable, Sendable {
946952
"macro",
947953
"message",
948954
"metadata",
955+
"modify",
949956
"module",
950957
"mutableAddressWithNativeOwner",
951958
"mutableAddressWithOwner",

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
243243
.keyword("mutableAddressWithNativeOwner"),
244244
.keyword("_read"),
245245
.keyword("_modify"),
246+
.keyword("modify"),
246247
.keyword("init")
247248
]))
248249
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
251251
///
252252
/// - `attributes`: ``AttributeListSyntax``
253253
/// - `modifier`: ``DeclModifierSyntax``?
254-
/// - `accessorSpecifier`: (`get` | `set` | `didSet` | `willSet` | `unsafeAddress` | `addressWithOwner` | `addressWithNativeOwner` | `unsafeMutableAddress` | `mutableAddressWithOwner` | `mutableAddressWithNativeOwner` | `_read` | `_modify` | `init`)
254+
/// - `accessorSpecifier`: (`get` | `set` | `didSet` | `willSet` | `unsafeAddress` | `addressWithOwner` | `addressWithNativeOwner` | `unsafeMutableAddress` | `mutableAddressWithOwner` | `mutableAddressWithNativeOwner` | `_read` | `_modify` | `modify` | `init`)
255255
/// - `parameters`: ``AccessorParametersSyntax``?
256256
/// - `effectSpecifiers`: ``AccessorEffectSpecifiersSyntax``?
257257
/// - `body`: ``CodeBlockSyntax``?
@@ -419,6 +419,7 @@ public struct AccessorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclS
419419
/// - `mutableAddressWithNativeOwner`
420420
/// - `_read`
421421
/// - `_modify`
422+
/// - `modify`
422423
/// - `init`
423424
public var accessorSpecifier: TokenSyntax {
424425
get {

Tests/SwiftParserTest/DeclarationTests.swift

+34
Original file line numberDiff line numberDiff line change
@@ -3334,4 +3334,38 @@ final class DeclarationTests: ParserTestCase {
33343334
)
33353335
)
33363336
}
3337+
3338+
func testCoroutineAccessors() {
3339+
assertParse(
3340+
"""
3341+
var i_rm: Int {
3342+
_read {
3343+
yield _i
3344+
}
3345+
modify {
3346+
yield &_i
3347+
}
3348+
}
3349+
""",
3350+
experimentalFeatures: .coroutineAccessors
3351+
)
3352+
assertParse(
3353+
"""
3354+
var i_rm: Int {
3355+
_read {
3356+
yield _i
3357+
}
3358+
1️⃣modify {
3359+
yield &_i
3360+
}
3361+
}
3362+
""",
3363+
diagnostics: [
3364+
DiagnosticSpec(
3365+
message: "unexpected code in variable"
3366+
)
3367+
]
3368+
)
3369+
3370+
}
33373371
}

0 commit comments

Comments
 (0)