Files
aji/tests/conformance/phase2/run/region_file_copy.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

215 lines
5.8 KiB
LLVM

; File copy with a 64 KiB buffer allocated in a region from a 64 KiB budget.
; expect: run
; grant: src=fs.read:/in
; grant: heap=mem.alloc:65536
; grant: dst=fs.write:/out
; vfs: /in/data.txt=Aji copies files.\n
; result: null
; file: /out/copy.txt=Aji copies files.\n
; phase: 2
; spec: docs/reference/intrinsics.md
module test.region_file_copy
air 0
lang 0.1
features [arrays, capabilities, effects, heap, ownership, regions, resources]
fn @main(%src: cap<fs.read>, %dst: cap<fs.write>, %heap: cap<mem.alloc>) -> void
effects [fs.read, fs.write, mem.alloc]
entry:
%ip = local.alloc array<u8, 12>
local.zero %ip
%ip_m = borrow.mut %ip
%ip_i0 = const.usize 0
%ip_c0 = const.u8 47
%ip_e0 = borrow.index %ip_m, %ip_i0
store %ip_e0, %ip_c0
borrow.end %ip_e0
%ip_i1 = const.usize 1
%ip_c1 = const.u8 105
%ip_e1 = borrow.index %ip_m, %ip_i1
store %ip_e1, %ip_c1
borrow.end %ip_e1
%ip_i2 = const.usize 2
%ip_c2 = const.u8 110
%ip_e2 = borrow.index %ip_m, %ip_i2
store %ip_e2, %ip_c2
borrow.end %ip_e2
%ip_i3 = const.usize 3
%ip_c3 = const.u8 47
%ip_e3 = borrow.index %ip_m, %ip_i3
store %ip_e3, %ip_c3
borrow.end %ip_e3
%ip_i4 = const.usize 4
%ip_c4 = const.u8 100
%ip_e4 = borrow.index %ip_m, %ip_i4
store %ip_e4, %ip_c4
borrow.end %ip_e4
%ip_i5 = const.usize 5
%ip_c5 = const.u8 97
%ip_e5 = borrow.index %ip_m, %ip_i5
store %ip_e5, %ip_c5
borrow.end %ip_e5
%ip_i6 = const.usize 6
%ip_c6 = const.u8 116
%ip_e6 = borrow.index %ip_m, %ip_i6
store %ip_e6, %ip_c6
borrow.end %ip_e6
%ip_i7 = const.usize 7
%ip_c7 = const.u8 97
%ip_e7 = borrow.index %ip_m, %ip_i7
store %ip_e7, %ip_c7
borrow.end %ip_e7
%ip_i8 = const.usize 8
%ip_c8 = const.u8 46
%ip_e8 = borrow.index %ip_m, %ip_i8
store %ip_e8, %ip_c8
borrow.end %ip_e8
%ip_i9 = const.usize 9
%ip_c9 = const.u8 116
%ip_e9 = borrow.index %ip_m, %ip_i9
store %ip_e9, %ip_c9
borrow.end %ip_e9
%ip_i10 = const.usize 10
%ip_c10 = const.u8 120
%ip_e10 = borrow.index %ip_m, %ip_i10
store %ip_e10, %ip_c10
borrow.end %ip_e10
%ip_i11 = const.usize 11
%ip_c11 = const.u8 116
%ip_e11 = borrow.index %ip_m, %ip_i11
store %ip_e11, %ip_c11
borrow.end %ip_e11
borrow.end %ip_m
%ip_r = borrow.ref %ip
%ip_s = slice.make %ip_r
%op = local.alloc array<u8, 13>
local.zero %op
%op_m = borrow.mut %op
%op_i0 = const.usize 0
%op_c0 = const.u8 47
%op_e0 = borrow.index %op_m, %op_i0
store %op_e0, %op_c0
borrow.end %op_e0
%op_i1 = const.usize 1
%op_c1 = const.u8 111
%op_e1 = borrow.index %op_m, %op_i1
store %op_e1, %op_c1
borrow.end %op_e1
%op_i2 = const.usize 2
%op_c2 = const.u8 117
%op_e2 = borrow.index %op_m, %op_i2
store %op_e2, %op_c2
borrow.end %op_e2
%op_i3 = const.usize 3
%op_c3 = const.u8 116
%op_e3 = borrow.index %op_m, %op_i3
store %op_e3, %op_c3
borrow.end %op_e3
%op_i4 = const.usize 4
%op_c4 = const.u8 47
%op_e4 = borrow.index %op_m, %op_i4
store %op_e4, %op_c4
borrow.end %op_e4
%op_i5 = const.usize 5
%op_c5 = const.u8 99
%op_e5 = borrow.index %op_m, %op_i5
store %op_e5, %op_c5
borrow.end %op_e5
%op_i6 = const.usize 6
%op_c6 = const.u8 111
%op_e6 = borrow.index %op_m, %op_i6
store %op_e6, %op_c6
borrow.end %op_e6
%op_i7 = const.usize 7
%op_c7 = const.u8 112
%op_e7 = borrow.index %op_m, %op_i7
store %op_e7, %op_c7
borrow.end %op_e7
%op_i8 = const.usize 8
%op_c8 = const.u8 121
%op_e8 = borrow.index %op_m, %op_i8
store %op_e8, %op_c8
borrow.end %op_e8
%op_i9 = const.usize 9
%op_c9 = const.u8 46
%op_e9 = borrow.index %op_m, %op_i9
store %op_e9, %op_c9
borrow.end %op_e9
%op_i10 = const.usize 10
%op_c10 = const.u8 116
%op_e10 = borrow.index %op_m, %op_i10
store %op_e10, %op_c10
borrow.end %op_e10
%op_i11 = const.usize 11
%op_c11 = const.u8 120
%op_e11 = borrow.index %op_m, %op_i11
store %op_e11, %op_c11
borrow.end %op_e11
%op_i12 = const.usize 12
%op_c12 = const.u8 116
%op_e12 = borrow.index %op_m, %op_i12
store %op_e12, %op_c12
borrow.end %op_e12
borrow.end %op_m
%op_r = borrow.ref %op
%op_s = slice.make %op_r
region.create %heap, ok -> @have_region, err -> @nomem
have_region(%reg: region):
%rb = borrow.ref %reg
%size = const.usize 65536
%zero = const.u8 0
region.array %rb, %size, %zero, ok -> @have_buf, err -> @nomem2
have_buf(%bs: slice_mut<u8>):
intrinsic fs.open_read(%src, %ip_s), ok -> @opened_in, err -> @fail
opened_in(%in: file<read>):
intrinsic fs.create(%dst, %op_s), ok -> @opened_out, err -> @fail_in
opened_out(%out: file<write>):
%fi = borrow.mut %in
%fo = borrow.mut %out
br @loop()
loop:
intrinsic fs.read(%fi, %bs), ok -> @got, err -> @fail_loop
got(%n: usize):
%z = const.usize 0
%eof = eq.usize %n, %z
cbr %eof, @finish(), @write()
write:
%chunk = slice.sub %bs, %z, %n
%cr = borrow.ref %chunk
intrinsic fs.write_all(%fo, %cr), ok -> @wrote, err -> @fail_write
wrote:
borrow.end %cr
borrow.end %chunk
br @loop()
finish:
borrow.end %fo
borrow.end %fi
borrow.end %bs
borrow.end %rb
region.destroy %reg
intrinsic fs.close(%in), ok -> @closed_in, err -> @fail_close_in
closed_in:
intrinsic fs.close(%out), ok -> @done, err -> @fail_close_out
done:
borrow.end %op_s
borrow.end %op_r
borrow.end %ip_s
borrow.end %ip_r
ret
fail(%e: io_error):
trap
nomem(%a1: alloc_error):
trap
nomem2(%a2: alloc_error):
trap
fail_in(%e2: io_error):
trap
fail_loop(%e3: io_error):
trap
fail_write(%e4: io_error):
trap
fail_close_in(%e5: io_error):
trap
fail_close_out(%e6: io_error):
trap