[Git][ghc/ghc][master] compiler: Small optimisation of assertM

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Jan 17 11:36:26 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
dbbab95d by Ben Gamari at 2023-01-17T06:36:06-05:00
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.

- - - - -


1 changed file:

- compiler/GHC/Utils/Panic/Plain.hs


Changes:

=====================================
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 ()



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dbbab95debd4405acdfaceee2be547fd69d9bb6f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dbbab95debd4405acdfaceee2be547fd69d9bb6f
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230117/a9ac61d7/attachment-0001.html>


More information about the ghc-commits mailing list