Open and answer this issue on GitHub.
compiler, ready · opened 2026-11-15 · updated 2026-11-21 · 1 comment
Part of #1626. Step 4 of 5 of ADR-shared-handle-cycles-1. It rests on #1648 (function summaries). Needs #1648 Needs #1647 Needs #1646
After #1647 and #1648, a tree whose children hold a link to their parent is refused, because it is a cycle. With this issue the compiler proves such a link is a back field and lowers it so that it does not keep its target alive. The user writes the plain field and nothing else. The order: parent links first, then doubly linked lists, then observer pairs.
This issue builds the first part, the proof and the choice of F1 or F2 in the cycle check; the lowering, the other shapes and the measurements are split off (below).
null once the target is gone. Used only for optional fields (T?), where outliving is not proved.parent: SharedMut[Node]?. No keyword, no Weak. Weak[T] written by hand is a separate decision (D5).std::rc::Weak for SharedMut, std::sync::Weak for Locked.struct Node { name: String, parent: SharedMut[Node]?, children: List[SharedMut[Node]] }
fn add_child(p: SharedMut[Node], name: String) -> SharedMut[Node] {
let c = SharedMut(Node { name: name, parent: p, children: [] })
p.update(fn(mut v) { v.children.push(c) })
c
}
fn main() throws {
let root = SharedMut(Node { name: "root", parent: null, children: [] })
let a = add_child(root, "a")
print(a.read(fn(v) { v.parent?.read(fn(p) { p.name }) ?? "none" }))
}
NK1352 at the store v.children.push(c), because c reaches p through parent.root. parent is a back field (F2: optional, and c can be handed out and outlive root). Run under valgrind, it loses no bytes.nikaia check --cycles on the probe names Node.parent as a back field, F2, and refuses no store; the two refusal tests of item 3 pass; the commit that builds item 3 writes Fixes #1649.
check_cycles.nika (an output of #1646): in each cycle that #1646 reports, a field whose stores all write a value that dominates the holder (the holder was built from the target, or the target is a parameter the holder was built with). Domination uses the reach sets of #1647 and the summaries of #1648.NK1352, and the note says: “make it optional, or use an index”. check --cycles names every back field with F1/F2.tests/compiler/tests/: a_back_field_that_is_not_optional_and_not_proved_is_refused (.stderr) and a_link_that_does_not_point_back_is_still_refused (.stderr: a store that only looks like a parent link); and the check --cycles output on the probe naming Node.parent F2.check_cycles.nika (an output of #1646; the compiler’s .nika files live in crates/nikaia-std/src/compiler/, no longer src/tools/), its lowered .rs; the new tests.nikaia check on the compiler may grow by at most 5 % over #1648’s figure (measured in the last part).weak: D3, the user writes nothing.Split into run-sized issues (2026-11-21).
Found built: none of the seven items. No commit names this issue, and the work it rests on (#1646, #1647, #1648) is still open; check_cycles.nika does not exist yet. The body said it rests on #1648 but had no Needs line, so the driver could have queued it early: Needs #1648, Needs #1647 and Needs #1646 are now at the top.
Where the items went:
check --cycles naming each back field, moved here from old item 3) and the two refusal tests of old item 4. Title narrowed to match.Generated by Claude Code