Skip to content

Commit c3350a0

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 85687b5 commit c3350a0

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
@@ -629,7 +629,3 @@ hash(data::AbstractString, h::UInt) =
629629
hash_bytes(utf8units(data), UInt64(h), HASH_SECRET) % UInt
630630
@assume_effects :total hash(data::String, h::UInt) =
631631
GC.@preserve data hash_bytes(pointer(data), sizeof(data), UInt64(h), HASH_SECRET) % UInt
632-
633-
# no longer used in Base, but a lot of packages access these internals
634-
const memhash = UInt === UInt64 ? :memhash_seed : :memhash32_seed
635-
const memhash_seed = UInt === UInt64 ? 0x71e729fd56419c81 : 0x56419c81

0 commit comments

Comments
 (0)