Skip to content

Commit 18b5ff6

Browse files
authored
remove Base.memhash global (#59697)
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 and unsound programs. Since #59691, these broken `hash` methods in the ecosystem 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. n.b. this is expected to break several packages (notably among them, JuliaInterpreter, which has several tests specifically just for the existence of this global), which will require some ecosystem updates. The update should just be to delete the offending method (they is now redundant, undesirable, and have been giving unsafely buggy answers), but we need to do some work to identify those places and release new versions.
1 parent de98c0c commit 18b5ff6

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ 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+
22+
* 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])
2123

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

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)