-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[RuntimeAsync] Fix Await pattern detection for ValueTask in ConfigureAwait cases. #120810
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
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
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.
Pull Request Overview
This PR fixes await pattern detection for ValueTask in ConfigureAwait cases by recognizing the stloc; ldloca; instruction sequence that occurs when ConfigureAwait is called on ValueTask (a struct type). The fix enables proper optimization of ValueTask await patterns in runtime async methods.
Key Changes:
- Enhanced IL pattern matching to detect
stloc; ldloca;sequences before ConfigureAwait calls - Changed return type of
impMatchTaskAwaitPatternfrom bool to pointer for better control flow - Enabled runtime async tests by default
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/importer.cpp | Added logic to detect and validate stloc/ldloca sequences in ValueTask ConfigureAwait patterns |
| src/coreclr/jit/compiler.h | Changed impMatchTaskAwaitPattern signature to return position pointer instead of bool |
| src/coreclr/inc/clrconfigvalues.h | Enabled RuntimeAsync feature by default (changed from 0 to 1) |
| src/tests/async/Directory.Build.targets | Removed property group that disabled async tests |
| src/tests/async/Directory.Build.props | Added SYSLIB5007 to NoWarn list |
| src/tests/async/struct/struct.cs | Added opt-out attributes for async methods in structs pending Roslyn support |
jakobbotsch
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.
LGTM except the nits about nullptr vs NULL
|
Wondering whether such optimization can be done in VN as well instead of the importer only so that it can capture more patterns that are not awaiting the Task/ValueTask{.ConfigureAwait()} directly? var t = FooAsync();
Bar();
await t.ConfigureAwait(false); |
It would not help your case. There is no way to call the async version of We may still do an optimization like this in the future of we find that some cases we aren't getting (perhaps after inlining). But it is not so simple because currently finding the async variant of a method requires token information, and we do not keep token information around. We will either need to do that or only do the optimization for statically resolvable calls. |
|
GCC complained that CEE_STLOC and CEE_LDLOCA are out of range of the switch value (uint8_t). I think GCC is right about this. These are wide opcodes. |
Fixes: #119617
Since ValueTask is a struct, we need to see through
stloc; ldloca;sequence when matchingConfigureAwaitcall