GHC.Exts.Heap.Closures

ghc-heap-8.6.3: Functions for walking GHC's heap

Safe Haskell | None
Language | Haskell2010

GHC.Exts.Heap.Closures

Contents

- Closures
- Boxes

Synopsis

- type Closure = GenClosure Box
- data GenClosure b
  - = ConstrClosure {
    - info :: !StgInfoTable
    - ptrArgs :: ![b]
    - dataArgs :: ![Word]
    - pkg :: !String
    - modl :: !String
    - name :: !String
    }
  - | FunClosure {
    - info :: !StgInfoTable
    - ptrArgs :: ![b]
    - dataArgs :: ![Word]
    }
  - | ThunkClosure {
    - info :: !StgInfoTable
    - ptrArgs :: ![b]
    - dataArgs :: ![Word]
    }
  - | SelectorClosure {
    - info :: !StgInfoTable
    - selectee :: !b
    }
  - | PAPClosure {
    - info :: !StgInfoTable
    - arity :: !HalfWord
    - n_args :: !HalfWord
    - fun :: !b
    - payload :: ![b]
    }
  - | APClosure {
    - info :: !StgInfoTable
    - arity :: !HalfWord
    - n_args :: !HalfWord
    - fun :: !b
    - payload :: ![b]
    }
  - | APStackClosure {
    - info :: !StgInfoTable
    - fun :: !b
    - payload :: ![b]
    }
  - | IndClosure {
    - info :: !StgInfoTable
    - indirectee :: !b
    }
  - | BCOClosure {
    - info :: !StgInfoTable
    - instrs :: !b
    - literals :: !b
    - bcoptrs :: !b
    - arity :: !HalfWord
    - size :: !HalfWord
    - bitmap :: ![Word]
    }
  - | BlackholeClosure {
    - info :: !StgInfoTable
    - indirectee :: !b
    }
  - | ArrWordsClosure {
    - info :: !StgInfoTable
    - bytes :: !Word
    - arrWords :: ![Word]
    }
  - | MutArrClosure {
    - info :: !StgInfoTable
    - mccPtrs :: !Word
    - mccSize :: !Word
    - mccPayload :: ![b]
    }
  - | MVarClosure {
    - info :: !StgInfoTable
    - queueHead :: !b
    - queueTail :: !b
    - value :: !b
    }
  - | MutVarClosure {
    - info :: !StgInfoTable
    - var :: !b
    }
  - | BlockingQueueClosure {
    - info :: !StgInfoTable
    - link :: !b
    - blackHole :: !b
    - owner :: !b
    - queue :: !b
    }
  - | IntClosure {
    - ptipe :: PrimType
    - intVal :: !Int
    }
  - | WordClosure {
    - ptipe :: PrimType
    - wordVal :: !Word
    }
  - | Int64Closure {
    - ptipe :: PrimType
    - int64Val :: !Int64
    }
  - | Word64Closure {
    - ptipe :: PrimType
    - word64Val :: !Word64
    }
  - | AddrClosure {
    - ptipe :: PrimType
    - addrVal :: !Int
    }
  - | FloatClosure {
    - ptipe :: PrimType
    - floatVal :: !Float
    }
  - | DoubleClosure {
    - ptipe :: PrimType
    - doubleVal :: !Double
    }
  - | OtherClosure {
    - info :: !StgInfoTable
    - hvalues :: ![b]
    - rawWords :: ![Word]
    }
  - | UnsupportedClosure {
    - info :: !StgInfoTable
    }
- data PrimType
  - = PInt
  - | PWord
  - | PInt64
  - | PWord64
  - | PAddr
  - | PFloat
  - | PDouble
- allClosures :: GenClosure b -> [b]
- data Box = Box Any
- areBoxesEqual :: Box -> Box -> IO Bool
- asBox :: a -> Box

# Closures

type Closure = GenClosure Box #

data GenClosure b #

This is the representation of a Haskell value on the heap. It reflects http://hackage.haskell.org/trac/ghc/browser/includes/rts/storage/Closures.h

The data type is parametrized by the type to store references in. Usually this is a `Box` with the type synonym `Closure`.

All Heap objects have the same basic layout. A header containing a pointer to the info table and a payload with various fields. The `info` field below always refers to the info table pointed to by the header. The remaining fields are the payload.

See https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/HeapObjects for more information.

Constructors

ConstrClosure | A data constructor
Fields info :: !StgInfoTable ptrArgs :: ![b] Pointer arguments dataArgs :: ![Word] Non-pointer arguments pkg :: !String Package name modl :: !String Module name name :: !String Constructor name
FunClosure | A function
Fields info :: !StgInfoTable ptrArgs :: ![b] Pointer arguments dataArgs :: ![Word] Non-pointer arguments
ThunkClosure | A thunk, an expression not obviously in head normal form
Fields info :: !StgInfoTable ptrArgs :: ![b] Pointer arguments dataArgs :: ![Word] Non-pointer arguments
SelectorClosure | A thunk which performs a simple selection operation
Fields info :: !StgInfoTable selectee :: !b Pointer to the object being selected from
PAPClosure | An unsaturated function application
Fields info :: !StgInfoTable arity :: !HalfWord Arity of the partial application n_args :: !HalfWord Size of the payload in words fun :: !b Pointer to a `FunClosure` payload :: ![b] Sequence of already applied arguments
APClosure | A function application
Fields info :: !StgInfoTable arity :: !HalfWord Arity of the partial application n_args :: !HalfWord Size of the payload in words fun :: !b Pointer to a `FunClosure` payload :: ![b] Sequence of already applied arguments
APStackClosure | A suspended thunk evaluation
Fields info :: !StgInfoTable fun :: !b Pointer to a `FunClosure` payload :: ![b] Sequence of already applied arguments
IndClosure | A pointer to another closure, introduced when a thunk is updated to point at its value
Fields info :: !StgInfoTable indirectee :: !b Target closure
BCOClosure | A byte-code object (BCO) which can be interpreted by GHC's byte-code interpreter (e.g. as used by GHCi)
Fields info :: !StgInfoTable instrs :: !b A pointer to an ArrWords of instructions literals :: !b A pointer to an ArrWords of literals bcoptrs :: !b A pointer to an ArrWords of byte code objects arity :: !HalfWord Arity of the partial application size :: !HalfWord The size of this BCO in words bitmap :: ![Word] An StgLargeBitmap describing the pointerhood of its args/free vars
BlackholeClosure | A thunk under evaluation by another thread
Fields info :: !StgInfoTable indirectee :: !b Target closure
ArrWordsClosure | A `ByteArray#`
Fields info :: !StgInfoTable bytes :: !Word Size of array in bytes arrWords :: ![Word] Array payload
MutArrClosure | A `MutableByteArray#`
Fields info :: !StgInfoTable mccPtrs :: !Word Number of pointers mccSize :: !Word ?? Closures.h vs ClosureMacros.h mccPayload :: ![b] Array payload Card table ignored
MVarClosure | An `MVar#`, with a queue of thread state objects blocking on them
Fields info :: !StgInfoTable queueHead :: !b Pointer to head of queue queueTail :: !b Pointer to tail of queue value :: !b Pointer to closure
MutVarClosure | A `MutVar#`
Fields info :: !StgInfoTable var :: !b Pointer to closure
BlockingQueueClosure | An STM blocking queue.
Fields info :: !StgInfoTable link :: !b ?? Here so it looks like an IND blackHole :: !b The blackhole closure owner :: !b The owning thread state object queue :: !b ??
IntClosure | Primitive Int
Fields ptipe :: PrimType intVal :: !Int
WordClosure | Primitive Word
Fields ptipe :: PrimType wordVal :: !Word
Int64Closure | Primitive Int64
Fields ptipe :: PrimType int64Val :: !Int64
Word64Closure | Primitive Word64
Fields ptipe :: PrimType word64Val :: !Word64
AddrClosure | Primitive Addr
Fields ptipe :: PrimType addrVal :: !Int
FloatClosure | Primitive Float
Fields ptipe :: PrimType floatVal :: !Float
DoubleClosure | Primitive Double
Fields ptipe :: PrimType doubleVal :: !Double
OtherClosure | Another kind of closure
Fields info :: !StgInfoTable hvalues :: ![b] rawWords :: ![Word]
UnsupportedClosure |
Fields info :: !StgInfoTable

Instances

Show b => Show (GenClosure b) # |
Instance details Defined in GHC.Exts.Heap.Closures Methods showsPrec :: Int -> GenClosure b -> ShowS Source # show :: GenClosure b -> String Source # showList :: [GenClosure b] -> ShowS Source #

data PrimType #

Constructors

PInt |
PWord |
PInt64 |
PWord64 |
PAddr |
PFloat |
PDouble |

Instances

Eq PrimType # |
Instance details Defined in GHC.Exts.Heap.Closures Methods (==) :: PrimType -> PrimType -> Bool Source # (/=) :: PrimType -> PrimType -> Bool Source #
Show PrimType # |
Instance details Defined in GHC.Exts.Heap.Closures Methods showsPrec :: Int -> PrimType -> ShowS Source # show :: PrimType -> String Source # showList :: [PrimType] -> ShowS Source #

allClosures :: GenClosure b -> [b] #

For generic code, this function returns all referenced closures.

# Boxes

data Box #

An arbitrary 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 evaluate the argument.

Constructors

Box Any |

Instances

Show Box # |
Instance details Defined in GHC.Exts.Heap.Closures Methods showsPrec :: Int -> Box -> ShowS Source # show :: Box -> String Source # showList :: [Box] -> ShowS Source #

areBoxesEqual :: Box -> Box -> IO Bool #

Boxes can be compared, but this is not pure, as different heap objects can, after garbage collection, become the same object.

asBox :: a -> Box #

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