From 18b14e74819fac08f3f886bf1670ed2f716bd681 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Sat, 8 Jun 2024 18:25:04 +0300 Subject: [PATCH] QuantifiedConstraints Also change Arg instance --- .github/workflows/haskell-ci-bench.yml | 52 ++-------------- .github/workflows/haskell-ci.yml | 58 +++-------------- .github/workflows/simple.yml | 4 +- CHANGES.md | 17 +++++ hashable-bench/hashable-bench.cabal | 62 +++---------------- hashable.cabal | 70 +++++---------------- src/Data/Hashable/Class.hs | 86 +++++--------------------- src/Data/Hashable/XXH3.hs | 29 +-------- 8 files changed, 77 insertions(+), 301 deletions(-) diff --git a/.github/workflows/haskell-ci-bench.yml b/.github/workflows/haskell-ci-bench.yml index b5cefce..6b25bf4 100644 --- a/.github/workflows/haskell-ci-bench.yml +++ b/.github/workflows/haskell-ci-bench.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.19.20240514 +# version: 0.19.20240608 # -# REGENDATA ("0.19.20240514",["github","--project","cabal.bench.project","-o",".github/workflows/haskell-ci-bench.yml","--github-action-name","Benchmarks"]) +# REGENDATA ("0.19.20240608",["github","--project","cabal.bench.project","-o",".github/workflows/haskell-ci-bench.yml","--github-action-name","Benchmarks"]) # name: Benchmarks on: @@ -47,46 +47,6 @@ jobs: compilerVersion: 9.6.5 setup-method: ghcup allow-failure: false - - compiler: ghc-9.4.8 - compilerKind: ghc - compilerVersion: 9.4.8 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.2.8 - compilerKind: ghc - compilerVersion: 9.2.8 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.0.2 - compilerKind: ghc - compilerVersion: 9.0.2 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.0.1 - compilerKind: ghc - compilerVersion: 9.0.1 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.10.7 - compilerKind: ghc - compilerVersion: 8.10.7 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.10.4 - compilerKind: ghc - compilerVersion: 8.10.4 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.8.3 - compilerKind: ghc - compilerVersion: 8.8.3 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.6.5 - compilerKind: ghc - compilerVersion: 8.6.5 - setup-method: ghcup - allow-failure: false fail-fast: false steps: - name: apt @@ -239,10 +199,10 @@ jobs: rm -f cabal.project.local - name: constraint set filepath-1.5 run: | - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all --dry-run ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then cabal-plan topo | sort ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' --dependencies-only -j2 all ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all ; fi + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all --dry-run + cabal-plan topo | sort + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all - name: constraint set filepath-1.4.100.0 run: | if [ $((HCNUMVER < 91000)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all --dry-run ; fi diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 1ece4c4..e8270da 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.19.20240514 +# version: 0.19.20240608 # -# REGENDATA ("0.19.20240514",["github","cabal.project"]) +# REGENDATA ("0.19.20240608",["github","cabal.project"]) # name: Haskell-CI on: @@ -42,49 +42,9 @@ jobs: compilerVersion: 9.8.2 setup-method: ghcup allow-failure: false - - compiler: ghc-9.6.4 + - compiler: ghc-9.6.5 compilerKind: ghc - compilerVersion: 9.6.4 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.4.8 - compilerKind: ghc - compilerVersion: 9.4.8 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.2.8 - compilerKind: ghc - compilerVersion: 9.2.8 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.0.2 - compilerKind: ghc - compilerVersion: 9.0.2 - setup-method: ghcup - allow-failure: false - - compiler: ghc-9.0.1 - compilerKind: ghc - compilerVersion: 9.0.1 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.10.7 - compilerKind: ghc - compilerVersion: 8.10.7 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.10.4 - compilerKind: ghc - compilerVersion: 8.10.4 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.8.4 - compilerKind: ghc - compilerVersion: 8.8.4 - setup-method: ghcup - allow-failure: false - - compiler: ghc-8.6.5 - compilerKind: ghc - compilerVersion: 8.6.5 + compilerVersion: 9.6.5 setup-method: ghcup allow-failure: false fail-fast: false @@ -242,11 +202,11 @@ jobs: rm -f cabal.project.local - name: constraint set filepath-1.5 run: | - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all --dry-run ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then cabal-plan topo | sort ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' --dependencies-only -j2 all ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all ; fi - if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all ; fi + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all --dry-run + cabal-plan topo | sort + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all + $CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all - name: constraint set filepath-1.4.100.0 run: | if [ $((HCNUMVER < 91000)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all --dry-run ; fi diff --git a/.github/workflows/simple.yml b/.github/workflows/simple.yml index 655ccb4..02e5ff6 100644 --- a/.github/workflows/simple.yml +++ b/.github/workflows/simple.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest] - ghc: ['9.2','9.4.8','9.6.5','9.8.2'] + ghc: ['9.6.5','9.8.2'] fail-fast: false steps: - name: Set git to use LF @@ -52,7 +52,7 @@ jobs: CC: "gcc" strategy: matrix: - ghc: ['9.2.8'] + ghc: ['9.6.5'] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/CHANGES.md b/CHANGES.md index 8ac2741..5a328fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/hashable-bench/hashable-bench.cabal b/hashable-bench/hashable-bench.cabal index d68e551..bffd85e 100644 --- a/hashable-bench/hashable-bench.cabal +++ b/hashable-bench/hashable-bench.cabal @@ -20,15 +20,7 @@ stability: Provisional category: Data build-type: Simple tested-with: - GHC ==8.6.5 - || ==8.8.3 - || ==8.10.4 - || ==8.10.7 - || ==9.0.1 - || ==9.0.2 - || ==9.2.8 - || ==9.4.8 - || ==9.6.5 + GHC ==9.6.5 || ==9.8.2 || ==9.10.1 @@ -37,13 +29,6 @@ extra-source-files: include/HsXXHash.h 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 - library exposed-modules: Data.Hashable @@ -74,38 +59,17 @@ library , 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 - - if !impl(ghc >=9.2) - build-depends: base-orphans >=0.8.6 + -- 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 - 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 - if impl(ghc >=9) - build-depends: ghc-bignum >=1.0 && <1.4 - - if !impl(ghc >=9.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 + -- Integer internals + build-depends: ghc-bignum >=1.3 && <1.4 default-language: Haskell2010 other-extensions: @@ -146,12 +110,6 @@ benchmark hashable-benchmark ghc-prim , text >=0.11.0.5 - if (impl(ghc) && flag(integer-gmp)) - build-depends: integer-gmp >=0.2 - - if impl(ghc >=7.2.1) - cpp-options: -DGENERICS - ghc-options: -Wall default-language: Haskell2010 diff --git a/hashable.cabal b/hashable.cabal index b8bb7ea..89d6e5b 100644 --- a/hashable.cabal +++ b/hashable.cabal @@ -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. @@ -32,15 +32,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 + GHC ==9.6.5 || ==9.8.2 || ==9.10.1 @@ -51,13 +43,6 @@ extra-source-files: 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 +85,24 @@ library 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 + , text >=2.0.2 && <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 + -- 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 - - if !impl(ghc >=9.2) - build-depends: base-orphans >=0.8.6 && <0.10 - - 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 +124,7 @@ library KindSignatures MagicHash MultiParamTypeClasses + QuantifiedConstraints ScopedTypeVariables Trustworthy TypeOperators @@ -193,7 +157,7 @@ test-suite hashable-tests , 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 diff --git a/src/Data/Hashable/Class.hs b/src/Data/Hashable/Class.hs index d16b186..9de9209 100644 --- a/src/Data/Hashable/Class.hs +++ b/src/Data/Hashable/Class.hs @@ -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.List (foldl') 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 @@ import Foreign.C.Types (CInt (..)) #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 qualified "filepath" System.OsString.Internal.Types as FP (OsString (..), 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 @@ newtype instance HashArgs One a = HashArgs1 (Int -> a -> Int) 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 :: (Generic1 t, GHashable One (Rep1 t)) => (Int -> a -> 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 @@ instance Hashable Char where 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,22 +399,6 @@ instance Hashable Integer where 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) #-} @@ -835,8 +778,11 @@ deriving newtype instance Hashable a => Hashable (Semi.Max a) -- | __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 @@ deriving newtype instance Hashable a => Hashable (Semi.Option a) -- 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 (Compose f g) where 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 @@ instance Hashable v => Hashable (Tree.Tree v) where -- 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 diff --git a/src/Data/Hashable/XXH3.hs b/src/Data/Hashable/XXH3.hs index 7d7a53d..685b99e 100644 --- a/src/Data/Hashable/XXH3.hs +++ b/src/Data/Hashable/XXH3.hs @@ -5,7 +5,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE UnboxedTuples #-} -{-# LANGUAGE ViewPatterns #-} module Data.Hashable.XXH3 ( -- * One shot xxh3_64bit_withSeed_ptr, @@ -30,37 +29,11 @@ import Data.ByteString.Internal (ByteString (..), accursedUnutterablePerformIO) 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 -------------------------------------------------------------------------------