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
This commit is contained in:
1 parent
571cc6e362
commit
d405d4ea50
49 files changed
+2325
-81
No files matched your search
@@ -0,0 +1,23 @@
|
||||
; A failed close still consumes the file; closing again is a double consume.
|
||||
; expect: reject E2002
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.close_twice_after_error
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
intrinsic fs.close(%f), ok -> @closed, err -> @retry
|
||||
closed:
|
||||
ret
|
||||
retry(%e2: io_error):
|
||||
intrinsic fs.close(%f), ok -> @closed, err -> @gone
|
||||
gone(%e3: io_error):
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,24 @@
|
||||
; The file is closed while a borrow of it is live.
|
||||
; expect: reject E2101
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.close_while_borrowed
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
%m = borrow.mut %f
|
||||
intrinsic fs.close(%f), ok -> @closed, err -> @cfail
|
||||
closed:
|
||||
borrow.end %m
|
||||
ret
|
||||
cfail(%e2: io_error):
|
||||
borrow.end %m
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,22 @@
|
||||
; Resources are linear and cannot be copied.
|
||||
; expect: reject E1001
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.copy_resource
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
%g = copy %f
|
||||
intrinsic fs.close(%f), ok -> @x, err -> @xf
|
||||
x:
|
||||
ret
|
||||
xf(%e2: io_error):
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,14 @@
|
||||
; fs.open_read is fallible and needs ok/err targets.
|
||||
; expect: reject E1001
|
||||
; phase: 2
|
||||
; spec: docs/reference/intrinsics.md
|
||||
module test.fallible_without_targets
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p)
|
||||
ret
|
||||
@@ -0,0 +1,19 @@
|
||||
; The caller does not declare the effect of the intrinsic.
|
||||
; expect: reject E3101
|
||||
; phase: 2
|
||||
; spec: docs/reference/intrinsics.md
|
||||
module test.intrinsic_effect
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects []
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
intrinsic fs.close(%f), ok -> @x, err -> @fail
|
||||
x:
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,17 @@
|
||||
; The ok target of fs.open_read takes exactly one parameter.
|
||||
; expect: reject E5002
|
||||
; phase: 2
|
||||
; spec: docs/reference/intrinsics.md
|
||||
module test.ok_arity
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened:
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,15 @@
|
||||
; Resources in aggregates need the reserved feature linear_aggregates.
|
||||
; expect: reject E0006
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.resource_in_struct
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
type @Log = struct { f: file<append> }
|
||||
|
||||
fn @f() -> void
|
||||
effects []
|
||||
entry:
|
||||
ret
|
||||
@@ -0,0 +1,25 @@
|
||||
; The file is closed on one path into the join but still owned on the other.
|
||||
; expect: reject E3002
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.resource_join_mismatch
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>, %b: bool) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
cbr %b, @close(), @keep()
|
||||
close:
|
||||
intrinsic fs.close(%f), ok -> @join, err -> @cf
|
||||
keep:
|
||||
br @join()
|
||||
join:
|
||||
trap
|
||||
cf(%e2: io_error):
|
||||
trap
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,17 @@
|
||||
; The opened file is never closed.
|
||||
; expect: reject E3002
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.resource_leak
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,23 @@
|
||||
; The file is borrowed after it was closed.
|
||||
; expect: reject E3001
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.use_after_close
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
intrinsic fs.close(%f), ok -> @closed, err -> @cfail
|
||||
closed:
|
||||
%m = borrow.mut %f
|
||||
borrow.end %m
|
||||
ret
|
||||
cfail(%e2: io_error):
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -1,16 +1,29 @@
|
||||
; %p is moved into %q and then used again.
|
||||
; The file is moved into a callee and then borrowed.
|
||||
; expect: reject E2001
|
||||
; phase: 2
|
||||
; spec: docs/spec/03-memory-model.md
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.use_after_move
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, heap, ownership]
|
||||
|
||||
fn @f(%p: Own<u64>) -> Own<u64>
|
||||
effects []
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
%q = move %p
|
||||
%r = move %p
|
||||
ret %r
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
call @take(%f)
|
||||
%m = borrow.mut %f
|
||||
borrow.end %m
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
|
||||
fn @take(%f: file<read>) -> void
|
||||
effects []
|
||||
entry:
|
||||
intrinsic fs.close(%f), ok -> @a, err -> @b
|
||||
a:
|
||||
ret
|
||||
b(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,19 @@
|
||||
; fs.create needs cap<fs.write>, not cap<fs.read>.
|
||||
; expect: reject E3201
|
||||
; phase: 2
|
||||
; spec: docs/reference/intrinsics.md
|
||||
module test.wrong_capability_kind
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.write]
|
||||
entry:
|
||||
intrinsic fs.create(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<write>):
|
||||
intrinsic fs.close(%f), ok -> @x, err -> @fail
|
||||
x:
|
||||
ret
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
@@ -0,0 +1,28 @@
|
||||
; Writing through a file opened for reading is rejected by the verifier.
|
||||
; expect: reject E1001
|
||||
; phase: 2
|
||||
; spec: docs/spec/06-resources-and-errors.md
|
||||
module test.wrong_file_mode
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, capabilities, effects, ownership, resources]
|
||||
|
||||
fn @f(%c: cap<fs.read>, %p: slice<u8>) -> void
|
||||
effects [fs.read]
|
||||
entry:
|
||||
intrinsic fs.open_read(%c, %p), ok -> @opened, err -> @fail
|
||||
opened(%f: file<read>):
|
||||
%m = borrow.mut %f
|
||||
intrinsic fs.write_all(%m, %p), ok -> @w, err -> @wf
|
||||
w:
|
||||
borrow.end %m
|
||||
intrinsic fs.close(%f), ok -> @x, err -> @xf
|
||||
x:
|
||||
ret
|
||||
xf(%e3: io_error):
|
||||
ret
|
||||
wf(%e2: io_error):
|
||||
borrow.end %m
|
||||
intrinsic fs.close(%f), ok -> @x, err -> @xf
|
||||
fail(%e: io_error):
|
||||
ret
|
||||
Reference in new issue
Block a user