Skip to content

Commit

Permalink
Clearer description of unsafe functions
Browse files Browse the repository at this point in the history
Fixes #180.
  • Loading branch information
arybczak committed Sep 10, 2023
1 parent 8b1b4a8 commit a2da29e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions effectful-core/src/Effectful/Dispatch/Static/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
-- sufficient.
--
-- /Warning:/ playing the so called "type tetris" with functions from this
-- module is not enough. Their misuse might lead to memory corruption or
-- segmentation faults, so make sure you understand what you're doing.
-- module is not enough. Their misuse might lead to data races or internal
-- consistency check failures, so make sure you understand what you're doing.
module Effectful.Dispatch.Static.Primitive
( -- * The environment
Env
Expand Down
22 changes: 14 additions & 8 deletions effectful-core/src/Effectful/Dispatch/Static/Unsafe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Effectful.Internal.Monad
--
-- @'Eff' es a -> 'Eff' es b@
--
-- This function is __highly unsafe__ because:
-- This function is __really unsafe__ because:
--
-- - It can be used to introduce arbitrary 'IO' actions into pure 'Eff'
-- computations.
Expand All @@ -23,15 +23,18 @@ import Effectful.Internal.Monad
-- sequential to the outside observer, e.g. in the same thread or in a worker
-- thread that finishes before the argument is run again.
--
-- __Warning:__ if you disregard the second point, the following might happen:
-- data races, internal consistency check failures or (in extreme cases)
-- segmentation faults.
-- __Warning:__ if you disregard the second point, you will experience weird
-- bugs, data races or internal consistency check failures.
--
-- When in doubt, use 'Effectful.Dispatch.Static.unsafeLiftMapIO', especially
-- since this version saves only one pointer comparison per call of
-- @reallyUnsafeLiftMapIO f@.
reallyUnsafeLiftMapIO :: (IO a -> IO b) -> Eff es a -> Eff es b
reallyUnsafeLiftMapIO f m = unsafeEff $ \es -> f (unEff m es)

-- | Create an unlifting function.
--
-- This function is __highly unsafe__ because:
-- This function is __really unsafe__ because:
--
-- - It can be used to introduce arbitrary 'IO' actions into pure 'Eff'
-- computations.
Expand All @@ -41,8 +44,11 @@ reallyUnsafeLiftMapIO f m = unsafeEff $ \es -> f (unEff m es)
-- of 'reallyUnsafeUnliftIO' or in a worker thread that finishes before
-- another unlifted computation is run.
--
-- __Warning:__ if you disregard the second point, the following might happen:
-- data races, internal consistency check failures or (in extreme cases)
-- segmentation faults.
-- __Warning:__ if you disregard the second point, you will experience weird
-- bugs, data races or internal consistency check failures.
--
-- When in doubt, use 'Effectful.Dispatch.Static.unsafeSeqUnliftIO', especially
-- since this version saves only one pointer comparison per call of the
-- unlifting function.
reallyUnsafeUnliftIO :: ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
reallyUnsafeUnliftIO k = unsafeEff $ \es -> k (`unEff` es)

0 comments on commit a2da29e

Please sign in to comment.