Files
aji/tests/conformance/phase2/run/file_copy.air
T
dev d405d4ea50 Phase 2: I/O intrinsics, linear resources, deterministic profile (RFC 0007)
- air: resource types file<read|write|append>, listener, stream; io_error;
  intrinsic registry (19 intrinsics) synced with reference/intrinsics.md;
  fallible intrinsics as ok/err terminators; fs prefix narrowing;
  linear_aggregates gating
- verifier: intrinsic form, operand, result and capability-kind checks
  (E1001, E3201, E5002); intrinsic effects (E3101); resource linearity
  in the borrow walker with per-edge moves: E3002 leaks and join
  mismatches, E3001, E2001, E2002, E2101 for close while borrowed;
  resources as borrow roots
- interp: deterministic world (captured console, VFS, loopback TCP,
  instruction clock, pinned xoshiro256 PRNG), blocked outcome, run
  record with stdout/stderr/files
- CLI: --stdin, --vfs, --seed, --result-file, --profile (hosted: exit 3),
  exit code 7; runner: stdin/vfs/seed/stdout/stderr/file/blocked headers
- conformance: hello, file copy and TCP echo exit programs; 37 new tests;
  4000 mutants without a crash
2026-10-04 14:02:17 +03:00

206 lines
5.5 KiB
LLVM

; Phase 2 exit program: copy /in/data.txt to /out/copy.txt through scoped capabilities.
; expect: run
; grant: src=fs.read:/in
; 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.file_copy
air 0
lang 0.1
features [arrays, capabilities, effects, ownership, resources]
fn @main(%src: cap<fs.read>, %dst: cap<fs.write>) -> void
effects [fs.read, fs.write]
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
%buf = local.alloc array<u8, 4>
local.zero %buf
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>):
%bm = borrow.mut %buf
%bs = slice.make %bm
%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 %bm
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
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