[Git][ghc/ghc][wip/andreask/callstack-prelude] Make use of DebugCallStack for plain panic.

Andreas Klebinger gitlab at gitlab.haskell.org
Tue May 26 11:16:56 UTC 2020



Andreas Klebinger pushed to branch wip/andreask/callstack-prelude at Glasgow Haskell Compiler / GHC


Commits:
f9ceab26 by Andreas Klebinger at 2020-05-26T13:16:01+02:00
Make use of DebugCallStack for plain panic.

Also move HasDebugCallStack into GHC.Prelude.

This allows it to be used without indirectly depending on
the Outputable module.

- - - - -


3 changed files:

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


Changes:

=====================================
compiler/GHC/Prelude.hs
=====================================
@@ -1,5 +1,6 @@
 {-# LANGUAGE CPP #-}
-
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE ConstraintKinds #-}
 -- | Custom GHC "Prelude"
 --
 -- This module serves as a replacement for the "Prelude" module
@@ -10,7 +11,7 @@
 --   * Is compiled with -XNoImplicitPrelude
 --   * Explicitly imports GHC.Prelude
 
-module GHC.Prelude (module X) where
+module GHC.Prelude (module X, HasDebugCallStack) where
 
 -- We export the 'Semigroup' class but w/o the (<>) operator to avoid
 -- clashing with the (Outputable.<>) operator which is heavily used
@@ -19,6 +20,19 @@ module GHC.Prelude (module X) where
 import Prelude as X hiding ((<>))
 import Data.Foldable as X (foldl')
 
+import GHC.Exts (Constraint)
+#if defined(DEBUG)
+import GHC.Stack (HasCallStack)
+#endif
+-- We define
+
+-- | A call stack constraint, but only when 'isDebugOn'.
+#if defined(DEBUG)
+type HasDebugCallStack = HasCallStack
+#else
+type HasDebugCallStack = (() :: Constraint)
+#endif
+
 {-
 Note [Why do we import Prelude here?]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


=====================================
compiler/GHC/Utils/Misc.hs
=====================================
@@ -1440,13 +1440,6 @@ mulHi a b = fromIntegral (r `shiftR` 32)
    where r :: Int64
          r = fromIntegral a * fromIntegral b
 
--- | A call stack constraint, but only when 'isDebugOn'.
-#if defined(DEBUG)
-type HasDebugCallStack = HasCallStack
-#else
-type HasDebugCallStack = (() :: Constraint)
-#endif
-
 data OverridingBool
   = Auto
   | Always


=====================================
compiler/GHC/Utils/Panic/Plain.hs
=====================================
@@ -111,15 +111,15 @@ throwPlainGhcException :: PlainGhcException -> a
 throwPlainGhcException = Exception.throw
 
 -- | Panics and asserts.
-panic, sorry, pgmError :: String -> a
+panic, sorry, pgmError :: CallStack => String -> a
 panic    x = unsafeDupablePerformIO $ do
    stack <- ccsToStrings =<< getCurrentCCS x
    if null stack
-      then throwPlainGhcException (PlainPanic x)
-      else throwPlainGhcException (PlainPanic (x ++ '\n' : renderStack stack))
+      then throwPlainGhcException (PlainPanic ((prettyCallStack callStack) ++ "\n" ++ x))
+      else throwPlainGhcException (PlainPanic ((prettyCallStack callStack) ++ "\n" ++ x ++ '\n' : renderStack stack))
 
-sorry    x = throwPlainGhcException (PlainSorry x)
-pgmError x = throwPlainGhcException (PlainProgramError x)
+sorry    x = throwPlainGhcException (PlainSorry $ (prettyCallStack callStack) ++ "\n" ++ x)
+pgmError x = throwPlainGhcException (PlainProgramError $ (prettyCallStack callStack) ++ "\n" ++x)
 
 cmdLineError :: String -> a
 cmdLineError = unsafeDupablePerformIO . cmdLineErrorIO
@@ -132,7 +132,7 @@ cmdLineErrorIO x = do
     else throwPlainGhcException (PlainCmdLineError (x ++ '\n' : renderStack stack))
 
 -- | Throw a failed assertion exception for a given filename and line number.
-assertPanic :: String -> Int -> a
+assertPanic :: CallStack => String -> Int -> a
 assertPanic file line =
   Exception.throw (Exception.AssertionFailed
-           ("ASSERT failed! file " ++ file ++ ", line " ++ show line))
+           ((prettyCallStack callStack) ++ "\nASSERT failed! file " ++ file ++ ", line " ++ show line))



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f9ceab26b4c3fc754ed7ea3209de31a050eeaf3c
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/20200526/2a28d774/attachment-0001.html>


More information about the ghc-commits mailing list