Files
aji/tests/conformance/phase2/run/region_lifecycle.air
T
dev 7f4ce71d44 Phase 2: heap, regions and allocation budgets (RFC 0008)
- air: own<T>, own_array<T>, region, alloc_error; own.new/array/take/
  free, region.create/new/array/reset/destroy; mem.alloc budget form;
  linear contents of owners gated by linear_aggregates
- verifier: allocation types and capability kind (E1001, E3201),
  mem.alloc effect (E3101), ok/err counts; borrow-typed block params
  checked in the CFG stage with the region-allocation exception; linear
  owners and regions (E3002, E3001, E2001, E2002, E2101); region
  allocations as disjoint exclusive children of the shared region
  borrow; E2104 when reset/destroy would invalidate a live reference
- interp: live-byte budgets charged along the narrowing chain, shared by
  copies, mandatory in the deterministic profile; heap cells; regions
  return quota only on reset/destroy
- conformance: 25 heap/region tests including a 64 KiB region file copy;
  4000 mutants without a crash
2026-10-04 14:26:34 +03:00

39 lines
911 B
LLVM

; Allocate in a region, reset to return the quota, allocate again, destroy.
; expect: run
; grant: heap=mem.alloc:8
; result: 7
; phase: 2
; spec: docs/spec/03-memory-model.md
module test.region_lifecycle
air 0
lang 0.1
features [arrays, capabilities, effects, heap, ownership, regions, resources]
fn @main(%heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
entry:
region.create %heap, ok -> @have, err -> @nomem
have(%r: region):
%rb = borrow.ref %r
%v = const.u64 7
region.new %rb, %v, ok -> @one, err -> @nomem2
one(%p: mut<u64>):
%x = load %p
borrow.end %p
borrow.end %rb
region.reset %r
%rb2 = borrow.ref %r
region.new %rb2, %x, ok -> @two, err -> @nomem3
two(%q: mut<u64>):
%y = load %q
borrow.end %q
borrow.end %rb2
region.destroy %r
ret %y
nomem2(%e2: alloc_error):
trap
nomem3(%e3: alloc_error):
trap
nomem(%e: alloc_error):
trap