|Version 2 (modified by simonmar, 10 years ago) (diff)|
[ Up: Commentary/Rts ]
GHC Commentary: The Layout of Heap Objects
- A lifted type is one that contains bottom (_|_), conversely an unlifted type does not contain _|_. For example, Array is lifted, but ByteArray# is unlifted.
- A boxed type is represented by a pointer to an object in the heap, an unboxed object is represented by a value. For example, Int is boxed, but Int# is unboxed.
The representation of _|_ must be a pointer: it is an object that when evaluated throws an exception or enters an infinite loop. Therefore, only boxed types may be lifted.
There are boxed unlifted types: eg. ByteArray#. If you have a value of type ByteArray#, it definitely points to a heap object with type ARR_WORDS (see below), rather than an unevaluated thunk.
Unboxed tuples (#...#) are both unlifted and unboxed. They are represented by multiple values passed in registers or on the stack, according to the return convention.
All heap objects have the same basic layout, embodied by the type StgClosure in Closures.h. The diagram below shows the layout of a heap object: