- 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
40 lines
941 B
LLVM
40 lines
941 B
LLVM
; own.array of runtime length, borrowed as a slice.
|
|
; expect: run
|
|
; grant: heap=mem.alloc:64
|
|
; result: [7,7,9,7,7]
|
|
; phase: 2
|
|
; spec: docs/spec/03-memory-model.md
|
|
module test.own_array_buffer
|
|
air 0
|
|
lang 0.1
|
|
features [arrays, capabilities, effects, heap, ownership, resources]
|
|
|
|
fn @main(%heap: cap<mem.alloc>) -> array<u8, 5>
|
|
effects [mem.alloc]
|
|
entry:
|
|
%dst = local.alloc array<u8, 5>
|
|
local.zero %dst
|
|
%n = const.usize 5
|
|
%seven = const.u8 7
|
|
own.array %n, %seven, %heap, ok -> @have, err -> @nomem
|
|
have(%a: own_array<u8>):
|
|
%s = borrow.mut %a
|
|
%i = const.usize 2
|
|
%el = borrow.index %s, %i
|
|
%nine = const.u8 9
|
|
store %el, %nine
|
|
borrow.end %el
|
|
%src = borrow.ref %s
|
|
%dm = borrow.mut %dst
|
|
%ds = slice.make %dm
|
|
slice.copy %ds, %src
|
|
borrow.end %ds
|
|
borrow.end %dm
|
|
borrow.end %src
|
|
borrow.end %s
|
|
own.free %a
|
|
%r = local.load %dst
|
|
ret %r
|
|
nomem(%e: alloc_error):
|
|
trap
|