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
The run path (bend file.bend) overflows its stack on a 32k-element list, while --check-only and -o are fine #1894
The plain run path dies with bend: memory fault (machine stack overflow?) and exit 1 — no file, no line — on a twelve-line program that the checker accepts and that compiles and runs natively without trouble.
Repro
import Base
import [email protected]/main.bend as G
def main() -> IO(Unit):
xs = G.noise_of(7n, 32768n)
do IO<Unit>:
IO.print(Nat.show(List.length(&2, F32, xs)))
return Unit{}
$ bend repro.bend
bend: memory fault (machine stack overflow?) # exit 1
$ bend repro.bend -o prog && ./prog
32768 # fine
Where the line is
list length
bend file.bend
-o then run
4096
prints 4096
fine
8192
prints 8192
fine
16384
prints 16384
fine
32768
faults
prints 32768
65536
faults
prints 65536
Same on 2.0.38 and 2.0.39 (both checked on the same machine).
Why I think it is the run path, not the program
--check-only passes.
bend … -o prog then running prog does the same work (65536 elements) in both versions.
It is frame size, not recursion depth: a 65536-element Nat list summed by a recursive match on the same run path is fine, so the run path tolerates 65536 frames when each frame is small. Each element here is a Box–Muller call (G.noise_of → gauss_at), and ~32k of those frames do not fit.
Why it matters
bend <file>.bend is the documented way to run a program ("check the file, then run main"). A program of this size is ordinary for data and ML work; the failure mode gives no location and looks like a fault in the program, so the first move is to rewrite code that is fine. It cost me an afternoon before I noticed -o was unaffected.
A larger stack for the run path, or a diagnostic that names the limit (stack limit reached: N frames; build with -o for the compiled path), would both resolve it.
I can minimise further or test a patch if that helps.
Closing as a known limit rather than a bug. bend file.bend runs on the JS backend, whose depth is bounded by the host engine's call stack; a deep non-tail recursion with large frames hits it, and the run reports it as the same numbered stack-overflow line the C runtime uses. The native backend (bend file.bend -o app && ./app) has much larger guarded stacks and is the path for data-sized recursion. Lifting the JS limit would mean replacing host recursion in the JS emitter, which we're not planning now. Thanks for the careful report and the size table.
Activity
Lorenzobattistela commentedon Oct 29, 2026
Closing as a known limit rather than a bug.
bend file.bendruns on the JS backend, whose depth is bounded by the host engine's call stack; a deep non-tail recursion with large frames hits it, and the run reports it as the same numbered stack-overflow line the C runtime uses. The native backend (bend file.bend -o app && ./app) has much larger guarded stacks and is the path for data-sized recursion. Lifting the JS limit would mean replacing host recursion in the JS emitter, which we're not planning now. Thanks for the careful report and the size table.