Movatterモバイル変換


[0]ホーム

URL:


base-4.12.0.0: Basic libraries

Copyright(c) The University of Glasgow 2011
Licensesee libraries/base/LICENSE
Maintainercvs-ghc@haskell.org
Stabilityinternal
Portabilitynon-portable (GHC Extensions)
Safe HaskellTrustworthy
LanguageHaskell2010

GHC.Stack

Contents

Description

Access to GHC's call-stack simulation

Since: 4.5.0.0

Synopsis

Documentation

errorWithStackTrace ::String -> aSource#

Deprecated:error appends the call stack now

Like the functionerror, but appends a stack trace to the error message if one is available.

Since: 4.7.0.0

Profiling call stacks

currentCallStack ::IO [String]Source#

Returns a[String] representing the current call stack. This can be useful for debugging.

The implementation uses the call-stack simulation maintained by the profiler, so it only works if the program was compiled with-prof and contains suitable SCC annotations (e.g. by using-fprof-auto). Otherwise, the list returned is likely to be empty or uninformative.

Since: 4.5.0.0

whoCreated :: a ->IO [String]Source#

Get the stack trace attached to an object.

Since: 4.5.0.0

HasCallStack call stacks

dataCallStackSource#

CallStacks are a lightweight method of obtaining a partial call-stack at any point in the program.

A function can request its call-site with theHasCallStack constraint. For example, we can define

putStrLnWithCallStack :: HasCallStack => String -> IO ()

as a variant ofputStrLn that will get its call-site and print it, along with the string given as argument. We can access the call-stack insideputStrLnWithCallStack withcallStack.

putStrLnWithCallStack :: HasCallStack => String -> IO ()putStrLnWithCallStack msg = do  putStrLn msg  putStrLn (prettyCallStack callStack)

Thus, if we callputStrLnWithCallStack we will get a formatted call-stack alongside our string.

>>>putStrLnWithCallStack "hello"helloCallStack (from HasCallStack):  putStrLnWithCallStack, called at <interactive>:2:1 in interactive:Ghci1

GHC solvesHasCallStack constraints in three steps:

  1. If there is aCallStack in scope -- i.e. the enclosing function has aHasCallStack constraint -- GHC will append the new call-site to the existingCallStack.
  2. If there is noCallStack in scope -- e.g. in the GHCi session above -- and the enclosing definition does not have an explicit type signature, GHC will infer aHasCallStack constraint for the enclosing definition (subject to the monomorphism restriction).
  3. If there is noCallStack in scope and the enclosing definition has an explicit type signature, GHC will solve theHasCallStack constraint for the singletonCallStack containing just the current call-site.

CallStacks do not interact with the RTS and do not require compilation with-prof. On the other hand, as they are built up explicitly via theHasCallStack constraints, they will generally not contain as much information as the simulated call-stacks maintained by the RTS.

ACallStack is a[(String, SrcLoc)]. TheString is the name of function that was called, theSrcLoc is the call-site. The list is ordered with the most recently called function at the head.

NOTE: The intrepid user may notice thatHasCallStack is just an alias for an implicit parameter?callStack :: CallStack. This is an implementation detail andshould not be considered part of theCallStack API, we may decide to change the implementation in the future.

Since: 4.8.1.0

Instances
IsListCallStackSource#

Be aware that 'fromList . toList = id' only for unfrozenCallStacks, sincetoList removes frozenness information.

Since: 4.9.0.0

Instance details

Defined inGHC.Exts

Associated Types

typeItemCallStack ::TypeSource#

ShowCallStackSource#

Since: 4.9.0.0

Instance details

Defined inGHC.Show

typeItemCallStackSource# 
Instance details

Defined inGHC.Exts

typeHasCallStack = ?callStack ::CallStackSource#

Request a CallStack.

NOTE: The implicit parameter?callStack :: CallStack is an implementation detail andshould not be considered part of theCallStack API, we may decide to change the implementation in the future.

Since: 4.9.0.0

callStack ::HasCallStack =>CallStackSource#

Return the currentCallStack.

Does *not* include the call-site ofcallStack.

Since: 4.9.0.0

emptyCallStack ::CallStackSource#

The emptyCallStack.

Since: 4.9.0.0

freezeCallStack ::CallStack ->CallStackSource#

Freeze a call-stack, preventing any further call-sites from being appended.

pushCallStack callSite (freezeCallStack callStack) = freezeCallStack callStack

Since: 4.9.0.0

fromCallSiteList :: [([Char],SrcLoc)] ->CallStackSource#

Convert a list of call-sites to aCallStack.

Since: 4.9.0.0

getCallStack ::CallStack -> [([Char],SrcLoc)]Source#

Extract a list of call-sites from theCallStack.

The list is ordered by most recent call.

Since: 4.8.1.0

popCallStack ::CallStack ->CallStackSource#

Pop the most recent call-site off theCallStack.

This function, likepushCallStack, has no effect on a frozenCallStack.

Since: 4.9.0.0

prettyCallStack ::CallStack ->StringSource#

Pretty print aCallStack.

Since: 4.9.0.0

pushCallStack :: ([Char],SrcLoc) ->CallStack ->CallStackSource#

Push a call-site onto the stack.

This function has no effect on a frozenCallStack.

Since: 4.9.0.0

withFrozenCallStack ::HasCallStack => (HasCallStack => a) -> aSource#

Perform some computation without adding new entries to theCallStack.

Since: 4.9.0.0

Source locations

dataSrcLocSource#

A single location in the source code.

Since: 4.8.1.0

Constructors

SrcLoc 
Instances
EqSrcLocSource#

Since: 4.9.0.0

Instance details

Defined inGHC.Stack.Types

ShowSrcLocSource#

Since: 4.9.0.0

Instance details

Defined inGHC.Show

prettySrcLoc ::SrcLoc ->StringSource#

Pretty print aSrcLoc.

Since: 4.9.0.0

Internals

dataCostCentreStackSource#

A cost-centre stack from GHC's cost-center profiler.

dataCostCentreSource#

A cost-centre from GHC's cost-center profiler.

getCurrentCCS :: dummy ->IO (PtrCostCentreStack)Source#

Returns the currentCostCentreStack (value isnullPtr if the current program was not compiled with profiling support). Takes a dummy argument which can be used to avoid the call togetCurrentCCS being floated out by the simplifier, which would result in an uninformative stack (CAF).

getCCSOf :: a ->IO (PtrCostCentreStack)Source#

Get theCostCentreStack associated with the given value.

clearCCS ::IO a ->IO aSource#

Run a computation with an empty cost-center stack. For example, this is used by the interpreter to run an interpreted computation without the call stack showing that it was invoked from GHC.

ccsCC ::PtrCostCentreStack ->IO (PtrCostCentre)Source#

Get theCostCentre at the head of aCostCentreStack.

ccsParent ::PtrCostCentreStack ->IO (PtrCostCentreStack)Source#

Get the tail of aCostCentreStack.

ccLabel ::PtrCostCentre ->IOCStringSource#

Get the label of aCostCentre.

ccModule ::PtrCostCentre ->IOCStringSource#

Get the module of aCostCentre.

ccSrcSpan ::PtrCostCentre ->IOCStringSource#

Get the source span of aCostCentre.

ccsToStrings ::PtrCostCentreStack ->IO [String]Source#

Format aCostCentreStack as a list of lines.

renderStack :: [String] ->StringSource#

Produced byHaddock version 2.20.0


[8]ページ先頭

©2009-2025 Movatter.jp