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

improve the inferrability of isequal(::Any, ::Any) #42195

Merged
merged 1 commit into from
Sep 11, 2021
Merged

Conversation

aviatesk
Copy link
Sponsor Member

@aviatesk aviatesk commented Sep 10, 2021

Currently, the return type of isequal(::Any, ::Any) is inferred as
Union{Bool,Missing} because it takes the possibilities of e.g.
==(::Any, ::Missing) -> Missing into account.
But actually isequal already handles every missing case by dispatch:

julia/base/missing.jl

Lines 80 to 82 in 2f00c5f

isequal(::Missing, ::Missing) = true
isequal(::Missing, ::Any) = false
isequal(::Any, ::Missing) = false

, and thus we can improve the inferrability by type annotation.

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

yes, this is the documented requirement

@@ -81,6 +81,14 @@ import Base.<
@test isequal(minmax(TO23094(2), TO23094(1))[1], TO23094(1))
@test isequal(minmax(TO23094(2), TO23094(1))[2], TO23094(2))

let
m = Module()
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

don't make anonymous modules unless you must. they unnecessarily complicate the tests

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

I prefer using it because it makes sure we can avoid name collision.
f42195(...) = ... as toplevel code would look better ?

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

seems like this test might fail is any new isequal method gets added

julia> methods(isequal, (Any,Int))
# 3 methods for generic function "isequal":
[1] isequal(x::AbstractFloat, y::Real) in Base at operators.jl:147
[2] isequal(::Missing, ::Any) in Base at missing.jl:81
[3] isequal(x, y) in Base at operators.jl:140

Currently, the return type of `isequal(::Any, ::Any)` is inferred as
`Union{Bool,Missing}` because it takes the possibilities of e.g.
`==(::Any, ::Missing)` into account.
But actually `isequal` already handles every `missing` case by dispatch:
<https://github.com/JuliaLang/julia/blob/2f00c5f6e2211ed1588976dbbe7b022148716d95/base/missing.jl#L80-L82>
, and thus we can improve the inferrability by type annotation.
@aviatesk aviatesk merged commit ffac475 into master Sep 11, 2021
@aviatesk aviatesk deleted the avi/isequalinf branch September 11, 2021 03:20
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
Currently, the return type of `isequal(::Any, ::Any)` is inferred as
`Union{Bool,Missing}` because it takes the possibilities of e.g.
`==(::Any, ::Missing)` into account.
But actually `isequal` already handles every `missing` case by dispatch:
<https://github.com/JuliaLang/julia/blob/2f00c5f6e2211ed1588976dbbe7b022148716d95/base/missing.jl#L80-L82>
, and we can improve the inferrability by type annotation.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Currently, the return type of `isequal(::Any, ::Any)` is inferred as
`Union{Bool,Missing}` because it takes the possibilities of e.g.
`==(::Any, ::Missing)` into account.
But actually `isequal` already handles every `missing` case by dispatch:
<https://github.com/JuliaLang/julia/blob/2f00c5f6e2211ed1588976dbbe7b022148716d95/base/missing.jl#L80-L82>
, and we can improve the inferrability by type annotation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants