Repository navigation
Calls passing a source lambda to a non-recursive def inline the callee, through a leading one-arm match - #1866
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
…e, through a leading one-arm match A call whose argument in a live position is a source lambda inlines a non-recursive callee at the call site, so the lambda is applied in place and no closure is built. Inlining passes through a callee's leading match on a one-constructor type (tuples, records): def_at puts the callback into the match arm. A lambda applied directly to its arguments is reduced in anf. In the emitter, a let bound to a one-arm match moves the rest of the code into that arm, and a tail one-arm match is emitted directly. Skipped: multi-arm matches, recursive callees, callees with more than one non-callback argument left at the match. Replaces bendlang#1356. Fixtures from bendlang#1288 (by @mizchi) included unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
nicolas-abril
force-pushed
the
callback-inline
branch
from
October 30, 2026 17:16
c26fe4d to
6e705ee
Compare
nicolas-abril
marked this pull request as ready for review
October 30, 2026 17:18
nicolas-abril
marked this pull request as draft
November 3, 2026 12:20
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,846 ttok, 846 over the 66,000 cap, sorepo-gatefails until that is settled. Replaces #1356. It does the same job by inlining instead of minting specialized defs: +886 ttok againstmain, where #1356 cost +1,136, with the same speed.What it does
When a call passes a lambda written in the source in a live parameter position, and the callee isn't recursive, the callee is inlined at the call site. The lambda is then applied in place, and no closure is built.
matchwhen the matched type has one constructor (tuples, records). A small helper,def_at, puts the callback into the match arm.anf.letbinds the result of a one-arm match, the rest of the code moves into that arm. A match in tail position is emitted directly. This also applies to one-arm matches written in source.There are no new defs, keys, markers or fuel. Termination comes from the callee being non-recursive.
Results
The fixtures from #1288 (by @mizchi) are included unchanged, and all 5 print their expected output.
Speed (M4, 10⁸ steps, 7 runs each, measured before the rebase onto #1968; after it, a re-measured helper-with-a-capturing-lambda loop went from about 0.26 s on
mainto about 0.01 s):get-style)Closures built in the fixtures (main / #1356 / this, measured before the rebase):
known_callbackknown_callback_arrayknown_callback_layoutsknown_callback_shapesknown_callback_edgesChecks:
test.tspasses 1803/1803 andperf.ts124/124, onmainat refactor(comp): shed tokens and compile large programs faster #1968.bench/compiles to the same C as main, and JS output is unchanged across the corpus. The C changes in 42 of the 1,383 programs that load, including the demosapp_slash_boss_3dandio_tcp_echos.tscshows no new errors incomp.ts.repo.tsfails only on the ttok cap.Not covered
None of the fixtures need these.
Cost
+886 ttok. Getting under the cap needs about 846 tokens cut elsewhere in
comp.ts, or a raise.Not run: CUDA, Linux and the JS benches.
🤖 Generated with Claude Code