Teach #isolation
to respect the flow-sensitive nature of actor initializers
#74225
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.
Actor initializers have a flow-sensitive property where they are isolated to the actor being initialized only after the actor instance itself is fully-initialized. However, this behavior was not being reflected in the expansion of
#isolation
, which was always expanding toself
, even beforeself
is fully formed.This led to a source compatibility issue with code that used the async for..in loop within an actor initializer prior to the point where the actor was fully initialized, because the type checker is introducing the
#isolation
(SE-0421) but Definite Initialization properly rejects the use ofself
before it is initialized.Address this issue by delaying the expansion of
#isolation
until after the actor is fully initialized. In SILGen, we introduce a new builtin for this case (and just this case) calledflowSensitiveSelfIsolation
, which takes inself
as its argument and produces an(any Actor)?
. Definite initialization does not treat this as a use ofself
. Rather, it tracks these builtins and replaces them either withself
(if it is fully-initialized at this point) ornil
(if it is not fully-initialized at this point), mirroring the flow-sensitive isolation semantics described in SE-0327.Fixes rdar://127080037.