Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix FNV bug on 64-bit Windows (hashes being cut off to 32-bit) - #211

#211
Closed
mtolly wants to merge 1 commit into
haskell-unordered-containers:masterhaskell-unordered-containers/hashable:masterfrom
mtolly:mastermtolly/hashable:masterCopy head branch name to clipboard
Closed

Fix FNV bug on 64-bit Windows (hashes being cut off to 32-bit)#211
mtolly wants to merge 1 commit into
haskell-unordered-containers:masterhaskell-unordered-containers/hashable:masterfrom
mtolly:mastermtolly/hashable:masterCopy head branch name to clipboard

Conversation

@mtolly

@mtolly mtolly commented Aug 5, 2021

Copy link
Copy Markdown
Contributor

I observed an issue in my app where many input values (of a nested record type) were being hashed to the same value, and eventually determined it was only happening on Windows. After tracing the problem back, I noticed Text values were always being hashed to 32-bit values, and that when I combined the hashes of (record, text), the input record hash (used as salt) was also being cut off to 32-bit.

That led me to these issues with fnv.c. It is using long which is 32 bits on 64-bit Windows. However Haskell Int, as well as WORD_SIZE_IN_BITS, are 64. So hashes in general are 64-bit, but then getting improperly cut off when they interact with this code, such as through Text and other byte array types. I also noticed the FNV_PRIME constant added recently was not actually being used; I assume it was supposed to replace the numeric constant in the function below.

I tested that this fixes the hash behavior in my app, but I have not tested on a 32-bit platform yet.

@mtolly mtolly changed the title Fix FNV bug on 64-bit Windows (hashes being clamped to 32-bit) Fix FNV bug on 64-bit Windows (hashes being cut off to 32-bit) Aug 5, 2021
@phadej

phadej commented Aug 24, 2021

Copy link
Copy Markdown
Contributor

Merged in #213

@phadej phadej closed this Aug 24, 2021
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Feb 11, 2022
Version 1.4.0.2
* Restore older GHC support
* Support GHC-9.0.2

Version 1.4.0.1
* text-2.0 compatibility

Version 1.4.0.0
* Eq is now a superclass of Hashable. Also Eq1 is a superclass of Hashable1
  and Eq2 is a superclass of Hashable2 when exists.
* Remove Hashable1 Fixed instance
* Remove Hashable1 Semi.Min/Max/... instances as they don't have Eq1
  instance.

Version 1.3.5.0
* Add Solo instance (base-4.15+, GHC-9+)

Version 1.3.4.1
* Fix compilation on 32 bit platforms
* Fix Tree instance

Version 1.3.4.0
* Text and ByteString hashes include length. This fixes a variant of
  haskell-unordered-containers/hashable#74 for
  texts and
  bytestrings. haskell-unordered-containers/hashable#223
* Use correct prime in combine. This should improve the hash quality of
  compound structures on 64bit
  systems. haskell-unordered-containers/hashable#224
* Add instance for types in containers package
  haskell-unordered-containers/hashable#226
* Change Int, Int64 and Word64 hashWithSalt
  slightly. haskell-unordered-containers/hashable#227

Version 1.3.3.0
* Text hashing uses 64-bit FNV prime
* Don't truncate Text hashvalues on 64bit Windows:
  haskell-unordered-containers/hashable#211

Version 1.3.2.0
* Add Hashable (Fixed a) for base <4.7 versions.
* Add documentation:
  * hashable is not a stable hash
  * hashWithSalt may return negative values
  * there is time-compat with Hashable instances for time types.
* Add random-initial-seed flag causing the initial seed to be randomized on
  each start of an executable using hashable.
msk pushed a commit to msk/pkgsrc that referenced this pull request May 11, 2026
Version 1.4.0.2
* Restore older GHC support
* Support GHC-9.0.2

Version 1.4.0.1
* text-2.0 compatibility

Version 1.4.0.0
* Eq is now a superclass of Hashable. Also Eq1 is a superclass of Hashable1
  and Eq2 is a superclass of Hashable2 when exists.
* Remove Hashable1 Fixed instance
* Remove Hashable1 Semi.Min/Max/... instances as they don't have Eq1
  instance.

Version 1.3.5.0
* Add Solo instance (base-4.15+, GHC-9+)

Version 1.3.4.1
* Fix compilation on 32 bit platforms
* Fix Tree instance

Version 1.3.4.0
* Text and ByteString hashes include length. This fixes a variant of
  haskell-unordered-containers/hashable#74 for
  texts and
  bytestrings. haskell-unordered-containers/hashable#223
* Use correct prime in combine. This should improve the hash quality of
  compound structures on 64bit
  systems. haskell-unordered-containers/hashable#224
* Add instance for types in containers package
  haskell-unordered-containers/hashable#226
* Change Int, Int64 and Word64 hashWithSalt
  slightly. haskell-unordered-containers/hashable#227

Version 1.3.3.0
* Text hashing uses 64-bit FNV prime
* Don't truncate Text hashvalues on 64bit Windows:
  haskell-unordered-containers/hashable#211

Version 1.3.2.0
* Add Hashable (Fixed a) for base <4.7 versions.
* Add documentation:
  * hashable is not a stable hash
  * hashWithSalt may return negative values
  * there is time-compat with Hashable instances for time types.
* Add random-initial-seed flag causing the initial seed to be randomized on
  each start of an executable using hashable.
jperkin pushed a commit to TritonDataCenter/pkgsrc that referenced this pull request May 14, 2026
Version 1.4.0.2
* Restore older GHC support
* Support GHC-9.0.2

Version 1.4.0.1
* text-2.0 compatibility

Version 1.4.0.0
* Eq is now a superclass of Hashable. Also Eq1 is a superclass of Hashable1
  and Eq2 is a superclass of Hashable2 when exists.
* Remove Hashable1 Fixed instance
* Remove Hashable1 Semi.Min/Max/... instances as they don't have Eq1
  instance.

Version 1.3.5.0
* Add Solo instance (base-4.15+, GHC-9+)

Version 1.3.4.1
* Fix compilation on 32 bit platforms
* Fix Tree instance

Version 1.3.4.0
* Text and ByteString hashes include length. This fixes a variant of
  haskell-unordered-containers/hashable#74 for
  texts and
  bytestrings. haskell-unordered-containers/hashable#223
* Use correct prime in combine. This should improve the hash quality of
  compound structures on 64bit
  systems. haskell-unordered-containers/hashable#224
* Add instance for types in containers package
  haskell-unordered-containers/hashable#226
* Change Int, Int64 and Word64 hashWithSalt
  slightly. haskell-unordered-containers/hashable#227

Version 1.3.3.0
* Text hashing uses 64-bit FNV prime
* Don't truncate Text hashvalues on 64bit Windows:
  haskell-unordered-containers/hashable#211

Version 1.3.2.0
* Add Hashable (Fixed a) for base <4.7 versions.
* Add documentation:
  * hashable is not a stable hash
  * hashWithSalt may return negative values
  * there is time-compat with Hashable instances for time types.
* Add random-initial-seed flag causing the initial seed to be randomized on
  each start of an executable using hashable.
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.