- 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
31 lines
743 B
Rust
31 lines
743 B
Rust
// A region borrow is bound explicitly and outlives the allocation borrows derived from it.
|
|
// expect: run
|
|
// grant: heap=mem.alloc:256
|
|
// result: 30
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md
|
|
module demo.region
|
|
|
|
fn main(heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc]
|
|
{
|
|
let r = region.create(heap) or trap;
|
|
var total: u64 = 0;
|
|
{
|
|
ref arena = r;
|
|
match region.new(arena, 10u64) {
|
|
ok(item) => {
|
|
*item = *item + 10;
|
|
total = total + *item;
|
|
}
|
|
err(e) => {}
|
|
}
|
|
let s = region.array(arena, 4, 2u64) or trap;
|
|
s[0] = 8;
|
|
total = total + s[0] + s[1];
|
|
}
|
|
region.reset(r);
|
|
region.destroy(move r);
|
|
total
|
|
}
|