From 528709fd6b42c1d47205c0a72b327a1468c80d5d Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Fri, 15 Jan 2021 18:59:25 +0000 Subject: [PATCH] Use arch-independent magic number as start seed for Preferences hash `Preferences.jl` is currently broken on 32-bit because hashing natively uses `UInt32`'s instead of `UInt64`'s. We allow `Preferences.jl` to polymorph to whichever it requires here, while eliminating a confusing large constant and simply starting from zero. --- base/loading.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index cc0cd88a4b123..093e14e00e74e 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1645,9 +1645,10 @@ function get_preferences(uuid::UUID) end function get_preferences_hash(uuid::Union{UUID, Nothing}, prefs_list::Vector{String}) - # Start from the "null" hash - h = UInt64(0x6e65726566657250) - uuid === nothing && return h + # Start from a predictable hash point to ensure that the same preferences always + # hash to the same value, modulo changes in how Dictionaries are hashed. + h = UInt(0) + uuid === nothing && return UInt64(h) # Load the preferences prefs = get_preferences(uuid) @@ -1659,7 +1660,8 @@ function get_preferences_hash(uuid::Union{UUID, Nothing}, prefs_list::Vector{Str h = hash(prefs_name, h) end end - return h + # We always return a `UInt64` so that our serialization format is stable + return UInt64(h) end get_preferences_hash(m::Module, prefs_list::Vector{String}) = get_preferences_hash(PkgId(m).uuid, prefs_list)