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:
dev committed 2026-10-06 21:23:52 +03:00
1 parent 7eea31518d
commit 4f084decce
109 files changed
+1814 -142

No files matched your search

+15 -3
View File
@@ -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.
+2 -2
View File
@@ -368,7 +368,7 @@ Any other `T` is `E1001`: 128-bit integers, aggregates, references, owners and h
`atomic<T>` is **linear**, `Send` and `Share`, and not copyable.
- It may appear where graph owners may (spec 03 §22): SSA values, parameters, returns, block arguments, channel elements and mutex contents.
- As an aggregate member or as the contents of `local`, `own` or a region it needs `linear_aggregates` (`E0006`).
- As an aggregate member or individual own<T> content it needs `linear_aggregates` (spec 03 §25; E0006 without it). Frame/bulk-region/heap-array content remains Copy-only.
- It is not `IslandSafe` (`E2111`).
- Size and alignment equal those of `T`.
@@ -718,7 +718,7 @@ Decision record: RFC 0012. Depends on `cancellation`, `heap`.
| `sender<T>` | a sending endpoint | linear |
| `receiver<T>` | the receiving endpoint, exactly one per channel | linear |
Endpoints may be block arguments, function parameters and return values, and may be moved into tasks. They may not be aggregate members (reserved `linear_aggregates`) or heap contents. Channels are MPSC: several receivers are the reserved feature `receiver_dup`.
Endpoints may be block arguments, function parameters and return values, and may be moved into tasks. Aggregate membership and individual own<T> content require `linear_aggregates` (spec 03 §25); bulk heap arrays remain Copy-only. Channels are MPSC: several receivers are the reserved feature `receiver_dup`.
**Element rules** for `T` (also used by `mutex<T>`, §40):
+1 -1
View File
@@ -87,7 +87,7 @@ The mode of a file is part of its type, so using a file in the wrong mode is a v
Resource types are **linear** and **authority-bearing** (spec 05 §10.1): not copyable (`copy` is `E1001`), not zeroable, not comparable, not serializable.
In format 0, resource types MUST NOT appear as struct fields, enum payloads or array elements; that requires the reserved feature `linear_aggregates` (`E0006` reason `feature_not_declared` without it). They may appear as function parameters, return types, block parameters and as operands of borrow instructions.
Resource types as struct fields, enum payloads or fixed-array elements require `linear_aggregates` (spec 03 §25) (`E0006` reason `feature_not_declared` without it). They may appear as function parameters, return types, block parameters and as operands of borrow instructions.
### 6.2 Consumption
+2 -2
View File
@@ -222,7 +222,7 @@ Features describe what the implementation must understand. They grant no authori
- Integer types, `bool`, `void` and `never` are built in. `usize`/`isize` are distinct from all fixed-width types; their width comes from the target description (spec 09 §9).
- `type @T = struct { … }` and `type @T = enum { … }` declare nominal aggregate types. An aggregate MUST NOT contain itself by value, directly or through other aggregates (`E1003`).
- Every type defined in this section is copyable. Types added later under §8.7 (for example `Own<T>` in Phase 1) may be move-only or linear; that does not change the types defined here.
- Baseline aggregate types are Copy. Under `linear_aggregates`, newly permitted linear members make structs/enums/fixed arrays linear structurally (spec 03 §25); baseline Copy aggregates retain their semantics.
- `void` is only valid as a function return type. A `void` function returns with `ret` without operand; a call to it MUST NOT bind a result. A `never` function MUST NOT contain `ret`.
### 8.4 Reserved
@@ -289,6 +289,6 @@ Feature membership: `local<T>`, `ref<T>`, `mut<T>` and the `from` clause belong
**Second-class rule.** Storage and borrow types MUST NOT appear as struct fields, enum payloads, array elements or the `T` of another storage or borrow type (`E1001`). A storage type MUST NOT appear as a function parameter, return type or block parameter (`E1001`). A borrow type MAY appear as a function parameter and, with `from`, as a return type (spec 08 §11.3). As a block parameter type it requires the reserved feature `borrow_joins` (spec 08 §11.6).
All value types of format 0 and Phase 1 are copyable. Move-only values arrive with `heap` in Phase 2.
Baseline value types are Copy; owners/resources and feature-gated linear aggregates obey whole-value consumption (spec 03 §25).
Syntax additions (reference/air-text.ebnf): `-> type from %param` on function signatures, the type forms above, and `%a, %b = op` for instructions specified with two results (`slice.split`; `atomic.cmpxchg` with feature `atomics`, spec 04 §42).
+25 -1
View File
@@ -6,7 +6,7 @@ This file covers the format-0 baseline (Phase 0) and the features `ownership` an
## Common contract for format version 0
All format-version-0 instructions operate on copyable values only. Unless an entry says otherwise:
The baseline instructions operate on Copy values; feature-specific contracts below specify linear ownership. Unless an entry says otherwise:
| Field | Value |
|---|---|
@@ -309,3 +309,27 @@ Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (capture
- every entry of `files`: always `{"encoding":"base64","data":"…"}`, since file contents are arbitrary bytes.
Base64 is RFC 4648 with padding. Two records are equal exactly when their bytes are equal. When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
## Linear aggregates (`linear_aggregates`)
These contracts specialize ownership of newly enabled linear member types; baseline Copy instructions keep their prior semantics. All instructions require `linear_aggregates`; an array type also requires `arrays`, and `own.pack` also requires `heap`. Existing feature dependency closures apply.
### `array.make array<T, N>(%v0, …, %vN-1)`
Operands MUST be exactly N complete values of T (E1001). Result is array<T,N>. Linear inputs are consumed, each exactly once; Copy inputs remain available. Memory, synchronization, effects, capabilities and traps: none. Interpreter assembles elements in order. Verifier marks a linear result available. Normal SSA/size/argument limits apply.
### `struct.unpack @S %value, next -> @block` and `array.unpack array<T,N> %value, next -> @block`
Operand MUST have the named struct/array type. No SSA result; the sole continuation MUST have all field/element parameters of exactly those types in order (E5002 counts, E1001 types). The whole linear operand is consumed and linear parameters become available; Copy operands remain available. Memory, synchronization, effects, capabilities and traps: none. Interpreter transfers every component and jumps. Block-parameter/size limits apply; there are no ignored components.
### `enum.take @E %value, Variant -> @block, …`
Operand MUST be the named enum type; every variant MUST appear exactly once with no default (E5002). No SSA result; target payload types/counts follow ordinary enum.switch rules. It consumes a linear operand and transfers its selected complete payload; Copy operands remain available. Memory, synchronization, effects, capabilities and traps: none. Interpreter selects the tag deterministically. Existing enum.switch MUST reject E1001 for a linear enum.
### `%old = value.swap %borrow, %replacement`
Operands MUST be mut<T> and T; T MUST be an initialized value, never a borrow/storage/function-bound value (E1001). Result T. A linear replacement is consumed; a linear result becomes available. The borrowed place remains initialized with the complete replacement. Reads/writes: the whole place; exclusive alias and task-loan rules apply (E2101/E4101). Synchronization, effects, capabilities and traps: none; swapping an atomic cell through an ordinary borrow remains forbidden (E4202). Interpreter exchanges whole values in one instruction, retaining existing race instrumentation.
### `own.pack T %value, %cap, ok -> @success, err -> @failure`
Operands MUST be complete T and cap<mem.alloc> (E1001/E3201); T may be Copy or linear. No SSA result; success receives own<T>, failure receives (alloc_error,T) (E5002/E1001). Linear input is consumed on both edges; success owns it inside the allocation, failure owns the same original value. Memory: new allocation initialized with the complete value on success; none on failure. Effects: mem.alloc. Capability: explicit bounded mem.alloc. Synchronization/traps: none; ordinary alloc_error failure reasons/budget rules apply. Interpreter transfers handles without duplicating ownership and charges/frees the same accounted bytes as own.new/own.take.
+14 -4
View File
@@ -199,7 +199,7 @@ The value is evaluated first, then the place is borrowed for the store and the b
**Arrays and byte strings.**
- `[e; N]` evaluates `e` once and copies the value N times (`array.splat`). The element must be copyable; a linear element is `E7006`.
- `[e; N]` evaluates `e` once and copies the value N times (`array.splat`). The element must be copyable; a linear element rejects (E1001 for the §16 surface).
- `b"…"` is an immutable `[u8; N]` value held in frame storage, written there byte by byte, with no heap. The escapes are exactly `\n \r \t \\ \" \0 \xNN`.
- Used where a `slice<u8>` is expected, it is borrowed for the operation.
@@ -362,7 +362,7 @@ Passing the region itself is `E7005`; the frontend never creates a temporary reg
**Container borrows are explicit, as for regions.** `.root`, `.at` and `island.alloc` take a named borrow binding of the graph's owner (`mut g = isl;`), which outlives the borrows derived from it. Passing the owner itself is `E7005`, with a hint. A container borrow written inline is `E7006`. `island.at`, `frozen.at` and `arc.at` appear only as the place of a `ref`/`mut` binding (`E7006` elsewhere).
**Linear aggregates.** A struct or enum with a linear field (`own<T>`, `region`, a resource) needs the reserved feature `linear_aggregates`. The frontend lowers it as written and the AIR is rejected (`E0006`) until that feature is published.
**Linear aggregates.** A struct, enum or fixed array with linear members follows §16 and spec 03 §25. The frontend declares `linear_aggregates` and lowers complete explicit ownership transfers.
A byte string or array used where a `slice<u8>` is expected is materialized in frame storage and borrowed for the operation.
@@ -505,7 +505,7 @@ Module names use source paths. The first component of a package mapping MUST NOT
A module sees its own functions and types by short name, and declarations of directly imported modules by full path. Imports MUST NOT inject short names, aliases or transitive visibility. An entry outside reserved built-in namespaces can also qualify its own declarations with its module name; built-in operations retain precedence. An inaccessible or unknown function/type/member is `E7002`, even if a different module linked the declaration. Qualified names resolve by module identity, independently of local bindings with the same prefix. A value may have a type inferred from a directly imported function contract without importing that type's defining module; spelling the type or its constructors by name still requires a direct import. Module-local calls MUST NOT capture an entry's similarly named function; named types from different modules are nominally distinct.
Type annotations and wrappers use qualified types, for example `app.model.Pair`, `ref<app.model.Pair>` and `[app.model.Pair; 2]`. Enum construction/patterns use `app.model.Result::ok(value)`. Qualified struct construction is `app.model.Pair { a: 1, b: 2 }`, with existing field typing/completeness and ownership rules. The final component must begin with an uppercase ASCII letter, as for current short-name struct literals. Struct literals remain forbidden in unparenthesized conditions, where `{` starts a block. This adds no methods, reflection or permission to store forbidden linear/borrowed values in aggregates. Generic forms are specified separately in §15.
Type annotations and wrappers use qualified types, for example `app.model.Pair`, `ref<app.model.Pair>` and `[app.model.Pair; 2]`. Enum construction/patterns use `app.model.Result::ok(value)`. Qualified struct construction is `app.model.Pair { a: 1, b: 2 }`, with existing field typing/completeness and ownership rules. The final component must begin with an uppercase ASCII letter, as for current short-name struct literals. Struct literals remain forbidden in unparenthesized conditions, where `{` starts a block. This adds no methods, reflection or permission to store forbidden borrowed values in aggregates; linear members follow §16. Generic forms are specified separately in §15.
A qualified named function MAY be passed as the function operand of `task.spawn(scope, app.work.run, ...)`. Existing Send/effect/structured-lifetime rules still apply; there is no function value, dynamic dispatch or detached task. All other calls use the existing argument, borrow, move, failure and effect rules.
@@ -523,7 +523,7 @@ Functions, structs and enums MAY declare 1–8 type parameters immediately after
Every generic use MUST supply exactly its ordered type arguments. Type annotations use `Pair<u64>`; expression applications use `identity::<u64>(42)`, `Pair::<u64> { left: 20, right: 22 }` and `Option::<u64>::some(42)`. Enum patterns use `Option::<u64>::some(value)` and `Option::<u64>::none`. The `::<...>` spelling separates generic application from comparisons; bare `f<T>(...)` is outside the expression grammar. Qualified forms obey §14's direct-import rules. `task.spawn(s, worker::<u64>, ...)` statically specializes the worker; this creates no function value. Existing `channel.make<T>(...)` retains its spelling and single type argument.
Type parameters are substituted in types, casts, declarations, explicit applications and enum/struct constructors/patterns, including nested templates. A parameter used as a constructor requires its own explicit concrete type arguments if that concrete type is generic; parameters are types, not values or operations. Type arguments MUST be concrete source types after substitution, excluding `void` and `never`. Ordinary type-position, layout, ownership and capability restrictions still apply to every emitted specialization; generics MUST NOT enable linear or borrowed aggregate members.
Type parameters are substituted in types, casts, declarations, explicit applications and enum/struct constructors/patterns, including nested templates. A parameter used as a constructor requires its own explicit concrete type arguments if that concrete type is generic; parameters are types, not values or operations. Type arguments MUST be concrete source types after substitution, excluding `void` and `never`. Ordinary type-position, layout, ownership and capability restrictions still apply to every emitted specialization; generics MUST NOT bypass the member restrictions; linear members require §16, and borrowed aggregate members remain forbidden.
Templates are parsed and declaration parameter/constraint/duplicate rules, signature type names/arity, effects and the prohibition of trusted clauses are checked even if unused. Generic bodies are type/ownership/effect checked for each required concrete specialization, not abstractly proved for all possible arguments. An unused template body has no emitted code and no runtime effects; successful checking does not claim it is valid for every future instantiation. All non-generic declarations in reachable modules continue to be verified even if unused. A missing generic type argument or wrong arity is `E7006`; unknown/inaccessible templates/types use `E7002`; an unsatisfied constraint is `E7005` at the application, with `parameter`, `constraint` and `found` metadata. Body failures point at template source.
@@ -538,3 +538,13 @@ A type can satisfy several constraints; each requirement MUST be checked. Constr
A specialization is keyed by template module identity, declaration kind/name and the ordered structural identity of concrete arguments. Named arguments use nominal defining-module identity, independent of source filename, short/qualified spelling or import/provider order. Each key MUST emit at most one concrete declaration; repeated same-key recursion reuses it. Type-specialization cycles still obey ordinary finite-layout rules. Expanding specialization is bounded by 4,096 generated declarations and active expansion depth 64 (`E7006`), with structural type traversal bounded at depth 64. These are fixed compiler input limits, not runtime fuel or semantic flags.
Non-generic declarations retain their AIR names and order. Generated types and functions append in lexicographic specialization-key order within their categories. Their AIR identifier starts with `__aji_g_` followed by lowercase SHA-256 of the canonical key bytes; collisions with original names or earlier keys in sorted order receive the smallest unused `_1`, `_2`, … suffix. The canonical key is `type:` or `fn:`, full defining-module/declaration path, and ordered `<...>` arguments. Named arguments use full nominal paths, applied arguments recursively spell their template/arguments, arrays spell `[T;N]` with decimal N, wrappers/cap/file spell `name<T>`; argument separators are commas without whitespace. Full keys, not hashes, determine identity and reuse. Keys are limited to 16,384 bytes (`E7006`). Every required body lowers to existing format-0 constructs, and the combined module MUST pass the ordinary verifier. There is no new AIR instruction/feature, verifier transfer state, runtime dispatch, implicit allocation/refcount/destructor, effect inference or authority. Source provenance retains template locations and the locations of supplied argument types. Generic borrow/owner/task contracts use the existing runtime/interpreter rules unchanged. Existing monomorphic source and AIR retain meaning and canonical lowering. The finite-layout verifier now visits array elements as well as direct nominal members, closing a prior E1003 implementation gap without changing the normative no-recursive-value rule. Existing unimplemented source `from`-returns remain unimplemented; specialization retains their contract rather than inventing borrow lifetimes.
## 16. Source linear aggregates
Structs, enums and fixed arrays with linear members MUST obey spec 03 §25. Constructors consume linear inputs with explicit `move`; whole aggregate calls/returns/bindings also require `move` on named values. No partial field move is allowed. Copy fields may be read without consumption. `let (a, b, …) = struct.unpack(move value);` and `let (a, b, …) = array.unpack(move value);` bind all fields/elements in order, including a one-element parenthesized binding. `_` is allowed only for Copy components; a linear ignored component MUST reject E3002 through the ordinary verifier. Array literals `[e0, e1, …]` use complete ordered inputs; repeated `[e;N]` remains Copy-only. Existing argument/block limits bound unpacking.
`match move value { Enum::Variant(payload) => … }` exhaustively consumes a linear enum and lowers to enum.take. Ordinary Copy matches keep enum.switch. An arm MUST consume or transfer each linear payload, including those named `_`; there is no automatic destructor. Unused payload-free variants still consume the linear enum.
`value.swap(mut place, move replacement)` returns the previous complete value and stores the replacement; it lowers to value.swap with the existing borrow scope. The same spelling accepts Copy replacements without move. The caller MUST explicitly consume a returned linear value. `match own.pack(move value, heap) { ok(owner) => …, err(error, value) => … }` makes allocation authority/failure explicit and preserves ownership on both outcomes; `or trap` retains ordinary abnormal-path semantics. own.new/own.array/region storage and local storage remain Copy-only; own.take extracts whole linear content and own.free cannot destroy it.
The frontend MUST declare linear_aggregates plus its dependencies whenever any emitted aggregate has linear members or any of the new operations is emitted. Existing Source/AIR diagnostics and deterministic behavior apply. This phase does not implement partial moves, borrowed aggregates, dynamic linear buffers or source from-returns.
+4 -4
View File
@@ -138,15 +138,15 @@ When dst can hold the complete representation, the function MUST write exactly t
The preserved invariant is exclusive writes only within the supplied initialized slice, no escaping borrow, and no partial mutation on returned failure. Functions declare `effects []`, allocate no heap, use constant scalar auxiliary storage and O(decimal digit count) work. Existing call, initialization, alias, lifetime, bounds and enum verifier rules apply; conflicting live borrows MUST reject even on short output. No new verifier state, runtime rule, diagnostic, AIR feature or authority is added. Valid slices and every scalar value MUST NOT produce arithmetic, cast or bounds traps; interpreter fuel exhaustion remains an environment outcome and is outside the returned-error preservation guarantee. Behavior is identical in deterministic and hosted profiles. Existing APIs, source syntax and AIR format 0 retain their contracts.
### 2.9 Copy option and result
### 2.9 Option and result
The compiler registry MUST also include `std.option` and `std.result`. They declare ordinary generic enums:
```aji
enum Option<T: Copy> { some(T), none }
enum Result<T: Copy, E: Copy> { ok(T), err(E) }
enum Option<T> { some(T), none }
enum Result<T, E> { ok(T), err(E) }
```
`std.option.is_some<T: Copy>(value: Option<T>) -> bool` and `std.result.is_ok<T: Copy, E: Copy>(value: Result<T, E>) -> bool` declare `effects []`, allocate no heap and classify the active variant. They neither extract nor implicitly consume any payload. Call them using spec 15 §15's explicit expression arguments, e.g. `std.option.is_some::<u64>(value)`. Types/constructors/patterns are fully qualified and require a direct import; exhaustive matches extract payloads through ordinary enum rules. `none` still requires a type argument. `err(E)` is an ordinary enum variant, not the intrinsic outcome shorthand.
These APIs are restricted to Copy arguments under format 0's existing aggregate-member rules. They MUST NOT accept owners, resources, endpoints or borrows as payloads. Invalid generic constraints use `E7005`; naming/arity/exhaustiveness/alias diagnostics remain the existing source/verifier codes. No must-use obligation, implicit default, prelude, borrow aggregate, new AIR primitive or failure conversion is introduced. Each specialization is a normal Copy enum/static function, deterministic under spec 15 §15. The later linear-aggregate feature is required before owning option/result types can be promised.
Option/Result accept ordinary complete value payloads, including owners/resources/endpoints under linear_aggregates (spec 03 §25, source §16). Their class is structural: an owning specialization is linear even when the active variant is none or a Copy error. It MUST be explicitly moved and exhaustively consumed; unused linear payloads reject E3002. Borrow/storage/function-bound payloads remain forbidden by ordinary member/type rules. is_some/is_ok retain Copy constraints and MUST reject E7005 for linear arguments; they do not consume a resource merely to classify it. Match an owning value explicitly instead. Existing Copy specializations retain behavior. No implicit unwrap/default/conversion or cleanup is added.