tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Core: split giant functions into tail-call chains (issue #281)

tests/run/msgpack.lse's generated main is ~12,800 lines of C (std impls
and derived methods inlined into it). clang's LiveDebugVariables is
quadratic in function size: at -O1 -g the unit needs 88 s and 6.5 GB
peak RSS (2.8 s and 166 MB at -g1), and the tsan workflow OOM'd.
LOUISE_CFLAGS=-g is the documented way to keep variable info in release
builds (issue #116), so any big enough program hits this.

New Core pass opt::split, run by the C backend between the optimiser
and Perceus (codegen only; the interpreter never runs it): a function
whose top-level let-chain exceeds LOUISE_SPLIT_NODES (default 500 Core
nodes; 0 disables) is cut into chunks connected by tail calls. A chunk
ends `let r = f$split{k+1}(live…); r` — the shape emit makes a
TL_MUSTTAIL of — with the variables live at the cut (one backward
liveness walk) as owned parameters, renumbered compactly so no chunk
declares the whole function's locals. Perceus then inserts the counts
and infers borrowed parameters as for any function; borrow inference
treats a chain and its origin as one recursive group, so chunk
boundaries stay tail calls and the C stack stays constant.

Only the top-level chain is cut: block labels cannot cross a C function
boundary, so size inside a switch arm or a Value::Block body leaves the
function unsplit, as does a cut point with more live variables than a C
signature takes with headroom (24 of 32). Unboxed-signature functions
and CPR workers are skipped (theirs is not the uniform signature).

Measured on the issue's repro (clang 22.1.8, -O1 -g,
msgpack.msgpack.c), LOUISE_SPLIT_NODES varied:

  unsplit:  87.8 s, 6.49 GB peak RSS, largest fn 12,838 lines
     1500:  10.9 s, 690 MB, largest 5,650 lines
      800:  10.7 s, 334 MB
      500:   5.9 s, 200 MB, largest 2,104 lines
      300:   4.2 s, 169 MB
  -g1:       2.8 s, 166 MB (the floor: no per-variable debug info)

Default 500 puts -g within reach of the -g1 floor; chunk overhead is
one musttail call per boundary, and the pass itself costs 1.4 ms on
msgpack. The split binary's output is byte-identical to the unsplit
one's; the full tests/run suite passes natively, optimised and not.

ADR 0056.

olivier · il y a 1 mois · 3e3cb38ada4e57cce8e78e3e0b97f2fd26446f54

Parents f97e052

9 fichiers modifiés, 964 ajouts, 3 suppressions