summaryrefslogtreecommitdiff
path: root/compiler/GHC/Utils
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2023-01-11 22:42:13 -0500
committerBen Gamari <ben@smart-cactus.org>2023-01-16 12:01:29 -0500
commit4e17ebb1872f1b0ec7868abe0e92c11b9effd910 (patch)
tree6ab656415f1bdb0d00b51c8e1774232bebb45b41 /compiler/GHC/Utils
parentb3be0d185b6e597fa517859430cf6d54df04ca46 (diff)
downloadhaskell-wip/T22739.tar.gz
compiler: Small optimisation of assertMwip/T22739
In #22739 @AndreasK noticed that assertM performed the action to compute the asserted predicate regardless of whether DEBUG is enabled. This is inconsistent with the other assertion operations and general convention. Fix this. Closes #22739.
Diffstat (limited to 'compiler/GHC/Utils')
-rw-r--r--compiler/GHC/Utils/Panic/Plain.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/GHC/Utils/Panic/Plain.hs b/compiler/GHC/Utils/Panic/Plain.hs
index 10b963bf5d..a12ddb4050 100644
--- a/compiler/GHC/Utils/Panic/Plain.hs
+++ b/compiler/GHC/Utils/Panic/Plain.hs
@@ -29,6 +29,8 @@ import GHC.Utils.Constants
import GHC.Utils.Exception as Exception
import GHC.Stack
import GHC.Prelude.Basic
+
+import Control.Monad (when)
import System.IO.Unsafe
-- | This type is very similar to 'GHC.Utils.Panic.GhcException', but it omits
@@ -150,4 +152,8 @@ massert cond = withFrozenCallStack (assert cond (pure ()))
assertM :: (HasCallStack, Monad m) => m Bool -> m ()
{-# INLINE assertM #-}
-assertM mcond = withFrozenCallStack (mcond >>= massert)
+assertM mcond
+ | debugIsOn = withFrozenCallStack $ do
+ res <- mcond
+ when (not res) assertPanic'
+ | otherwise = return ()