Skip save/restore of contexts in task-returning thunks; mark thunk infrastructure NonVersionable#129894
Skip save/restore of contexts in task-returning thunks; mark thunk infrastructure NonVersionable#129894jakobbotsch wants to merge 4 commits into
NonVersionable#129894Conversation
We do not need to save/restore contexts in task-returning thunks since that already happens in the JIT generated code for async functions. Also make the types and methods used in the thunks `NonVersionable` so they can be inlined by crossgen2. Bump R2R version and also rename some async members that were poorly named.
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
Pull request overview
Updates the CoreCLR runtime-async thunk contract (the members referenced from task-returning thunks and ReadyToRun images) by renaming key AsyncHelpers entrypoints, removing thunk-side context save/restore, and bumping the ReadyToRun major version to reflect the contract change.
Changes:
- Renames the thunk finalization entrypoints from
Finalize*ReturningThunktoCreateRuntimeAsync*and updates both VM-generated and crossgen2-generated thunk IL to call the new methods. - Removes
AsyncHelpers.CompletedTask*helpers and their binder entries. - Bumps ReadyToRun major/minimum version to
25and updates managed/native module header constants accordingly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/corelib.h | Updates CoreLibBinder method IDs for renamed runtime-async thunk entrypoints; removes binder entries for deleted CompletedTask* helpers. |
| src/coreclr/vm/asyncthunks.cpp | Updates VM IL stub emission to call the renamed CreateRuntimeAsync* methods when the wrapped async method suspends. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncThunks.cs | Updates crossgen2 thunk IL emitter to call the renamed CreateRuntimeAsync* methods. |
| src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs | Bumps managed ReadyToRun major version constant to 25. |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Removes root context save/restore from RuntimeAsyncAwaitState used by thunks; introduces dispatch-only context save/restore and renames thunk-entry methods. |
| src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h | Bumps native ReadyToRun major version constant to 25. |
| src/coreclr/inc/readytorun.h | Bumps ReadyToRun major/minimum to 25 and documents the version 25 change rationale. |
| private static Task<T?> CreateRuntimeAsyncTask<T>(ref RuntimeAsyncAwaitState state) | ||
| { | ||
| RuntimeAsyncTask<T?> result = new(); | ||
| FinalizeRuntimeAsyncTask(ref state, result!); | ||
| return result; |
There was a problem hiding this comment.
I think it's ok for these to not be NonVersionable, RuntimeAsyncStackState and RuntimeAsyncAwaitState are more important since they are used even for synchronously finishing tasks.
| [BypassReadyToRun] | ||
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] | ||
| private static unsafe void TransparentAwaitValueTask(ValueTask valueTask) | ||
| private static unsafe void Suspend(IValueTaskSource source, short token, bool continueOnCapturedContext) |
There was a problem hiding this comment.
No functional changes in these, just renaming and reordering.
There was a problem hiding this comment.
(Decided to remove the reordering from this PR to make the diff easier.)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs:1320
- TaskFromException helpers are also invoked by the task-returning thunks (see asyncthunks.cpp / AsyncThunks.cs). If the goal is to make thunk infrastructure NonVersionable for crossgen2 efficiency, these should likely be annotated as well (and similarly the adjacent ValueTaskFromException overloads, which are also thunk helpers but are outside the changed-line window for a separate inline comment here).
private static Task<T?> TaskFromException<T>(Exception ex)
{
Task<T?> task = new();
bool successfullySet = ex is OperationCanceledException oce ?
task.TrySetCanceled(oce.CancellationToken, oce) :
We do not need to save/restore contexts in task-returning thunks since that already happens in the JIT generated code for async functions.
Needs to wait for the bug fix in #129890.
Also make the types and methods used in the thunks
NonVersionablefor more efficient handling by crossgen2. Bump R2R version, and at the same time take the opportunity to rename various internal functions:FinalizeTaskReturningThunkandFinalizeValueTaskReturningThunktoCreateRuntimeAsyncTaskandCreateRuntimeAsyncValueTaskrespectivelySuspendandTransparentSuspendTransparentAwaitWithResultoverloads have been renamed toTransparentAwaitFix #122512