Skip to content

[Concurrency] nonisolated can only be applied to actor properties with Sendable type. #70909

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 28, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 13, 2024

Previously, the compiler allowed nonisolated to be written on any immutable stored property regardless of whether the type conformed to Sendable. Similarly, let properties in isolated types were considered nonisolated within the module regardless of the property type. This is unfortunate for a few reasons:

  • nonisolated on a non-Sendable property isn't helpful because you still cannot access the value across isolation boundaries. There were special case Sendable checks for actor lets sprinkled around to handle the diagnostics in these cases.
  • There's a semantic difference between accessing a nonisolated let vs a nonisolated(unsafe) var property across isolation domains. From the caller's perspective, nonisolated should have the same semantics regardless of whether or not unsafe was used.

Instead, we should treat lets of non-Sendable type as still being isolated, and ban writing nonisolated on a non-Sendable let property. Programmers can now use nonisolated(unsafe) if they need to access non-Sendable state across isolation boundaries. This also fixes an issue where flow isolation would prevent access to a nonisolated(unsafe) actor property after self becomes nonisolated in an initializer.

@hborla
Copy link
Member Author

hborla commented Jan 13, 2024

@swift-ci please smoke test

@hborla hborla force-pushed the nonisolated-nonsendable branch from 89ab8d8 to 5729c91 Compare January 13, 2024 21:03
@hborla
Copy link
Member Author

hborla commented Jan 13, 2024

@swift-ci please smoke test

1 similar comment
@hborla
Copy link
Member Author

hborla commented Jan 16, 2024

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Jan 17, 2024

@swift-ci please smoke test Linux

@hborla hborla force-pushed the nonisolated-nonsendable branch from 5729c91 to 009d7d0 Compare January 26, 2024 16:54
@hborla
Copy link
Member Author

hborla commented Jan 27, 2024

@swift-ci please smoke test

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