Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h
// If you update this, ensure you run `git grep MINIMUM_READYTORUN_MAJOR_VERSION`
// and handle pending work.
#define READYTORUN_MAJOR_VERSION 24
#define READYTORUN_MAJOR_VERSION 25
#define READYTORUN_MINOR_VERSION 0x0000

#define MINIMUM_READYTORUN_MAJOR_VERSION 24
#define MINIMUM_READYTORUN_MAJOR_VERSION 25

// R2R Version 2.1 adds the InliningInfo section
// R2R Version 2.2 adds the ProfileDataInfo section
Expand Down Expand Up @@ -64,6 +64,7 @@
// R2R Version 22 changes NativeVarInfo encoding to include CALL_RETURN_VALUE
// R2R Version 23 changes delegate layout to have target before methodPtr
// R2R Version 24 changes ARM32 virtual stub dispatch hidden parameter register to R12
// R2R Version 25 renames runtime async infrastructure members and makes thunk-used members NonVersionable

struct READYTORUN_CORE_HEADER
{
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11689,7 +11689,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode)
//------------------------------------------------------------------------
// impWrapTopOfStackInAwait:
// Wrap the value on the top of the stack in
// AsyncHelpers.TransparentAwaitWithResult.
// AsyncHelpers.TransparentAwait.
//
// Returns:
// True if successful. False if the EE could not create the call (only during
Expand All @@ -11701,7 +11701,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode)
// mistyped; the original IL returns a Task or ValueTask, but the runtime
// async version expects to return the unwrapped result. This function
// accomplishes the unwrapping by inserting an async call to
// AsyncHelpers.TransparentAwaitWithResult around the value on the top of the
// AsyncHelpers.TransparentAwait around the value on the top of the
// stack.
//
bool Compiler::impWrapTopOfStackInAwait()
Expand Down Expand Up @@ -11814,7 +11814,7 @@ bool Compiler::impWrapTopOfStackInAwait()
//------------------------------------------------------------------------
// impFoldAwaitedTopOfStack:
// Fold a few patterns where introducing a call to
// AsyncHelpers.TransparentAwaitWithResult is unnecessary.
// AsyncHelpers.TransparentAwait is unnecessary.
//
// Returns:
// True if the top of stack was folded and the importer stack was updated
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ReadyToRunHeaderConstants
{
static const uint32_t Signature = 0x00525452; // 'RTR'

static const uint32_t CurrentMajorVersion = 24;
static const uint32_t CurrentMajorVersion = 25;
static const uint32_t CurrentMinorVersion = 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal struct ReadyToRunHeaderConstants
{
public const uint Signature = 0x00525452; // 'RTR'

public const ushort CurrentMajorVersion = 24;
public const ushort CurrentMajorVersion = 25;
public const ushort CurrentMinorVersion = 0;
}
#if READYTORUN
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3521,7 +3521,7 @@ private void getAsyncInfo(ref CORINFO_ASYNC_INFO pAsyncInfoOut)
? context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "ValueTask"u8)
: context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "Task"u8);
MethodSignature signature = new MethodSignature(MethodSignatureFlags.Static, 0, context.GetWellKnownType(WellKnownType.Void), [parameterType]);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwaitWithResult"u8, signature);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwait"u8, signature);
}
else
{
Expand All @@ -3530,7 +3530,7 @@ private void getAsyncInfo(ref CORINFO_ASYNC_INFO pAsyncInfoOut)
? context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "ValueTask`1"u8).MakeInstantiatedType(signatureVariable)
: context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "Task`1"u8).MakeInstantiatedType(signatureVariable);
MethodSignature signature = new MethodSignature(MethodSignatureFlags.Static, 1, signatureVariable, [parameterType]);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwaitWithResult"u8, signature).MakeInstantiatedMethod(returnType);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwait"u8, signature).MakeInstantiatedMethod(returnType);
}

MethodDesc result = runtimeDeterminedResult.GetCanonMethodTarget(CanonicalFormKind.Specific);
Expand Down
18 changes: 9 additions & 9 deletions src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncThunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class AsyncThunkILEmitter
// Emits a thunk that wraps an async method to return a Task or ValueTask.
// The thunk calls the async method, and if it completes synchronously,
// it returns a completed Task/ValueTask. If the async method suspends,
// it calls FinalizeTaskReturningThunk/FinalizeValueTaskReturningThunk method to get the Task/ValueTask.
// it calls CreateRuntimeAsyncTask/CreateRuntimeAsyncValueTask method to get the Task/ValueTask.

// The emitted code matches method EmitTaskReturningThunk in CoreCLR VM.
public static MethodIL EmitTaskReturningThunk(MethodDesc taskReturningMethod, MethodDesc asyncMethod)
Expand Down Expand Up @@ -191,35 +191,35 @@ public static MethodIL EmitTaskReturningThunk(MethodDesc taskReturningMethod, Me

codestream.EmitLabel(suspendedLabel);

MethodDesc finalizeTaskReturningThunkMd;
MethodDesc createRuntimeAsyncTaskMd;
if (logicalReturnType != null)
{
MethodSignature finalizeReturningThunkSignature = new MethodSignature(
MethodSignature createRuntimeAsyncTaskSignature = new MethodSignature(
MethodSignatureFlags.Static,
genericParameterCount: 1,
returnType: ((MetadataType)returnType.GetTypeDefinition()).MakeInstantiatedType(context.GetSignatureVariable(0, true)),
parameters: [awaitStateType.MakeByRefType()]
);

finalizeTaskReturningThunkMd = asyncHelpersType
.GetKnownMethod(isValueTask ? "FinalizeValueTaskReturningThunk"u8 : "FinalizeTaskReturningThunk"u8, finalizeReturningThunkSignature)
createRuntimeAsyncTaskMd = asyncHelpersType
.GetKnownMethod(isValueTask ? "CreateRuntimeAsyncValueTask"u8 : "CreateRuntimeAsyncTask"u8, createRuntimeAsyncTaskSignature)
.MakeInstantiatedMethod(new Instantiation(logicalReturnType));
}
else
{
MethodSignature finalizeReturningThunkSignature = new MethodSignature(
MethodSignature createRuntimeAsyncTaskSignature = new MethodSignature(
MethodSignatureFlags.Static,
genericParameterCount: 0,
returnType: returnType,
parameters: [awaitStateType.MakeByRefType()]
);

finalizeTaskReturningThunkMd = asyncHelpersType
.GetKnownMethod(isValueTask ? "FinalizeValueTaskReturningThunk"u8 : "FinalizeTaskReturningThunk"u8, finalizeReturningThunkSignature);
createRuntimeAsyncTaskMd = asyncHelpersType
.GetKnownMethod(isValueTask ? "CreateRuntimeAsyncValueTask"u8 : "CreateRuntimeAsyncTask"u8, createRuntimeAsyncTaskSignature);
}

codestream.EmitLdLoc(refAwaitStateLocal);
codestream.Emit(ILOpcode.call, emitter.NewToken(finalizeTaskReturningThunkMd));
codestream.Emit(ILOpcode.call, emitter.NewToken(createRuntimeAsyncTaskMd));
codestream.EmitStLoc(returnTaskLocal);
codestream.Emit(ILOpcode.leave, returnTaskLabel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ private void ImportReturn()
? context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "ValueTask"u8)
: context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "Task"u8);
MethodSignature signature = new MethodSignature(MethodSignatureFlags.Static, 0, context.GetWellKnownType(WellKnownType.Void), [parameterType]);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwaitWithResult"u8, signature);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwait"u8, signature);
}
else
{
Expand All @@ -1819,7 +1819,7 @@ private void ImportReturn()
? context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "ValueTask`1"u8).MakeInstantiatedType(signatureVariable)
: context.SystemModule.GetKnownType("System.Threading.Tasks"u8, "Task`1"u8).MakeInstantiatedType(signatureVariable);
MethodSignature signature = new MethodSignature(MethodSignatureFlags.Static, 1, signatureVariable, [parameterType]);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwaitWithResult"u8, signature).MakeInstantiatedMethod(returnType);
runtimeDeterminedResult = asyncHelpers.GetKnownMethod("TransparentAwait"u8, signature).MakeInstantiatedMethod(returnType);
}

MethodDesc targetMethod = runtimeDeterminedResult.GetCanonMethodTarget(CanonicalFormKind.Specific);
Expand Down
18 changes: 9 additions & 9 deletions src/coreclr/vm/asyncthunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void MethodDesc::EmitTaskReturningThunk(MethodDesc* pAsyncCallVariant, MetaSig&
// if (AsyncHelpers.AsyncCallContinuation() == null)
// return Task.FromResult(result);
//
// return FinalizeTaskReturningThunk(ref awaitState);
// return CreateRuntimeAsyncTask(ref awaitState);
// }
// catch (Exception ex)
// {
Expand Down Expand Up @@ -229,29 +229,29 @@ void MethodDesc::EmitTaskReturningThunk(MethodDesc* pAsyncCallVariant, MetaSig&

pCode->EmitLabel(suspendedLabel);

int finalizeTaskReturningThunkToken;
int createRuntimeAsyncTaskToken;
if (logicalResultLocal != UINT_MAX)
{
MethodDesc* md;
if (isValueTask)
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__FINALIZE_VALUETASK_RETURNING_THUNK_1);
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__CREATE_RUNTIME_ASYNC_VALUE_TASK_1);
else
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__FINALIZE_TASK_RETURNING_THUNK_1);
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__CREATE_RUNTIME_ASYNC_TASK_1);

md = FindOrCreateAssociatedMethodDesc(md, md->GetMethodTable(), FALSE, Instantiation(&thLogicalRetType, 1), FALSE);
finalizeTaskReturningThunkToken = GetTokenForGenericMethodCallWithAsyncReturnType(pCode, md);
createRuntimeAsyncTaskToken = GetTokenForGenericMethodCallWithAsyncReturnType(pCode, md);
}
else
{
MethodDesc* md;
if (isValueTask)
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__FINALIZE_VALUETASK_RETURNING_THUNK);
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__CREATE_RUNTIME_ASYNC_VALUE_TASK);
else
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__FINALIZE_TASK_RETURNING_THUNK);
finalizeTaskReturningThunkToken = pCode->GetToken(md);
md = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__CREATE_RUNTIME_ASYNC_TASK);
createRuntimeAsyncTaskToken = pCode->GetToken(md);
}
pCode->EmitLDLOC(refAwaitStateLocal);
pCode->EmitCALL(finalizeTaskReturningThunkToken, 1, 1);
pCode->EmitCALL(createRuntimeAsyncTaskToken, 1, 1);
pCode->EmitSTLOC(returnTaskLocal);
pCode->EmitLEAVE(returnTaskLabel);

Expand Down
22 changes: 8 additions & 14 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,26 +707,20 @@ DEFINE_METHOD(ASYNC_HELPERS, ALLOC_CONTINUATION, AllocContinuation,
DEFINE_METHOD(ASYNC_HELPERS, ALLOC_CONTINUATION_METHOD, AllocContinuationMethod, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, ALLOC_CONTINUATION_CLASS, AllocContinuationClass, NoSig)

DEFINE_METHOD(ASYNC_HELPERS, FINALIZE_TASK_RETURNING_THUNK, FinalizeTaskReturningThunk, SM_RefRuntimeAsyncAwaitState_RetTask)
DEFINE_METHOD(ASYNC_HELPERS, FINALIZE_TASK_RETURNING_THUNK_1, FinalizeTaskReturningThunk, GM_RefRuntimeAsyncAwaitState_RetTaskOfT)
DEFINE_METHOD(ASYNC_HELPERS, FINALIZE_VALUETASK_RETURNING_THUNK, FinalizeValueTaskReturningThunk, SM_RefRuntimeAsyncAwaitState_RetValueTask)
DEFINE_METHOD(ASYNC_HELPERS, FINALIZE_VALUETASK_RETURNING_THUNK_1, FinalizeValueTaskReturningThunk, GM_RefRuntimeAsyncAwaitState_RetValueTaskOfT)
DEFINE_METHOD(ASYNC_HELPERS, CREATE_RUNTIME_ASYNC_TASK, CreateRuntimeAsyncTask, SM_RefRuntimeAsyncAwaitState_RetTask)
DEFINE_METHOD(ASYNC_HELPERS, CREATE_RUNTIME_ASYNC_TASK_1, CreateRuntimeAsyncTask, GM_RefRuntimeAsyncAwaitState_RetTaskOfT)
DEFINE_METHOD(ASYNC_HELPERS, CREATE_RUNTIME_ASYNC_VALUE_TASK, CreateRuntimeAsyncValueTask, SM_RefRuntimeAsyncAwaitState_RetValueTask)
DEFINE_METHOD(ASYNC_HELPERS, CREATE_RUNTIME_ASYNC_VALUE_TASK_1, CreateRuntimeAsyncValueTask, GM_RefRuntimeAsyncAwaitState_RetValueTaskOfT)

DEFINE_METHOD(ASYNC_HELPERS, TASK_FROM_EXCEPTION, TaskFromException, SM_Exception_RetTask)
DEFINE_METHOD(ASYNC_HELPERS, TASK_FROM_EXCEPTION_1, TaskFromException, GM_Exception_RetTaskOfT)
DEFINE_METHOD(ASYNC_HELPERS, VALUETASK_FROM_EXCEPTION, ValueTaskFromException, SM_Exception_RetValueTask)
DEFINE_METHOD(ASYNC_HELPERS, VALUETASK_FROM_EXCEPTION_1, ValueTaskFromException, GM_Exception_RetValueTaskOfT)

DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT, TransparentAwait, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_OF_T, TransparentAwaitOfT, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_VALUE_TASK, TransparentAwaitValueTask, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_VALUE_TASK_OF_T, TransparentAwaitValueTaskOfT, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_TASK_WITH_RESULT, TransparentAwaitWithResult, SM_Task_RetVoid)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_VALUETASK_WITH_RESULT, TransparentAwaitWithResult, SM_ValueTask_RetVoid)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_TASK_OF_T_WITH_RESULT, TransparentAwaitWithResult, GM_TaskOfT_RetT)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_VALUETASK_OF_T_WITH_RESULT, TransparentAwaitWithResult, GM_ValueTaskOfT_RetT)
DEFINE_METHOD(ASYNC_HELPERS, COMPLETED_TASK_RESULT, CompletedTaskResult, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, COMPLETED_TASK, CompletedTask, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_TASK, TransparentAwait, SM_Task_RetVoid)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_VALUETASK, TransparentAwait, SM_ValueTask_RetVoid)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_TASK_OF_T, TransparentAwait, GM_TaskOfT_RetT)
DEFINE_METHOD(ASYNC_HELPERS, TRANSPARENT_AWAIT_VALUETASK_OF_T, TransparentAwait, GM_ValueTaskOfT_RetT)
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_EXECUTION_CONTEXT, CaptureExecutionContext, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_CONTINUATION_CONTEXT, CaptureContinuationContext, NoSig)
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_CONTEXTS, CaptureContexts, NoSig)
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10345,23 +10345,23 @@ CORINFO_METHOD_HANDLE CEEInfo::getAwaitReturnCall(CORINFO_METHOD_HANDLE callerHa
{
if (sig.IsReturnTypeVoid())
{
pTypicalAwaitMD = pMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_VALUETASK_WITH_RESULT);
pTypicalAwaitMD = pMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_VALUETASK);
}
else
{
pTypicalAwaitMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_VALUETASK_OF_T_WITH_RESULT);
pTypicalAwaitMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_VALUETASK_OF_T);
pMD = MethodDesc::FindOrCreateAssociatedMethodDesc(pTypicalAwaitMD, pTypicalAwaitMD->GetMethodTable(), FALSE, Instantiation(&retType, 1), TRUE);
}
}
else
{
if (sig.IsReturnTypeVoid())
{
pTypicalAwaitMD = pMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_TASK_WITH_RESULT);
pTypicalAwaitMD = pMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_TASK);
}
else
{
pTypicalAwaitMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_TASK_OF_T_WITH_RESULT);
pTypicalAwaitMD = CoreLibBinder::GetMethod(METHOD__ASYNC_HELPERS__TRANSPARENT_AWAIT_TASK_OF_T);
pMD = MethodDesc::FindOrCreateAssociatedMethodDesc(pTypicalAwaitMD, pTypicalAwaitMD->GetMethodTable(), FALSE, Instantiation(&retType, 1), TRUE);
}
}
Expand Down
Loading
Loading