Skip to content

[Concurrency] Add a builtin to get the current task in an async function #34595

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

This introduces a new builtin, getCurrentAsyncTask(), that produces a
reference to the current task. This builtin can only be used within
async functions, and IR generation merely grabs the task argument
and packages it up.

The type of this function is () -> Builtin.NativeObject, because we
don't currently have a Swift-level representation of tasks, and can
probably handle everything through builtins or runtime calls.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

…ion.

This introduces a new builtin, `getCurrentAsyncTask()`, that produces a
reference to the current task. This builtin can only be used within
`async` functions, and IR generation merely grabs the task argument
and packages it up.

The type of this function is `() -> Builtin.NativeObject`, because we
don't currently have a Swift-level representation of tasks, and can
probably handle everything through builtins or runtime calls.
@DougGregor DougGregor force-pushed the get-current-async-task-builtin branch from 0696ad4 to 55a3c83 Compare November 5, 2020 20:18
Rather than produce an "unowned" result from `getCurrentAsyncTask()`,
take advantage of the fact that the task is effectively guaranteed in
the scope. Do so be returning it as "unowned", and push an
end_lifetime cleanup to end the lifetime. This eliminates unnecessary
ref-count traffic as well as introducing another use of unowned.

Approach is thanks to Michael Gottesman, bugs are mine.
@DougGregor DougGregor force-pushed the get-current-async-task-builtin branch from 55a3c83 to ed9a548 Compare November 5, 2020 20:19
Michael has ghostwritten all of this to address his own comments.
Thank you!
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 111b201 into swiftlang:main Nov 5, 2020
@DougGregor DougGregor deleted the get-current-async-task-builtin branch November 5, 2020 23:51
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.

2 participants