Repository navigation
Fuse a recursive consumer with the recursive producer it consumes (deforestation) - #2031
Closed
nicolas-abril wants to merge 1 commit into
Closed
nicolas-abril wants to merge 1 commit into
nicolas-abril wants to merge 1 commit into
Conversation
A call c(p(xs), ys), where c and p call themselves and take live closed datatypes, runs a def c<p(xs, ys) made from p's body with c applied at each result. A constructor result meets c's match there and is never built, and c called on a call of p inside is c<p again. The fused def is kept only if some constructor meets the match. A lone let of a producer call forwards into its use, and a result's lone let of a constructor forwards into it, so producer forks become the consumer's. Fused defs fuse again, up to three levels. The comptime twins pass the mapped list second (through sum), so no fusion consumes the map and they still compare template to hand-written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 24, 2026
Collaborator
Author
|
Moved to nicolas-abril#3, which keeps it saved off the main queue until it can be accepted. |
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 67,762 ttok, 1,762 over the 66,000 cap, sorepo-gatefails until that is settled. This is independent of #2030 (closure inlining). Both editfun_of's body line and addlt_any,term_underandlet_end, so whichever merges second shares them.What it does
A call
c(p(xs), ys)runs a new defc<p(xs, ys), where c is a consumer and p a producer. Both must call themselves and take only live, closed datatypes.c<pis p's body with c applied at each result.c<pagain.letof a producer call forwards into its use. A result's loneletof a constructor (a b = p(..) p(..); Ctr{a, b}) forwards into it, so the producer's fork becomes the consumer's.sum<bump<bump<grow. Fused defs live inFL.made; the book is not mutated.The comptime twins (
tests/comptime/hand.bend,tmpl.bend) now consume the mapped list throughsum(acc, xs), which takes the list second. Otherwise fusion consumesList.map~0and the gate's "only tmpl declares List.map" probe fails. Both twins change the same way, so they still compare template output to the hand-written version.Results
Paired cluster runs: each case on 3 nodes, 5 rotated samples per node after a warm-up, wall time, medians.
collect(change(grow(24, s), 17))changesBench suite:
tree-radixis the only one of the 17bench/runtimeprograms whose C changes (to_arrfused throughto_map'smerge). In the paired run it took 3.342 s against 3.573 s on SEQ-CPU (0.935x), 0.602 s against 0.641 s on PAR-CPU (0.939x), and 1.108 s against 1.118 s on GPU (0.991x). Every other bench compiles to byte-identical C.Checks
test.ts: 1827/1827, with the newtests/compile/deforest.bend.compile_bookover all tests took 18.2 s against main's 18.0 s, in one concurrent run. Warmcompile_bookon the benches is within 0.5 ms of main excepttree-radix(7.2 to 16.5 ms) andmerkle(32.7 to 37.2 ms).tscshows no new errors incomp.ts.repo.tsfails only on the ttok cap.Not covered
keephelper on its own. The consumer and producer around it still fuse.Cost
+1,767 ttok. Getting under the cap needs that many tokens cut elsewhere in
comp.ts, or a raise.🤖 Generated with Claude Code