Phase 6A: .aji layer 6 (intrinsics, resources, narrowing, unsafe operations)
- intrinsics from the registry as plain calls: fallible ones are outcome matches or `or trap` (E7006 otherwise), infallible ones plain calls - resource operands by name, borrowed mut for the one operation and ended on every edge; a mut binding/parameter passes as is; `mut f` is E7006 - closes consume with `move` (E7003); no inserted closes (E3002/E3001) - data operands explicit (ref/mut/byte string, E7005 otherwise) - file<…>, stream, listener types; cap.narrow.prefix with cap_error edges - ref/mut unchecked s[i] (also as a binding) and assume(c) under effects [unsafe]; boundary left to the verifier (E6001) - trusted is reserved and rejected (E7006) - parameter names preserved; generated names avoid them (normative) - parser: >> closes two type arguments - conformance: `equivalent:` compares the run record with a reference AIR program (hello, file_copy, tcp_echo, narrow ok/not_subset/invalid, random) - spec 15, grammar, quick reference (io_error match fixed), plan, examples
This commit is contained in:
1 parent
bdcf871e5d
commit
c18fb7acc1
39 files changed
+1309
-69
No files matched your search
@@ -0,0 +1,12 @@
|
||||
// Closing consumes the resource: a named one must be written `move f`.
|
||||
// expect: reject E7003
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.closenomove
|
||||
|
||||
fn main(src: cap<fs.read>) -> void
|
||||
effects [fs.read]
|
||||
{
|
||||
let f = fs.open_read(src, b"/in/a") or trap;
|
||||
fs.close(f) or trap;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Data borrows stay explicit: a buffer is passed as `mut buf`.
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.databorrow
|
||||
|
||||
fn main(input: cap<io.read>) -> usize
|
||||
effects [io.read]
|
||||
{
|
||||
var buf: [u8; 4] = zero;
|
||||
io.stdin_read(input, buf) or trap
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// An infallible intrinsic has no outcomes to match.
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.infalliblematch
|
||||
|
||||
fn main(clock: cap<clock.read>) -> u64
|
||||
effects [clock.read]
|
||||
{
|
||||
match clock.monotonic(clock) {
|
||||
ok(t) => t,
|
||||
err(e) => 0,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// An intrinsic without its effect: the verifier's E3101 names it.
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.ioeffect
|
||||
|
||||
fn main(out: cap<io.write>) -> void
|
||||
effects []
|
||||
{
|
||||
io.stdout_write(out, b"x") or trap;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// A resource operand is written by name; the operation borrows it (one canonical spelling).
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.resourceborrow
|
||||
|
||||
fn main(src: cap<fs.read>) -> void
|
||||
effects [fs.read]
|
||||
{
|
||||
let f = fs.open_read(src, b"/in/a") or trap;
|
||||
var buf: [u8; 4] = zero;
|
||||
let n = fs.read(mut f, mut buf) or trap;
|
||||
fs.close(move f) or trap;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// The frontend never inserts a close: an unclosed file is the verifier's leak.
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.resourceleak
|
||||
|
||||
fn main(src: cap<fs.read>) -> void
|
||||
effects [fs.read]
|
||||
{
|
||||
let f = fs.open_read(src, b"/in/a") or trap;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// `trusted` belongs to runtime, std and toolchain modules; a program cannot declare its own code trusted.
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.trusted
|
||||
|
||||
fn get(s: slice<u64>, i: usize) -> u64
|
||||
effects []
|
||||
trusted "callers check the bound"
|
||||
{
|
||||
ref unchecked e = s[i];
|
||||
*e
|
||||
}
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// `unchecked` applies to one element, not a range.
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.uncheckedrange
|
||||
|
||||
fn f(s: slice<u64>) -> u64
|
||||
effects [unsafe]
|
||||
{
|
||||
ref unchecked r = s[0..2];
|
||||
0
|
||||
}
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// A fallible intrinsic is handled with `match` or `or trap`; there is no implicit propagation.
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.unhandledio
|
||||
|
||||
fn main(out: cap<io.write>) -> void
|
||||
effects [io.write]
|
||||
{
|
||||
io.stdout_write(out, b"x");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// An unsafe operation outside an `unsafe` function: the verifier decides (E6001).
|
||||
// expect: reject E6001
|
||||
// phase: 6
|
||||
// spec: docs/spec/13-contracts-and-unsafe.md
|
||||
module demo.unsafeboundary
|
||||
|
||||
fn get(s: slice<u64>, i: usize) -> u64
|
||||
effects []
|
||||
{
|
||||
ref unchecked e = s[i];
|
||||
*e
|
||||
}
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// A file used after it was closed: the verifier reports it.
|
||||
// expect: reject E3001
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.useafterclose
|
||||
|
||||
fn main(src: cap<fs.read>) -> void
|
||||
effects [fs.read]
|
||||
{
|
||||
let f = fs.open_read(src, b"/in/a") or trap;
|
||||
fs.close(move f) or trap;
|
||||
var buf: [u8; 4] = zero;
|
||||
let n = fs.read(f, mut buf) or trap;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// A capability of the wrong kind: the verifier's E3201.
|
||||
// expect: reject E3201
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.wrongcap
|
||||
|
||||
fn main(out: cap<io.read>) -> void
|
||||
effects [io.write]
|
||||
{
|
||||
io.stdout_write(out, b"x") or trap;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// fs.write_all needs a writable file; a file<read> is rejected at the operand.
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.wrongmode
|
||||
|
||||
fn main(src: cap<fs.read>) -> void
|
||||
effects [fs.read, fs.write]
|
||||
{
|
||||
let f = fs.open_read(src, b"/in/a") or trap;
|
||||
fs.write_all(f, b"x") or trap;
|
||||
fs.close(move f) or trap;
|
||||
}
|
||||
Reference in new issue
Block a user