-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
inline attribute on async fn doesn't work properly #63647
Copy link
Copy link
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-codegenArea: Code generationArea: Code generationAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-codegenArea: Code generationArea: Code generationAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Playground link
In the playground, an
async fnis marked#[inline(always)]:However, if you compile it in debug mode (where inlining only happens for
#[inline(always)]functions), and search for12345in the generated assembly, you can see that it is not inlined.Indeed, there are multiple levels of function calls that are not inlined:
run_it→
GenFuture<T>::poll→
std::future::set_task_context→
GenFuture<T>::poll::{closure}→
playground::test::{{closure}}That last closure is the generator that contains the actual body of
test.#[inline(always)]is taking effect on the post-transformation functiontest, but all that does is initialize the generator struct.As long as async is implemented based on generators, this will be hard to fix. Even if the generator itself were marked
alwaysinline, that wouldn't affectGenFutureorset_task_context, both of which are fromlibstd.Related to #62918, since if you want an async fn to be
#[inline(always)], you probably also want to get rid of the TLS usage byset_task_context.