Fix incorrect one-arg Base.hash for Block in NDTensors#1716
Merged
Conversation
70b5b28 to
8f77816
Compare
79578aa to
8d3086a
Compare
1 task
8d3086a to
c33645e
Compare
2 tasks
1 task
1 task
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1716 +/- ##
==========================================
- Coverage 81.09% 79.38% -1.71%
==========================================
Files 59 53 -6
Lines 4676 4556 -120
==========================================
- Hits 3792 3617 -175
- Misses 884 939 +55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merged
1 task
This was referenced Mar 23, 2026
Generated as part of an ecosystem-wide audit for one-arg hash methods. The `hash(b::Block)` method only defines a one-arg `Base.hash` (via `import Base: hash` in imports.jl), 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 each session. The existing two-arg method also used addition (`h + hash(b)`) instead of proper hash chaining. Fix by replacing both with a single proper two-arg method: `hash(b::Block, h::UInt) = hash(b.hash, h)`. Co-Authored-By: Claude <noreply@anthropic.com>
c33645e to
fac0cda
Compare
Merged
1 task
Member
|
Thanks @adienes! Sorry for all the PR noise, we are reworking some of our CI workflows and this PR exposed an issue when running downstream tests of private repositories from fork PRs, looks like that is fixed now and tests are passing so I'll merge this. |
Contributor
Author
|
glad it ended up helpful! no worries about the noise. I had ~30 of these PRs open 😂 so inbox was already cooked |
ipasichnyk
pushed a commit
to ipasichnyk/ITensors.jl
that referenced
this pull request
May 25, 2026
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generated as part of an ecosystem-wide audit for one-arg hash methods.
Summary
hash(b::Block)inNDTensors/src/blocksparse/block.jldefines a one-argBase.hash(viaimport Base: hashinimports.jl). This means the two-arg fallbackhash(x, h::UInt)usesobjectid-based hashing, which can cause:Blocks may hash differently when used as compound keys inDictorSetzero(UInt)to a random valueThe existing two-arg method also used addition (
h + hash(b)) instead of proper hash chaining.Fix
Replace both methods with a single proper two-arg
hash(b::Block, h::UInt) = hash(b.hash, h)that chains the cached hash value through the seed.Test plan
==forBlock; default struct equality comparesdataandhashfields, which is consistent with the new hash methodBlockis used as Dict key (Dict{Block{NR}, Bool}), so correctBase.hashis importantThis PR was generated with the assistance of generative AI.
Co-Authored-By: Claude noreply@anthropic.com