Repository navigation
Closed
Description
Parent: #934
Related: #936 (parser), #935 (flat chains), #932 (a compiler quadratic on the same shapes)
Confirmed by execution
Reproduced with the current test262 --eval binary; recursion from an lldb backtrace at the crash. In several rows the parser succeeds and the compiler is the first phase to overflow, so a parser-only guard would not prevent these.
| source | first crash | recursion |
|---|---|---|
destructuring catch nested in a function |
~7,390 deep | compileStmtList > compileStmt > compileTry > compileStmt > compileHoistedStmtList |
{ { … } } blocks, top level or in a function |
~14,773 deep | stmtListHasDisposableDecl <-> stmtHasDisposableDecl — the using-declaration pre-scan, which overflows before code generation starts |
a=a=… assignment chain |
15,000 | compileExpr > compileNamedExpr; parses fine |
x=>x=>… arrow chain |
10,000 | shadowAdd > functionBindingInventory > functionNeedsTdzChecks > compileFunction; parses fine |
!!!… unary chain |
30,000 | compileExpr > compileExpr; parses fine |
The destructuring-catch row fails at roughly half the depth the parser survives, so the compiler's per-level stack cost is the binding constraint for that shape.
Why this is broad
A mapping pass found 40 recursion chokepoints and no existing guard in compiler.zig. They fall into two groups:
- Code generation dispatchers:
compileStmt(3172),compileExpr(5155),compilePattern(4178),compileTailExpr(4552),compileOptionalValue(4924),compileFunction(6350). - Independent pre-scans, each re-walking full subtree depth before code generation reaches it:
stmtHasDisposableDecl/stmtListHasDisposableDecl(1517/1526),stmtContainsDisposableDeclDeep(1531),nodeHasYield(802),nameRefInClosure(1222),collectRepeatedBodyBindings(1136),shadowScanStmt(1871),tdzScanStmt(1983),collectFunctionLocals(6714),stmtCanEscapeAbruptly(1389), the pattern predicates (patternBindsName626,collectPatternBindingNames1066,patternHasEvaluationExpressions1102), and the environment-lexical pattern emitters (2650–2923).
Guarding only the dispatchers leaves the pre-scans: the blocks row above crashes in a pre-scan while compileStmt has plenty of headroom.
Design constraints
- Surface
RangeError: Maximum call stack size exceeded. It must not come back aserror.Unsupported: that silently falls back to the tree-walker, which then recurses over the same tree and crashes in evaluation instead (see the tree-walker issue). - Use
stack_scan.nearLimitwith a depth floor, asInterpreter.stackGuarddoes, so shallow code pays a single comparison. - Re-measure the Frontend: private-name use validation copies every inherited name per nested class #926 and Frontend: lexical/var early-error scan rebuilds the subtree var set at every nested block #928 frozen workloads and the Perf: nested destructuring catch parameters are quadratic inside function bodies #932 curve after adding guards, to show they cost nothing on normal code.
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix(parser): raise RangeError for source nested deeper than the stack
glennmichael123 commentedon Sep 17, 2026
Fixed in b895723
The bytecode compiler and its pre-scans now stop at the same stack floor as the parser (#936). A tree that parses but is too deep to compile raises
RangeError: Maximum call stack size exceeded.instead of segfaulting.Where the check goes
compileStmt,compileExpr,compilePattern,compileOptionalValue,compileTailExprand the environment-lexical walkers.nodeHasYield,nameRefInClosure, the disposable-declaration, TDZ and shadow scans, the binding collectors,collectFunctionLocals, the repeated-body and pattern predicates, andannex_b.collect.Surfacing: a RangeError, never a fallback
CompileErrorgainsStackExhausted. Admission passes it through rather than turning it into a rejection, which would fall back to the tree-walker.OutOfMemory; it now raises the RangeError.evalModule, and its throw never reached the context. A read-only review found this, and I reproduced it:import()of such a module rejected withSyntaxError: Cannot parse modulebefore the throw was surfaced. The same review found that nested generator/async compiles re-read the floor instead of inheriting it; that is fixed too.Results (binaries from the parent engine and from this change)
import()/ static import / self-declaring module with a too-deep generator body--vm-witness-subtree, 12 subtrees--diag, 18 subtreesThe shapes that crashed only when compiled were blocks, destructuring catch parameters, assignment chains, arrows, unary chains, if-chains, member chains, var patterns, conditionals and labels.
Pinned test. A new
test-runtimecase sweeps 7 shapes × 3 wrappers (generator body, nested plain function, loop body) to depth 128,000. Every depth must either work or throw the RangeError. For the four shapes the parser walks more cheaply than the compiler, the case binary-searches for the deepest source that parses inside an unexecuted block and requires that creating it throws. That check fails if exhaustion ever becomes a rejection again. It crashes the parent binary (exit 139).Left for #938. Tree-walker evaluation recursion, including
annexbListMayNeedScanat function creation, which the review traced to the path before admission.fix(interpreter): raise RangeError for trees deeper than the stack