Note [GHCi unboxed tuples stack spills]
In the calling convention for compiled code, a tuple is returned
in registers, with everything that doesn't fit spilled onto the STG
stack.
At the time the continuation is called, Sp points to the highest word
used on the stack:
...
stg_ctoi_t (next stack frame, continuation)
spilled_1
spilled_2
spilled_3 <- Sp
This makes it difficult to write a procedure that can handle tuples of
any size.
To get around this, we use a Cmm procedure that adjusts the stack pointer
to skip over the tuple:
...
stg_ctoi_t3 (advances Sp by 3 words, then calls stg_ctoi_t)
spilled_1
spilled_2
spilled_3 <- Sp
When stg_ctoi_t is called, the stack looks like:
...
tuple_BCO
tuple_info
cont_BCO (continuation in bytecode)
stg_ctoi_t3 <- Sp
spilled_1
spilled_2
spilled_3
stg_ctoi_t then reads the tuple_info word to determine the registers
to save onto the stack and construct a call to tuple_BCO. Afterwards the
stack looks as follows:
...
tuple_BCO
tuple_info
cont_BCO
stg_ctoi_t3
spilled_1
spilled_2
spilled_3
saved_R2
saved_R1
saved_D3
...
tuple_BCO
stg_apply_interp <- Sp
tuple_BCO contains the bytecode instructions to return the tuple to
cont_BCO. The bitmap in tuple_BCO describes the contents of
the tuple to the storage manager.
At this point we can safely jump to the interpreter. References 0
This Note does not link to any other.
Referenced by 1
- unboxed tuple bytecodes and tuple_BCO GHC.StgToByteCode