Checker recursion depth: valid programs with ~10k-deep terms (e.g. a 10000n literal) fail with "machine stack overflowed"
Author: docxologyCreated Sep 18, 2026Updated Sep 18, 2026
What you did
# lit.bend
import Base
def main() -> Nat:
10000nbend lit.bend (same via the bun/node import hook).
What happened
Error: the machine stack overflowed (a deep recursion, or a literal too large to expand)5000nchecks and runs fine;10000n(and everything larger up to the advertisedNumber.MAX_SAFE_INTEGERbound) dies.- The same overflow hits valid non-literal programs: a single def body with ~4,000 sequential do-block statements fails the same way while the same program at 2,000 statements compiles (in 73s — see the separate quadratic-compile report).
So the practical term-depth budget of the checker is ~10k constructor nodes / call frames, well below any documented limit, and the MAX_SAFE_INTEGER guard in parse_term_num (bend.ts:2234) is decorative: nothing between ~10k and 9e15 can ever expand.
The failure itself is handled (caught RangeError with a decent message), so this is a robustness/usability issue, not a crash: valid programs fail with a message that doesn't say which literal or construct was too deep.
Expected
- Make the checker's recursion depth budget explicit and iterative where cheap (the Nat literal expansion loop itself is iterative; the overflow happens downstream in checking/normalization).
- At minimum, catch the overflow at the offending span and report "this literal/term is too large (limit ~N)".
Version / system
- bend 2.0.5 (main @ e6676b0)
- Darwin arm64
Source: HigherOrderCO/Bend