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:
101 files changed
+2377
-71
No files matched your search
@@ -107,3 +107,5 @@ RFC 0022 explicit generics (cl100k, relative to modules): Quick Reference 6,501
|
||||
|
||||
|
||||
RFC 0023 whole-value linear aggregates (cl100k, relative to generics): Quick Reference 6,948 → 7,225 (+4.0%); other source docs 41,086 → 42,364 (+3.1%); full source docs excluding AIR 48,034 → 49,589 (+3.2%). New on-demand `language/linear-aggregates.md` is 1,133 tokens; `library/std.md` is 8,398. AIR grows to 168,336 bytes (+4.7%). Whole unpack/exhaustive match/explicit swap/allocation failure expose ownership without per-field holes, cleanup or new transfer state. Cumulative source growth is approximately +45.9%; Quick Reference remains beyond its 4–6k target. RFC 0023 justifies the added contracts; consolidation remains separate work and no MCC improvement is claimed.
|
||||
|
||||
RFC 0024 initialized buffers and safe Vec (cl100k, relative to linear aggregates): Quick Reference 7,225 → 7,667 (+6.1%); other source docs 42,364 → 44,717 (+5.6%); full source excluding AIR 49,589 → 52,384 (+5.6%). New on-demand language/buffers.md is 1,175 tokens; library/std.md is 9,432. AIR grows to 175,736 bytes (+4.4%). Initialized prefixes, explicit reserve, returned failure ownership and empty-only free permit safe resource containers without per-slot verifier state. Cumulative full source growth is +54.2%, with the RFC's owner-review justification; Quick Reference consolidation remains separate work and no empirical MCC improvement is claimed.
|
||||
@@ -89,3 +89,6 @@ docs/reference/intrinsics.md
|
||||
|
||||
# Whole-value linear aggregates (STD-5)
|
||||
docs/spec/03-memory-model.md :: ## 25. Linear aggregates in AIR
|
||||
|
||||
# Dynamic initialized storage (STD-6a)
|
||||
docs/spec/03-memory-model.md :: ## 26. Dynamic initialized buffers
|
||||
@@ -426,3 +426,26 @@ fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
```
|
||||
|
||||
`[move a, move b]` constructs ordered array elements; `let (a,b) = array.unpack(move data);` extracts every element. `value.swap(mut place, move replacement)` returns the old complete value. `own.pack(move value, heap)` has ok(owner) and err(error, original_value); own.take extracts linear content, while own.free cannot destroy it. Dynamic heap arrays/regions/frame storage remain Copy-only. Owning std.option/std.result use ordinary linear enums; is_some/is_ok retain Copy constraints. Full contracts: language/linear-aggregates.md.
|
||||
|
||||
## 14. Buffers and Vec
|
||||
|
||||
`buffer<T>` uniquely owns capacity and an initialized prefix, including owners/resources. Allocate with `buffer.new<T>(capacity, heap)` (mem.alloc); borrow the handle first for len/capacity/reserve/push/pop/view. `reserve(b, capacity, heap)` grows explicitly, charging old+new capacity at the peak. Push never grows: full returns the original item. Pop moves the last element out. Free succeeds only when empty; otherwise it returns the buffer. No destructor drains it.
|
||||
|
||||
```aji
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let data = buffer.new<own<u64>>(1, heap) or trap;
|
||||
let item = own.new(42u64, heap) or trap;
|
||||
var answer: u64 = 0;
|
||||
{ mut b = data;
|
||||
buffer.push(b, move item) or trap;
|
||||
let last = buffer.pop(b) or trap;
|
||||
answer = own.take(move last);
|
||||
}
|
||||
buffer.free(move data) or trap;
|
||||
return answer;
|
||||
}
|
||||
```
|
||||
|
||||
`ref values = buffer.view(b);` / `mut values = buffer.view(b);` borrow only the prefix. A live child view/task loan blocks shape changes, even a no-op reserve. Read Copy elements; use value.swap to replace linear elements, consuming the returned old value. Full contracts: language/buffers.md.
|
||||
|
||||
Import `std.vec` for `Vec<T>` and new/len/capacity/reserve/push/pop/free/get/replace, each explicitly specialized `::<T>`. new/reserve require mem.alloc; push is bounded, get requires Copy, pop returns std.option.Option<T>. Failure variants retain ownership: full(item), out_of_bounds(item), not_empty(vector). Match move on linear results; import std.option to name its variants. Signatures: library/std.md. Inside a specialized generic body, `move name` also accepts complete Copy bindings and retains their availability; monomorphic Copy moves and moves of borrows still reject.
|
||||
@@ -25,6 +25,10 @@ docs/spec/15-source-language.md :: ## 13. Built-in standard modules
|
||||
docs/spec/15-source-language.md :: ## 16. Source linear aggregates
|
||||
docs/spec/03-memory-model.md :: ## 25. Linear aggregates in AIR
|
||||
|
||||
> language/buffers.md
|
||||
docs/spec/15-source-language.md :: ## 17. Source dynamic buffers
|
||||
docs/spec/03-memory-model.md :: ## 26. Dynamic initialized buffers
|
||||
|
||||
> language/generics.md
|
||||
docs/spec/15-source-language.md :: ## 15. Explicit source generics
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ The other files in `/docs` hold the full rules. Open one only when this page is
|
||||
|
||||
| Need | Read |
|
||||
|---|---|
|
||||
| built-in bytes/math/UTF-8/hex/Base64/decimal integers, signatures and failure contracts | `/docs/library/std.md` |
|
||||
| built-in bytes/math/text/formatting, option/result and owning Vec, signatures and failure contracts | `/docs/library/std.md` |
|
||||
| initialized buffer storage, explicit growth/drain and child views | `/docs/language/buffers.md` |
|
||||
| whole-value linear aggregates, unpack, exchange and allocation failure | `/docs/language/linear-aggregates.md` |
|
||||
| generic declarations/applications, property constraints and specialization limits | `/docs/language/generics.md` |
|
||||
| explicit package imports, qualified types, manifest file inputs | `/docs/language/modules.md` |
|
||||
|
||||
Reference in new issue
Block a user