In the .NET Standard review of Span<T> @marek-safar wrote:
Why it does not implement
IEquatable<T>?
...
Well, if it's hard why do you havepublic bool Equals(System.Memory<T> other)? I think it'd make sense to have the interface here if the implementation is there too.
It seems odd to providing a strongly typed Equals method but not implementing IEquatable<T>.
@KrzysztofCwalina @stephentoub @GrabYourPitchforks @jkotas
I think we should implement it. Thanking said that it will have unexpected semantics, i.e. quasi referential equality. It will be especially surprising if ReadOnlyMemory
The Memory<T> in corefxlab implemented it originally, but we have later removed it in: https://github.com/dotnet/corefxlab/pull/1607/files. Why did we remove it?
@ahsonkhan for the question above.
Why did we remove it?
As @KrzysztofCwalina mentioned, it was because Equals does referential equality rather than deep value equality which might be unexpected for users. Regardless, we essentially implement the interface already (with the equals API), so I don't see any reason we shouldn't explicitly add the IEquatable back to the type.
Looking back at previous design discussions at the time when we removed it (i.e. https://github.com/dotnet/corefxlab/pull/1607), the meeting notes state: "We can remove the interface but keep the Equals methods", so that doesn't shed much light :p
@ahsonkhan @KrzysztofCwalina I still think we should add the interface. While I generally agree with the deep-vs-shallow equality problem, I think the current state is incosistent. Providing a strongly typed Equals but not implementing IEquatable feels inconsistent.
Unless someone pushes back, we should keep it approved an assign a dev to it :-)
Is it up to grab? If so, could i try make PR for this issue?
Is it up to grab? If so, could i try make PR for this issue?
That sounds great. Feel free to ping me on the PR for review. Thanks for the contribution.
@ahsonkhan should I add IEquatable
should I add IEquatable to ReadOnlyMemory or is thing for another issue?
Yes, you should. We don't have a separate issue for that since the interface applies naturally to the ReadOnly version as well.
@ahsonkhan
Is the plan to wait for a community member to do the work? It would be nice if we could complete this for 3.0 so that we can also expose it from .NET Standard 2.1.
Has this not been done yet? I can try to make the changes real quick.
Yes, please, that would be awesome!
The previous PR was abandoned: https://github.com/dotnet/corefx/pull/35501
Ping me if you need any help (see https://github.com/dotnet/corefx/pull/35501#discussion_r259200377)
Is that the only change required in coreclr? Shall I just open a PR (in coreclr) mentioning this issue with the changes?
Is that the only change required in coreclr? Shall I just open a PR (in coreclr) mentioning this issue with the changes?
Yep. The three changes you mentioned above is what is required. So the ref and test changes will be in corefx.
Can this be closed now? I forgot to put Fixes: dotnet/corefx#32905 in the PR 鈽猴笍 .
Thanks :)
Thanks :)
@terrajobst, is there a standard follow-up to be done here?
Yep. I'll submit the PR.
Most helpful comment
@ahsonkhan @KrzysztofCwalina I still think we should add the interface. While I generally agree with the deep-vs-shallow equality problem, I think the current state is incosistent. Providing a strongly typed
Equalsbut not implementingIEquatablefeels inconsistent.Unless someone pushes back, we should keep it approved an assign a dev to it :-)