Repository navigation
Conversation
Updated the proposal to properly support cancellation (a corresponding implementation is available).
al45tair
force-pushed
the
delayed-enqueuing-update
branch
from
July 1, 2026 14:19
a046a4e to
d5cd7b2
Compare
Revise the cancellation design to match the implementation.
Cancellation:
- `cancel` hands the job back (`ExecutorJob?`) rather than applying a
`CancellationBehavior`, so the caller decides what to do with an
unstarted job. Drop `CancellationBehavior` and the `onCancellation:`
parameter, and say why in Alternatives Considered.
- Split cancellation into `JobCanceller` (an `AnyObject, Sendable`
protocol with `cancel(jobWithToken:)` and a defaulted
`release(token:)`) and `JobCancellationToken`, which is `~Copyable`
and `Sendable` and has a borrowing, idempotent `cancel()`.
`release(token:)` is called exactly once, when the token is
destroyed, including after a cancel. Replace the `@convention(thin)`
clean-up function with it.
- Store `opaqueData` as `InlineArray<2, Int>` instead of a tuple, and
drop `jobID`.
- Say that tokens are `@unsafe` to create and that an executor may only
trust tokens it issued.
- Add "Implementing `cancel`". Cancelling a `Task.sleep()` runs `cancel`
from a cancellation handler while the runtime holds the task's status
record lock, so `cancel` must not wait on anything that is held while
jobs are enqueued or run. Describe the lock-free and try-lock
approaches.
Scheduling:
- Rename `enqueue(_:run:...)` to `schedule(_:at:tolerance:clock:)`. Make
`SchedulingExecutorFireTime` `Equatable`, `Hashable` and `Sendable`.
- `supportsScheduling(on:)` has no default. Executors that don't
handle a standard clock say so, and the runtime then never asks them
to schedule it.
- Add `SchedulingClock`, a permanent refining protocol of `Clock`, in
place of the scheduling methods on `Clock`, and explain the choice.
The standard clocks conform and schedule directly on a supporting
executor.
Task.sleep:
- Describe `Task.sleep()` in terms of split continuations: the
continuation is the job, so there is no separate continuation API or
stand-in job. Explain why `cancel` returns the job rather than a
continuation.
- Describe how the executor is chosen, the fallback when there is no
scheduling executor, and the allocation cost per sleep. Correct the
earlier "no additional allocation" claim.
Also update the ABI section to cover removed 6.3 SPI symbols, non-task
jobs reaching the C deadline entry points (`swift_job_alloc` returns
NULL for them), and the default Dispatch leeway change.
Removed the `asJob()` method in favour of providing a safe continuation API.
Re-wrapped some of the text. Tweaked the wording in places. Added a note about the necessity of a Job-based API.
Comparing the proposal and the implementation, we need to update a comment and also mention some of the other things that aren't there for Embedded Swift.
…add alternatives and future directions.
I don't think we should do `async` methods for `sleep` or `withDeadline`; this just pushes all of the implementation problems down into each executor, where we should be able to handle many of the difficult parts in the Concurrency runtime itself (making it much easier to write executors).
…ly for continuations with no result.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Updated the proposal to properly support cancellation (a corresponding implementation is available).