Skip to content

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

Closed

Description

@jakobbotsch

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

Activity

  1. jakobbotsch commented on Nov 27, 2024

    @jakobbotsch
    MemberAuthor

    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?

  2. VSadov commented on Nov 27, 2024

    @VSadov
    Member

    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.

  3. VSadov commented on Nov 27, 2024

    @VSadov
    Member

    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).

  4. jakobbotsch commented on Dec 2, 2024

    @jakobbotsch
    MemberAuthor

    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).

  5. VSadov commented on May 3, 2025

    @VSadov
    Member

    this may no longer be relevant.

  6. transferred this issue fromdotnet/runtimelabon May 3, 2025
  7. ghost added
    area-CodeGen-coreclr
    on May 3, 2025
  8. added
    untriaged
    on May 3, 2025
  9. added and removed
    area-CodeGen-coreclr
    untriaged
    on May 3, 2025
  10. dotnet-policy-service commented on May 3, 2025

    @dotnet-policy-service
    Contributor

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

  11. added
    area-CodeGen-coreclr
    on May 5, 2025
  12. dotnet-policy-service commented on May 5, 2025

    @dotnet-policy-service
    Contributor

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

  13. jakobbotsch commented on May 14, 2025

    @jakobbotsch
    MemberAuthor
  14. locked and limited conversation to collaborators on Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrruntime-async

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions