Skip to content

[Concurrency] Allow struct members to have isolation annotations. #72214

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
Mar 10, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 9, 2024

The compiler was banning writing global actors or nonisolated on struct stored properties. This change removes those diagnostics.

I believe global actors were banned because it's safe to access a stored property as nonisolated if the property type is Sendable because of value semantics. We should absolutely allow that, but we should only allow it within the module (to preserve the ability for a stored property to evolve into a computed property), we should use the same mechanism that's used for allowing nonisolated access to actor lets that are Sendable, and we should formalize that semantic rule in a Swift evolution proposal.

For nonisolated, I'm not sure why the compiler banned this. nonisolated is fine on a struct stored property that is Sendable, and nonisolated(unsafe) can be used as a granular opt out for making a struct conform to Sendable without resorting to an @unchecked Sendable conformance when the property type is not Sendable.

@hborla
Copy link
Member Author

hborla commented Mar 9, 2024

@swift-ci please smoke test

@hborla hborla force-pushed the isolated-struct-properties branch from 1af0380 to 8bfe832 Compare March 9, 2024 22:15
@hborla
Copy link
Member Author

hborla commented Mar 9, 2024

@swift-ci please smoke test

@hborla hborla merged commit d3ed4a4 into swiftlang:main Mar 10, 2024
@hborla hborla deleted the isolated-struct-properties branch March 10, 2024 01:30
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.

1 participant