Issue #1649: The cycle check proves a field that points back to a parent and chooses a reference or a weak handle for it

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

Goal

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).

Governing decision

Probe (to run after #1648)

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" }))
}

Done when

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.

To build

  1. Find candidates in 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.
  2. Choose F1 or F2: F1 where the holder never escapes the target’s lifetime, which means it is only reachable through the target’s forward edges (no other handle to it is stored or returned). Otherwise F2, if the field is optional. A non-optional field that is not proved for F1 stays refused with NK1352, and the note says: “make it optional, or use an index”. check --cycles names every back field with F1/F2.
  3. Tests in 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.

Files and limits

Ruled out

Split (2026-11-21)

Comments

keywan-ghadami, 2026-11-21

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:


Generated by Claude Code

Back to Open Issues