Design decisions

5. State and effects

#DecisionStatusCurrent leanDepends onWhere
5.1Ownership modelSettledvariables own, params borrow, no pointers, mut at both endsplan/17-syntax.md
5.2Copies and movesSettledbig values need .copy(); last-use moves are implicitplan/17-syntax.md
5.3Precise borrow rulesSettled 2026-11-19, revised 2026-11-20 (v2.2)lexical exclusivity: no stored and no returned borrows (so no lifetimes); fields borrow separately; two lends of one projection are separate when @law disjoint is proven from flow facts (5.13; auto-derived for trivial single-index forwarding); copyable element reads release borrows immediately before enclosing calls; a[idx].f = rhs, ??=, and compound assignments evaluate all index expressions and rhs before borrowing the mutable place in a; for mut and .absorb() deleted; .swap(i, j), O(1) swap, .take(), and mutable subslices handle same-container/small-to-large cleanly5.1§18.4, §19.4, §19.8
5.4Inline closures reusing a caller's mut borrowRevised 2026-11-20 (v2.2)yes: closure args and lends/yield carry inline-desugaring semantics automatically; inline keyword deleted5.3§19.1, research/archive/RECOMMENDATIONS.md §1
5.5Moves out of arraysSettled 2026-11-20swap, take (leaves default) and pair_mut are library fns over at, allowed by its disjoint law; no partial moves5.13plan/19-index-and-lends.md §3.6
5.6Pools and handlesDeleted 2026-11-20 (v2)Replaced by type Id = 0..=MAX + List<Node> + .push_id(x) + .freeze() (see 2.7)2.7§16, research/archive/audits/subtraction-audit-1.md Cut 6
5.7deferDeleted 2026-11-20 (v2.2)Removed (1/642 ports, active bug in search-and-keep backtracking); use explicit 1-line dsu.undo_to(snap) or cur.pop()§19.1, research/archive/audits/subtraction-audit-2-v21.md §2.1
5.8Rollback, undo, withRevised 2026-11-20 (v2.2)undo, with, and defer deleted; rollback is a plain 2-method struct API (let snap = dsu.mark(); ...; dsu.undo_to(snap))5.7§16, §19.1
5.9@memo controlRevised 2026-11-20 (v2.2)Bare @memo only (@memo(flat)/@memo(hash) deleted): auto-dispatches flat niche-packed [Params]?R for any value return type up to 2^24 (2^26 for ?Bool/Bool), else salted flat hash; nested @memo scoped to enclosing fn/loop iteration; permits ask(...) and deterministic extern @grader fn oracles (exact 1 call per arg tuple); forbids mutated captured vars and read()/print()2.16§16, §19.3, §19.9
5.10Nested fn mutation (mut fn deleted)Revised 2026-11-20 (v2)mut fn deleted. Any nested fn declared after a var reads/writes it directly; the compiler tracks captured borrows automatically and forbids escaping5.3§16, research/archive/audits/subtraction-audit-1.md Cut 3
5.11Keeping the borrow rules understandableSettled 2026-11-19 (the method; the rules stay open to change)fresh agents repeatedly search for the smallest programs where a borrow rule surprises; each one changes the rule or its error message and is kept as a test5.3plan/agent-context.md
5.12Projections: lends (tail expression)Revised 2026-11-20 (v2.2)fn row(self, r: A) lends mut [B]T lends via its tail expression or return mut place (lend keyword deleted). Post-lend write-back lets SegTree/LazySegTree repair invariants after mutations5.3, 5.4§16, §19.1
5.13@law disjointRevised 2026-11-20 (v2.2)law demoted from hard keyword to @law (@law disjoint(i, j) = i != j); trivial single-index forwarding (mut self.data[i.to_idx]) auto-derives disjoint. Two live lends of one projection on one receiver, one mut, need the law proven from flow facts (if, while, assert, value ranges)3.4, 5.12§19.1, plan/19-index-and-lends.md §3.6
5.14Lent values are second-classSettled 2026-11-20a value built from lent parts is lent and lives only in the block that made it: it may be passed, bound by let, iterated and lent onward; not put in a var, a field or a container, captured by a non-inline lambda, or returned. Borrowed-ness is a mode of the binding, not a type, so there is no view keyword5.3plan/19-index-and-lends.md §3.5