Skip to content

[5.6] Revert the partial SE-0338 implementation #41272

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

Conversation

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Feb 8, 2022

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 not Sendable, 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-isolated async 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 an async 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 calling with*Continuation from an actor-isolated context. The appropriate fix would be to annotate with*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 functions
Risk: Low, as it reverts to prior behavior
Testing: Regression
Review: @DougGregor

@rjmccall rjmccall requested a review from a team as a code owner February 8, 2022 19:08
@rjmccall
Copy link
Contributor Author

rjmccall commented Feb 8, 2022

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 8, 2022

Build failed
Swift Test OS X Platform
Git Sha - 1b58617

@rjmccall
Copy link
Contributor Author

rjmccall commented Feb 8, 2022

Please test with pull request:
swiftlang/llvm-project#3916

@swift-ci Please test macOS

@rjmccall rjmccall merged commit ce64fe8 into swiftlang:release/5.6 Feb 10, 2022
@rjmccall rjmccall deleted the revert-hop-to-generic-executor-5.6 branch February 10, 2022 04:55
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.

3 participants