-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Make Refs compare equal when their contents are equal #31885
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
Conversation
Currently `Ref(a) == Ref(b)` is always `false`, even when `a == b`. This changes the behavior such that `Ref(a) == Ref(b)` if `a == b`, and likewise for `isequal` and `isapprox`. Fixes #31813.
|
Why is this a minor change if this is a user visible behavior change that wasn't an error before? |
|
Seems unlikely to me that anyone has been relying on |
|
Compare, maybe not, but not that unlikely for |
That's a good point, I hadn't thought of that.
Good call, I can do that. |
|
(And other than the technical aspect of the behavioral change being breaking (and the easily fixable missing |
|
What's the most sensible way to implement hashing for const hash_ref_seed = UInt === UInt64 ? 0x039511594a926cf3 : 0x56cdecdd
hash(r::RefValue, h::UInt) = hash(hash_ref_seed ⊻ hash(r.x), h)locally but I want to make sure that's sensible before pushing. |
|
I agree with yuyichao: FWIW, I prefer the current behavior. Mutation semantics (out-parameters, shared state, etc) is the entire point of ever using a |
|
That's a very fair assessment. I'm fine closing this if the consensus is to keep things how they are. |
Based on the current equality behavior, it should be identity hashing. |
|
FWIW, we could speed up by In general, the generic fallback If we wanted more speed, we could use For bitstype (very important special case!), we should hash the object as a binary blob, after zeroing structure padding. This should be faster because the speed of hashing would scale in Imo the easiest way of getting there would be to change what we emit for |
|
|
Ok, I'm intrigued: What are situations where this could be violated? I get that For example: Suppose Afaiu |
If the two are in the same |
I don't think the compiler is currently doing this (though with combination of store to load forwarding to remove dead uses it COULD, just not from a single pass) but this is certainly allowed. |
|
Also, AFAICT, #31885 (comment) and your reply to it is OT for this PR. |
|
From triage: we noted that |
Currently
Ref(a) == Ref(b)is alwaysfalse, even whena == b. This changes the behavior such thatRef(a) == Ref(b)ifa == b, and likewise forisequalandisapprox.Fixes #31813.