Skip to main content

Module recursion

Module recursion 

Source
Expand description

Stack-depth bounds for the crate’s recursive types.

big-code-analysis’s FuncSpace and Ops, and this crate’s AstNode, are trees whose nesting depth is caller-controlled: nested functions, nested closures, and nested expressions are ordinary legal constructs in every supported language. Issues #700 / #709 converted every AST traversal to an explicit work stack, but two implicit recursions survived on the types themselves — Serialize and the compiler-generated Drop glue. Overflowing the stack in either is not a catchable panic: the runtime aborts the process with SIGABRT, taking every in-flight bca-web request with it (#1056).

Drop is made iterative outright by [impl_iterative_drop]. Serialize cannot be: serde offers no way to emit a tree without one native frame per level, because serialize_field must run the child’s Serialize to completion before it returns. So it is bounded instead — [serialize_bounded] refuses to descend past a per-type limit and returns an ordinary serializer error, mirroring the 128-level recursion limit serde_json’s Deserializer already applies to the same shapes.

The third recursion #1056 covered is not here: projecting a compute tree onto its wire form. That one is de-recursed outright, by wire::map_tree, which lives next to the From impls it serves.