cli: add whole-value linear aggregates
Implement STD-5 through source, AIR, verifier and deterministic interpreter. Constructors consume nested owners; exhaustive unpack/take, explicit swap and own.pack preserve ownership on success and failure. Support owning Option and Result while keeping classification helpers Copy-only. Preserve borrow identity across whole replacement and collection; distinguish individual owned arrays from repeated heap arrays. Specify feature contracts, invariants, diagnostics, compatibility and measured source/AIR budgets in RFC 0023 and normative docs. Add canonical round trips, AIR/source acceptance and rejection fixtures, CLI integration and CI checks. Validate build, unit/extended tests, full conformance, forced-collection schedule stress (32 seeds per quantum), hosted smoke, CLI suites, source coverage (88/88), formatting and reference bundle generation. Source bundle grows 3.2%; Quick Reference grows 4.0%. No MCC improvement is claimed. Dynamic initialized linear buffers and explicit drain remain Q-036/STD-6; frame/region/repeated heap storage is Copy-only. RFC remains Proposed.
This commit is contained in:
109 files changed
+1814
-142
No files matched your search
@@ -252,7 +252,7 @@ Invariants:
|
||||
3. **No dangling access.** Heap and region memory is reached only through second-class borrows, which cannot outlive the owner (heap) or the region generation (regions). There are no runtime generation checks.
|
||||
4. **Bounded memory.** Every allocation is charged against a budget held by the authority object of the capability. The budget limits the bytes that are **live at the same time**.
|
||||
5. **Shared quota.** Copies of a capability refer to one authority object and share one budget; narrowing creates a child budget whose charges also count against every ancestor.
|
||||
6. **No hidden destruction of linear values.** `own.free`, `own.take`, `region.reset` and `region.destroy` can never make a linear value disappear: until `linear_aggregates` is specified, values stored in `own<T>`, `own_array<T>` and region allocations MUST NOT transitively contain linear values (resources, owners, regions).
|
||||
6. **No hidden destruction of linear values.** `own.free`, `own.take`, `region.reset` and `region.destroy` can never make a linear value disappear: Copy-only allocations retain this restriction. Feature `linear_aggregates` permits individual `own<T>` content with ownership-preserving `own.pack`/`own.take` (§25); own.free and bulk arrays/regions cannot destroy linear content.
|
||||
|
||||
### 18.1 Budget semantics
|
||||
|
||||
@@ -313,7 +313,7 @@ Both are linear and not copyable; as members of aggregates they need `linear_agg
|
||||
|
||||
Heap memory is always initialized, so no initialization tracking is needed. `own.free` or `own.take` while a borrow of the owner is live is `E2101`. `own.take` is the inverse of `own.new` (`T → own<T> → T`); an `own_array<T>` has no `take`, since a runtime-sized array is not an SSA value.
|
||||
|
||||
`T` in `own<T>` and `own_array<T>` must be a value type; a linear `T` (for example `own<file<read>>` or `own<own<u64>>`) needs `linear_aggregates` (`E0006` reason `feature_not_declared`), which will define extraction and destruction of nested linear values. An owner is passed to a function by value (moving it) or by borrow (lending it), exactly like a resource.
|
||||
`T` in baseline `own<T>` and in `own_array<T>` must be Copy. Linear `T` in individual `own<T>` needs `linear_aggregates` (`E0006` reason `feature_not_declared`), whose whole-value extraction/allocation rules are §25; bulk linear heap arrays remain unsupported. An owner is passed to a function by value (moving it) or by borrow (lending it), exactly like a resource.
|
||||
|
||||
## 20. Regions in AIR (feature `regions`)
|
||||
|
||||
@@ -370,7 +370,7 @@ Decision record: RFC 0014. Depends on `heap` and its closure.
|
||||
- `island<T>`: a graph owner; linear; `Send`, not `Share`.
|
||||
- `iref<T>`: an opaque `{graph identity, slot}`; copyable, `IslandSafe`, `Send`, `Share`.
|
||||
|
||||
Graph owners may be parameters, returns, block arguments, channel elements and mutex contents. They may not be aggregate members (`linear_aggregates` stays reserved).
|
||||
Graph owners may be parameters, returns, block arguments, channel elements and mutex contents. Their membership in aggregates requires `linear_aggregates` (§25); it does not weaken IslandSafe graph-content rules.
|
||||
|
||||
**Identity.** A graph's identity comes from a per-execution counter and is never reused. A handle cannot be built from, cast to or inspected as an integer.
|
||||
|
||||
@@ -445,3 +445,15 @@ The count is not a user atomic: no memory ordering is chosen by the program. Eac
|
||||
| `frozen.release` | − the graph |
|
||||
| `island.destroy` | − the graph |
|
||||
|
||||
|
||||
## 25. Linear aggregates in AIR
|
||||
|
||||
Feature `linear_aggregates` permits resources, owners, regions, graph owners, atomic cells, channel endpoints and mutexes as struct fields, enum payloads and fixed-array elements. Borrows/storage, task/scope/shield and guards MUST NOT become aggregate members; their existing gates remain. A declared aggregate or fixed array is linear exactly when any transitive member is linear. All variants contribute to an enum's class, including a payload-free variant. Copy remains structural. Ownership type graphs through aggregate members and owning wrappers MUST be acyclic (E1003); `iref` graph edges remain opaque. This initial feature does not add partial moves, holes, automatic cleanup or dynamic linear buffers.
|
||||
|
||||
Construction (`struct.make`, `enum.make`, `array.make`) MUST consume every linear input exactly once and produce one complete owned value. Every normal path MUST transfer or fully unpack that value; no nested resource may disappear. Copy projections of a live linear struct are allowed, but projecting a linear field with `struct.get`, or duplicating a linear value with `copy`, `load`, `local.load`, `array.splat` or `slice.copy`, MUST reject E1001. Ordinary `store` MUST NOT overwrite linear content. Borrowed fields/elements use existing exclusive/shared alias and task-loan rules; `value.swap` exchanges a complete initialized value with an explicitly supplied replacement and returns the previous value. No field is ever uninitialized.
|
||||
|
||||
`struct.unpack` and `array.unpack` consume their whole operand and deliver every field/element in declaration/index order to one continuation. `enum.take` consumes its whole enum and delivers the selected payload to an exhaustive variant continuation. It MUST have every variant exactly once and no default. Payload-free variants still consume the enum. Copy operands may also be unpacked; they remain available. Existing `enum.switch` remains observational and MUST NOT read a linear enum. Existing linear diagnostics E2001/E2002/E3001/E3002 apply to moved, repeated or missing consumption, with E2101/E4101 for live borrows/task loans.
|
||||
|
||||
Among heap/frame/region storage forms, only individual `own<T>` may hold linear aggregate content in this phase; channels and mutexes retain their existing complete-value transfer rules. `own.pack` explicitly moves a value into an individually owned allocation: on failure, the error continuation receives both alloc_error and the original complete value. `own.take` consumes the owner, frees the allocation and returns its complete content, including all nested owners/resources. `own.free` MUST reject E1001 when content is linear. Repeated heap arrays, region allocations and frame locals MUST remain Copy-only; bulk freeing cannot destroy resources. Dynamic linear buffers require a separate feature/API with an explicit drain contract. Existing heap/region operations on Copy values retain their semantics.
|
||||
|
||||
Verifier state is whole-value availability, existing borrow provenance and initialization, with no per-field moved state. Structural Send/Share still apply, so transfer to workers/channels/mutexes requires their ordinary rules. The deterministic interpreter moves existing handles, performs swaps as one instruction and uses existing allocation budgets/fuel; it performs no user cleanup on normal paths or traps. AIR format 0 remains compatible: previously unsupported feature/type/opcode cases gain meanings; previously accepted Copy modules keep identical behavior.
|
||||
Reference in new issue
Block a user