[5.6] Revert the partial SE-0338 implementation #41272
Merged
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.
This reverts commit 0106bde (#41055).
Applying the SE-0338 semantics change to standard library functions like
with*Continuation
is causing bugs. The type of the closure argument to these functions is notSendable
, which means that a closure expression written there inherits the isolation of the caller. This is the desired behavior. However, SE-0338 is in fact “sending” the closure if the caller is actor-isolated: these functions are implemented as non-isolatedasync
functions, which means they immediately switch to the generic executor on entry, and then they call the closure on the generic executor instead of on the original executor. This is supposed to be forbidden by the sendability rule described in SE-0338: it should be illegal to pass a non-Sendable
closure to anasync
function that isn’t known to be isolated the same way as the calling context. That rule isn’t yet implemented; but even worse, if it was implemented, it would forbid callingwith*Continuation
from an actor-isolated context. The appropriate fix would be to annotatewith*Continuation
as inheriting the isolation of its caller, which would allow a non-Sendable
closure to be passed in and also ensure that the closure is called with the right isolation. However, that’s not a feature we can reasonably implement in Swift 5.6.SE-0338 also puts renewed pressure on programmers to get their actor annotations right, e.g. so that they don't rely on inheriting the main actor from the caller but instead express themselves where they need to run. However, that's clearly desirable in the long term, even if Swift hasn't yet fully held up its end of the grand bargain by reliably diagnosing isolation failures, such that programmers must remain proactively vigilant about running code on the right actor.
Fixes rdar://88639480
Scope: Affects compilation of all non-isolated
async
functionsRisk: Low, as it reverts to prior behavior
Testing: Regression
Review: @DougGregor