Skip to content

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

Merged

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jun 24, 2021

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

ktoso and others added 23 commits June 23, 2021 18:58
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)
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.
@DougGregor DougGregor requested a review from a team as a code owner June 24, 2021 06:26
@DougGregor
Copy link
Member Author

@swift-ci please test

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

👍

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - fcca37b

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - bf3f917

@DougGregor
Copy link
Member Author

Spurious failure on Linux. Retrying...

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bf3f917

@DougGregor
Copy link
Member Author

macOS hit the async_stream failure but is otherwise good. Rerunning...

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

@swift-ci please nominate

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bf3f917

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2673285

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@tkremenek tkremenek merged commit 847e3f7 into swiftlang:release/5.5 Jun 25, 2021
@DougGregor DougGregor deleted the centralize-task-creation-5.5 branch June 25, 2021 17:11
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.5 labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants