Skip to content

Commit

Permalink
Add a few INLINE pragmas to small unlifting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arybczak committed Sep 16, 2024
1 parent 0809257 commit 255b153
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions effectful-core/src/Effectful/Dispatch/Dynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ localSeqUnlift
localSeqUnlift (LocalEnv les) k = unsafeEff $ \es -> do
seqUnliftIO les $ \unlift -> do
(`unEff` es) $ k $ unsafeEff_ . unlift
{-# INLINE localSeqUnlift #-}

-- | Create a local unlifting function with the 'SeqUnlift' strategy. For the
-- general version see 'localUnliftIO'.
Expand All @@ -725,6 +726,7 @@ localSeqUnliftIO
-- ^ Continuation with the unlifting function in scope.
-> Eff es a
localSeqUnliftIO (LocalEnv les) k = liftIO $ seqUnliftIO les k
{-# INLINE localSeqUnliftIO #-}

-- | Create a local unlifting function with the given strategy.
localUnlift
Expand Down Expand Up @@ -781,6 +783,7 @@ localSeqLift !_ k = unsafeEff $ \es -> do
-- localEs type variable. It's also strict so that callers don't cheat.
seqUnliftIO es $ \unlift -> do
(`unEff` es) $ k $ unsafeEff_ . unlift
{-# INLINE localSeqLift #-}

-- | Create a local lifting function with the given strategy.
--
Expand Down Expand Up @@ -830,6 +833,7 @@ withLiftMap !_ k = unsafeEff $ \es -> do
(`unEff` es) $ k $ \mapEff m -> unsafeEff $ \localEs -> do
seqUnliftIO localEs $ \unlift -> do
(`unEff` es) . mapEff . unsafeEff_ $ unlift m
{-# INLINE withLiftMap #-}

-- | Utility for lifting 'IO' computations of type
--
Expand Down Expand Up @@ -868,6 +872,7 @@ withLiftMapIO !_ k = k $ \mapIO m -> unsafeEff $ \es -> do
-- The LocalEnv parameter is not used, but we need it to constraint the
-- localEs type variable. It's also strict so that callers don't cheat.
seqUnliftIO es $ \unlift -> mapIO $ unlift m
{-# INLINE withLiftMapIO #-}

----------------------------------------
-- Bidirectional lifts
Expand Down
8 changes: 5 additions & 3 deletions effectful-core/src/Effectful/Internal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ withSeqEffToIO
=> ((forall r. Eff es r -> IO r) -> IO a)
-- ^ Continuation with the unlifting function in scope.
-> Eff es a
withSeqEffToIO f = unsafeEff $ \es -> seqUnliftIO es f
withSeqEffToIO k = unsafeEff $ \es -> seqUnliftIO es k
{-# INLINE withSeqEffToIO #-}

-- | Create an unlifting function with the given strategy.
--
Expand Down Expand Up @@ -218,8 +219,8 @@ withConcEffToIO
-> ((forall r. Eff es r -> IO r) -> IO a)
-- ^ Continuation with the unlifting function in scope.
-> Eff es a
withConcEffToIO persistence limit f = unsafeEff $ \es ->
concUnliftIO es persistence limit f
withConcEffToIO persistence limit k = unsafeEff $ \es ->
concUnliftIO es persistence limit k
{-# DEPRECATED withConcEffToIO "Use withEffToIO with the appropriate strategy." #-}

-- | Create an unlifting function with the 'SeqUnlift' strategy.
Expand Down Expand Up @@ -249,6 +250,7 @@ seqForkUnliftIO
-- ^ Continuation with the unlifting function in scope.
-> IO a
seqForkUnliftIO es0 k = cloneEnv es0 >>= \es -> seqUnliftIO es k
{-# INLINE seqForkUnliftIO #-}

-- | Create an unlifting function with the 'ConcUnlift' strategy.
concUnliftIO
Expand Down

0 comments on commit 255b153

Please sign in to comment.