Repository navigation
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 intoOct 8, 2026
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1316.
tests/eval/deep_thunk_chain.bendpins the interpreter collapsing a lazy accumulator deeper than the host stack, but its main is IO, andbend file.bendruns an IO main throughComp.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 throughterm_snf.This adds
tests/eval/deep_thunk_chain_pure.bend: sameNat.pow2, samego, same head demand through a match, but main answers a Bool instead of printing. The interpreter now has to collapse the 262144-linkNat.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--checkupwithBUN_JSC_maxPerThreadStackUsage=33554432: printsTrue{}under the file header, 1.1 s-o t.js+ bun, and-o t+./t: bothTrue{}, well under the 5 s alarmbun gates/repo.ts: PASSIt 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.