Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RuntimeHelpers.Await rules #77957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

333fred
Copy link
Member

@333fred 333fred commented Apr 1, 2025

These rules now clarify the extensibility point we're looking to establish with the runtime for Await helpers. Generally speaking, these are just ordinary methods that a user is free to call, so there's no issue with us using them for subtypes of Task, since the user could write that themselves and the runtime will have to handle it.

These rules now clarify the extensibility point we're looking to establish with the runtime for `Await` helpers. Generally speaking, these are just ordinary methods that a user is free to call, so there's no issue with us using them for subtypes of `Task`, since the user could write that themselves and the runtime will have to handle it.
@333fred 333fred requested a review from a team as a code owner April 1, 2025 21:01
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 1, 2025
@333fred 333fred requested review from RikkiGibson, jcouv and agocke April 1, 2025 21:05
For any lvalue of one of these types, we'll generally rewrite `await expr` into `System.Runtime.CompilerServices.RuntimeHelpers.Await(expr)`. A number of different example scenarios for this are covered below. The
#### `RuntimeHelpers.Await` Scenarios

The for any `await expr` with type `E`, the compiler will attempt to match it to a helper method in `System.Runtime.CompilerServices.RuntimeHelpers`. The following algorithm is used:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for

Extraneous "the"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the sentence suggests that await expr has type E, but you mean that expr has type E.

2. If `Mi` takes more than 1 parameter (named `P`), it is removed.
3. If `Mi` has a generic arity of 0, all of the following must be true, or `Mi` is removed:
1. The return type is `System.Void`
2. There is an identity or implicit reference conversion from `E` to the type of `P`.
Copy link
Member

@jcouv jcouv Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or implicit reference conversion

Let's confirm whether this degree of freedom is needed. Also applies below.

@jcouv jcouv self-assigned this Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Runtime Async untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants