diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs index 64169a699065f4..5cd0a8e4298491 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs @@ -349,7 +349,6 @@ private static unsafe Continuation AllocContinuationClass(Continuation prevConti } #endif - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe void AwaitTask(Task task, ConfigureAwaitOptions options) { @@ -384,7 +383,6 @@ private static unsafe void AwaitTask(Task task, ConfigureAwaitOptions options) AsyncSuspend(taskCont); } - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe T AwaitTask(Task task, ConfigureAwaitOptions options) { @@ -430,7 +428,6 @@ private static unsafe T AwaitTask(Task task, ConfigureAwaitOptions options /// awaiting a completion of an underlying Task or ValueTaskSource. /// /// ValueTask whose completion we are awaiting. - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe void TransparentAwaitValueTask(ValueTask valueTask) { @@ -479,7 +476,6 @@ private static unsafe void TransparentAwaitValueTask(ValueTask valueTask) AsyncSuspend(nextCont); } - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe void AwaitValueTaskSource(IValueTaskSource source, short token, bool continueOnCapturedContext) { @@ -516,7 +512,6 @@ private static unsafe void AwaitValueTaskSource(IValueTaskSource source, short t AsyncSuspend(vtsCont); } - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe T TransparentAwaitValueTaskOfT(ValueTask valueTask) { @@ -565,7 +560,6 @@ private static unsafe T TransparentAwaitValueTaskOfT(ValueTask valueTask) return default!; } - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe T AwaitValueTaskSource(IValueTaskSource source, short token, bool continueOnCapturedContext) { @@ -607,7 +601,6 @@ private static unsafe T AwaitValueTaskSource(IValueTaskSource source, shor /// Used by internal thunks that implement awaiting on Task. /// /// Task whose completion we are awaiting. - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe void TransparentAwait(Task task) { @@ -637,7 +630,6 @@ private static unsafe void TransparentAwait(Task task) /// Used by internal thunks that implement awaiting on Task. /// /// Task whose completion we are awaiting. - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] private static unsafe T TransparentAwaitOfT(Task task) { diff --git a/src/coreclr/tools/Common/Compiler/AsyncMethodVariant.cs b/src/coreclr/tools/Common/Compiler/AsyncMethodVariant.cs index 78b0c9c76b174b..ad0c94de6626d7 100644 --- a/src/coreclr/tools/Common/Compiler/AsyncMethodVariant.cs +++ b/src/coreclr/tools/Common/Compiler/AsyncMethodVariant.cs @@ -152,9 +152,20 @@ public static bool IsReturnDroppingAsyncThunk(this MethodDesc method) public static bool IsAsyncThunk(this MethodDesc method) { + if (method.IsNonTaskReturningAsyncMethod()) + return false; + return (method.IsAsyncVariant() ^ method.IsAsync) || method.IsReturnDroppingAsyncThunk(); } + public static bool IsNonTaskReturningAsyncMethod(this MethodDesc method) + { + bool isNonTaskReturningAsyncMethod = method.GetTypicalMethodDefinition() is EcmaMethod && method.IsAsync && !method.Signature.ReturnsTaskOrValueTask(); + // non-task-returning async methods should only be in corelib + Debug.Assert(!isNonTaskReturningAsyncMethod || (method.GetTypicalMethodDefinition() is EcmaMethod methodDef && methodDef.Context.SystemModule == methodDef.Module)); + return isNonTaskReturningAsyncMethod; + } + public static bool IsCompilerGeneratedILBodyForAsync(this MethodDesc method) { return method.IsAsyncThunk() || method is AsyncResumptionStub; @@ -163,6 +174,7 @@ public static bool IsCompilerGeneratedILBodyForAsync(this MethodDesc method) public static MethodDesc GetAsyncVariant(this MethodDesc method) { Debug.Assert(!method.IsAsyncVariant()); + Debug.Assert(!method.IsNonTaskReturningAsyncMethod()); return ((CompilerTypeSystemContext)method.Context).GetAsyncVariantMethod(method); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.cs index daa89fb6a7a225..63212fdfe6f07e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.cs @@ -14,7 +14,6 @@ namespace System.Runtime.CompilerServices public static partial class AsyncHelpers { #if CORECLR || NATIVEAOT - // "BypassReadyToRun" is until AOT/R2R typesystem has support for MethodImpl.Async // Must be NoInlining because we use AsyncSuspend to manufacture an explicit suspension point. // It will not capture/restore any local state that is live across it. @@ -23,7 +22,6 @@ public static partial class AsyncHelpers /// /// The awaiter type. /// The awaiter to await. - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] [StackTraceHidden] public static unsafe void AwaitAwaiter(TAwaiter awaiter) where TAwaiter : INotifyCompletion @@ -43,7 +41,6 @@ public static unsafe void AwaitAwaiter(TAwaiter awaiter) where TAwaite /// /// The awaiter type. /// The awaiter to await. - [BypassReadyToRun] [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)] [StackTraceHidden] public static unsafe void UnsafeAwaitAwaiter(TAwaiter awaiter) where TAwaiter : ICriticalNotifyCompletion @@ -61,7 +58,6 @@ public static unsafe void UnsafeAwaitAwaiter(TAwaiter awaiter) where T /// The result type produced by the task. /// The task to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static T Await(Task task) @@ -81,7 +77,6 @@ public static T Await(Task task) /// /// The task to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static void Await(Task task) @@ -102,7 +97,6 @@ public static void Await(Task task) /// The result type produced by the value task. /// The value task to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static T Await(ValueTask task) @@ -141,7 +135,6 @@ public static T Await(ValueTask task) /// /// The value task to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static void Await(ValueTask task) @@ -182,7 +175,6 @@ public static void Await(ValueTask task) /// /// The configured awaitable to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static void Await(ConfiguredTaskAwaitable configuredAwaitable) @@ -206,7 +198,6 @@ public static void Await(ConfiguredTaskAwaitable configuredAwaitable) } [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async | MethodImplOptions.NoInlining)] [StackTraceHidden] private static void AwaitTaskWithRareOptions(ConfiguredTaskAwaitable.ConfiguredTaskAwaiter awaiter) @@ -224,7 +215,6 @@ private static void AwaitTaskWithRareOptions(ConfiguredTaskAwaitable.ConfiguredT /// /// The configured value task awaitable to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static void Await(ConfiguredValueTaskAwaitable configuredAwaitable) @@ -267,7 +257,6 @@ public static void Await(ConfiguredValueTaskAwaitable configuredAwaitable) /// The result type produced by the awaitable. /// The configured awaitable to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static T Await(ConfiguredTaskAwaitable configuredAwaitable) @@ -292,7 +281,6 @@ public static T Await(ConfiguredTaskAwaitable configuredAwaitable) /// The result type produced by the awaitable. /// The configured awaitable to await. [Intrinsic] - [BypassReadyToRun] [MethodImpl(MethodImplOptions.Async)] [StackTraceHidden] public static T Await(ConfiguredValueTaskAwaitable configuredAwaitable)