Skip to content

Commit 28d7653

Browse files
committed
remove Base.memhash global
This became unsound to use even though it was preserved "to avoid breakage" in v1.13, since continuing to use it would give incorrect hash results, which could result in corrupt dictionaries. Since #59691, these broken `hash` methods can now simply be deleted as they no longer provide any value. It is hard to say whether this is technically breaking or not as a change. It causes packages to go from giving subtly wrong answers (the worst kind of wrong) to crashing in v1.13, until the offending incorrect methods are deleted.
1 parent afb44f5 commit 28d7653

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Language changes
1717
* `mod(x::AbstractFloat, -Inf)` now returns `x` (as long as `x` is finite), this aligns with C standard and
1818
is considered a bug fix ([#47102])
1919

20-
- The `hash` algorithm and its values have changed. Most `hash` specializations will remain correct and require no action. Types that reimplement the core hashing logic independently, such as some third-party string packages do, may require a migration to the new algorithm. ([#57509])
20+
- The `hash` algorithm and its values have changed for certain types, most notably AbstractString. Any `hash` specializations for equal types to those that changed, such as some third-party string packages, may need to be deleted. ([#57509], [#59691])
21+
- The `hash(::AbstractString)` function is now a zero-copy / zero-cost function, based upon providing a correct implementation of the `codeunit` and `iterate` functions. Third-party string packages should migrate to the new algorithm by deleting their existing overrides of the `hash` function. ([#59691])
2122

2223
* Indexless `getindex` and `setindex!` (i.e. `A[]`) on `ReinterpretArray` now correctly throw a `BoundsError` when there is more than one element. ([#58814])
2324

base/hashing.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,3 @@ hash(data::AbstractString, h::UInt) =
643643
hash_bytes(utf8units(data), UInt64(h), HASH_SECRET) % UInt
644644
@assume_effects :total hash(data::String, h::UInt) =
645645
GC.@preserve data hash_bytes(pointer(data), sizeof(data), UInt64(h), HASH_SECRET) % UInt
646-
647-
# no longer used in Base, but a lot of packages access these internals
648-
const memhash = UInt === UInt64 ? :memhash_seed : :memhash32_seed
649-
const memhash_seed = UInt === UInt64 ? 0x71e729fd56419c81 : 0x56419c81

0 commit comments

Comments
 (0)