Skip to content

Commit 8d9679b

Browse files
committed
Build values eagerly on lift
1 parent e4a8963 commit 8d9679b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Define `dataCast1` for `HashMap`.
44

5+
* [Add `Lift` instances for Template Haskell](https://github.com/haskell-unordered-containers/unordered-containers/pull/343)
6+
57
## [0.2.16.0]
68

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

Data/HashMap/Internal.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
{-# LANGUAGE PatternGuards #-}
77
{-# LANGUAGE RoleAnnotations #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
9+
{-# LANGUAGE StandaloneDeriving #-}
10+
{-# LANGUAGE TemplateHaskellQuotes #-}
911
{-# LANGUAGE TypeFamilies #-}
1012
{-# LANGUAGE UnboxedTuples #-}
1113
#if __GLASGOW_HASKELL__ >= 802
@@ -192,11 +194,19 @@ hash :: H.Hashable a => a -> Hash
192194
hash = fromIntegral . H.hash
193195

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

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

202+
-- | @since 0.2.17.0
203+
instance (TH.Lift k, TH.Lift v) => TH.Lift (Leaf k v) where
204+
#if MIN_VERSION_template_haskell(2,16,0)
205+
liftTyped (L k v) = [|| L k $! v ||]
206+
#else
207+
lift (L k v) = [| L k $! v |]
208+
#endif
209+
200210
#if MIN_VERSION_deepseq(1,4,3)
201211
-- | @since 0.2.14.0
202212
instance NFData k => NF.NFData1 (Leaf k) where
@@ -218,10 +228,12 @@ data HashMap k v
218228
| Leaf !Hash !(Leaf k v)
219229
| Full !(A.Array (HashMap k v))
220230
| Collision !Hash !(A.Array (Leaf k v))
221-
deriving (TH.Lift)
222231

223232
type role HashMap nominal representational
224233

234+
-- | @since 0.2.17.0
235+
deriving instance (TH.Lift k, TH.Lift v) => TH.Lift (HashMap k v)
236+
225237
instance (NFData k, NFData v) => NFData (HashMap k v) where
226238
rnf Empty = ()
227239
rnf (BitmapIndexed _ ary) = rnf ary

Data/HashSet/Internal.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DeriveLift #-}
33
{-# LANGUAGE RoleAnnotations #-}
4+
{-# LANGUAGE StandaloneDeriving #-}
45
{-# LANGUAGE TypeFamilies #-}
56
{-# LANGUAGE Trustworthy #-}
67
{-# OPTIONS_HADDOCK not-home #-}
@@ -120,10 +121,12 @@ import qualified Language.Haskell.TH.Syntax as TH
120121
newtype HashSet a = HashSet {
121122
asMap :: HashMap a ()
122123
}
123-
} deriving (TH.Lift)
124124

125125
type role HashSet nominal
126126

127+
-- | @since 0.2.17.0
128+
deriving instance TH.Lift a => TH.Lift (HashSet a)
129+
127130
instance (NFData a) => NFData (HashSet a) where
128131
rnf = rnf . asMap
129132
{-# INLINE rnf #-}

0 commit comments

Comments
 (0)