Skip to content

Commit 86a3e1a

Browse files
authored
check that hashing of types does not foreigncall (jl_type_hash is concrete evaluated) (#58401)
1 parent ee47bd4 commit 86a3e1a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

base/hashing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ hash(data::Any) = hash(data, HASH_SEED)
3434
hash(w::WeakRef, h::UInt) = hash(w.value, h)
3535

3636
# Types can't be deleted, so marking as total allows the compiler to look up the hash
37-
hash(T::Type, h::UInt) =
38-
hash((@assume_effects :total ccall(:jl_type_hash, UInt, (Any,), T)), h)
37+
@noinline _jl_type_hash(T::Type) = @assume_effects :total ccall(:jl_type_hash, UInt, (Any,), T)
38+
hash(T::Type, h::UInt) = hash(_jl_type_hash(T), h)
3939
hash(@nospecialize(data), h::UInt) = hash(objectid(data), h)
4040

4141
function mul_parts(a::UInt64, b::UInt64)

test/hashing.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,10 @@ struct AUnionParam{T<:Union{Nothing,Float32,Float64}} end
308308
@test hash(5//3) == hash(big(5)//3)
309309
end
310310

311-
@test Core.Compiler.is_foldable_nothrow(Base.infer_effects(hash, Tuple{Type{Int}, UInt}))
311+
@testset "concrete eval type hash" begin
312+
@test Core.Compiler.is_foldable_nothrow(Base.infer_effects(hash, Tuple{Type{Int}, UInt}))
313+
314+
f(h...) = hash(Char, h...);
315+
src = only(code_typed(f, Tuple{UInt}))[1]
316+
@test count(stmt -> Meta.isexpr(stmt, :foreigncall), src.code) == 0
317+
end

0 commit comments

Comments
 (0)