Index and Field Assignment via Copy-on-Write Desugaring

5 sections

21%
Overview

Implement index and field assignment syntax (list[i] = x, state.name = x, mixed chains state.items[i] = x / list[i].name = x, nested grid[x][y][z] = v, compound list[i] += 1) as type-directed copy-on-write desugaring. list[i] = x desugars to list = list.updated(key: i, value: x) via the IndexSet trait; state.f = x desugars to state = { ...state, f: x } via struct spread. Under ARC at refcount==1 (the common local-binding case) the copy is optimized to in-place mutation. Root binding must be mutable (non-$, not a parameter, not a loop variable).

Planned

5 sections
Section 1 Not Started

IndexSet trait + updated method + ARC copy-on-write

Define the IndexSet<Key, Value> trait in the prelude, register updated as a built-in method on [T] / {K: V} / [T, max N], and implement it with ARC-aware copy-on-write (in-place at refcount==1, clone-then-mutate otherwise). The desugar in section-03 lowers index assignment to updated calls, so the trait + method must exist first.

8/8 tasks
Section 2 Not Started

Parser — assignment_target grammar + AssignTarget AST node

Extend the parser to accept assignment_target (identifier followed by any chain of index `[expr]` and field `.ident` accesses) on the LHS of `=` and compound operators, emitting a SINGLE AssignTarget AST node capturing the chain. The parser stays syntax-only: no desugaring at parse time (type-directed desugar is section-03); complex targets are NOT duplicated.

0/9 tasks
Section 3 Not Started

Type-directed desugar + IndexSet resolution + validation + diagnostics

In the TYPE CHECKER (ori_types) — NOT canon — desugar every AssignTarget chain into updated() calls (index steps) and struct spreads (field steps), reassigning the root binding; resolve IndexSet trait impls; validate root-binding mutability, field membership, key/value types; emit the proposal's diagnostics. This is the dominant phase and closes BUG-04-129 (the E4003/E6080 unimplemented-desugar symptom).

0/8 tasks
Section 4 Not Started

Spec + grammar.ebnf sync

Sync grammar.ebnf (assignment_target production) and the affected spec clauses (13-variables, 09-properties-of-types, 14-expressions, 21-memory-model) via /sync-grammar + /sync-spec — NEVER direct edit. grammar.ebnf + the spec clauses (sourced from the APPROVED index-assignment proposal) are authoritative; /sync-grammar + /sync-spec update the spec docs to that approved surface, and the implementation (sections 01-03) conforms to them — never 'impl is the source of truth' (spec-is-SSOT per CLAUDE.md: implementation divergence is a compiler bug, never a reason to weaken the spec).

0/7 tasks
Section 5 Not Started

Spec test corpus + dual-execution parity + error cases

Complete the spec test corpus for index/field assignment (simple, nested, field, mixed chains, maps, compound, errors), verify dual-execution parity (interpreter == LLVM) on every case, and pin every error case with #compile_fail. Sections 01-03 add their own focused tests; this section is the comprehensive matrix + the rosetta-dogfood regression that motivated the work.

0/6 tasks