Skip to content

[Concurrency] improve cancellation handler to not hop and use caller execution context #80753

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Apr 11, 2025

The problem is that even with the #isolation parameter the non-Sendable
async closure operation still would potentially hop off the caller
isolation. We introduced this change because the plan was the
non-Sendable closure would run on the isolated parameter's isolation,
but that's not actually the case:

Instead, we can use the @execution(caller) on the function and closure,
in order to guarantee there is no hop between those at all, and
developers can trust that adding this cancellation handler will not
cause any unexpected isolation changes and hops. The API was always
documented to not hop as we execute the operation, so this brings the
correct and expected behavior.

resolves rdar://140110775

@ktoso ktoso requested a review from a team as a code owner April 11, 2025 07:24
@ktoso ktoso force-pushed the wip-improve-withTaskCancellationHandler-with-caller-execution branch 2 times, most recently from de601db to 1303d99 Compare April 11, 2025 07:28
@ktoso
Copy link
Contributor Author

ktoso commented Apr 12, 2025

This is blocked by incorrect behavior of the caller execution on a closure rdar://149107104

@ktoso ktoso added the concurrency Feature: umbrella label for concurrency language features label Apr 17, 2025
@ktoso ktoso force-pushed the wip-improve-withTaskCancellationHandler-with-caller-execution branch from 1303d99 to a583630 Compare April 25, 2025 08:10
ktoso added 2 commits April 30, 2025 10:53
The problem is that even with the #isolation parameter the non-Sendable
async closure operation _still_ would potentially hop off the caller
isolation. We introduced this change because the plan was the
non-Sendable closure would run on the isolated parameter's isolation,
but that's not actually the case:

Instead, we can use the @execution(caller) on the function and closure,
in order to guarantee there is no hop between those at all, and
developers can trust that adding this cancellation handler will not
cause any unexpected isolation changes and hops. The API was always
documented to not hop as we execute the operation, so this brings the
correct and expected behavior.

resolves rdar://140110775
@ktoso ktoso force-pushed the wip-improve-withTaskCancellationHandler-with-caller-execution branch from a583630 to 9ea3293 Compare April 30, 2025 02:13
@ktoso
Copy link
Contributor Author

ktoso commented Apr 30, 2025

Now blocked on rdar://150017382

@ktoso
Copy link
Contributor Author

ktoso commented May 15, 2025

@swift-ci please smoke test

@@ -63,6 +63,8 @@ endif()
list(APPEND SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS
"-enable-experimental-feature"
"IsolatedAny"
"-enable-experimental-feature"
"ExecutionAttribute"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant