Skip to content

Fix incorrect one-arg Base.hash method#15

Open
adienes wants to merge 1 commit intoasterycs:trunkfrom
adienes:fix-hash-one-arg
Open

Fix incorrect one-arg Base.hash method#15
adienes wants to merge 1 commit intoasterycs:trunkfrom
adienes:fix-hash-one-arg

Conversation

@adienes
Copy link

@adienes adienes commented Mar 19, 2026

Generated as part of an ecosystem-wide audit for one-arg hash methods.

Summary

The hash(arg::LowerOrUpperIndex) method in src/index.jl only defines a one-arg Base.hash. This means the two-arg fallback hash(x, h::UInt) uses objectid-based hashing instead, which can cause:

  • Correctness bugs: equal objects may hash differently when used in containers like Dict or Set
  • Performance issues: excessive method invalidation across the ecosystem
  • Julia 1.13+ breakage: the default hash seed is changing from zero(UInt) to a random value, so the one-arg method will produce different results each session

Fix

Convert to a proper two-arg hash(arg::LowerOrUpperIndex, h::UInt) that chains the seed through the computation.

Test plan

  • Verified the fix compiles and the hash contract is maintained

This PR was generated with the assistance of generative AI.

Co-Authored-By: Claude noreply@anthropic.com

Generated as part of an ecosystem-wide audit for one-arg hash methods.

The `hash(arg::LowerOrUpperIndex)` method only defined a one-arg
`Base.hash`, which means the two-arg fallback `hash(x, h::UInt)`
uses `objectid`-based hashing instead. This can cause correctness
issues (equal objects hashing differently) and performance problems
(excessive invalidation). With Julia 1.13+, the default hash seed
is changing from `zero(UInt)` to a random value, which will make
the one-arg method produce different results on each session.

Fix by converting to a proper two-arg method that chains the seed `h`
through the hash computation.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant