[commit: ghc] wip/nonmoving-gc: rts: Add Note explaining applicability of selector optimisation depth limit (b96cb9c)

git at git.haskell.org git at git.haskell.org
Wed Feb 6 14:09:31 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nonmoving-gc
Link       : http://ghc.haskell.org/trac/ghc/changeset/b96cb9c83a60add4b09dad388d8e1fd2081e2627/ghc

>---------------------------------------------------------------

commit b96cb9c83a60add4b09dad388d8e1fd2081e2627
Author: Ben Gamari <ben at well-typed.com>
Date:   Tue Jul 3 19:58:37 2018 -0400

    rts: Add Note explaining applicability of selector optimisation depth limit
    
    This was slightly non-obvious so a note seems deserved.


>---------------------------------------------------------------

b96cb9c83a60add4b09dad388d8e1fd2081e2627
 rts/sm/Evac.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/rts/sm/Evac.c b/rts/sm/Evac.c
index 2890319..45431fe 100644
--- a/rts/sm/Evac.c
+++ b/rts/sm/Evac.c
@@ -39,7 +39,19 @@
         copy_tag(p, info, src, size, stp, tag)
 #endif
 
-/* Used to avoid long recursion due to selector thunks
+/* Note [Selector optimisation depth limit]
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * MAX_THUNK_SELECTOR_DEPTH is used to avoid long recursion of
+ * eval_thunk_selector due to nested selector thunks. Note that this *only*
+ * counts nested selector thunks, e.g. `fst (fst (... (fst x)))`. The collector
+ * will traverse interleaved selector-constructor pairs without limit, e.g.
+ *
+ *     a = (fst b, _)
+ *     b = (fst c, _)
+ *     c = (fst d, _)
+ *     d = (x, _)
+ *
  */
 #define MAX_THUNK_SELECTOR_DEPTH 16
 
@@ -1252,6 +1264,7 @@ selector_loop:
 
           // recursively evaluate this selector.  We don't want to
           // recurse indefinitely, so we impose a depth bound.
+          // See Note [Selector optimisation depth limit].
           if (gct->thunk_selector_depth >= MAX_THUNK_SELECTOR_DEPTH) {
               goto bale_out;
           }



More information about the ghc-commits mailing list