{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Trustworthy #-}
module GHC.Stack (
errorWithStackTrace,
currentCallStack,
whoCreated,
CallStack, HasCallStack, callStack, emptyCallStack, freezeCallStack,
fromCallSiteList, getCallStack, popCallStack, prettyCallStack,
pushCallStack, withFrozenCallStack,
SrcLoc(..), prettySrcLoc,
CostCentreStack,
CostCentre,
getCurrentCCS,
getCCSOf,
clearCCS,
ccsCC,
ccsParent,
ccLabel,
ccModule,
ccSrcSpan,
ccsToStrings,
renderStack
) where
import GHC.Stack.CCS
import GHC.Stack.Types
import GHC.IO
import GHC.Base
import GHC.List
import GHC.Exception
{-# DEPRECATED errorWithStackTrace "'error' appends the call stack now" #-}
errorWithStackTrace :: String -> a
errorWithStackTrace :: forall a. String -> a
errorWithStackTrace String
x = forall a. IO a -> a
unsafeDupablePerformIO forall a b. (a -> b) -> a -> b
$ do
[String]
stack <- Ptr CostCentreStack -> IO [String]
ccsToStrings forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall dummy. dummy -> IO (Ptr CostCentreStack)
getCurrentCCS String
x
if forall a. [a] -> Bool
null [String]
stack
then forall e a. Exception e => e -> IO a
throwIO (String -> ErrorCall
ErrorCall String
x)
else forall e a. Exception e => e -> IO a
throwIO (String -> String -> ErrorCall
ErrorCallWithLocation String
x ([String] -> String
renderStack [String]
stack))
popCallStack :: CallStack -> CallStack
popCallStack :: CallStack -> CallStack
popCallStack CallStack
stk = case CallStack
stk of
CallStack
EmptyCallStack -> forall a. String -> a
errorWithoutStackTrace String
"popCallStack: empty stack"
PushCallStack String
_ SrcLoc
_ CallStack
stk' -> CallStack
stk'
FreezeCallStack CallStack
_ -> CallStack
stk
{-# INLINE popCallStack #-}
callStack :: HasCallStack => CallStack
callStack :: HasCallStack => CallStack
callStack =
case HasCallStack
?callStack of
CallStack
EmptyCallStack -> CallStack
EmptyCallStack
CallStack
_ -> CallStack -> CallStack
popCallStack HasCallStack
?callStack
{-# INLINE callStack #-}
withFrozenCallStack :: HasCallStack
=> ( HasCallStack => a )
-> a
withFrozenCallStack :: forall a. HasCallStack => (HasCallStack => a) -> a
withFrozenCallStack HasCallStack => a
do_this =
let ?callStack = CallStack -> CallStack
freezeCallStack (CallStack -> CallStack
popCallStack HasCallStack => CallStack
callStack)
in HasCallStack => a
do_this