Skip to content
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

RuntimeHelpers.Equals difference between CoreCLR and Mono #13715

Open
filipnavara opened this issue Nov 3, 2019 · 4 comments
Open

RuntimeHelpers.Equals difference between CoreCLR and Mono #13715

filipnavara opened this issue Nov 3, 2019 · 4 comments
Labels
area-System.Runtime bug runtime-mono specific to the Mono runtime
Milestone

Comments

@filipnavara
Copy link
Member

The following program:

using System;
using System.Text;
using System.Runtime.CompilerServices;

public class C {
    struct S {
        public int a;
        public string b;
    };
    
    public static void Main() {
        var b1 = 42.ToString();
        var b2 = 42.ToString();
        var s1 = new S { a = 42, b = b1 };
        var s2 = new S { a = 42, b = b2 };
        Console.WriteLine(object.ReferenceEquals(b1, b2));
        Console.WriteLine(s1.Equals(s2));
        Console.WriteLine(RuntimeHelpers.Equals(s1, s2));
    }
}

prints

False
True
False

on CoreCLR.

On Mono it prints

False
True
True

The difference is in how ValueTypes are treated by RuntimeHelpers.Equals. CoreCLR does memcmp of the contents, Mono does field-by-field comparison. Which one is right and which one is wrong?

@filipnavara
Copy link
Member Author

I think https://github.com/dotnet/corefx/issues/13692#issuecomment-263101741 partially answers that. Follow up question though, is there any incentive to get this fixed and align the behavior? Is it emitted by the compiler in some cases?

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@joperezr joperezr added runtime-mono specific to the Mono runtime bug and removed untriaged New issue has not been triaged by the area owner labels Jul 7, 2020
@joperezr joperezr added this to the 5.0.0 milestone Jul 7, 2020
@joperezr
Copy link
Member

joperezr commented Jul 7, 2020

cc: @jkotas do you mind answering the above question? Also, do we want to either fix this or document it for 5.0?

@jkotas
Copy link
Member

jkotas commented Jul 8, 2020

Is it emitted by the compiler in some cases?

I am not aware of any compilers that emit calls to this API.

https://apisof.net/catalog/System.Runtime.CompilerServices.RuntimeHelpers.Equals(Object,Object) says that the usage is 0.7%. It is a lot for a broken slow API. It may be a good idea to understand where this API is actually used before deciding what to do here.

is there any incentive to get this fixed and align the behavior?

Aligning the behavior between CoreCLR and Mono sounds good to me.

Also, the documentation for the API is wrong. It says "true if the o1 parameter is the same instance as the o2 parameter, or if both are null, or if o1.Equals(o2) returns true; otherwise, false.". This description does not match neither CoreCLR nor Mono implementations.

@danmoseley danmoseley modified the milestones: 5.0.0, Future Aug 12, 2020
@danmoseley
Copy link
Member

Not required to fix this to ship the product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime bug runtime-mono specific to the Mono runtime
Projects
None yet
Development

No branches or pull requests

5 participants