hashable 1.4.7.0 → 1.5.0.0
raw patch · 4 files changed
+50/−156 lines, 4 filesdep −base-orphansdep −ghc-bignum-orphansdep −integer-gmpdep ~QuickCheckdep ~basedep ~bytestring
Dependencies removed: base-orphans, ghc-bignum-orphans, integer-gmp, integer-simple
Dependency ranges changed: QuickCheck, base, bytestring, containers, deepseq, filepath, ghc-bignum, os-string, tasty-quickcheck, text
Files
- CHANGES.md +17/−0
- hashable.cabal +17/−57
- src/Data/Hashable/Class.hs +15/−71
- src/Data/Hashable/XXH3.hs +1/−28
CHANGES.md view
@@ -1,5 +1,22 @@ See also https://pvp.haskell.org/faq +## Version 1.5.0.0++ * Add `QuantifiedConstraints` superclasses to `Hashable1/2`:++```haskell+class (Eq1 t, forall a. Hashable a => Hashable (t a)) => Hashable1 t where+class (Eq2 t, forall a. Hashable a => Hashable1 (t a)) => Hashable2 t where+```++ * Change contexts of `Compose`, `Product` and `Sum` instances.+ This and above is the similar change as [CLC proposal #10](https://github.com/haskell/core-libraries-committee/issues/10)++ * The above changes require `base-4.18.0.0`, so we drop support for GHC prior GHC-9.6.5+ (The `hashable-1.4` branch will be maintained for time being for older GHC users).++ * Make `Arg a b` instance behave as `Hashable a` instance.+ ## Version 1.4.7.0 * Make `arch-native` disabled by default.
hashable.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: hashable-version: 1.4.7.0+version: 1.5.0.0 synopsis: A class for types that can be converted to a hash value description: This package defines a class, 'Hashable', for types that can be converted to a hash value.@@ -31,19 +31,7 @@ stability: Provisional category: Data build-type: Simple-tested-with:- GHC ==8.6.5- || ==8.8.4- || ==8.10.4- || ==8.10.7- || ==9.0.1- || ==9.0.2- || ==9.2.8- || ==9.4.8- || ==9.6.4- || ==9.8.2- || ==9.10.1-+tested-with: GHC ==9.6.5 || ==9.8.2 || ==9.10.1 extra-source-files: CHANGES.md include/HsHashable.h@@ -51,13 +39,6 @@ README.md xxHash-0.8.2/xxhash.h -flag integer-gmp- description:- Are we using @integer-gmp@ to provide fast Integer instances? No effect on GHC-9.0 or later.-- manual: False- default: True- flag arch-native description: Use @-march=native@ when compiling C sources.@@ -100,46 +81,24 @@ hs-source-dirs: src build-depends:- , base >=4.12.0.0 && <4.21- , bytestring >=0.10.8.2 && <0.13- , containers >=0.6.0.1 && <0.8- , deepseq >=1.4.4.0 && <1.6+ , base >=4.18.0.0 && <4.21+ , bytestring >=0.11.5.3 && <0.13+ , containers >=0.6.7 && <0.8+ , deepseq >=1.4.8.1 && <1.6 , ghc-prim- , text >=1.2.3.0 && <1.3 || >=2.0 && <2.2-- if impl(ghc >=9.2)- -- depend on os-string on newer GHCs only.- -- os-string has tight lower bound on bytestring, which prevents- -- using bundled version on older GHCs.- build-depends: os-string >=2.0.2-- -- we also ensure that we can get filepath-1.5 only with GHC-9.2- -- therefore there is else-branch with stricter upper bound.- build-depends: filepath >=1.4.1.2 && <1.6-- else- build-depends: filepath >=1.4.1.2 && <1.5+ , text >=2.0.2 && <2.2 - if !impl(ghc >=9.2)- build-depends: base-orphans >=0.8.6 && <0.10+ -- depend on os-string on newer GHCs only.+ -- os-string has tight lower bound on bytestring, which prevents+ -- using bundled version on older GHCs.+ build-depends: os-string >=2.0.2 && <2.1 - if !impl(ghc >=9.4)- build-depends: data-array-byte >=0.1.0.1 && <0.2+ -- we also ensure that we can get filepath-1.5 only with GHC-9.2+ -- therefore there is else-branch with stricter upper bound.+ build-depends: filepath >=1.4.200.1 && <1.6 -- Integer internals- if impl(ghc >=9)- build-depends: ghc-bignum >=1.0 && <1.4-- if !impl(ghc >=9.0.2)- build-depends: ghc-bignum-orphans >=0.1 && <0.2-- else- if flag(integer-gmp)- build-depends: integer-gmp >=0.4 && <1.1-- else- -- this is needed for the automatic flag to be well-balanced- build-depends: integer-simple+ build-depends: ghc-bignum >=1.3 && <1.4 if (flag(random-initial-seed) && impl(ghc)) cpp-options: -DHASHABLE_RANDOM_SEED=1@@ -161,6 +120,7 @@ KindSignatures MagicHash MultiParamTypeClasses+ QuantifiedConstraints ScopedTypeVariables Trustworthy TypeOperators@@ -193,7 +153,7 @@ , ghc-prim , hashable , HUnit- , QuickCheck >=2.4.0.1+ , QuickCheck >=2.15 , random >=1.0 && <1.3 , tasty ^>=1.5 , tasty-hunit ^>=0.10.1
src/Data/Hashable/Class.hs view
@@ -9,13 +9,12 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PackageImports #-} {-# LANGUAGE PolyKinds #-}+{-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-}-{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UnliftedFFITypes #-}- {-# OPTIONS_GHC -fno-warn-deprecations #-} ------------------------------------------------------------------------@@ -86,6 +85,7 @@ import Data.Proxy (Proxy) import Data.Ratio (Ratio, denominator, numerator) import Data.String (IsString (..))+import Data.Tuple (Solo (..)) import Data.Unique (Unique, hashUnique) import Data.Version (Version (..)) import Data.Void (Void, absurd)@@ -134,32 +134,14 @@ #endif #endif -#ifdef VERSION_ghc_bignum import GHC.Exts (Int (..), sizeofByteArray#) import GHC.Num.BigNat (BigNat (..)) import GHC.Num.Integer (Integer (..)) import GHC.Num.Natural (Natural (..))-#endif -#ifdef VERSION_integer_gmp-import GHC.Exts (Int (..))-import GHC.Integer.GMP.Internals (Integer (..))-import GHC.Exts (sizeofByteArray#)-import GHC.Integer.GMP.Internals (BigNat (BN#))-#endif -#ifndef VERSION_ghc_bignum-import GHC.Natural (Natural (..))-#endif- import GHC.Float (castDoubleToWord64, castFloatToWord32) -#if MIN_VERSION_base(4,16,0)-import Data.Tuple (Solo (..))-#elif MIN_VERSION_base(4,15,0)-import GHC.Tuple (Solo (..))-#endif- -- filepath >=1.4.100 && <1.5 has System.OsString.Internal.Types module #if MIN_VERSION_filepath(1,4,100) && !(MIN_VERSION_filepath(1,5,0)) #define HAS_OS_STRING_filepath 1@@ -182,14 +164,6 @@ import System.OsString.Internal.Types (OsString (..), PosixString (..), WindowsString (..)) #endif -#ifdef VERSION_base_orphans-import Data.Orphans ()-#endif--#ifdef VERSION_ghc_bignum_orphans-import GHC.Num.Orphans ()-#endif- import Data.Hashable.Imports import Data.Hashable.LowLevel import Data.Hashable.XXH3@@ -275,7 +249,7 @@ class GHashable arity f where ghashWithSalt :: HashArgs arity a -> Int -> f a -> Int -class Eq1 t => Hashable1 t where+class (Eq1 t, forall a. Hashable a => Hashable (t a)) => Hashable1 t where -- | Lift a hashing function through the type constructor. liftHashWithSalt :: (Int -> a -> Int) -> Int -> t a -> Int @@ -290,7 +264,7 @@ genericLiftHashWithSalt = \h salt -> ghashWithSalt (HashArgs1 h) salt . from1 {-# INLINE genericLiftHashWithSalt #-} -class Eq2 t => Hashable2 t where+class (Eq2 t, forall a. Hashable a => Hashable1 (t a)) => Hashable2 t where -- | Lift a hashing function through the binary type constructor. liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> t a b -> Int @@ -407,32 +381,17 @@ hash = fromEnum hashWithSalt = defaultHashWithSalt -#if defined(VERSION_integer_gmp) || defined(VERSION_ghc_bignum) instance Hashable BigNat where hashWithSalt salt (BN# ba) = hashWithSalt salt (ByteArray ba)-#endif instance Hashable Natural where-#if defined(VERSION_ghc_bignum) hash (NS n) = hash (W# n) hash (NB bn) = hash (BN# bn) hashWithSalt salt (NS n) = hashWithSalt salt (W# n) hashWithSalt salt (NB bn) = hashWithSalt salt (BN# bn)-#elif defined(VERSION_integer_gmp)- hash (NatS# n) = hash (W# n)- hash (NatJ# bn) = hash bn - hashWithSalt salt (NatS# n) = hashWithSalt salt (W# n)- hashWithSalt salt (NatJ# bn) = hashWithSalt salt bn-#else- hash (Natural n) = hash n-- hashWithSalt salt (Natural n) = hashWithSalt salt n-#endif- instance Hashable Integer where-#if defined(VERSION_ghc_bignum) hash (IS n) = I# n hash (IP bn) = hash (BN# bn) hash (IN bn) = negate (hash (BN# bn))@@ -440,23 +399,7 @@ hashWithSalt salt (IS n) = hashWithSalt salt (I# n) hashWithSalt salt (IP bn) = hashWithSalt salt (BN# bn) hashWithSalt salt (IN bn) = negate (hashWithSalt salt (BN# bn))-#elif defined(VERSION_integer_gmp)- hash (S# n) = (I# n)- hash (Jp# bn) = hash bn- hash (Jn# bn) = negate (hash bn) - hashWithSalt salt (S# n) = hashWithSalt salt (I# n)- hashWithSalt salt (Jp# bn) = hashWithSalt salt bn- hashWithSalt salt (Jn# bn) = negate (hashWithSalt salt bn)-#else- hashWithSalt salt = foldl' hashWithSalt salt . go- where- go n | inBounds n = [fromIntegral n :: Int]- | otherwise = fromIntegral n : go (n `shiftR` WORD_SIZE_IN_BITS)- maxInt = fromIntegral (maxBound :: Int)- inBounds x = x >= fromIntegral (minBound :: Int) && x <= maxInt-#endif- instance Hashable a => Hashable (Complex a) where {-# SPECIALIZE instance Hashable (Complex Double) #-} {-# SPECIALIZE instance Hashable (Complex Float) #-}@@ -835,8 +778,11 @@ -- | __Note__: Prior to @hashable-1.3.0.0@ the hash computation included the second argument of 'Arg' which wasn't consistent with its 'Eq' instance. --+-- Since @hashable-1.5.0.0@, @hash (Semi.arg a _) = hash a@+-- -- @since 1.3.0.0 instance Hashable a => Hashable (Semi.Arg a b) where+ hash (Semi.Arg a _) = hash a hashWithSalt p (Semi.Arg a _) = hashWithSalt p a deriving newtype instance Hashable a => Hashable (Semi.First a)@@ -870,10 +816,9 @@ -- instance Hashable1 Option where liftHashWithSalt h salt (Option a) = liftHashWithSalt h salt a #endif --- | In general, @hash (Compose x) ≠ hash x@. However, @hashWithSalt@ satisfies--- its variant of this equivalence.-instance (Hashable1 f, Hashable1 g, Hashable a) => Hashable (Compose f g a) where- hashWithSalt = hashWithSalt1+instance (Hashable (f (g a))) => Hashable (Compose f g a) where+ hash (Compose x) = hash x+ hashWithSalt p (Compose x) = hashWithSalt p x instance (Hashable1 f, Hashable1 g) => Hashable1 (Compose f g) where liftHashWithSalt h s = liftHashWithSalt (liftHashWithSalt h) s . getCompose@@ -881,15 +826,16 @@ instance (Hashable1 f, Hashable1 g) => Hashable1 (FP.Product f g) where liftHashWithSalt h s (FP.Pair a b) = liftHashWithSalt h (liftHashWithSalt h s a) b -instance (Hashable1 f, Hashable1 g, Hashable a) => Hashable (FP.Product f g a) where- hashWithSalt = hashWithSalt1+instance (Hashable (f a), Hashable (g a)) => Hashable (FP.Product f g a) where+ hashWithSalt s (FP.Pair a b) = s `hashWithSalt` a `hashWithSalt` b instance (Hashable1 f, Hashable1 g) => Hashable1 (FS.Sum f g) where liftHashWithSalt h s (FS.InL a) = liftHashWithSalt h (s `hashInt` 0) a liftHashWithSalt h s (FS.InR a) = liftHashWithSalt h (s `hashInt` distinguisher) a -instance (Hashable1 f, Hashable1 g, Hashable a) => Hashable (FS.Sum f g a) where- hashWithSalt = hashWithSalt1+instance (Hashable (f a), Hashable (g a)) => Hashable (FS.Sum f g a) where+ hashWithSalt s (FS.InL a) = hashWithSalt (s `hashInt` 0) a+ hashWithSalt s (FS.InR a) = hashWithSalt (s `hashInt` distinguisher) a -- | This instance was available since 1.4.1.0 only for GHC-9.4+ --@@ -1047,9 +993,7 @@ -- Solo ------------------------------------------------------------------------------- -#if MIN_VERSION_base(4,15,0) instance Hashable a => Hashable (Solo a) where hashWithSalt = hashWithSalt1 instance Hashable1 Solo where liftHashWithSalt h salt (Solo x) = h salt x-#endif
src/Data/Hashable/XXH3.hs view
@@ -5,7 +5,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE UnboxedTuples #-}-{-# LANGUAGE ViewPatterns #-} module Data.Hashable.XXH3 ( -- * One shot xxh3_64bit_withSeed_ptr,@@ -30,36 +29,10 @@ import Data.Word (Word32, Word64, Word8) import Foreign (Ptr) import GHC.Exts (Int (..), MutableByteArray#, newAlignedPinnedByteArray#)+import GHC.ForeignPtr (unsafeWithForeignPtr) import GHC.ST (ST (..)) import Data.Hashable.FFI--#if MIN_VERSION_base(4,15,0)-import GHC.ForeignPtr (unsafeWithForeignPtr)-#else-import Foreign (ForeignPtr, withForeignPtr)-#endif--#if MIN_VERSION_bytestring(0,11,0)-#else-import Foreign (ForeignPtr, plusForeignPtr)-#endif--#if !MIN_VERSION_base(4,15,0)-unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b-unsafeWithForeignPtr = withForeignPtr-#endif--#if MIN_VERSION_bytestring(0,11,0)-#else-pattern BS :: ForeignPtr Word8 -> Int -> ByteString-pattern BS fptr len <- (matchBS -> (fptr,len))- where BS fptr len = PS fptr 0 len-{-# COMPLETE BS #-}--matchBS :: ByteString -> (ForeignPtr Word8, Int)-matchBS (PS fptr off len) = (plusForeignPtr fptr off, len)-#endif ------------------------------------------------------------------------------- -- OneShot