Skip to content

fix: spill wide live segments beyond the 247-word C bank - #1494

Closed
oxura wants to merge 2 commits into
bendlang:mainfrom
oxura:fix/1069-live-bank-spill-20261011
Closed

oxura wants to merge 2 commits into
bendlang:mainfrom
oxura:fix/1069-live-bank-spill-20261011

Conversation

@oxura

@oxura oxura commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #1069.

The limit is on live segment arguments, not just constructor width. Increasing the shared C register bank reintroduces the Clang failure, and an 8-bit logical arity loses large closure/fork arguments.

This keeps the physical bank at 247 words and spills excess segment arguments through the existing evaluator stack. Continuation entry consumes its frame and spill tail before loading locals; closure application appends its final argument after spilled captures. Ordinary native C spins retain their own C parameters, including self jumps. Logical arity is u32; the flat result width and frame/fork flags remain compact. The existing foreign-request width guard is unchanged.

Four permanent consumer regressions cover 248 live boxed fields, a materialized 300-capture callback, a 300-live-value fork, and a weighted 301-word native self-spin which always recurses. Before the change all four are valid interpreter programs but native emission fails with an arity over 247. Generated observation: callback logical arity 301, fork arity 303, physical bank still 247.

Verification on Linux x64:

  • Real standalone compiled CLI built all four permanent inputs to native binaries and executable JS.
  • All four returned the interpreter results under native 1/4 threads, Bun and Node: 16 actual executions.
  • Four existing word-copy/native-spin/wide-record-drop/stale-field consumers matched their expected results in source, native 1/4 threads, Bun and Node: 20 executions.
  • Real namespaced --checkup passes for all four new consumers.
  • bun gates/repo.ts: 54/54 on the rebased branch; permanent token limits and allow-list are unchanged.

Older Clang versions and Metal/CUDA hardware are not available here, so I am not claiming those runs. bend2/bend.ts, the kernel, GUIDE and CHANGELOG are untouched. README documents the bounded bank/spill distinction.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks for working on this, @oxura. Spilling the extra arguments to the evaluator stack is a reasonable idea, and the regression tests make it clear what goes wrong past 247 words.

We're closing it for now, for these reasons:

  • C backend: a segment with more than 247 live one-word values fails to compile #1069 is labelled later, and we haven't settled how to fix it yet. A wider arity table and emitting LLVM IR have both come up, and we'd like to pick one direction before taking a fix.
  • comp.ts is close to its token cap. This PR fits by shortening existing comments, which we'd rather keep as they are.
  • The wider arity makes the function table bigger on every build, to handle a case that rarely comes up. It was also tested on Linux x64 only.

Once #1069 has a direction we'll come back to it, and this PR is a good reference for that.

@oxura

oxura commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Understood. I will not reopen this implementation or trim compiler comments to fit another version. #1069 remains unresolved and parked until the wider-table versus LLVM-IR direction is chosen; the Linux regression evidence here is only a reference, not a completed fix or cross-platform verification.

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.

C backend: a segment with more than 247 live one-word values fails to compile

2 participants