ghc-lib-parser-9.12.2.20250421: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Runtime.Heap.Layout

Contents

- Words and bytes
- Closure representation
  - Construction
  - Predicates
  - Size-related things
  - RTS closure types
  - Arrays

Synopsis

- type WordOff = Int
- type ByteOff = Int
- wordsToBytes :: Num a => Platform -> a -> a
- bytesToWordsRoundUp :: Platform -> ByteOff -> WordOff
- roundUpToWords :: Platform -> ByteOff -> ByteOff
- roundUpTo :: ByteOff -> ByteOff -> ByteOff
- data StgWord
- fromStgWord :: StgWord -> Integer
- toStgWord :: Platform -> Integer -> StgWord
- data StgHalfWord
- fromStgHalfWord :: StgHalfWord -> Integer
- toStgHalfWord :: Platform -> Integer -> StgHalfWord
- halfWordSize :: Platform -> ByteOff
- halfWordSizeInBits :: Platform -> Int
- data SMRep
  - = HeapRep IsStatic !WordOff !WordOff ClosureTypeInfo
  - | ArrayPtrsRep !WordOff !WordOff
  - | SmallArrayPtrsRep !WordOff
  - | ArrayWordsRep !WordOff
  - | StackRep Liveness
  - | RTSRep Int SMRep
- type IsStatic = Bool
- data ClosureTypeInfo
  - = Constr ConTagZ ConstrDescription
  - | Fun FunArity ArgDescr
  - | Thunk
  - | ThunkSelector SelectorOffset
  - | BlackHole
  - | IndStatic
- data ArgDescr
  - = ArgSpec !Int
  - | ArgGen Liveness
  - | ArgUnknown
- type Liveness = [Bool]
- type ConstrDescription = ByteString
- mkHeapRep :: Profile -> IsStatic -> WordOff -> WordOff -> ClosureTypeInfo -> SMRep
- blackHoleRep :: SMRep
- indStaticRep :: SMRep
- mkStackRep :: [Bool] -> SMRep
- mkRTSRep :: Int -> SMRep -> SMRep
- arrPtrsRep :: Platform -> WordOff -> SMRep
- smallArrPtrsRep :: WordOff -> SMRep
- arrWordsRep :: Platform -> ByteOff -> SMRep
- isStaticRep :: SMRep -> IsStatic
- isConRep :: SMRep -> Bool
- isThunkRep :: SMRep -> Bool
- isFunRep :: SMRep -> Bool
- isStaticNoCafCon :: SMRep -> Bool
- isStackRep :: SMRep -> Bool
- heapClosureSizeW :: Profile -> SMRep -> WordOff
- fixedHdrSizeW :: Profile -> WordOff
- arrWordsHdrSize :: Profile -> ByteOff
- arrWordsHdrSizeW :: Profile -> WordOff
- arrPtrsHdrSize :: Profile -> ByteOff
- arrPtrsHdrSizeW :: Profile -> WordOff
- profHdrSize :: Profile -> WordOff
- thunkHdrSize :: Profile -> WordOff
- nonHdrSize :: Platform -> SMRep -> ByteOff
- nonHdrSizeW :: SMRep -> WordOff
- smallArrPtrsHdrSize :: Profile -> ByteOff
- smallArrPtrsHdrSizeW :: Profile -> WordOff
- hdrSize :: Profile -> SMRep -> ByteOff
- hdrSizeW :: Profile -> SMRep -> WordOff
- fixedHdrSize :: Profile -> ByteOff
- rtsClosureType :: SMRep -> Int
- rET_SMALL :: Int
- rET_BIG :: Int
- aRG_GEN :: Int
- aRG_GEN_BIG :: Int
- card :: Platform -> Int -> Int
- cardRoundUp :: Platform -> Int -> Int
- cardTableSizeB :: Platform -> Int -> ByteOff
- cardTableSizeW :: Platform -> Int -> WordOff

# Words and bytes

type WordOff = Int Source #

Word offset, or word count

type ByteOff = Int Source #

Byte offset, or byte count

wordsToBytes :: Num a => Platform -> a -> a Source #

Convert the given number of words to a number of bytes.

This function morally has type `WordOff -> ByteOff`, but uses `Num a` to allow for overloading.

bytesToWordsRoundUp :: Platform -> ByteOff -> WordOff Source #

First round the given byte count up to a multiple of the machine's word size and then convert the result to words.

roundUpToWords :: Platform -> ByteOff -> ByteOff Source #

Round up the given byte count to the next byte count that's a multiple of the machine's word size.

roundUpTo :: ByteOff -> ByteOff -> ByteOff Source #

Round up `base` to a multiple of `size`.

data StgWord Source #

#### Instances

Instances details

Bits StgWord Source # |

Instance details

Defined in GHC.Runtime.Heap.Layout

Methods

(.&.) :: StgWord -> StgWord -> StgWord Source #

(.|.) :: StgWord -> StgWord -> StgWord Source #

xor :: StgWord -> StgWord -> StgWord Source #

complement :: StgWord -> StgWord Source #

shift :: StgWord -> Int -> StgWord Source #

rotate :: StgWord -> Int -> StgWord Source #

zeroBits :: StgWord Source #

bit :: Int -> StgWord Source #

setBit :: StgWord -> Int -> StgWord Source #

clearBit :: StgWord -> Int -> StgWord Source #

complementBit :: StgWord -> Int -> StgWord Source #

testBit :: StgWord -> Int -> Bool Source #

bitSizeMaybe :: StgWord -> Maybe Int Source #

bitSize :: StgWord -> Int Source #

isSigned :: StgWord -> Bool Source #

shiftL :: StgWord -> Int -> StgWord Source #

unsafeShiftL :: StgWord -> Int -> StgWord Source #

shiftR :: StgWord -> Int -> StgWord Source #

unsafeShiftR :: StgWord -> Int -> StgWord Source #

rotateL :: StgWord -> Int -> StgWord Source #

rotateR :: StgWord -> Int -> StgWord Source #

popCount :: StgWord -> Int Source #

Outputable StgWord Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods ppr :: StgWord -> SDoc Source #
Eq StgWord Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods (==) :: StgWord -> StgWord -> Bool Source # (/=) :: StgWord -> StgWord -> Bool Source #

fromStgWord :: StgWord -> Integer Source #

toStgWord :: Platform -> Integer -> StgWord Source #

data StgHalfWord Source #

#### Instances

Instances details

Outputable StgHalfWord Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods ppr :: StgHalfWord -> SDoc Source #
Eq StgHalfWord Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods (==) :: StgHalfWord -> StgHalfWord -> Bool Source # (/=) :: StgHalfWord -> StgHalfWord -> Bool Source #

fromStgHalfWord :: StgHalfWord -> Integer Source #

toStgHalfWord :: Platform -> Integer -> StgHalfWord Source #

halfWordSize :: Platform -> ByteOff Source #

Half word size in bytes

halfWordSizeInBits :: Platform -> Int Source #

# Closure representation

data SMRep Source #

A description of the layout of a closure. Corresponds directly to the closure types in includes/rts/storage/ClosureTypes.h.

Constructors

HeapRep IsStatic !WordOff !WordOff ClosureTypeInfo |
ArrayPtrsRep !WordOff !WordOff |
SmallArrayPtrsRep !WordOff |
ArrayWordsRep !WordOff |
StackRep Liveness |
RTSRep Int SMRep |

#### Instances

Instances details

Outputable SMRep Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods ppr :: SMRep -> SDoc Source #
Eq SMRep Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods (==) :: SMRep -> SMRep -> Bool Source # (/=) :: SMRep -> SMRep -> Bool Source #
Ord SMRep Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods compare :: SMRep -> SMRep -> Ordering Source # (<) :: SMRep -> SMRep -> Bool Source # (<=) :: SMRep -> SMRep -> Bool Source # (>) :: SMRep -> SMRep -> Bool Source # (>=) :: SMRep -> SMRep -> Bool Source # max :: SMRep -> SMRep -> SMRep Source # min :: SMRep -> SMRep -> SMRep Source #

type IsStatic = Bool Source #

True <=> This is a static closure. Affects how we garbage-collect it. Static closure have an extra static link field at the end. Constructors do not have a static variant; see Note [static constructors]

data ClosureTypeInfo Source #

Constructors

Constr ConTagZ ConstrDescription |
Fun FunArity ArgDescr |
Thunk |
ThunkSelector SelectorOffset |
BlackHole |
IndStatic |

#### Instances

Instances details

Outputable ClosureTypeInfo Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods ppr :: ClosureTypeInfo -> SDoc Source #
Eq ClosureTypeInfo Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods (==) :: ClosureTypeInfo -> ClosureTypeInfo -> Bool Source # (/=) :: ClosureTypeInfo -> ClosureTypeInfo -> Bool Source #
Ord ClosureTypeInfo Source # |

Instance details

Defined in GHC.Runtime.Heap.Layout

Methods

compare :: ClosureTypeInfo -> ClosureTypeInfo -> Ordering Source #

(<) :: ClosureTypeInfo -> ClosureTypeInfo -> Bool Source #

(<=) :: ClosureTypeInfo -> ClosureTypeInfo -> Bool Source #

(>) :: ClosureTypeInfo -> ClosureTypeInfo -> Bool Source #

(>=) :: ClosureTypeInfo -> ClosureTypeInfo -> Bool Source #

max :: ClosureTypeInfo -> ClosureTypeInfo -> ClosureTypeInfo Source #

min :: ClosureTypeInfo -> ClosureTypeInfo -> ClosureTypeInfo Source #

data ArgDescr Source #

An ArgDescr describes the argument pattern of a function

Constructors

ArgSpec !Int |
ArgGen Liveness |
ArgUnknown |

#### Instances

Instances details

Outputable ArgDescr Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods ppr :: ArgDescr -> SDoc Source #
Eq ArgDescr Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods (==) :: ArgDescr -> ArgDescr -> Bool Source # (/=) :: ArgDescr -> ArgDescr -> Bool Source #
Ord ArgDescr Source # |
Instance details Defined in GHC.Runtime.Heap.Layout Methods compare :: ArgDescr -> ArgDescr -> Ordering Source # (<) :: ArgDescr -> ArgDescr -> Bool Source # (<=) :: ArgDescr -> ArgDescr -> Bool Source # (>) :: ArgDescr -> ArgDescr -> Bool Source # (>=) :: ArgDescr -> ArgDescr -> Bool Source # max :: ArgDescr -> ArgDescr -> ArgDescr Source # min :: ArgDescr -> ArgDescr -> ArgDescr Source #

type Liveness = [Bool] Source #

We represent liveness bitmaps as a Bitmap (whose internal representation really is a bitmap). These are pinned onto case return vectors to indicate the state of the stack for the garbage collector.

In the compiled program, liveness bitmaps that fit inside a single word (StgWord) are stored as a single word, while larger bitmaps are stored as a pointer to an array of words.

type ConstrDescription = ByteString Source #

## Construction

mkHeapRep :: Profile -> IsStatic -> WordOff -> WordOff -> ClosureTypeInfo -> SMRep Source #

blackHoleRep :: SMRep Source #

indStaticRep :: SMRep Source #

mkStackRep :: [Bool] -> SMRep Source #

mkRTSRep :: Int -> SMRep -> SMRep Source #

arrPtrsRep :: Platform -> WordOff -> SMRep Source #

smallArrPtrsRep :: WordOff -> SMRep Source #

arrWordsRep :: Platform -> ByteOff -> SMRep Source #

## Predicates

isStaticRep :: SMRep -> IsStatic Source #

isConRep :: SMRep -> Bool Source #

isThunkRep :: SMRep -> Bool Source #

isFunRep :: SMRep -> Bool Source #

isStaticNoCafCon :: SMRep -> Bool Source #

isStackRep :: SMRep -> Bool Source #

## Size-related things

heapClosureSizeW :: Profile -> SMRep -> WordOff Source #

The total size of the closure, in words.

fixedHdrSizeW :: Profile -> WordOff Source #

Size of a closure header (StgHeader in includes/rts/storage/Closures.h)

arrWordsHdrSize :: Profile -> ByteOff Source #

arrWordsHdrSizeW :: Profile -> WordOff Source #

arrPtrsHdrSize :: Profile -> ByteOff Source #

arrPtrsHdrSizeW :: Profile -> WordOff Source #

profHdrSize :: Profile -> WordOff Source #

Size of the profiling part of a closure header (StgProfHeader in includes/rts/storage/Closures.h)

thunkHdrSize :: Profile -> WordOff Source #

nonHdrSize :: Platform -> SMRep -> ByteOff Source #

nonHdrSizeW :: SMRep -> WordOff Source #

smallArrPtrsHdrSize :: Profile -> ByteOff Source #

smallArrPtrsHdrSizeW :: Profile -> WordOff Source #

hdrSize :: Profile -> SMRep -> ByteOff Source #

hdrSizeW :: Profile -> SMRep -> WordOff Source #

fixedHdrSize :: Profile -> ByteOff Source #

## RTS closure types

rtsClosureType :: SMRep -> Int Source #

Derives the RTS closure type from an `SMRep`

rET_SMALL :: Int Source #

rET_BIG :: Int Source #

aRG_GEN :: Int Source #

aRG_GEN_BIG :: Int Source #

## Arrays

card :: Platform -> Int -> Int Source #

The byte offset into the card table of the card for a given element

cardRoundUp :: Platform -> Int -> Int Source #

Convert a number of elements to a number of cards, rounding up

cardTableSizeB :: Platform -> Int -> ByteOff Source #

The size of a card table, in bytes

cardTableSizeW :: Platform -> Int -> WordOff Source #

The size of a card table, in words