Repository navigation
A spin called in a jump's argument sinks the variable it was lent, so a loop no longer keeps the old list's cells - #1243
Conversation
… a loop no longer keeps the old list's cells Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Thanks, the leak and the fix check out. On current main (75cc360) the test's max RSS goes from 81.6 MB to 1.7 MB, and the PR merges cleanly. I ran every gate on the PR merged onto main, and they all match main: test 1532/1532, perf 124/124, ping 46/46, and safe agrees with the kernel on the new test. There is a problem with forks, though. Before this PR, a rest that missed a later use only leaked memory. Now bind_dead(fl, fl.rest) frees whatever rest doesn't list. emit_fork evaluates the args of call i with rest: [chain[i]], which leaves out hold, the variables the parallel join task captures. So a spin nested in a fork argument now frees a held variable. The serial path then gives the join fewer values than the parallel task stored, and it reads the wrong slots. The program below prints "12 5" on main with 1, 4 and 8 threads. With this PR it prints "12 5" on 1 thread, but on 4 and 8 threads it fails with "bend: frontier drained without a result". Including hold in that rest fixes it; with this change the program prints "12 5" on 1, 4 and 8 threads:
A few more things:
|
Include hold in the rest used to evaluate fork arguments so nested spins preserve the captures shared with the parallel join. Add the reviewer regression and correct the RSS comment in spin_lent_sink. Verified Red on 4/8 C threads, then Green on 1/4/8 threads and JS. All 28 related tests pass on C, Bun and Node; the new test passes the interpreter and kernel verdict. Repo gate: 50/50.
|
Thanks for the review! Addressed in bee6b1a.
All 28 related spin/fork tests pass on C (1/4/8 threads, GPU off) and Bun/Node JS. The new regression also passes the interpreter and |
… keeps handing its held lists to its calls bee6b1a put the fork's held variables in the rest of every call's arguments. That kept a nested spin from sinking them, but it also made every held variable passed straight to a forked call look alive after it, so the call borrowed it instead of taking it: tree-matmul ran 1.94x slower SEQ and 1.76x PAR. The sink after a non-tail spin call now looks only at the spin's own variable arguments, which is where the lent variable that leaked lives, and emit_fork's rest is main's again. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Thanks for the quick update! I ran every gate on the PR merged onto main (947db72). Your fork fix fixed the fork_spin_hold case, but it made tree-matmul about 1.8x slower: SEQ went from 1.05x to 1.94x and PAR from 1.03x to 1.76x. Adding hold to the fork's rest also covered the variables passed straight to the forked calls. Those then looked alive after the call, so the call borrowed them instead of taking them, couldn't free their cells in place, and its frame grew. I pushed 897a313 on top of your branch. It reverts the emit_fork line and limits the sink after a non-tail spin call to the spin's own variable arguments, which is where the leaked lent variable is. Both of your regression tests pass on 1, 4 and 8 threads, and the leak test still runs at 1.7 MB. Every bench compiles to the same C as main except hashmap, where one term_sink moves up a line, and tree-matmul is back to 1.05x. Gates: repo 49/49, ping 46/46, test 1540/1540, perf 124/124. |
36 commits since 2.0.34: the M1/M2 Metal pipeline crash (#1154), names keyed ns:name so a library's CID(None) means its own None (#1045), less CPU memory from the host's column and a spin's lent variable (#1171, #1269, #1243), equality-proof arrays (#1130), timers firing under a busy loop (#1122), and the CLI and --verdict fixes listed in CHANGELOG.md. Gates on 5e56772 over the bastion: repo 49/49, ping 46/46, test 1540/1540, perf 121/124. CHANGELOG.md and VERSION name 2.0.35. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
What you did
On
main @ 43513c4, save the program below asmain.bend, compile it, and run it on the C and JS lanes:What happened
All runs print the correct result:
The C run retains the old list's cells on every loop iteration. A spin called inside a jump's argument, as in
go(p, Xs.walk(xs, xs, X0{})), is lent a variable that dies at the call;emit_fuserunsbind_deadonly for a tail call, and the jump runs none. Reproduced locally.Measured with
wait4of the child, decimal MB,--gpu off.This PR calls
bind_dead(fl, tail ? [] : fl.rest)after the spin returns. Tail calls keep their existing cleanup; non-tail calls sink bindings the remaining expressions do not use. Reclamation adds work where memory previously leaked and can move cleanup earlier at other non-tail spin calls. The generated C for this program differs only by two addedterm_sinkcalls.Fork argument evaluation also includes
holdinrest:emit_args({ ...fl, rest: [...hold, chain[i]] }, c). A nested spin must preserve the parallel join's captures even when the serial chain no longer uses them, so both paths supply the same values to the join.spin_lent_sink.bendcovers passing one variable twice (go) and lending one variable to a parameter another call site made borrowed (go2). Its#|lines check output, not RSS; memory was checked separately. The comment now records approximately 81.6 MB before and 1.7 MB after the fix, consistent with the review measurements. Local measurements after both fixes were 1.6 MB with 1, 4 and 8 C threads.fork_spin_hold.bendadds the reviewer's fork program as a regression. Before the fork fix, it prints12 5with 1 C thread but fails withbend: frontier drained without a resultwith 4 and 8 threads. With the fix, all three thread settings print12 5.tests/compile,tests/regandtests/runpass on C with--gpu off --threads 1,4and8, and on JS under both Bun and Node 24 (140 executions).--verdict(ALL PROOFS CHECK).gates/repo.ts:PASS: 50 / 50, including the new regression file.gates/test.ts --gatecould not connect: SSH could not resolve theclusterhost. The cluster test/performance gates remain unverified locally. GPU execution was not run.Searched issues and PRs in all states for
leak spin,emit_fuse,bind_dead,RSS grows,term_sink, andspin lent; no matching leak report found. No open PR touchingcomp.tschanges this branch ofemit_fuse.The file
main.bend
bend --version
uname -sm
macOS 26.6.2, Bun 1.3.5.
clang --version (the first line)