hashable-generics 1.1.6 → 1.1.7
raw patch · 4 files changed
+49/−13 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Hashable/Generic.hs +20/−7
- bench/Bench.hs +21/−1
- hashable-generics.cabal +2/−2
- test/Suite.hs +6/−3
Data/Hashable/Generic.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE TypeOperators, FlexibleContexts, BangPatterns #-}+{-# OPTIONS_GHC -Wall #-} -- | Stability: stable -- Portability: GHC module Data.Hashable.Generic ( gHashWithSalt@@ -42,15 +43,22 @@ -- > -- a non-generic implementation. If you use this method, the generic -- > -- hashWithSalt will generate the exact same code as a hand-rolled -- > -- one.+-- > --+-- > -- Also, the INLINEABLE pragma is there to help hashable data+-- > -- structures in other modules write more efficient generic hashable+-- > -- instances too. This is the best way to get extremely performant,+-- > -- fully generic hash functions. -- > instance Hashable AccountId -- > instance Hashable Foo where -- > hashWithSalt s x = gHashWithSalt s x+-- > {-# INLINEABLE hashWithSalt #-} -- > -- > -- recursive list-like type -- > data N = Z | S N deriving Generic -- > -- > instance Hashable N where -- > hashWithSalt s x = gHashWithSalt s x+-- > {-# INLINEABLE hashWithSalt #-} -- > -- > -- parametric and recursive type -- > data Bar a = Bar0 | Bar1 a | Bar2 (Bar a)@@ -58,11 +66,16 @@ -- > -- > instance Hashable a => Hashable (Bar a) where -- > hashWithSalt s x = gHashWithSalt s x+-- > {-# INLINEABLE hashWithSalt #-} --+-- I intend for 'gHashWithSalt' to be just as fast as a hand-rolled+-- implementation. Benchmarks are currently showing a 1.3x slowdown. Patches+-- to improve performance are welcome!+-- -- Note: The 'GHashable' type-class showing up in the type-signature is -- used internally and not exported on purpose. gHashWithSalt :: (Generic a, GHashable (Rep a)) => Int -> a -> Int-gHashWithSalt salt x = gHashWithSalt_ salt $ from x+gHashWithSalt salt = gHashWithSalt_ salt . from {-# INLINE gHashWithSalt #-} -- | A value with bit pattern (01)* (or 5* in hexa), for any size of Int.@@ -79,22 +92,22 @@ gHashWithSalt_ :: Int -> f a -> Int instance GHashable U1 where- gHashWithSalt_ salt _ = hashWithSalt salt ()+ gHashWithSalt_ = const {-# INLINE gHashWithSalt_ #-} instance Hashable a => GHashable (K1 i a) where- gHashWithSalt_ !salt = hashWithSalt salt . unK1+ gHashWithSalt_ salt = hashWithSalt salt . unK1 {-# INLINE gHashWithSalt_ #-} instance GHashable a => GHashable (M1 i c a) where- gHashWithSalt_ !salt = gHashWithSalt_ salt . unM1+ gHashWithSalt_ salt = gHashWithSalt_ salt . unM1 {-# INLINE gHashWithSalt_ #-} instance (GHashable a, GHashable b) => GHashable (a :*: b) where- gHashWithSalt_ !salt (x :*: y) = gHashWithSalt_ (gHashWithSalt_ salt x) y+ gHashWithSalt_ salt (x :*: y) = gHashWithSalt_ (gHashWithSalt_ salt x) y {-# INLINE gHashWithSalt_ #-} instance (GHashable a, GHashable b) => GHashable (a :+: b) where- gHashWithSalt_ !salt (L1 x) = gHashWithSalt_ (salt `combine` 0) x- gHashWithSalt_ !salt (R1 x) = gHashWithSalt_ (salt `combine` distinguisher) x+ gHashWithSalt_ !salt (L1 x) = gHashWithSalt_ (combine salt 0) x+ gHashWithSalt_ !salt (R1 x) = gHashWithSalt_ (combine salt distinguisher) x {-# INLINE gHashWithSalt_ #-}
bench/Bench.hs view
@@ -37,7 +37,27 @@ i = HR2 e f j = HR2 g h k = HR2 i j- in HR2 k k+ l = HR2 k k+ m = HR2 l l+ n = HR2 m m+ o = HR2 n n+ p = HR2 o o+ q = HR2 p p+ r = HR2 q q+ s = HR2 r r+ t = HR2 s s+ u = HR2 t t+ v = HR2 u u+ w = HR2 v v+ x = HR2 w w+ y = HR2 x x+ z = HR2 y y+ za = HR2 z z+ zb = HR2 za za+ zc = HR2 zb zb+ zd = HR2 zc zc+ ze = HR2 zd zd+ in ze bigGenericRolledDS :: GenericRolled bigGenericRolledDS = f bigHandRolledDS
hashable-generics.cabal view
@@ -1,5 +1,5 @@ name: hashable-generics-version: 1.1.6+version: 1.1.7 synopsis: Automatically generates Hashable instances with GHC.Generics. description: This package provides a "GHC.Generics"-based 'Data.Hashable.Generic.gHashWithSalt'@@ -18,7 +18,7 @@ category: Data build-type: Simple cabal-version: >=1.8-tested-with: GHC >=7.4+tested-with: GHC ==7.4.1, GHC ==7.6.1 source-repository head type: git
test/Suite.hs view
@@ -51,7 +51,8 @@ arbitrary = AccountId <$> arbitrary instance Hashable FooA where- hashWithSalt = gHashWithSalt+ hashWithSalt s x = gHashWithSalt s x+ {-# INLINEABLE hashWithSalt #-} instance Hashable FooB where hashWithSalt salt (FooB ac n ad) = hashWithSalt@@ -74,9 +75,10 @@ instance Hashable NA where hashWithSalt s x = gHashWithSalt s x+ {-# INLINEABLE hashWithSalt #-} instance Hashable NB where- hashWithSalt !salt ZB = hashWithSalt (salt `combine` 0) ()+ hashWithSalt !salt ZB = combine salt 0 hashWithSalt !salt (SB xs) = hashWithSalt (salt `combine` distinguisher) xs instance Arbitrary NA where@@ -107,9 +109,10 @@ instance Hashable a => Hashable (BarA a) where hashWithSalt s x = gHashWithSalt s x+ {-# INLINEABLE hashWithSalt #-} instance Hashable a => Hashable (BarB a) where- hashWithSalt !salt BarB0 = hashWithSalt (salt `combine` 0) ()+ hashWithSalt !salt BarB0 = salt `combine` 0 hashWithSalt !salt (BarB1 x) = hashWithSalt (salt `combine` distinguisher `combine` 0) x hashWithSalt !salt (BarB2 x) = hashWithSalt (salt `combine` distinguisher `combine` distinguisher) x