Skip to main content

Module stack

Module stack 

Source
Expand description

Stack-growth guard for deeply recursive work.

Recursive value walks (Display, value_to_json, pretty_print) and re-entrant native→VM calls consume the real OS thread stack per level. On a deep-but-finite structure — or a recursive Sema function that maps over its children — this overflows the fixed 8 MB main-thread stack and aborts the process with an uncatchable SIGABRT, before the VM’s frame guard can turn it into a catchable error. maybe_grow grows the stack on demand at those recursion points so the process survives to hit the guarded limit instead.

Functions§

maybe_grow
Run f, first extending the stack if it is near exhaustion. Cheap when there’s ample stack left (a bounds check), so it’s safe to call at every level of a recursion.