summaryrefslogtreecommitdiff
path: root/rts/TraverseHeap.c
diff options
context:
space:
mode:
authorAlexis King <lexi.lambda@gmail.com>2022-09-11 11:30:32 +0200
committerAlexis King <lexi.lambda@gmail.com>2022-09-11 11:30:32 +0200
commit04062510806e2a3ccf0ecdb71c704a8e1c548c53 (patch)
tree23fe7599fa11138695b127581e2f8904ddc9b6d9 /rts/TraverseHeap.c
parent9c4ea90c6b493eee6df1798c63a6031cc18ae6da (diff)
downloadhaskell-04062510806e2a3ccf0ecdb71c704a8e1c548c53.tar.gz
Add native delimited continuations to the RTS
This patch implements GHC proposal 313, "Delimited continuation primops", by adding native support for delimited continuations to the GHC RTS. All things considered, the patch is relatively small. It almost exclusively consists of changes to the RTS; the compiler itself is essentially unaffected. The primops come with fairly extensive Haddock documentation, and an overview of the implementation strategy is given in the Notes in rts/Continuation.c. This first stab at the implementation prioritizes simplicity over performance. Most notably, every continuation is always stored as a single, contiguous chunk of stack. If one of these chunks is particularly large, it can result in poor performance, as the current implementation does not attempt to cleverly squeeze a subset of the stack frames into the existing stack: it must fit all at once. If this proves to be a performance issue in practice, a cleverer strategy would be a worthwhile target for future improvements.
Diffstat (limited to 'rts/TraverseHeap.c')
-rw-r--r--rts/TraverseHeap.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/rts/TraverseHeap.c b/rts/TraverseHeap.c
index 60c88a278d..e40e380765 100644
--- a/rts/TraverseHeap.c
+++ b/rts/TraverseHeap.c
@@ -336,8 +336,8 @@ traversePushReturn(traverseState *ts, StgClosure *c, stackAccum acc, stackElemen
*
* Invariants:
*
- * - 'c' is not any of TSO, AP, PAP, AP_STACK, which means that there cannot
- * be any stack objects.
+ * - 'c' is not any of TSO, AP, PAP, AP_STACK, or CONTINUATION, which means
+ * that there cannot be any stack objects.
*
* Note: SRTs are considered to be children as well.
*/
@@ -517,6 +517,7 @@ traverseGetChildren(StgClosure *c, StgClosure **first_child, bool *other_childre
case PAP:
case AP:
case AP_STACK:
+ case CONTINUATION:
case TSO:
case STACK:
case IND_STATIC:
@@ -818,6 +819,7 @@ traversePop(traverseState *ts, StgClosure **c, StgClosure **cp, stackData *data,
case PAP:
case AP:
case AP_STACK:
+ case CONTINUATION:
case TSO:
case STACK:
case IND_STATIC:
@@ -1288,6 +1290,14 @@ inner_loop:
(StgPtr)((StgAP_STACK *)c)->payload +
((StgAP_STACK *)c)->size);
goto loop;
+
+ case CONTINUATION:
+ {
+ StgContinuation *cont = (StgContinuation *)c;
+ traversePushStack(ts, c, sep, child_data,
+ cont->stack, cont->stack + cont->stack_size);
+ goto loop;
+ }
}
stackElement se;