From 6f60a1e30cc08387d6928b3a6f1956a68274d5a8 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 25 Jan 2022 23:25:52 +0100 Subject: [PATCH] Consistently call the unmasking function unmask instead of restore --- effectful-core/src/Effectful/Internal/Monad.hs | 12 ++++++------ effectful-core/src/Effectful/Writer/Static/Local.hs | 4 ++-- effectful-core/src/Effectful/Writer/Static/Shared.hs | 4 ++-- effectful/src/Effectful/Resource.hs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/effectful-core/src/Effectful/Internal/Monad.hs b/effectful-core/src/Effectful/Internal/Monad.hs index fb8c2bb..31a02ca 100644 --- a/effectful-core/src/Effectful/Internal/Monad.hs +++ b/effectful-core/src/Effectful/Internal/Monad.hs @@ -235,16 +235,16 @@ instance C.MonadCatch (Eff es) where unEff (handler e) es instance C.MonadMask (Eff es) where - mask k = unsafeEff $ \es -> E.mask $ \restore -> - unEff (k $ \m -> unsafeEff $ restore . unEff m) es + mask k = unsafeEff $ \es -> E.mask $ \unmask -> + unEff (k $ \m -> unsafeEff $ unmask . unEff m) es - uninterruptibleMask k = unsafeEff $ \es -> E.uninterruptibleMask $ \restore -> - unEff (k $ \m -> unsafeEff $ restore . unEff m) es + uninterruptibleMask k = unsafeEff $ \es -> E.uninterruptibleMask $ \unmask -> + unEff (k $ \m -> unsafeEff $ unmask . unEff m) es - generalBracket acquire release use = unsafeEff $ \es -> E.mask $ \restore -> do + generalBracket acquire release use = unsafeEff $ \es -> E.mask $ \unmask -> do size <- sizeEnv es resource <- unEff acquire es - b <- restore (unEff (use resource) es) `E.catch` \e -> do + b <- unmask (unEff (use resource) es) `E.catch` \e -> do checkSizeEnv size es _ <- unEff (release resource $ C.ExitCaseException e) es E.throwIO e diff --git a/effectful-core/src/Effectful/Writer/Static/Local.hs b/effectful-core/src/Effectful/Writer/Static/Local.hs index 7a11e32..f43345b 100644 --- a/effectful-core/src/Effectful/Writer/Static/Local.hs +++ b/effectful-core/src/Effectful/Writer/Static/Local.hs @@ -75,9 +75,9 @@ tell w = stateStaticRep $ \(Writer w0) -> ((), Writer (w0 <> w)) -- :} -- "Hi there!" listen :: (Writer w :> es, Monoid w) => Eff es a -> Eff es (a, w) -listen m = unsafeEff $ \es -> mask $ \restore -> do +listen m = unsafeEff $ \es -> mask $ \unmask -> do w0 <- stateEnv es $ \(Writer w) -> (w, Writer mempty) - a <- restore (unEff m es) `onException` merge es w0 + a <- unmask (unEff m es) `onException` merge es w0 (a, ) <$> merge es w0 where merge es w0 = diff --git a/effectful-core/src/Effectful/Writer/Static/Shared.hs b/effectful-core/src/Effectful/Writer/Static/Shared.hs index 737fc93..4916fec 100644 --- a/effectful-core/src/Effectful/Writer/Static/Shared.hs +++ b/effectful-core/src/Effectful/Writer/Static/Shared.hs @@ -83,11 +83,11 @@ listen m = unsafeEff $ \es -> do -- The mask is uninterruptible because modifyMVar_ v0 in the merge function -- might block and if an async exception is received while waiting, w1 will be -- lost. - uninterruptibleMask $ \restore -> do + uninterruptibleMask $ \unmask -> do v1 <- newMVar mempty -- Replace thread local MVar with a fresh one for isolated listening. v0 <- stateEnv es $ \(Writer v) -> (v, Writer v1) - a <- restore (unEff m es) `onException` merge es v0 v1 + a <- unmask (unEff m es) `onException` merge es v0 v1 (a, ) <$> merge es v0 v1 where -- Merge results accumulated in the local MVar with the mainline. If an diff --git a/effectful/src/Effectful/Resource.hs b/effectful/src/Effectful/Resource.hs index b95fec6..a2a53db 100644 --- a/effectful/src/Effectful/Resource.hs +++ b/effectful/src/Effectful/Resource.hs @@ -38,9 +38,9 @@ runResource :: IOE :> es => Eff (Resource : es) a -> Eff es a runResource m = unsafeEff $ \es0 -> do size0 <- sizeEnv es0 istate <- R.createInternalState - mask $ \restore -> do + mask $ \unmask -> do es <- unsafeConsEnv (Resource istate) dummyRelinker es0 - a <- restore (unEff m es) `catch` \e -> do + a <- unmask (unEff m es) `catch` \e -> do unsafeTailEnv size0 es RI.stateCleanupChecked (Just e) istate throwIO e