JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.78k stars 5.49k forks source link

incorrect hash for equal types, with Union instead of lower bound #53109

Open vtjnash opened 9 months ago

vtjnash commented 9 months ago

Looks like what happened in #52997 pkgeval is during serialization of Parquet2 there were 2 distinct MethodInstance objects

getindex(WeakRefStrings.StringArray{Union{Base.Missing, 𝒯}, 1} where 𝒯, Int64)
getindex(WeakRefStrings.StringArray{𝒯, 1} where Base.Missing<:𝒯<:Any, Int64)

But during deserialization of it, these got merged into a single object.

Resulting from this bug in hash:

julia> A = Tuple{Int, Val{Union{Base.Missing, 𝒯}} where 𝒯, Int}
Tuple{Int64, Val{Union{Missing, 𝒯}} where 𝒯, Int64}

julia> B = Tuple{Int, Val{𝒯}, Int} where Missing<:𝒯<:Any
Tuple{Int64, Val{𝒯}, Int64} where 𝒯>:Missing

julia> hash(A)
0x77cfa1eef01bca90

julia> hash(B)
0x3e21480671c6d257

julia> A == B
true
KristofferC commented 6 months ago

Jameson says that the assertion here might have to be uncommented since this case is not so bad and actually fixing this is very hard.

KristofferC commented 6 months ago

Removing milestone due to https://github.com/JuliaLang/julia/pull/54408