ghc-heap-view-0.3.0.4: Extract the heap representation of Haskell values and thunks

MaintainerJoachim Breitner <mail@joachim-breitner.de>
Safe HaskellNone

GHC.HeapView

Contents

Description

With this module, you can investigate the heap representation of Haskell values, i.e. to investigate sharing and lazy evaluation.

Synopsis

Heap data types

data Closure Source

This is the main data type of this module, representing a Haskell value on the heap. This reflects http://hackage.haskell.org/trac/ghc/browser/includes/rts/storage/Closures.h

Instances

allPtrs :: Closure -> [Box]Source

For generic code, this function returns all referenced closures.

data StgInfoTable Source

This is a somewhat faithful representation of an info table. See http://hackage.haskell.org/trac/ghc/browser/includes/rts/storage/InfoTables.h for more details on this data structure. Note that the Storable instance provided here does _not_ support writing.

Constructors

StgInfoTable 

Reading from the heap

getClosureData :: a -> IO ClosureSource

This function returns parsed heap representation of the argument _at this moment_, even if it is unevaluated or an indirection or other exotic stuff. Beware when passing something to this function, the same caveats as for asBox apply.

getBoxedClosureData :: Box -> IO ClosureSource

Like getClosureData, but taking a Box, so it is easier to work with.

getClosureRaw :: a -> IO (Ptr StgInfoTable, [Word], [Box])Source

This returns the raw representation of the given argument. The second component of the triple are the words on the heap, and the third component are those words that are actually pointers. Once back in Haskell word, the Word may be outdated after a garbage collector run, but the corresponding Box will still point to the correct value.

Boxes

data Box Source

An arbitrarily Haskell value in a safe Box. The point is that even unevaluated thunks can safely be moved around inside the Box, and when required, e.g. in getBoxedClosureData, the function knows how far it has to evalue the argument.

Constructors

Box Any 

Instances

asBox :: a -> BoxSource

This takes an arbitrary value and puts it into a box. Note that calls like

 asBox (head list) 

will put the thunk "head list" into the box, not the element at the head of the list. For that, use careful case expressions:

 case list of x:_ -> asBox x