Issue #1648: The cycle rule reads across calls through function summaries

Open and answer this issue on GitHub.

compiler, ready · opened 2026-11-15 · updated 2026-11-15 · 0 comments

Part of #1626. Step 3 of 5 of ADR-shared-handle-cycles-1. It rests on #1647 (the rule within one function).

Goal

After #1647, a store whose value comes from a call or a parameter of a self-reaching type is unknown, and an unknown store is refused. This issue gives every function a summary, so those stores are judged instead: correct programs that pass handles through helpers compile, and a cycle closed in a helper is still refused.

Governing decision

Probe (to run after #1647)

struct Node { name: String, next: SharedMut[Node]? }

fn link(from: SharedMut[Node], to: SharedMut[Node]) {
	from.update(fn(mut v) { v.next = to })
}

fn fresh(name: String) -> SharedMut[Node] {
	SharedMut(Node { name: name, next: null })
}

fn main() throws {
	let a = fresh("a")
	let b = SharedMut(Node { name: "b", next: a })
	link(a, b)
	print("built")
}

Done when

The probe is refused at the call, the variant compiles, the tests below pass, and measurement 5 of #1626 §9 is posted again: how many unknown refusals the summaries remove from #1647’s count.

To build

  1. Summaries in check_cycles.nika: for each function, compute its reach-and-store summary from the per-function walk of #1647, and solve them bottom-up over the call graph. Reuse the call graph and reach_index_of from check_doors.nika; no second call graph. Strongly connected parts of the call graph are iterated to a fixed point.
  2. Apply at calls: a call result reaches what the summary says of the arguments. A call that stores into a field of an argument counts as that store at the call site, so it is refused there when it closes a cycle. The note points to the store inside the callee.
  3. Conservative cases: generic functions (before instantiation), trait-object calls, function values and closures that are passed in. Summaries of instantiations are computed where check_program_instantiations_beside (check_program.nika) already visits them.
  4. check --cycles prints each function’s summary in one line under the type list of #1646.
  5. Tests in tests/compiler/tests/:
    • a_cycle_closed_in_a_helper_is_refused_at_the_call (the probe, .stderr);
    • a_handle_from_a_constructor_function_reaches_nothing (the variant, .stdout);
    • a_cycle_closed_through_mutual_recursion_is_refused (.stderr);
    • a_call_through_a_trait_object_is_judged_conservatively (.stderr);
    • a_generic_helper_that_links_handles_is_judged_at_its_instantiation (.stderr).
  6. Measurement 5, again: refusals per reason before and after, over crates/nikaia-std/src/tools/, packages/ and examples/. If #1647 held back the refusal at stop point 1, it is switched on here once unknown refusals of correct code are gone, and this issue says so.

The rule that repeats

Summaries over the call graph are also built for door reach (check_doors.nika) and lock order. Use the same graph and the same order of solving; do not add a third.

Files and limits

Ruled out

Back to Open Issues