Skip to content

Commit 54be8c8

Browse files
authored
Move StubHelpers.AsyncCallContinuation to AsyncHelpers. (#121458)
Moves StubHelpers.AsyncCallContinuation to AsyncHelpers so StubHelpers.cs doesn't need to be added to nativeaot. Thought it would be good to have separate commits for this and the rest of #121456
1 parent 4459d20 commit 54be8c8

File tree

9 files changed

+21
-17
lines changed

9 files changed

+21
-17
lines changed

src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,20 @@ public ref byte GetResultStorageOrNull()
144144

145145
public static partial class AsyncHelpers
146146
{
147-
// This is the "magic" method on wich other "Await" methods are built.
147+
// This is the "magic" method on which other "Await" methods are built.
148148
// Calling this from an Async method returns the continuation to the caller thus
149149
// explicitly initiates suspension.
150150
[Intrinsic]
151151
private static void AsyncSuspend(Continuation continuation) => throw new UnreachableException();
152152

153+
// An intrinsic that provides access to continuations produced by Async calls.
154+
// Calling this after an Async method call returns:
155+
// * `null` if the call has completed synchronously, or
156+
// * a continuation object if the call requires suspension.
157+
// In this case the formal result of the call is undefined.
158+
[Intrinsic]
159+
private static Continuation? AsyncCallContinuation() => throw new UnreachableException();
160+
153161
// Used during suspensions to hold the continuation chain and on what we are waiting.
154162
// Methods like FinalizeTaskReturningThunk will unlink the state and wrap into a Task.
155163
private struct RuntimeAsyncAwaitState

src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,9 +1610,6 @@ internal static void MulticastDebuggerTraceHelper(object o, int count)
16101610

16111611
[Intrinsic]
16121612
internal static IntPtr NextCallReturnAddress() => throw new UnreachableException(); // Unconditionally expanded intrinsic
1613-
1614-
[Intrinsic]
1615-
internal static Continuation? AsyncCallContinuation() => throw new UnreachableException(); // Unconditionally expanded intrinsic
16161613
} // class StubHelpers
16171614

16181615
#if FEATURE_COMINTEROP

src/coreclr/jit/gentree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ bool GenTreeCall::HasSideEffects(Compiler* compiler, bool ignoreExceptions, bool
22652265
// those cases the JIT does not know (and does not need to know) which arg is
22662266
// the async continuation.
22672267
//
2268-
// The VM also uses the StubHelpers.AsyncCallContinuation() intrinsic in the
2268+
// The VM also uses the AsyncHelpers.AsyncCallContinuation() intrinsic in the
22692269
// stubs discussed above. The JIT must take care in those cases to still mark
22702270
// the preceding call as an async call; this is required for correct LSRA
22712271
// behavior and GC reporting around the returned async continuation. This is

src/coreclr/jit/importercalls.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,7 +3323,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
33233323
return new (this, GT_LABEL) GenTree(GT_LABEL, TYP_I_IMPL);
33243324
}
33253325

3326-
if (ni == NI_System_StubHelpers_AsyncCallContinuation)
3326+
if (ni == NI_System_Runtime_CompilerServices_AsyncHelpers_AsyncCallContinuation)
33273327
{
33283328
GenTree* node = new (this, GT_ASYNC_CONTINUATION) GenTree(GT_ASYNC_CONTINUATION, TYP_REF);
33293329
node->SetHasOrderingSideEffect();
@@ -10872,6 +10872,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
1087210872
{
1087310873
result = NI_System_Runtime_CompilerServices_AsyncHelpers_Await;
1087410874
}
10875+
else if (strcmp(methodName, "AsyncCallContinuation") == 0)
10876+
{
10877+
result = NI_System_Runtime_CompilerServices_AsyncHelpers_AsyncCallContinuation;
10878+
}
1087510879
}
1087610880
else if (strcmp(className, "StaticsHelpers") == 0)
1087710881
{
@@ -11129,10 +11133,6 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
1112911133
{
1113011134
result = NI_System_StubHelpers_NextCallReturnAddress;
1113111135
}
11132-
else if (strcmp(methodName, "AsyncCallContinuation") == 0)
11133-
{
11134-
result = NI_System_StubHelpers_AsyncCallContinuation;
11135-
}
1113611136
}
1113711137
}
1113811138
else if (strcmp(namespaceName, "Text") == 0)

src/coreclr/jit/namedintrinsiclist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ enum NamedIntrinsic : unsigned short
107107
NI_System_RuntimeType_get_TypeHandle,
108108
NI_System_StubHelpers_GetStubContext,
109109
NI_System_StubHelpers_NextCallReturnAddress,
110-
NI_System_StubHelpers_AsyncCallContinuation,
111110

112111
NI_Array_Address,
113112
NI_Array_Get,
@@ -126,6 +125,7 @@ enum NamedIntrinsic : unsigned short
126125

127126
NI_System_Runtime_CompilerServices_AsyncHelpers_AsyncSuspend,
128127
NI_System_Runtime_CompilerServices_AsyncHelpers_Await,
128+
NI_System_Runtime_CompilerServices_AsyncHelpers_AsyncCallContinuation,
129129

130130
NI_System_Runtime_CompilerServices_StaticsHelpers_VolatileReadAsByref,
131131

src/coreclr/vm/asyncthunks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void MethodDesc::EmitTaskReturningThunk(MethodDesc* pAsyncOtherVariant, MetaSig&
190190

191191
if (logicalResultLocal != UINT_MAX)
192192
pCode->EmitSTLOC(logicalResultLocal);
193-
pCode->EmitCALL(METHOD__STUBHELPERS__ASYNC_CALL_CONTINUATION, 0, 1);
193+
pCode->EmitCALL(METHOD__ASYNC_HELPERS__ASYNC_CALL_CONTINUATION, 0, 1);
194194
pCode->EmitBRFALSE(finishedLabel);
195195

196196
pCode->EmitLEAVE(suspendedLabel);

src/coreclr/vm/corelib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,9 @@ DEFINE_METHOD(ASYNC_HELPERS, COMPLETED_TASK, CompletedTask, NoSi
747747
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_EXECUTION_CONTEXT, CaptureExecutionContext, NoSig)
748748
DEFINE_METHOD(ASYNC_HELPERS, RESTORE_EXECUTION_CONTEXT, RestoreExecutionContext, NoSig)
749749
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_CONTINUATION_CONTEXT, CaptureContinuationContext, NoSig)
750-
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_CONTEXTS, CaptureContexts, NoSig)
751-
DEFINE_METHOD(ASYNC_HELPERS, RESTORE_CONTEXTS, RestoreContexts, NoSig)
750+
DEFINE_METHOD(ASYNC_HELPERS, CAPTURE_CONTEXTS, CaptureContexts, NoSig)
751+
DEFINE_METHOD(ASYNC_HELPERS, RESTORE_CONTEXTS, RestoreContexts, NoSig)
752+
DEFINE_METHOD(ASYNC_HELPERS, ASYNC_CALL_CONTINUATION, AsyncCallContinuation, NoSig)
752753

753754
#ifdef TARGET_BROWSER
754755
DEFINE_METHOD(ASYNC_HELPERS, HANDLE_ASYNC_ENTRYPOINT, HandleAsyncEntryPoint, SM_TaskOfInt_RetInt)
@@ -1098,7 +1099,6 @@ DEFINE_METHOD(STUBHELPERS, VALIDATE_BYREF, Validate
10981099
DEFINE_METHOD(STUBHELPERS, GET_STUB_CONTEXT, GetStubContext, SM_RetIntPtr)
10991100
DEFINE_METHOD(STUBHELPERS, LOG_PINNED_ARGUMENT, LogPinnedArgument, SM_IntPtr_IntPtr_RetVoid)
11001101
DEFINE_METHOD(STUBHELPERS, NEXT_CALL_RETURN_ADDRESS, NextCallReturnAddress, SM_RetIntPtr)
1101-
DEFINE_METHOD(STUBHELPERS, ASYNC_CALL_CONTINUATION, AsyncCallContinuation, SM_RetContinuation)
11021102
DEFINE_METHOD(STUBHELPERS, SAFE_HANDLE_ADD_REF, SafeHandleAddRef, SM_SafeHandle_RefBool_RetIntPtr)
11031103
DEFINE_METHOD(STUBHELPERS, SAFE_HANDLE_RELEASE, SafeHandleRelease, SM_SafeHandle_RetVoid)
11041104

src/coreclr/vm/jitinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14763,7 +14763,7 @@ CORINFO_METHOD_HANDLE CEEJitInfo::getAsyncResumptionStub(void** entryPoint)
1476314763

1476414764
TypeHandle continuationTypeHnd = CoreLibBinder::GetClass(CLASS__CONTINUATION);
1476514765
DWORD newContinuationLoc = pCode->NewLocal(LocalDesc(continuationTypeHnd));
14766-
pCode->EmitCALL(METHOD__STUBHELPERS__ASYNC_CALL_CONTINUATION, 0, 1);
14766+
pCode->EmitCALL(METHOD__ASYNC_HELPERS__ASYNC_CALL_CONTINUATION, 0, 1);
1476714767
pCode->EmitSTLOC(newContinuationLoc);
1476814768

1476914769
if (!msig.IsReturnTypeVoid())

src/coreclr/vm/metasig.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ DEFINE_METASIG(SM(PtrByte_RetStr, P(b), s))
619619
DEFINE_METASIG(SM(Str_RetPtrByte, s, P(b)))
620620
DEFINE_METASIG(SM(PtrByte_RetVoid, P(b), v))
621621

622-
DEFINE_METASIG_T(SM(RetContinuation, , C(CONTINUATION)))
623622
DEFINE_METASIG(GM(T_RetVoid, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, M(0), v))
624623
DEFINE_METASIG_T(GM(RetTaskOfT, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, , GI(C(TASK_1), 1, M(0))))
625624
DEFINE_METASIG_T(GM(RetValueTaskOfT, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, , GI(g(VALUETASK_1), 1, M(0))))

0 commit comments

Comments
 (0)