You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS lane: a long do block emits JS that node cannot load (parser stack overflow from ~300 steps) #1086
bend t.bend -o t.js && node t.js, where t.bend is one do IO<Unit>: block of N sequential IO.print steps (generator below).
What happened
$ node t.js # N = 300
node:internal/modules/cjs/loader:1866
const result = compileFunctionForCJSLoader(content, filename, false /* is_sea_main */, shouldDetectModule);
^
RangeError: Maximum call stack size exceeded
at wrapSafe (node:internal/modules/cjs/loader:1866:18)
at Module._compile (node:internal/modules/cjs/loader:1908:20)
By N:
200: runs
250: runs, then bend: memory fault (machine stack overflow?)
300, 400: the RangeError above, raised while node loads the file, before any code runs
The native build (bend t.bend -o t) prints all 400 lines.
The 250 failure looks like the SOON "Continuation passing for non-tail calls on the JS lane" entry in WONTFIX.txt. The 300+ one happens in V8's parser on the emitted source, so it may need flatter codegen for long do blocks rather than CPS. Workaround: split the block into defs of ~20 steps each.
The file
# generated by:# python3 -c "print('import Base\n\ndef main() -> IO(Unit):\n do IO<Unit>:'); [print(f' IO.print(\"{i}\")') for i in range(300)]" > t.bendimportBasedefmain() ->IO(Unit):
doIO<Unit>:
IO.print("0")
IO.print("1")
# ... one IO.print per line, 300 in totalIO.print("299")
bend --version
bend 2.0.28
uname -sm
Darwin arm64
clang --version (the first line)
Apple clang version 21.0.0 (clang-2100.1.1.101); node v26.7.0
Two more data points for this class, measured on 2.0.36 (commit 1d895ca), re-verified in isolation — posting here since they look like the same family rather than new issues:
1. The JS emitter itself dies before node ever loads the file. A do IO<Unit>: block of N sequential typed lets (x0 : U32 = 0, x{i} : U32 = ((x{i-1} * 7 + 5 : U32)), …):
checking is linear (0.4 s at n=2000) and the native build+run is linear and correct (n=3000 builds in ~1.6 s),
but bend t.bend -o t.js spends quadratic time emitting (n=2300 ≈ 42 s, n=2600 ≈ 55 s, measured in the campaign) and from n≈3000 the build fails with Error: the machine stack overflowed (a deep recursion, or a literal too large to expand) after ~60-100 s — so the failure is inside comp.ts's emission walk, upstream of the emitted-JS parsing failure this issue describes. The emitted JS, when it does emit, runs in 0.03 s.
2. The interpreter's run is quadratic in the same program.bend t.bend on the let-chain: 300 lets 0.8 s, 600 2.5 s, 1000 6.9 s, 1500 16-27 s, 2000 33 s, n=3000 → ~60 s then Error: the machine stack overflowed, at both BUN_JSC_maxPerThreadStackUsage=33554432 and 134217728 (so it does not track that knob). No known WONTFIX entry seems to cover the straight-line case: the continuation-passing entry is about non-tail calls, and this is a flat block of lets.
Found by an automated AI-model differential-testing campaign against bend 2.0.36; measured numbers are floors under system load, re-measured in isolation where it mattered.
Activity
Giulio2002 commentedon Oct 8, 2026
Two more data points for this class, measured on 2.0.36 (commit 1d895ca), re-verified in isolation — posting here since they look like the same family rather than new issues:
1. The JS emitter itself dies before node ever loads the file. A
do IO<Unit>:block of N sequential typed lets (x0 : U32 = 0,x{i} : U32 = ((x{i-1} * 7 + 5 : U32)), …):bend t.bend -o t.jsspends quadratic time emitting (n=2300 ≈ 42 s, n=2600 ≈ 55 s, measured in the campaign) and from n≈3000 the build fails withError: the machine stack overflowed (a deep recursion, or a literal too large to expand)after ~60-100 s — so the failure is insidecomp.ts's emission walk, upstream of the emitted-JS parsing failure this issue describes. The emitted JS, when it does emit, runs in 0.03 s.2. The interpreter's run is quadratic in the same program.
bend t.bendon the let-chain: 300 lets 0.8 s, 600 2.5 s, 1000 6.9 s, 1500 16-27 s, 2000 33 s, n=3000 → ~60 s thenError: the machine stack overflowed, at bothBUN_JSC_maxPerThreadStackUsage=33554432and 134217728 (so it does not track that knob). No known WONTFIX entry seems to cover the straight-line case: the continuation-passing entry is about non-tail calls, and this is a flat block of lets.Repro shape (generator):
Found by an automated AI-model differential-testing campaign against bend 2.0.36; measured numbers are floors under system load, re-measured in isolation where it mattered.