-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Labels
Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.This issue involves adding, removing, clarification, or modification of an API.Feature - Runtime AsyncFeature Requestapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedblockingAPI needs to reviewed with priority to unblock workAPI needs to reviewed with priority to unblock work
Milestone
Description
Background and Motivation
Runtime async introduces a new lowering for async methods, which can have one of two patterns:
await exprhas a directly supported type, and we just emit:
System.Runtime.CompilerServices.AsyncHelpers.Await(expr);await exprhas a not supported type, and we emit:
var awaiter = expr.GetAwaiterMethod();
if (!awaiter.IsCompletedProperty)
{
System.Runtime.CompilerServices.AwaitAwaiter(awaiter);
// or
System.Runtime.CompilerServices.UnsafeAwaitAwaiter(awaiter);
}
awaiter.GetResultMethod()Consumers of AwaitExpressionInfo, such as the preview features analyzer, will need to be able to see this new method symbol and take action on it.
Proposed API
namespace Microsoft.CodeAnalysis.CSharp;
public readonly struct AwaitExpressionInfo
{
public IMethodSymbol? GetAwaiterMethod { get; }
public IPropertySymbol? IsCompletedProperty { get; }
public IMethodSymbol? GetResultMethod { get; }
public bool IsDynamic { get; }
+ /// <summary>
+ /// When runtime async is enabled for this await expression, this represents either:
+ /// <list type="bullet">
+ /// <item>
+ /// A call to <c>System.Runtime.CompilerServices.AsyncHelpers.Await</c>, if this is a
+ /// supported task type. In such cases, <see cref="GetAwaiterMethod" />,
+ /// <see cref="IsCompletedProperty" />, and <see cref="GetResultMethod" /> will be
+ /// <see langword="null" />.
+ /// </item>
+ /// <item>
+ /// A call to <c>System.Runtime.CompilerServices.AsyncHelpers.AwaitAwaiter|UnsafeAwaitAwaiter</c>.
+ /// In these cases, the other properties may be non-<see langword="null" /> if the
+ /// the rest of the await expression is successfully bound.
+ /// </item>
+ /// </list>
+ /// </summary>
+ public IMethodSymbol? RuntimeAwaitMethod { get; }
}Usage Examples
var awaitInfo = semanticModel.GetAwaitExpressionInfo(expr);
if (awaitInfo.RuntimeAwaitMethod is IMethodSymbol)
{
// Ensure that `EnablePreviewFeatures` is on.
}Alternative Designs
Risks
bernd5
Metadata
Metadata
Assignees
Labels
Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.This issue involves adding, removing, clarification, or modification of an API.Feature - Runtime AsyncFeature Requestapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedblockingAPI needs to reviewed with priority to unblock workAPI needs to reviewed with priority to unblock work