From d0431451a2ec52cf4ab9e913797db5f5ee21c47e Mon Sep 17 00:00:00 2001 From: Andy Dienes Date: Thu, 19 Mar 2026 16:22:58 -0400 Subject: [PATCH] Fix Base.hash to use only the two-arg method Generated as part of an ecosystem-wide audit for one-arg hash methods. `Base.hash` should only be extended via the two-arg method `hash(x, h::UInt)`. Defining a one-arg `hash(x)` method, or giving the second argument a default value, can lead to correctness bugs (hash contract violations when the seed differs from the hard-coded default) and invalidation-related performance issues. This is particularly necessary for Julia 1.13+ where the default hash seed value will change. Co-Authored-By: Claude Opus 4.6 --- src/notebook.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/notebook.jl b/src/notebook.jl index c9c1036..23b7539 100644 --- a/src/notebook.jl +++ b/src/notebook.jl @@ -311,12 +311,12 @@ begin a.rejected_val[] == b.rejected_val[] end - Base.hash(p::Promise) = hash(( + Base.hash(p::Promise, h::UInt) = hash(( typeof(p), isready(p), p.resolved_val[], p.rejected_val[], - )) + ), h) Base.promote_rule(::Type{Promise{T}}, ::Type{Promise{S}}) where {T,S} = Promise{promote_type(T,S)} function Base.convert(PT::Type{Promise{T}}, p::Promise{S}) where {T,S} @@ -775,7 +775,7 @@ begin @eval Base.only(a::$RT) = a.value @eval Base.:(==)(a::$RT, b::$RT) = a.value == b.value - @eval Base.hash(a::$RT) = hash(a.value, hash($RT)) + @eval Base.hash(a::$RT, h::UInt) = hash(a.value, hash($RT, h)) @eval Base.promote_rule( t1::Type{$RT{T}},