Repository navigation
Inline calls that pass a lambda to a non-recursive def, through matches on runtime values - #2
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
def_simp runs on a def's body before the analyses read it. It reduces a lambda applied in place, and inlines a saturated call that passes a lambda to a def that cannot reach itself (by its checked body). An argument that is no value is bound first, so it runs once. When the callee opens a match on a runtime value, the arguments left and the rest of the let that binds the call move into the match's arms (the emitter now takes a match applied to its scrutinee in tail position), so a function chosen by a match is applied in each arm. Callees whose body returns more lambdas than the call supplies (IO.bind and the rest of CPS IO) are left alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 24, 2026
Owner
Author
nicolas-abril
added a commit
that referenced
this pull request
Dec 1, 2026
…opy's arms #2's missing case, in the closure pass: - A lambda argument is known by its own function type where its parameter's type is a variable (choose(-A: Type, flag, a: A, b: A)), so choose(flag, λa, λb) gets a copy at all. - An over-applied call with a known lambda knows its extra arguments too (variables, as captures, or constants): choose(flag, λa, λb)(x) calls a copy whose arms apply λa or λb to x in place (clo_rm applies a known argument to whatever term is left past the case tree). - f = choose(flag, λa, λb); ...; f(x): a let of such a call, read once as a call's function and under no lambda, puts the call there. tests/compile/known_fn_inline: 4 closures to 2 (#2's count); #2's other fixtures as before. A loop of 300M picks, applied after a let or in place: 2.70x fewer cycles (-89% instructions), as fast as a fresh lambda. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 4f162fb)
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,625 ttok, 1,625 over the 66,000 cap, sorepo-gatefails until that is settled. Supersedes bendlang#1866: it covers the same cases with no more closures on its fixtures (included here), and adds callees that match on a runtime value with more than one arm.What it does
def_simpruns on each def's body infun_of, before the analyses (flatness, spins, call sites) read it:letbinds the call, the rest of thatletmoves into the arms too. Sof = choose(c, λa, λb); f(x)appliesλaorλbdirectly in each arm.file_bookandterm_anykeep such a match's arms as tail positions.Callees that return more lambdas than the call supplies (
IO.bindand the rest of CPSIO) are left alone. A pre-check on the checked term keeps defs without a lambda argument untouched.Results
Paired cluster runs: each case on 3 nodes, 5 rotated samples per node after a warm-up, wall time, medians.
Boolmatch, applied after aletAll four match the hand-inlined program on SEQ-CPU. On PAR-CPU, the chosen-function loop goes from 6.571 s to 2.017 s.
Closure sites in the C (
term_clo(FID_…)) on the fixtures from bendlang#1288/bendlang#1866, main / bendlang#1866 / this:known_callbackknown_callback_arrayknown_callback_edgesknown_callback_layoutsknown_callback_shapesChecks
test.ts: 1832/1832, with the newtests/compile/known_fn_inline.bendand the fivetests/run/known_callback*.bend. In one of four earlier runs,io_bundle_inline [js]timed out; that test also flakes on output that is byte-identical to main.bench/runtimeprograms compile to the same C as main. A paired SEQ/PAR/GPU run of all of them showed only node noise.compile_bookover all tests took 16.7 s against main's 18.0 s, in one concurrent run. Warmcompile_bookon the benches is within about 0.5–2 ms of main.tscshows no new errors incomp.ts.repo.tsfails only on the ttok cap.Not covered
~templates still cover those.Cost
+1,630 ttok. Getting under the cap needs that many tokens cut elsewhere in
comp.ts, or a raise.Updates
🤖 Generated with Claude Code