inline attribute on async fn doesn't work properly #63647
Labels
A-async-await
Area: Async & Await
A-attributes
Area: #[attributes(..)]
A-codegen
Area: Code generation
AsyncAwait-Triaged
Async-await issues that have been triaged during a working group meeting.
C-bug
Category: This is a bug.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
requires-nightly
This issue requires a nightly compiler in some way.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Playground link
In the playground, an
async fn
is marked#[inline(always)]
:However, if you compile it in debug mode (where inlining only happens for
#[inline(always)]
functions), and search for12345
in 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 affectGenFuture
orset_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
.The text was updated successfully, but these errors were encountered: