Skip to content

JIT: Disallow forward substitution of async calls #115936

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

Merged
merged 7 commits into from
May 25, 2025

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented May 23, 2025

This can be forwarded into an overlapping byref temp, which is invalid IR.

We could look for that condition specifically, but that's more complex. Do the simple thing for now and skip forward substituting trees containing async calls with a new method gtTreeHasAsyncCall. In the future when we have async contexts in SPMI collections we can try the more precise check and see if it makes a difference.

The opposite might also be possible: forward substituting a TYP_BYREF into a tree with an async call. However, I am not 100% sure that can create overlapping lifetimes, so let's wait and see if Fuzzlyn comes up with an example.

Fix #115894

This can be forwarded into an overlapping byref temp, which is invalid
IR.

We could look for that condition specifically, but that's more complex.
Do the simple thing for now and skip forward substituting trees
containing async calls with a new method `gtTreeHasAsyncCall`. In the
future when we have async contexts in SPMI collections we can try the
more precise check and see if it makes a difference.

Also introduce `impSpillAsyncCalls` using `gtTreeHasAsyncCall`, and
resolve a TODO-Async using it.

The opposite might also be possible: forward substituting a TYP_BYREF
into a tree with an async call. However, I am not 100% sure that can
create overlapping lifetimes, so let's wait and see if Fuzzlyn comes up
with an example.
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 23, 2025
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 23, 2025 19:00
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

This passed CI previously but with some minor TP costs that I pushed a fix to mitigate.

@jakobbotsch jakobbotsch requested a review from AndyAyersMS May 23, 2025 19:00
@jakobbotsch
Copy link
Member Author

I realized that we also need to check for GT_RET_EXPR for the importer case, so added that check.

@jakobbotsch
Copy link
Member Author

That RET_EXPR check is not enough. We also need to check whether the inline candidate's arguments may contain async calls in them.

Add a new helper `gtFindNodeInTree` to avoid multiple visitors.
@jakobbotsch
Copy link
Member Author

Even that isn't enough, the call that the RET_EXPR points to can itself have RET_EXPR subtrees that recursively need to be processed. I'm going to revert the importer changes and just fix the forward sub one, and look at addressing the spilling inefficiency separately.

@jakobbotsch
Copy link
Member Author

/ba-g Android tests not picked up by Helix

@jakobbotsch jakobbotsch merged commit 8115429 into dotnet:main May 25, 2025
107 of 109 checks passed
@jakobbotsch jakobbotsch deleted the fix-115894 branch May 25, 2025 13:31
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT: Assertion failed 'dsc->TypeGet() != TYP_BYREF' during 'Transform async'
2 participants