Skip to content

Commit 76f9f33

Browse files
committed
Build values eagerly on lift
1 parent ce90ecc commit 76f9f33

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.2.17.0]
2+
3+
* [Add `Lift` instances for Template Haskell](https://github.com/haskell-unordered-containers/unordered-containers/pull/343)
4+
15
## [0.2.16.0]
26

37
* [Increase maximum branching factor from 16 to 32](https://github.com/haskell-unordered-containers/unordered-containers/pull/317)

Data/HashMap/Internal.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
{-# LANGUAGE PatternGuards #-}
88
{-# LANGUAGE RoleAnnotations #-}
99
{-# LANGUAGE ScopedTypeVariables #-}
10+
{-# LANGUAGE StandaloneDeriving #-}
11+
{-# LANGUAGE TemplateHaskellQuotes #-}
1012
{-# LANGUAGE TypeFamilies #-}
1113
{-# LANGUAGE UnboxedTuples #-}
1214
#if __GLASGOW_HASKELL__ >= 802
@@ -194,11 +196,19 @@ hash :: H.Hashable a => a -> Hash
194196
hash = fromIntegral . H.hash
195197

196198
data Leaf k v = L !k v
197-
deriving (Eq, TH.Lift)
199+
deriving (Eq)
198200

199201
instance (NFData k, NFData v) => NFData (Leaf k v) where
200202
rnf (L k v) = rnf k `seq` rnf v
201203

204+
-- | @since 0.2.17.0
205+
instance (TH.Lift k, TH.Lift v) => TH.Lift (Leaf k v) where
206+
#if MIN_VERSION_template_haskell(2,16,0)
207+
liftTyped (L k v) = [|| L k $! v ||]
208+
#else
209+
lift (L k v) = [| L k $! v |]
210+
#endif
211+
202212
#if MIN_VERSION_deepseq(1,4,3)
203213
-- | @since 0.2.14.0
204214
instance NFData k => NF.NFData1 (Leaf k) where
@@ -220,10 +230,13 @@ data HashMap k v
220230
| Leaf !Hash !(Leaf k v)
221231
| Full !(A.Array (HashMap k v))
222232
| Collision !Hash !(A.Array (Leaf k v))
223-
deriving (Typeable, TH.Lift)
233+
deriving (Typeable)
224234

225235
type role HashMap nominal representational
226236

237+
-- | @since 0.2.17.0
238+
deriving instance (TH.Lift k, TH.Lift v) => TH.Lift (HashMap k v)
239+
227240
instance (NFData k, NFData v) => NFData (HashMap k v) where
228241
rnf Empty = ()
229242
rnf (BitmapIndexed _ ary) = rnf ary

Data/HashSet/Internal.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE DeriveDataTypeable #-}
33
{-# LANGUAGE DeriveLift #-}
44
{-# LANGUAGE RoleAnnotations #-}
5+
{-# LANGUAGE StandaloneDeriving #-}
56
{-# LANGUAGE TypeFamilies #-}
67
{-# LANGUAGE Trustworthy #-}
78
{-# OPTIONS_HADDOCK not-home #-}
@@ -121,10 +122,13 @@ import qualified Language.Haskell.TH.Syntax as TH
121122
-- | A set of values. A set cannot contain duplicate values.
122123
newtype HashSet a = HashSet {
123124
asMap :: HashMap a ()
124-
} deriving (Typeable, TH.Lift)
125+
} deriving (Typeable)
125126

126127
type role HashSet nominal
127128

129+
-- | @since 0.2.17.0
130+
deriving instance TH.Lift a => TH.Lift (HashSet a)
131+
128132
instance (NFData a) => NFData (HashSet a) where
129133
rnf = rnf . asMap
130134
{-# INLINE rnf #-}

0 commit comments

Comments
 (0)