Skip to content
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
2 changes: 2 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public let DECL_NODES: [Node] = [
.keyword(._modify),
.keyword(.modify),
.keyword(.`init`),
.keyword(.borrow),
.keyword(.mutate),
])
),
Child(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ExperimentalFeature: String, CaseIterable {
case oldOwnershipOperatorSpellings
case defaultIsolationPerFile
case moduleSelector
case borrowAndMutateAccessors

/// The name of the feature as it is written in the compiler's `Features.def` file.
public var featureName: String {
Expand All @@ -47,6 +48,8 @@ public enum ExperimentalFeature: String, CaseIterable {
return "DefaultIsolationPerFile"
case .moduleSelector:
return "ModuleSelector"
case .borrowAndMutateAccessors:
return "BorrowAndMutateAccessors"
}
}

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

Expand Down
3 changes: 3 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public enum Keyword: CaseIterable {
case metadata
case modify
case module
case mutate
case mutableAddressWithNativeOwner
case mutableAddressWithOwner
case mutating
Expand Down Expand Up @@ -535,6 +536,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("modify", experimentalFeature: .coroutineAccessors)
case .module:
return KeywordSpec("module")
case .mutate:
return KeywordSpec("mutate", experimentalFeature: .borrowAndMutateAccessors)
case .mutableAddressWithNativeOwner:
return KeywordSpec("mutableAddressWithNativeOwner")
case .mutableAddressWithOwner:
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, .read, ._modify, .modify,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify, .mutate,
// Misc
.import, .using:
self = .declKeyword
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftParser/generated/ExperimentalFeatures.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3473,6 +3473,28 @@ final class DeclarationTests: ParserTestCase {
)
}

func testBorrowAndMutateAccessors() {
assertParse(
"""
public class Klass {}

public struct Wrapper {
var _otherK: Klass

var k1: Klass {
borrow {
Copy link
Member

Choose a reason for hiding this comment

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

I just want to mention that this will be source breaking for the following code, which is currently valid. I’ll leave it up to you to decide whether that source breakage is acceptable.

func borrow<T>(_ x: () -> T) -> T {
    return x()
}

var x: Int {
    borrow {
        1
    }
}

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 for pointing that out. This is currently experimental and is not an immediate problem. We may gate the feature on language version in the future if source breakage becomes a concern.

return _otherK
}
mutate {
return &_otherK
}
}
}
""",
experimentalFeatures: .borrowAndMutateAccessors
)
}

func testMissingCommaInParameters() {
assertParse(
"func a(foo: Bar1️⃣ foo2: Bar2) {}",
Expand Down
Loading