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

Add indirection in == fallback #44678

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ include("range.jl")
include("error.jl")

# core numeric operations & types
==(x, y) = x === y
unwrap_isequal(x) = x
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, if we go with this, it should be used much more broadly:

Suggested change
unwrap_isequal(x) = x
unwrap_for_compare(x) = x

Then we need to go update ==, <, isless, isequal, hash etc.

But perhaps instead I should open an issue about eliminating WeakRef (in favor, similar to the atomic attribute, of being a runtime-settable attribute in Array flags or in the field properties of a struct). Unfortunately, we cannot delete WeakRef until v2 regardless, since we can give a replacement for it, but we cannot remove it, until then.

function ==(x, y)
ux = unwrap_isequal(x)
uy = unwrap_isequal(y)
ux === x && uy === y && return x === y
return ux == uy
end
include("bool.jl")
include("number.jl")
include("int.jl")
Expand Down
4 changes: 1 addition & 3 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

==(w::WeakRef, v::WeakRef) = isequal(w.value, v.value)
==(w::WeakRef, v) = isequal(w.value, v)
==(w, v::WeakRef) = isequal(w, v.value)
unwrap_isequal(w::WeakRef) = w.value

"""
finalizer(f, x)
Expand Down