Skip to content

JIT: Add an AsyncHelpers.TailAwait intrinsic#124175

Closed
jakobbotsch wants to merge 4 commits intodotnet:mainfrom
jakobbotsch:tail-await
Closed

JIT: Add an AsyncHelpers.TailAwait intrinsic#124175
jakobbotsch wants to merge 4 commits intodotnet:mainfrom
jakobbotsch:tail-await

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Feb 9, 2026

Can be used to instruct the JIT that an upcoming await should not create an explicit suspension point. This can be used to optimize instantiating/unboxing stubs and will simplify the NAOT side of the implementation of those (#122126).

Can be used to instruct the JIT that an upcoming await should not create
an explicit suspension point. This can be used to optimize
instantiating/unboxing stubs and will simplify the NAOT side of the
implementation of those.
Copilot AI review requested due to automatic review settings February 9, 2026 13:07
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new AsyncHelpers.TailAwait intrinsic to let the runtime/JIT treat certain awaits as “tail awaits”, avoiding creation of an additional suspension point/continuation in forwarding stubs (notably instantiating/unboxing stubs), and updates the runtime async codegen documentation accordingly.

Changes:

  • Emit AsyncHelpers.TailAwait() from instantiating/unboxing IL stubs when the target method is async.
  • Add JIT recognition of AsyncHelpers.TailAwait (named intrinsic + importer handling) and plumb a “tail await” flag into async call metadata.
  • Extend async transformation to rewrite tail awaits to directly return the callee’s continuation (no new continuation allocation), plus small comment/doc updates.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/vm/prestub.cpp Emits TailAwait before async calli in generated instantiating/unboxing IL stubs.
src/coreclr/vm/corelib.h Adds CoreLib binder entry for AsyncHelpers.TailAwait.
src/coreclr/vm/asyncthunks.cpp Updates comment to refer to AsyncHelpers.AsyncCallContinuation.
src/coreclr/jit/namedintrinsiclist.h Adds named intrinsic enum value for AsyncHelpers.TailAwait.
src/coreclr/jit/importercalls.cpp Maps and imports TailAwait, setting a “next await is tail” flag that’s consumed by async-call setup.
src/coreclr/jit/gentree.h Adds IsTailAwait to AsyncCallInfo.
src/coreclr/jit/compiler.h Adds m_nextAwaitIsTail importer state.
src/coreclr/jit/async.h Adds tail-await transformation helpers and adjusts liveness plumbing signatures.
src/coreclr/jit/async.cpp Implements tail-await transformation and refactors continuation temp allocation to be lazy.
src/coreclr/System.Private.CoreLib/.../AsyncHelpers.CoreCLR.cs Adds intrinsic stub for TailAwait.
docs/design/coreclr/botr/runtime-async-codegen.md Updates documentation to reference AsyncHelpers.AsyncCallContinuation.

Copilot AI review requested due to automatic review settings February 9, 2026 14:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

@jakobbotsch
Copy link
Member Author

Folded into #122126

MichalStrehovsky added a commit that referenced this pull request Feb 12, 2026
We need to:

* Compile the unboxing/instantiating thunk as `CORJIT_FLAG_ASYNC` when
the target is AsyncCall
* Use the TailAwait intrinsic to just return the suspended state from
the called method instead of trying to suspend the instantiating thunk
too.

Also includes a JIT change from #124175.

Fixes #121781.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant