Save async contexts for ValueTask methods#129890
Open
jakobbotsch wants to merge 1 commit into
Open
Conversation
We were not properly saving/restoring async contexts for ValueTask methods because of an incorrect flag check.
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Runtime Async’s ExecutionContext save/restore behavior for ValueTask-returning async variants by correcting an overly strict async-flag check in the VM. It also adds/updates tests to cover the regression and re-enables a previously skipped System.Net.Http diagnostics test.
Changes:
- Fix VM async-flag logic to treat ValueTask async variants as requiring async-context save/restore.
- Add an ExecutionContext regression test covering
async ValueTaskflows and re-enable the affected diagnostics functional test. - Add DEBUG-only JIT knobs to selectively enable/break on await-optimization by hash range.
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/tests/async/execution-context/execution-context.cs | Adds a new ValueTask-focused ExecutionContext regression test. |
| src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs | Removes ActiveIssue to re-enable the diagnostics test previously associated with the bug. |
| src/coreclr/vm/method.hpp | Fixes async-flag check for ValueTask variants; adds operator~ helper for flag masking. |
| src/coreclr/jit/jitconfigvalues.h | Introduces DEBUG-only config entries for await optimization range/break. |
| src/coreclr/jit/importer.cpp | Adds an await-level “optimize or not” check (DEBUG-configurable) when selecting async variants. |
| src/coreclr/jit/compiler.h | Declares the new importer helper (impCheckOptimizeAwait). |
jakobbotsch
commented
Jun 26, 2026
| AsyncMethodFlags asyncFlags = GetAddrOfAsyncMethodData()->flags; | ||
| // asynccall that is also async variant, but not a thunk | ||
| return asyncFlags == (AsyncMethodFlags::AsyncCall | AsyncMethodFlags::IsAsyncVariant); | ||
| return (asyncFlags & ~AsyncMethodFlags::IsAsyncVariantForValueTask) == (AsyncMethodFlags::AsyncCall | AsyncMethodFlags::IsAsyncVariant); |
Member
Author
|
PTAL @VSadov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We were not properly saving/restoring async contexts for ValueTask methods because of an incorrect flag check.
Fix #129771
Also add a mechanism to allow a bisection-like search of optimized awaits in the JIT.
This is a surprising bug/test hole. It is also surprising that it was exposed by #128384, but the test seems to be timing sensitive -- it also stops reproducing if I introduce an
await Task.Yield()inWaitForConnectionWithTelemetryAsync.