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
@@ -28,6 +28,9 @@ jobs:
|
||||
- run: python3 tools/deque_vectors.py
|
||||
- run: python3 tests/hosted/source_hash.py
|
||||
- run: python3 tools/hash_vectors.py
|
||||
- run: python3 tests/hosted/source_errors.py
|
||||
- run: python3 tests/hosted/source_map.py
|
||||
- run: python3 tools/map_vectors.py
|
||||
- run: zig-out/bin/aji run --grant out=io.write --grant heap=mem.alloc:64 docs/agent/syntax-example.air
|
||||
- run: zig build agent-reference
|
||||
- name: Source construct coverage (Phase 6A)
|
||||
|
||||
@@ -23,6 +23,8 @@ python3 tests/hosted/source_buffers.py # initialized storage, owning vectors and
|
||||
python3 tests/hosted/source_deque.py # ring order, returned owners and CLI contracts
|
||||
python3 tests/hosted/source_hash.py # pure hashes, chunks and source/package/hosted contracts
|
||||
python3 tests/hosted/source_errors.py # pure built-in error construction and authority separation
|
||||
python3 tests/hosted/source_map.py # exact numeric keys, owning values and profile/package parity
|
||||
python3 tools/map_vectors.py # independent dictionary oracle for public map traces
|
||||
(cd tools/eval && python3 -m unittest discover tests) # evaluation harness self-tests
|
||||
zig fmt --check build.zig src tools
|
||||
```
|
||||
|
||||
@@ -33,6 +33,7 @@ pub fn build(b: *std.Build) void {
|
||||
mod.addAnonymousImport("std_encoding_hex_aji", .{ .root_source_file = b.path("std/encoding/hex.aji") });
|
||||
mod.addAnonymousImport("std_fmt_aji", .{ .root_source_file = b.path("std/fmt.aji") });
|
||||
mod.addAnonymousImport("std_hash_aji", .{ .root_source_file = b.path("std/hash.aji") });
|
||||
mod.addAnonymousImport("std_map_aji", .{ .root_source_file = b.path("std/map.aji") });
|
||||
mod.addAnonymousImport("std_math_aji", .{ .root_source_file = b.path("std/math.aji") });
|
||||
mod.addAnonymousImport("std_option_aji", .{ .root_source_file = b.path("std/option.aji") });
|
||||
mod.addAnonymousImport("std_result_aji", .{ .root_source_file = b.path("std/result.aji") });
|
||||
|
||||
@@ -115,3 +115,5 @@ RFC 0025 safe owning Deque (cl100k, relative to buffer/Vec): Quick Reference 7,6
|
||||
RFC 0026 std.hash (cl100k, relative to Deque): Quick Reference 7,747 → 7,806 (+0.8%); other source docs 46,246 → 47,475; full source excluding AIR 53,993 → 55,281 (+2.4%). library/std.md is 12,190 tokens; AIR remains 175,736 bytes. Four pure functions expose exact FNV/CRC continuation with no semantic, verifier or authority growth. Cumulative full-source growth is +62.7%, justified in the RFC for owner review without an empirical MCC claim. The proposed map contract stays outside the bundles.
|
||||
|
||||
RFC 0027 explicit error values (cl100k, relative to hashes): Quick Reference 7,806 → 7,863; other source docs 47,475 → 48,061; full source excluding AIR 55,281 → 55,924 (+1.2%). AIR is 179,282 bytes / 51 sections, and its source-bundle copy is 46,300 tokens. The measurement excludes the developing map contract. Existing variant syntax gains pure built-in error values; no authority, resource or ownership state is added. Cumulative source growth is +64.6%; the RFC records the complexity justification, without claiming MCC improvement.
|
||||
|
||||
RFC 0028 numeric-key owning map (cl100k, relative to error_values; includes the separate integer-pattern clarification): Quick Reference stays 7,863, other source docs 48,061 → 50,079, full source excluding AIR 55,924 → 57,942 (+3.6%). The on-demand library page is 14,167 tokens. AIR remains 179,282 bytes / 51 sections. No map-specific instruction, source form, verifier state or diagnostic is added; general keys remain Q-037. Cumulative source growth is +70.5%, with review justification in the RFC and no claimed MCC benefit.
|
||||
@@ -1,16 +1,16 @@
|
||||
# Owning hash map contract proposal
|
||||
# Owning hash map design
|
||||
|
||||
Status: proposed STD-6d design; no map module is implemented or registered yet. Spec 16 defines the available std.hash API only. This document fixes the next implementation scope and review cases; it does not override the specification.
|
||||
Status: STD-6d.2 numeric-key branch implementation (RFC 0028 Proposed); general keys remain Q-037. Spec 16 §2.13 is normative for std.map. This document records design rationale and does not override the specification.
|
||||
|
||||
## Key policy and scope
|
||||
|
||||
The eventual collection gate still requires HashMap<Key, Own<Value>>. Current type parameters are types, not hashing/equality operations (spec 15 §15); Copy supplies neither. Source has no callbacks, methods, user traits or value generic parameters. Treating a digest as key identity is incorrect because different keys can collide. Adding a language feature solely to make this API look generic would add more agent concepts before establishing their general value.
|
||||
|
||||
Start with `std.map.U64Map<V>`: exact u64 keys, generic Copy or linear values, existing source primitives only. Users with genuine numeric identifiers can use it directly. Bytes/struct keys cannot be converted to digests and then treated as unique numeric keys; general key hashing/equality is Q-037. Byte-key ownership needs a separate owning representation contract. Do not name this specialization HashMap<K,V> or claim that it satisfies the general-key gate.
|
||||
Start with `std.map.U64Map<V>`: exact u64 keys, generic Copy or linear values, initialized buffer primitives and explicit error construction (RFC 0027). Users with genuine numeric identifiers can use it directly. Bytes/struct keys cannot be converted to digests and then treated as unique numeric keys; general key hashing/equality is Q-037. Byte-key ownership needs a separate owning representation contract. Do not name this specialization HashMap<K,V> or claim that it satisfies the general-key gate.
|
||||
|
||||
## Proposed public API
|
||||
## Public API
|
||||
|
||||
Ten generic functions, each explicitly specialized `::<V>`; only new/reserve declare effects [mem.alloc] and take cap<mem.alloc>. All other functions declare effects []. Names/types below are proposed, unavailable calls today.
|
||||
Ten generic functions, each explicitly specialized `::<V>`; only new/reserve declare effects [mem.alloc] and take cap<mem.alloc>. All other functions declare effects []. The numeric-key names/types below are implemented on the branch; spec 16 §2.13 is authoritative.
|
||||
|
||||
| Function | Result/ownership |
|
||||
|---|---|
|
||||
@@ -41,12 +41,12 @@ Expected probing depends on collisions/history; worst-case lookup/insert/remove
|
||||
|
||||
## Ownership and implementation gate
|
||||
|
||||
Preserved invariant: every live entry holds one complete V, occupied count equals length, keys are unique, and each occupied slot is reachable by its probe sequence. Occupied state corresponds exactly to some(V); vacant/deleted states correspond to none and own no V. Unused keys remain initialized Copy values, never identity sentinels. Existing aggregate/enum availability, exchange, slice bounds, mutable exclusion and task-loan rules verify every operation. Runtime uses ordinary deterministic AIR, initialized buffer accounting and no new instruction. No new diagnostic is expected: bad moves/leaks use E7003/E2002/E3002, alias/task conflicts E2101/E4101, Copy/Send/Share restrictions E7005/E4002. User owners, files and endpoints remain subject to ordinary resource/task rules; no destructor closes them. Existing AIR/APIs retain meaning; map support would be an additive registry entry, with its spec/reference delivered alongside code.
|
||||
Preserved invariant: every live entry holds one complete V, occupied count equals length, keys are unique, and each occupied slot is reachable by its probe sequence. Occupied state corresponds exactly to some(V); vacant/deleted states correspond to none and own no V. Unused keys remain initialized Copy values, never identity sentinels. Existing aggregate/enum availability, exchange, slice bounds, mutable exclusion and task-loan rules verify every operation. Runtime uses ordinary deterministic AIR, initialized buffer accounting and no new instruction. No new diagnostic is expected: bad moves/leaks use E7003/E2002/E3002, alias/task conflicts E2101/E4101, Copy/Send/Share restrictions E7005/E4002. User owners, files and endpoints remain subject to ordinary resource/task rules; no destructor closes them. Existing AIR/APIs retain meaning; map support is an additive registry entry, with its spec/reference delivered alongside code.
|
||||
|
||||
The checked [slot prerequisite](../../tests/conformance/source/hash/map_storage.aji) already demonstrates read-only key/state access without consuming an owning payload, complete extraction and explicit cleanup; it does not implement a map. A valid owning use creates U64Map<own<u64>>, inserts a moved owner under key 7, handles replaced/full payloads, removes or pops and explicitly consumes the returned owner, then handles empty free. Rejected uses omit the move, ignore a linear replaced/full/pop result, copy an owner through get, free without consuming not_empty, mutate while a slice/task loan exists or share a file-valued map with workers. These become executable conformance examples with the implementation; this proposal is not evidence that they run today.
|
||||
The checked [slot prerequisite](../../tests/conformance/source/hash/map_storage.aji) already demonstrates read-only key/state access without consuming an owning payload, complete extraction and explicit cleanup; it does not implement a map. A valid owning use creates U64Map<own<u64>>, inserts a moved owner under key 7, handles replaced/full payloads, removes or pops and explicitly consumes the returned owner, then handles empty free. Rejected uses omit the move, ignore a linear replaced/full/pop result, copy an owner through get, free without consuming not_empty, mutate while a slice/task loan exists or share a file-valued map with workers. Executable valid/rejected examples are in tests/conformance/source/map; RFC 0028 records validation.
|
||||
|
||||
Before marking the specialization done, test exact collisions, tombstones before matching keys, wraparound, a table with no empty slots, full-table replacement, zero capacity and all scalar keys. Compare mixed operations and all associations with an independent Python dict oracle. Include Copy/owner/file/sender cleanup, repeated reuse, peak-charge failure, exact failure-state preservation, cross-authority refunds and invalid-representation safety. Verify canonical AIR/package/hosted behavior, GC after each instruction and schedules for valid workers. Integrate normative rules in spec 16 and the API reference, register the module, measure bundle costs and report the remaining general-key gate explicitly.
|
||||
|
||||
## Agent complexity impact
|
||||
|
||||
This proposal adds no language concept, verifier state, syntax, diagnostic, callback, trait or runtime feature. The future library adds key equality, probing and returned replacement ownership; the latter reuses existing complete-value patterns. Ten operations avoid independent entry/cursor/borrow lifetimes. Public representation invariants increase documentation needs, so full details belong on demand. This draft stays outside the source/AIR bundles; the runnable hash increment measures its own cost in RFC 0026. No performance or Model Capability Compression result is inferred from the proposal or from benchmark tasks.
|
||||
The numeric-key library adds no map-specific language concept, verifier state, syntax, diagnostic, callback, trait or runtime feature. Its separately implemented error construction prerequisite is RFC 0027. Key equality, probing and returned replacement ownership reuse existing complete-value patterns. Ten operations avoid independent entry/cursor/borrow lifetimes. Public representation invariants increase documentation needs, so full details belong on demand. This design stays outside the source/AIR bundles; RFC 0028 measures the normative API cost. No performance or Model Capability Compression result is inferred from fixtures or benchmark tasks.
|
||||
@@ -141,4 +141,4 @@ Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) a
|
||||
| P6-9 | todo | Port reference programs and examples to `.aji` | P6-5 | `tests/programs/`, `examples/` | exit criterion passes |
|
||||
| P6-10 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||||
|
||||
The [standard-library track](standard-library.md) implements eleven compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints on the branch. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer<T> and safe std.vec, explicit growth, returned failure ownership and draining (spec 15 §17). STD-6c/RFC 0025 adds safe owning Deque with existing source primitives. STD-6d.1/RFC 0026 adds pure std.hash; the next map contract is proposed with general key policy Q-037. Remaining maps/sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
|
||||
The [standard-library track](standard-library.md) implements twelve compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints on the branch. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer<T> and safe std.vec, explicit growth, returned failure ownership and draining (spec 15 §17). STD-6c/RFC 0025 adds safe owning Deque with existing source primitives. STD-6d.1/RFC 0026 adds pure std.hash; STD-6d.2/RFC 0028 adds safe owning U64Map<V> after the explicit error_values prerequisite (RFC 0027). General key policy remains Q-037. Remaining maps/sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
|
||||
@@ -57,10 +57,10 @@ SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protob
|
||||
| STD-6a | done (branch implementation; RFC 0024 Proposed) | dynamic initialized buffer<T> storage/drain contract (Q-036) | STD-4/5 | vertical allocate/grow/push/pop/view/free; allocation failures preserve state, returned owners consumed; no hidden destruction |
|
||||
| STD-6b | done (branch implementation; RFC 0024 Proposed) | safe std.vec for Copy/owners/files/channel endpoints | STD-6a | explicit reserve, bounded push, moving pop/replace, empty-only free; deterministic and failure/cleanup tests |
|
||||
| STD-6c | done (branch implementation; RFC 0025 Proposed) | safe std.deque for Copy/owners/files/endpoints | STD-6a/b | bounded ring, both ends, failure-preserving explicit growth, complete resource transfer and empty-only free |
|
||||
| STD-6d | todo (hash foundation done; maps proposed) | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap<Key, Own<Value>>, recoverable failures and explicit draining |
|
||||
| STD-6d | todo (hash and numeric-key map done; general keys, sets and heaps remain) | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap<Key, Own<Value>>, recoverable failures and explicit draining |
|
||||
| STD-6d.1 | done (branch implementation; RFC 0026 Proposed) | pure std.hash: FNV-1a 64 / CRC32C, fresh/extend | STD-1b | four safe functions, exact byte/chunk conventions, independent public vectors and CLI/profile checks |
|
||||
| STD-6d.2a | done (branch implementation; RFC 0027 Proposed) | pure built-in error construction prerequisite | STD-6d.1 | vertical error_values feature, no authority/effect/resource changes; preflight allocation validation |
|
||||
| STD-6d.2 | proposed; not implemented | U64Map<V> first; general HashMap<K,V> key policy Q-037 | STD-6d.1 | [reviewable contract](../design/hash-map.md), then executable safe map with ownership/failure/collision tests; general-key gate remains open |
|
||||
| STD-6d.2 | done (numeric-key branch implementation; RFC 0028 Proposed) | U64Map<V> first; general HashMap<K,V> key policy Q-037 | STD-6d.1 | safe map with ownership/failure/collision tests and error_values prerequisite (RFC 0027); general-key gate remains open |
|
||||
| STD-7 | todo | concrete I/O adapters, buffered I/O and lexical paths | STD-1b/2a/2b; STD-3 for public types | short reads, EOF, capacity and write failures covered; paths never grant filesystem authority |
|
||||
| STD-8 | todo | filesystem gaps, args/env capability RFC, time/random distinctions and structured log | STD-3/7; vertical runtime feature where needed | CLI/storage milestone examples work in deterministic and hosted profiles; all authority is granted at entry |
|
||||
| STD-9 | todo | independent integration application and API review | STD-6/7/8 | integration gate; public application is not private benchmark material |
|
||||
@@ -136,4 +136,4 @@ RFC 0024 records storage/Vec validation. RFC 0025 records the deque API/budget m
|
||||
|
||||
## Hash foundation and next map contract
|
||||
|
||||
STD-6d.1/RFC 0026 adds safe std.hash with four byte-only fresh/continuation operations, no new semantics or heap authority. FNV/CRC constants and public vectors are independently verified; hashes never replace key equality. [The map contract proposal](../design/hash-map.md) specifies numeric-key U64Map<V>, bounded insert, returned replacement/full ownership, tombstone lookup, moving removal/drain and explicit peak-charged rehash. No map module is implemented; Q-037 keeps general key policy explicit, and HashMap<Key, Own<Value>>/HashSet/BinaryHeap remain required by STD-6d.
|
||||
STD-6d.1/RFC 0026 adds safe std.hash with four byte-only fresh/continuation operations, no new semantics or heap authority. FNV/CRC constants and public vectors are independently verified; hashes never replace key equality. [The map design](../design/hash-map.md) specifies numeric-key U64Map<V>, bounded insert, returned replacement/full ownership, tombstone lookup, moving removal/drain and explicit peak-charged rehash. STD-6d.2/RFC 0028 implements safe std.map.U64Map<V> with ten operations, using explicit error construction (RFC 0027) for preflight validation. Independent dictionary traces, collision/tombstone/wrap cases, exact peak/refund accounting, owning/files/sender/task tests and rejected leaks/aliases/Copy uses cover the contract. Q-037 keeps general key policy explicit; HashMap<Key, Own<Value>>/HashSet/BinaryHeap remain required by STD-6d.
|
||||
+25
-2
@@ -1,8 +1,8 @@
|
||||
# Standard library API
|
||||
|
||||
Normative contracts: spec 16. Import rules: spec 15 §13. These modules are bundled with the compiler, with no external source dependencies. Allocation authority is explicit for std.vec/std.deque new/reserve.
|
||||
Normative contracts: spec 16. Import rules: spec 15 §13. These modules are bundled with the compiler, with no external source dependencies. Allocation authority is explicit for std.vec/std.deque/std.map new/reserve.
|
||||
|
||||
Except std.vec/std.deque new/reserve, functions below declare `effects []`, allocate no heap memory and retain no borrows. Pass arrays/slices using explicit `ref` or `mut`. Names are fully qualified; no alias or short-name import exists.
|
||||
Except std.vec/std.deque/std.map new/reserve, functions below declare `effects []`, allocate no heap memory and retain no borrows. Pass arrays/slices using explicit `ref` or `mut`. Names are fully qualified; no alias or short-name import exists.
|
||||
|
||||
| Module | Function signature | Result/failure |
|
||||
|---|---|---|
|
||||
@@ -278,3 +278,26 @@ Import std.deque; every operation supplies `::<T>`. Deque<T> is always linear an
|
||||
Indices count from the front. Full pushes, out-of-bounds replaces and nonempty free preserve the queue and return ownership. Allocation failure also preserves physical slots/head/length. Successful growth preserves logical order, resets head and charges the old+new capacities at the peak; no shrink occurs. Every slot is an Option<T> (tag plus payload), including free slots: capacity 3 of own<u64> charges 27 bytes. Empty free explicitly drains internal none slots; it never destroys a user's T. Callers pop and consume resources before freeing; match move on linear result values and import std.option to name pop/get variants.
|
||||
|
||||
End operations and indexing use constant slot work; construction/growth/free use O(capacity) work. Interpreter representation costs remain those of buffer primitives. Deque<T> fields are ordinarily visible; direct representation writes/construction must preserve spec 16 §2.11's ring invariant. Library calls maintain it. [Executable owning deque](../../examples/std/deque.aji) returns 42 with heap=mem.alloc:1024. There is no iterator, returned borrow, trait hierarchy or implicit allocation/cleanup. Existing alias, task-loan and Copy/Send/Share checks apply.
|
||||
|
||||
## Owning numeric-key maps
|
||||
|
||||
Import `std.map`; each generic operation supplies `::<V>`. `U64Map<V>` is always linear, uses exact u64 key equality and supports Copy values, owners, files and sender endpoints. Hashes select probe positions; they never establish key equality. General `HashMap<K,V>` remains Q-037.
|
||||
|
||||
| Operation | Return / ownership |
|
||||
|---|---|
|
||||
| `new<V>(capacity: usize, heap: cap<mem.alloc>)` | `NewResult<V>::ok(U64Map<V>)` / `err(alloc_error)` |
|
||||
| `len<V>(map: ref<U64Map<V>>) -> usize` | entry count |
|
||||
| `capacity<V>(map: ref<U64Map<V>>) -> usize` | maximum live entries before a new key returns full |
|
||||
| `reserve<V>(map: mut<U64Map<V>>, capacity: usize, heap: cap<mem.alloc>)` | `ReserveResult::ok` / `err(alloc_error)`; grow explicitly, preserve every slot on returned failure |
|
||||
| `insert<V>(map: mut<U64Map<V>>, key: u64, value: V)` | `InsertResult<V>::inserted` / `replaced(V)` / `full(V)` |
|
||||
| `contains<V>(map: ref<U64Map<V>>, key: u64) -> bool` | presence without copying V |
|
||||
| `get<V: Copy>(map: ref<U64Map<V>>, key: u64)` | `std.option.Option<V>` copied lookup |
|
||||
| `remove<V>(map: mut<U64Map<V>>, key: u64)` | `std.option.Option<V>` moved removal |
|
||||
| `pop<V>(map: mut<U64Map<V>>)` | `std.option.Option<Entry<V>>`; Entry has key: u64, value: V |
|
||||
| `free<V>(map: U64Map<V>)` | `FreeResult<V>::ok` / `not_empty(U64Map<V>)` |
|
||||
|
||||
Only new/reserve declare `effects [mem.alloc]` and take allocation authority. No operation implicitly grows. Full insertion returns the exact input; replacement works even when full and returns the old value. Callers must explicitly consume owning results and drain before free. Use `ref map` for reads and `mut map` for mutation, including explicit shared reborrows from mut parameters.
|
||||
|
||||
Representation: `U64Map<V> { storage: buffer<Slot<V>>, length: usize }`, `Slot<V> { key: u64, state: SlotState, value: std.option.Option<V> }`, `SlotState { empty, deleted, occupied }`. Occupied implies some(V), vacancies imply none, keys are unique and reachable, and length equals occupied count. Direct representation writes must preserve spec 16 §2.13's invariant. Capacity N allocates and initializes 2N physical slots, with both enum tags charged. N=0 allocates no bytes. Both whole tables and user allocations count toward growth's peak quota; old storage is refunded to its original authority. Overflowing size returns budget_exceeded.
|
||||
|
||||
Lookup traverses deleted slots, compares original keys and terminates after bounded probes, even with no empty slots. Pop drains physical-index order; successful rehash may change this deterministic order. Worst-case probe work is O(N); collision-heavy growth is O(N²). Existing borrow, task-loan, Copy/Send/Share and resource diagnostics apply. The [owning example](../../examples/std/map.aji) returns 42 with heap=mem.alloc:256.
|
||||
@@ -0,0 +1,72 @@
|
||||
# RFC 0028: Safe owning numeric-key map
|
||||
|
||||
Status: Proposed
|
||||
Scope: STD-6d.2, safe standard source; general-key gate remains Q-037
|
||||
Language version: 0.1
|
||||
|
||||
## Motivation
|
||||
|
||||
Numeric identifiers need bounded lookup and storage without rebuilding ownership, quota and collision handling. std.hash supplies pure hashing; initialized buffers and whole-value exchange supply safe storage. Pure error construction (RFC 0027) permits size validation before allocation. No map-specific language feature or trusted runtime is needed.
|
||||
|
||||
## Precise invariant
|
||||
|
||||
U64Map<V> has 2N initialized slots for logical capacity N. Copy key/state fields permit observation with owning V. Each occupied slot holds exactly one some(V); vacancies hold none. Keys are unique and reachable through the probe chain, occupied count equals length≤N. Linear owners/resources are always transferred or explicitly consumed. Both state and option tags are charged; the owning-handle slot is 18 bytes under air64.
|
||||
|
||||
## Normative rule changes
|
||||
|
||||
Spec 16 §2.13 registers std.map and its ten functions. It defines exact u64 equality, FNV-1a over eight little-endian key bytes, bounded linear probing, tombstones, ownership of inserted/replaced/full/removed/popped/not_empty results, complete failure preservation and explicit growth/cleanup. Reference/std.md publishes the API. General keys remain Q-037; this specialization does not satisfy HashMap<Key, Own<Value>>.
|
||||
|
||||
## Verifier implications
|
||||
|
||||
No new verifier state or privileges. Ordinary generic constraints, field borrows, whole Option/Slot exchange, move/unpack, task loans and Copy/Send/Share apply. Only get requires V: Copy; contains needs no value copy. Library functions maintain the invariant; direct representation mutation is governed by spec 16. Existing diagnostic codes cover leaks, invalid copies/moves/aliases, task loans and missing effects.
|
||||
|
||||
## Interpreter / runtime implications
|
||||
|
||||
Existing buffer/allocation semantics and deterministic fuel apply. New/reserve explicitly require mem.alloc authority/effect; insert never grows. Growth allocates and initializes the whole new table before mutation. Returned failure preserves all old slots, metadata, key/value contents and pop order. Peak quota includes both tables and user-owned allocations. Refund uses the original table's authority, even when another funds growth. Successful transfer uses old physical-index order and clears tombstones. Pop uses first occupied physical slot. No hidden resource close or destructor exists; corrupted empty metadata cannot cause normal destruction of an owner.
|
||||
|
||||
## AIR changes
|
||||
|
||||
None. Lowered safe library source uses existing instructions, including error.const from the separately registered error_values prerequisite. Source integer-pattern canonicalization was repaired separately; no existing instruction semantics change.
|
||||
|
||||
## Valid example
|
||||
|
||||
`examples/std/map.aji` creates a map of own<u64>, inserts a moved owner under key 7, removes and consumes it, and frees the drained map, returning 42. Tests also transfer files, sender endpoints and exclusive task loans.
|
||||
|
||||
## Rejected example
|
||||
|
||||
`tests/conformance/source/map/get_owner.aji` attempts copying lookup for own<u64> (E7005). Other tests reject missing moves, discarded replaced/full/pop/not_empty owners, mutation during borrows/task loans, shared file-valued maps and growth without its allocation effect.
|
||||
|
||||
## Diagnostics impact
|
||||
|
||||
No new codes. E7003/E7005, E2002/E3002, E2101, E4101, E4002 and E3101 retain their existing meaning. Broken caller representation may trap; valid library operations do not trap except execution limits. Recoverable failures are explicit returned data.
|
||||
|
||||
## Compatibility and migration
|
||||
|
||||
New compiler-pinned source module only, no map-specific AIR feature. Existing std and AIR API meanings remain unchanged. Maps do not implicitly allocate, compact, iterate or expose escaping borrows. General HashMap/HashSet, BinaryHeap and the remaining Std 0.1 gates remain open.
|
||||
|
||||
## Agent complexity impact
|
||||
|
||||
Library concepts: bounded exact-key map and returned-value ownership, reusing Vec/Deque result names and cleanup. Ten canonical operations, no aliases, overloads, traits, reflection, callbacks or new source syntax. The slot's metadata stays Copy while values may be linear; there is no new verifier state or repair diagnostic. Existing primitives suffice after the separately measured error_values prerequisite. Full contracts remain in the on-demand library page; no long Quick Reference tutorial is added. Measurements and final checks follow below; no MCC improvement is inferred from fixtures or documentation size.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
A linear entry enum prevents read-only metadata observation with owning V. Digest equality would conflate colliding original keys. Automatic growth hides allocation/authority. Compacting on deletion changes pop order and increases mutation. Generic key hashing/equality needs a separate source contract, rather than map-specific compiler magic.
|
||||
|
||||
## Unresolved questions
|
||||
|
||||
Q-037: general key hashing and equality. Numeric U64Map is explicitly a specialization.
|
||||
|
||||
## Validation and measured documentation budget
|
||||
|
||||
`zig build`, `zig build test`, formatting and source coverage pass (98/98). All 30 map conformance cases pass with collection before every instruction; concurrent fixtures additionally use 12 schedule seeds under quanta 1, 2, 7 and their declared quantum. The independent Python dictionary oracle verifies 128 mixed operations across Copy and owning traces without modelling the hash/probe implementation. Source/package/hosted CLI checks pass (76), including exact source/AIR records, canonical lowering, import order and absence of trusted operations. Full conformance passes: 863 cases, 0 failed, 0 pending.
|
||||
|
||||
Relative to the error_values prerequisite (the source-doc difference also includes the separate integer-pattern clarification):
|
||||
|
||||
| Group | cl100k | o200k | Qwen2.5 |
|
||||
|---|---|---|---|
|
||||
| Quick Reference | 7,863 → 7,863 | 7,894 → 7,894 | 8,102 → 8,102 |
|
||||
| Other source docs | 48,061 → 50,079 | 48,204 → 50,223 | 49,419 → 51,509 |
|
||||
| Full source excluding AIR | 55,924 → 57,942 | 56,098 → 58,117 | 57,521 → 59,611 |
|
||||
| Library page | 12,190 → 14,167 | 12,239 → 14,216 | 12,559 → 14,604 |
|
||||
|
||||
AIR remains 179,282 bytes / 19 files / 51 sections (source-bundle copy 46,300 / 46,451 / 47,800 tokens). Full source grows 3.6% incrementally and 70.5% cumulatively from the pre-stdlib cl100k baseline 33,981. The cumulative cost is above the existing review line: explicit ownership, failure preservation and peak accounting require a reviewable contract. No Quick Reference catalog, new source form or map-specific language semantics is added; the API remains on demand. This cost is documented for owner review and is not evidence of MCC improvement.
|
||||
@@ -10,7 +10,7 @@ APIs SHOULD offer one canonical operation for a common need, small documentation
|
||||
|
||||
## 2. Bootstrap module registry
|
||||
|
||||
The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.hash`, `std.math`, `std.option`, `std.result`, `std.utf8`, `std.vec` and `std.deque`. They are implemented in safe `.aji`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/hash.aji`, `std/math.aji`, `std/option.aji`, `std/result.aji`, `std/utf8.aji`, `std/vec.aji` and `std/deque.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile and have no concurrency effects. Modules other than std.vec/std.deque declare effects [] and allocate no heap memory. std.vec/std.deque new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11); their other functions allocate no heap. Ordinary interpreter fuel limits apply.
|
||||
The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.hash`, `std.map`, `std.math`, `std.option`, `std.result`, `std.utf8`, `std.vec` and `std.deque`. They are implemented in safe `.aji`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/hash.aji`, `std/map.aji`, `std/math.aji`, `std/option.aji`, `std/result.aji`, `std/utf8.aji`, `std/vec.aji` and `std/deque.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile and have no concurrency effects. Modules other than std.vec/std.deque/std.map declare effects [] and allocate no heap memory. std.vec/std.deque/std.map new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11, §2.13); their other functions allocate no heap. Ordinary interpreter fuel limits apply.
|
||||
|
||||
### 2.1 `std.math`
|
||||
|
||||
@@ -201,3 +201,30 @@ FNV MUST process each byte in slice order by XOR with its zero-extended value, t
|
||||
Empty input returns the supplied state/checksum; a fresh empty hash is the FNV offset basis or zero CRC. For any bytes A/B, extending hash(A) with B MUST equal hashing their concatenation. Any u64/u32 continuation value is valid; it need not come from a previous call. Input bytes including zero MUST all participate. No UTF-8 validation, terminator, implicit padding or field separator is introduced. The caller MUST encode field boundaries and scalar byte order when hashing structured data.
|
||||
|
||||
These operations MUST NOT allocate heap memory, mutate input, retain a borrow, obtain authority or consume an owner. They use ordinary slice bounds, immutable borrows and explicit wrapping arithmetic; no new verifier/runtime rule, diagnostic, AIR feature or unsafe boundary is introduced. Conflicting mutable access rejects under existing E2101; argument type errors use E7005 and missing imports/members E7002. Valid calls do not trap except ordinary execution limits. Time is O(data.len), auxiliary state O(1); the initial CRC implementation MAY use eight bit steps per byte rather than a lookup table. Deterministic and hosted profiles MUST return the same values, and existing APIs/AIR retain meaning. Hashes/checksums provide neither cryptographic authentication nor adversarial collision resistance and MUST NOT be used as key equality in a map.
|
||||
|
||||
### 2.13 `std.map`: bounded owning numeric-key map
|
||||
|
||||
The registry MUST include std.map, ordinary safe source. U64Map<V> stores exact u64 keys and complete V values; V MAY be Copy, an owner, file or endpoint subject to existing member/Send/Share rules. It does not implement general HashMap<K,V> hashing/equality (Q-037). Entry<V> has key: u64 and value: V. Ten operations use explicit `::<V>` specialization:
|
||||
|
||||
| Function | Result |
|
||||
|---|---|
|
||||
| `new<V>(capacity: usize, heap: cap<mem.alloc>)` | NewResult<V>: ok(U64Map<V>), err(alloc_error) |
|
||||
| `len<V>(map: ref<U64Map<V>>) -> usize` | live entries |
|
||||
| `capacity<V>(map: ref<U64Map<V>>) -> usize` | maximum live entries |
|
||||
| `reserve<V>(map: mut<U64Map<V>>, capacity: usize, heap: cap<mem.alloc>)` | ReserveResult: ok, err(alloc_error) |
|
||||
| `insert<V>(map: mut<U64Map<V>>, key: u64, value: V)` | InsertResult<V>: inserted, replaced(V), full(V) |
|
||||
| `contains<V>(map: ref<U64Map<V>>, key: u64) -> bool` | exact presence |
|
||||
| `get<V: Copy>(map: ref<U64Map<V>>, key: u64) -> std.option.Option<V>` | copy of value, or none |
|
||||
| `remove<V>(map: mut<U64Map<V>>, key: u64) -> std.option.Option<V>` | moving extraction, or none |
|
||||
| `pop<V>(map: mut<U64Map<V>>) -> std.option.Option<Entry<V>>` | first occupied physical slot, or none |
|
||||
| `free<V>(map: U64Map<V>)` | FreeResult<V>: ok, not_empty(U64Map<V>) |
|
||||
|
||||
Representation: U64Map<V> has storage: buffer<Slot<V>> and length: usize. Slot<V> has key: u64, state: SlotState and value: std.option.Option<V>; SlotState is the Copy enum empty/deleted/occupied. A logical capacity N uses exactly 2N initialized physical slots. buffer.len(storage) equals buffer.capacity(storage); length≤N equals occupied count; occupied slots contain some(V), other slots none; occupied keys are unique and reachable by the probing rule. Copy key/state fields are observable through ref without copying V. Ordinary visible fields have no special access protection; manual construction/mutation MUST preserve this invariant. Invalid representations retain ordinary ownership/bounds safety but need not preserve map behavior.
|
||||
|
||||
New creates all-empty slots. Only new/reserve declare effects [mem.alloc] and require cap<mem.alloc>; every other operation is effects [] and allocates no heap. Multiplication/charge overflow MUST return alloc_error.budget_exceeded before mutation. Each slot charges the key, SlotState tag and Option<V> tag plus maximum payload, including vacancies/tombstones; separately allocated V owners retain their own charges. Zero capacity succeeds with zero slots, no modulo; new-key insertion returns full(value). A key's hash is FNV-1a of exactly eight little-endian key bytes; the starting slot is that u64 hash modulo physical count. Probing visits at most the physical count and wraps without overflowing. Lookup passes deleted and stops at empty/end. Hash equality MUST NOT substitute for exact u64 equality; 0 and maximum u64 are valid keys.
|
||||
|
||||
Insert searches for an existing key before choosing its first deleted/empty slot. Existing-key replacement MUST succeed even at full logical capacity, returning the old complete V. A new key when full MUST return the exact input V without mutation. Deletion/pop exchange a complete Option<V> for none, mark deleted and return ownership; missing removal preserves all state. Tombstones need no implicit compaction. Tables with no empty slots MUST still terminate probes and reuse deleted slots without duplicate keys. pop order is physical-index order, deterministic for the complete history; successful rehash MAY change that order. No borrowed value or cursor escapes.
|
||||
|
||||
Reserve≤N is an unchanged no-op, retaining its explicit effect/capability/mut contract. Growth MUST allocate/initialize the entire new table before changing the original. Returned failure MUST preserve every old slot, metadata, key/value association and pop order. Peak quota includes both whole tables and existing user-owned allocations; old storage is refunded to its recorded authority even if a different capability funds growth. After successful allocation, transfer complete entries in old physical-index order, clear tombstones and explicitly free old internal vacant storage. No subsequent recoverable error is permitted; fuel/traps are abnormal outcomes outside returned-error preservation. Nonempty free MUST return the entire map; empty free MUST consume all internal none values and free the storage, never normally discarding an occupied/owning payload, including with corrupted caller metadata. Callers MUST consume returned linear replacements/full/remove/pop/not_empty results; no hidden destructor closes user resources.
|
||||
|
||||
Existing aggregate/enum moves, value.swap, slice bounds, borrow/task-loan exclusion, Copy/Send/Share, effects and allocation accounting verify this library without map-specific rules, diagnostics, AIR instructions/features or runtime behavior. Preflight size failures construct alloc_error values through error_values (spec 05 §14); map adds no further semantic feature. Bad moves/leaks/aliases/tasks/Copy uses retain E7003/E2002/E3002/E2101/E4101/E7005 and Share restrictions E4002. Valid operations do not trap except execution limits. Deterministic/hosted profiles agree; existing source/AIR/API meanings remain unchanged. Lookup/insert/remove are O(N) worst-case slot work, pop/free O(N), growth O(N²) worst-case collision work. Initialized-prefix copying may increase interpreter host cost; no native throughput guarantee or adversarial collision bound is added.
|
||||
@@ -0,0 +1,30 @@
|
||||
module example.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
match std.map.new::<own<u64>>(1, heap) {
|
||||
std.map.NewResult::<own<u64>>::err(error) => { trap; }
|
||||
std.map.NewResult::<own<u64>>::ok(map) => {
|
||||
let owner = own.new(42u64, heap) or trap;
|
||||
{ mut q = map;
|
||||
match std.map.insert::<own<u64>>(q, 7, move owner) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
var answer: u64 = 0;
|
||||
{ mut q = map;
|
||||
match std.map.remove::<own<u64>>(q, 7) {
|
||||
std.option.Option::<own<u64>>::none => { trap; }
|
||||
std.option.Option::<own<u64>>::some(value) => { answer = own.take(move value); }
|
||||
}
|
||||
}
|
||||
match std.map.free::<own<u64>>(move map) {
|
||||
std.map.FreeResult::<own<u64>>::ok => {}
|
||||
std.map.FreeResult::<own<u64>>::not_empty(returned) => { trap; }
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ pub const registry = [_]Source{
|
||||
.{ .name = "std.encoding.hex", .file = "std/encoding/hex.aji", .source = @embedFile("std_encoding_hex_aji") },
|
||||
.{ .name = "std.fmt", .file = "std/fmt.aji", .source = @embedFile("std_fmt_aji") },
|
||||
.{ .name = "std.hash", .file = "std/hash.aji", .source = @embedFile("std_hash_aji") },
|
||||
.{ .name = "std.map", .file = "std/map.aji", .source = @embedFile("std_map_aji") },
|
||||
.{ .name = "std.math", .file = "std/math.aji", .source = @embedFile("std_math_aji") },
|
||||
.{ .name = "std.option", .file = "std/option.aji", .source = @embedFile("std_option_aji") },
|
||||
.{ .name = "std.result", .file = "std/result.aji", .source = @embedFile("std_result_aji") },
|
||||
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
module std.map
|
||||
import std.hash;
|
||||
import std.option;
|
||||
|
||||
struct Slot<V> { key: u64, state: SlotState, value: std.option.Option<V> }
|
||||
enum SlotState { empty, deleted, occupied }
|
||||
struct U64Map<V> { storage: buffer<Slot<V>>, length: usize }
|
||||
struct Entry<V> { key: u64, value: V }
|
||||
enum NewResult<V> { ok(U64Map<V>), err(alloc_error) }
|
||||
enum ReserveResult { ok, err(alloc_error) }
|
||||
enum InsertResult<V> { inserted, replaced(V), full(V) }
|
||||
enum FreeResult<V> { ok, not_empty(U64Map<V>) }
|
||||
|
||||
fn new<V>(capacity: usize, heap: cap<mem.alloc>) -> NewResult<V> effects [mem.alloc] {
|
||||
let maximum = 0usize -% 1usize;
|
||||
if capacity > maximum / 2usize { return NewResult::<V>::err(alloc_error::budget_exceeded); }
|
||||
let count = capacity * 2usize;
|
||||
match buffer.new<Slot<V>>(count, heap) {
|
||||
ok(storage) => {
|
||||
{ mut slots = storage;
|
||||
for index in 0usize..count {
|
||||
let empty = Slot::<V> { key: 0, state: SlotState::empty, value: std.option.Option::<V>::none };
|
||||
buffer.push(slots, move empty) or trap;
|
||||
}
|
||||
}
|
||||
return NewResult::<V>::ok(U64Map::<V> { storage: move storage, length: 0 });
|
||||
}
|
||||
err(error) => { return NewResult::<V>::err(error); }
|
||||
}
|
||||
}
|
||||
|
||||
fn len<V>(map: ref<U64Map<V>>) -> usize effects [] { return map.length; }
|
||||
fn capacity<V>(map: ref<U64Map<V>>) -> usize effects [] {
|
||||
ref storage = map.storage;
|
||||
return buffer.capacity(storage) / 2usize;
|
||||
}
|
||||
|
||||
fn insert<V>(map: mut<U64Map<V>>, key: u64, value: V) -> InsertResult<V> effects [] {
|
||||
mut storage = map.storage;
|
||||
let count = buffer.capacity(storage);
|
||||
if count == 0usize { return InsertResult::<V>::full(move value); }
|
||||
mut slots = buffer.view(storage);
|
||||
var wire: [u8; 8] = zero;
|
||||
for byte in 0usize..8usize { wire[byte] = (key >> ((byte as! u64) * 8u64)) as% u8; }
|
||||
let hash = std.hash.fnv1a64(ref wire);
|
||||
var position: usize = (hash % (count as! u64)) as! usize;
|
||||
var chosen: usize = count;
|
||||
for probe in 0usize..count {
|
||||
var found: bool = false;
|
||||
var stop: bool = false;
|
||||
{ ref slot = slots[position];
|
||||
match slot.state {
|
||||
SlotState::occupied => { found = slot.key == key; }
|
||||
SlotState::deleted => { if chosen == count { chosen = position; } }
|
||||
SlotState::empty => { if chosen == count { chosen = position; } stop = true; }
|
||||
}
|
||||
}
|
||||
if found {
|
||||
mut slot = slots[position];
|
||||
let replacement = std.option.Option::<V>::some(move value);
|
||||
let previous = value.swap(mut slot.value, move replacement);
|
||||
match move previous {
|
||||
std.option.Option::<V>::some(old) => { return InsertResult::<V>::replaced(move old); }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
if stop { break; }
|
||||
position = if position == count - 1usize { 0usize } else { position + 1usize };
|
||||
}
|
||||
if map.length == count / 2usize { return InsertResult::<V>::full(move value); }
|
||||
if chosen == count { trap; }
|
||||
mut slot = slots[chosen];
|
||||
let replacement = std.option.Option::<V>::some(move value);
|
||||
let previous = value.swap(mut slot.value, move replacement);
|
||||
match move previous {
|
||||
std.option.Option::<V>::none => {}
|
||||
std.option.Option::<V>::some(unexpected) => { trap; }
|
||||
}
|
||||
slot.key = key;
|
||||
slot.state = SlotState::occupied;
|
||||
map.length = map.length + 1usize;
|
||||
return InsertResult::<V>::inserted;
|
||||
}
|
||||
|
||||
fn contains<V>(map: ref<U64Map<V>>, key: u64) -> bool effects [] {
|
||||
ref storage = map.storage;
|
||||
let count = buffer.capacity(storage);
|
||||
if count == 0usize { return false; }
|
||||
ref slots = buffer.view(storage);
|
||||
var wire: [u8; 8] = zero;
|
||||
for byte in 0usize..8usize { wire[byte] = (key >> ((byte as! u64) * 8u64)) as% u8; }
|
||||
let hash = std.hash.fnv1a64(ref wire);
|
||||
var position: usize = (hash % (count as! u64)) as! usize;
|
||||
for probe in 0usize..count {
|
||||
{ ref slot = slots[position];
|
||||
match slot.state {
|
||||
SlotState::occupied => { if slot.key == key { return true; } }
|
||||
SlotState::empty => { return false; }
|
||||
SlotState::deleted => {}
|
||||
}
|
||||
}
|
||||
position = if position == count - 1usize { 0usize } else { position + 1usize };
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fn get<V: Copy>(map: ref<U64Map<V>>, key: u64) -> std.option.Option<V> effects [] {
|
||||
ref storage = map.storage;
|
||||
let count = buffer.capacity(storage);
|
||||
if count == 0usize { return std.option.Option::<V>::none; }
|
||||
ref slots = buffer.view(storage);
|
||||
var wire: [u8; 8] = zero;
|
||||
for byte in 0usize..8usize { wire[byte] = (key >> ((byte as! u64) * 8u64)) as% u8; }
|
||||
let hash = std.hash.fnv1a64(ref wire);
|
||||
var position: usize = (hash % (count as! u64)) as! usize;
|
||||
for probe in 0usize..count {
|
||||
{ ref slot = slots[position];
|
||||
match slot.state {
|
||||
SlotState::occupied => {
|
||||
if slot.key == key {
|
||||
match slot.value {
|
||||
std.option.Option::<V>::some(value) => { return std.option.Option::<V>::some(value); }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
}
|
||||
SlotState::empty => { return std.option.Option::<V>::none; }
|
||||
SlotState::deleted => {}
|
||||
}
|
||||
}
|
||||
position = if position == count - 1usize { 0usize } else { position + 1usize };
|
||||
}
|
||||
return std.option.Option::<V>::none;
|
||||
}
|
||||
|
||||
fn remove<V>(map: mut<U64Map<V>>, key: u64) -> std.option.Option<V> effects [] {
|
||||
mut storage = map.storage;
|
||||
let count = buffer.capacity(storage);
|
||||
if count == 0usize { return std.option.Option::<V>::none; }
|
||||
mut slots = buffer.view(storage);
|
||||
var wire: [u8; 8] = zero;
|
||||
for byte in 0usize..8usize { wire[byte] = (key >> ((byte as! u64) * 8u64)) as% u8; }
|
||||
let hash = std.hash.fnv1a64(ref wire);
|
||||
var position: usize = (hash % (count as! u64)) as! usize;
|
||||
for probe in 0usize..count {
|
||||
{ mut slot = slots[position];
|
||||
match slot.state {
|
||||
SlotState::occupied => {
|
||||
if slot.key == key {
|
||||
let empty = std.option.Option::<V>::none;
|
||||
let previous = value.swap(mut slot.value, move empty);
|
||||
slot.state = SlotState::deleted;
|
||||
map.length = map.length - 1usize;
|
||||
match move previous {
|
||||
std.option.Option::<V>::some(value) => { return std.option.Option::<V>::some(move value); }
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
}
|
||||
SlotState::empty => { return std.option.Option::<V>::none; }
|
||||
SlotState::deleted => {}
|
||||
}
|
||||
}
|
||||
position = if position == count - 1usize { 0usize } else { position + 1usize };
|
||||
}
|
||||
return std.option.Option::<V>::none;
|
||||
}
|
||||
|
||||
fn pop<V>(map: mut<U64Map<V>>) -> std.option.Option<Entry<V>> effects [] {
|
||||
if map.length == 0usize { return std.option.Option::<Entry<V>>::none; }
|
||||
mut storage = map.storage;
|
||||
let count = buffer.capacity(storage);
|
||||
mut slots = buffer.view(storage);
|
||||
for index in 0usize..count {
|
||||
mut slot = slots[index];
|
||||
match slot.state {
|
||||
SlotState::occupied => {
|
||||
let key = slot.key;
|
||||
let empty = std.option.Option::<V>::none;
|
||||
let previous = value.swap(mut slot.value, move empty);
|
||||
slot.state = SlotState::deleted;
|
||||
map.length = map.length - 1usize;
|
||||
match move previous {
|
||||
std.option.Option::<V>::some(value) => {
|
||||
return std.option.Option::<Entry<V>>::some(Entry::<V> { key: key, value: move value });
|
||||
}
|
||||
std.option.Option::<V>::none => { trap; }
|
||||
}
|
||||
}
|
||||
SlotState::empty => {}
|
||||
SlotState::deleted => {}
|
||||
}
|
||||
}
|
||||
trap;
|
||||
}
|
||||
|
||||
fn free<V>(map: U64Map<V>) -> FreeResult<V> effects [] {
|
||||
if map.length != 0usize { return FreeResult::<V>::not_empty(move map); }
|
||||
let (storage, length) = struct.unpack(move map);
|
||||
{ mut slots = storage;
|
||||
while buffer.len(slots) != 0usize {
|
||||
let slot = buffer.pop(slots) or trap;
|
||||
let (key, state, value) = struct.unpack(move slot);
|
||||
match state {
|
||||
SlotState::empty => {}
|
||||
SlotState::deleted => {}
|
||||
SlotState::occupied => { trap; }
|
||||
}
|
||||
match move value {
|
||||
std.option.Option::<V>::none => {}
|
||||
std.option.Option::<V>::some(unexpected) => { trap; }
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.free(move storage) or trap;
|
||||
return FreeResult::<V>::ok;
|
||||
}
|
||||
|
||||
fn reserve<V>(map: mut<U64Map<V>>, capacity: usize, heap: cap<mem.alloc>) -> ReserveResult effects [mem.alloc] {
|
||||
let old_length = map.length;
|
||||
{ ref storage = map.storage;
|
||||
if capacity <= buffer.capacity(storage) / 2usize { return ReserveResult::ok; }
|
||||
}
|
||||
match std.map.new::<V>(capacity, heap) {
|
||||
NewResult::<V>::err(error) => { return ReserveResult::err(error); }
|
||||
NewResult::<V>::ok(next) => {
|
||||
{ mut old_storage = map.storage;
|
||||
mut new_storage = next.storage;
|
||||
let old_count = buffer.capacity(old_storage);
|
||||
let count = buffer.capacity(new_storage);
|
||||
mut old_slots = buffer.view(old_storage);
|
||||
mut new_slots = buffer.view(new_storage);
|
||||
for index in 0usize..old_count {
|
||||
var occupied: bool = false;
|
||||
var key: u64 = 0;
|
||||
{ ref slot = old_slots[index];
|
||||
key = slot.key;
|
||||
match slot.state {
|
||||
SlotState::occupied => { occupied = true; }
|
||||
SlotState::empty => {}
|
||||
SlotState::deleted => {}
|
||||
}
|
||||
}
|
||||
if occupied {
|
||||
var wire: [u8; 8] = zero;
|
||||
for byte in 0usize..8usize { wire[byte] = (key >> ((byte as! u64) * 8u64)) as% u8; }
|
||||
let hash = std.hash.fnv1a64(ref wire);
|
||||
var position: usize = (hash % (count as! u64)) as! usize;
|
||||
var found: bool = false;
|
||||
for probe in 0usize..count {
|
||||
{ ref slot = new_slots[position];
|
||||
match slot.state {
|
||||
SlotState::empty => { found = true; }
|
||||
SlotState::deleted => { trap; }
|
||||
SlotState::occupied => {}
|
||||
}
|
||||
}
|
||||
if found { break; }
|
||||
position = if position == count - 1usize { 0usize } else { position + 1usize };
|
||||
}
|
||||
if not found { trap; }
|
||||
let vacant = Slot::<V> { key: 0, state: SlotState::empty, value: std.option.Option::<V>::none };
|
||||
let transferred = value.swap(mut old_slots[index], move vacant);
|
||||
let empty = value.swap(mut new_slots[position], move transferred);
|
||||
let (unused_key, unused_state, payload) = struct.unpack(move empty);
|
||||
match move payload {
|
||||
std.option.Option::<V>::none => {}
|
||||
std.option.Option::<V>::some(unexpected) => { trap; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{ mut replacement = next; replacement.length = old_length; }
|
||||
map.length = 0;
|
||||
let previous = value.swap(mut map, move next);
|
||||
match std.map.free::<V>(move previous) {
|
||||
FreeResult::<V>::ok => {}
|
||||
FreeResult::<V>::not_empty(unexpected) => { trap; }
|
||||
}
|
||||
return ReserveResult::ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Numeric owning map: source/AIR parity, profiles, packages and diagnostics."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / "zig-out/bin/aji"
|
||||
FIXTURES = REPO / "tests/conformance/source/map"
|
||||
checks = 0
|
||||
|
||||
|
||||
def cli(*args, code=0):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True)
|
||||
assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr)
|
||||
checks += 1
|
||||
return result.stdout
|
||||
|
||||
|
||||
def returned(path, *grants):
|
||||
arguments = [argument for grant in grants for argument in ("--grant", grant)]
|
||||
record = json.loads(cli("run", "--fuel", "2000000", *arguments, path))
|
||||
assert record["status"] == "returned" and record["value"] == 42, record
|
||||
return record
|
||||
|
||||
|
||||
example = REPO / "examples/std/map.aji"
|
||||
returned(example, "heap=mem.alloc:256")
|
||||
with tempfile.TemporaryDirectory(prefix="aji-map-") as directory:
|
||||
root = Path(directory)
|
||||
air = root / "result.air"
|
||||
for name, grants in (
|
||||
("copy", ("heap=mem.alloc:1024",)),
|
||||
("owner", ("heap=mem.alloc:1024",)),
|
||||
("zero", ("heap=mem.alloc:8",)),
|
||||
("allocation", ("heap=mem.alloc:35",)),
|
||||
("collision", ("heap=mem.alloc:1024",)),
|
||||
("tombstones", ("heap=mem.alloc:1024",)),
|
||||
("reserve_failure", ("heap=mem.alloc:195",)),
|
||||
("reserve_peak", ("heap=mem.alloc:196",)),
|
||||
("reserve_authority", ("first=mem.alloc:72", "second=mem.alloc:108", "items=mem.alloc:8")),
|
||||
("model", ("heap=mem.alloc:1024",)),
|
||||
("model_owner", ("heap=mem.alloc:1024",)),
|
||||
("loan_join", ("heap=mem.alloc:44",)),
|
||||
("sender", ("heap=mem.alloc:256",)),
|
||||
):
|
||||
source = FIXTURES / f"{name}.aji"
|
||||
canonical = cli("lower", source)
|
||||
assert cli("lower", source) == canonical
|
||||
assert "unsafe" not in canonical
|
||||
air.write_text(canonical)
|
||||
cli("check", air)
|
||||
assert returned(source, *grants) == returned(air, *grants)
|
||||
for name, code in (("get_owner", "E7005"), ("missing_move", "E7003"),
|
||||
("loan", "E4101"), ("alias", "E2101"), ("not_share", "E4002")):
|
||||
diagnostics = cli("check", FIXTURES / f"{name}.aji", code=1)
|
||||
assert [json.loads(line)["code"] for line in diagnostics.splitlines()] == [code]
|
||||
assert cli("check", "--report", "unsafe", example) == ""
|
||||
reordered = root / "reordered.aji"
|
||||
reordered.write_text(example.read_text().replace("import std.map;\nimport std.option;",
|
||||
"import std.option;\nimport std.map;"))
|
||||
assert cli("lower", reordered) == cli("lower", example)
|
||||
cli("run", "--profile", "hosted", "--grant", "heap=mem.alloc:256",
|
||||
"--result-file", root / "hosted.json", example)
|
||||
record = json.loads((root / "hosted.json").read_text())
|
||||
assert record["status"] == "returned" and record["value"] == 42, record
|
||||
(root / "main.aji").write_text(example.read_text())
|
||||
(root / "aji.toml").write_text('[package]\nname = "map"\nversion = "1"\nentry = "main.aji"\n[capabilities]\nheap = "mem.alloc:256"\n')
|
||||
record = json.loads(cli("run", "--manifest", root / "aji.toml"))
|
||||
assert record["status"] == "returned" and record["value"] == 42, record
|
||||
print(f"source map: {checks} checks passed")
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check public map traces against independent Python dictionaries.
|
||||
|
||||
The oracle models bounded capacity, values and returned ownership, never
|
||||
hashing, probing, tombstones or physical slots. Golden .aji traces are
|
||||
checked byte-for-byte and executed by conformance.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import random
|
||||
import re
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/map"
|
||||
|
||||
def main(body):
|
||||
return "fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {\n" + body + "\n return 42;\n}\n"
|
||||
|
||||
def test(name, body):
|
||||
if name == "model":
|
||||
body = body.replace("struct.unpack(move entry)", "struct.unpack(entry)")
|
||||
body = re.sub(r"(std\.map\.(?:get|contains|len|capacity)::<[^\n(]+>\()(q)([,)])", r"\1ref \2\3", body)
|
||||
text = (ROOT / (name + ".aji")).read_text()
|
||||
actual = text[text.index("fn main("):]
|
||||
assert actual == body + "\n", name + " disagrees with Python dictionary oracle"
|
||||
|
||||
for owning,seed,steps in [(False,1701,72),(True,1702,56)]:
|
||||
rng=random.Random(seed);model={};capacity=2;ty='own<u64>' if owning else 'u64'
|
||||
lines=[f' let map = opened::<{ty}>({capacity}, heap);',' { mut q = map;']
|
||||
for step in range(steps):
|
||||
key=rng.choice([0,1,8,16,24,32,2**64-1]);value=rng.randrange(1,1000)
|
||||
op=rng.choice(['insert','insert','remove','contains','get'] if not owning else ['insert','insert','remove','contains'])
|
||||
if step in (18,36):
|
||||
capacity+=2;lines.append(f' match std.map.reserve::<{ty}>(q, {capacity}, heap) {{ std.map.ReserveResult::ok => {{}}, std.map.ReserveResult::err(error) => {{ trap; }} }}')
|
||||
if op=='insert':
|
||||
tag='replaced' if key in model else 'full' if len(model)==capacity else 'inserted'
|
||||
expected=model.get(key,value)
|
||||
if owning:lines.append(f' let input{step} = own.new({value}u64, heap) or trap;')
|
||||
inp=f'move input{step}' if owning else str(value)
|
||||
lines.append(f' match std.map.insert::<{ty}>(q, {key}, {inp}) {{')
|
||||
for variant in ['inserted','replaced','full']:
|
||||
arg='' if variant=='inserted' else '(returned)'
|
||||
expr='own.take(move returned)' if owning else 'returned'
|
||||
action='{}' if variant==tag=='inserted' else '{ assert('+expr+f' == {expected}u64); }}' if variant==tag else '{ trap; }'
|
||||
lines.append(f' std.map.InsertResult::<{ty}>::{variant}{arg} => {action}')
|
||||
lines.append(' }')
|
||||
if tag!='full':model[key]=value
|
||||
elif op=='remove':
|
||||
expected=model.pop(key,None)
|
||||
expr='own.take(move returned)' if owning else 'returned'
|
||||
some='{ trap; }' if expected is None else '{ assert('+expr+f' == {expected}u64); }}'
|
||||
none='{}' if expected is None else '{ trap; }'
|
||||
lines.append(f' match std.map.remove::<{ty}>(q, {key}) {{ std.option.Option::<{ty}>::some(returned) => {some}, std.option.Option::<{ty}>::none => {none} }}')
|
||||
elif op=='get':
|
||||
expected=model.get(key);some='{ trap; }' if expected is None else f'{{ assert(returned == {expected}u64); }}';none='{}' if expected is None else '{ trap; }'
|
||||
lines.append(f' match std.map.get::<u64>(q, {key}) {{ std.option.Option::<u64>::some(returned) => {some}, std.option.Option::<u64>::none => {none} }}')
|
||||
else:lines.append(f' assert(std.map.contains::<{ty}>(q, {key}) == '+str(key in model).lower()+');')
|
||||
lines.append(f' assert(std.map.len::<{ty}>(q) == {len(model)}usize);')
|
||||
lines.append(f' var seen: [bool; {len(model) or 1}] = zero;')
|
||||
for _ in model:
|
||||
lines.append(f' {{ let entry = extracted::<std.map.Entry<{ty}>>(std.map.pop::<{ty}>(q)); let (key, value) = struct.unpack(move entry);')
|
||||
if owning:lines.append(' let number = own.take(move value);')
|
||||
else:lines.append(' let number = value;')
|
||||
lines.append(' match key {')
|
||||
for index,(key,value) in enumerate(sorted(model.items())):lines.append(f' {key}u64 => {{ assert(number == {value}u64); assert(not seen[{index}]); seen[{index}] = true; }}')
|
||||
lines.append(' _ => { trap; } } }')
|
||||
lines.append(f' assert(std.map.len::<{ty}>(q) == 0usize);')
|
||||
lines.append(f' match std.map.pop::<{ty}>(q) {{ std.option.Option::<std.map.Entry<{ty}>>::none => {{}}, std.option.Option::<std.map.Entry<{ty}>>::some(unexpected) => {{ trap; }} }}')
|
||||
lines+=[' }',f' released::<{ty}>(move map);']
|
||||
test('model_owner' if owning else 'model',main('\n'.join(lines)))
|
||||
|
||||
print("map oracle traces passed (2 seeds, 128 operations; Copy and owning values)")
|
||||
@@ -20,6 +20,8 @@ TESTS = os.path.join(ROOT, "tests", "conformance", "source")
|
||||
|
||||
# (area, construct, regex, needs a reject test)
|
||||
CHECKLIST = [
|
||||
("map", "bounded exact-key owning insert/lookup", r"std\.map\.(insert|get|contains)", True),
|
||||
("map", "explicit growth, removal and drain", r"std\.map\.(reserve|remove|pop|free)", True),
|
||||
("failure", "explicit built-in error value", r"(?:return|=) (alloc_error|io_error|cap_error)::", True),
|
||||
("hash", "pure FNV/CRC byte hashing", r"std\.hash\.(fnv1a64|crc32c)\(", True),
|
||||
("hash", "continuation from explicit state", r"std\.hash\.(fnv1a64_extend|crc32c_extend)\(", True),
|
||||
|
||||
Reference in new issue
Block a user