Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[RuntimeAsync] Double check OSR in async2 struct instance methods #115259

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

Open
jakobbotsch opened this issue Nov 27, 2024 · 7 comments
Open

[RuntimeAsync] Double check OSR in async2 struct instance methods #115259

jakobbotsch opened this issue Nov 27, 2024 · 7 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async

Comments

@jakobbotsch
Copy link
Member

OSR might not be saving the struct instance copy made implicitly by the JIT. Double check and fix this if necessary.

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Nov 27, 2024

These sort of complications make me think that perhaps we should still leave it up to the IL code generators to create these copies themselves. I think we are going to run into similar problems around EnC and also diagnostics with the implicitly created locals that are hidden from the user.

Leaving it up to IL creators to create these copies would probably also simplify the spec; it is already saying that byrefs are not captured across suspension points, so the "this" argument in struct methods already fall under this rule, hence IL code generators are forced to create the copy if they need access to the instance after suspension points.

Thoughts @333fred @agocke @davidwrighton @VSadov?

@VSadov
Copy link
Member

VSadov commented Nov 27, 2024

We would still need some policy from the JIT on what happens when refs are alive across suspension points.

Ideally that should not end in behavior that is dependent on whether suspension happened or not or on whether JIT is optimizing.

@VSadov
Copy link
Member

VSadov commented Nov 27, 2024

Rewriting this accesses in async instance methods in structs to use a local copy captured at first entry into the method is a fairly straightforward rewrite that Roslyn can do.
We already decided that Roslyn will rewrite byrefs accesses into using ordinary locals for cases like arr[i] += await foo(). That would be more complex.

If there are no bugs, there should be no IL byrefs that try to be alive across awaits. I think we can guarantee this on Roslyn side.

I just wonder what will happen if there is a bug, in Roslyn, or in some IL rewriting/instrumentation tool. Will JIT just throw InvalidProgramException or leave the behavior dependent on whether suspension happens.
Like some code may never take suspension path and one day it takes that path and then crashes with NRE while accessing nulled out byref.

I think I might prefer not accepting IL that carries byrefs across awaits. It feels a bit more deterministic, even if it may depend on whether the code was actually JIT-ed and perhaps on quality of flow analysis (and thus on JIT version or optimization mode).

@jakobbotsch
Copy link
Member Author

We would still need some policy from the JIT on what happens when refs are alive across suspension points.

I agree, but I think this is orthogonal to this particular question -- we need some policy regardless.

I think I might prefer not accepting IL that carries byrefs across awaits. It feels a bit more deterministic, even if it may depend on whether the code was actually JIT-ed and perhaps on quality of flow analysis (and thus on JIT version or optimization mode).

It does seem hard to come up with good IL validity rules without having something like HoistedLocal (in my opinion we should call it HoistableLocal if we end up with it).

@VSadov
Copy link
Member

VSadov commented May 3, 2025

this may no longer be relevant.

@VSadov VSadov transferred this issue from dotnet/runtimelab May 3, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 3, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 3, 2025
@VSadov VSadov added runtime-async and removed area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels May 3, 2025
Copy link
Contributor

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

@jeffschwMSFT jeffschwMSFT added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 5, 2025
Copy link
Contributor

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

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

No branches or pull requests

3 participants