Skip to content

Commit 974c292

Browse files
authored
Merge pull request #3150 from meg-gupta/borrowandmutateaccessors
Add support for borrow and mutate accessors
2 parents c636838 + d165336 commit 974c292

File tree

10 files changed

+68
-3
lines changed

10 files changed

+68
-3
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public let DECL_NODES: [Node] = [
120120
.keyword(._modify),
121121
.keyword(.modify),
122122
.keyword(.`init`),
123+
.keyword(.borrow),
124+
.keyword(.mutate),
123125
])
124126
),
125127
Child(

CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum ExperimentalFeature: String, CaseIterable {
2323
case oldOwnershipOperatorSpellings
2424
case defaultIsolationPerFile
2525
case moduleSelector
26+
case borrowAndMutateAccessors
2627

2728
/// The name of the feature as it is written in the compiler's `Features.def` file.
2829
public var featureName: String {
@@ -47,6 +48,8 @@ public enum ExperimentalFeature: String, CaseIterable {
4748
return "DefaultIsolationPerFile"
4849
case .moduleSelector:
4950
return "ModuleSelector"
51+
case .borrowAndMutateAccessors:
52+
return "BorrowAndMutateAccessors"
5053
}
5154
}
5255

@@ -73,6 +76,8 @@ public enum ExperimentalFeature: String, CaseIterable {
7376
return "set default actor isolation for a file"
7477
case .moduleSelector:
7578
return "Module selector syntax (`ModName::identifier`)"
79+
case .borrowAndMutateAccessors:
80+
return "borrow and mutate accessors"
7681
}
7782
}
7883

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public enum Keyword: CaseIterable {
201201
case metadata
202202
case modify
203203
case module
204+
case mutate
204205
case mutableAddressWithNativeOwner
205206
case mutableAddressWithOwner
206207
case mutating
@@ -535,6 +536,8 @@ public enum Keyword: CaseIterable {
535536
return KeywordSpec("modify", experimentalFeature: .coroutineAccessors)
536537
case .module:
537538
return KeywordSpec("module")
539+
case .mutate:
540+
return KeywordSpec("mutate", experimentalFeature: .borrowAndMutateAccessors)
538541
case .mutableAddressWithNativeOwner:
539542
return KeywordSpec("mutableAddressWithNativeOwner")
540543
case .mutableAddressWithOwner:

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 1 deletion
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, .read, ._modify, .modify,
242+
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify, .mutate,
243243
// Misc
244244
.import, .using:
245245
self = .declKeyword

Sources/SwiftParser/generated/ExperimentalFeatures.swift

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

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

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

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 5 additions & 0 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: 3 additions & 1 deletion
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: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,6 +3473,28 @@ final class DeclarationTests: ParserTestCase {
34733473
)
34743474
}
34753475

3476+
func testBorrowAndMutateAccessors() {
3477+
assertParse(
3478+
"""
3479+
public class Klass {}
3480+
3481+
public struct Wrapper {
3482+
var _otherK: Klass
3483+
3484+
var k1: Klass {
3485+
borrow {
3486+
return _otherK
3487+
}
3488+
mutate {
3489+
return &_otherK
3490+
}
3491+
}
3492+
}
3493+
""",
3494+
experimentalFeatures: .borrowAndMutateAccessors
3495+
)
3496+
}
3497+
34763498
func testMissingCommaInParameters() {
34773499
assertParse(
34783500
"func a(foo: Bar1️⃣ foo2: Bar2) {}",

0 commit comments

Comments
 (0)