Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Development/Shake/Internal/Core/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
import System.Time.Extra


-- All of General.Wait is used at Locked here; its functions are INLINABLE.
{-# SPECIALISE runWait :: Wait Locked a -> Locked (Wait Locked a) #-}

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC runWait"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC runWait @locked @_"

Check failure on line 42 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC runWait @locked @_"
{-# SPECIALISE fromLater :: Wait Locked a -> (a -> Locked ()) -> Locked () #-}

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC fromLater"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC fromLater @locked @_"

Check failure on line 43 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC fromLater @locked @_"
{-# SPECIALISE firstJustWaitUnordered :: (a -> Wait Locked (Maybe b)) -> [a] -> Wait Locked (Maybe b) #-}

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Orphan rule: "SPEC firstJustWaitUnordered"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.6)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.10)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.8)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.12)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"

Check failure on line 44 in src/Development/Shake/Internal/Core/Build.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

Orphan rule: "USPEC firstJustWaitUnordered @locked @_ @_"


---------------------------------------------------------------------
-- LOW-LEVEL OPERATIONS ON THE DATABASE

Expand Down
3 changes: 3 additions & 0 deletions src/Development/Shake/Internal/Core/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ createDatabase status journal vDefault = do
-- SAFE READ-ONLY

getValueFromKey :: (Eq k, Hashable k) => DatabasePoly k v -> k -> IO (Maybe v)
{-# INLINABLE getValueFromKey #-}
getValueFromKey Database{..} k = do
is <- readIORef intern
case Intern.lookup k is of
Expand All @@ -76,6 +77,7 @@ getKeyValuesFromId :: DatabasePoly k v -> IO (Map.HashMap Id (k, v))
getKeyValuesFromId Database{..} = Ids.toMap status

getIdFromKey :: (Eq k, Hashable k) => DatabasePoly k v -> IO (k -> Maybe Id)
{-# INLINABLE getIdFromKey #-}
getIdFromKey Database{..} = do
is <- readIORef intern
pure $ flip Intern.lookup is
Expand All @@ -86,6 +88,7 @@ getIdFromKey Database{..} = do

-- | Ensure that a Key has a given Id, creating an Id if there is not one already
mkId :: (Eq k, Hashable k) => DatabasePoly k v -> k -> Locked Id
{-# INLINABLE mkId #-}
mkId Database{..} k = liftIO $ do
is <- readIORef intern
case Intern.lookup k is of
Expand Down
6 changes: 6 additions & 0 deletions src/Development/Shake/Internal/Core/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@

type Database = DatabasePoly Key Status

-- The only instantiation of the Core.Database lookups; every caller imports this module.
-- These rules are orphans (the functions live in Core.Database), which is harmless here.
{-# SPECIALISE getValueFromKey :: Database -> Key -> IO (Maybe Status) #-}

Check failure on line 444 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘getValueFromKey’

Check failure on line 444 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘getValueFromKey’

Check failure on line 444 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘getValueFromKey’

Check failure on line 444 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘getValueFromKey’

Check failure on line 444 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘getValueFromKey’

Check failure on line 444 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘getValueFromKey’
{-# SPECIALISE getIdFromKey :: Database -> IO (Key -> Maybe Id) #-}

Check failure on line 445 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘getIdFromKey’

Check failure on line 445 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘getIdFromKey’

Check failure on line 445 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘getIdFromKey’

Check failure on line 445 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘getIdFromKey’

Check failure on line 445 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘getIdFromKey’

Check failure on line 445 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘getIdFromKey’
{-# SPECIALISE mkId :: Database -> Key -> Locked Id #-}

Check failure on line 446 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘mkId’

Check failure on line 446 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘mkId’

Check failure on line 446 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

You cannot SPECIALISE ‘mkId’

Check failure on line 446 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘mkId’

Check failure on line 446 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘mkId’

Check failure on line 446 in src/Development/Shake/Internal/Core/Types.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

You cannot SPECIALISE ‘mkId’

-- global constants of Action
data Global = Global
{globalBuild :: [String] -> [Key] -> Action [Value]
Expand Down
8 changes: 8 additions & 0 deletions src/General/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ binaryOpMap mp = BinaryOp


binarySplit :: forall a . Storable a => BS.ByteString -> (a, BS.ByteString)
{-# INLINABLE binarySplit #-}
binarySplit bs | BS.length bs < sizeOf (undefined :: a) = error "Reading from ByteString, insufficient left"
| otherwise = unsafeBinarySplit bs

binarySplit2 :: forall a b . (Storable a, Storable b) => BS.ByteString -> (a, b, BS.ByteString)
{-# INLINABLE binarySplit2 #-}
binarySplit2 bs | BS.length bs < sizeOf (undefined :: a) + sizeOf (undefined :: b) = error "Reading from ByteString, insufficient left"
| (a,bs) <- unsafeBinarySplit bs, (b,bs) <- unsafeBinarySplit bs = (a,b,bs)

binarySplit3 :: forall a b c . (Storable a, Storable b, Storable c) => BS.ByteString -> (a, b, c, BS.ByteString)
{-# INLINABLE binarySplit3 #-}
binarySplit3 bs | BS.length bs < sizeOf (undefined :: a) + sizeOf (undefined :: b) + sizeOf (undefined :: c) = error "Reading from ByteString, insufficient left"
| (a,bs) <- unsafeBinarySplit bs, (b,bs) <- unsafeBinarySplit bs, (c,bs) <- unsafeBinarySplit bs = (a,b,c,bs)


unsafeBinarySplit :: Storable a => BS.ByteString -> (a, BS.ByteString)
{-# INLINABLE unsafeBinarySplit #-}
unsafeBinarySplit bs = (v, BS.unsafeDrop (sizeOf v) bs)
where v = unsafePerformIO $ BS.unsafeUseAsCString bs $ \ptr -> peek (castPtr ptr)

Expand Down Expand Up @@ -173,20 +177,24 @@ instance BinaryEx Float where


putExStorable :: forall a . Storable a => a -> Builder
{-# INLINABLE putExStorable #-}
putExStorable x = Builder (sizeOf x) $ \p i -> pokeByteOff p i x

getExStorable :: forall a . Storable a => BS.ByteString -> a
{-# INLINABLE getExStorable #-}
getExStorable = \bs -> unsafePerformIO $ BS.unsafeUseAsCStringLen bs $ \(p, size) ->
if size /= n then error "size mismatch" else peek (castPtr p)
where n = sizeOf (undefined :: a)


putExStorableList :: forall a . Storable a => [a] -> Builder
{-# INLINABLE putExStorableList #-}
putExStorableList xs = Builder (n * length xs) $ \ptr i ->
for2M_ [i,i+n..] xs $ \i x -> pokeByteOff ptr i x
where n = sizeOf (undefined :: a)

getExStorableList :: forall a . Storable a => BS.ByteString -> [a]
{-# INLINABLE getExStorableList #-}
getExStorableList = \bs -> unsafePerformIO $ BS.unsafeUseAsCStringLen bs $ \(p, size) ->
let (d,m) = size `divMod` n in
if m /= 0 then error "size mismatch" else forM [0..d-1] $ \i -> peekElemOff (castPtr p) i
Expand Down
4 changes: 4 additions & 0 deletions src/General/Fence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ newtype Fence m a = Fence (IORef (Either (a -> m ()) a))
instance Show (Fence m a) where show _ = "Fence"

newFence :: MonadIO m => IO (Fence m a)
{-# SPECIALISE newFence :: IO (Fence IO a) #-}
newFence = Fence <$> newIORef (Left $ const $ pure ())

signalFence :: (Partial, MonadIO m) => Fence m a -> a -> m ()
{-# SPECIALISE signalFence :: Partial => Fence IO a -> a -> IO () #-}
signalFence (Fence ref) v = join $ liftIO $ atomicModifyIORef' ref $ \case
Left queue -> (Right v, queue v)
Right _ -> throwImpure $ errorInternal "signalFence called twice on one Fence"

waitFence :: MonadIO m => Fence m a -> (a -> m ()) -> m ()
{-# SPECIALISE waitFence :: Fence IO a -> (a -> IO ()) -> IO () #-}
waitFence (Fence ref) call = join $ liftIO $ atomicModifyIORef' ref $ \case
Left queue -> (Left (\a -> queue a >> call a), pure ())
Right v -> (Right v, call v)
Expand All @@ -42,6 +45,7 @@ testFence (Fence x) = eitherToMaybe <$> readIORef x
-- FENCE COMPOSITES

exceptFence :: MonadIO m => [Fence m (Either e r)] -> m (Fence m (Either e [r]))
{-# SPECIALISE exceptFence :: [Fence IO (Either e r)] -> IO (Fence IO (Either e [r])) #-}
exceptFence xs = do
-- number of items still to complete, becomes negative after it has triggered
todo <- liftIO $ newIORef $ length xs
Expand Down
15 changes: 13 additions & 2 deletions src/General/Wait.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}

-- | A bit like 'Fence', but not thread safe and optimised for avoiding taking the fence
module General.Wait(
Expand All @@ -18,10 +17,12 @@ import Prelude


runWait :: Monad m => Wait m a -> m (Wait m a)
{-# INLINABLE runWait #-}
runWait (Lift x) = runWait =<< x
runWait x = pure x

fromLater :: Monad m => Wait m a -> (a -> m ()) -> m ()
{-# INLINABLE fromLater #-}
fromLater (Lift x) f = do x <- x; fromLater x f
fromLater (Now x) f = f x
fromLater (Later x) f = x f
Expand All @@ -32,9 +33,15 @@ quickly = Lift . fmap Now
data Wait m a = Now a
| Lift (m (Wait m a))
| Later ((a -> m ()) -> m ())
deriving Functor

instance Functor m => Functor (Wait m) where
{-# INLINABLE fmap #-}
fmap f (Now x) = Now $ f x
fmap f (Lift x) = Lift $ fmap (fmap f) x
fmap f (Later x) = Later $ \c -> x $ \a -> c $ f a

instance (Monad m, Applicative m) => Applicative (Wait m) where
{-# INLINABLE (<*>) #-}
pure = Now
Now x <*> y = x <$> y
Lift x <*> y = Lift $ (<*> y) <$> x
Expand All @@ -44,6 +51,7 @@ instance (Monad m, Applicative m) => Applicative (Wait m) where
Later x <*> Later y = Later $ \c -> x $ \x -> y $ \y -> c $ x y

instance (Monad m, Applicative m) => Monad (Wait m) where
{-# INLINABLE (>>=) #-}
return = pure
(>>) = (*>)
Now x >>= f = f x
Expand All @@ -55,12 +63,14 @@ instance (Monad m, Applicative m) => Monad (Wait m) where
_ -> fromLater x c

instance (MonadIO m, Applicative m) => MonadIO (Wait m) where
{-# INLINABLE liftIO #-}
liftIO = Lift . liftIO . fmap Now

instance MonadFail m => MonadFail (Wait m) where
fail = Lift . Control.Monad.Fail.fail

firstJustWaitUnordered :: MonadIO m => (a -> Wait m (Maybe b)) -> [a] -> Wait m (Maybe b)
{-# INLINABLE firstJustWaitUnordered #-}
firstJustWaitUnordered f = go 0 [] . map f
where
-- keep a list of those things we might visit later, and ask for each we see in turn
Expand Down Expand Up @@ -88,6 +98,7 @@ firstJustWaitUnordered f = go 0 [] . map f


firstLeftWaitUnordered :: MonadIO m => (a -> Wait m (Either e b)) -> [a] -> Wait m (Either e [b])
{-# INLINABLE firstLeftWaitUnordered #-}
firstLeftWaitUnordered f xs = do
let n = length xs
mut <- liftIO $ newArray n undefined
Expand Down
Loading