summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2023-01-11 22:42:13 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-01-17 06:36:06 -0500
commitdbbab95debd4405acdfaceee2be547fd69d9bb6f (patch)
treeb8e6083972b9371a47ee23fa19d3de22ebdf9370 /compiler
parent97ac8230b0a645aae27b7ee42aa55b0c84735684 (diff)
downloadhaskell-dbbab95debd4405acdfaceee2be547fd69d9bb6f.tar.gz
compiler: Small optimisation of assertM
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')
-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 ()