Skip to content

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Oct 16, 2025

Fixes: #119617

Since ValueTask is a struct, we need to see through stloc; ldloca; sequence when matching ConfigureAwait call

Copilot AI review requested due to automatic review settings October 16, 2025 16:19
@VSadov VSadov added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async labels Oct 16, 2025
@VSadov VSadov requested a review from jakobbotsch October 16, 2025 16:19
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a 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 impMatchTaskAwaitPattern from 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

Copy link
Member

@jakobbotsch jakobbotsch left a 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

@hez2010
Copy link
Contributor

hez2010 commented Oct 17, 2025

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?
For example,

var t = FooAsync();
Bar();
await t.ConfigureAwait(false);

@jakobbotsch
Copy link
Member

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? For example,

var t = FooAsync();
Bar();
await t.ConfigureAwait(false);

It would not help your case. There is no way to call the async version of FooAsync without waiting for its completion, which is not the semantics of this program that runs Bar after starting FooAsync.

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.

@VSadov
Copy link
Member Author

VSadov commented Oct 17, 2025

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.

@VSadov VSadov enabled auto-merge (squash) October 17, 2025 19:29
@VSadov VSadov merged commit 3db77c1 into dotnet:main Oct 17, 2025
111 checks passed
@VSadov VSadov deleted the vtConfig branch October 17, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RuntimeAsync] ConfigureAwait(bool) is not optimized for ValueTask-returning method.

3 participants