Skip to content

A pure main forces deep_thunk_chain's 262144-link Nat thunk chain in the source interpreter, which its IO main left to the JS lane - #1398

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
HamedShams:deep-thunk-chain-pure
Oct 8, 2026

Conversation

@HamedShams

Copy link
Copy Markdown
Contributor

Closes #1316.

tests/eval/deep_thunk_chain.bend pins the interpreter collapsing a lazy accumulator deeper than the host stack, but its main is IO, and bend file.bend runs an IO main through Comp.io_run, i.e. the JS emitter. So the chain that comment describes only ever gets forced by the strict JS lane; the interpreter never sees it. Only a pure main goes through term_snf.

This adds tests/eval/deep_thunk_chain_pure.bend: same Nat.pow2, same go, same head demand through a match, but main answers a Bool instead of printing. The interpreter now has to collapse the 262144-link Nat.add(acc, 1n) chain itself before the match can pick an arm. I kept the match rather than returning the Nat so the test pins thunk forcing alone, not the printer's walk over a 262144-deep Succ chain, which is a separate concern.

Ran it the way the gate does, from the repo root:

  • --check-only: ALL PROOFS CHECK
  • aggregator --checkup with BUN_JSC_maxPerThreadStackUsage=33554432: prints True{} under the file header, 1.1 s
  • -o t.js + bun, and -o t + ./t: both True{}, well under the 5 s alarm
  • bun gates/repo.ts: PASS

It also passes with a 512 KB JSC stack, so the forcing really is off the host stack. I couldn't rerun it from before the LAZ-frame law landed: the tree at that point predates law, so the parser rejects the file.

HamedShams and others added 2 commits October 8, 2026 03:05
…the source interpreter, which its IO main left to the JS lane

deep_thunk_chain.bend describes the interpreter collapsing a lazy Nat
accumulator deeper than the host stack, but its main is IO, and an IO
main runs through Comp.io_run, the JS emitter. Only a pure main reaches
term_snf. This twin keeps Nat.pow2, go and the match-walk head demand,
and answers a Bool, so the interpreter forces the chain itself.
… IO main runs on the emitted JS, and deep_thunk_chain_pure pins the interpreter (bendlang#1316)
@Lorenzobattistela
Lorenzobattistela merged commit b0e5149 into bendlang:main Oct 8, 2026
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.

Test gap: The deep Nat thunk test runs compiled JavaScript instead of the source interpreter

2 participants