Issue #2493: A user function’s code parameter called at most once may take what its lambda captures (inferred once, lowered as impl FnOnce)

Open and answer this issue on GitHub.

ready · opened 2026-11-21 · updated 2026-11-21 · 0 comments

Part of #973 After #973

What it is

Step (b) of ADR-lambdas-1 (D3): a code parameter of a user function is once when its body calls it at most once on every path and hands it on only to a once parameter. A call in a loop, two calls or keeping it makes it many. This is inferred, written to the ledger beside kept and lent, has no syntax, and is lowered as impl FnOnce, so a user wrapper of entry or a lock works like std’s. The inference and the lowering go together: the accepted program only compiles under rustc once the parameter is impl FnOnce.

To build

  1. Infer once-ness of a user code parameter: called at most once on every path, handed on only to a once parameter. A call in a loop, two calls or keeping it makes it many. Fixpoint over calls, as for kept/lent. Written to the ledger as once.
  2. Lower a once parameter as impl FnOnce (crates/nikaia-std/src/compiler/emit_core_types.nika, where code parameters are written as impl Fn(..)). Kept stays Kept<dyn Fn>.
  3. Test in tests/compiler/tests/ (Nikaia, with .stdout): a user wrapper of entry accepting the move of a captured value into its lambda, run end to end.

Done when

A user function that calls its code parameter once and hands it only to or_insert_with accepts a caller’s lambda moving a captured value, the program runs, and its ledger shows the parameter as once, shown by a test in tests/compiler/tests/; the commit that builds item 3 carries the Fixes line for this issue.

Split from #973 by Claude Code

Back to Open Issues