Files
aji/tests/conformance/buffers/empty_free_leak.air
dev 4138a52af6 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.
2026-10-06 23:26:41 +03:00

46 lines
1.3 KiB
LLVM

; expect: reject E3002
; phase: 6
; spec: docs/spec/07a-air-instructions.md Dynamic buffers
module test.buffers
air 0
lang 0.1
features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources]
fn @main(%heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
entry:
%capacity = const.usize 1
%n = const.u64 42
buffer.new own<u64> %capacity, %heap, ok -> @made, err -> @failed
made(%data: buffer<own<u64>>):
own.new %n, %heap, ok -> @owned, err -> @owner_failed
owned(%owner: own<u64>):
%b = borrow.mut %data
buffer.push %b, %owner, ok -> @pushed, err -> @full
full(%returned: own<u64>):
trap
pushed:
%next_capacity = const.usize 2
buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed
grown:
%length = buffer.len %b
%capacity_after = buffer.capacity %b
%view = buffer.view %b
borrow.end %view
buffer.pop %b, ok -> @popped, err -> @empty
popped(%part: own<u64>):
%answer = own.take %part
borrow.end %b
buffer.free %data, ok -> @done, err -> @nonempty
nonempty(%original: buffer<own<u64>>):
ret %answer
done:
ret %answer
empty:
trap
failed(%error: alloc_error):
trap
owner_failed(%owner_error: alloc_error):
trap
reserve_failed(%reserve_error: alloc_error):
trap