Issue #2428: a function type’s own code parameter has no run-or-kept rule, and a lambda…

Open and answer this issue on GitHub.

decision, bugs · opened 2026-11-20 · updated 2026-11-20 · 1 comment

Filed by the driver from the Found: of the run of issue-1121 (#1121) (owner, 2026-11-06).

Found

a function type’s own code parameter has no run-or-kept rule, and a lambda of that type may keep it today. Probe struct Box { f: fn() -> i64 sync } / fn twice(scoped: fn(i64, fn() -> i64 sync) -> Box sync) -> i64 throws { let b = scoped(1, fn() { return 2 }) / return b.f() } / fn main() throws { println(f"{twice(fn(at, run) { return Box { f: run } })}") } prints 2 and lowers the lambda to |at, run| { Box { f: run.clone() } }. So “run” in fn(i64, fn() -> i64 sync) cannot be read from the type. Run versus kept is inferred from a body (ADR-277 D8, D11) or from a trait’s default body and its own package’s impls (ADR-277 D17), but a function type has no body and no ADR decides it. Lowering the inner type to &dyn Fn() -> i64 breaks this program (run is borrowed for the call alone). The choices are: a word in the function type (for example fn(i64, keep fn() -> i64), lent by default, a keeping lambda refused) or a D17-like column made from every function handed to that type. No decision yet.

Needs

supervisor decision: how a function type’s own code parameter is run or kept (ADR-277 D8 and D17 cover a body and a trait method, not a function type), before #1121 can lower it to &dyn Fn

Cause not marked

The Found does not say how sure its cause is (docs/issues.md I7): a cause it names is a hypothesis, unknown until checked. The second item checks it (nikaia run scripts/where.nika, a probe, callgrind) before anything is built on it; a cause shown false is answered wrong I7: ... in the report.

To build

Done when

The probe or check gives the expected output the first item names from its ADR or Part I-III section, and a tests/compiler/tests/ test (or the named check) that failed on the unfixed tree is green; or the probe already passes on develop and a test pins it, naming the commit that fixed it; or the issue is closed as by design, naming the function or ADR.


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-20

Supervisor, 2026-11-20, after talking with the owner: the question is wider than “keyword or inference”. “Kept” must not mean Kept(Arc::new(..)) by default. Nikaia does not copy behind the programmer’s back, and the region analysis already knows when memory is freed, as the fix for #2348 showed. So before the run-or-kept rule is written, each case gets its cheapest shape, with a probe and a callgrind figure:

  1. The lambda captures nothing (as in the probe: fn() { return 2 }). Its shape needs no heap at all: a function pointer or a &'static dyn Fn, whether it is run or kept.
  2. Run only. It is lent as &dyn Fn or &impl Fn, with no allocation.
  3. Kept, but the keeper dies inside the caller’s region. In the probe, b lives and dies inside twice. It can be lent with a lifetime, the way a returned box was built in the caller’s block in the fix for #2348.
  4. Exactly one concrete lambda reaches the type in the package. Monomorphise it: no dyn and no heap.
  5. Kept and it escapes upward, or is given to a task. It is moved to the heap once, as a Box, not an Arc. An Arc is used only where ownership is really shared (ADR-312 D1).
  6. A pub boundary with unknown foreign lambdas. The narrowest contract that still covers cases 1–5, following D17 (NK1264, NK1265).

No new keyword (ADR-277 D8: nothing is written). The rule is inferred, and the ledger shows which shape each position got and why. The next step is a study that measures each case on the probe and in the compiler’s own call sites; it then gives the ADR text and the build items for #1121.


Generated by Claude Code

Back to Open Issues