cli: add safe owning numeric-key maps
Register std.map with bounded U64Map<V>, exact key equality and explicit allocation/growth. Preserve returned ownership, old slots on reserve failure and original-authority refunds; support Copy values, owners and resources. Cover collision/tombstone/wrap behavior, independent dictionary traces, quota/cleanup/borrow/task rules, source/AIR parity and hosted/package CLI. Publish the API, roadmap and measured documentation cost. General key hashing/equality remains Q-037; numeric maps do not satisfy that gate.
This commit is contained in:
1 parent
fc23f1b23a
commit
57603860df
46 files changed
+2430
-15
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<u64>>) -> void effects [] { ref observed = q; inserted::<u64>(std.map.insert::<u64>(q, 0, 42)); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:35
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
match std.map.new::<own<u64>>(1, heap) {
|
||||
std.map.NewResult::<own<u64>>::ok(map) => { trap; }
|
||||
std.map.NewResult::<own<u64>>::err(error) => {
|
||||
match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } }
|
||||
}
|
||||
}
|
||||
match std.map.new::<u64>((0usize -% 1usize) / 2usize + 1usize, heap) {
|
||||
std.map.NewResult::<u64>::ok(map) => { trap; }
|
||||
std.map.NewResult::<u64>::err(error) => {
|
||||
match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } }
|
||||
}
|
||||
}
|
||||
let owner = own.new(42u64, heap) or trap; return own.take(move owner);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:1024
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<u64>(4, heap);
|
||||
{ mut q = map;
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 0, 1));
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 8, 2));
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 16, 3));
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 24, 4));
|
||||
assert(extracted::<u64>(std.map.remove::<u64>(q, 8)) == 2u64);
|
||||
match std.map.insert::<u64>(q, 16, 42) {
|
||||
std.map.InsertResult::<u64>::replaced(previous) => { assert(previous == 3u64); }
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 32, 5));
|
||||
assert(extracted::<u64>(std.map.get::<u64>(ref q, 24)) == 4u64);
|
||||
assert(extracted::<u64>(std.map.get::<u64>(ref q, 16)) == 42u64);
|
||||
assert(extracted::<u64>(std.map.get::<u64>(ref q, 32)) == 5u64);
|
||||
assert(not std.map.contains::<u64>(ref q, 8));
|
||||
match std.map.reserve::<u64>(q, 7, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
for key in 0u64..5u64 {
|
||||
if key != 1u64 { let removed = extracted::<u64>(std.map.remove::<u64>(q, key * 8u64)); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 0usize);
|
||||
}
|
||||
released::<u64>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:1024
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<u64>(2, heap);
|
||||
{ ref q = map; assert(std.map.len::<u64>(ref q) == 0); assert(std.map.capacity::<u64>(ref q) == 2); }
|
||||
{ mut q = map;
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 0, 7u64));
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 0xffffffffffffffffu64, 42u64));
|
||||
match std.map.insert::<u64>(q, 0, 9u64) {
|
||||
std.map.InsertResult::<u64>::replaced(old) => { assert(old == 7u64); }
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::full(value) => { trap; }
|
||||
}
|
||||
match std.map.insert::<u64>(q, 3, 99u64) {
|
||||
std.map.InsertResult::<u64>::full(value) => { assert(value == 99u64); }
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(old) => { trap; }
|
||||
}
|
||||
}
|
||||
{ ref q = map;
|
||||
assert(std.map.contains::<u64>(ref q, 0)); assert(not std.map.contains::<u64>(ref q, 3));
|
||||
assert(extracted::<u64>(std.map.get::<u64>(ref q, 0)) == 9u64);
|
||||
assert(extracted::<u64>(std.map.get::<u64>(ref q, 0xffffffffffffffffu64)) == 42u64);
|
||||
}
|
||||
{ mut q = map;
|
||||
match std.map.remove::<u64>(q, 3) { std.option.Option::<u64>::none => {}, std.option.Option::<u64>::some(value) => { trap; } }
|
||||
assert(extracted::<u64>(std.map.remove::<u64>(q, 0)) == 9u64);
|
||||
match std.map.reserve::<u64>(q, 4, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
let entry = extracted::<std.map.Entry<u64>>(std.map.pop::<u64>(q));
|
||||
assert(entry.key == 0xffffffffffffffffu64 and entry.value == 42u64);
|
||||
match std.map.pop::<u64>(q) { std.option.Option::<std.map.Entry<u64>>::none => {}, std.option.Option::<std.map.Entry<u64>>::some(value) => { trap; } }
|
||||
}
|
||||
released::<u64>(move map);
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// expect: reject E2002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
fn bad(map: std.map.U64Map<u64>) -> void effects [] {
|
||||
let first = std.map.free::<u64>(move map);
|
||||
let second = std.map.free::<u64>(move map);
|
||||
trap;
|
||||
}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,46 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// file: /out/map.txt=42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:36
|
||||
// grant: dst=fs.write:/out
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>, dst: cap<fs.write>) -> u64 effects [mem.alloc, fs.write] {
|
||||
let map = opened::<file<write>>(1, heap);
|
||||
let file = fs.create(dst, b"/out/map.txt") or trap;
|
||||
{ mut q = map; inserted::<file<write>>(std.map.insert::<file<write>>(q, 7, move file));
|
||||
let item = extracted::<file<write>>(std.map.remove::<file<write>>(q, 7));
|
||||
fs.write_all(item, ref b"42") or trap; fs.close(move item) or trap;
|
||||
}
|
||||
released::<file<write>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(map: std.map.U64Map<own<u64>>) -> void effects [] { match std.map.free::<own<u64>>(move map) { std.map.FreeResult::<own<u64>>::ok => { return; }, std.map.FreeResult::<own<u64>>::not_empty(returned) => { return; } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<own<u64>>>, item: own<u64>) -> void effects [] { match std.map.insert::<own<u64>>(q, 0, move item) { std.map.InsertResult::<own<u64>>::inserted => { return; }, std.map.InsertResult::<own<u64>>::replaced(old) => { own.free(move old); return; }, std.map.InsertResult::<own<u64>>::full(returned) => { return; } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: ref<std.map.U64Map<own<u64>>>) -> void effects [] { let item = std.map.get::<own<u64>>(ref q, 0); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<u64>>, heap: cap<mem.alloc>) -> void effects [] { match std.map.reserve::<u64>(q, 8, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => {} } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,40 @@
|
||||
// expect: run
|
||||
// trap: T0001
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:44
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(1, heap); let owner = own.new(42u64, heap) or trap;
|
||||
{ mut q = map; inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 0, move owner)); q.length = 0; }
|
||||
released::<own<u64>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// expect: run
|
||||
// trap: T0001
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:44
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(1, heap); let owner = own.new(42u64, heap) or trap;
|
||||
{ mut q = map; inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 0, move owner)); q.length = 0;
|
||||
{ mut storage = q.storage; mut slots = buffer.view(storage);
|
||||
for index in 0usize..2usize { mut slot = slots[index]; slot.state = std.map.SlotState::deleted; }
|
||||
} }
|
||||
released::<own<u64>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: reject E4101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn worker(q: mut<std.map.U64Map<u64>>) -> void effects [] {}
|
||||
fn bad(q: mut<std.map.U64Map<u64>>) -> void effects [task.spawn, task.wait] { scope s { let t = task.spawn(s, worker, q); inserted::<u64>(std.map.insert::<u64>(q, 0, 42)); task.join(move t); } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,45 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:44
|
||||
// schedules: 12
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn worker(q: mut<std.map.U64Map<own<u64>>>) -> void effects [] { let item = extracted::<own<u64>>(std.map.remove::<own<u64>>(q, 7)); assert(own.take(move item) == 42u64); }
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc, task.spawn, task.wait] {
|
||||
let map = opened::<own<u64>>(1, heap); let owner = own.new(42u64, heap) or trap;
|
||||
{ mut q = map; inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 7, move owner));
|
||||
scope s { let t = task.spawn(s, worker, q); task.join(move t); }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 0usize);
|
||||
}
|
||||
released::<own<u64>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E7003
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<own<u64>>>, item: own<u64>) -> void effects [] { inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 0, item)); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,371 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:1024
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<u64>(2, heap);
|
||||
{ mut q = map;
|
||||
assert(std.map.contains::<u64>(ref q, 16) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 0usize);
|
||||
match std.map.insert::<u64>(q, 16, 607) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 1usize);
|
||||
match std.map.insert::<u64>(q, 1, 165) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.get::<u64>(ref q, 1) { std.option.Option::<u64>::some(returned) => { assert(returned == 165u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.remove::<u64>(q, 1) { std.option.Option::<u64>::some(returned) => { assert(returned == 165u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 1usize);
|
||||
assert(std.map.contains::<u64>(ref q, 24) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 1usize);
|
||||
match std.map.insert::<u64>(q, 1, 63) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.get::<u64>(ref q, 18446744073709551615) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.insert::<u64>(q, 1, 584) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 63u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.insert::<u64>(q, 24, 218) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 218u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.get::<u64>(ref q, 1) { std.option.Option::<u64>::some(returned) => { assert(returned == 584u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.insert::<u64>(q, 32, 836) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 836u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.insert::<u64>(q, 32, 996) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 996u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.insert::<u64>(q, 32, 511) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 511u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
assert(std.map.contains::<u64>(ref q, 24) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.insert::<u64>(q, 32, 733) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 733u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.remove::<u64>(q, 32) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.remove::<u64>(q, 32) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 2usize);
|
||||
match std.map.reserve::<u64>(q, 4, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
match std.map.insert::<u64>(q, 8, 173) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
assert(std.map.contains::<u64>(ref q, 18446744073709551615) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
assert(std.map.contains::<u64>(ref q, 18446744073709551615) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
assert(std.map.contains::<u64>(ref q, 0) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.get::<u64>(ref q, 18446744073709551615) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.insert::<u64>(q, 8, 495) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 173u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.get::<u64>(ref q, 8) { std.option.Option::<u64>::some(returned) => { assert(returned == 495u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
assert(std.map.contains::<u64>(ref q, 16) == true);
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.insert::<u64>(q, 32, 693) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 18446744073709551615, 999) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 999u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 8, 391) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 495u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.remove::<u64>(q, 32) { std.option.Option::<u64>::some(returned) => { assert(returned == 693u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.insert::<u64>(q, 32, 238) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 18446744073709551615, 172) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { assert(returned == 172u64); }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 16, 415) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 607u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.remove::<u64>(q, 8) { std.option.Option::<u64>::some(returned) => { assert(returned == 391u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.insert::<u64>(q, 32, 595) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 238u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.insert::<u64>(q, 18446744073709551615, 27) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.reserve::<u64>(q, 6, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
assert(std.map.contains::<u64>(ref q, 0) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.remove::<u64>(q, 18446744073709551615) { std.option.Option::<u64>::some(returned) => { assert(returned == 27u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 3usize);
|
||||
match std.map.insert::<u64>(q, 8, 258) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.remove::<u64>(q, 18446744073709551615) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 32, 446) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 595u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 1, 311) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 584u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
assert(std.map.contains::<u64>(ref q, 24) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.get::<u64>(ref q, 24) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 24, 764) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.get::<u64>(ref q, 16) { std.option.Option::<u64>::some(returned) => { assert(returned == 415u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.remove::<u64>(q, 0) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
assert(std.map.contains::<u64>(ref q, 0) == false);
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 0, 274) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 6usize);
|
||||
match std.map.remove::<u64>(q, 8) { std.option.Option::<u64>::some(returned) => { assert(returned == 258u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 0, 58) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 274u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.get::<u64>(ref q, 16) { std.option.Option::<u64>::some(returned) => { assert(returned == 415u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 8, 394) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 6usize);
|
||||
match std.map.get::<u64>(ref q, 8) { std.option.Option::<u64>::some(returned) => { assert(returned == 394u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 6usize);
|
||||
match std.map.remove::<u64>(q, 0) { std.option.Option::<u64>::some(returned) => { assert(returned == 58u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.get::<u64>(ref q, 0) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 0, 476) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 6usize);
|
||||
match std.map.remove::<u64>(q, 8) { std.option.Option::<u64>::some(returned) => { assert(returned == 394u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.remove::<u64>(q, 1) { std.option.Option::<u64>::some(returned) => { assert(returned == 311u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 1, 893) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 0, 529) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 476u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 0, 385) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 529u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.get::<u64>(ref q, 8) { std.option.Option::<u64>::some(returned) => { trap; }, std.option.Option::<u64>::none => {} }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.insert::<u64>(q, 0, 777) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 385u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
assert(std.map.contains::<u64>(ref q, 32) == true);
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.remove::<u64>(q, 1) { std.option.Option::<u64>::some(returned) => { assert(returned == 893u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 18446744073709551615, 423) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.remove::<u64>(q, 18446744073709551615) { std.option.Option::<u64>::some(returned) => { assert(returned == 423u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 16, 269) {
|
||||
std.map.InsertResult::<u64>::inserted => { trap; }
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { assert(returned == 415u64); }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 4usize);
|
||||
match std.map.insert::<u64>(q, 8, 172) {
|
||||
std.map.InsertResult::<u64>::inserted => {}
|
||||
std.map.InsertResult::<u64>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<u64>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.get::<u64>(ref q, 0) { std.option.Option::<u64>::some(returned) => { assert(returned == 777u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
match std.map.get::<u64>(ref q, 24) { std.option.Option::<u64>::some(returned) => { assert(returned == 764u64); }, std.option.Option::<u64>::none => { trap; } }
|
||||
assert(std.map.len::<u64>(ref q) == 5usize);
|
||||
var seen: [bool; 5] = zero;
|
||||
{ let entry = extracted::<std.map.Entry<u64>>(std.map.pop::<u64>(q)); let (key, value) = struct.unpack(entry);
|
||||
let number = value;
|
||||
match key {
|
||||
0u64 => { assert(number == 777u64); assert(not seen[0]); seen[0] = true; }
|
||||
8u64 => { assert(number == 172u64); assert(not seen[1]); seen[1] = true; }
|
||||
16u64 => { assert(number == 269u64); assert(not seen[2]); seen[2] = true; }
|
||||
24u64 => { assert(number == 764u64); assert(not seen[3]); seen[3] = true; }
|
||||
32u64 => { assert(number == 446u64); assert(not seen[4]); seen[4] = true; }
|
||||
_ => { trap; } } }
|
||||
{ let entry = extracted::<std.map.Entry<u64>>(std.map.pop::<u64>(q)); let (key, value) = struct.unpack(entry);
|
||||
let number = value;
|
||||
match key {
|
||||
0u64 => { assert(number == 777u64); assert(not seen[0]); seen[0] = true; }
|
||||
8u64 => { assert(number == 172u64); assert(not seen[1]); seen[1] = true; }
|
||||
16u64 => { assert(number == 269u64); assert(not seen[2]); seen[2] = true; }
|
||||
24u64 => { assert(number == 764u64); assert(not seen[3]); seen[3] = true; }
|
||||
32u64 => { assert(number == 446u64); assert(not seen[4]); seen[4] = true; }
|
||||
_ => { trap; } } }
|
||||
{ let entry = extracted::<std.map.Entry<u64>>(std.map.pop::<u64>(q)); let (key, value) = struct.unpack(entry);
|
||||
let number = value;
|
||||
match key {
|
||||
0u64 => { assert(number == 777u64); assert(not seen[0]); seen[0] = true; }
|
||||
8u64 => { assert(number == 172u64); assert(not seen[1]); seen[1] = true; }
|
||||
16u64 => { assert(number == 269u64); assert(not seen[2]); seen[2] = true; }
|
||||
24u64 => { assert(number == 764u64); assert(not seen[3]); seen[3] = true; }
|
||||
32u64 => { assert(number == 446u64); assert(not seen[4]); seen[4] = true; }
|
||||
_ => { trap; } } }
|
||||
{ let entry = extracted::<std.map.Entry<u64>>(std.map.pop::<u64>(q)); let (key, value) = struct.unpack(entry);
|
||||
let number = value;
|
||||
match key {
|
||||
0u64 => { assert(number == 777u64); assert(not seen[0]); seen[0] = true; }
|
||||
8u64 => { assert(number == 172u64); assert(not seen[1]); seen[1] = true; }
|
||||
16u64 => { assert(number == 269u64); assert(not seen[2]); seen[2] = true; }
|
||||
24u64 => { assert(number == 764u64); assert(not seen[3]); seen[3] = true; }
|
||||
32u64 => { assert(number == 446u64); assert(not seen[4]); seen[4] = true; }
|
||||
_ => { trap; } } }
|
||||
{ let entry = extracted::<std.map.Entry<u64>>(std.map.pop::<u64>(q)); let (key, value) = struct.unpack(entry);
|
||||
let number = value;
|
||||
match key {
|
||||
0u64 => { assert(number == 777u64); assert(not seen[0]); seen[0] = true; }
|
||||
8u64 => { assert(number == 172u64); assert(not seen[1]); seen[1] = true; }
|
||||
16u64 => { assert(number == 269u64); assert(not seen[2]); seen[2] = true; }
|
||||
24u64 => { assert(number == 764u64); assert(not seen[3]); seen[3] = true; }
|
||||
32u64 => { assert(number == 446u64); assert(not seen[4]); seen[4] = true; }
|
||||
_ => { trap; } } }
|
||||
assert(std.map.len::<u64>(ref q) == 0usize);
|
||||
match std.map.pop::<u64>(q) { std.option.Option::<std.map.Entry<u64>>::none => {}, std.option.Option::<std.map.Entry<u64>>::some(unexpected) => { trap; } }
|
||||
}
|
||||
released::<u64>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:1024
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(2, heap);
|
||||
{ mut q = map;
|
||||
match std.map.remove::<own<u64>>(q, 16) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 0usize);
|
||||
let input1 = own.new(972u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 1, move input1) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 1usize);
|
||||
match std.map.remove::<own<u64>>(q, 0) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 1usize);
|
||||
match std.map.remove::<own<u64>>(q, 0) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 1usize);
|
||||
match std.map.remove::<own<u64>>(q, 8) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 1usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 18446744073709551615) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 1usize);
|
||||
let input6 = own.new(149u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 8, move input6) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
match std.map.remove::<own<u64>>(q, 24) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input8 = own.new(969u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 0, move input8) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 969u64); }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input9 = own.new(139u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 32, move input9) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 139u64); }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 18446744073709551615) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input11 = own.new(639u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 32, move input11) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 639u64); }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input12 = own.new(431u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 24, move input12) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 431u64); }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 8) == true);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input14 = own.new(61u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 24, move input14) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 61u64); }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input16 = own.new(202u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 24, move input16) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 202u64); }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
match std.map.reserve::<own<u64>>(q, 4, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
match std.map.remove::<own<u64>>(q, 24) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 16) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
match std.map.remove::<own<u64>>(q, 0) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 8) == true);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
match std.map.remove::<own<u64>>(q, 16) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input23 = own.new(44u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 1, move input23) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { assert(own.take(move returned) == 972u64); }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 24) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input25 = own.new(235u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 16, move input25) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
let input26 = own.new(287u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 32, move input26) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 287u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 18446744073709551615) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
let input29 = own.new(678u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 18446744073709551615, move input29) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
match std.map.remove::<own<u64>>(q, 8) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 149u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 24) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
let input34 = own.new(275u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 24, move input34) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 8) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
match std.map.reserve::<own<u64>>(q, 6, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
let input36 = own.new(369u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 32, move input36) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 5usize);
|
||||
let input37 = own.new(207u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 24, move input37) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { assert(own.take(move returned) == 275u64); }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 5usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 18446744073709551615) == true);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 5usize);
|
||||
let input39 = own.new(351u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 24, move input39) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { assert(own.take(move returned) == 207u64); }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 5usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 8) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 5usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 369u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 32) == false);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
assert(std.map.contains::<own<u64>>(ref q, 18446744073709551615) == true);
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
let input45 = own.new(557u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 8, move input45) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 5usize);
|
||||
match std.map.remove::<own<u64>>(q, 24) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 351u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
let input47 = own.new(171u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 18446744073709551615, move input47) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { assert(own.take(move returned) == 678u64); }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 4usize);
|
||||
match std.map.remove::<own<u64>>(q, 8) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 557u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
match std.map.remove::<own<u64>>(q, 0) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
match std.map.remove::<own<u64>>(q, 24) { std.option.Option::<own<u64>>::some(returned) => { trap; }, std.option.Option::<own<u64>>::none => {} }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
let input51 = own.new(533u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 18446744073709551615, move input51) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { assert(own.take(move returned) == 171u64); }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
match std.map.remove::<own<u64>>(q, 18446744073709551615) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 533u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input53 = own.new(91u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 32, move input53) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
match std.map.remove::<own<u64>>(q, 32) { std.option.Option::<own<u64>>::some(returned) => { assert(own.take(move returned) == 91u64); }, std.option.Option::<own<u64>>::none => { trap; } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize);
|
||||
let input55 = own.new(610u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 32, move input55) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(returned) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 3usize);
|
||||
var seen: [bool; 3] = zero;
|
||||
{ let entry = extracted::<std.map.Entry<own<u64>>>(std.map.pop::<own<u64>>(q)); let (key, value) = struct.unpack(move entry);
|
||||
let number = own.take(move value);
|
||||
match key {
|
||||
1u64 => { assert(number == 44u64); assert(not seen[0]); seen[0] = true; }
|
||||
16u64 => { assert(number == 235u64); assert(not seen[1]); seen[1] = true; }
|
||||
32u64 => { assert(number == 610u64); assert(not seen[2]); seen[2] = true; }
|
||||
_ => { trap; } } }
|
||||
{ let entry = extracted::<std.map.Entry<own<u64>>>(std.map.pop::<own<u64>>(q)); let (key, value) = struct.unpack(move entry);
|
||||
let number = own.take(move value);
|
||||
match key {
|
||||
1u64 => { assert(number == 44u64); assert(not seen[0]); seen[0] = true; }
|
||||
16u64 => { assert(number == 235u64); assert(not seen[1]); seen[1] = true; }
|
||||
32u64 => { assert(number == 610u64); assert(not seen[2]); seen[2] = true; }
|
||||
_ => { trap; } } }
|
||||
{ let entry = extracted::<std.map.Entry<own<u64>>>(std.map.pop::<own<u64>>(q)); let (key, value) = struct.unpack(move entry);
|
||||
let number = own.take(move value);
|
||||
match key {
|
||||
1u64 => { assert(number == 44u64); assert(not seen[0]); seen[0] = true; }
|
||||
16u64 => { assert(number == 235u64); assert(not seen[1]); seen[1] = true; }
|
||||
32u64 => { assert(number == 610u64); assert(not seen[2]); seen[2] = true; }
|
||||
_ => { trap; } } }
|
||||
assert(std.map.len::<own<u64>>(ref q) == 0usize);
|
||||
match std.map.pop::<own<u64>>(q) { std.option.Option::<std.map.Entry<own<u64>>>::none => {}, std.option.Option::<std.map.Entry<own<u64>>>::some(unexpected) => { trap; } }
|
||||
}
|
||||
released::<own<u64>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: reject E4002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn worker(q: ref<std.map.U64Map<file<write>>>) -> void effects [] {}
|
||||
fn bad(q: ref<std.map.U64Map<file<write>>>) -> void effects [task.spawn, task.wait] { scope s { let t = task.spawn(s, worker, q); task.join(move t); } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,65 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:1024
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(1, heap);
|
||||
let first = own.new(7u64, heap) or trap;
|
||||
{ mut q = map; inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 7, move first)); }
|
||||
{ ref q = map; assert(std.map.contains::<own<u64>>(ref q, 7)); }
|
||||
let second = own.new(42u64, heap) or trap;
|
||||
{ mut q = map;
|
||||
match std.map.insert::<own<u64>>(q, 7, move second) {
|
||||
std.map.InsertResult::<own<u64>>::replaced(old) => { assert(own.take(move old) == 7u64); }
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
let third = own.new(99u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 8, move third) {
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { assert(own.take(move returned) == 99u64); }
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(old) => { trap; }
|
||||
}
|
||||
}
|
||||
match std.map.free::<own<u64>>(move map) {
|
||||
std.map.FreeResult::<own<u64>>::not_empty(returned) => {
|
||||
{ mut q = returned;
|
||||
match std.map.reserve::<own<u64>>(q, 3, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
let entry = extracted::<std.map.Entry<own<u64>>>(std.map.pop::<own<u64>>(q));
|
||||
let (key, owner) = struct.unpack(move entry); assert(key == 7u64); assert(own.take(move owner) == 42u64);
|
||||
}
|
||||
released::<own<u64>>(move returned);
|
||||
}
|
||||
std.map.FreeResult::<own<u64>>::ok => { trap; }
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<own<u64>>>) -> void effects [] { let item = std.map.pop::<own<u64>>(q); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<own<u64>>>, item: own<u64>) -> void effects [] { match std.map.insert::<own<u64>>(q, 0, move item) { std.map.InsertResult::<own<u64>>::inserted => {}, std.map.InsertResult::<own<u64>>::replaced(old) => {}, std.map.InsertResult::<own<u64>>::full(returned) => { own.free(move returned); } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,48 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: first=mem.alloc:72
|
||||
// grant: second=mem.alloc:108
|
||||
// grant: items=mem.alloc:8
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(first: cap<mem.alloc>, second: cap<mem.alloc>, items: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(2, first);
|
||||
let a = own.new(42u64, items) or trap;
|
||||
{ mut q = map; inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 9, move a));
|
||||
match std.map.reserve::<own<u64>>(q, 3, second) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
}
|
||||
let reused = opened::<own<u64>>(2, first); released::<own<u64>>(move reused);
|
||||
{ mut q = map; let owner = extracted::<own<u64>>(std.map.remove::<own<u64>>(q, 9)); assert(own.take(move owner) == 42u64); }
|
||||
released::<own<u64>>(move map);
|
||||
let next = opened::<own<u64>>(3, second); released::<own<u64>>(move next);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:195
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(2, heap);
|
||||
let a = own.new(7u64, heap) or trap; let b = own.new(42u64, heap) or trap;
|
||||
{ mut q = map;
|
||||
inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 0, move a));
|
||||
inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 8, move b));
|
||||
var keys: [u64; 4] = zero; var occupied: [bool; 4] = zero;
|
||||
{ ref storage = q.storage; ref slots = buffer.view(storage);
|
||||
for i in 0usize..4usize { ref slot = slots[i]; keys[i] = slot.key;
|
||||
occupied[i] = match slot.state { std.map.SlotState::occupied => { true }, std.map.SlotState::empty => { false }, std.map.SlotState::deleted => { trap; } };
|
||||
}
|
||||
}
|
||||
match std.map.reserve::<own<u64>>(q, 3, heap) {
|
||||
std.map.ReserveResult::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }
|
||||
std.map.ReserveResult::ok => { trap; }
|
||||
}
|
||||
match std.map.reserve::<own<u64>>(q, (0usize -% 1usize) / 2usize + 1usize, heap) {
|
||||
std.map.ReserveResult::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }
|
||||
std.map.ReserveResult::ok => { trap; }
|
||||
}
|
||||
assert(std.map.len::<own<u64>>(ref q) == 2usize); assert(std.map.capacity::<own<u64>>(ref q) == 2usize);
|
||||
{ ref storage = q.storage; ref slots = buffer.view(storage);
|
||||
for i in 0usize..4usize { ref slot = slots[i]; assert(slot.key == keys[i]);
|
||||
let state = match slot.state { std.map.SlotState::occupied => { true }, std.map.SlotState::empty => { false }, std.map.SlotState::deleted => { trap; } };
|
||||
assert(state == occupied[i]);
|
||||
}
|
||||
}
|
||||
for i in 0usize..4usize { if occupied[i] {
|
||||
let entry = extracted::<std.map.Entry<own<u64>>>(std.map.pop::<own<u64>>(q));
|
||||
let (key, item) = struct.unpack(move entry); assert(key == keys[i]);
|
||||
let value = own.take(move item); assert(value == if key == 0u64 { 7u64 } else { 42u64 });
|
||||
} }
|
||||
}
|
||||
released::<own<u64>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:196
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let first = cap.narrow.budget(heap, 88usize) or trap;
|
||||
let map = opened::<own<u64>>(2, first);
|
||||
let a = own.new(7u64, first) or trap; let b = own.new(42u64, first) or trap;
|
||||
{ mut q = map;
|
||||
inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 0, move a));
|
||||
inserted::<own<u64>>(std.map.insert::<own<u64>>(q, 8, move b));
|
||||
match std.map.reserve::<own<u64>>(q, 3, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
}
|
||||
// Old table's 72 bytes must be refunded to the original narrowed authority.
|
||||
let reclaimed = own.array(9usize, 42u64, first) or trap; own.free(move reclaimed);
|
||||
{ mut q = map;
|
||||
let first_owner = extracted::<own<u64>>(std.map.remove::<own<u64>>(q, 0)); assert(own.take(move first_owner) == 7u64);
|
||||
let second_owner = extracted::<own<u64>>(std.map.remove::<own<u64>>(q, 8)); assert(own.take(move second_owner) == 42u64);
|
||||
}
|
||||
released::<own<u64>>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:256
|
||||
// schedules: 12
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
struct Job { number: u64 }
|
||||
fn worker(map: std.map.U64Map<sender<Job>>) -> void effects [task.wait] {
|
||||
{ mut q = map; let entry = extracted::<std.map.Entry<sender<Job>>>(std.map.pop::<sender<Job>>(q));
|
||||
let (key, tx) = struct.unpack(move entry); assert(key == 7u64);
|
||||
channel.send(tx, Job { number: 42 }) or trap; channel.close_sender(move tx);
|
||||
}
|
||||
released::<sender<Job>>(move map);
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc, task.spawn, task.wait] {
|
||||
match channel.make<Job>(1, heap) { ok(tx, rx) => {
|
||||
let map = opened::<sender<Job>>(1, heap);
|
||||
{ mut q = map; inserted::<sender<Job>>(std.map.insert::<sender<Job>>(q, 7, move tx)); }
|
||||
scope s { let t = task.spawn(s, worker, move map); let job = channel.recv(rx) or trap; task.join(move t); channel.close_receiver(move rx) or trap; assert(job.number == 42u64); }
|
||||
}, err(error) => { trap; } }
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:36
|
||||
// schedules: 12
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn worker(q: ref<std.map.U64Map<u64>>) -> u64 effects [] { return extracted::<u64>(std.map.get::<u64>(ref q, 7)); }
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc, task.spawn, task.wait] {
|
||||
let map = opened::<u64>(1, heap);
|
||||
{ mut q = map; inserted::<u64>(std.map.insert::<u64>(q, 7, 42)); }
|
||||
{ ref q = map; scope s { let a = task.spawn(s, worker, q); let b = task.spawn(s, worker, q); assert(task.join(move a) == 42u64); assert(task.join(move b) == 42u64); } }
|
||||
{ mut q = map; assert(extracted::<u64>(std.map.remove::<u64>(q, 7)) == 42u64); }
|
||||
released::<u64>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
fn bad(map: mut<std.map.U64Map<u64>>) -> void effects [] {
|
||||
ref storage = map.storage;
|
||||
ref slots = buffer.view(storage);
|
||||
let result = std.map.remove::<u64>(map, 7);
|
||||
}
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,55 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:1024
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<u64>(2, heap);
|
||||
{ mut q = map;
|
||||
for key in 0u64..4u64 {
|
||||
inserted::<u64>(std.map.insert::<u64>(q, key, 42));
|
||||
assert(extracted::<u64>(std.map.remove::<u64>(q, key)) == 42u64);
|
||||
}
|
||||
{ ref storage = q.storage; ref slots = buffer.view(storage);
|
||||
for index in 0usize..4usize {
|
||||
ref slot = slots[index];
|
||||
match slot.state { std.map.SlotState::deleted => {}, std.map.SlotState::empty => { trap; }, std.map.SlotState::occupied => { trap; } }
|
||||
}
|
||||
}
|
||||
assert(not std.map.contains::<u64>(ref q, 99));
|
||||
match std.map.remove::<u64>(q, 99) { std.option.Option::<u64>::none => {}, std.option.Option::<u64>::some(unexpected) => { trap; } }
|
||||
inserted::<u64>(std.map.insert::<u64>(q, 42, 42));
|
||||
assert(extracted::<u64>(std.map.remove::<u64>(q, 42)) == 42u64);
|
||||
}
|
||||
released::<u64>(move map);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn bad(q: mut<std.map.U64Map<u64>>) -> void effects [] { inserted::<u64>(std.map.insert::<u64>(q, 0u32, 42)); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,49 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.13
|
||||
// grant: heap=mem.alloc:8
|
||||
module test.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn opened<V>(capacity: usize, heap: cap<mem.alloc>) -> std.map.U64Map<V> effects [mem.alloc] {
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
std.map.NewResult::<V>::ok(map) => { return move map; }
|
||||
std.map.NewResult::<V>::err(error) => { trap; }
|
||||
}
|
||||
}
|
||||
fn inserted<V>(result: std.map.InsertResult<V>) -> void effects [] {
|
||||
match move result {
|
||||
std.map.InsertResult::<V>::inserted => {}
|
||||
std.map.InsertResult::<V>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<V>::full(value) => { trap; }
|
||||
}
|
||||
}
|
||||
fn released<V>(map: std.map.U64Map<V>) -> void effects [] {
|
||||
match std.map.free::<V>(move map) {
|
||||
std.map.FreeResult::<V>::ok => {}
|
||||
std.map.FreeResult::<V>::not_empty(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
fn extracted<V>(value: std.option.Option<V>) -> V effects [] {
|
||||
match move value {
|
||||
std.option.Option::<V>::some(item) => { return move item; }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
let map = opened::<own<u64>>(0, heap);
|
||||
{ mut q = map;
|
||||
match std.map.reserve::<own<u64>>(q, 0, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } }
|
||||
match std.map.pop::<own<u64>>(q) { std.option.Option::<std.map.Entry<own<u64>>>::none => {}, std.option.Option::<std.map.Entry<own<u64>>>::some(entry) => { trap; } }
|
||||
match std.map.remove::<own<u64>>(q, 0) { std.option.Option::<own<u64>>::none => {}, std.option.Option::<own<u64>>::some(value) => { trap; } }
|
||||
let value = own.new(42u64, heap) or trap;
|
||||
match std.map.insert::<own<u64>>(q, 0, move value) {
|
||||
std.map.InsertResult::<own<u64>>::full(value) => { assert(own.take(move value) == 42u64); }
|
||||
std.map.InsertResult::<own<u64>>::inserted => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::replaced(old) => { trap; }
|
||||
}
|
||||
}
|
||||
{ ref q = map; assert(not std.map.contains::<own<u64>>(ref q, 0)); }
|
||||
released::<own<u64>>(move map); return 42;
|
||||
}
|
||||
Reference in new issue
Block a user