diff --git a/base/hashing.jl b/base/hashing.jl index 5dbae09123bd6..7de9f47de3182 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -29,7 +29,9 @@ See also: [`objectid`](@ref), [`Dict`](@ref), [`Set`](@ref). """ hash(x::Any) = hash(x, zero(UInt)) hash(w::WeakRef, h::UInt) = hash(w.value, h) -hash(T::Type, h::UInt) = hash_uint(3h - ccall(:jl_type_hash, UInt, (Any,), T)) + +# Types can't be deleted, so marking as total allows the compiler to look up the hash +hash(T::Type, h::UInt) = hash_uint(3h - @assume_effects :total ccall(:jl_type_hash, UInt, (Any,), T)) ## hashing general objects ## diff --git a/test/hashing.jl b/test/hashing.jl index 7c3024640aa32..173a31d10a6a9 100644 --- a/test/hashing.jl +++ b/test/hashing.jl @@ -302,3 +302,5 @@ struct AUnionParam{T<:Union{Nothing,Float32,Float64}} end # test hashing of rational with odd denominator @test hash(5//3) == hash(big(5)//3) end + +@test Core.Compiler.is_foldable_nothrow(Base.infer_effects(hash, Tuple{Type{Int}, UInt}))