# RFC 0023: Whole-value linear aggregates Status: Implemented Scope: STD-5, vertical source/AIR/verifier/interpreter phase; AIR format 0 Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. ## Motivation Resources need explicit compositional ownership. The preserved invariant is that every normal path consumes each nested owner/resource exactly once, never hides allocation/destruction and never leaves a partial object. Q-035 resolves the scope in spec 03 §25, spec 07a contracts and source spec 15 §16. Ownership type graphs are acyclic; iref graph edges remain opaque. Dynamic linear buffers, partial moves and bulk resource cleanup require a separate collection storage contract. ## Verifier and runtime Structural linearity flows through struct/enum/fixed-array members. Constructors move inputs; whole unpack/enum take move complete components; ordinary copying/overwriting and freeing linear contents reject. Whole-value availability and existing alias/task-loan state suffice. own.pack failure returns the original value; value.swap returns the replaced value, leaving an initialized place. Interpreter handle transfer, explicit budgets, fuel and race checks are deterministic, with no destructor. Existing diagnostics are reused; no new effect/capability/trap is added. ## Valid and rejected examples Valid source constructs an owned field, unpacks the struct and calls own.take exactly once. Rejected counterparts copy a linear field, move one value twice, leak a component or consume an aggregate while borrowed. AIR/source fixtures cover both, plus allocation failure, enum none/some, arrays, exchange and task transfer. The checked positive example is examples/std/owning-option.aji. The following minimal pair exposes the ownership repair: ```aji struct Item { owner: own } fn main(heap: cap) -> u64 effects [mem.alloc] { let owner = own.new(42u64, heap) or trap; let item = Item { owner: move owner }; let (part) = struct.unpack(move item); return own.take(move part); } ``` Replacing `(part)` with `(_)` and returning `42` MUST reject E3002: the component is still owned. Repair by consuming it explicitly, as above. Copying `item.owner` MUST reject E1001; passing `item` to unpack without move MUST reject E7003. The AIR counterparts are linear/struct.air, copy.air, field.air and leak.air; source twins live in source/linear/ and source/quickref/linear.aji. ## Compatibility linear_aggregates was reserved; previously accepted Copy modules retain canonical spelling and ownership behavior. Individual own> borrowing now follows its already-specified array place type rather than being misrepresented as a repeated own_array slice; a baseline-feature AIR regression covers this runtime correction. New instructions are additive under the registered feature. Guard/task-transfer gates, transitive channel_transfer restrictions, second-class borrows and IslandSafe graph contents remain unchanged. Owning option/result use explicit ordinary enum matching; classification helpers retain Copy constraints. Source diagnostics for forbidden Result borrow payloads now come from ordinary member validation (E1001 rather than the removed enum Copy constraint E7005). Owner acceptance remains separate from branch implementation. ## Agent complexity impact New concepts: structural whole-value linearity, exhaustive unpacking, failure returning ownership and replacement returning old ownership. New verifier transfer state: none; ordinary availability/borrow state applies to aggregates. New source forms: ordered array literal and aggregate unpack calls with ordered multi-binding; existing move/match/outcome/borrow syntax composes. Five new AIR operation families expose transfers which Copy-only primitives cannot express. array.make also resolves Q-025: Copy-only frame stores and splat cannot assemble distinct linear elements, so this operation provides a new ownership transfer rather than solely syntax sugar. No per-field holes, implicit drop, trait inference, new effects or capabilities. Explicit errors retain direct repairs. Source/AIR/Quick Reference growth and final verification are recorded below; no MCC benefit is assumed from implementation or fixtures. ## Instruction and diagnostic contract Spec 07a gives operand/result types, ownership transfer, memory/synchronization, capabilities/effects, traps and verifier state for all five families. New operations require the published linear_aggregates feature and full dependency closure; own.pack additionally requires heap, and array forms require arrays. Existing format-0 constructs retain meanings; new opcodes extend only previously unsupported cases. own.pack carries T explicitly to account for differently sized owning handles without runtime guessing. No new diagnostic code is added. E1001 covers illegal copying, member/storage types and overwrite/free; E1003 covers cyclic ownership type graphs; E2001/E2002 cover use/repeated consumption; E3002 covers missing consumption; E2101/E4101 preserve alias/task-loan exclusion; E5002 covers complete continuation/variant shape; E7003/E7005/E7006 retain explicit move and source shape checks. Guards, task handles/scopes and borrows retain separate gates. Atomic cells continue to reject ordinary exchange through an atomic pointee (E4202). Normal paths require consumption; traps terminate without hidden resource cleanup, under the existing profile contract. The runtime transfers handles in initialized values, returns the original on failed allocation and performs exchange as one instruction. Borrowed SSA roots retain identity across whole replacement and tracing collection, including enum tags and fixed arrays. This uses internal frame-backed cells, not a new source allocation or verifier state. Structural Send/Share and synchronized-cell/channel rules remain authoritative; a task loan excludes exchange until join. Allocation charges and fuel/scheduler choices stay deterministic. ## Validation Required build, unit tests, formatter check, source coverage and agent-reference checks pass (88/88 source constructs). Full conformance and forced-collection schedule stress pass; source/linear/task, channel and task_loan_join run 32 seeds per stress quantum. A 1,000-exchange loop with an eight-byte authority verifies explicit consumption, bounded live ownership and collection relocation. Long interpreter memory tests, hosted filesystem/stdin/TCP smoke and source CLI integration also pass. Canonical parsing/printing covers the new families; CLI integration covers success/failure ownership, imported nominal generic payloads, run/check/report/explore and ordinary diagnostic repair. Existing module and generic CLI suites pass (36 and 20 checks); new linear CLI integration passes 49 checks. File and Arc member fixtures explicitly borrow their fields through named bindings, following the existing intrinsic API. A payload-free owning Option that is never consumed still rejects E3002. ## Measured documentation cost Relative to STD-4, using tools/agent_bundle_tokens.py --source after zig build agent-reference: | Group | cl100k | o200k | Qwen2.5 | |---|---:|---:|---:| | Quick Reference | 6,948 → 7,225 (+4.0%) | 6,972 → 7,251 (+4.0%) | 7,172 → 7,455 (+3.9%) | | Other source docs | 41,086 → 42,364 (+3.1%) | 41,212 → 42,496 (+3.1%) | 42,228 → 43,548 (+3.1%) | | Full source without AIR | 48,034 → 49,589 (+3.2%) | 48,184 → 49,747 (+3.2%) | 49,400 → 51,003 (+3.2%) | | AIR docs | 42,454 → 43,966 (+3.6%) | 42,602 → 44,114 (+3.5%) | 43,827 → 45,403 (+3.6%) | AIR grows from 160,797 to 168,336 bytes (+4.7%), 19 files and 49 selected sections. New on-demand language/linear-aggregates.md is 1,133 cl100k tokens; library/std.md is 8,398. Quick Reference exceeds its 4–6k target. This growth buys explicit complete ownership transfer and recoverable allocation ownership, rather than per-field holes/destruction state. Cumulative full source growth from the pre-stdlib 33,981-token baseline is approximately 45.9%; front-door consolidation remains separately needed. Documentation growth and successful fixtures do not establish MCC improvement. No private held-out tasks or former smoke M/C guided this design or validation. ## Next boundary Q-036 remains open for STD-6: dynamic storage needs initialized length, move extraction, failure-preserving growth and explicit drain before free. This RFC completes whole-value aggregates, not Vec or Std 0.1. Bulk frame/region/repeated heap storage remains Copy-only; recursive owning type graphs remain rejected. Those limits are explicit rather than implemented with partial-state heuristics or implicit destructors.