-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Centralize task creation in the Concurrency runtime #38076
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
Centralize task creation in the Concurrency runtime #38076
Conversation
introduce new options parameter to all task spawning [Concurrency] ABI for asynclet start to accept options [Concurrency] fix unittest usages of changed task creation ABI [Concurrency] introduce constants for parameter indexes in ownership [Concurrency] fix test/SILOptimizer/closure_lifetime_fixup_concurrency.swift (cherry picked from commit 8536100)
(cherry picked from commit f37ae3d)
ExecutorRefs are a (pointer, witness table) pair that are meant to be passed around. We don't need to form a reference to one because they are ABI already.
Collapse the `group` parameter of this API into the task options, and have existing callers set up the options appropriately. The goal for this function is to become the centralized entry point for all task creation, with an extensible interface.
The flags that are useful for task creation are a bit different from the flags that go on a job. Create a separate flag set for task creation and use that in the API for `swift_task_create`. For now, have the callers do the remapping.
Introduce a builtin `createAsyncTask` that maps to `swift_task_create`, and use that for the non-group task creation operations based on the task-creation flags. `swift_task_create` and the thin function version `swift_task_create_f` go through the dynamically-replaceable `swift_task_create_common`, where all of the task creation logic is present. While here, move copying of task locals and the initial scheduling of the task into `swift_task_create_common`, enabling by separate flags.
We no longer need these entry points.
Extend the behavior of `swift_task_create_common` to also encompass adding the pending group task (when requested) and attaching it to the group.
We've moved everything over to `CreateAsyncTask` now.
This is a small shim over `swift_task_create`. Use that instead.
…all. Introduce a task option record to capture the async-let storage, so that `swift_task_create` can perform the appropriate initialization.
It's a tiny shim over `swift_task_create_common` that is rarely used. Switch all of the former callers over the common API.
Rather than using group task options constructed from the Swift parts of the _Concurrency library and passed through `createAsyncTask`'s options, introduce a separate builtin that always takes a group. Move the responsibility for creating the options structure into IRGen, so we don't need to expose the TaskGroupTaskOptionRecord type in Swift.
We'll keep the task options entirely as a contract between IRGen and the concurrency runtime, so Swift code need not deal with them.
We're not actually performing the adjustments at the moment due to an unrelated bug, and will want to perform them within `swift_task_create_common` based on inheritContext and the given priority.
The `swift_task_create` entry point is our general runtime ABI for launching tasks. Make the various Swift APIs sitting on top of it always-emit-into-client to take them out of the ABI. This reduces the number of ABI entry points and allows us to make more ABI-compatible changes to the Swift side.
This entry point is a small shim over `swift_task_create_common`, which is overridable. We don't need a separate override point here.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Build failed |
@swift-ci please test |
Build failed |
Spurious failure on Linux. Retrying... |
@swift-ci please test Linux |
Build failed |
macOS hit the async_stream failure but is otherwise good. Rerunning... |
@swift-ci please test macOS |
@swift-ci please nominate |
Build failed |
@swift-ci please test |
Build failed |
@swift-ci please test Linux |
Explanation: Centralize and clean up task creation facilities for the concurrency runtime. This reduces the number of entry points we use to create tasks while making them more general, so we can extend the task-creation facilities without breaking the ABI again. This itself is a significant ABI break for Swift Concurrency.
Scope: Affects all programs using Swift Concurrency
Radar/SR Issue: rdar://79584250
Risk: Moderate. It's a rework of compiler/runtime interaction for concurrent task creation, so it carries some risk of breaking programs using concurrency.
Testing: PR testing and CI on main.
Original PR: #38021