tobogganSe connecter

louise

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

Perceus: borrow inference for parameters (issue #34)

A parameter a function only reads is now borrowed: the caller keeps its
reference, so a call saves a dup before it and a drop in the callee
(ADR 0002 planned this; the runtime ABI allows it for direct calls).

- Inference (tilc_perceus/src/borrow.rs) is Lean's: every parameter of
  a function that is never made into a closure starts borrowed, and
  becomes owned if the body consumes it, or if a tail call in the same
  recursive group passes it a value the caller owns (the caller would
  have to drop it after the call, breaking the tail call). Closures,
  effect clauses and externs keep the owned convention.
- One deliberate departure: a parameter the function matches (switch)
  stays owned. Borrowing walked structures kept temporaries alive until
  the call returned: lists was ~15% slower, and html (the quadratic
  string.join) regressed through glibc trimming and re-faulting its heap
  (314k minor faults instead of 1.4k). Owned, drop specialisation can
  free their cells as they are matched (next commit).
- Projections now borrow from the value they read: Perceus adds the dup
  when the projection must be owned (its value is owned), and none when
  the value is borrowed, so a borrowed structure is walked without
  counting.
- FnDecl.borrowed records the signature; tilc_perceus::uses takes the
  functions to classify CallFn arguments; the emitter does not hold
  borrowed parameters (unwinding does not drop them) and drops an entry
  function's borrowed root capabilities after it returns.
- verify (now in verify.rs) tracks liveness: a borrowed parameter is
  live, a projection is live while its value is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

olivier · il y a 1 mois · 27250c5c19372195efb2d0904c37b98825e5e9cb

Parents 007bc19

9 fichiers modifiés, 862 ajouts, 250 suppressions

Mcrates/tilc_codegen_c/src/emit.rs+37−15
Acrates/tilc_perceus/src/borrow.rs+289−0
Mcrates/tilc_perceus/src/lib.rs+177−224
Acrates/tilc_perceus/src/verify.rs+205−0
Mcrates/tilc_perceus/tests/programs.rs+87−8
Acrates/tilc_perceus/tests/snapshots/programs__borrowing_and_reuse_of_a_small_program.snap+39−0
Mcrates/tilc_perceus/tests/snapshots/programs__rc_of_a_small_program.snap+8−1