Repository navigation
JIT: Avoid keeping BYREFs live across async calls when boxing - #121621
Merged
Merged
Conversation
When boxing or storing values that may contain async calls in async methods, the JIT was creating IR where BYREF addresses (computed as base + offset) were evaluated before the async call and kept live across await points. This violated the async transformation's invariant that BYREFs cannot be live across await points, causing an assert: !dsc->TypeIs(TYP_BYREF) in async.cpp:1085. The fix introduces gtContainsAsyncCall(), a helper that efficiently checks if a tree contains an async call by using a GenTreeVisitor that leverages GTF_CALL to skip subtrees without calls. The helper includes the compIsAsync() check internally. Updated impImportAndPushBox() and STSFLD handling to use this helper to spill values containing async calls before computing BYREF destinations, ensuring BYREFs are never kept live across await points.
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This was referenced Nov 14, 2025
Open
jakobbotsch
marked this pull request as ready for review
November 14, 2025 16:35
jakobbotsch
commented
Nov 14, 2025
Member
Author
|
cc @dotnet/jit-contrib PTAL @EgorBo |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where the JIT was keeping BYREF addresses live across async call await points, violating an async transformation invariant. The fix introduces spilling logic to ensure values containing async calls are materialized before computing BYREF destinations.
Key Changes:
- Introduced
gtContainsAsyncCall()helper to detect async calls in expression trees - Updated
impImportAndPushBox()to spill values with async calls before boxing - Improved STSFLD handling to spill only when the stored value contains an async call (more precise than before)
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/coreclr/jit/gentree.cpp | Adds new gtContainsAsyncCall() helper function using GenTreeVisitor |
| src/coreclr/jit/compiler.h | Declares the new gtContainsAsyncCall() function |
| src/coreclr/jit/importer.cpp | Uses new helper in boxing and STSFLD to spill values with async calls before computing BYREF destinations |
| src/coreclr/jit/importercalls.cpp | Updates debug string for temp variable (minor cleanup) |
3 tasks
EgorBo
reviewed
Nov 14, 2025
EgorBo
approved these changes
Nov 14, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
When boxing or storing values that may contain async calls in async methods, the
JIT was creating IR where BYREF addresses (computed as base + offset) were
evaluated before the async call and kept live across await points. This violated
the async transformation's invariant that BYREFs cannot be live across await
points, causing an assert.
Updated impImportAndPushBox() and STSFLD handling to use the
gtTreeContainsAsyncCallhelper to spill values containing async calls beforecomputing BYREF destinations, ensuring BYREFs are never kept live across await
points.