Skip to content

Commit 5f976f5

Browse files
authored
Merge pull request #685 from IntersectMBO/jeltsch/add-missing-io-and-st-specialisations
Add missing `IO` and `ST` specializations
2 parents 89ab77c + 49c2305 commit 5f976f5

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

src/Database/LSMTree/Internal/Arena.hs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ import Data.Word (Word8)
3434

3535
data ArenaManager s = ArenaManager (MutVar s [Arena s])
3636

37+
{-# SPECIALISE
38+
newArenaManager :: ST s (ArenaManager s)
39+
#-}
40+
{-# SPECIALISE
41+
newArenaManager :: IO (ArenaManager RealWorld)
42+
#-}
3743
newArenaManager :: PrimMonad m => m (ArenaManager (PrimState m))
3844
newArenaManager = do
3945
m <- newMutVar []
@@ -116,8 +122,12 @@ closeArena (ArenaManager arenas) arena = do
116122

117123
atomicModifyMutVar' arenas $ \xs -> (arena : xs, ())
118124

119-
120-
125+
{-# SPECIALISE
126+
scrambleArena :: Arena s -> ST s ()
127+
#-}
128+
{-# SPECIALISE
129+
scrambleArena :: Arena RealWorld -> IO ()
130+
#-}
121131
scrambleArena :: PrimMonad m => Arena (PrimState m) -> m ()
122132
#ifndef NO_IGNORE_ASSERTS
123133
scrambleArena _ = return ()
@@ -127,6 +137,12 @@ scrambleArena Arena {..} = do
127137
readMutVar full >>= mapM_ scrambleBlock
128138
readMutVar free >>= mapM_ scrambleBlock
129139

140+
{-# SPECIALISE
141+
scrambleBlock :: Block s -> ST s ()
142+
#-}
143+
{-# SPECIALISE
144+
scrambleBlock :: Block RealWorld -> IO ()
145+
#-}
130146
scrambleBlock :: PrimMonad m => Block (PrimState m) -> m ()
131147
scrambleBlock (Block _ mba) = do
132148
size <- getSizeofMutableByteArray mba
@@ -157,6 +173,12 @@ resetArena Arena {..} = do
157173
-- | Create unmanaged arena.
158174
--
159175
-- Never use this in non-tests code.
176+
{-# SPECIALISE
177+
withUnmanagedArena :: (Arena s -> ST s a) -> ST s a
178+
#-}
179+
{-# SPECIALISE
180+
withUnmanagedArena :: (Arena RealWorld -> IO a) -> IO a
181+
#-}
160182
withUnmanagedArena :: PrimMonad m => (Arena (PrimState m) -> m a) -> m a
161183
withUnmanagedArena k = do
162184
mgr <- newArenaManager
@@ -165,6 +187,9 @@ withUnmanagedArena k = do
165187
{-# SPECIALISE
166188
allocateFromArena :: Arena s -> Size -> Alignment -> ST s (Offset, MutableByteArray s)
167189
#-}
190+
{-# SPECIALISE
191+
allocateFromArena :: Arena RealWorld -> Size -> Alignment -> IO (Offset, MutableByteArray RealWorld)
192+
#-}
168193
-- | Allocate a slice of mutable byte array from the arena.
169194
allocateFromArena :: PrimMonad m => Arena (PrimState m)-> Size -> Alignment -> m (Offset, MutableByteArray (PrimState m))
170195
allocateFromArena !arena !size !alignment =
@@ -175,6 +200,9 @@ allocateFromArena !arena !size !alignment =
175200
{-# SPECIALISE
176201
allocateFromArena' :: Arena s -> Size -> Alignment -> ST s (Offset, MutableByteArray s)
177202
#-}
203+
{-# SPECIALISE
204+
allocateFromArena' :: Arena RealWorld -> Size -> Alignment -> IO (Offset, MutableByteArray RealWorld)
205+
#-}
178206
-- TODO!? this is not async exception safe
179207
allocateFromArena' :: PrimMonad m => Arena (PrimState m)-> Size -> Alignment -> m (Offset, MutableByteArray (PrimState m))
180208
allocateFromArena' arena@Arena { .. } !size !alignment = do
@@ -206,7 +234,12 @@ allocateFromArena' arena@Arena { .. } !size !alignment = do
206234
-- * go again
207235
allocateFromArena' arena size alignment
208236

209-
{-# SPECIALISE newBlockWithFree :: MutVar s [Block s] -> ST s (Block s) #-}
237+
{-# SPECIALISE
238+
newBlockWithFree :: MutVar s [Block s] -> ST s (Block s)
239+
#-}
240+
{-# SPECIALISE
241+
newBlockWithFree :: MutVar RealWorld [Block RealWorld] -> IO (Block RealWorld)
242+
#-}
210243
-- | Allocate new block, possibly taking it from a free list
211244
newBlockWithFree :: PrimMonad m => MutVar (PrimState m) [Block (PrimState m)] -> m (Block (PrimState m))
212245
newBlockWithFree free = do

src/Database/LSMTree/Internal/CRC32C.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,10 @@ data FileCorruptedError
466466

467467
{-# SPECIALISE
468468
expectValidFile ::
469-
(MonadThrow m)
470-
=> FsPath
469+
FsPath
471470
-> FileFormat
472471
-> Either String a
473-
-> m a
472+
-> IO a
474473
#-}
475474
expectValidFile ::
476475
(MonadThrow m)

src/Database/LSMTree/Internal/IncomingRun.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ creditThresholdForLevel conf (LevelNo _i) =
246246
-- This is /not/ itself thread safe. All 'TableContent' update operations are
247247
-- expected to be serialised by the caller. See concurrency comments for
248248
-- 'TableContent' for detail.
249+
{-# SPECIALISE depositNominalCredits ::
250+
NominalDebt
251+
-> PrimVar RealWorld NominalCredits
252+
-> NominalCredits
253+
-> IO (NominalCredits, NominalCredits) #-}
249254
depositNominalCredits ::
250255
PrimMonad m
251256
=> NominalDebt

src/Database/LSMTree/Internal/MergeSchedule.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ newtype UnionCache m h = UnionCache {
402402
cachedTree :: MT.LookupTree (V.Vector (Ref (Run m h)))
403403
}
404404

405+
{-# SPECIALISE mkUnionCache ::
406+
ActionRegistry IO
407+
-> Ref (MergingTree IO h)
408+
-> IO (UnionCache IO h) #-}
405409
mkUnionCache ::
406410
(PrimMonad m, MonadMVar m, MonadMask m)
407411
=> ActionRegistry m
@@ -410,6 +414,10 @@ mkUnionCache ::
410414
mkUnionCache reg mt =
411415
UnionCache <$> MT.buildLookupTree reg mt
412416

417+
{-# SPECIALISE duplicateUnionCache ::
418+
ActionRegistry IO
419+
-> UnionCache IO h
420+
-> IO (UnionCache IO h) #-}
413421
duplicateUnionCache ::
414422
(PrimMonad m, MonadMask m)
415423
=> ActionRegistry m
@@ -419,6 +427,10 @@ duplicateUnionCache reg (UnionCache mt) =
419427
UnionCache <$>
420428
MT.mapMStrict (mapMStrict (\r -> withRollback reg (dupRef r) releaseRef)) mt
421429

430+
{-# SPECIALISE releaseUnionCache ::
431+
ActionRegistry IO
432+
-> UnionCache IO h
433+
-> IO () #-}
422434
releaseUnionCache ::
423435
(PrimMonad m, MonadMask m)
424436
=> ActionRegistry m

src/Database/LSMTree/Internal/MergingTree.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ supplyCredits hfs hbio resolve runParams threshold root uc = \mt0 c0 -> do
532532

533533
-- | This does /not/ release the reference, but allocates a new reference for
534534
-- the returned run, which must be released at some point.
535+
{-# SPECIALISE expectCompleted ::
536+
Ref (MergingTree IO h)
537+
-> IO (Ref (Run IO h)) #-}
535538
expectCompleted ::
536539
(MonadMVar m, MonadSTM m, MonadST m, MonadMask m)
537540
=> Ref (MergingTree m h) -> m (Ref (Run m h))

src/Database/LSMTree/Internal/MergingTree/Lookup.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ data LookupTree a =
3333

3434
-- | Deriving 'Traversable' leads to functions that are not strict in the
3535
-- elements of the vector of children. This function avoids that issue.
36+
{-# SPECIALISE mapMStrict ::
37+
(a -> IO b)
38+
-> LookupTree a
39+
-> IO (LookupTree b) #-}
3640
mapMStrict :: Monad m => (a -> m b) -> LookupTree a -> m (LookupTree b)
3741
mapMStrict f = \case
3842
LookupBatch a -> LookupBatch <$!> f a

0 commit comments

Comments
 (0)