Phase 6A: .aji layer 5 (linear values, own, regions, outcome matches, or trap)
- explicit move for named linear values; E7003 with suggestion "move x"; move of a copyable value is E7006; moved state left to the verifier - own.new/own.array/region.create/region.new/region.array/cap.narrow.budget as outcome matches or with `or trap`; own.take/own.free/region.reset/ region.destroy as AIR names in AIR operand order - region.new/region.array take an explicit ref/mut region binding (E7005 otherwise); reset/destroy end nothing (verifier E2104) - match kind (enum/outcome/integer) decided by the parser; built-in error enums (alloc_error, cap_error, io_error) matched exhaustively - cap<K> types; linear owners borrowed in place - features header = registry closure of the features used - parameters keep their source names (grants by @main parameter name) - aji lower --stats: mechanical_air_eliminated = 1 - source/AIR bytes - spec 15, grammar, quick reference, plan updated
This commit is contained in:
1 parent
eca30f817a
commit
bdcf871e5d
28 files changed
+882
-78
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// Correct source, but the owner is consumed again after its move: the verifier reports E2002.
|
||||
// expect: reject E2002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.doubleconsume
|
||||
|
||||
fn sink(o: own<u64>) -> void
|
||||
effects []
|
||||
{
|
||||
own.free(move o);
|
||||
}
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let x = own.new(1u64, heap) or trap;
|
||||
sink(move x);
|
||||
own.take(move x)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// An owner that is never consumed: the verifier reports the leak.
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.leak
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let x = own.new(1u64, heap) or trap;
|
||||
7
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// A struct with a linear field needs the unpublished linear_aggregates feature: AIR rejects it.
|
||||
// expect: reject E0006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.linearfield
|
||||
|
||||
struct Holder { o: own<u64> }
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Allocation without the effect: the verifier's E3101 (with suggested_effects).
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.missingeffect
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects []
|
||||
{
|
||||
let x = own.new(1u64, heap) or trap;
|
||||
own.take(move x)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// A named linear value passed without `move`: the frontend asks for it (hint "move x").
|
||||
// expect: reject E7003
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.missingmove
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let x = own.new(1u64, heap) or trap;
|
||||
own.take(x)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// An outcome match handles every outcome of the operation.
|
||||
// expect: reject E7004
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.missingoutcome
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
match own.new(1u64, heap) {
|
||||
ok(x) => own.take(move x),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// `move` applies only to linear values.
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.movecopy
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
let a = 3u64;
|
||||
move a
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// region.new takes an explicit region borrow binding; the frontend creates no hidden one.
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.regionvalue
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let r = region.create(heap) or trap;
|
||||
let item = region.new(r, 1u64) or trap;
|
||||
region.destroy(move r);
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// region.reset while an allocation borrow is live: the frontend ends nothing early; the verifier reports E2104.
|
||||
// expect: reject E2104
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.resetlive
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let r = region.create(heap) or trap;
|
||||
var v: u64 = 0;
|
||||
{
|
||||
ref arena = r;
|
||||
let item = region.new(arena, 1u64) or trap;
|
||||
region.reset(r);
|
||||
v = *item;
|
||||
}
|
||||
region.destroy(move r);
|
||||
v
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// A fallible operation used as a plain value: handle it with match or `or trap`.
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.unhandled
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let x = own.new(1u64, heap);
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Correct source, but the owner is borrowed after its move: the verifier reports E2001.
|
||||
// expect: reject E2001
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module demo.useaftermove
|
||||
|
||||
fn sink(o: own<u64>) -> void
|
||||
effects []
|
||||
{
|
||||
own.free(move o);
|
||||
}
|
||||
|
||||
fn read(c: ref<u64>) -> u64
|
||||
effects []
|
||||
{
|
||||
*c
|
||||
}
|
||||
|
||||
fn main(heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc]
|
||||
{
|
||||
let x = own.new(1u64, heap) or trap;
|
||||
sink(move x);
|
||||
read(ref x)
|
||||
}
|
||||
Reference in new issue
Block a user