Skip to content

Lift deep JS continuations so long do blocks load (#1086) - #1096

Closed
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/js-long-do-stack
Closed

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/js-long-do-stack

Conversation

@oxura

@oxura oxura commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Closes #1086.

A single long do emitted hundreds of nested run_clo arrows; Node 22 raises RangeError: Maximum call stack size exceeded while loading a 400-step program, and Bun also hits its parser stack. The JS compiler now lifts every 33rd nested continuation into a top-level function and explicitly passes its captured local values. Ordinary shallow closures keep their existing shape. Hoisted function bodies undergo the same non-tail-call/trampoline substitution as other emitted functions.

tests/io/do_long_js.bend has 400 sequential effects, carries a string across them and calls a pure def in the final effect; expected output is [value]. Interpreted checkup, emitted Node, emitted Bun and native C complete. A separate 1000-step program also completes on Node, and a long match branch retaining a constructor field completes. bun gates/repo.ts: PASS 46/46. Cluster gate and macOS not run.

@VictorTaelin

Copy link
Copy Markdown
Contributor

Thank you for this. #1086 is labelled later: we want the JS lane's deep continuations fixed in its code shape, not by lifting them after the fact. Closing for now; #1086 stays open.

@VictorTaelin

Copy link
Copy Markdown
Contributor

To be precise: the fix we want lambda-lifts every JS continuation to a top-level function, as the C lane's seg_clo does. Lifting every 33rd one works, but the period is a magic number, not a cause.

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.

JS lane: a long do block emits JS that node cannot load (parser stack overflow from ~300 steps)

2 participants