Repository navigation
A fork-free segment takes its sequential path on the host without testing seq - #2176
Draft
nicolas-abril wants to merge 1 commit into
Draft
nicolas-abril wants to merge 1 commit into
nicolas-abril wants to merge 1 commit into
Conversation
A segment that reaches no fork tested seq before each frame it pushed and before each call, and carried the task path it never takes: FID_ENTER and FID_EXIT set seq for a fork-free task, and a forking segment hands a fork-free callee to a task of its own. WL_SEQ(F) is seq, or on the host true for a fork-free segment, so clang drops the test, the task path and the frame the path's calls forced on every entry. The one such segment that ran with seq clear is a closure body entered through a Clo~apply that may fork; it now keeps its frames on the stack above the task's frame, as a fork-free task does. symreg -15.8% instructions, queens -6.3%, lexer -2.8% (one thread, M4). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 16, 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.
comp.tsis 66,000 ttok, exactly at the 66,000 cap (main is 65,966):WL_SEQ's#definehas one space where its neighbours are aligned, which is the token that keeps it there. Measured on one Mac (M4), not on the cluster: thetestandperfgates have not been run.What it does
A non-tail call has two ways to keep its continuation: a frame on the stack (
if (seq)) or a task node on the heap (theelse), and a jump into a fork-free def from a forking one makes a task (!DEVICE && !seq && fid_nofk(F)).seqis set whenever the task at hand is fork-free (FID_ENTERandFID_EXITor infid_nofk), so a segment that reaches no fork tested a flag that was always set, and carried a task path it never took.WL_SEQ(F)isseq, or on the host true when segmentFis fork-free.FID_Tis a constant table, so clang folds it per segment. In a fork-free segment the host build then drops:task_nodeandheap_alloc_miss. Those calls were what made clang give the segment a C frame:evalinsymregsavedx29/x30and set three constants on every entry, for code it never ran.A forking segment and every device segment still test
seq.The one case that changes behaviour: a fork-free closure body entered through a
Clo~applythat may fork (some other closure forks), from a forking def running withseqclear. It used to keep its continuations in task nodes; it now keeps them on the stack above the task's frame, as a fork-free task does. Everything it reaches is fork-free too, so the frames are popped before control returns to the forking code. The new test runs that path.Results
One M4, GPU off, one thread unless said. Instructions retired and cycles from
/usr/bin/time -l, builds run in turn, minimum of 3 to 5 runs.symregqueenslexertree-matmulCycles move much less than instructions. Each build was swept over 16 code positions (nops at the head of
work_loop, 4 bytes a step), cycles on a P-core, minimum of 2 or 3 rounds per position:lexersymregqueensnbody(same instructions)On an E-core (
taskpolicy -b, one run each):symreg17.29G to 17.13G cycles,queens28.70G to 27.95G,lexer16.02G to 15.67G. At 8 threads the wall time does not move (symreg0.52 s,queens0.91 s to 0.90 s,lexer0.39 s to 0.37 s).Why
symregkeeps its cycles: it is bound by taken branches, not by instructions. Counted with Instruments' CPU Counters over the whole run: 8.13G taken branches before and after, 0.044G mispredictions before and after, no cache misses. Over twelve variants of the bench (C twins and hand edits of the emitted C, 37.9G to 51.2G instructions) cycles follow taken branches (R² 0.95, about 1.2 cycles each) and not instructions (R² 0.23). The instructions removed here are stores, moves and a never-taken test.Three small recursive kernels (scaled copies of the
fib,hanoiandtakports in koru-benchmarks' osprey-compute-kernels, nothing but calls and returns), instructions / cycles at one placement:fib(42)hanoi(29)tak(38, 19, 9)Elsewhere: the emitted C of every program changes (
mainpushes a frame too), by the spelling of the test only where the segment may fork.Checks
All local, against main
f0cf0a7c:#|lines on both, 21 differ from them and 1 times out on both (IO, gfx and network tests), no status differs.-DBEND_POISONand a count of live heap words at exit: the same output, exit code and count as main on every one.seqclear. The new test reaches it tens of thousands of times at 8 threads (50,280 and 100,464 in two builds) and never at one; a larger copy 7 to 10 million times at 2, 4 and 8 threads. Both print main's lines at every thread count, and pass the memory check at 1 and 8 threads.tests/run/fork_free_closure.bend: fork-free closure bodies with non-tail calls, a deep recursion and frames live across allocations, called from a forking def beside a closure that forks. Its lines are main's; it prints them on the C lane (1 and 8 threads), under bun and underbend file.bend.seq(WL_SEQisseqthere). The 47 tests that make a!call print the same with--gpu onon main and on A call into a tree recursion runs the callee's returning arms itself and jumps straight to its continuation #2177, which contains this commit.repo.tspasses (56 / 56):comp.tsis at the cap, not over it.Not covered
tscwas not run.seqat run time and keeps both paths.Where this came from
symregis 1.37x behind its C twin and no draft had moved it.eval's segment showed a frame set up on every entry for calls that sit on the task path, which a fork-free def never takes. The cycles are a different matter: they follow taken branches, and #2177, which stacks on this one, removes those (symreg12.4G to 8.2G cycles).🤖 Generated with Claude Code