Repository navigation
An erased last argument no longer cuts its call, so a def whose last parameter is erased keeps its fork (#1374) - #1377
Merged
Conversation
…parameter is erased keeps its fork (bendlang#1374) anf's spine cut the call prefix before every argument, live or erased. In tree(q, i, z) with z erased, the prefix tree(q, i) already carries every live argument, so term_spine reads it as a complete call: anf cut it into a sequential `h = tree(q, i)` and the parallel let's values became plain variables, so the let compiled with continuations and no join. Only a live argument over-applies a call now, so the prefix is cut only before one; an erased argument stays in the application, as it already did when it sat in the middle. The same cut made a tail call into a non-flat def with an erased last parameter a call plus a continuation; it is a tail call again (Word.add_comm.go's calls to Word.add_comm.arm). Fixes bendlang#1374.
Lorenzobattistela
approved these changes
Oct 7, 2026
nuxyel
added a commit
to nuxyel/bend-ml
that referenced
this pull request
Oct 8, 2026
Merged
This was referenced Oct 14, 2026
nuxyel
added a commit
to nuxyel/bend-ml
that referenced
this pull request
Oct 17, 2026
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.
Fixes #1374.
Cause
anf'sspinecut the call prefix before every argument, live or erased. Intree(q, i, z)withzerased, the prefixtree(q, i)already carries every live argument, soterm_spinereads it as a complete call.anfcut it into a sequentialh = tree(q, i), the parallel let's values became plain variables, and the let compiled with continuations and no join. With-zanywhere else, the prefix before it isn't a complete call, so nothing was cut. That's why only an erased last parameter showed it.The same cut also hit tail calls into a def that isn't flat.
Word.add_comm.goends each arm withWord.add_comm.arm(p, at, bt, k, h), whose last parameter-his erased, so each of its eight arms was emitted as a cut plus a continuation (FID_WORD_ADD_COMM_GO_K4…K11) instead of a tail call.Change
In
anf, only a live argument over-applies a call, so the prefix is cut only before one. An erased argument stays in the application, as it already did when it sat in the middle. Variables keep their rule: a variable applied to erased arguments is the variable. The header comment aboveanfnow says "a live over-application".comp.ts63,849 → 63,858 ttok (+9; cl100k_base, ttok's default).gates/repo.tspasses 50 / 50.tests/compile/fork_erased_last.bendis a parallel let in a def whose last parameter is erased. Its C now has the join (FID_TREE_J4), and main's has none. Stdout can't show a fork, so main prints the same#|line: the test runs the forked shape on every lane but doesn't catch a revert, and its header says so. The evidence for the fork is the C and the timings below.Checked
Linux x86-64 (Core Ultra 7 155H, 22 threads), bun 1.4.2, clang 22.1.8. Main is 0ad47fc.
The repros from #1374 (best of 3; all print
3942408568):--threads 1(main / this PR)--threads 16(main / this PR)tree(+d, +i)tree(+d, +i, -z)tree(+d, -z, +i)The two controls emit byte-identical C on main and here, so their timing differences are noise.
Same output elsewhere.
.bendfiles undertests/,bench/runtime/anddemos/, each lane builds the same files as main (770 C, 794 JS), and every error message is identical. Every emitted JS file is byte-identical. Two C files differ:proof/word_add_comm: the eight cuts above become tail calls;reg/erased_call_cut: one local is renamed (_h_0→_v0_0), and its binary is byte-identical to main's..mjsand binaries: built with-o t.js -o t.mjs -o tfor all 1,593 tests. Every.mjsis byte-identical. Of the 736 binaries, two differ:proof/word_add_command the new test.#|lines fail identically on main: display tests,io/process_run,io/chan_try_late, and helper modules undertests/importandtests/reg/respelled.--checkuponreg/erased_call_cut,proof/word_add_command the new test prints their#|lines.tsc -p bend2/pack: the same 12 errors as main, none incomp.ts.Performance. For each of the 17
bench/runtimeprograms I ran SEQ-CPU (--threads 1 --gpu off) and PAR-CPU (--threads 32 --gpu off) after one warm run, taking the median of 5 runs interleaved with main. For every bench:-o main.c), geomeanbench/checker, min of 3Memory. A side effect, not pinned by any test, since output can't show it. A tail-recursive loop that forks in its body and has an erased last parameter got one continuation per iteration on main. Over 3M iterations, peak RSS was 30 MB on main and 12 MB here at 1 thread, and 104 MB against 14 MB at 16 threads. The output is the same.
Not run: the cluster gates (
gates/test.ts,gates/perf.ts,gates/safe.ts,gates/ping.ts), Metal and CUDA. This machine has no access to the minis and no Apple GPU.