diff --git a/docs/design/specs/runtime-async.md b/docs/design/specs/runtime-async.md index adc1d2ff064046..48985b139b4cec 100644 --- a/docs/design/specs/runtime-async.md +++ b/docs/design/specs/runtime-async.md @@ -11,7 +11,15 @@ These are proposed modifications to the ECMA-335 specification for runtime-async ### I.8.4.5 Sync and Async Methods -Methods may be either 'sync' or 'async'. Async method definitions are methods with a return type of `System.Threading.Task`, `System.Threading.ValueTask`, `System.Threading.Task`, or `System.Threading.ValueTask` attributed with `[System.Runtime.CompilerServices.RuntimeAsyncMethodAttribute]`. Async method definitions are only valid inside async-capable assemblies. An async-capable assembly is one which references a corlib containing an `abstract sealed class RuntimeFeature` with a `public const string` field member named `Async`, or a corelib meeting these requirements. The `RuntimeAsyncMethodAttribute` should only be applied to methods, and may be defined in any assembly. Inside async method bodies, certain methods are also invokable by a special signature encoding, described in [### I.8.6.1.5 Method signatures]. +Methods may be either 'sync' or 'async'. Async method definitions are methods attributed with `[MethodImpl(MethodImplOptions.Async)]`. Inside async method bodies, certain methods are also invokable by a special signature encoding, described in [### I.8.6.1.5 Method signatures]. + +Applicability of `MethodImplOptions.Async`: +* The `[MethodImpl(MethodImplOptions.Async)]` only has effect when applied to method definitions that return generic or nongeneric variants of Task or ValueTask. +* The `[MethodImpl(MethodImplOptions.Async)]` only has effect when applied to method definitions with CIL implementation. +* Async method definitions are only valid inside async-capable assemblies. An async-capable assembly is one which references a corlib containing an `abstract sealed class RuntimeFeature` with a `public const string` field member named `Async`. +* Combining `MethodImplOptions.Async` with `MethodImplOptions.Synchronized` is invalid. +* Applying `MethodImplOptions.Async` to methods with `byref` or `ref-like` parameters is invalid. +* Applying `MethodImplOptions.Async` to vararg methods is invalid. Sync methods are all other methods. @@ -28,9 +36,9 @@ Async methods support the following suspension points: { public static class RuntimeHelpers { - [RuntimeAsyncMethod] + [MethodImpl(MethodImplOptions.Async)] public static Task AwaitAwaiterFromRuntimeAsync(TAwaiter awaiter) where TAwaiter : INotifyCompletion { ... } - [RuntimeAsyncMethod] + [MethodImpl(MethodImplOptions.Async)] public static Task UnsafeAwaitAwaiterFromRuntimeAsync(TAwaiter awaiter) where TAwaiter : ICriticalNotifyCompletion } } @@ -55,6 +63,13 @@ All async methods effectively have two entry points, or signatures. The first si Callers may retrieve a Task/ValueTask return type from an async method via calling its primary, definitional signature. This functionality is available in both sync and async methods. +### II.23.1.11 Flags for methods [MethodImplAttributes] + +| Flag | Value | Description | +| ------------- | ------------- | ------------- | +| . . . | . . . | . . . | +|Async |0x0400 |Method is an Async Method.| + ### I.8.6.1.5 Method signatures The list of relevant components is augmented to include sync vs. async method types. Async methods have some additions to normal signature compatibility.