{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE MagicHash, NoImplicitPrelude, ImplicitParams, RankNTypes #-}
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 x = unsafeDupablePerformIO $ do
stack <- ccsToStrings =<< getCurrentCCS x
if null stack
then throwIO (ErrorCall x)
else throwIO (ErrorCallWithLocation x (renderStack stack))
popCallStack :: CallStack -> CallStack
popCallStack stk = case stk of
EmptyCallStack -> errorWithoutStackTrace "popCallStack: empty stack"
PushCallStack _ _ stk' -> stk'
FreezeCallStack _ -> stk
{-# INLINE popCallStack #-}
callStack :: HasCallStack => CallStack
callStack =
case ?callStack of
EmptyCallStack -> EmptyCallStack
_ -> popCallStack ?callStack
{-# INLINE callStack #-}
withFrozenCallStack :: HasCallStack
=> ( HasCallStack => a )
-> a
withFrozenCallStack do_this =
let ?callStack = freezeCallStack (popCallStack callStack)
in do_this