Skip to content

Implement #isolation macro to produce the isolation of the current context #70902

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
merged 1 commit into from
Jan 16, 2024

Conversation

DougGregor
Copy link
Member

Introduce a new expression macro that produces an value of type (any AnyActor)? that describes the current actor isolation. This isolation will be nil in non-isolated code, and refer to either the actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag OptionalIsolatedParameters.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Looks like a great first step 🥳

@@ -0,0 +1,11 @@
@@ -1053,8 +1060,8 @@
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to commit this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, sorry. My local tree is a mess. This PR needs a bit of work still

…context

Introduce a new expression macro that produces an value of type
`(any AnyActor)?` that describes the current actor isolation. This
isolation will be `nil` in non-isolated code, and refer to either the
actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag
OptionalIsolatedParameters.
@DougGregor
Copy link
Member Author

Already tested, and I only dropped the one file. Merging...

@DougGregor DougGregor merged commit 8b514ec into swiftlang:main Jan 16, 2024
@DougGregor DougGregor deleted the isolation-macro branch January 16, 2024 22:27
/// isolated, or `nil` if the code is nonisolated.
@available(SwiftStdlib 5.1, *)
@freestanding(expression)
public macro isolation() -> (any AnyActor)? = Builtin.IsolationMacro
Copy link
Member

Choose a reason for hiding this comment

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

This just broke the Android community CI, which doesn't have a prebuilt host Swift compiler so the trunk compiler it builds doesn't use the swift-syntax parser and doesn't support macros:

swift/stdlib/public/Concurrency/Actor.swift:80:14: error: macros are not supported in this compiler
public macro isolation() -> (any AnyActor)? = Builtin.IsolationMacro
             ^

Other uses of macros in the stdlib have put in checks to avoid this problem, maybe something similar would work here?

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.

4 participants