Skip to content

Comparers don't work for messy generic corner cases #89767

Closed

Description

@MichalStrehovsky

Compile the repro below with/without optimizations.

Without optimizations, this prints:

Here
False
True

That's good.

With optimizations, this prints:

Here
False
Here
False

That's not so good.

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
{
    MyStruct<object, object> s1 = default;
    MyStruct<object, object> s2 = default;
    Console.WriteLine(Equals(s1, s2));
}

{
    MyStruct<object, string> s1 = default;
    MyStruct<object, string> s2 = default;
    Console.WriteLine(Equals(s1, s2));
}

[MethodImpl(MethodImplOptions.NoInlining)]
static bool Equals<T>(T x, T y)
{
    return EqualityComparer<T>.Default.Equals(x, y);
}

struct MyStruct<T, U> : IEquatable<MyStruct<U, U>>
{
    public bool Equals(MyStruct<U, U> other)
    {
        Console.WriteLine("Here");
        return false;
    }
}

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Aug 1, 2023
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Aug 1, 2023
  3. MichalStrehovsky commented on Aug 1, 2023

    @MichalStrehovsky
    MemberAuthor

    (To be clear, this issue is not for Native AOT, it's broken for JIT scenarios. It's also broken on Native AOT but I'm going to wait until there's a defined behavior for this, defined by the JIT side.)

  4. jakobbotsch commented on Aug 1, 2023

    @jakobbotsch
    Member

    What is the non-NAOT repro case? This one doesn't seem to repro without NativeAOT for me.

  5. jakobbotsch commented on Aug 1, 2023

    @jakobbotsch
    Member

    (Seems like it was failing just recently until #88006. Also #88006 (comment) looks related.)

  6. JulieLeeMSFT commented on Aug 1, 2023

    @JulieLeeMSFT
    Member

    @EgorBo PTAL. CC @jkotas.

  7. removed
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Aug 1, 2023
  8. jkotas commented on Aug 1, 2023

    @jkotas
    Member

    This is a bug in native AOT implementation of JIT/EE interface. I will take a look.

  9. added a commit that references this issue on Aug 2, 2023
    337354f
  10. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 2, 2023
  11. MichalStrehovsky commented on Aug 2, 2023

    @MichalStrehovsky
    MemberAuthor

    I would have sworn I tested it with the latest installer build but probably fell into the trap of having something else on PATH. Sorry for the noise.

  12. added a commit that references this issue on Aug 2, 2023
    41b8bc4
  13. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 2, 2023
  14. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 2, 2023
  15. ghost locked as resolved and limited conversation to collaborators on Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions