Skip to content

[AST/Sema] SE-0478: Implement using declaration under an experimental flag #81863

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented May 30, 2025

This is an alternative spelling of typealias DefaultIsolation = (MainActor | nonisolated) that was proposed as part of SE-0478.

using declaration accepts an attribute or a modifier and currently could be used to set a default actor isolation per file, but could be extended to support other use-cases in the future.

Implementation uses DefaultIsolationPerFile experimental feature flag to hide the syntax.

xedin added 2 commits May 30, 2025 00:39
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.
@xedin
Copy link
Contributor Author

xedin commented May 30, 2025

swiftlang/swift-syntax#3087
@swift-ci please test

@xedin xedin force-pushed the using-for-default-isolation-in-file-context branch from 724a885 to ae89b98 Compare May 30, 2025 23:41
@xedin
Copy link
Contributor Author

xedin commented May 30, 2025

swiftlang/swift-syntax#3087
@swift-ci please test

@xedin xedin changed the title [AST/Sema] SE-0478: Implement using declaration under an experimental flag [AST/Sema] SE-0478: Implement using declaration under an experimental flag May 30, 2025
xedin added 10 commits May 31, 2025 10:49
…f `.swift`

These are split-file C++ tests, this is a problem for swift-syntax
because `.swift` tests get parsed for round-trip testing if
swift-syntax is located near swift.
The default isolation is computed based on `using` declaration
found in the file, if any.
These declarations are effectively `fileprivate` at the moment
and should appear in swift interfaces.
Infer default actor isolation from `using` declaration in the
file scope and use it to override one that is set by `-default-isolation`
flag.
@xedin xedin force-pushed the using-for-default-isolation-in-file-context branch from ae89b98 to bc61bfb Compare May 31, 2025 18:10
@xedin
Copy link
Contributor Author

xedin commented May 31, 2025

swiftlang/swift-syntax#3087
@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jun 2, 2025

swiftlang/swift-syntax#3087
@swift-ci please smoke test macOS platform

@xedin
Copy link
Contributor Author

xedin commented Jun 2, 2025

swiftlang/swift-syntax#3087
@swift-ci please test source compatibility

@@ -66,3 +71,12 @@ func misisngPatternTest(arr: [Int]) {
for {} // expected-error {{expected pattern, 'in', and expression in 'for' statement}}
// expected-note@-1 {{insert pattern, 'in', and expression}} {{7-7=<#pattern#> }} {{7-7=in }} {{7-7=<#expression#> }}
}

using @MainActor // expected-note {{default isolation was previously declared here}}
using nonisolated // expected-error {{invalid redeclaration of file-level default actor isolation}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hah, exactly what I was worried about when I saw the proposal update :)
Good to see we diagnose this.

@xedin xedin merged commit e1e9f04 into swiftlang:main Jun 2, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants