[Concurrency] nonisolated
can only be applied to actor properties with Sendable
type.
#70909
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the compiler allowed
nonisolated
to be written on any immutable stored property regardless of whether the type conformed toSendable
. Similarly,let
properties in isolated types were considerednonisolated
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 caseSendable
checks for actorlet
s sprinkled around to handle the diagnostics in these cases.nonisolated let
vs anonisolated(unsafe) var
property across isolation domains. From the caller's perspective,nonisolated
should have the same semantics regardless of whether or notunsafe
was used.Instead, we should treat
let
s of non-Sendable
type as still being isolated, and ban writingnonisolated
on a non-Sendable
let property. Programmers can now usenonisolated(unsafe)
if they need to access non-Sendable
state across isolation boundaries. This also fixes an issue where flow isolation would prevent access to anonisolated(unsafe)
actor property afterself
becomesnonisolated
in an initializer.