-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Emit async-iterators with runtime-async when possible #81314
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
base: features/runtime-async-streams
Are you sure you want to change the base?
Emit async-iterators with runtime-async when possible #81314
Conversation
2765f0d to
8542bed
Compare
8542bed to
cfbdbfb
Compare
| The `GetAsyncEnumerator` method either returns the current instance if it can be reused, | ||
| or creates a new instance of the state machine class. | ||
|
|
||
| Assuming that the unspeakble state machine class is named `Unspeakable`, `GetAsyncEnumerator` is emitted as: |
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:
| Assuming that the unspeakble state machine class is named `Unspeakable`, `GetAsyncEnumerator` is emitted as: | |
| Assuming that the unspeakable state machine class is named `Unspeakable`, `GetAsyncEnumerator` is emitted as: | |
| ``` #Resolved |
|
|
||
| #### Lowering of `yield return` | ||
|
|
||
| `yield return` is disallowed in finally, in try with catch and in catch. |
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.
Unrelated to this PR, we were going to look at removing some of these restrictions, in particular for yields inside of a try with a catch, right? #Resolved
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.
Yes, there's a proposal for that, tracked independently: dotnet/csharplang#8414
It's not clear whether this would make it into C# 15 yet
|
|
||
| ## Open issues | ||
|
|
||
| Question: AsyncIteratorStateMachineAttribute, or IteratorStateMachineAttribute, or other attribute on kickoff method? |
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.
Why would this need to differ from what we do today? #Resolved
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.
I'm not sure yet. We introduced a different attribute for each state machine design so far.
Edit&Continue looks at this attribute and also relies on Symreader which also looks at the attribute. Symreader uses it to find the MoveNext method, but here the naming convention is different (it's "MoveNextAsync").
I didn't investigate the debug symbols or EnC yet. Need to talk to Tomas ;-)
src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncIteratorRewriter.cs
Show resolved
Hide resolved
333fred
left a comment
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.
Done review pass (commit 1). Tests are not looked at yet.
src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/RuntimeAsyncRewriter.cs
Show resolved
Hide resolved
.../Lowering/RuntimeAsyncIteratorRewriter/RuntimeAsyncIteratorRewriter.MoveNextAsyncRewriter.cs
Outdated
Show resolved
Hide resolved
.../Lowering/RuntimeAsyncIteratorRewriter/RuntimeAsyncIteratorRewriter.MoveNextAsyncRewriter.cs
Outdated
Show resolved
Hide resolved
.../Lowering/RuntimeAsyncIteratorRewriter/RuntimeAsyncIteratorRewriter.MoveNextAsyncRewriter.cs
Outdated
Show resolved
Hide resolved
...pilers/CSharp/Portable/Lowering/RuntimeAsyncIteratorRewriter/RuntimeAsyncIteratorRewriter.cs
Show resolved
Hide resolved
...pilers/CSharp/Portable/Lowering/RuntimeAsyncIteratorRewriter/RuntimeAsyncIteratorRewriter.cs
Show resolved
Hide resolved
...rs/CSharp/Portable/Lowering/RuntimeAsyncIteratorRewriter/RuntimeAsyncIteratorStateMachine.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/SynthesizedStateMachineMethod.cs
Show resolved
Hide resolved
|
|
||
| Async methods that return `IAsyncEnumerable<T>` or `IAsyncEnumerator<T>` are transformed by the compiler into state machines. | ||
| States are created for each `await` and `yield`. | ||
| Runtime-async support was added in .NET 10 as a preview feature and reduces the overhead of async methods by letting the runtime handling `await` suspensions. |
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.
| Runtime-async support was added in .NET 10 as a preview feature and reduces the overhead of async methods by letting the runtime handling `await` suspensions. | |
| Runtime-async support was added in .NET 10 as a preview feature and reduces the overhead of async methods by letting the runtime handle `await` suspensions. | |
| ``` #Resolved |
333fred
left a comment
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.
Mostly LGTM. Just a couple of small comments.
Relates to test plan #75960