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 1 commit 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 from 5d6b4f8 to de601db Compare April 11, 2025 07:25
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 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

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.

1 participant