Skip to content

Explain JS run-stack exhaustion and give the native command - #1921

Closed
oxura wants to merge 3 commits into
bendlang:mainfrom
oxura:fix/1894-run-stack-diagnostic-20261028
Closed

oxura wants to merge 3 commits into
bendlang:mainfrom
oxura:fix/1894-run-stack-diagnostic-20261028

Conversation

@oxura

@oxura oxura commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1894.

This takes the diagnostic option from the report; it does not raise the JS recursion limit. An IO run that exhausts the JS stack now gives bend file.bend -o app && ./app, instead of calling it a memory fault. Other RangeErrors are passed through unchanged.

Checked the report's G.noise_of(7n, 32768n) example on this branch:

  • Bun and emitted Node code give the new command and exit 1.
  • The native build runs and prints 32768.
  • bun gates/repo.ts: PASS: 54 / 54, with the existing caps.

@adeerkhan

Copy link
Copy Markdown
Contributor

The diagnostic is right, and narrowing to /call stack/ is the correct part: V8/Node and Bun all say "Maximum call stack size exceeded", so a nested RangeError from anywhere else still reaches the caller. The README line is the useful half — it names the workaround instead of leaving a memory fault to be deciphered.

Two things while you are in this line:

  1. The line you are replacing is itself broken on main. throw e instanceof RangeError ? "bend: ${ERRS[7]}" : e; is a double-quoted string, so what a user sees today is literally bend: ${ERRS[7]} — ERRS[7] is never interpolated. Your patch fixes that incidentally. Worth a sentence in the body (or its own commit) so the changelog records two fixes, not one.

  2. This is a diagnosis, not a lift. #1894's substance is that the run path cannot do what bend file.bend -o app can, at the same program; the recursion limit is unchanged here. If the project's position is "documented limitation, use -o", then retitling The run path (bend file.bend) overflows its stack on a 32k-element list, while --check-only and -o are fine #1894 from "overflows its stack" to "says how to run natively" is honest and this can close it — I filed it and I am fine with that. If it is meant to stay an open limitation, Refs #1894 fits better than Fixes, so the issue does not disappear while the limitation stands.

One nit on the message: compile with -o <binary> to run natively is good; bend file.bend -o app && ./app (as in the README) would be even more copy-pasteable, and it is the one thing a person hitting this needs next.

@oxura

oxura commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — switched to Refs #1894 and added the full command in bf67bb6. The stack limit is unchanged.

One detail: that line lives inside the outer RUNTIME_MAIN String.raw template, so ${ERRS[7]} is interpolated. The saved before-run prints bend: memory fault (machine stack overflow?), not a placeholder; I haven't claimed a second fix for it.

@adeerkhan

Copy link
Copy Markdown
Contributor

You are right and I was wrong: the line lives inside the outer RUNTIME_MAIN String.raw template, so ${ERRS[7]} is interpolated, and the before-run really does print bend: memory fault (machine stack overflow?). My "second fix" was a misread of a template literal as a plain one — thank you for checking it instead of taking it.

Refs #1894 plus the full command is exactly the shape I meant, and with the limit unchanged the issue stays open as the limitation rather than disappearing behind a Fixes. Nothing else from me on this one.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 29, 2026
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks for this, and for checking the template-literal detail. We're going to close it, though.

The JS wall printing the C wall's numbered line is deliberate: tests/io/stack_fault_trap.bend pins io_run's catch to the same bend: memory fault (machine stack overflow?) line on every backend, and this change makes that test fail on the interp and js lanes (1780 / 1781 on current main). A free-form message outside ERRS splits one fault into several wordings across backends, and the RangeErrors that now pass through still end up labelled as a stack overflow by book_err under bend file.bend.

#1894 is being closed as a known limit (see there).

@oxura

oxura commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Understood. I missed the existing cross-backend output contract in stack_fault_trap.bend; the 32k repro and repo gate weren’t enough to qualify this change. I’ll leave the shared ERRS wording alone and won’t resubmit a diagnostic change as a fix for #1894. Thanks for spelling out the intended contract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants