louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
ADR 0046: Cheaper calls (exact-arity direct calls; preemption on recursive-group entries)
Status: Accepted by the project owner on 2026-10-15; proposed the same day (issue #191); needs engineering review (#44), in particular of the calling-convention change (runtime ABI). It changes what the C backend emits — the language and the type system are untouched.
Context
Every Louise function has the same C signature: ctx plus six value arguments (a0..a5), extra ones in ctx->xargs. Every function entry decrements a reduction counter (preemption — a self tail call re-enters through goto entry, so loops keep counting), except the entries of functions proven never to unwind, which skip the point entirely (issue #61: 44 of 135 entries in a typical program). A call that may unwind is followed by a yield check. On 2026-10-13 fib(38) was 0.61 s in Louise against 0.15 s in Rust.
A measurement, before any change (so the pieces are aimed where they pay): removing the reduction counter and the yield checks entirely from fib — which is not safe to ship — cuts its instructions by only ~9%. The recursive function keeps the counter at its entry (its own entries are the loop), and its yield checks follow calls that may unwind. So the counter and the checks are NOT the gap on fib. The gap is the uniform calling convention (six argument slots for a one-parameter function, the marshalling) and the value representation (tagged integers; #190). This ADR aims the pieces at the measured costs.
Decision
Three independent pieces, ordered by the measurement:
- Exact-arity direct calls. A function that is never taken as a closure and never the target of a cross-function tail call is emitted as a
staticC function with exactly its parameters, and its direct (CallFn) sites pass exactly the arguments —lf_fib(ctx, n)instead oflf_fib(ctx, n, TL_UNIT, …). A self tail call is agoto, whose signature nothing checks, so a self-recursive function likefibstill qualifies. The uniform signature stays for closures,musttailsites and thexargsconvention: becausemusttailrequires the caller's and callee's C signatures to match (ADR 0003, Revision 1), the split is uniform within a recursive group, exact elsewhere — the members of a mutually recursive group tail-call each other, so the group keeps one shape and itsmusttails stay valid, while a function outside any recursive group is exact. This is thefib/arithwin — a calling-convention change, and the reason for this ADR. - Preemption on recursive-group entries only. The counter decrements at the entries of functions that can reach themselves (the loops), not at every entry: a non-cyclic function runs a bounded amount of straight-line code and returns, so its caller's loop provides the preemption. This is a new analysis — cyclicity, the strongly connected components of the direct-call graph — not an extension of
never_unwinds(an unwind analysis that already skips the preemption point of bounded leaves as a side effect). The SCC computation itself already exists in Perceus's borrow inference (recursive_groups) and should be shared, not re-derived. The constraint is the done-when's: preemption latency unchanged (the ticker/timersbenchmark, and the loom scheduler models). Worst-case latency grows by one bounded non-cyclic call chain's straight-line work between two decrements; the loop drivers keep their decrements, and the benchmark is the check that the bound stays negligible. - Fast integer paths: a leaf function whose integer range is provably small (no overflow possible) skips the overflow checks. A separate, smaller analysis; independent of the other two.
Consequences
fib,arithandeffectsimprove measurably; the done-when's bar is that nothing is more than 5% slower and preemption latency is unchanged.- The runtime ABI gains a second call shape (exact-arity) alongside the uniform one, at
CallFnsites only — closures and the uniformtl_fntrampoline are unchanged. The runtime ABI note gets a revision.
Alternatives considered
- Fewer yield checks via a further interprocedural cannot-unwind analysis (issue #61): the emitter is already precise about which externs unwind, and the residual yield checks follow calls that genuinely may unwind — thin, and it interacts with the exit-delivery latency. Not the win.
- Counting in larger steps / a timer-set flag (BEAM-style): coarsens preemption latency, which the done-when forbids.
Open for review
- The recursive-group/exact split's interaction with the workers that already exist: TRMC's
$trmcworkers (uniform signature plus a trailing context parameter) and CPR's$wrkworkers (#210 — already a second C signature, a small struct returned by value). Exact-arity adds a third shape; the workers' constraints — uniform-compatible tail calls for$trmc, at most six register parameters for$wrk— must survive it, and the analysis for "in a recursive group" is the careful part. - Whether the
never_unwindsandcyclicanalyses merge into one call-graph pass: they answer different questions (may-unwind vs can-reach-itself) over the same graph, and the SCC itself should come from the existing Tarjan inlouise_perceus, not a third walk.
Revision 1 — 2026-10-15: piece 1 measured and not landed; piece 2 implemented
Status: Proposed; needs engineering review (#44). Issue #191. The pieces' own measurements, per the done-when.
- Piece 1 (exact-arity direct calls): measured, not landed. Implemented in full on the
calls-exact-aritybranch (PR #231, closed unmerged): the rule ended up "never a closure value, never an entry, on neither side of a cross-function tail call, not a CPR worker" — with one rule found by the test suite: a tail call through a closure musttails into the uniformtl_fn, so its caller keeps the uniform shape too. Then the measurement: user-space instructions (LOUISE_THREADS=1, deterministic to a few parts in 10^8 here) are within ±0.00% of the uniform build on every benchmark and onfib, with and without ThinLTO. Release builds are single-unit, so every program function isstaticand clang's dead-argument elimination already removes the padding stores piece 1 targeted; the premise that the convention's padding costs instructions does not survive. The gap onfibis the value representation (#190) and the counter/checks only. - Piece 2 (preemption on recursive-group entries): implemented, on its numbers. The cyclicity analysis shares Perceus's Tarjan (extracted to
louise_core::callgraph);LOUISE_NO_GROUP_PREEMPTrestores a point at every entry. Instructions:effects−2.3%,idle−1.5%, the rest within ±0.8% (fib/arith±0.0%, as the assessment predicted: their own entries are their loops). Preemption latency: the new ticker test (tests/run/ticker.lse),process.lse's busy-actor kill, the loom models andtimersare unchanged. - Piece 3 (fast integer paths): built, with the scope widened. The ceiling probe (checks hacked out of
tl_int_add/sub/mul) measuredarith−6.2%,fib−4.2% instructions — real enough to build for. The leaf-local version scoped by this ADR would prove nothing hot, so the analysis is a whole-program interval pass (louise_codegen_c::ranges): parameters from every direct call site to a widening fixpoint over the call graph, guards refine the arms of aswitchon a comparison (i > nbounds the counter), and safety needs only |value| ≤ 2^60, never exactness — so accumulators that no guard bounds (an honestBig) stay checked while loop variables prove out. Measured:arith−26.2%,floats−17.0% (its Int counter),fib−3.1%,arrays−4.8%,parallel−3.1%, the rest within ±1.4% (deterministic instruction counts). The emitter's*_uncheckedops live in the generated prelude — no runtime or ABI change; the interpreter always promotes, and the differential tests hold.LOUISE_NO_FAST_INTSturns it off.