-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
base: main
Are you sure you want to change the base?
Conversation
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.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ofTask
, since the user could write that themselves and the runtime will have to handle it.