You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RuntimeAsync] Double check OSR in async2 struct instance methods #115259
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.
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).
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).
Activity
jakobbotsch commentedon 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 commentedon 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 commentedon Nov 27, 2024
Rewriting
thisaccesses 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
InvalidProgramExceptionor 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 commentedon Dec 2, 2024
I agree, but I think this is orthogonal to this particular question -- we need some policy regardless.
It does seem hard to come up with good IL validity rules without having something like
HoistedLocal(in my opinion we should call itHoistableLocalif we end up with it).VSadov commentedon May 3, 2025
this may no longer be relevant.
dotnet-policy-service commentedon May 3, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon May 5, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jakobbotsch commentedon May 14, 2025
Obsolete with dotnet/runtimelab#3088