cli: add initialized buffers and safe owning vectors

Introduce linear_buffers through the specification, AIR parser/serializer,
verifier, deterministic interpreter and source lowering. A buffer owns an
initialized prefix with explicit reserve, bounded push, moving pop/views and
recoverable empty-only free. Growth charges old+new capacity; failed growth,
full push and nonempty free preserve or return complete ownership.

Implement compiler-pinned safe std.vec with nine operations for Copy values,
owners, files and channel endpoints. Permit complete Copy moves inside
specialized generic bodies without weakening monomorphic or borrow rules.
Update RFC 0024, Q-036, STD-6a/b, reference grammar, Quick Reference, bundles,
source coverage and CI. Remaining collections stay STD-6c.

Validation: unit tests and AIR round-trip; 757 conformance cases; 56 dedicated
buffer cases with per-instruction collection and 32-seed schedule stress;
extended memory test; hosted smoke; 36 module, 20 generic, 49 linear and
118 buffer CLI checks; 91/91 source constructs; Zig fmt and reference bundles.
Full source bundle: 49,589 -> 52,384 cl100k tokens (+5.6%); AIR 175,736 bytes.
The reference interpreter's push copies its initialized prefix; no native
performance or empirical MCC benefit is claimed.
This commit is contained in:
dev committed 2026-10-06 23:26:41 +03:00
1 parent 4f084decce
commit 4138a52af6
101 files changed
+2377 -71

No files matched your search

+1
View File
@@ -43,6 +43,7 @@ Declaring `features [capabilities, effects, ownership]` grants no authority. It
| `heap` | published | 2 | `capabilities`, `effects`, `ownership`, `resources` | `own<T>`, `own_array<T>`, `own.*`, built-in `alloc_error`, `mem.alloc` budgets and `budget` narrowing (spec 03 §18–§19) |
| `islands` | published | 4 | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `island<T>`, `frozen<T>`, `iref<T>`, `island.*`, `frozen.*`, `iref.eq`, `IslandSafe`, `T0010` (spec 03 §22–§23) |
| `linear_aggregates` | published | 6 | `capabilities`, `effects`, `ownership`, `resources` | whole-value linear structs/enums/fixed arrays, unpack/take/swap and ownership-preserving own.pack; spec 03 §25 |
| `linear_buffers` | published | 6 | `arrays`, `capabilities`, `effects`, `heap`, `linear_aggregates`, `ownership`, `resources` | initialized prefix buffer<T>, explicit growth/push/pop/view/empty-only free; spec 03 §26 |
| `ownership` | published | 1 | — | frame storage `local<T>`, second-class borrows `ref<T>`/`mut<T>`, `from` returns, initialization (spec 07 §8.8, spec 07a, spec 08 §11, §13) |
| `receiver_dup` | reserved | — | `cancellation`, `capabilities`, `channels`, `effects`, `heap`, `ownership`, `resources`, `tasks` | several receivers of one channel (MPMC); unscheduled |
| `regions` | published | 2 | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `region`, `region.*`, static generations (spec 03 §20) |
+6
View File
@@ -118,6 +118,11 @@ capability_op = "cap.narrow." ident local { "," local } ok_err (* te
(* Feature heap (spec 03 §18–§19). *)
heap_op = "own.new" local "," local ok_err (* terminator: value, cap<mem.alloc> *)
| "buffer.new" type local "," local ok_err
| ( "buffer.len" | "buffer.capacity" | "buffer.view" ) local
| "buffer.reserve" local "," local "," local ok_err
| "buffer.push" local "," local ok_err
| ( "buffer.pop" | "buffer.free" ) local ok_err
| "own.array" local "," local "," local ok_err (* terminator: count, element, cap<mem.alloc> *)
| "own.take" local
| "own.free" local ;
@@ -211,6 +216,7 @@ type = int_type | "bool" | "void" | "never" | global
| "cap" "<" path ">" (* feature capabilities; a capability kind, e.g. cap<fs.read> *)
| "file" "<" ( "read" | "write" | "append" ) ">" (* feature resources *)
| "listener" | "stream" (* feature resources *)
| "buffer" "<" type ">" (* feature linear_buffers *)
| ( "own" | "own_array" ) "<" type ">" (* feature heap *)
| "region" (* feature regions *)
| "scope" | "task" "<" type ">" (* feature tasks *)
+4 -2
View File
@@ -41,7 +41,7 @@ type = int_type | "bool" | "void" | "never" | path
| "file" "<" ( "read" | "write" | "append" ) ">" ;
(* `>>` closes two type arguments: mut<file<write>> *)
wrapper = "ref" | "mut" | "slice" | "slice_mut" | "own" | "own_array"
| "task" | "sender" | "receiver" | "mutex" ;
| "task" | "sender" | "receiver" | "mutex" | "buffer" ;
int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" ;
(* `region`, `listener`, `stream`, `io_error`, `alloc_error`,
@@ -52,7 +52,7 @@ int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
block = "{" { statement } [ expr ] "}" ; (* optional tail expression: the block's value *)
statement = "let" binding [ ":" type ] "=" expr ";"
| "var" ident ":" type "=" ( expr | "zero" ) ";"
| ( "ref" | "mut" ) [ "unchecked" ] ident "=" place ";" (* borrow binding *)
| ( "ref" | "mut" ) [ "unchecked" ] ident "=" ( place | borrow_call ) ";" (* borrow binding; buffer.view(b) / graph access also bind child borrows, spec 15 §17 *)
| place "=" expr ";"
| "break" ";" | "continue" ";" | "return" [ expr ] ";" | "trap" ";"
| expr ";"
@@ -102,6 +102,8 @@ primary = int_lit | "true" | "false" | string
| "(" expr ")"
| if_expr | match_expr | block ;
field_init = ident ":" expr ;
borrow_call = "buffer" "." "view" "(" ident ")"
| ( "island" | "frozen" | "arc" ) "." "at" "(" expr "," expr ")" ;
place = ident { "." ident | "[" expr [ ".." expr ] "]" } | "*" unary ;
int_lit = digit { digit | "_" } [ int_type ] | "0x" hexdigit { hexdigit | "_" } [ int_type ] ;
+19 -2
View File
@@ -1,8 +1,8 @@
# Standard library API
Normative contracts: spec 16. Import rules: spec 15 §13. These modules are bundled with the compiler, with no external dependencies or grants.
Normative contracts: spec 16. Import rules: spec 15 §13. These modules are bundled with the compiler, with no external source dependencies. Allocation authority is explicit for std.vec new/reserve.
All functions below declare `effects []`, allocate no heap memory and retain no borrows. Pass arrays/slices using explicit `ref` or `mut`. Names are fully qualified; no alias or short-name import exists.
Except std.vec new/reserve, functions below declare `effects []`, allocate no heap memory and retain no borrows. Pass arrays/slices using explicit `ref` or `mut`. Names are fully qualified; no alias or short-name import exists.
| Module | Function signature | Result/failure |
|---|---|---|
@@ -227,3 +227,20 @@ Requires direct `import std.option;` / `import std.result;`; explicit generic sp
| `std.result.is_ok<T: Copy, E: Copy>(value: Result<T, E>) -> bool` | true for ok; false for err; effects [] |
All are ordinary safe source/static specialization, with no allocation or authority. Generic helper calls use `is_some::<u64>(value)` / `is_ok::<u64, u8>(value)`. Constructors and patterns use `std.option.Option::<u64>::some(value)` or `std.result.Result::<u64, u8>::err(code)`; names and variant matches remain explicit even for none. Extract values by exhaustive match; an err variant is not intrinsic outcome syntax. Owners/resources/endpoints make these enums linear under spec 03 §25 and require exhaustive `match move`. Borrows remain invalid members; Copy classification helpers reject linear arguments with E7005. No must-use or implicit unwrap/default/conversion is introduced. [Checked example](../../examples/std/generics.aji) returns 42 without grants.
## Owning vectors
Import std.vec; every function supplies explicit `::<T>`. Vec<T> contains a buffer<T> and is always linear. No implicit growth or cleanup occurs. The storage field follows ordinary aggregate visibility/borrow rules. New/reserve require cap<mem.alloc> and effects [mem.alloc]; all other functions declare effects [].
| Function | Parameters | Result |
|---|---|---|
| new<T> | capacity: usize, heap: cap<mem.alloc> | NewResult<T>: ok(Vec<T>) / err(alloc_error) |
| len<T> / capacity<T> | value: ref<Vec<T>> | usize |
| reserve<T> | value: mut<Vec<T>>, capacity: usize, heap: cap<mem.alloc> | ReserveResult: ok / err(alloc_error) |
| push<T> | value: mut<Vec<T>>, item: T | PushResult<T>: ok / full(T) |
| pop<T> | value: mut<Vec<T>> | std.option.Option<T>: some(T) / none |
| free<T> | value: Vec<T> | FreeResult<T>: ok / not_empty(Vec<T>) |
| get<T: Copy> | value: ref<Vec<T>>, index: usize | std.option.Option<T>: some(T) / none |
| replace<T> | value: mut<Vec<T>>, index: usize, item: T | ReplaceResult<T>: ok(old_value: T) / out_of_bounds(original_item: T) |
Growth has an old+new capacity allocation peak. Failure preserves capacity/length/elements; full push and out-of-bounds replacement return the exact input. Nonempty free returns the vector; pop/consume all elements before retrying. get returns none out of bounds, replace returns the old complete element on success. Generic moves compose Copy and linear types. Qualified variants require direct imports (including std.option for pop/get). [Executable owning vector](../../examples/std/vector.aji) returns 42 with heap=mem.alloc:256. Views and nested element borrows cannot escape or overlap shape changes. Normative contracts: spec 16 §2.10 and spec 03 §26.
+3 -1
View File
@@ -52,6 +52,8 @@ An `ArcSafe` value may be held by an `arc` (spec 03 §24): the last release dest
## Format-0 source constraints
Spec 15 §15 fixes the exact property queries used by explicit generic specialization. Copy includes integers, booleans, built-in enums, capabilities, `iref` and aggregates of Copy members; borrows and linear values are excluded. Send/Share use spec 04 §35. Freeze currently equals IslandSafe plain graph content; it does not promise conversion of arbitrary owners or resources. Local has task/scope/shield/guard/internal-storage base cases and propagates through borrow/own/own_array/mutex wrappers and arrays/aggregates containing Local content. It is not the complement of Send. These properties add no methods, effects, unsafe declarations or implicit resource actions.
Spec 15 §15 fixes the exact property queries used by explicit generic specialization. Copy includes integers, booleans, built-in enums, capabilities, `iref` and aggregates of Copy members; borrows and linear values are excluded. Send/Share use spec 04 §35. Freeze currently equals IslandSafe plain graph content; it does not promise conversion of arbitrary owners or resources. Local has task/scope/shield/guard/internal-storage base cases and propagates through borrow/own/own_array/buffer/mutex wrappers and arrays/aggregates containing Local content. It is not the complement of Send. These properties add no methods, effects, unsafe declarations or implicit resource actions.
Under linear_aggregates (spec 03 §25), structs/enums/fixed arrays containing any linear member are linear as whole values. Every variant contributes, regardless of the active tag. Borrow/storage/function-bound members remain forbidden; whole-value unpack/take/exchange preserve exactly-once consumption.
Under linear_buffers (spec 03 §26), buffer<T> is always linear; Send/Share follow T, and Local propagates. Borrow/storage/task-bound content is forbidden. It is neither IslandSafe nor ArcSafe: its nested linear values require explicit draining.