diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e1894d..1a862cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,30 @@ jobs: - run: zig build conformance - run: zig build conformance -- --stress 200 - run: zig build && python3 tests/hosted/smoke.py + - run: python3 tests/hosted/source_modules.py + - run: python3 tests/hosted/source_generics.py + - run: python3 tests/hosted/source_static_functions.py + - run: python3 tests/hosted/source_linear.py + - run: python3 tests/hosted/source_buffers.py + - run: python3 tests/hosted/source_deque.py + - 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: python3 tests/hosted/source_hashmap.py + - run: python3 tools/hashmap_vectors.py + - run: python3 tests/hosted/source_hashset.py + - run: python3 tools/hashset_vectors.py + - run: python3 tests/hosted/source_heap.py + - run: python3 tools/heap_vectors.py + - run: python3 tests/hosted/source_io.py + - run: python3 tools/io_vectors.py + - run: python3 tests/hosted/source_buffered_io.py + - run: python3 tools/buffered_io_vectors.py + - run: python3 tests/hosted/source_path.py + - run: python3 tools/path_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) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 80db10e..968511f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,28 @@ zig build conformance # conformance suite, see tests/conformance/README.m zig build run -- check f.air # verify a text AIR module zig build run -- run f.air # verify and execute @main (deterministic profile) python3 tests/hosted/smoke.py # hosted profile against the real OS +python3 tests/hosted/source_modules.py # explicit package CLI and file-loading contracts +python3 tests/hosted/source_generics.py # explicit generics, constraints and provenance +python3 tests/hosted/source_static_functions.py # explicit operations, effects, nominal policy identity and workers +python3 tests/hosted/source_linear.py # whole-value owners, canonical AIR and CLI errors +python3 tests/hosted/source_buffers.py # initialized storage, owning vectors and CLI contracts +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 +python3 tests/hosted/source_hashmap.py # explicit general key policies, profiles and returned ownership +python3 tools/hashmap_vectors.py # independent dict and dense-order oracle, Copy/owning values +python3 tests/hosted/source_hashset.py # duplicate key ownership, source/AIR, packages and profiles +python3 tools/hashset_vectors.py # independent set and representative oracle, Copy/owning keys +python3 tests/hosted/source_heap.py # explicit ordering, owning extraction and profile/package parity +python3 tools/heap_vectors.py # independent heapq traces and exhaustive small permutations +python3 tests/hosted/source_io.py # bounded I/O, profiles, partial errors and explicit resources +python3 tools/io_vectors.py # independent byte/count/cursor oracle for read/copy boundaries +python3 tests/hosted/source_buffered_io.py # owning adapters, partial failures and no retry +python3 tools/buffered_io_vectors.py # independent read-prefix and segmented-write bytes +python3 tests/hosted/source_path.py # pure paths, ranges, profiles and independent authority +python3 tools/path_vectors.py # independent forward-stack path/query/capacity oracle (cd tools/eval && python3 -m unittest discover tests) # evaluation harness self-tests zig fmt --check build.zig src tools ``` @@ -41,6 +63,7 @@ src/ reference implementation (Zig) main.zig `aji` CLI tools/conformance.zig conformance runner tests/conformance/ .air conformance tests +std/ safe Aji standard modules embedded with the compiler examples/ illustrative Aji source programs ``` diff --git a/README.md b/README.md index 0b50d69..f33d2ca 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,8 @@ docs/plan/ Implementation plan and per-phase task breakdowns docs/dev/ Reference implementation architecture and testing src/ Reference implementation (Zig): diagnostics, AIR, verifier, interpreter tools/ Conformance runner -tests/ Conformance suite (.air accept/reject tests) +tests/ Conformance suite (.air and .aji accept/reject/run tests) +std/ Safe compiler-pinned .aji standard modules examples/ Illustrative Aji programs AGENTS.md Instructions for AI coding agents CONTRIBUTING.md Toolchain, commands, workflow, definition of done @@ -70,7 +71,7 @@ zig build test # unit tests zig build conformance # conformance suite ``` -Current state: Phases 0–2 are complete. AIR format 0 has frame storage and second-class borrows, arrays and slices with bounds proofs, flat effects and unforgeable capabilities, linear I/O resources (files, TCP), heap owners and regions with allocation budgets, and explicit unsafe boundaries. `aji run` executes programs in a reproducible deterministic world by default and against the real OS with `--profile hosted`. Phase 3 (structured concurrency) is next; see [`docs/plan/README.md`](docs/plan/README.md). +Current state: Phases 0–5 and the Phase 6A `.aji` frontend are implemented. Source modules, explicit generics/static operations, linear aggregates and initialized owning buffers support the intermediate standard-library foundation: owning collections, bytes/text/formatting/encodings, bounded and buffered I/O, and lexical paths. Full Phase 6 and Std 0.1 remain in progress; see the [language plan](docs/plan/README.md) and [std API](docs/reference/std.md). `aji run` uses a reproducible deterministic world by default and the real OS with `--profile hosted`. ```sh zig build diff --git a/build.zig b/build.zig index fd19bb2..c91c83b 100644 --- a/build.zig +++ b/build.zig @@ -27,6 +27,25 @@ pub fn build(b: *std.Build) void { mod.addAnonymousImport("intrinsics_md", .{ .root_source_file = b.path("docs/reference/intrinsics.md"), }); + mod.addAnonymousImport("std_bytes_aji", .{ .root_source_file = b.path("std/bytes.aji") }); + mod.addAnonymousImport("std_deque_aji", .{ .root_source_file = b.path("std/deque.aji") }); + mod.addAnonymousImport("std_encoding_base64_aji", .{ .root_source_file = b.path("std/encoding/base64.aji") }); + 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_hashmap_aji", .{ .root_source_file = b.path("std/hashmap.aji") }); + mod.addAnonymousImport("std_hashset_aji", .{ .root_source_file = b.path("std/hashset.aji") }); + mod.addAnonymousImport("std_heap_aji", .{ .root_source_file = b.path("std/heap.aji") }); + mod.addAnonymousImport("std_io_aji", .{ .root_source_file = b.path("std/io.aji") }); + mod.addAnonymousImport("std_io_reader_aji", .{ .root_source_file = b.path("std/io/reader.aji") }); + mod.addAnonymousImport("std_io_writer_aji", .{ .root_source_file = b.path("std/io/writer.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_path_aji", .{ .root_source_file = b.path("std/path.aji") }); + mod.addAnonymousImport("std_result_aji", .{ .root_source_file = b.path("std/result.aji") }); + mod.addAnonymousImport("std_utf8_aji", .{ .root_source_file = b.path("std/utf8.aji") }); + mod.addAnonymousImport("std_vec_aji", .{ .root_source_file = b.path("std/vec.aji") }); // CLI: `aji`. const exe = b.addExecutable(.{ diff --git a/docs/agent/README.md b/docs/agent/README.md index d079375..26948a5 100644 --- a/docs/agent/README.md +++ b/docs/agent/README.md @@ -86,3 +86,48 @@ The groups `quick_reference`, `source_docs` and `air_docs` come from the `doc_gr [`quick-reference.md`](quick-reference.md) is the front door of the Source Reference Bundle (`QUICK.md`). It targets 4–6k tokens (about 4.4k with the navigation table, cl100k), covers most programs, and is kept consistent with spec 15. **Its examples are checked.** Every ```aji block must be an excerpt of a program in `tests/conformance/source/quickref/`. Comments and whitespace are ignored, and `…` matches any text. Those programs are conformance tests, so each example is part of a program that verifies and runs. `zig build test` and `zig build agent-reference` fail on an example that is not. The concurrency programs (§7) are PENDING until layers 7–8 exist. + +## Standard library bootstrap + +`language/syntax.md` includes the built-in import rules (spec 15 §13). The on-demand `library/std.md` includes spec 16 and the signature table in `reference/std.md`. The source profile counts `library/` with `source_docs`. Pure library source is verified through the ordinary pipeline; no AIR bundle addition is needed. RFC 0016 records bootstrap complexity growth; RFC 0017 records endian APIs and qualified standard enum types. The plan tracks the next APIs. + +RFC 0016 bootstrap measurement (cl100k): Quick Reference 5,511 → 5,777 (+4.8%); other source docs 28,470 → 30,461 (+7.0%); full source docs excluding AIR 33,981 → 36,238 (+6.6%). The on-demand library page is 1,346 tokens. The AIR bundle stays 160,797 bytes. The RFC also records o200k and Qwen2.5 counts. + +RFC 0017 endian increment (cl100k, relative to bootstrap): Quick Reference 5,777 → 6,000 (+3.9%); other source docs 30,461 → 31,918 (+4.8%); full source docs excluding AIR 36,238 → 37,918 (+4.6%). The library page is 2,533 tokens. AIR remains unchanged. The additional Quick Reference example shows explicit typed success/short-buffer handling; future API catalogs stay on demand. + +RFC 0018 bounded operations (cl100k, relative to endian): Quick Reference 6,000 → 6,082 (+1.4%); other source docs 31,918 → 33,628 (+5.4%); full source docs excluding AIR 37,918 → 39,710 (+4.7%). The library page is 4,223 tokens. AIR remains unchanged. Copy, substring lookup and recoverable arithmetic reuse existing verified primitives; detailed contracts and the checked sizing example stay on demand. + +RFC 0019 text/encodings (cl100k, relative to bounded): Quick Reference 6,082 → 6,163 (+1.3%); other source docs 33,628 → 36,042 (+7.2%); full source docs excluding AIR 39,710 → 42,205 (+6.3%). The library page is 6,644 tokens. AIR remains unchanged. UTF-8, hex and canonical Base64 use existing primitives and fixed frame tables. Cumulative full source growth since the pre-stdlib baseline is +24.2%, above the 20% review line; RFC 0019 records the justification and owner-review scope. Future API references should be split/read selectively instead of expanding the front-door catalog. + +RFC 0020 supplied-buffer decimal formatting (cl100k, relative to text): Quick Reference 6,163 → 6,220 (+0.9%); other source docs 36,042 → 37,128 (+3.0%); full source docs excluding AIR 42,205 → 43,348 (+2.7%). The library page is 7,730 tokens. AIR remains unchanged. Four scalar writers reuse ordinary source and one Copy enum; full contracts and explicit record composition stay on demand. Cumulative source growth from the pre-stdlib baseline is +27.6%, with the existing owner-review justification recorded in RFC 0020. No compression benefit is inferred from documentation or fixtures. + +RFC 0021 package modules (cl100k, relative to formatting): Quick Reference 6,220 → 6,501 (+4.5%); other source docs 37,128 → 38,822 (+4.6%); full source docs excluding AIR 43,348 → 45,323 (+4.6%). New on-demand `language/modules.md` is 1,566 tokens, library/std.md and AIR remain unchanged. The front door has one checked module example; package input/name/loader contracts stay on demand. Cumulative source growth is +33.4%, documented for owner review; no compression benefit is claimed. Pure modules need no new AIR feature or verifier state. + +RFC 0022 explicit generics (cl100k, relative to modules): Quick Reference 6,501 → 6,948 (+6.9%); other source docs 38,822 → 41,086 (+5.8%); full source docs excluding AIR 45,323 → 48,034 (+6.0%). New on-demand `language/generics.md` is 1,324 tokens; `library/std.md` is 8,380 tokens. AIR remains 160,797 bytes. Cumulative source growth is +41.3%, and Quick Reference exceeds its 4–6k target; the RFC explains the cost for owner review and calls for separate front-door consolidation/selective API reading. Explicit specialization adds no AIR instruction or verifier transfer state; documentation growth alone does not establish a compression benefit. + + +RFC 0023 whole-value linear aggregates (cl100k, relative to generics): Quick Reference 6,948 → 7,225 (+4.0%); other source docs 41,086 → 42,364 (+3.1%); full source docs excluding AIR 48,034 → 49,589 (+3.2%). New on-demand `language/linear-aggregates.md` is 1,133 tokens; `library/std.md` is 8,398. AIR grows to 168,336 bytes (+4.7%). Whole unpack/exhaustive match/explicit swap/allocation failure expose ownership without per-field holes, cleanup or new transfer state. Cumulative source growth is approximately +45.9%; Quick Reference remains beyond its 4–6k target. RFC 0023 justifies the added contracts; consolidation remains separate work and no MCC improvement is claimed. + +RFC 0024 initialized buffers and safe Vec (cl100k, relative to linear aggregates): Quick Reference 7,225 → 7,667 (+6.1%); other source docs 42,364 → 44,717 (+5.6%); full source excluding AIR 49,589 → 52,384 (+5.6%). New on-demand language/buffers.md is 1,175 tokens; library/std.md is 9,432. AIR grows to 175,736 bytes (+4.4%). Initialized prefixes, explicit reserve, returned failure ownership and empty-only free permit safe resource containers without per-slot verifier state. Cumulative full source growth is +54.2%, with the RFC's owner-review justification; Quick Reference consolidation remains separate work and no empirical MCC improvement is claimed. + +RFC 0025 safe owning Deque (cl100k, relative to buffer/Vec): Quick Reference 7,667 → 7,747 (+1.0%); other source docs 44,717 → 46,246 (+3.4%); full source excluding AIR 52,384 → 53,993 (+3.1%). library/std.md is 10,961 tokens; AIR remains 175,736 bytes. Eleven generic safe functions reuse buffer/Option/exchange and existing ownership/borrow rules without semantic or verifier-state growth. Full ring invariants and accounting stay on demand; cumulative full-source growth is +58.9%, with the RFC's owner-review justification and no empirical MCC claim. + +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. + +RFC 0029 static function parameters (cl100k, relative to numeric maps): Quick Reference 7,863 → 8,051 (+2.4%); other source docs 50,079 → 51,002 (+1.8%); full source excluding AIR 57,942 → 59,053 (+1.9%). language/generics.md is 2,194 tokens; AIR remains 179,282 bytes / 51 sections. One explicit operation-selection concept adds two source forms and bounded frontend state, with no runtime/verifier state or new AIR construct/diagnostic. Cumulative growth is +73.8%; the RFC justifies the general hash/equality/order prerequisite, keeps general collections open and makes no empirical MCC claim. + +RFC 0030 general owning HashMap (cl100k, relative to static operations): Quick Reference 8,051 → 8,124 (+0.9%), other source docs 51,002 → 53,363 (+4.6%), full source excluding AIR 59,053 → 61,487 (+4.1%). library/std.md is 16,504 tokens; AIR remains 179,282 bytes / 51 sections. Ten safe source functions use explicit static policies and complete key/value transfer, with no new language form, verifier/runtime state or diagnostic. Cumulative source growth is +80.9%, justified in the RFC without an empirical MCC claim; full policies/failure/dense-index invariants stay on demand. + +RFC 0031 general owning HashSet (cl100k, relative to HashMap): Quick Reference 8,124 → 8,201 (+0.9%), other source docs 53,363 → 54,798 (+2.7%), full source excluding AIR 61,487 → 62,999 (+2.5%). library/std.md is 17,939 tokens; AIR remains 179,282 bytes / 51 sections. Nine safe wrappers return duplicate/full incoming keys and transfer stored keys through ordinary ownership rules. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +85.4%, justified by explicit ownership/accounting contracts without an empirical MCC claim. + +RFC 0032 owning BinaryHeap (cl100k, relative to HashSet): Quick Reference 8,201 → 8,284 (+1.0%), other source docs 54,798 → 56,770 (+3.6%), full source excluding AIR 62,999 → 65,054 (+3.3%). library/std.md is 19,911 tokens; AIR remains 179,282 bytes / 51 sections. Eight safe source operations bind explicit pure order and sift Copy indices while complete owners remain in initialized storage. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +91.4%, justified by visible ordering/ownership/failure/accounting contracts without an empirical MCC claim. + +RFC 0033 bounded I/O (cl100k, relative to BinaryHeap): Quick Reference 8,284 → 8,350 (+0.8%), other source docs 56,770 → 58,473 (+3.0%), full source excluding AIR 65,054 → 66,823 (+2.7%). library/std.md is 21,614 tokens; AIR remains 179,282 bytes / 51 sections. Six safe concrete compositions retain exact effects and caller resource loans, distinguishing EOF/limits from partial failure. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +96.6%, justified by progress/authority/cleanup contracts without an empirical MCC claim. + +RFC 0034 owning buffered files (cl100k, relative to bounded I/O): Quick Reference 8,350 → 8,445 (+1.1%), other source docs 58,473 → 61,223 (+4.7%), full source excluding AIR 66,823 → 69,668 (+4.3%). library/std.md is 24,364 tokens; AIR remains 179,282 bytes / 51 sections. Ten safe concrete operations keep fixed allocation, file transfer, prefetch and first-error/partial-write cleanup visible. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +105.0%, justified by these contracts without an empirical MCC claim. Full representation/API details stay on demand; front-door consolidation remains separate work. + +RFC 0035 caller-buffer paths (cl100k, relative to buffered files): Quick Reference 8,445 → 8,518 (+0.9%), other source docs 61,223 → 63,296 (+3.4%), full source excluding AIR 69,668 → 71,814 (+3.1%). library/std.md is 26,437 tokens; AIR remains 179,282 bytes / 51 sections. Six pure operations return raw Copy ranges or write a measured canonical prefix, keeping lifetime, byte syntax, capacity failure and authority visible. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +111.3%, justified by these contracts without an empirical MCC claim. API details stay on demand; front-door consolidation remains separate work. diff --git a/docs/agent/bundle.txt b/docs/agent/bundle.txt index 9143118..43955d1 100644 --- a/docs/agent/bundle.txt +++ b/docs/agent/bundle.txt @@ -59,6 +59,7 @@ docs/spec/05-effects-and-capabilities.md :: ## 9. Effects in AIR docs/spec/05-effects-and-capabilities.md :: ## 10. Capabilities in AIR docs/spec/05-effects-and-capabilities.md :: ## 11. Intrinsic calls docs/spec/05-effects-and-capabilities.md :: ## 12. Runtime +docs/spec/05-effects-and-capabilities.md :: ## 14. Explicit error values # Resources and I/O errors docs/spec/06-resources-and-errors.md :: ## 6. Resources in AIR @@ -86,3 +87,9 @@ docs/reference/air-features.md docs/reference/effects.md docs/reference/capabilities.md docs/reference/intrinsics.md + +# Whole-value linear aggregates (STD-5) +docs/spec/03-memory-model.md :: ## 25. Linear aggregates in AIR + +# Dynamic initialized storage (STD-6a) +docs/spec/03-memory-model.md :: ## 26. Dynamic initialized buffers diff --git a/docs/agent/quick-reference.md b/docs/agent/quick-reference.md index ce24038..3644048 100644 --- a/docs/agent/quick-reference.md +++ b/docs/agent/quick-reference.md @@ -149,6 +149,8 @@ region.reset(r); `err(e)` binds a real value: `match e { alloc_error::budget_exceeded => …, alloc_error::out_of_memory => … }`. +Built-in errors are Copy data: `let e = alloc_error::budget_exceeded;` constructs a payload-free value without effects, allocation or authority. All registered `alloc_error`, `cap_error` and `io_error` variants work this way (spec 05 §14). + - **Narrowing:** `cap.narrow.prefix(c, b"/data")` and `cap.narrow.budget(heap, 4096)`, each giving `ok(c2) / err(e)`. - Resource operands (`f`, `s`, `l`, endpoints) are borrowed automatically for an operation; a region is not (bind `ref arena = r;`); data borrows (`mut buf`, `ref bytes`) are always written. - Memory budgets count live bytes, so freeing returns them. In the deterministic profile `mem.alloc` needs a grant with a budget: `--grant heap=mem.alloc:4096`. @@ -316,3 +318,163 @@ scope s { // every task spawned in s must | E2111 | graph content not plain data | store only integers, booleans, enums, structs/arrays of them and `iref`s in a graph | | T0010 | `iref` of another graph | use a handle with the graph it came from | | T0001–T0009 | runtime trap | see `kind` and `source_location` | + +## 10. Standard library + +Import a bundled module after the module header; call its functions by their full path. `std.bytes` and `std.math` are safe source, declare `effects []` and allocate no heap. No grants are needed. Read `/docs/library/std.md` for the API. + +```aji +module demo.standard +import std.bytes; +import std.math; + +fn main() -> u64 +effects [] +{ + var data: [u8; 4] = zero; + std.bytes.fill(mut data, 65); + assert(std.bytes.equal(ref data, b"AAAA")); + let index = std.bytes.find(ref data, 65); + if index < data.len { assert(data[index] == 65); } + return std.math.clamp_u64(42, 0, 100); +} +``` + +`find` returns the searched slice's length when absent; check before indexing. `clamp_u64` traps `T0002` for an inverted range. Missing import/module/member: `E7002`; duplicate import: `E7006`; wrong arguments: `E7005`. Aliases are unavailable; explicit generics use §12. + +Endian reads/writes cover `u16/u32/u64` in LE and BE. Pass a sub-slice for an offset. Reads return `std.bytes.ReadUW` with `ok(uW)`/`short_input`; writes return `std.bytes.WriteResult` with `ok`/`short_output`. A short destination is unchanged. Handle them with qualified enum patterns (not intrinsic outcome patterns): + +```aji +match std.bytes.write_u32_be(mut wire[1..5], 0x12345678) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } +} +match std.bytes.read_u32_be(ref wire[1..5]) { + std.bytes.ReadU32::ok(value) => { return value; } + std.bytes.ReadU32::short_input => { return 0; } +} +``` + +The usual enum rules apply: missing arm `E7004`, wrong enum/payload `E7005`, unknown type/variant `E7002`. See `/docs/library/std.md` for signatures. + +`std.bytes.copy` returns `WriteResult`; short output is unchanged and overlap rejects. `find_slice` returns `FindResult::found(index)` / `not_found` (empty needle: found at 0). Recoverable `u64`/`usize` arithmetic, split composition and a checked example are in `/docs/library/std.md`; wrapping stays `+%`, `-%`, `*%`. + +`std.utf8` validates bytes and decodes the next scalar with an explicit consumed count. `std.encoding.hex` and `std.encoding.base64` encode/decode into `mut` output slices; ordinary enum results expose malformed input and short capacity, leaving output unchanged on errors. Base64 accepts canonical padded standard encoding. Signatures and a checked example are in `/docs/library/std.md`. + +`std.fmt.write_u64/i64/usize/isize` write decimal integers into supplied output slices; `WriteResult::ok(count)` / `short_output` expose capacity, with unchanged output on failure. Composition and signatures are in `/docs/library/std.md`. + +`std.hashmap.HashMap` supports general owning keys/values through explicit pure ref-key operations (§12). Insert returns replaced/full key/value pairs; remove/pop move both out, get requires only V: Copy, growth is explicit and free returns nonempty maps. Full contracts are in `/docs/library/std.md`. + +`std.hashset.HashSet` uses the same policies for complete owning keys. Insert returns `present(input)` for duplicates, preserving the stored key, or `full(input)`; remove/pop move stored keys out. Only new/reserve allocate with explicit authority; free returns nonempty sets. Full contracts are in `/docs/library/std.md`. + +`std.heap.BinaryHeap` binds pure `fn(ref,ref)->bool effects []` as a stable strict weak order. Push returns full input; pop moves the priority root; peek requires T: Copy. Only new/reserve allocate with explicit authority; free returns nonempty heaps. Ties have no stable-order guarantee. Full contracts are in `/docs/library/std.md`. + +`std.io` supplies exact stdin/file/stream reads, bounded file read-to-end and limited file copy/append with caller slices and explicit effects/authority. EOF differs from full/limit; errors report confirmed progress. Resources stay borrowed, no heap or close is hidden, and failed external writes may be partial. Full contracts are in `/docs/library/std.md`. + +`std.io.reader`/`std.io.writer` own a file and an explicitly allocated fixed byte buffer. Use new, read/read_exact or write/flush, then finish to return the file for explicit close. Unread/failed finish returns the whole adapter; discard explicitly abandons buffered bytes and frees storage. A failed writer preserves its first error and never retries. Capacity zero uses direct I/O. Effects and ownership remain explicit; see `/docs/library/std.md`. + +`std.path` provides pure slash-based is_absolute/basename/parent/extension and supplied-buffer normalize/join. Queries return Copy Range{start,end}; explicitly borrow that range from the original path. Writers preserve output on error and return the successful prefix size, with no heap or filesystem authority. Dot/parent and root rules are in `/docs/library/std.md`. + +`std.hash.fnv1a64` and `crc32c` hash byte slices without allocation; their `_extend` forms continue from a previous result. Hashes do not establish key equality or authentication. Exact algorithms and chunk/byte-order conventions are in `/docs/library/std.md`. + +## 11. Package modules + +Declare package inputs explicitly in `aji.toml`: + +```toml +[package] +entry = "main.aji" +[modules] +app.model = "model.aji" +``` + +`model.aji` declares `module app.model`. Import it directly; functions, structs and enums use full names. Short names stay local to their defining module; imports grant no authority or transitive name visibility. + +```aji +module app.entry +import app.model; + +fn main() -> u64 +effects [] +{ + let pair = app.model.Pair { left: 20, right: 22 }; + return app.model.total(pair); +} +``` + +Use `aji check|lower|report|run|explore --manifest aji.toml`; `run` and `explore` instantiate manifest grants. A file-only command does not discover packages. Qualified workers work in `task.spawn(s, app.work.run, args)` with ordinary `move`, borrow and join rules. Missing/direct-import names: `E7002`; cycles/header mismatch/duplicates: `E7006`. Read `/docs/language/modules.md` for limits and file-loading rules. `lower --stats` counts entry source against combined AIR, so it is not a whole-package size metric. + +## 12. Generics + +Declare type parameters on functions, structs or enums: ``, `` or ``. Every use supplies all types: `Pair` in annotations, `Pair:: { ... }`, `identity::(42)` and `Option::::some(42)` in expressions/patterns. Qualified forms require a direct import. No inference, traits, defaults or overloads. `task.spawn(s, worker::, args)` specializes a static worker with the ordinary ownership/effect rules. + +```aji +module demo.generic +import std.option; + +fn identity(value: T) -> T effects [] { return value; } + +fn main() -> u64 effects [] { + let value = std.option.Option::::some(identity::(42)); + match value { + std.option.Option::::some(n) => { return n; } + std.option.Option::::none => { return 0; } + } +} +``` + +`std.option.Option` has `some(T)`/`none`; `std.result.Result` has `ok(T)`/`err(E)`. `is_some::` and `is_ok::` classify Copy specializations; match to extract payloads. Owning payloads follow §13; borrowed payloads reject. Unknown names: `E7002`; missing/extra arguments, duplicate/unknown constraints or expansion limits: `E7006`; unsatisfied constraints: `E7005` with `parameter`, `constraint`, `found`. Borrow conflicts, moves, effects and cleanup keep their existing rules. + +Each required specialization is checked as concrete code; an unused template body is not a proof for future types. `Copy` gives no arithmetic or ordering operation. Read `/docs/language/generics.md` for exact Copy/Send/Share/Freeze/Local rules, deterministic keys and fixed limits; `/docs/library/std.md` for option/result contracts. + +An operation is an explicit static parameter, with exact parameter/return types and effect set. Select a declared function with `fn path` (generic: `fn path::`); `fn F` forwards a bound operation. It has no runtime value or captures; F is only a direct call or `task.spawn` worker. Different operations produce distinct nominal instances. Mismatch: `E7005`; escaping/shadowing F or borrowed return contracts: `E7006`. Effects and capability arguments remain explicit. + +```aji +module demo.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { + return F(move value); +} +fn main() -> u64 effects [] { return apply::(42u64); } +``` + +## 13. Linear aggregates + +A struct/enum/fixed array containing owners or resources is linear. Construct with `move`; consume it completely. Read Copy fields normally. A linear enum needs exhaustive `match move`; even none must be consumed. No partial moves or automatic cleanup. + +```aji +struct Item { owner: own } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let value = Item { owner: move owner }; + let (part) = struct.unpack(move value); + return own.take(move part); +} +``` + +`[move a, move b]` constructs ordered array elements; `let (a,b) = array.unpack(move data);` extracts every element. `value.swap(mut place, move replacement)` returns the old complete value. `own.pack(move value, heap)` has ok(owner) and err(error, original_value); own.take extracts linear content, while own.free cannot destroy it. Dynamic heap arrays/regions/frame storage remain Copy-only. Owning std.option/std.result use ordinary linear enums; is_some/is_ok retain Copy constraints. Full contracts: language/linear-aggregates.md. + +## 14. Buffers and Vec + +`buffer` uniquely owns capacity and an initialized prefix, including owners/resources. Allocate with `buffer.new(capacity, heap)` (mem.alloc); borrow the handle first for len/capacity/reserve/push/pop/view. `reserve(b, capacity, heap)` grows explicitly, charging old+new capacity at the peak. Push never grows: full returns the original item. Pop moves the last element out. Free succeeds only when empty; otherwise it returns the buffer. No destructor drains it. + +```aji +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + let item = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { mut b = data; + buffer.push(b, move item) or trap; + let last = buffer.pop(b) or trap; + answer = own.take(move last); + } + buffer.free(move data) or trap; + return answer; +} +``` + +`ref values = buffer.view(b);` / `mut values = buffer.view(b);` borrow only the prefix. A live child view/task loan blocks shape changes, even a no-op reserve. Read Copy elements; use value.swap to replace linear elements, consuming the returned old value. Full contracts: language/buffers.md. + +Import `std.vec` for `Vec` and new/len/capacity/reserve/push/pop/free/get/replace, each explicitly specialized `::`. new/reserve require mem.alloc; push is bounded, get requires Copy, pop returns std.option.Option. Failure variants retain ownership: full(item), out_of_bounds(item), not_empty(vector). Match move on linear results; import std.option to name its variants. Signatures: library/std.md. Inside a specialized generic body, `move name` also accepts complete Copy bindings and retains their availability; monomorphic Copy moves and moves of borrows still reject. + +`std.deque` uses the same explicit allocation, returned-ownership and empty-only free contract, with push_front/push_back and pop_front/pop_back. Indices count from the front. Each capacity slot charges Option (tag plus payload); reserve preserves order and needs old+new quota. It uses existing source primitives; signatures and representation invariants stay in library/std.md. diff --git a/docs/agent/source-bundle.txt b/docs/agent/source-bundle.txt index d173265..f4a5344 100644 --- a/docs/agent/source-bundle.txt +++ b/docs/agent/source-bundle.txt @@ -9,7 +9,7 @@ > QUICK.md docs/agent/quick-reference.md -docs/agent/source-notes.md :: ## 10. Where to read more +docs/agent/source-notes.md :: ## 14. Where to read more > language/syntax.md docs/reference/grammar.ebnf @@ -19,6 +19,28 @@ docs/spec/15-source-language.md :: ## 4. Statements and control flow docs/spec/15-source-language.md :: ## 5. Expressions docs/spec/15-source-language.md :: ## 6. Fallible operations and `match` +docs/spec/15-source-language.md :: ## 13. Built-in standard modules + +> language/linear-aggregates.md +docs/spec/15-source-language.md :: ## 16. Source linear aggregates +docs/spec/03-memory-model.md :: ## 25. Linear aggregates in AIR + +> language/buffers.md +docs/spec/15-source-language.md :: ## 17. Source dynamic buffers +docs/spec/03-memory-model.md :: ## 26. Dynamic initialized buffers + +> language/generics.md +docs/spec/15-source-language.md :: ## 15. Explicit source generics +docs/spec/15-source-language.md :: ## 18. Static function parameters + +> language/modules.md +docs/spec/15-source-language.md :: ## 14. Package source modules +docs/spec/12-packages-and-build.md :: ### 1.3 Package source mapping + +> library/std.md +docs/spec/16-standard-library.md +docs/reference/std.md + > language/types.md docs/spec/15-source-language.md :: ## 3. Types docs/spec/02-types-and-values.md :: ## 2. Integer semantics @@ -51,6 +73,7 @@ docs/spec/05-effects-and-capabilities.md :: ## 4. Narrowing docs/spec/05-effects-and-capabilities.md :: ## 5. Capability transfer docs/spec/05-effects-and-capabilities.md :: ## 9. Effects in AIR docs/spec/05-effects-and-capabilities.md :: ## 10. Capabilities in AIR +docs/spec/05-effects-and-capabilities.md :: ## 14. Explicit error values docs/reference/effects.md docs/reference/capabilities.md diff --git a/docs/agent/source-notes.md b/docs/agent/source-notes.md index 2aa6b3e..e5fcd78 100644 --- a/docs/agent/source-notes.md +++ b/docs/agent/source-notes.md @@ -2,12 +2,17 @@ Text that exists only for the Source Reference Bundle (`source-bundle.txt`). Non-normative: it points at the normative files and states which source layers are implemented. -## 10. Where to read more +## 14. Where to read more The other files in `/docs` hold the full rules. Open one only when this page is not enough. | Need | Read | |---|---| +| built-in bytes/math/text/formatting/hash, option/result, owning collections and bounded I/O, signatures and failure contracts | `/docs/library/std.md` | +| initialized buffer storage, explicit growth/drain and child views | `/docs/language/buffers.md` | +| whole-value linear aggregates, unpack, exchange and allocation failure | `/docs/language/linear-aggregates.md` | +| generic declarations/applications, property constraints, static function contracts and specialization limits | `/docs/language/generics.md` | +| explicit package imports, qualified types, manifest file inputs | `/docs/language/modules.md` | | exact syntax, every construct, `match` and outcomes | `/docs/language/syntax.md` | | integer semantics, conversions, Copy/Send/Share, traps | `/docs/language/types.md` | | borrows, scopes, frame storage, slices, initialization | `/docs/language/ownership.md` | diff --git a/docs/design/hash-map.md b/docs/design/hash-map.md new file mode 100644 index 0000000..b8149e1 --- /dev/null +++ b/docs/design/hash-map.md @@ -0,0 +1,57 @@ +# Owning hash map design + +Status: STD-6d.2 numeric-key and STD-6d.4/5 general-key branch implementations validated (RFCs 0028/0030/0031 Proposed); Q-037 resolved. Spec 16 §2.13–§2.15 is normative for std.map/std.hashmap/std.hashset. This document records design rationale and does not override the specification. + +## Key policy and scope + +The eventual collection gate still requires HashMap>. At the numeric-map decision, type parameters supplied no hashing/equality operations (spec 15 §15); Copy supplies neither. RFC 0029/spec 15 §18 now supplies explicit static functions without runtime callbacks, methods, user traits or captured values. 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. + +The initial branch increment was `std.map.U64Map`: 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 was Q-037, now resolved by explicit static policies and dense complete owning entries (spec 16 §2.14–§2.15). Byte-key ownership uses that general owning representation contract. Do not name this specialization HashMap or claim that it satisfies the general-key gate. + +## Public API + +Ten generic functions, each explicitly specialized `::`; only new/reserve declare effects [mem.alloc] and take cap. 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 | +|---|---| +| `new(capacity: usize, heap: cap)` | `NewResult::ok(U64Map)` / `err(alloc_error)` | +| `len(map: ref>) -> usize` | occupied entries | +| `capacity(map: ref>) -> usize` | guaranteed maximum entries before new-key insert returns full | +| `reserve(map: mut>, capacity: usize, heap: cap)` | `ReserveResult::ok` / `err(alloc_error)`; <= current capacity is an unchanged no-op | +| `insert(map: mut>, key: u64, value: V)` | `InsertResult::inserted` / `replaced(V)` / `full(V)` | +| `contains(map: ref>, key: u64) -> bool` | presence without copying V | +| `get(map: ref>, key: u64) -> std.option.Option` | copied value or none | +| `remove(map: mut>, key: u64) -> std.option.Option` | moves out value or none; missing key leaves state unchanged | +| `pop(map: mut>) -> std.option.Option>` | moves out one key/value or none; Entry has key: u64 and value: V | +| `free(map: U64Map)` | `FreeResult::ok` / `not_empty(U64Map)` | + +Insert first searches for exact key equality. Replacing an existing key succeeds even when full and returns the old complete value; the new input is consumed exactly once. A new key at capacity returns its unchanged input without modifying any slot or metadata. It never allocates or grows. Keys 0 and 2^64-1 are ordinary valid keys, not empty/tombstone sentinels. pop permits explicit cleanup without requiring a Copy value, iterator or returned borrow; no clear/drop helper is planned. + +## Representation, lookup and accounting + +Use initialized `buffer>`, with Slot an ordinary struct containing key: u64, state: SlotState and value: Option. SlotState is a Copy enum empty/deleted/occupied. Copy key/state fields remain readable through ref even when V is linear (spec 15 §16); a linear enum containing the key/value would not support observational lookup with existing enum.switch. The representation therefore needs no borrowed-enum or partial-move feature. A capacity N uses exactly 2N physical slots and limits live entries to N. N=0 has zero slots and no live entries; no modulo is evaluated. Capacity multiplication/byte-charge overflow returns existing budget_exceeded, before allocation or mutation. Slot quota includes the key, SlotState tag and Option tag/maximum payload, including vacant/deleted slots; no hidden allocation owns payloads. Manual field construction/mutation must preserve the documented invariant, as for Vec/Deque. + +A deterministic hash hashes exactly eight little-endian key bytes using std.hash.fnv1a64; it never hashes host padding or object addresses. Linear probing begins at hash modulo the physical slot count, visits at most that count, and advances with an overflow-free wrapped index. Hash only chooses the probe start; occupied keys always compare by exact u64 equality. Lookup passes deleted slots and stops at empty or after the full bounded probe. Insert remembers the first deleted slot but continues searching for an existing key until empty/end, so deletion cannot create a duplicate. At least half the slots are non-occupied, but deletion may leave no empty slots: deleted-only probe termination must work. + +Remove/pop exchange a complete Option for none, set the Copy state to deleted, decrement length and return user ownership. No tombstone compaction is required during remove/pop; this keeps them allocation-free and avoids partial holes. When logically empty, free examines/consumes all physical slots; invalid metadata cannot make it normally discard an occupied value. This is explicit internal cleanup only. pop chooses the first occupied physical index, so order is deterministic for the operation history, not insertion or key order. Rehash may change that order; callers requiring sorted output must sort explicitly. + +Reserve first allocates and initializes the whole new table, while the old table and every user owner remain unchanged. Failure refunds temporary storage to its authority and preserves old slots, length, capacity and iteration order exactly. Once allocation succeeds, no recoverable operation may fail: exchange each complete occupied slot into the new table in old physical-index order, then explicitly consume internal none payloads and free old empty/deleted storage. Peak quota includes both full tables plus separately charged user owners. Refund the old table to its recorded authority, even when reserve uses another capability. A successful growth clears tombstones and preserves every key/value association. Do not build this on buffer.reserve alone: rehash needs both old and new layouts until transfer finishes. + +Expected probing depends on collisions/history; worst-case lookup/insert/remove is O(N). Pop/empty free inspect O(N) slots. New/reserve perform O(N) slot work, with possible O(N²) rehash collision work and the interpreter's existing prefix-copy overhead. Fixed non-cryptographic FNV is not an adversarial hashing guarantee. Fuel and capacity bound work explicitly; no random seed or ambient entropy is introduced. + +## 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 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>, 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 + +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. + + +## General-key implementation + +RFC 0030/spec 16 §2.14 introduces separate std.hashmap so std.map's numeric signatures remain compatible without overloads. Explicit H/E contracts support arbitrary complete owning keys and values. Dense initialized StoredEntry slots plus Copy bucket indices permit shared key borrows, avoiding vacancy/default keys and borrowed-enum/partial-move features. Replacement returns the entire previous key/value; full returns the entire input pair. Removal exchanges the last entry into the hole and repairs its index; pop is reverse current dense order. Growth initializes new indices first, then uses failure-preserving buffer.reserve, rehashes cached hashes and frees old indices. This keeps failure exact while charging both layouts at the peak. The full library contract, rather than this historical numeric design, is normative. HashSet and BinaryHeap are later increments. diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 3582af4..c78de40 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -27,7 +27,11 @@ Status values: `open`, `resolved`. | Q-019 | resolved | P3 | Non-terminating programs in test tooling | | Q-020 | resolved | P2 | Size bound for SSA array values | | Q-024 | resolved | P5 | Memory-model clarifications found by the independent oracle | -| Q-025 | open | — | No array construction from element values in AIR | +| Q-025 | resolved | STD-5 | Array construction from complete element values | +| Q-035 | resolved | STD-5 | Whole-value linear aggregates | +| Q-036 | resolved | STD-6a | Dynamic initialized linear buffer storage and drain | +| Q-038 | resolved | STD-6d.2 | Pure construction of built-in errors | +| Q-039 | resolved | STD-6d | Explicit static function parameters | ## Q-001 — Text AIR grammar @@ -202,3 +206,85 @@ Points 1–3 and 5 are editorial. Point 4 fixes FIFO, which spec 04 §38 already Found by the independent author of `program_atomic_stats.air` (P5-9b). AIR has `array.splat` but no way to build an array from distinct element values. A six-element constant array costs a mutable borrow, six `borrow.index`/`store`/`borrow.end` triples and six index constants. `.aji` has the same gap: it has `[e; N]` but no array literal. The options are an `array.make T (%a, %b, …)` instruction (a value constructor like `struct.make`) with an `.aji` literal `[a, b, c]`, or no change. This is a convenience question, not a correctness one. It is not urgent, and any RFC for it must report its agent-complexity cost. + +**Resolved on STD-5 (RFC 0023 Implemented):** array.make and ordered source literals transfer complete linear elements. Copy-only frame stores/splat cannot express this ownership-preserving construction. The same constructor supports distinct Copy elements; its contract, feature gate, argument limits and measured complexity are specified with the vertical linear_aggregates feature. + + +## Q-026 — Standard library distribution and initial source imports + +The source frontend had no import resolution and the package manifest no dependencies. A source-only std therefore needed either manual concatenation or a specified import path. + +**Resolved in the std bootstrap branch:** spec 15 §13 defines a closed compiler-pinned registry, fully qualified calls, deterministic name mangling and library source locations. Spec 16 defines the initial pure API. General user modules and imported types remain STD-3/P6-3; no filesystem search is invented. RFC 0016 records the proposal; the owner adopted it with the intermediate std merge (2026-10-07). + +## Q-027 — Empty byte strings in source + +Found while testing `std.bytes`: the frontend rejects `b""` with `E7006` (“an empty byte string has no array type”), but spec 15 §5 does not state a nonempty restriction. Zero-length byte slices work as `ref storage[0..0]` and std tests use that existing form. Resolve the source literal rule separately; the std bootstrap does not change it or format-0 array semantics. + +## Q-028 — Recoverable endian reads need public standard result types + +A plain integer cannot distinguish a decoded zero from a short input. A trap on malformed protocol input is not a recoverable API, and a boolean plus mutable out-parameter leaves an invalid/stale output for callers to track. + +**Resolved in the endian work branch:** spec 16 §2.3 defines width-specific read result enums and one write result enum. Spec 15 §13 defines fully qualified standard enum type names, constructors and patterns using existing AIR enum semantics. RFC 0017 records the proposal. General modules, imported struct literals, generics and a must-use result rule remain outside this change. + +## Q-029 — Bounded byte copy/search/split and recoverable arithmetic surface + +Short destination capacity needs explicit failure without partial mutation. A substring search's empty needle can match the end of empty data, so the existing single-byte length sentinel cannot unambiguously encode all outcomes. A returned split pair would hold borrows inside an aggregate before that source/lifetime surface is available. Arithmetic operators currently either trap or wrap; buffer sizing needs a recoverable overflow result. + +**Resolved in the STD-1b branch:** spec 16 §2.4 reuses `WriteResult` for copy, adds `FindResult` for substring search, and composes splitting from explicit caller-owned slices. Spec 16 §2.1.1 adds checked add/sub/mul for u64 and target-width usize with ordinary result enums. Wrapping stays with existing operators. No new borrowed aggregate, generic type, AIR instruction or arithmetic mode is introduced. RFC 0018 records this API policy; the owner adopted it with the intermediate std merge (2026-10-07). + +## Q-030 — Strict text/encoding failures and destination state + +UTF-8 needs a scalar-level iteration contract without an owning iterator. Hex/Base64 decoders need a choice between permissive input and one reproducible accepted encoding, plus a defined destination state when a bad byte appears after a valid prefix. Size calculations must not trap before reporting short capacity. + +**Resolved in STD-2a:** spec 16 §2.5–§2.7 define UTF-8 next/validate with explicit offsets, lowercase hex output with case-insensitive ASCII decoding, and canonical padded standard Base64 with checked unused bits. Decoders validate all input before checking output capacity and before writing; invalid input wins over short output and both preserve the entire destination. Capacity guards avoid arithmetic overflow. RFC 0019 records the policy. No streaming state, URL-safe/permissive options, borrowed iterator or allocation is introduced. Formatting remains STD-2b. + +## Q-031 — Minimal formatting and signed limits + +Formatting needs a defined byte representation, insufficient-capacity state and signed-minimum behavior before a library promises arbitrary integer output. A format-string parser or growable writer would add contracts beyond the supplied-buffer milestone. + +**Resolved in the STD-2b branch:** spec 16 §2.8 defines decimal writers for u64/i64 and target-width usize/isize with one ordinary result enum. Complete capacity is checked before mutation, successful counts include the sign, suffixes stay unchanged and no terminator is emitted. Signed minimum is supported without negating it directly. RFC 0020 records the proposal. General formatting, other widths, floats and parsing remain separate work; explicit caller offsets compose records with existing byte copy. + +## Q-032 — Package module resolution and namespace boundaries + +General source modules need explicit build inputs, stable ordering/provenance, local name binding and a choice of import visibility before reusable types can be published. Ambient directory/manifest discovery would make verification depend on environment state; transitive names would make one module's public surface depend on unrelated imports. + +**Resolved on the STD-3 branch (RFC 0021 Implemented):** spec 12 §1.3 supplies an explicit `[modules]` name-to-source map, with bounded no-follow loading inside the chosen package root. Spec 15 §14 specifies an acyclic graph, direct qualified imports, module-local names, qualified struct literals, module-aware spawning, stable mangling and whole-graph verification through existing AIR. All declarations are available through import; aliases, re-exports, visibility modifiers, dependencies and generics remain separate work. File-only commands never discover manifests. + +## Q-033 — Generic specialization and property constraints + +The source plan names monomorphized generics but does not define application syntax, checking of unused templates, specialization bounds or precise Freeze/Local constraints. + +**Resolved on the STD-4 branch (RFC 0022 Implemented):** spec 15 §15 defines explicit `::<...>` expression arguments, applied type names, ordered canonical specializations and concrete-body checking. Copy/Send/Share reuse existing rules; Freeze is format-0 IslandSafe content and Local is context-bound state, with explicit propagation rather than complementing Send. No trait inference or generic runtime representation is added; ordinary aggregate restrictions remain until linear_aggregates. + +## Q-034 — Source calls returning borrows + +During STD-4 validation, existing `from` declarations still return the frontend's unimplemented outcome and borrow bindings accept places rather than borrow-returning calls. Generics preserve the syntax/metadata and this existing limitation; they do not add an implicit lifetime or a new binding spelling. A separate source/lifetime increment must specify and implement the binding/temporary-end rules vertically before public libraries return retained borrowed views. + +## Q-035 — Whole-value linear aggregates + +**Resolved on the STD-5 branch (RFC 0023 Implemented):** spec 03 §25 and source spec 15 §16 specify complete construction/exhaustive consumption, fixed arrays, explicit exchange and ownership-preserving allocation failure. No partial-move/field initialization state or destructor is introduced. Among heap/frame/region storage forms, only individual own may hold linear content; frame locals, repeated heap arrays and bulk regions retain Copy-only content. Dynamic linear buffers need a separately specified extension in the collection phase. + + +## Q-036 — Dynamic initialized linear buffer storage and drain + +STD-5 intentionally enables only complete fixed-size values and individually owned allocation. A growable Vec of resources needs bounded dynamic storage with explicit initialized length, moving extraction, failure-preserving growth and complete drain before freeing. Repeated own.array and bulk region/frame freeing remain Copy-only. STD-6 must specify this storage contract through all layers before publishing Vec, Vec> or a HashMap owning values. Partial holes, implicit destructors or host-only container magic are not an answer. + +**Resolved on STD-6a (RFC 0024 Implemented):** spec 03 §26 uses an initialized contiguous prefix, explicit peak-charged reserve, failure returning pushed values and empty-only free returning the buffer on failure. Views reuse slice provenance and bounds. Safe Vec wrappers are spec 16 §2.10; other collections remain separate work. + +## Q-037 — General hash-map key hashing and equality + +HashMap needs a stable hash/equality pair: equal keys must hash equally, while hash collisions must still compare actual keys. Current Copy/Send/Share/Freeze/Local constraints supply no user operations; type parameters cannot carry callbacks or values (spec 15 §15). Struct/byte-key equality, key ownership and effect-visible callable policies have no general source contract. A hash digest alone cannot represent original-key identity. + +**Resolved on the STD-6d branch (RFCs 0029/0030/0031 Implemented):** spec 15 §18 supplies exact explicit static hash/equality operations; spec 16 §2.14–§2.15 specifies general owning HashMap/HashSet with dense complete entries and Copy probe indices. HashMap> and owning keys pass ordinary ownership/effect/borrow/task rules, independent model traces, source/AIR/profile/package checks and collection-before-every-step/scheduler stress. Numeric U64Map retains its API. No digest identity, inferred policy or map-only compiler primitive is introduced. + +## Q-038 — Pure construction of built-in errors + +STD-6d.2 needs to return allocation-size validation failure without allocating. Existing built-in errors were obtainable only from fallible runtime operations. + +**Resolved (RFC 0027 Implemented):** spec 05 §14 adds feature `error_values` and pure `error.const B.variant`; source reuses `B::variant`. Every registered payload-free error variant is ordinary Copy data, never authority. Existing `enum.make` and runtime outcome rules are unchanged. + +## Q-039 — Explicit static function parameters + +General collections and algorithms need explicit typed hash/equality/order operations, while current generics carry only types. + +**Resolved contract (RFC 0029 Implemented):** spec 15 §18 permits explicitly selected source functions as static parameters with exact typed/effect contracts. Selection is part of nominal specialization identity and lowers to existing named AIR calls/workers. No function pointers, capture environment, inferred effects or runtime dispatch are introduced. Q-037 is resolved by the implemented and verified generic map/set contracts (RFCs 0030/0031). diff --git a/docs/plan/README.md b/docs/plan/README.md index 0c9f7b6..91b5f68 100644 --- a/docs/plan/README.md +++ b/docs/plan/README.md @@ -139,6 +139,10 @@ Targets for Phase 6A, measured on dev tasks: | feature-header diagnostics | 0 (the frontend infers the feature closure) | | safety guarantees | unchanged, because the same AIR is verified | Every Phase 3+ semantic RFC re-measures the Agent Reference Bundle (`docs/agent/README.md`). +## Standard library track + +At the owner’s request (2026-10-06), reusable std APIs were implemented in a separate work branch. On 2026-10-07 the owner requested adoption/merge of the completed STD-0..7 intermediate foundation and resumption of source-language work; Q-034/P6-11 is next. Remaining std milestones stay in the backlog. [Standard library plan](standard-library.md) defines the bootstrap, prerequisites (`linear_aggregates`, general modules and generics), Std 0.1/0.2/0.3 and the public integration gate. P7/P8 remain on hold pending B1 analysis; this track does not change frozen evaluation inputs. + ## Task conventions - IDs are `P-` and never reused. A task split later becomes `P1-4a`, `P1-4b`. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index 7dd954e..dafc0fb 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -132,11 +132,14 @@ Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) a |---|---|---|---|---|---| | P6-1 | todo | Complete the source grammar: expressions, `match`, `borrow` blocks, `task.scope`, `select`, `defer`, `?`, generics, lifetimes, contracts, attributes | — (may start after P2) | `reference/grammar.ebnf`, spec 01 | every construct in `examples/` is covered; grammar is LL(k) or otherwise documented as unambiguous | | P6-2 | todo | Lexer and parser with spans | P6-1 | `src/frontend/{lex,parse}.zig` | all `examples/` parse; syntax errors are registered diagnostics | -| P6-3 | todo | Modules, imports, name resolution | P6-2 | `src/frontend/resolve.zig` | unresolved names produce registered diagnostics | -| P6-4 | todo | Type checking and monomorphized generics with structural constraints (`Copy`, `Send`, `Share`, `Freeze`, `Local`) | P6-3 | `src/frontend/types.zig` | generic code instantiates deterministically; constraint violations diagnosed | +| P6-3 | done (RFC 0021 Implemented) | Explicit package modules, direct imports and qualified nominal types | P6-2 | `src/frontend/modules.zig`, spec 15 §14 | deterministic graph/name resolution; source/AIR and CLI tests | +| P6-4 | done (RFC 0022 Implemented) | Type checking and monomorphized generics with structural constraints (`Copy`, `Send`, `Share`, `Freeze`, `Local`) | P6-3 | `src/frontend/generics.zig`, spec 15 §15 | generic code instantiates deterministically; constraint violations diagnosed | | P6-5 | todo | Lowering to AIR: control flow, `?`, `defer` cleanup edges, borrow blocks, task scopes | P6-4 | `src/frontend/lower.zig` | lowered AIR verifies; lowering is a pure function (same input ⇒ same AIR bytes) | | P6-6 | todo | Contracts: `requires`/`ensures`/invariants → contract table; status classification | P6-5 | frontend + verifier | each contract reported as PROVEN_STATICALLY / CHECKED_AT_RUNTIME / ASSUMED_UNSAFE / UNPROVEN | | P6-7 | todo | Source spans in diagnostics for verifier errors on lowered AIR | P6-5 | `src/diag.zig`, lowering | every conformance reject test has a source-level twin with the same code | | P6-8 | todo | Formatter | P6-2 | `aji fmt` | idempotent; output parses to the same AST | | P6-9 | todo | Port reference programs and examples to `.aji` | P6-5 | `tests/programs/`, `examples/` | exit criterion passes | +| P6-11 | todo | Source functions/calls returning borrows with explicit `from` origin; Q-034 | P6-3/4 | spec 15, binding/call/return lowering, Quick Reference and source/AIR conformance | origin/lifetime and temporary-end rules specified; valid/rejected returned views use existing verifier/interpreter semantics | | P6-10 | todo | Phase exit review | all | plan status | exit criterion passes | + +The [standard-library track](standard-library.md) implements nineteen compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 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. 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 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 after the explicit error_values prerequisite (RFC 0027). STD-6d.3/RFC 0029 adds explicit static function parameters for general hash/equality/order operations with existing AIR calls/workers. STD-6d.4/RFC 0030 implements the general owning-key std.hashmap contract; its full GC/stress validation passes and Q-037 is resolved. STD-6d.5/RFC 0031 implements general owning std.hashset with duplicate input return; its conformance, GC/schedule, CLI and documentation checks pass. STD-6d.6/RFC 0032 implements safe owning std.heap with explicit order; conformance, GC/schedule, CLI and documentation checks pass. STD-7a/RFC 0033 implements bounded std.io composition with explicit progress, resource loans and exact effects; conformance, GC/schedule, CLI and documentation checks pass. STD-7b/RFC 0034 implements safe owning buffered file adapters with explicit finish/discard and first-error/no-retry behavior; conformance, GC/schedule, CLI and documentation checks pass. STD-7c/RFC 0035 adds pure caller-buffer lexical paths and Copy component ranges; conformance, GC/schedule, CLI and documentation checks pass. The owner adopts STD-0..7 as an intermediate foundation and resumes language work (2026-10-07); remaining std system/service milestones stay in the backlog. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6. diff --git a/docs/plan/standard-library.md b/docs/plan/standard-library.md new file mode 100644 index 0000000..7f72cfd --- /dev/null +++ b/docs/plan/standard-library.md @@ -0,0 +1,196 @@ +# Standard library implementation plan + +Non-normative. Started on `feat/std-bootstrap`, 2026-10-06, at the owner's request. Normative contracts live in spec 16 and the relevant source/runtime specifications. The owner requested an intermediate STD-0..7 merge on 2026-10-07 and a return to source-language work; remaining std work stays in the backlog. P7/P8 remain on hold for B1 analysis. B1 frozen inputs and private held-out tasks do not guide API design and MUST NOT be inspected or changed by this work. + +## Target and design constraints + +Without external source dependencies, Aji should support ordinary CLI tools, storage components, network services and structured concurrent programs. The mandatory semantic surface stays small. + +- Prefer safe `.aji` over new AIR opcodes or opaque runtime implementations. +- One canonical API for a common operation; effects, borrows, moves, failure and allocation budgets remain visible. +- Caller-provided slices first; owning/growing buffers request `cap` and expose failure and explicit consumption. +- Separate features (implementation support), effects (behavior) and capabilities (authority). Importing a module grants none. +- Avoid a broad trait hierarchy. Begin with concrete adapters; add abstractions only when they reduce contracts and repair work. +- Library functions use the existing verifier. A trusted crypto/TLS boundary is a separate audited dependency with a deterministic-profile model. Do not implement homemade cryptography. +- Runtime capabilities and primitive coverage must be specified through every layer before a wrapper promises them. No implicit cleanup, detached tasks, reflection or ambient environment access. + +## Current prerequisites + +| Capability | Current state | Consequence | +|---|---|---| +| Scalars, structs/enums, slices/arrays, explicit borrows | implemented | pure fixed-storage algorithms can start now | +| Heap/regions, I/O, files, TCP, clock/random, structured tasks/channels/mutex | implemented primitives | wrappers can reuse them, but their presence does not imply the complete APIs below | +| Built-in standard imports and enum types | STD-0/1a/2a/2b implementation | compiler-pinned, closed registry; nineteen modules; qualified enum types/constructors/patterns; no package lookup | +| General modules/imported struct literals | STD-3 implementation (P6-3; RFC Implemented) | explicit manifest mapping, direct qualified names, ordinary verifier | +| User generics/structural constraints | STD-4 implementation (P6-4; RFC Implemented) | needed for reusable `Vec`, `HashMap`, option/result | +| `linear_aggregates` | STD-5 implementation (RFC Implemented) | whole-value owning structs/enums/fixed arrays; initialized buffer/std.vec implemented by STD-6a/b | +| Extended filesystem, IPv6/DNS, args/env, TLS/crypto | not promised by current runtime | audit each primitive, authority, error and profile model before implementation | + +A `Vec` prototype is not completion of `Vec`. The collection gate requires valid and rejected examples for `Vec`, `HashMap>` and `Vec>`, plus cleanup and failure paths. No linked list is planned. + +## Milestones + +| Milestone | Deliverable | Exit criterion | +|---|---|---| +| Bootstrap | `std.math`, `std.bytes`, compiler-pinned import, normative API, source tests and bundle entry | all functions lower to existing AIR, verify and run; bad calls/aliases reject; import order does not affect canonical AIR; no hidden allocations or authority | +| Intermediate foundation — STD-0..7 | nineteen pinned modules, explicit owning collections, bytes/text/formatting/encodings, bounded and buffered I/O, lexical paths | module contracts, failure/ownership, GC/schedule and source/AIR/profile/package gates pass; adopted for continuing language development | +| Std 0.1 — system utilities | core bytes/math/mem/slice/hash, option/result, buffer and owning collections, UTF-8/fmt, hex/base64, small I/O/fs/path/time/random/log APIs | a CLI and bounded storage utility written in `.aji` use only std, explicit grants, documented failure/cleanup and deterministic fixture tests | +| Integration gate | public, independently chosen 5–10k LOC application | ownership, cancellation, bounded memory and error cleanup work together; API/documentation costs recorded; defects become general repairs | +| Std 0.2 — network services | TCP, IPv4/IPv6, DNS, task/channel helpers, JSON DOM, URI, bounded HTTP/1.1 | a local concurrent JSON/HTTP service passes deterministic fixtures and hosted smoke tests without external source packages | +| Std 0.3 — internet services | audited secure random, SHA-256/SHA-512/HMAC/constant-time compare, TLS client/server, complete HTTP client/server and buffered I/O | verified caller contracts, audited trusted boundary, certificate validation, explicit network authority, bounded buffers and deterministic failure fixtures | + +**CLI args/env move before the Std 0.1 exit**, rather than waiting for Std 0.3: they are required by the CLI target. Their capabilities and startup contracts need a vertical feature. Secure entropy is distinct from deterministic test randomness. Typed JSON schema generation waits for an independently justified compile-time facility; the DOM comes first. + +SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protobuf, GUI, templating, regex and broad compression suites remain package-ecosystem work. TLS may initially depend on a vetted host crypto library; “no external source dependencies for callers” does not mean “no trusted native dependency.” + +## Tasks + +| ID | Status | Work | Depends | Done when | +|---|---|---|---|---| +| STD-0 | done (RFC Implemented) | bootstrap spec, source std, closed imports, conformance, documentation and complexity measurement | existing source frontend | bootstrap exit criterion above and required repository checks pass | +| STD-1a | done (RFC Implemented) | endian u16/u32/u64 and qualified standard enum results | STD-0 | recoverable short-input/output failure, no partial mutation; all short lengths, empty/maximal values, fixtures and rejected alias examples pass | +| STD-1b | done (RFC Implemented) | bounded copy/search, split composition and recoverable arithmetic for u64/usize | STD-1a | contracts define capacity/overflow failure, no partial mutation, empty inputs and aliasing; independent fixtures pass | +| STD-2a | done (RFC Implemented) | UTF-8 next/validate and supplied-buffer hex/base64 | STD-1a/1b | malformed text and insufficient capacity are explicit, output unchanged on returned errors; independent vectors and boundary cases pass | +| STD-2b | done (RFC Implemented) | decimal u64/i64/usize/isize formatting into supplied buffers | STD-2a | minimal explicit format contract, no implicit heap, capacity/empty/maximal scalar tests and caller example | +| STD-3 | done (RFC Implemented) | general modules and imported type names (P6-3) | STD-0 | deterministic resolution, collisions/cycles and diagnostics specified and covered | +| STD-4 | done (RFC Implemented) | source generics (P6-4), constraints and option/result | STD-3 | deterministic specialization and rejected constraint examples; source/AIR budgets measured | +| STD-5 | done (RFC Implemented) | independent whole-value `linear_aggregates` RFC and vertical implementation phase | STD-3/4 for its source surface | spec → AIR → verifier → interpreter → source/lowering → Quick Reference → AIR/source tests; linear elements consumed on every path | +| STD-6a | done (RFC 0024 Implemented) | dynamic initialized buffer 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 (RFC 0024 Implemented) | 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 (RFC 0025 Implemented) | 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 | done (RFCs Implemented) | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap>, recoverable failures and explicit draining | +| STD-6d.1 | done (RFC 0026 Implemented) | 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 (RFC 0027 Implemented) | pure built-in error construction prerequisite | STD-6d.1 | vertical error_values feature, no authority/effect/resource changes; preflight allocation validation | +| STD-6d.2 | done (numeric-key implementation; RFC 0028 Implemented) | U64Map first; general HashMap key policy Q-037 | STD-6d.1 | safe map with ownership/failure/collision tests and error_values prerequisite (RFC 0027); general-key gate resolved by STD-6d.4/5 | +| STD-6d.3 | done (RFC 0029 Implemented) | explicit static hash/equality/order functions | STD-4 | exact callable contracts, ordinary AIR calls/workers and nominal operation identity; general collections remain required | +| STD-6d.4 | done (RFC 0030 Implemented) | general owning HashMap | STD-6d.3 | dense complete entries, Copy probe indices, exact equality and returned key/value ownership | +| STD-6d.5 | done (RFC 0031 Implemented) | general owning HashSet | STD-6d.4 | exact membership, duplicate/full input ownership, moving extraction and empty-only free | +| STD-6d.6 | done (RFC 0032 Implemented) | owning BinaryHeap | STD-6a/6d.3 | explicit pure order, complete resource extraction, bounded push, failure-preserving growth | +| STD-7 | done (intermediate foundation) | 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-7a | done (RFC 0033 Implemented) | exact/bounded reads and limited file copies | STD-1b/3 | explicit progress/EOF/error, borrowed resources, caller slices and exact effects | +| STD-7b | done (RFC 0034 Implemented) | owning buffered concrete file reader/writer | STD-6a/7a | failure ownership, refill/flush, explicit finish/discard and no hidden cleanup | +| STD-7c | done (RFC 0035 Implemented) | caller-buffer lexical paths | STD-1b/2a | pure normalization/join/components with no 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 | +| STD-10 | todo | IPv4/IPv6/TCP/DNS contracts and runtime gaps; task/channel helpers | STD-9 | bounded service fixtures, deterministic scheduling and schedule stress pass | +| STD-11 | todo | JSON DOM, URI and bounded HTTP/1.1 | STD-6/10 | depth/size/header/body limits, malformed-input errors, streaming/EOF and cleanup tests | +| STD-12 | todo | vetted crypto backend and TLS vertical RFC | STD-10/11 | explicit trusted dependency, certificate/trust/entropy inputs, audit and deterministic model | +| STD-13 | todo | HTTP client/server integration and Std 0.3 review | STD-12 | internet-service exit criterion | + +Each task can be split into reviewable increments; only executable exit criteria mark it done. The intermediate foundation is complete; the remaining system and service milestones are backlog work. P7 is reconsidered after B1 analysis and the integration gate; this plan does not unilaterally reopen it. + +## API review and Model Capability Compression + +For each increment record public signatures, conceptual additions, syntax forms, diagnostics, required verifier state, allocations/budgets and cleanup obligations. Run `zig build agent-reference` and `tools/agent_bundle_tokens.py --source`; report Quick Reference and Source Reference Bundle growth by group. Library reference pages are read on demand. + +Use general public use cases and fixtures to measure documentation read, output size, verifier failures, repair cycles and ownership visibility. Performance and allocations also matter, but an API with five overlapping forms needs evidence. No language/API design decision is made from tasks M/C or the private corpus, and no compression benefit is claimed before measurement. + +## Bootstrap verification + +Required: `zig build`, `zig build test`, `zig build conformance`, `zig fmt --check build.zig build.zig.zon src tools tests/extended`, `python3 tools/source_coverage.py`, and `zig build agent-reference`. Because imported code reaches the ordinary CLI, also run `python3 tests/hosted/smoke.py`. Run tests use fuel, never wall-clock termination. + +The bootstrap does not add ownership or concurrency semantics. Preserved invariant: shared slices only read, exclusive slices only write, no borrow escapes or resource is consumed. Existing borrow/bounds transfer functions and interpreter rules apply; valid and rejected source fixtures exercise that boundary. Existing `E7001`, `E7002`, `E7005`, `E7006`, `E2101`, `T0002` suffice. AIR format 0 remains unchanged and existing programs without imports lower identically. + +Bootstrap result: nine APIs implemented; full conformance, unit/Quick Reference, formatting and source coverage checks pass. Hosted file/stdin/TCP smoke tests and evaluation harness self-tests pass (22 tests; one environment-dependent skip). The documented example returns 42 with no grants; invalid clamp bounds report `std/math.aji:20`. RFC 0016 remains Proposed for owner review. Token growth (cl100k): Quick Reference +4.8%; source bundle excluding AIR +6.6%; AIR unchanged. + +## STD-1a verification + +Twelve additional endian functions and four ordinary Copy enums lower to existing AIR. The invariant remains: no access outside the supplied slice, no escaping borrow, no hidden allocation, and no mutation on insufficient output capacity. The capacity branch precedes every access. Existing verifier/interpreter rules and diagnostics apply; valid/rejected source examples and hand-written AIR fixtures exercise payload typing and read behavior. AIR format 0 is unchanged. Qualified standard enum names implement only a closed-registry subset of STD-3; user modules, imported struct literals, dependencies and generics remain open. + +Run the same required checks as bootstrap. Endian fixtures include independent LE/BE byte vectors, every short length, zero/maximal values, every bit, nonzero offsets, extra input/output bytes, returned enum records, compound types, name collisions, exhaustive matches and forbidden mutable aliasing. RFC 0017 records final checks and complexity measurements. + +## STD-1b verification + +Eight further pure functions reuse existing primitives: `std.bytes.copy` and `find_slice`, plus checked add/sub/mul for `u64` and `usize`. Copy reuses `WriteResult`; three additional ordinary Copy enums represent substring matches and arithmetic results. Wrapping remains an operator. Splitting composes a search with explicit caller-bounded slice operations; no borrowed aggregate, iterator, cursor, compiler/runtime change or hidden allocation is added. + +The preserved invariant is shared-read/exclusive-write access only within the supplied slices, no escaping borrows and no mutation on short output. Existing verifier/call/alias/enum rules and interpreter behavior suffice. Valid/rejected source fixtures and hand-written AIR twins cover the contracts; current diagnostics and AIR format 0 are unchanged. Tests include all 81 input/output length pairs through eight, disjoint split borrows, overlapping and empty short-output aliases, 428 search cases, seven split cases and 320 independently computed arithmetic operand pairs exercised through both widths. The interpreter's numeric vectors use its default `air64`; library usize limits are computed with target-width wrapping subtraction. RFC 0018 records the final repository checks and complexity measurements. STD-2 can now start with UTF-8 and supplied-buffer encodings. + +## STD-2a verification + +Six functions and six ordinary result enums add UTF-8 next/validate and supplied-buffer hex/Base64 to the closed registry. UTF-8 returns a scalar plus consumed bytes; caller offsets carry iteration state. Hex accepts both ASCII letter cases and emits lowercase; Base64 accepts canonical padded standard text with zero unused bits. Decode validates all input before capacity/mutation, so malformed input wins over insufficient output and every returned error preserves the destination. Size guards avoid intermediate overflow. + +All algorithms are safe source using existing verifier/runtime rules, fixed frame storage and explicit slice borrows. No borrow escapes, owner/resource is consumed, heap allocation is hidden, AIR meaning changes or authority is granted. Valid/rejected examples, stable existing diagnostics, deterministic interpreter tests and compatibility are specified in spec 16 §2.5–§2.7 and RFC 0019. The registry embeds three additional modules without a resolver or dependency extension. Tests cover independent Python scalar/byte vectors, UTF-8 boundaries/truncation/surrogates, all input byte values, canonical pad bits, every relevant capacity, late invalid bytes, output suffixes, disjoint same-allocation buffers, namespace collisions and hand-written AIR equivalence. Formatting remains STD-2b; this increment does not mark the original whole text/formatting task complete. + +## STD-2b verification + +Four safe decimal writers and one ordinary result enum complete the supplied-buffer formatting increment. No heap, retained cursor, format-string language, runtime primitive or syntax is added. Counts include a negative sign, suffixes remain unchanged and insufficient capacity preserves the complete destination. Counting precedes mutation; signed magnitude uses `-(value + 1)` then an unsigned increment, avoiding signed-minimum negation. Explicit caller offsets and `std.bytes.copy` compose a record; failure preserves the individual call's destination, not earlier successful calls. + +Spec 16 §2.8 and RFC 0020 specify the invariant, existing verifier/runtime rules, valid/rejected examples, diagnostic impact, deterministic execution and unchanged AIR format 0. Independent Python decimal vectors exercise zero, all small values, decimal/binary transitions, seeded scalar inputs, both 64-bit limits and every capacity from zero through 22, checking all guard/suffix bytes. Target-width fixtures guard conversions against the target limits; the current interpreter executes at air64. Source/AIR result equivalence, explicit record composition, disjoint borrows, qualified types/collisions and rejection of conflicting borrows (including short output), missing imports, invalid payloads/types and incomplete matches cover the public boundary. RFC 0020 records required checks and source/AIR documentation budgets. Next semantic prerequisites for owning buffers and containers remain STD-3/4/5; a decimal writer does not complete general formatting or owning strings. + +## STD-3 verification + +P6-3 now links explicit package sources through the same frontend as compiler-pinned std. Manifest mappings supply source bytes; pure linking checks an acyclic graph, module identity and direct-import visibility, then emits collision-free deterministic AIR. Imported functions, structs, enums and qualified task workers use existing ownership, lifetime, effect and scheduler rules. Check/lower/report instantiate no grants; run/explore use explicit manifest grants and overrides. Package sources have portable bounded paths, no symlink traversal and a 64 MiB aggregate source budget; file-only commands never discover manifests. + +RFC 0021 records invariants, diagnostics, compatibility, complete validation and documentation growth. General modules and imported struct literals are implemented on this branch; dependencies and external package resolution are separate work. The next semantic step is STD-4/P6-4 generics and structural constraints, followed by the independent linear-aggregate gate. Owning collections still require both gates. + +## STD-4 verification + +Explicit function/struct/enum generics specialize deterministically to ordinary AIR. Structural Copy/Send/Share/Freeze/Local constraints, header checking, nominal identity, direct-import visibility and fixed expansion limits are specified by spec 15 §15 and RFC 0022. Every concrete specialization passes ordinary ownership/effect/task verification; unused bodies make no validity promise for future types. The compiler registry adds safe Copy-only std.option/std.result with classification helpers. No allocation, implicit cleanup, AIR opcode or authority is added. + +The finite-layout E1003 check now traverses arrays, repairing a prior verifier gap with source/AIR fixtures. Existing source `from`-returns remain unimplemented and are logged as Q-034 rather than given an invented lifetime/binding contract. RFC 0022 records complete validation and source/AIR budget measurements. Next is STD-5: the independent linear_aggregates vertical feature, required before containers or option/result can own resources. P6-4's generic/structural specialization task is implemented on this branch; this does not complete Phase 6. + + +## STD-5 verification + +RFC 0023 and spec 03 §25 implement whole-value linear structs/enums/fixed arrays vertically. Construction consumes nested owners; complete unpack, exhaustive match move, explicit exchange and own.pack failure preserve ownership on every normal path. Standard option/result accept owning payloads; observational classification helpers keep Copy constraints. Existing availability, alias/task-loan, Send/Share, budget and scheduler rules apply without per-field holes or hidden cleanup. No new diagnostic/effect/capability is introduced. + +Source/AIR tests cover nested ownership, allocation success/failure, repeated exchange with a one-owner budget, enum replacement, borrowed fixed arrays, channels, tasks, mutexes, regions, atomics and rejected copies/leaks/aliases/recursive ownership. The interpreter preserves borrowed SSA identity across whole replacement and collection; individual own> is distinguished from a repeated own_array allocation. RFC 0023 records final checks and documentation budgets. STD-6 starts with Q-036: dynamic storage, initialized length and explicit drain must be specified before growing resource collections. STD-5 does not complete Vec or Std 0.1. + +## STD-6a/b/c verification + +Initialized buffer and safe Vec/Deque use existing ownership/borrow/task rules and deterministic allocation budgets. Deque is ordinary library source: Option represents vacancy, both ends exchange complete elements, and explicit growth rotates a ring only after allocation succeeds. Nonempty free returns the queue, so no library action closes user resources. Slot charges include Option's enum tag. Ordinary visible representation fields have a documented invariant, with no unsafe bypass. + +RFC 0024 records storage/Vec validation. RFC 0025 records the deque API/budget measurements and validation: independent Python deque traces, all small head/length combinations under growth, wrapped owners, files/senders/workers, failure/cleanup and borrow/constraint rejections. Maps/sets/heaps are STD-6d; this increment does not complete Std 0.1. + +## 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 design](../design/hash-map.md) specifies numeric-key U64Map, 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 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 is now resolved by STD-6d.4/5; general HashMap>/HashSet and BinaryHeap validation are recorded below. + + +## General operation-selection prerequisite + +STD-6d.3/RFC 0029 implements explicitly bound static functions with exact typed/effect contracts, forwarding, generic function arguments, nominal operation identity and named workers. It reuses ordinary AIR and preserves direct-import visibility, capability inputs, ownership and task loans. Source/AIR positives/rejections, recursive/cyclic contracts, GC/scheduler stress, CLI/profile/provenance checks and documentation budgets are recorded in the RFC. General HashMap/HashSet storage/API subsequently resolves Q-037, and BinaryHeap completes STD-6d; STD-7 remains required. + + +## General owning set verification + +STD-6d.5/RFC 0031 implements safe HashSet over the general map, with nine explicit operations. Duplicate insertion preserves every stored entry/bucket and returns the exact incoming key, including its resources; full does likewise for new keys. Remove/pop transfer complete stored keys, and nonempty free returns the whole set. Allocation, failure rollback, peak/refund accounting and dense pop order follow the map. No new language syntax, verifier/runtime state, diagnostic, AIR feature or trusted boundary is added. + +All 973 conformance cases pass, including 26 set cases. Runtime fixtures pass collection before every instruction; the shared lookup fixture passes 12 seeds under quanta 1, 2, 7 and its own quantum. Independent Python set/representative oracles cover 80 operations across Copy/owning traces and check membership after each operation. Byte-buffer/file keys, exact duplicate-table preservation, returned owners, allocation failure/refunds/peaks and rejected leaks/moves/aliases/loans/policies/non-Share contents are covered. Unit/Quick Reference, formatting, hosted smoke, 53 CLI/profile/package/source/AIR checks, 106/106 source coverage constructs and bundle generation pass. RFC 0031 records documentation growth. The separate general-map full GC/stress process subsequently completed with all 33 cases passing. BinaryHeap validation follows below; STD-7 I/O/path is next. + + +## Owning binary heap verification + +STD-6d.6/RFC 0032 implements eight safe std.heap operations with an exact explicit pure ordering function. Copy-index sifting preserves complete owners in dense initialized storage; moving pop repairs dense holes. Full push returns its input without callbacks, nonempty free returns the heap, and explicit reserve preserves values/layout/extraction order on every returned allocation failure. No new source/AIR semantics, diagnostics, verifier/runtime state or trusted boundary are added. + +All 1007 conformance cases pass, including 34 heap fixtures. Heap runtime fixtures pass collection before every instruction; shared lookup, sender ownership transfer and restored task loans run 12 schedule seeds under quanta 1, 2, 7 and their own quantum. Independent heapq traces cover 160 operations over min/Copy and max/owning records, plus all 120 permutations of five values. Direct owners, owning byte buffers, files, sender endpoints, duplicates, empty/full/overflow, exact layout preservation under both reserve-failure phases, peaks/refunds/cross-authority accounting and rejected leaks/Copy/aliases/loans/policy/effects are covered. Unit/Quick Reference, formatting, hosted smoke, 70 CLI/source/AIR/package/profile/provenance checks, 109/109 source coverage constructs and bundle generation pass. RFC 0032 records documentation growth. + +The long general-map GC/stress process also completed with 33/33; Q-037 and the collection gate STD-6d are resolved on this branch. I/O and lexical paths are STD-7; filesystem gaps, args/env and logs remain STD-8. This does not complete Std 0.1 or reopen the native backend phase. + + +## Bounded I/O foundation verification + +STD-7a/RFC 0033 implements six safe std.io compositions with concrete io.read/fs.read/net.read/fs.write effects, borrowed resources and caller-supplied slices. Exact reads distinguish completed data, EOF and read errors. Bounded read-to-end/copy stop at capacity/limit without consuming an extra byte to probe EOF. Copy errors distinguish confirmed reads from confirmed writes; external partial writes have no rollback promise. No heap, retained borrow, open/close, task/timeout, new syntax/AIR semantics, verifier state or diagnostic is added. + +All 1027 conformance cases pass, including 20 I/O cases. All runtime I/O fixtures pass collection before every instruction; fragmented TCP and restored task loans run 12 schedule seeds under quanta 1, 2, 7 and their own quantum. An independent Python prefix oracle covers 162 exact/bounded reads and 250 copy/append combinations, validating bytes, guards, counts, source cursor tails, limits and empty scratch. Hosted tests produce a real read error and partial external file write: four bytes consumed, two confirmed written, three actually present. Unit/Quick Reference, formatting, hosted smoke, 55 CLI/source/AIR/package/import-order/profile/provenance checks, 111/111 source coverage constructs and bundle generation pass. RFC 0033 records documentation growth. Owning buffered adapters STD-7b and lexical paths STD-7c remain required; STD-7 and Std 0.1 are unfinished. + + +## Owning buffered file verification + +STD-7b/RFC 0034 implements safe std.io.reader/std.io.writer, each owning a file and a fixed-capacity initialized byte buffer. Only new allocates with explicit authority and failure returns the original file. Reads distinguish cached data/refill/EOF and finish returns unread readers. Writer errors preserve pending bytes and the first error, forbid further writes/retries, and return the whole failed writer from finish. Explicit discard reports abandoned cached/pending bytes, frees storage and returns the file. No file open/close/sync, hidden growth/cleanup or new syntax/AIR/runtime/verifier state is added. + +All 1061 conformance cases pass, including 34 buffered adapter fixtures. Every buffered fixture passes collection before every instruction; worker transfer and restored loans run 12 seeds under quanta 1, 2, 7 and their own quantum. Independent byte oracles cover 48 read streams, 64 exact prefixes and 96 segmented writes. On Linux, 89 CLI/source/AIR/package/profile/provenance checks include a real read fault and four external partial-write cases; raising the child's file quota after failure proves the writer still performs no retry and preserves pending bytes/error. Unit/Quick Reference, formatting, hosted smoke, 115/115 source coverage constructs and reference generation pass. RFC 0034 records documentation growth. Lexical paths STD-7c, system gaps STD-8 and the Std 0.1 exit examples remain required; the full std roadmap is unfinished. + + +## Caller-buffer lexical path verification + +STD-7c/RFC 0035 implements six pure std.path operations: raw component queries return bounded Copy ranges; normalize/join write into caller-provided storage with no heap or authority. NUL/size/capacity errors preserve the entire output. Reverse measurement/emission retains relative unmatched parents, drops parents above root, and needs only the final normalized capacity. Filesystem operations still enforce their independent path/grant rules. + +All 1079 conformance cases pass, including 18 path fixtures. All path runtime fixtures pass collection before every instruction; shared reads and restored output loans pass 12 seeds under quanta 1, 2, 7 and their own quantum. An independent Python forward-stack oracle covers 132 paths with raw queries/idempotence and every short/exact/extra capacity, 49 joins and four malformed pairs; separate fixtures cover all 255 non-NUL bytes, disjoint slices, one-byte canceled results, late malformed input, guards/suffixes and T0008 for reused ranges. The model uses bounded batches with separate literal frames, preserving all vectors and capacities. Linux CLI/source/AIR/package/profile/provenance/audit/authority checks pass (68); all fourteen preceding std/source CLI suites pass again. Unit/Quick Reference, formatting, hosted smoke, 117/117 source construct coverage and reference generation pass. RFC 0035 records documentation growth. STD-7 and the intermediate foundation are complete; STD-8, the full Std 0.1 exit and later service milestones remain unfinished. + + +## Intermediate adoption (owner decision, 2026-10-07) + +The owner requested a sufficient intermediate std stage, integration of the work branch and resumption of language development. STD-0 through STD-7 provide nineteen compiler-pinned safe source modules: math/bytes/hash, UTF-8/hex/Base64/formatting, option/result, Vec/Deque/U64Map/general HashMap/HashSet/BinaryHeap, bounded std.io, owning buffered file adapters and lexical paths. The branch also supplies explicit modules/generics, whole-value linear aggregates/initialized buffers, pure error values and exact static callable contracts, through source/AIR/verifier/interpreter and tests where applicable. RFCs 0016–0035 are adopted and implemented; their rules are integrated into spec/reference in the same merged change. + +This intermediate gate is sufficient to resume language work. It does not mark Std 0.1 complete: filesystem gaps, args/env, time/random wrappers, structured logs and CLI/storage exit examples remain STD-8; the public 5–10k LOC integration gate and network/JSON/HTTP/TLS milestones remain in the backlog. Frozen evaluation inputs and the private held-out corpus are untouched. Next source-language work is Q-034/P6-11 (explicit borrowed-return calls/bindings); P7/P8 retain their existing gate. diff --git a/docs/reference/air-features.md b/docs/reference/air-features.md index df47dbc..de92bbb 100644 --- a/docs/reference/air-features.md +++ b/docs/reference/air-features.md @@ -39,10 +39,12 @@ Declaring `features [capabilities, effects, ownership]` grants no authority. It | `channel_transfer` | reserved | — | `cancellation`, `capabilities`, `channels`, `effects`, `heap`, `ownership`, `resources`, `tasks` | endpoints inside channel elements or mutex contents; unscheduled | | `channels` | published | 3 | `cancellation`, `capabilities`, `effects`, `heap`, `ownership`, `resources`, `tasks` | `sender`, `receiver`, `channel.*`, `select` (spec 04 §38–§39) | | `effects` | published | 2 | — | flat effect checking of `effects [...]` for `call` and `intrinsic` (E3101, spec 05 §9) | +| `error_values` | published | 6 | `capabilities`, `effects`, `heap`, `ownership`, `resources` | pure construction of registered built-in errors with `error.const`; errors confer no authority (spec 05 §14) | | `guard_transfer` | reserved | — | `cancellation`, `effects`, `ownership`, `sync`, `tasks` | `guard` as parameter, return type or aggregate member; unscheduled | | `heap` | published | 2 | `capabilities`, `effects`, `ownership`, `resources` | `own`, `own_array`, `own.*`, built-in `alloc_error`, `mem.alloc` budgets and `budget` narrowing (spec 03 §18–§19) | | `islands` | published | 4 | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `island`, `frozen`, `iref`, `island.*`, `frozen.*`, `iref.eq`, `IslandSafe`, `T0010` (spec 03 §22–§23) | -| `linear_aggregates` | reserved | — | `capabilities`, `effects`, `ownership`, `resources` | resource types as struct fields, enum payloads and array elements; unscheduled | +| `linear_aggregates` | published | 6 | `capabilities`, `effects`, `ownership`, `resources` | whole-value linear structs/enums/fixed arrays, unpack/take/swap and ownership-preserving own.pack; spec 03 §25 | +| `linear_buffers` | published | 6 | `arrays`, `capabilities`, `effects`, `heap`, `linear_aggregates`, `ownership`, `resources` | initialized prefix buffer, explicit growth/push/pop/view/empty-only free; spec 03 §26 | | `ownership` | published | 1 | — | frame storage `local`, second-class borrows `ref`/`mut`, `from` returns, initialization (spec 07 §8.8, spec 07a, spec 08 §11, §13) | | `receiver_dup` | reserved | — | `cancellation`, `capabilities`, `channels`, `effects`, `heap`, `ownership`, `resources`, `tasks` | several receivers of one channel (MPMC); unscheduled | | `regions` | published | 2 | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `region`, `region.*`, static generations (spec 03 §20) | diff --git a/docs/reference/air-text.ebnf b/docs/reference/air-text.ebnf index f1276f9..9b4c216 100644 --- a/docs/reference/air-text.ebnf +++ b/docs/reference/air-text.ebnf @@ -57,6 +57,7 @@ instruction = [ local { "," local } "=" ] operation ; operation = "const." int_type int_lit | "const.bool" ( "true" | "false" ) + | "error.const" ( "alloc_error" | "cap_error" | "io_error" ) "." ident (* feature error_values; no payload *) | "copy" local | arith_op local "," local | "assert" local @@ -65,6 +66,7 @@ operation = "const." int_type int_lit | "struct.get" global "." ident "," local | "enum.make" global "." ident "(" [ local_list ] ")" | "call" global "(" [ local_list ] ")" + | linear_aggregate_op | ownership_op | arrays_op | capability_op @@ -117,6 +119,11 @@ capability_op = "cap.narrow." ident local { "," local } ok_err (* te (* Feature heap (spec 03 §18–§19). *) heap_op = "own.new" local "," local ok_err (* terminator: value, cap *) + | "buffer.new" type local "," local ok_err + | ( "buffer.len" | "buffer.capacity" | "buffer.view" ) local + | "buffer.reserve" local "," local "," local ok_err + | "buffer.push" local "," local ok_err + | ( "buffer.pop" | "buffer.free" ) local ok_err | "own.array" local "," local "," local ok_err (* terminator: count, element, cap *) | "own.take" local | "own.free" local ; @@ -210,6 +217,7 @@ type = int_type | "bool" | "void" | "never" | global | "cap" "<" path ">" (* feature capabilities; a capability kind, e.g. cap *) | "file" "<" ( "read" | "write" | "append" ) ">" (* feature resources *) | "listener" | "stream" (* feature resources *) + | "buffer" "<" type ">" (* feature linear_buffers *) | ( "own" | "own_array" ) "<" type ">" (* feature heap *) | "region" (* feature regions *) | "scope" | "task" "<" type ">" (* feature tasks *) @@ -240,3 +248,11 @@ int_lit = [ "-" ] ( dec_digits | "0x" hex_digits | "0b" bin_digits ) ; (* "_" may separate digits; it carries no meaning. *) version_lit = digit { digit } "." digit { digit } ; string = '"' { string_char | '\\"' | '\\\\' | '\\n' } '"' ; (* not empty; only in `trusted` *) + +(* Feature linear_aggregates, spec 03 §25 and spec 07a. *) +linear_aggregate_op = "array.make" type "(" [ local_list ] ")" + | "struct.unpack" global local "," "next" "->" global + | "array.unpack" type local "," "next" "->" global + | "enum.take" global local "," enum_arm { "," enum_arm } + | "value.swap" local "," local + | "own.pack" type local "," local ok_err ; diff --git a/docs/reference/grammar.ebnf b/docs/reference/grammar.ebnf index 3dc3496..cf9d492 100644 --- a/docs/reference/grammar.ebnf +++ b/docs/reference/grammar.ebnf @@ -12,29 +12,39 @@ - Every construct has one canonical spelling (spec 15 §1). *) -module = "module" path { item } ; +module = "module" path { module_import } { item } ; +module_import = "import" path ";" ; (* contextual word, spec 15 §13/§14 *) item = type_decl | fn_decl ; path = ident { "." ident } ; type_decl = struct_decl | enum_decl ; -struct_decl = "struct" ident "{" [ field { "," field } [ "," ] ] "}" ; +struct_decl = "struct" ident [ type_params ] "{" [ field { "," field } [ "," ] ] "}" ; field = ident ":" type ; -enum_decl = "enum" ident "{" variant { "," variant } [ "," ] "}" ; +enum_decl = "enum" ident [ type_params ] "{" variant { "," variant } [ "," ] "}" ; variant = ident [ "(" type { "," type } ")" ] ; -fn_decl = "fn" ident "(" [ param { "," param } ] ")" "->" type [ "from" ident ] +fn_decl = "fn" ident [ type_params ] "(" [ param { "," param } ] ")" "->" type [ "from" ident ] "effects" "[" [ path { "," path } ] "]" block ; (* `trusted` is reserved and rejected, E7006 *) param = ident ":" type ; +type_params = "<" type_param { "," type_param } ">" ; +type_param = ident [ ":" ( property { "+" property } | function_contract ) ] ; +function_contract = "fn" "(" [ type { "," type } ] ")" "->" type + "effects" "[" [ path { "," path } ] "]" ; +property = "Copy" | "Send" | "Share" | "Freeze" | "Local" ; +type_args = "<" generic_arg { "," generic_arg } ">" ; +generic_arg = type | "fn" path [ application ] ; (* static function selection; spec 15 §18 *) +application = "::" type_args ; (* explicit; no inference, spec 15 §15 *) -type = int_type | "bool" | "void" | "never" | ident +type = int_type | "bool" | "void" | "never" | path + | path type_args | "[" type ";" int_lit "]" | wrapper "<" type ">" | "cap" "<" path ">" | "file" "<" ( "read" | "write" | "append" ) ">" ; (* `>>` closes two type arguments: mut> *) wrapper = "ref" | "mut" | "slice" | "slice_mut" | "own" | "own_array" - | "task" | "sender" | "receiver" | "mutex" ; + | "task" | "sender" | "receiver" | "mutex" | "buffer" ; int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize" | "i8" | "i16" | "i32" | "i64" | "i128" | "isize" ; (* `region`, `listener`, `stream`, `io_error`, `alloc_error`, @@ -45,12 +55,12 @@ int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize" block = "{" { statement } [ expr ] "}" ; (* optional tail expression: the block's value *) statement = "let" binding [ ":" type ] "=" expr ";" | "var" ident ":" type "=" ( expr | "zero" ) ";" - | ( "ref" | "mut" ) [ "unchecked" ] ident "=" place ";" (* borrow binding *) + | ( "ref" | "mut" ) [ "unchecked" ] ident "=" ( place | borrow_call ) ";" (* borrow binding; buffer.view(b) / graph access also bind child borrows, spec 15 §17 *) | place "=" expr ";" | "break" ";" | "continue" ";" | "return" [ expr ] ";" | "trap" ";" | expr ";" | block_stmt ; -binding = ident | "(" ident "," ident ")" ; (* the pair form only for `split_at` *) +binding = ident | "(" [ ( ident | "_" ) { "," ( ident | "_" ) } ] ")" ; (* complete unpack; pairs also split_at/compare_exchange *) block_stmt = if_expr | match_expr | select_stmt | block | "while" expr block | "for" ident "in" expr ".." expr block @@ -63,7 +73,7 @@ if_expr = "if" expr block [ "else" ( if_expr | block ) ] ; match_expr = "match" expr "{" { arm } "}" ; arm = pattern "=>" ( block | expr "," ) ; pattern = "_" | int_lit (* integer matches only; `_` is required there *) - | ident "::" ident [ "(" ident { "," ident } ")" ] (* enum variant: Shape::Rect(w, h); no `_` in enum matches *) + | path [ application ] "::" ident [ "(" ident { "," ident } ")" ] (* enum variant: Shape::Rect(w, h); no `_` in enum matches *) | ident [ "(" ident { "," ident } ")" ] ; (* outcome of a fallible operation: ok(n), closed *) select_stmt = "select" "{" { select_arm } "cancelled" [ "(" ident { "," ident } ")" ] "=>" ( block | expr "," ) "}" ; @@ -83,16 +93,20 @@ unary = ( "-" | "not" | "*" ) unary | ( "ref" | "mut" ) [ "unchecked" ] place | "move" ident | postfix ; -postfix = primary { "." member | "[" expr [ ".." expr ] "]" | call_args } ; +postfix = primary { application | "." member | "[" expr [ ".." expr ] "]" | call_args } ; member = ident | keyword ; (* after `.` a keyword is a name: task.cancelled *) call_args = [ "<" type ">" ] "(" [ expr { "," expr } ] ")" ; primary = int_lit | "true" | "false" | string - | ident [ "{" field_init { "," field_init } [ "," ] "}" ] (* struct literal *) - | ident "::" ident (* enum variant; applied by a call *) + | "struct" "." "unpack" (* contextual built-in call, §16 *) + | ident | path [ application ] "{" [ field_init { "," field_init } [ "," ] ] "}" (* struct literal; uppercase final component *) + | path [ application ] "::" ident (* enum variant; applied by a call *) | "[" expr ";" int_lit "]" + | "[" expr { "," expr } [ "," ] "]" | "(" expr ")" | if_expr | match_expr | block ; field_init = ident ":" expr ; +borrow_call = "buffer" "." "view" "(" ident ")" + | ( "island" | "frozen" | "arc" ) "." "at" "(" expr "," expr ")" ; place = ident { "." ident | "[" expr [ ".." expr ] "]" } | "*" unary ; int_lit = digit { digit | "_" } [ int_type ] | "0x" hexdigit { hexdigit | "_" } [ int_type ] ; diff --git a/docs/reference/std.md b/docs/reference/std.md new file mode 100644 index 0000000..1329c07 --- /dev/null +++ b/docs/reference/std.md @@ -0,0 +1,450 @@ +# 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/std.map/std.hashmap/std.hashset/std.heap new/reserve and std.io.reader/std.io.writer new. + +Except std.io/std.io.reader/std.io.writer (§2.17–§2.18) and std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap 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 | +|---|---|---| +| `std.math` | `min_u64(a: u64, b: u64) -> u64` | smaller operand | +| `std.math` | `max_u64(a: u64, b: u64) -> u64` | larger operand | +| `std.math` | `clamp_u64(value: u64, lower: u64, upper: u64) -> u64` | inclusive clamp; `T0002` if `lower > upper` | +| `std.bytes` | `equal(a: slice, b: slice) -> bool` | byte equality | +| `std.bytes` | `compare(a: slice, b: slice) -> i8` | unsigned lexicographic order: exactly -1/0/1 | +| `std.bytes` | `find(data: slice, byte: u8) -> usize` | first index; `data.len` if absent | +| `std.bytes` | `starts_with(data: slice, prefix: slice) -> bool` | empty prefix matches | +| `std.bytes` | `ends_with(data: slice, suffix: slice) -> bool` | empty suffix matches | +| `std.bytes` | `fill(dst: slice_mut, byte: u8) -> void` | fills caller-provided storage | + +```aji +module demo.standard +import std.bytes; +import std.math; + +fn main() -> u64 +effects [] +{ + var data: [u8; 4] = zero; + std.bytes.fill(mut data, 65); + assert(std.bytes.equal(ref data, b"AAAA")); + let index = std.bytes.find(ref data, 65); + if index < data.len { assert(data[index] == 65); } + return std.math.clamp_u64(42, 0, 100); +} +``` + +Unknown module/member or absent import: `E7002`; duplicate import: `E7006`; malformed import or type arguments: `E7001`; wrong argument type/arity: `E7005`; conflicting borrows: `E2101`. No new diagnostic code. + +The example is `tests/conformance/source/quickref/std.aji`; library boundary and algorithm tests live under `tests/conformance/source/std/`. + +## Endian integers + +All functions operate at slice offset zero. Pass a sub-slice to select an offset. Extra bytes are ignored on read and preserved on write. No alignment or heap allocation is required. A short destination is unchanged; a short source yields no integer payload. + +| Width | Read functions (`src: slice`) | Result | Write functions (`dst: slice_mut, value: uW`) | Result | +|---|---|---|---|---| +| 16 | `std.bytes.read_u16_le`, `std.bytes.read_u16_be` | `std.bytes.ReadU16` | `std.bytes.write_u16_le`, `std.bytes.write_u16_be` | `std.bytes.WriteResult` | +| 32 | `std.bytes.read_u32_le`, `std.bytes.read_u32_be` | `std.bytes.ReadU32` | `std.bytes.write_u32_le`, `std.bytes.write_u32_be` | `std.bytes.WriteResult` | +| 64 | `std.bytes.read_u64_le`, `std.bytes.read_u64_be` | `std.bytes.ReadU64` | `std.bytes.write_u64_le`, `std.bytes.write_u64_be` | `std.bytes.WriteResult` | + +Read enums have exactly `ok(uW)` and `short_input`. `WriteResult` has exactly `ok` and `short_output`. These are ordinary Copy enums, handled with qualified enum patterns; they are not intrinsic outcome matches. They can be passed or returned through user functions. No generic must-use rule is introduced. + +```aji +module demo.endian +import std.bytes; + +fn main() -> u32 +effects [] +{ + var wire: [u8; 6] = zero; + match std.bytes.write_u32_be(mut wire[1..5], 0x12345678) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + match std.bytes.read_u32_be(ref wire[1..5]) { + std.bytes.ReadU32::ok(value) => { return value; } + std.bytes.ReadU32::short_input => { return 0; } + } +} +``` + +Missing enum arm: `E7004`; duplicate/wildcard enum arm: `E7006`; unknown type/variant or missing import: `E7002`; wrong width/payload, immutable destination or variant from another enum: `E7005`; conflicting destination borrows: `E2101`. Existing `or trap` only applies to fallible built-in operations, so it is not used with these enums. + +The example is checked in `source/quickref/std_endian.aji`; fixtures for every width/order and all short lengths are in `source/std/endian_u*.aji`. + +## Non-cryptographic hashing and CRC-32C + +Directly import `std.hash`. All four functions are ordinary safe source, `effects []`, with no heap allocation, mutation, retained borrow or capability requirement. + +| Function | Result | +|---|---| +| `std.hash.fnv1a64(data: slice) -> u64` | FNV-1a 64, offset basis `0xcbf29ce484222325` | +| `std.hash.fnv1a64_extend(state: u64, data: slice) -> u64` | continue from the supplied state | +| `std.hash.crc32c(data: slice) -> u32` | finalized Castagnoli CRC; empty input gives zero | +| `std.hash.crc32c_extend(checksum: u32, data: slice) -> u32` | continue from a finalized checksum, undo/reapply final XOR | + +Extend with the previous result and the next bytes: `crc32c_extend(crc32c(prefix), suffix)` equals CRC of their concatenation. Empty input preserves any supplied continuation value. FNV wraps multiplication modulo 2^64; CRC uses reflected polynomial `0x82f63b78` and initial/final XOR `0xffffffff`. Every byte participates, including zero; there are no implicit separators or padding. Numeric results are target-independent; serialize explicitly with `std.bytes.write_u32/u64_le/be`. These are not cryptographic functions, and CRC-32C is not IEEE CRC-32. A hash collision never establishes key equality. Structured fields need explicit byte encoding and boundaries. + +The [checked example](../../examples/std/hash.aji) computes CRC-32C of `123456789` (`0xe3069283`) in two chunks, hashes `foobar` and serializes the CRC little-endian. Empty slices use an existing array's `ref data[0..0]`; an empty byte literal has no array type. Calls cost O(bytes) work and O(1) auxiliary state; CRC initially uses eight bit steps per byte. Borrow/type/import errors keep E2101/E7005/E7002, and these monomorphic functions take no generic arguments. Definition/constants: [FNV RFC 9923](https://www.rfc-editor.org/rfc/rfc9923.html#section-2); independent published CRC vectors: [RFC 3720 B.4](https://www.rfc-editor.org/rfc/rfc3720.html#appendix-B.4). Exact recurrence is spec 16 §2.12. + +## Copy and substring search + +| Function | Result and contract | +|---|---| +| `std.bytes.copy(dst: slice_mut, src: slice) -> std.bytes.WriteResult` | `ok` copies the whole input into the output prefix, preserving the suffix; `short_output` leaves the whole output unchanged. Empty input succeeds. Overlap rejects (`E2101`), including on the error path. | +| `std.bytes.find_slice(data: slice, needle: slice) -> std.bytes.FindResult` | `found(index)` for the first match, or `not_found`. Empty needle is `found(0)`, including empty data. Offset is relative to the passed slice; it need not be a readable element index. | + +Search allocates no heap and uses constant auxiliary storage; the reference algorithm has O(data length × needle length) worst-case comparisons. Interpreter fuel bounds execution. For splitting at the first separator, match the search result, then take `data[0..index]` and `data[index + separator.len..data.len]`, or split at the index and borrow past the separator in the right half. An empty separator leaves the whole data in the right half; repeated splitting needs an explicit progress rule. There is no split iterator or returned pair of borrowed slices. + +## Recoverable arithmetic + +| Operand type | Functions | Result | +|---|---|---| +| `u64` | `std.math.checked_add_u64`, `std.math.checked_sub_u64`, `std.math.checked_mul_u64` | `std.math.U64Result::ok(u64)` / `overflow` | +| `usize` | `std.math.checked_add_usize`, `std.math.checked_sub_usize`, `std.math.checked_mul_usize` | `std.math.UsizeResult::ok(usize)` / `overflow` | + +Every function takes two operands of the indicated type. A representable mathematical result succeeds; unsigned subtraction underflow also returns `overflow`. Multiplication by zero always succeeds with zero. `usize` follows target pointer width. Normal arithmetic operators still trap on overflow; wrapping uses `+%`, `-%`, `*%`, with no library wrappers. These monomorphic APIs do not provide generic or signed arithmetic. Result enums use the same ordinary match rules as the endian results. + +For a zero-terminated byte record, check the complete output size before copying: + +```aji +fn encode(dst: slice_mut, data: slice) -> usize +effects [] +{ + match std.math.checked_add_usize(data.len, 1) { + std.math.UsizeResult::ok(total) => { + if total > dst.len { return 0; } + match std.bytes.copy(mut dst, ref data) { + std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; } + std.bytes.WriteResult::short_output => { return 0; } + } + } + std.math.UsizeResult::overflow => { return 0; } + } +} +``` + +This helper returns the encoded byte count or zero on failure, and leaves the destination unchanged on failure. Import both `std.math` and `std.bytes`. Its zero sentinel is unambiguous because a successful record includes the terminator. + +The checked [bounded example](../../examples/std/bounded.aji) combines overflow-aware output sizing, whole-input copy and delimiter search; it returns 10. Copy/search/split and independent arithmetic fixtures are in `source/std/bounded_*.aji`. Wrong operands/payloads are `E7005`; absent imports/types are `E7002`; missing result arms are `E7004`. No new diagnostic code, syntax, verifier state or runtime primitive is introduced. + +## UTF-8 and encodings + +| Function | Result and contract | +|---|---| +| `std.utf8.next(src: slice) -> std.utf8.NextResult` | `ok(scalar: u32, consumed: usize)` for the first scalar, `end` for empty input, or `invalid_input` for a bad/truncated first sequence; trailing bytes do not affect a successful first decode. | +| `std.utf8.validate(src: slice) -> std.utf8.ValidateResult` | `ok` for wholly valid bytes, including empty input; `invalid_input(offset)` at the beginning of the first bad/truncated sequence. | +| `std.encoding.hex.encode(dst: slice_mut, src: slice) -> std.encoding.hex.EncodeResult` | lowercase ASCII hex; `ok(count)` or `short_output`. | +| `std.encoding.hex.decode(dst: slice_mut, src: slice) -> std.encoding.hex.DecodeResult` | even-length ASCII digits, upper/lower/mixed case; `ok(count)`, `invalid_input` or `short_output`. | +| `std.encoding.base64.encode(dst: slice_mut, src: slice) -> std.encoding.base64.EncodeResult` | standard alphabet with canonical padding and zero unused bits; `ok(count)` or `short_output`. | +| `std.encoding.base64.decode(dst: slice_mut, src: slice) -> std.encoding.base64.DecodeResult` | canonical standard Base64 only; `ok(count)`, `invalid_input` or `short_output`. | + +UTF-8 uses shortest scalar encodings, excluding surrogates and values above U+10FFFF. NUL, BOM, noncharacters and unassigned scalars are accepted; validation does not normalize or replace bytes. Iteration repeatedly calls `next(ref data[offset..data.len])` and advances offset by the returned consumed count. `next` validates its first sequence only, so validate the whole slice when that is the required contract. A malformed final prefix is `invalid_input`, not a streaming "need more" result. [UTF-8 rules: RFC 3629 §3/§4](https://www.rfc-editor.org/rfc/rfc3629.html#section-3). + +Encoders check complete capacity before writing; decoders check the entire input first, then capacity. Invalid input takes precedence over short output. Every returned error preserves the whole destination. Success writes a prefix, preserves remaining output and appends no terminator. Empty encoding/decoding succeeds with `ok(0)`, including zero capacity. Mathematical lengths too large for usize/output are `short_output`, checked without overflowing an intermediate. Input/output cannot overlap; disjoint `split_at` siblings from the same allocation are allowed. These guarantees do not cover interpreter fuel interruption. + +Hex decoding rejects whitespace, prefixes, separators, odd length and non-hex bytes. Base64 uses the standard `+/` alphabet; incomplete final groups require `=` padding, and complete groups omit it. Decoding rejects whitespace, URL-safe symbols, incomplete groups, misplaced/excess padding and nonzero unused bits. This is a deliberate strict policy permitted by [RFC 4648 §3.5/§4](https://www.rfc-editor.org/rfc/rfc4648.html#section-3.5); no permissive or URL-safe mode is implied. + +```aji +module demo.text +import std.bytes; +import std.encoding.hex; +import std.encoding.base64; +import std.utf8; + +fn main() -> u32 +effects [] +{ + var utf8: [u8; 3] = zero; + match std.encoding.hex.decode(mut utf8, b"E282AC") { + std.encoding.hex.DecodeResult::ok(count) => { assert(count == 3); } + std.encoding.hex.DecodeResult::invalid_input => { return 0; } + std.encoding.hex.DecodeResult::short_output => { return 0; } + } + match std.utf8.validate(ref utf8) { + std.utf8.ValidateResult::ok => {} + std.utf8.ValidateResult::invalid_input(offset) => { return 0; } + } + var encoded: [u8; 4] = zero; + match std.encoding.base64.encode(mut encoded, ref utf8) { + std.encoding.base64.EncodeResult::ok(count) => { assert(count == 4); } + std.encoding.base64.EncodeResult::short_output => { return 0; } + } + assert(std.bytes.equal(ref encoded, b"4oKs")); + match std.utf8.next(ref utf8) { + std.utf8.NextResult::ok(scalar, count) => { assert(count == 3); return scalar; } + std.utf8.NextResult::end => { return 0; } + std.utf8.NextResult::invalid_input => { return 0; } + } +} +``` + +The [text example](../../examples/std/text.aji) is checked by `source/std/text_example.aji` and returns 8364 (U+20AC). Independent byte/scalar vectors, capacities, invalid-input precedence, namespace collisions, alias rejects and disjoint buffers are under `source/std/text_*.aji`. UTF-8/encoding algorithms allocate no heap and declare `effects []`; fixed local tables are constant auxiliary storage. Wrong operands/payloads: `E7005`; missing result arms: `E7004`; unknown types/imports: `E7002`; conflicting borrows: `E2101`. Results are ordinary Copy enums with no new must-use rule. + +## Integer formatting (`std.fmt`) + +Import `std.fmt`. Its four functions share `std.fmt.WriteResult::ok(count: usize)` / `short_output`: + +| Function | Value type | +|---|---| +| `write_u64(dst: slice_mut, value: u64)` | unsigned 64-bit | +| `write_i64(dst: slice_mut, value: i64)` | signed 64-bit | +| `write_usize(dst: slice_mut, value: usize)` | unsigned target pointer width | +| `write_isize(dst: slice_mut, value: isize)` | signed target pointer width | + +Output is decimal ASCII with no leading zeroes, plus sign, padding or terminator; negative values begin with `-` and zero is `0`. Every scalar value is supported, including signed minima. Success writes the prefix and preserves the suffix; short capacity preserves the entire output. Empty output is short even for zero. No heap allocation, cursor or format string exists. Full contracts are in spec 16 §2.8. + +Compose byte literals and integers using explicit offsets, advancing only after a successful operation: + +```aji +module demo.format +import std.bytes; +import std.fmt; + +fn main() -> usize +effects [] +{ + var record: [u8; 24] = [165; 24]; + match std.bytes.copy(mut record, b"value=") { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + var offset: usize = 6; + match std.fmt.write_i64(mut record[offset..record.len], -42) { + std.fmt.WriteResult::ok(count) => { offset = offset + count; } + std.fmt.WriteResult::short_output => { return 0; } + } + match std.bytes.copy(mut record[offset..record.len], b" count=") { + std.bytes.WriteResult::ok => { offset = offset + 7; } + std.bytes.WriteResult::short_output => { return 0; } + } + match std.fmt.write_usize(mut record[offset..record.len], 7) { + std.fmt.WriteResult::ok(count) => { offset = offset + count; } + std.fmt.WriteResult::short_output => { return 0; } + } + assert(std.bytes.equal(ref record[0..offset], b"value=-42 count=7")); + for i in offset..record.len { assert(record[i] == 165); } + return offset; +} +``` + +This checked program is `examples/std/format.aji` and `tests/conformance/source/std/fmt_example.aji`. It returns 17 without grants. Each operation preserves its own destination on short output; a sequence is not transactional across earlier successful calls. Existing alias checks apply even when a write would return short output. Smaller scalar widths require an explicit widening conversion to an appropriate writer; wider integers, float formatting and parsing are outside this increment. + +## Copy option/result templates + +Requires direct `import std.option;` / `import std.result;`; explicit generic spelling is spec 15 §15. + +| Declaration | Contract | +|---|---| +| `std.option.Option` | `some(T)`, `none` | +| `std.option.is_some(value: Option) -> bool` | true for some; false for none; effects [] | +| `std.result.Result` | `ok(T)`, `err(E)` | +| `std.result.is_ok(value: Result) -> bool` | true for ok; false for err; effects [] | + +All are ordinary safe source/static specialization, with no allocation or authority. Generic helper calls use `is_some::(value)` / `is_ok::(value)`. Constructors and patterns use `std.option.Option::::some(value)` or `std.result.Result::::err(code)`; names and variant matches remain explicit even for none. Extract values by exhaustive match; an err variant is not intrinsic outcome syntax. Owners/resources/endpoints make these enums linear under spec 03 §25 and require exhaustive `match move`. Borrows remain invalid members; Copy classification helpers reject linear arguments with E7005. No must-use or implicit unwrap/default/conversion is introduced. [Checked example](../../examples/std/generics.aji) returns 42 without grants. + +## Owning vectors + +Import std.vec; every function supplies explicit `::`. Vec contains a buffer and is always linear. No implicit growth or cleanup occurs. The storage field follows ordinary aggregate visibility/borrow rules. New/reserve require cap and effects [mem.alloc]; all other functions declare effects []. + +| Function | Parameters | Result | +|---|---|---| +| new | capacity: usize, heap: cap | NewResult: ok(Vec) / err(alloc_error) | +| len / capacity | value: ref> | usize | +| reserve | value: mut>, capacity: usize, heap: cap | ReserveResult: ok / err(alloc_error) | +| push | value: mut>, item: T | PushResult: ok / full(T) | +| pop | value: mut> | std.option.Option: some(T) / none | +| free | value: Vec | FreeResult: ok / not_empty(Vec) | +| get | value: ref>, index: usize | std.option.Option: some(T) / none | +| replace | value: mut>, index: usize, item: T | ReplaceResult: ok(old_value: T) / out_of_bounds(original_item: T) | + +Growth has an old+new capacity allocation peak. Failure preserves capacity/length/elements; full push and out-of-bounds replacement return the exact input. Nonempty free returns the vector; pop/consume all elements before retrying. get returns none out of bounds, replace returns the old complete element on success. Generic moves compose Copy and linear types. Qualified variants require direct imports (including std.option for pop/get). [Executable owning vector](../../examples/std/vector.aji) returns 42 with heap=mem.alloc:256. Views and nested element borrows cannot escape or overlap shape changes. Normative contracts: spec 16 §2.10 and spec 03 §26. + +## Owning deques + +Import std.deque; every operation supplies `::`. Deque is always linear and has bounded ring capacity. Pop transfers complete values. No operation grows except explicit reserve. New/reserve declare mem.alloc and take explicit authority; all others declare effects []. + +| Function | Parameters | Result | +|---|---|---| +| new | capacity: usize, heap: cap | NewResult: ok(Deque) / err(alloc_error) | +| len / capacity | value: ref> | usize | +| reserve | value: mut>, capacity: usize, heap: cap | ReserveResult: ok / err(alloc_error) | +| push_front / push_back | value: mut>, item: T | PushResult: ok / full(original_item: T) | +| pop_front / pop_back | value: mut> | std.option.Option: some(T) / none | +| free | value: Deque | FreeResult: ok / not_empty(Deque) | +| get | value: ref>, index: usize | std.option.Option: some(T) / none | +| replace | value: mut>, index: usize, item: T | ReplaceResult: ok(old_item: T) / out_of_bounds(original_item: T) | + +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 (tag plus payload), including free slots: capacity 3 of own 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 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 `::`. `U64Map` 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 keys use `std.hashmap` with explicit hash/equality (§2.14). + +| Operation | Return / ownership | +|---|---| +| `new(capacity: usize, heap: cap)` | `NewResult::ok(U64Map)` / `err(alloc_error)` | +| `len(map: ref>) -> usize` | entry count | +| `capacity(map: ref>) -> usize` | maximum live entries before a new key returns full | +| `reserve(map: mut>, capacity: usize, heap: cap)` | `ReserveResult::ok` / `err(alloc_error)`; grow explicitly, preserve every slot on returned failure | +| `insert(map: mut>, key: u64, value: V)` | `InsertResult::inserted` / `replaced(V)` / `full(V)` | +| `contains(map: ref>, key: u64) -> bool` | presence without copying V | +| `get(map: ref>, key: u64)` | `std.option.Option` copied lookup | +| `remove(map: mut>, key: u64)` | `std.option.Option` moved removal | +| `pop(map: mut>)` | `std.option.Option>`; Entry has key: u64, value: V | +| `free(map: U64Map)` | `FreeResult::ok` / `not_empty(U64Map)` | + +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 { storage: buffer>, length: usize }`, `Slot { key: u64, state: SlotState, value: std.option.Option }`, `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. + +## Owning general-key maps + +Import `std.hashmap` and `std.option` for lookup/extraction results. `HashMap` stores complete keys and values, including owning byte buffers, structs, owners, files and channel endpoints. The two declared functions have exactly `fn(ref) -> u64 effects []` / `fn(ref,ref) -> bool effects []`. Equality is stable equivalence and equal keys must hash equally; hash equality alone never identifies a key. Do not change a live key's hash/equality. Different bound functions produce distinct nominal map types. Operations never capture state or gain authority from selection. + +Every call supplies `::` (get additionally requires V: Copy, without requiring K: Copy): + +| Function arguments | Result | +|---|---| +| new(capacity: usize, heap: cap) | NewResult: ok(HashMap), err(alloc_error) | +| len(map: ref) | usize live count | +| capacity(map: ref) | usize maximum live entries | +| reserve(map: mut, capacity: usize, heap: cap) | ReserveResult: ok, err(alloc_error) | +| insert(map: mut, key: K, value: V) | InsertResult: inserted, replaced(Entry), full(Entry) | +| contains(map: ref, key: ref) | bool | +| get(map: ref, key: ref) | std.option.Option copied value | +| remove(map: mut, key: ref) | std.option.Option> moving extraction | +| pop(map: mut) | std.option.Option> moving extraction | +| free(map: HashMap) | FreeResult: ok, not_empty(HashMap) | + +Here HashMap abbreviates the fully applied type, and Entry has key: K/value: V. Pass `ref q` when querying through mut q; ownership transfer of named linear K/V requires move. Replacement returns both old resources and retains the new equivalent key. Full insert returns both original inputs. Explicitly consume every owning result; free returns the nonempty map. get cannot copy an owned V, while contains/remove work without Copy requirements. No borrowed value/cursor escapes. + +Only new/reserve allocate and declare mem.alloc with explicit authority. Growth has no implicit trigger and returned failure preserves every old entry/bucket and pop order. A capacity N reserves N StoredEntry slots (hash + full K/V sizes) and 2N Copy Bucket slots (hash + usize + state tag). Live entries form an initialized dense prefix, with a separate probe-index table and cached hashes. Removing a middle entry exchanges the last into its position, repairing the index. Pop drains reverse current dense order; reserve preserves it and clears tombstones. Zero capacity is valid. Peak growth includes both entry buffers, both index buffers and external user owners; refunds follow the recorded allocation capabilities. Capacity-one Key{id:u64}/own reserves 58 bytes, plus 8 for the owned payload in the [checked example](../../examples/std/hashmap.aji), which runs with heap=mem.alloc:66. + +Representation fields are ordinary visible source; manual construction/mutation must preserve the full invariant in spec 16 §2.14. Hash/equality traps and fuel exhaustion are abnormal outcomes. Existing moves, alias/task-loan and Copy/Send/Share rules apply without unsafe or map-specific runtime semantics. Worst-case lookup/insert/remove/pop is O(N) plus callback work, rehash O(N²); no adversarial collision/native-throughput guarantee is made. `std.map.U64Map` retains its existing API for numeric keys. + +## Owning general-key sets + +Import `std.hashset` and `std.option` for extraction results. `HashSet` uses the map's exact pure `fn(ref) -> u64 effects []` / `fn(ref,ref) -> bool effects []` contracts and stable equality/hash laws. Complete owning keys, including byte buffers and resource-bearing structs, need no Copy constraint. Every operation supplies `::`: + +| Function arguments | Result | +|---|---| +| new(capacity: usize, heap: cap) | NewResult: ok(HashSet), err(alloc_error) | +| len(set: ref) | usize live count | +| capacity(set: ref) | usize maximum live keys | +| reserve(set: mut, capacity: usize, heap: cap) | ReserveResult: ok, err(alloc_error) | +| insert(set: mut, key: K) | InsertResult: inserted, present(K), full(K) | +| contains(set: ref, key: ref) | bool | +| remove(set: mut, key: ref) | std.option.Option moving extraction | +| pop(set: mut) | std.option.Option moving extraction | +| free(set: HashSet) | FreeResult: ok, not_empty(HashSet) | + +Here HashSet abbreviates the applied type. Duplicate insertion preserves the stored representative and every entry/bucket, returning the original incoming K as present, even at capacity. Full returns the original new key. Remove/pop return stored keys; free returns a nonempty set. Explicitly consume all owning results. Use `move` for named linear inputs and `ref q` for queries through mut q; contains retains no borrow. Replacement requires explicit remove followed by insert. + +Only new/reserve allocate with mem.alloc and explicit authority. There is no automatic growth or cleanup. The visible representation is `map: std.hashmap.HashMap` with every live value true; callers must preserve spec 16 §2.15's complete invariant. Dense extraction/pop order, failure preservation, peak accounting and refunds follow the map. Each capacity slot charges hash + K + bool and two buckets: 51 bytes for u64, or 59 for Key{id:u64,owner:own}, plus the separately allocated payload. The [owning example](../../examples/std/hashset.aji) returns 42 with heap=mem.alloc:67. + +Policies may run for membership and again for insertion, with no runtime dispatch or gained authority. Existing moves/aliases/task loans and Copy/Send/Share checks apply. Callback traps/fuel exhaustion are abnormal outcomes. Worst-case membership/insert/remove/pop is O(N) plus callbacks; growth is O(N²) under collisions. No sorted iteration or native-throughput guarantee is made. + +## Owning binary heaps + +Import `std.heap` and `std.option`. `BinaryHeap` stores complete T with an explicit exact `fn(ref,ref) -> bool effects []` operation. before(a,b) means a has higher extraction priority. It must remain a stable strict weak order: irreflexive/transitive, with transitive incomparability. Equivalent items have deterministic extraction for a fixed operation sequence, without a stable tie-order promise. Use `<` for numeric minimum first or `>` for maximum first. Distinct bound operations give distinct nominal types; selection grants no authority. + +Every call supplies `::`; peek additionally requires T: Copy: + +| Function arguments | Result | +|---|---| +| new(capacity: usize, heap: cap) | NewResult: ok(BinaryHeap), err(alloc_error) | +| len(value: ref) | usize live count | +| capacity(value: ref) | usize maximum live count | +| reserve(value: mut, capacity: usize, heap: cap) | ReserveResult: ok, err(alloc_error) | +| push(value: mut, item: T) | PushResult: ok, full(T) | +| peek(value: ref) | std.option.Option copied root | +| pop(value: mut) | std.option.Option moving root extraction | +| free(value: BinaryHeap) | FreeResult: ok, not_empty(BinaryHeap) | + +Here BinaryHeap abbreviates the applied type. Use move for named linear inputs, mut for push/pop/reserve and ref for queries (ref q through a mut parameter). Full push preserves all state, returns the original input and calls no comparator. Empty pop/peek returns none; nonempty free returns the whole heap. Explicitly consume owning full/pop/not_empty results. Peek retains no borrow and cannot copy an owner; complete owning records, files and sender endpoints use pop. Only new/reserve allocate with mem.alloc and explicit authority; growth is never automatic. + +The visible representation is entries: buffer> / indices: buffer, Entry{position:usize,value:T}. Both initialized lengths/capacities agree. Indices are a permutation of dense positions; each entry points back to its index position, and no child precedes its parent. Callers must preserve spec 16 §2.16's complete invariant. Sifting swaps Copy indices and inverse positions; pop repairs the dense hole through complete exchange. No default T or implicit destruction is needed. + +New allocates empty entries then indices, refunding entries on second-allocation failure. Reserve allocates/copies new indices before growing entries; returned failure preserves both old buffers, values/positions/indices and extraction order, and refunds temporaries. Success preserves the layout and frees old indices explicitly. Peak quota includes both entry/index buffers and all external user allocations; refunds go to recorded authorities. Zero capacity is valid; size overflow returns budget_exceeded. On air64 each capacity slot costs sizeof(T)+16 bytes. The [owning example](../../examples/std/heap.aji) needs 32 bytes for one Item slot plus 8 for its payload: heap=mem.alloc:40. + +Existing ownership/alias/task-loan/Send/Share rules apply with no unsafe boundary or new runtime semantics. Callback/fuel traps are abnormal. Abstract push/pop need O(log L) comparisons/swaps, peek O(1), reserve O(L) copies; interpreter prefix-copy/GC costs may add host work. There is no native-throughput guarantee. + +## Bounded I/O composition + +Import `std.io`. Six concrete functions compose existing primitives with caller-provided slices. They never allocate, open/close resources or retain borrows. Effects and authority remain explicit even for empty/no-op paths. File/stream resources are mutably lent and remain owned by the caller on every normal return. + +| Function | Result | Effects | +|---|---|---| +| read_exact_stdin(input: cap, destination: slice_mut) | ReadExactResult | io.read | +| read_exact_file(input: mut>, destination: slice_mut) | ReadExactResult | fs.read | +| read_exact_stream(input: mut, destination: slice_mut) | ReadExactResult | net.read | +| read_to_end_file(input: mut>, destination: slice_mut) | ReadToEndResult | fs.read | +| copy_file(input: mut>, output: mut>, scratch: slice_mut, limit: usize) | CopyResult | fs.read, fs.write | +| copy_file_append(input: mut>, output: mut>, scratch: slice_mut, limit: usize) | CopyResult | fs.read, fs.write | + +ReadExactResult is ok / eof(completed:usize) / err(ReadError{completed:usize,error:io_error}). Exact reads fill the destination, looping over short reads. Empty destination is ok without I/O. EOF leaves the remaining suffix unchanged. A read error guarantees only the successful prefix; the attempted suffix follows the primitive's failure contract. Bytes outside the supplied destination remain unchanged. + +ReadToEndResult is eof(completed:usize) / full(completed:usize) / err(ReadError). Full means the supplied buffer was filled; it does not establish whether EOF was reached or unread data remains. Empty destination is full(0), and no extra byte is read/discarded to probe EOF. Growing/owning read-to-end is separate work; fixed-capacity adapters are below. + +CopyResult is eof(completed:usize) / limit(completed:usize) / err(CopyError{read:usize,confirmed_written:usize,error:io_error}). Copies bound every scratch chunk by remaining limit and stop without probing past it. Exact EOF at the limit reports limit. A read error has both counts equal to earlier completed chunks. A write error includes its consumed input chunk in read; confirmed_written includes only prior successful writes. The failed write may have externally written a prefix: there is no rollback promise or exact failed-output count. Resources remain borrowed for explicit caller cleanup. + +Zero limit returns limit(0) without I/O, even with empty scratch. Empty scratch with positive limit returns invalid_input with both error counts zero without I/O. No counter exceeds the limit or overflows. Scratch contents after a call are unspecified; bytes outside its slice remain unchanged. The [copy example](../../examples/std/io.aji) uses only fs.read/fs.write entry grants and a fixed frame scratch array, handling results and closing both resources explicitly. Existing fs.write_all/net.send_all/console writes already write all bytes on success, so this increment adds no duplicate write alias. + +Ordinary alias/task-loan, type/mode, capability and effect checks apply; imports grant nothing. Blocking/fuel/profile errors remain spec 11 behavior, with no hidden timeout, task or unsafe boundary. std.io's concrete contracts are spec 16 §2.17; owning buffered adapters and lexical paths remain forthcoming. + +## Owning buffered files + +Import `std.io.reader` for Reader/file and `std.io.writer` for Writer/file. Import `std.io` directly when spelling read_exact's result, and `std.option` when matching the writer failure state; dependency imports do not expose names to callers. Each adapter owns a fixed initialized buffer and its file. Only new allocates, with an explicit mem.alloc capability, charging N bytes. Zero capacity delegates directly to primitive I/O. Files are never implicitly closed or synced. All file/adapter-bearing results are linear: consume every normal branch explicitly. + +| Function arguments | Result | Effects | +|---|---|---| +| std.io.reader.new(input: file, capacity: usize, heap: cap) | NewResult: ok(Reader), err(NewError{file:file,error:alloc_error}) | mem.alloc | +| std.io.reader.read(input: mut, destination: slice_mut) | ReadResult: ok(usize), err(io_error) | fs.read | +| std.io.reader.read_exact(input: mut, destination: slice_mut) | std.io.ReadExactResult | fs.read | +| std.io.reader.finish(input: Reader) | FinishResult: ok(file), unread(Reader) | none | +| std.io.reader.discard(input: Reader) | Discarded{file:file,unread:usize} | none | +| std.io.writer.new(output: file, capacity: usize, heap: cap) | NewResult: ok(Writer), err(NewError{file:file,error:alloc_error}) | mem.alloc | +| std.io.writer.write(output: mut, bytes: slice) | WriteResult: ok, err(WriteError{accepted:usize,error:io_error}) | fs.write | +| std.io.writer.flush(output: mut) | FlushResult: ok, err(io_error) | fs.write | +| std.io.writer.finish(output: Writer) | FinishResult: ok(file), err(FinishError{writer:Writer,error:io_error}) | fs.write | +| std.io.writer.discard(output: Writer) | Discarded{file:file,pending:usize,failed:std.option.Option} | none | + +Move named files into new and named adapters into finish/discard. Constructor failure returns the exact original file before I/O; it can be closed or reused. Successful finish/discard drains/frees storage and refunds its recorded authority, returning the file for explicit use/close. No implicit growth, cleanup, retained caller borrow or extra authority is introduced. + +Reader.read copies one cached prefix without refilling; when empty it refills the storage once, then returns a prefix. Thus read can return short even with more data available. Empty destination returns ok(0) without consuming/refilling and does not establish EOF. read_exact loops to fill the destination, using the std.io prefix/EOF/error contract. Reader.finish returns the complete unchanged Reader if cached unread bytes remain. Empty cache permits finish without probing EOF. Discard explicitly abandons unread prefetched bytes and returns their count: the file cursor remains advanced through prefetch, with no rewind. A read error retains ownership/offsets but promises no external cursor rollback or untouched attempted destination suffix. + +Writer.write fills available storage and flushes a full buffer only when more input needs room. Ending with a full buffer keeps it pending. Empty input on a healthy writer does nothing. A write error reports bytes accepted from that call; accepted includes buffered data and is not an externally written/durable count. Pending data may include earlier calls. At capacity zero a direct failed write reports accepted=0 even if an external prefix was written. Healthy flush of empty storage performs no I/O; successful flush resets used to zero. + +Any failed external write preserves pending bytes/used and records its first io_error. Every subsequent write, including empty, returns that error with accepted=0; every flush returns it, with no I/O or mutation. Finish returns the complete failed Writer plus error. There is no retry/reset because the failed operation may already have externally written an unknown prefix. Discard returns the file, pending count and failure state; pending can overlap that prefix and is not an exact loss count. Callers can explicitly handle the returned file according to their application protocol. + +The visible representations are Reader{file,storage,begin,end}, 0≤begin≤end≤N, and Writer{file,storage,used,failed}, 0≤used≤N. Both buffers have initialized length=capacity=N. Caller field access/construction must preserve spec 16 §2.18's complete data/cursor/first-error invariant and must not independently consume/use the internal file/storage. Existing ownership, alias/task-loan, effects and Send/Share checks apply. Adapters can transfer to workers but cannot be shared immutably across tasks because files are non-Share. No unsafe/trusted boundary or new runtime/verifier state is needed. + +The [copy example](../../examples/std/buffered_io.aji) uses two three-byte buffers (heap=mem.alloc:6), explicitly handles constructor/finish failure and returns the copied byte count, or zero after normal error cleanup. Conformance fixtures include capacities zero/full, unread finish/discard, exact EOF, allocation failure/refunds, worker transfer and rejected ownership/effect/alias cases. Hosted tests exercise read errors and real partial external writes; Linux raises the child file quota after failure to detect forbidden retry. + +## Lexical paths + +Import `std.path`. Six pure operations use byte `/` separators in every profile. They never allocate heap, retain/return a borrow, inspect the filesystem/current directory or grant authority. Backslash, colon and non-UTF-8 bytes are ordinary component bytes; there is no drive/UNC or symlink resolution. Range{start:usize,end:usize} is Copy; callers explicitly borrow ref path[range.start..range.end]. A range is data, and bounds are still checked if it is reused for a different path. + +| Function arguments | Result | +|---|---| +| is_absolute(path: slice) | bool: first byte is `/` | +| basename(path: slice) | Range of final nonempty raw component, ignoring trailing separators; 0..0 for empty/root-only | +| parent(path: slice) | Range of raw prefix before basename, trimming the separator run before it; rooted input retains first `/`; 0..0 for empty/relative leaf | +| extension(path: slice) | Range after basename's last dot, excluding dot; empty at basename.end for absent/leading-only/trailing dot or `.`/`..` | +| normalize(destination: slice_mut, path: slice) | WriteResult: ok(usize), invalid_input, size_overflow, short_output | +| join(destination: slice_mut, base: slice, child: slice) | WriteResult | + +Queries accept arbitrary bytes, including NUL, and return offsets into the original input, without normalizing it. For a//b///, basename selects b and parent selects a; parent(a/../b) selects `a/..`. Root-only parent selects the first slash; root-only basename is empty. Extension(.profile) is empty, extension(.profile.json) selects json, extension(a..b) selects b, extension(a.) is empty. Empty extension deliberately makes no distinction between no dot and empty suffix. + +Normalize collapses separator runs and leading slashes, removes `.` and trailing slashes, and cancels each ordinary component followed by `..`. Relative unmatched parents remain leading `..`; parents above root are dropped. Empty/reduced-empty relative input becomes `.`; empty rooted output becomes `/`. Examples: a//b/../c/ → a/c; a/../../b → ../b; /../../a → /a; a/.. → . . Normalization is idempotent. Exactly two leading slashes have no special meaning. + +Join normalizes absolute child alone, replacing base. Otherwise it normalizes base followed by child as components separated by a slash; an empty base does not introduce a root. Empty child normalizes base, both empty become `.`, and child parents can cancel base components. Examples: /data/a + ../b → /data/b; a + /b → /b; empty + a → a. These transformations give no capability-containment proof. Filesystem primitives still reject normalized relative paths and enforce their granted scopes on absolute ones. + +Both writers first validate all input bytes: NUL yields invalid_input, including in base when an absolute child replaces it. Invalid input precedes size_overflow, which precedes short_output. Every returned error leaves the entire destination unchanged. Success writes exactly the reported prefix, preserves the suffix and writes no NUL terminator. Only final normalized size must fit: a long component followed by `..` can normalize into one byte of output. Reverse measurement/emission needs fixed frame state and no intermediate buffer or allocation. Work is linear in supplied input/output bytes. + +Input borrows can overlap each other; destination must be disjoint. Explicit split_at permits source/output in one allocation. Existing type/borrow/task-loan/Send/Share checks apply, including no-op/short-output paths. No unsafe boundary, new language/AIR semantics or hidden effects are needed. Borrow-return source support (Q-034) remains separate. The [pure example](../../examples/std/path.aji) joins into a caller buffer and borrows basename/parent/extension from the returned prefix. The independent Python forward-stack oracle covers normalization/join/query/capacity/idempotence; hosted fixtures confirm filesystem authority remains independent. diff --git a/docs/reference/type-properties.md b/docs/reference/type-properties.md index 85c1ea7..5e0008c 100644 --- a/docs/reference/type-properties.md +++ b/docs/reference/type-properties.md @@ -49,3 +49,11 @@ Because of it, a graph never holds outside authority or a mutable ownership edge An `ArcSafe` value may be held by an `arc` (spec 03 §24): the last release destroys it by freeing memory only, with no user or resource action. In format 0 it is exactly `IslandSafe`. `Share` alone is not enough; for example, a `mutex` is `Share` but not `ArcSafe`. + +## Format-0 source constraints + +Spec 15 §15 fixes the exact property queries used by explicit generic specialization. Copy includes integers, booleans, built-in enums, capabilities, `iref` and aggregates of Copy members; borrows and linear values are excluded. Send/Share use spec 04 §35. Freeze currently equals IslandSafe plain graph content; it does not promise conversion of arbitrary owners or resources. Local has task/scope/shield/guard/internal-storage base cases and propagates through borrow/own/own_array/buffer/mutex wrappers and arrays/aggregates containing Local content. It is not the complement of Send. These properties add no methods, effects, unsafe declarations or implicit resource actions. + +Under linear_aggregates (spec 03 §25), structs/enums/fixed arrays containing any linear member are linear as whole values. Every variant contributes, regardless of the active tag. Borrow/storage/function-bound members remain forbidden; whole-value unpack/take/exchange preserve exactly-once consumption. + +Under linear_buffers (spec 03 §26), buffer is always linear; Send/Share follow T, and Local propagates. Borrow/storage/task-bound content is forbidden. It is neither IslandSafe nor ArcSafe: its nested linear values require explicit draining. diff --git a/docs/rfcs/0016-standard-library-bootstrap.md b/docs/rfcs/0016-standard-library-bootstrap.md new file mode 100644 index 0000000..f2a1b15 --- /dev/null +++ b/docs/rfcs/0016-standard-library-bootstrap.md @@ -0,0 +1,122 @@ +# RFC 0016: Standard library bootstrap and built-in source imports + +Status: Implemented +Scope: `.aji` source composition and safe pure standard modules; AIR format 0 unchanged +Language version: 0.1 +Supersedes: — +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +This branch contains the proposed spec text, reference implementation and tests for review. Only the owner changes the RFC to Accepted; implementation on a work branch does not constitute acceptance. + +## Motivation + +Reusable byte operations reduce repeated loop/borrow code and the reasoning burden of basic system software. The current frontend has no modules/import resolution or user generics, while linear aggregates are reserved. Beginning with safe non-owning byte functions makes progress without pretending that resource-owning collections already work. + +The proposal improves implementation simplicity, deterministic behavior, auditability and machine repairability. Its value for Model Capability Compression is a hypothesis to measure, not a result inferred from smoke tasks. The full roadmap is `docs/plan/standard-library.md`. + +## Precise invariant + +Imported standard source is ordinary code under the same verifier: immutable slices only read, exclusive slices only write, no borrow escapes, no resource is consumed, no authority is created, no hidden heap allocation occurs. Every source call lowers to a normal AIR call with a collision-free identifier. + +## Normative rule changes + +The complete proposed text is integrated into spec 15 §2/§13, spec 16 and `reference/grammar.ebnf`/`reference/std.md` in this branch. It defines a closed compiler-pinned module registry, contextual `import std.bytes;`, fully qualified calls, lexicographic composition, collision-free name mangling, library source provenance and nine pure API contracts. + +This proposal covers only `std.bytes` and `std.math`. It does not make general package imports, aliases, imported types or generic collections available. The whole imported module is lowered, so unused declarations also contribute to the feature closure. Dependency pruning is deferred until there is evidence that the simple strategy becomes costly. + +## Verifier implications + +No new state, transfer functions, diagnostics or trusted exemptions. Calls, slices, alias checks, frame lifetime, bounds and initialization use the existing rules. Module/function limits apply to the combined module, including all standard declarations. Imported source cannot bypass verification. + +## Interpreter / runtime implications + +No new runtime rule. Ordinary function calls execute pure operations under fuel. `fill` writes only caller-provided storage. No initialization on import, hidden cleanup, allocation or task creation. Invalid clamp bounds trap `T0002` at the assertion in `std/math.aji`; valid byte slices do not trap due to library arithmetic or bounds. + +## AIR changes + +None. There is no new feature registry entry or opcode: the source import is composition, not an AIR construct. Dots are not allowed in format-0 global identifiers; standard functions therefore use deterministic collision-free `__aji_std_bytes_equal`-style names, with numeric suffixes when needed. The compiler emits the existing feature closure. Existing AIR constructs, types and effects retain their frozen semantics. + +## Valid example + +```aji +module example +import std.bytes; + +fn main() -> u8 +effects [] +{ + var buf: [u8; 4] = zero; + std.bytes.fill(mut buf, 65); + assert(std.bytes.equal(ref buf, b"AAAA")); + return 0; +} +``` + +## Rejected example + +```aji +module example +import std.bytes; + +fn main() -> u8 +effects [] +{ + var buf: [u8; 4] = zero; + ref saved = buf; + std.bytes.fill(mut buf, 65); + return 0; +} +``` + +The exclusive borrow conflicts with `saved`: `E2101`. Current verification reports it at both the borrowed argument and the call, as captured by the conformance test; no new rule or code is introduced. A wrong slice type/arity is `E7005`, an unknown import/member or absent import is `E7002`, a duplicate import is `E7006`, malformed import/type-argument syntax is `E7001`. + +## Diagnostics impact + +No new code. Library diagnostics and traps use the stable bundled source path and original positions; AIR locations remain available. User diagnostics retain their existing file and source mapping. Source-mapping deduplication compares the file as well as code/line/column, so separate files cannot silently suppress one another. + +## Spec integration + +- Spec 15 §2/§13: imports, resolution, lowering and source provenance. +- Spec 16: standard library contract and bootstrap modules. +- Reference grammar: import syntax; API reference: signatures/failure table. +- Source Reference Bundle: import rules in `language/syntax.md`, APIs in the on-demand `library/std.md`, navigation and a checked Quick Reference example. + +The AIR bundle is unchanged; the functions need only existing AIR contracts. The spec remains authoritative after owner acceptance. + +## Compatibility and migration + +AIR format 0 is unchanged, with no new instruction, type, verifier/runtime rule or interpretation. Programs without imports keep identical canonical AIR; the contextual word `import` still works as an ordinary local/function name. User functions/types with generated-name collisions are preserved and standard symbols get suffixes. A local binding named `std` does not change fully qualified standard resolution. No migration required. + +General user imports, public types and generics need their own source specifications. Resource-owning collections require the independent vertical `linear_aggregates` RFC; this proposal cannot be used as permission to weaken ownership. + +## Agent complexity impact + +- New concepts: compiler-bundled module import and fully qualified library call; nine named pure operations. +- New verifier state: none. +- New syntax forms: one import statement; qualified calls reuse existing dotted call expressions. No new AIR instruction. +- Interactions: existing call typing, frame/slice borrows, bounds, function naming, feature closure and source spans. No capability or effect is inferred away. +- Repairability: reuse checked functions instead of rewriting loops; absent import/type/alias mistakes reuse stable diagnostics. `find` uses a length sentinel that callers must check. No benefit is claimed until measured. +- Existing primitives suffice for every algorithm; source composition removes the need for manual source concatenation. +- Public generics are not invented; the three integer functions explicitly say `u64`. The source-side budget includes this temporary monomorphic surface. +- New source diagnostics: none; existing codes gain import/member cases. + +Measured with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source` on the bootstrap branch: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference (`QUICK.md`, includes navigation) | 5,511 → 5,777 (+4.8%) | 5,529 → 5,797 (+4.8%) | 5,664 → 5,948 (+5.0%) | +| Other source docs | 28,470 → 30,461 (+7.0%) | 28,552 → 30,546 (+7.0%) | 29,238 → 31,307 (+7.1%) | +| Full source docs without AIR | 33,981 → 36,238 (+6.6%) | 34,081 → 36,343 (+6.6%) | 34,902 → 37,255 (+6.7%) | +| AIR docs in the source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 | + +The new on-demand API page costs 1,346/1,347/1,406 tokens. Standalone AIR bundle size stays 160,797 bytes, 48 sections, 19 files. Growth is below the 10% warning threshold. Nine APIs replace repeated user loops without adding verifier state; later additions must remeasure rather than assuming this budget scales. + +Branch checks: build, unit tests, Quick Reference extraction, full conformance (456 passed, zero failed/pending), formatting and source coverage (69/69) pass. Hosted file/stdin/TCP smoke tests pass. Evaluation harness self-tests pass (22 tests; one environment-dependent skip). The source run tests execute twice for determinism, and one std test compares against hand-written AIR. Boundary tests cover empty slices, embedded zero/high bytes, length ordering, repeated/absent search results, every u8 fill value, sub-slice mutation, u64 extremes and inverted clamp bounds. Collision tests exercise both user type/function names and the local `std` name; mapping and CLI record tests preserve library provenance. + +## Alternatives considered + +Manual copying/concatenation makes library source and diagnostics hard to track. Hidden std intrinsics enlarge the trusted surface for ordinary algorithms. Implementing general packages and generics first delays pure reusable code; the closed two-module registry provides a bounded first increment while keeping those prerequisites explicit. Implicit prelude and aliases increase name-resolution choices and are omitted. + +## Unresolved questions + +Q-026 records the import/distribution decision. Q-027 records the existing discrepancy between the spec and frontend for empty byte literals; tests pass zero-length slices with the existing `ref storage[0..0]` form. Typed schemas, crypto backend choice, TLS trust configuration, cancellation-safe container cleanup and extended runtime capabilities are separate roadmap gates. diff --git a/docs/rfcs/0017-standard-endian-results.md b/docs/rfcs/0017-standard-endian-results.md new file mode 100644 index 0000000..f4bf563 --- /dev/null +++ b/docs/rfcs/0017-standard-endian-results.md @@ -0,0 +1,128 @@ +# RFC 0017: Recoverable endian operations and qualified standard enums + +Status: Implemented +Scope: STD-1a, safe `std.bytes` algorithms and closed-registry enum names; AIR format 0 unchanged +Language version: 0.1 +Supersedes: — +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +This branch integrates the proposed specification, implementation and tests for review. Only the owner changes the RFC to Accepted; branch implementation is not acceptance. RFC 0016 remains the historical bootstrap record. + +## Motivation + +Byte protocols and storage formats need bounded integer decoding and encoding. Short input/output is normal recoverable failure and cannot be represented by a numeric sentinel: every u16/u32/u64 value is valid. A trap would force every caller to duplicate capacity prechecks. A borrowed scalar output argument adds mutation and alias reasoning to an otherwise pure read. + +This increment improves semantic explicitness, deterministic behavior, memory safety and repairability by returning existing typed enums and checking capacity before access. Model Capability Compression remains a hypothesis requiring empirical evidence, not a conclusion from passing fixtures. + +## Precise invariant + +Read operations access only the first N bytes of a sufficiently long shared slice. Write operations mutate only the first N bytes of a sufficiently long exclusive slice. A short write leaves every byte unchanged. No borrow escapes, allocation occurs, resource is consumed, authority is created or task is started. A successful zero integer is distinct from short input. + +## Normative rule changes + +The complete rules are integrated into spec 16 §2.3 and spec 15 §13 in this branch: + +- Width and byte order MUST appear in the function name: `read_u16_le`/`be`, `read_u32_le`/`be`, `read_u64_le`/`be` and corresponding writes. There is no native-endian default, offset parameter or cursor state; offsets use explicit sub-slices. +- Reads MUST return the corresponding `std.bytes.ReadU16`, `ReadU32` or `ReadU64`: `ok(value)` or `short_input`. Extra input bytes MUST NOT affect the value. Short input MUST cause no element reads. +- Writes MUST return `std.bytes.WriteResult`: `ok` or `short_output`. Short output MUST leave the entire destination unchanged; success MUST leave bytes after the encoded integer unchanged. +- Qualified standard enum types, constructors and patterns MUST resolve only through explicitly imported modules in the closed compiler-pinned registry. They introduce no unqualified names or aliases. Source type diagnostics MUST use public qualified names, including inside compound types. +- Standard types and functions MUST receive deterministic collision-free AIR identifiers. Composition includes all imported declarations and uses the existing verifier with no exemption. + +These results are ordinary Copy values. This increment does not add must-use checking: callers can ignore a result under the same rules as any existing Copy-returning function. Applications that require successful writes should exhaustively match the result. General user modules, imported struct literals and generic result types remain separate work. + +## Verifier implications + +No new abstract state, transfer function or diagnostic code. The existing enum payload, exhaustive `enum.switch`, call typing, alias, lifetime, initialization and bounds rules apply. Imported enum values can appear in signatures, user fields, arrays and wrapper types under the same existing type-property rules. Shared inputs remain read-only; destinations require an exclusive slice. Module limits include all imported declarations. + +## Interpreter / runtime implications + +No new runtime primitive. Ordinary branches, integer widening, bounded shifts, bitwise operations, truncating byte casts, borrows and enum construction implement the APIs. Each capacity check precedes every access. Short results and successful values are identical in deterministic and hosted profiles. There are no library bounds, arithmetic, cast or shift traps for valid slices and scalar values; ordinary interpreter fuel limits still apply. Imports have no runtime initialization or heap allocation. + +## AIR changes + +None. Public enums lower to existing named Copy enums, constructors to `enum.make`, matches to `enum.switch` and functions to ordinary calls. Their full contracts remain those of spec 07/08. Generated names keep dots out of format-0 identifiers. No feature registration is needed because no AIR construct is introduced; the existing feature closure is emitted. + +## Valid example + +```aji +module example +import std.bytes; + +fn main() -> u32 +effects [] +{ + var wire: [u8; 6] = zero; + match std.bytes.write_u32_be(mut wire[1..5], 0x12345678) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + match std.bytes.read_u32_be(ref wire[1..5]) { + std.bytes.ReadU32::ok(value) => { return value; } + std.bytes.ReadU32::short_input => { return 0; } + } +} +``` + +This is checked by `source/quickref/std_endian.aji` and returns 305419896. `examples/std/endian.aji` is a runnable copy. + +## Rejected example + +```aji +module example +import std.bytes; + +fn main() -> u16 +effects [] +{ + return std.bytes.read_u16_le(b"\x34\x12"); +} +``` + +`E7005`: expected `u16`, found `std.bytes.ReadU16`. The caller must distinguish success from short input. Holding a shared borrow of the destination while passing an exclusive write argument is rejected with `E2101`; `endian_alias.aji` records the existing two alias diagnostics. Incorrect payload types are rejected in both source and AIR. + +## Diagnostics impact + +No new codes or registry entries. Existing `E7002` covers unknown/missing imports, types and variants; `E7005` wrong types/payloads or another enum; `E7004` missing arms; `E7006` duplicate/wildcard enum arms; `E2101` borrow conflicts. Malformed syntax remains `E7001`. Standard type fields display public source paths instead of generated identifiers. Unit tests check both direct and compound type fields. + +## Spec integration + +- Spec 15 §13: standard enum names, constructors/patterns, diagnostics and deterministic type/function mangling. +- Spec 16 §2.3: twelve signatures, four enums, byte order, capacity, mutation, failure and profile contracts. +- Reference grammar: qualified paths in type annotations, enum constructors and patterns. +- API reference and checked Quick Reference: ordinary enum result handling, explicit sub-slices and error repair. +- Source Reference Bundle: syntax rules and on-demand `library/std.md`. AIR bundle unchanged. + +## Compatibility and migration + +AIR format 0 and every existing AIR meaning remain unchanged. Programs without imports retain canonical lowering; the previous nine standard APIs keep their contracts. Importing `std.bytes` now composes twelve more functions and four enums. Public names do not collide with user short names; generated-name collisions use suffixes. A local `std` binding does not affect qualified standard resolution. Library path/source-span mapping remains intact. No migration is needed. + +## Agent complexity impact + +- New concepts: explicit width/order APIs and width-specific ordinary enum results; closed-registry qualified type names. Four enums and twelve function names are added to the public API, read on demand. +- New verifier state/instructions: none. No new ownership, allocation, lifetime, concurrency or capability obligation. +- New syntax forms: dotted paths in type positions and before the existing `::` constructor/pattern operator. No keyword or result-handling shorthand. Existing exhaustive enum matches suffice. +- Interactions: enum payload typing, Copy/type properties, signatures, field/array/wrapper types, canonical composition, feature closure, collision avoidance and source diagnostics. +- Repairability: stable names identify the required width, order and failure arm. Short writes cannot leave partially encoded records. Diagnostics expose source types instead of mangled AIR identifiers. Ignored Copy results remain a caller obligation; no compression benefit is claimed yet. +- Existing primitives suffice for every algorithm and result. The frontend only composes source declarations and resolves qualified names; no opaque intrinsic is needed. +- New source diagnostic codes: zero; existing codes cover the additional name/type/match cases. + +Measured against RFC 0016's bootstrap commit with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source`: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference (`QUICK.md`, includes navigation) | 5,777 → 6,000 (+3.9%) | 5,797 → 6,019 (+3.8%) | 5,948 → 6,189 (+4.1%) | +| Other source docs | 30,461 → 31,918 (+4.8%) | 30,546 → 32,001 (+4.8%) | 31,307 → 32,838 (+4.9%) | +| Full source docs without AIR | 36,238 → 37,918 (+4.6%) | 36,343 → 38,020 (+4.6%) | 37,255 → 39,027 (+4.8%) | +| AIR docs in the source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 | + +The on-demand library page grows from 1,346/1,347/1,406 to 2,533/2,532/2,654 tokens. Standalone AIR stays 160,797 bytes, 48 sections and 19 files. Incremental source growth is below the 10% warning threshold. The Quick Reference reaches its approximate 6k target; its new example spends 223 cl100k tokens on correct typed failure handling, while the signatures and detailed contracts remain on demand. Future API increments should avoid repeating full catalogs in the front door. + +Branch verification: `zig build`, `zig build test` (including checked Quick Reference excerpts and source diagnostic fields), full conformance (482 passed, zero failed/pending), formatting, source coverage (72/72), agent-reference and hosted file/stdin/TCP smoke tests pass. The executable example returns 305419896 without grants. All run fixtures execute twice for determinism. Twenty-six new tests cover each width/order, every short length, empty slices, maximal integers, every bit position, independently fixed byte vectors, offset/extra-byte preservation, compound type composition, symbol collisions and rejected payloads/matches/borrows. A source run returning the enum record matches hand-written AIR; an AIR wrong-payload fixture rejects with `E1001`. + +## Alternatives considered + +Capacity traps make recoverable protocol errors caller assertions. Boolean plus borrowed output requires an extra variable, mutable alias reasoning and a separate guarantee about unchanged output. A numeric sentinel cannot represent failure. A generic `Result` would be preferable once independently specified source generics exist; adding those now would enlarge this increment substantially. Three monomorphic read results keep success payloads width-correct with existing mechanisms. Runtime intrinsics would expand the trusted boundary for algorithms safe source already expresses. + +## Unresolved questions + +Q-028 records the short-buffer/result decision as resolved in this branch. Must-use results, general modules, imported structs and generics are separate design questions, not implicitly implemented. Q-027's existing empty byte-literal discrepancy is unchanged; empty input/output fixtures use zero-length sub-slices. diff --git a/docs/rfcs/0018-bounded-standard-operations.md b/docs/rfcs/0018-bounded-standard-operations.md new file mode 100644 index 0000000..2368528 --- /dev/null +++ b/docs/rfcs/0018-bounded-standard-operations.md @@ -0,0 +1,135 @@ +# RFC 0018: Bounded copy/search and recoverable unsigned arithmetic + +Status: Implemented +Scope: STD-1b, safe standard library APIs; existing source and AIR format 0 unchanged +Language version: 0.1 +Supersedes: — +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +The proposed spec, reference implementation and tests are integrated on the work branch for review. Only the owner changes an RFC to Accepted. RFCs 0016/0017 remain the historical records for imports and endian operations. + +## Motivation + +Storage and protocol code needs whole-input byte copy with capacity failure, substring lookup with an unambiguous empty-input result, and overflow-aware buffer sizing. Existing primitive copy and arithmetic trap on invalid capacity/overflow; manually repeating guards adds repair work. Standard functions can express these operations using existing verified source. + +This increment improves semantic explicitness, deterministic behavior, memory safety and implementation simplicity. It adds eight functions and three ordinary result enums, with no new language feature or verifier state. A reduction in model capability requirements remains an empirical hypothesis. + +## Precise invariant + +Copy accesses only supplied initialized slices and mutates exactly the source-length prefix of sufficient exclusive output. A short-output result leaves the entire destination unchanged and reads no source elements. Search only reads shared input. No borrowed value escapes, heap allocation occurs, resource is consumed, authority is created or task starts. Arithmetic returns a payload exactly when the mathematical result fits the operand type; neither overflow nor a zero multiplier traps. + +## Normative rule changes + +Integrated text is spec 16 §2.1.1/§2.4, with the primitive-versus-recoverable copy distinction clarified in spec 15 §6: + +- `std.bytes.copy(dst, src)` MUST return `WriteResult::short_output` before any element access when output is short. Success MUST copy the whole input into the output prefix and preserve the remainder. Empty input succeeds. Existing alias rules reject overlapping shared/exclusive borrows regardless of runtime capacity; this is not `memmove`. +- `find_slice(data, needle)` MUST return `FindResult::found(index)` at the first match or `not_found`. Empty needle MUST return `found(0)`, including empty data. A found offset may equal the data length and is not necessarily a readable index. No borrow is returned or retained. +- Splitting at the first separator composes that search with existing explicit slices or `split_at`. There is no split function returning an aggregate of borrows or implicit cursor. Empty separator gives an empty left part and the whole right part; repeated splitting requires a caller-chosen progress rule. +- `checked_add_u64`, `checked_sub_u64`, `checked_mul_u64` return `std.math.U64Result`; the `_usize` forms return `std.math.UsizeResult`. Both enums have `ok(value)` and `overflow`. Representability determines success; unsigned underflow is overflow. `usize` follows target width. +- Normal arithmetic still traps on overflow. Wrapping stays with `+%`, `-%`, `*%`; no synonymous library wrappers are added. Generalized widths, signed/saturating arithmetic and generics are outside this increment. + +## Verifier implications + +No new abstract state, transfer function, diagnostic or privilege. Existing slice initialization/lifetime, shared/exclusive alias, call typing and Copy enum payload/match rules apply. Capacity guards do not grant an alias exception. A disjoint `split_at` pair from one allocation can be copied; two sub-slices of the same parent retain the existing conservative overlap rule. Results are ordinary Copy values with no must-use checking. + +## Interpreter / runtime implications + +No runtime change. Copy checks capacity, then calls the existing primitive `slice.copy`. Search checks empty/oversize needles, bounds a scan by `data.len - needle.len`, and uses existing equality and sub-slices. It checks the final start before incrementing, avoiding an overflowing end-plus-one loop bound. Search has constant auxiliary storage and O(data length × needle length) worst-case byte comparisons. + +Unsigned arithmetic uses prechecks before checked operations: add checks available headroom, subtract compares operands, and multiply short-circuits the divisor check when its second operand is zero. The unsigned maximum is computed as `0 -% 1` in the operand type, without host constants or assumptions about pointer width. No implicit widening occurs. + +All APIs are safe `.aji` with `effects []`, no heap/authority/concurrency effect and identical deterministic/hosted behavior. Valid slices and scalar operands do not produce bounds, arithmetic, cast or shift traps. Interpreter fuel remains an environment limit and is not a returned library error; the unchanged-output guarantee applies to `short_output`, not interruption mid-execution. + +## AIR changes + +None. Functions lower to ordinary calls, branches, arithmetic, borrows, `slice.copy`, `enum.make` and `enum.switch`, under the existing published feature closure. There is no new instruction, type kind, feature entry or interpretation. AIR format 0 remains frozen. + +## Valid example + +```aji +module example +import std.bytes; +import std.math; + +fn encode(dst: slice_mut, data: slice) -> usize +effects [] +{ + match std.math.checked_add_usize(data.len, 1) { + std.math.UsizeResult::ok(total) => { + if total > dst.len { return 0; } + match std.bytes.copy(mut dst, ref data) { + std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; } + std.bytes.WriteResult::short_output => { return 0; } + } + } + std.math.UsizeResult::overflow => { return 0; } + } +} +``` + +`examples/std/bounded.aji` adds a main that encodes a zero-terminated byte record, searches its delimiter and verifies untouched output bytes. The conformance copy returns 10 without grants. `bounded_split.aji` checks first-separator composition, including empty inputs and separators. + +## Rejected example + +```aji +module example +import std.bytes; + +fn main() -> u8 +effects [] +{ + var buf: [u8; 4] = zero; + let result = std.bytes.copy(mut buf, ref buf); + return 0; +} +``` + +Existing `E2101` reports the conflicting shared borrow and the call's argument conflict. `bounded_copy_alias.aji` captures both diagnostics. Holding a shared borrow of the array and copying into its empty prefix is also rejected; runtime capacity checks do not weaken verification. + +## Diagnostics impact + +No new codes. Wrong operands/result payloads use `E7005` (AIR payload typing `E1001`); unknown/absent imports use `E7002`; incomplete matches use `E7004`; conflicting copy borrows use `E2101`. Existing diagnostic counts and source mapping remain unchanged. Capacity and overflow are result variants, not diagnostics or traps. + +## Spec integration + +- Spec 16 §2.1.1: six recoverable arithmetic functions, two result enums, exact representability and operator policy. +- Spec 16 §2.4: copy, search result enum, first-separator composition, capacity/empty/alias/profile contracts. +- Spec 15 §6: distinguishes primitive trapping copy from recoverable byte copy; no new grammar or lowering rule. +- API reference and Quick Reference: signatures, ordinary result handling, source example and on-demand contracts. +- Plan and Q-029: bounded split/arithmetic decisions and remaining general-module/generic work. + +## Compatibility and migration + +No source/AIR syntax, ownership, alias, effect, capability, runtime or existing API meaning changes. Existing `find` retains its single-byte length sentinel, including absence on empty data. Substring search uses an enum because an empty needle can successfully match empty data at offset zero. The distinct operations are intentionally documented together, without silently changing `find`'s result type. Import composition now includes eight additional functions and three enums; existing whole-module composition and collision-free names still apply. No migration required. + +## Agent complexity impact + +- New concepts: bounded whole-input copy; first substring offset including empty needles; recoverable scalar overflow. Results reuse ordinary enum handling. +- New verifier state: none. No new borrow return/lifetime or cleanup obligation. +- New syntax/instructions: none. Eight monomorphic function names and three ordinary result enum names are added, on demand. +- Interactions: slice aliases, disjoint split borrows, sub-slice bounds, Copy results, qualified standard type names, target-sized integers, short-circuit evaluation and interpreter fuel. +- Repairability: short copies cannot partially overwrite records; arithmetic sizing errors become typed results; search distinguishes absence from an empty match. Explicit splitting keeps borrow scopes visible. Callers can still ignore Copy results under existing rules; no measured compression claim is made. +- Existing primitives express all algorithms. No compiler change or trusted intrinsic is needed. Wrapping operators already suffice, so wrappers are omitted. +- New source diagnostic codes: zero. General width/signed APIs wait for a separate contract rather than proliferating wrappers. +- Quick Reference adds only a short routing paragraph; the signature catalog and full contracts remain in on-demand `library/std.md`. + +Measured against the endian increment (`a2ca293`) with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source`: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference (`QUICK.md`, includes navigation) | 6,000 → 6,082 (+1.4%) | 6,019 → 6,102 (+1.4%) | 6,189 → 6,272 (+1.3%) | +| Other source docs | 31,918 → 33,628 (+5.4%) | 32,001 → 33,718 (+5.4%) | 32,838 → 34,572 (+5.3%) | +| Full source docs without AIR | 37,918 → 39,710 (+4.7%) | 38,020 → 39,820 (+4.7%) | 39,027 → 40,844 (+4.7%) | +| AIR docs in the source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 | + +Standalone AIR remains 160,797 bytes, 48 sections and 19 files. Incremental source bundle growth stays below the 10% warning threshold. The library page grows from 2,533/2,532/2,654 to 4,223/4,229/4,367 tokens: eight APIs need capacity, empty-match, split progress, target-width and overflow contracts, plus one checked sizing/copy example. This is on-demand documentation; the Quick Reference only gains an 82-token routing paragraph (cl100k) instead of a repeated arithmetic catalog. Its approximately 6k target remains a front-door constraint for future increments. + +Branch checks: build, unit tests/Quick Reference extraction, full conformance (505 passed, zero failed/pending), formatting, source coverage (72/72), agent-reference and hosted file/stdin/TCP smoke all pass. The bounded example returns 10 without grants. Twenty-three new conformance tests exercise all 81 length/capacity pairs through eight, disjoint same-allocation copy, overlapping/empty short-output aliases, 428 substring cases, seven split cases and 320 independently computed arithmetic pairs through both u64 and usize APIs. Arithmetic fixtures include zero multipliers, underflow, addition headroom and multiplication near limits, plus seeded fixed random inputs. They use the interpreter's default `air64`; no 32-bit runtime test is claimed. Copy and arithmetic source runs match hand-written AIR; an AIR wrong-payload fixture rejects with `E1001`. All run tests execute twice for determinism, and accepted source lowers canonically and deterministically. + +## Alternatives considered + +An ambiguous length sentinel for substring search needs an extra empty-needle convention from the caller. A numeric result enum directly distinguishes absence. A split iterator or returned slice aggregate adds lifetime state and cursor semantics before imported structs/borrowed aggregates are specified; explicit existing slicing suffices. A silent partial copy makes output validity caller-dependent. A memmove wrapper cannot bypass the existing alias rule. Duplicating wrapping operators expands the API without changing the contract. Adding generics or a generic Result to this increment would substantially enlarge its semantic surface. + +## Unresolved questions + +Q-029 records these API decisions as resolved on the branch. General generics, imported structs, borrowed aggregates and must-use values remain separate work. The reference interpreter currently executes `air64`; arithmetic fixtures use that target, while the usize implementation computes its limit in target width. Q-027's empty byte-literal gap is unchanged; empty tests use existing zero-length slices. diff --git a/docs/rfcs/0019-standard-text-encodings.md b/docs/rfcs/0019-standard-text-encodings.md new file mode 100644 index 0000000..3f402f5 --- /dev/null +++ b/docs/rfcs/0019-standard-text-encodings.md @@ -0,0 +1,133 @@ +# RFC 0019: UTF-8 and supplied-buffer hex/Base64 + +Status: Implemented +Scope: STD-2a, safe standard modules; existing source syntax and AIR format 0 unchanged +Language version: 0.1 +Supersedes: — +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +This work branch contains the proposed specification, implementation and tests for review. Only the owner changes the RFC to Accepted. Formatting is a separate STD-2b increment. + +## Motivation + +CLI, protocol and storage code needs to validate text and transform arbitrary bytes without hidden allocation. UTF-8 iteration can use existing scalar/offset values, while caller-provided encoding buffers make capacity and mutation explicit. A bad trailing byte must not leave a partially decoded record that the caller needs to reason about. + +The increment improves semantic explicitness, deterministic behavior, memory safety and implementation simplicity. Its Model Capability Compression benefit is a hypothesis, not inferred from fixtures. Three modules add six functions and six ordinary Copy enums; no runtime codec or new language mechanism is needed. + +## Precise invariant + +UTF-8 only reads shared input and returns scalar/count or validation offset values. Encoding operations only access initialized supplied slices; successful writes modify exactly an output prefix. Returned invalid-input/short-output errors leave the entire destination unchanged. No borrow escapes, heap allocation occurs, owner/resource is consumed, authority is created or task starts. Fixed local tables are frame storage. Ordinary shared/exclusive alias rules apply on every path. + +## Normative rule changes + +Complete proposed contracts are integrated in spec 16 §2.5–§2.7; the closed registry/source-path table in §2 now lists five modules. Spec 15 §13 references that table without changing resolution rules. + +- `std.utf8.next(src)` MUST return `ok(scalar, consumed)`, `end` for empty input or `invalid_input` for a malformed/truncated first sequence. It checks only that sequence; caller offsets/sub-slices express iteration. +- `validate(src)` MUST validate all input and return `invalid_input(offset)` at the leading byte of the first bad/truncated sequence, or `ok`. Empty input succeeds. The scalar domain excludes surrogates and values above U+10FFFF; no normalization or replacement is performed. +- Hex encode MUST emit lowercase ASCII digits; decode MUST accept even-length ASCII hex in either letter case, with no prefixes, separators or whitespace. +- Base64 encode/decode MUST use canonical padded standard encoding. Decode rejects incomplete groups, nonalphabet bytes, misplaced/extra padding and nonzero unused bits. URL-safe/permissive modes are not part of the contract. +- Encoding MUST precheck the full output size without intermediate overflow. Decode MUST validate all input before checking capacity or writing. Invalid input MUST win over short output; both returned errors MUST preserve the entire destination. +- `ok(count)` identifies the written prefix; remaining output stays unchanged, no terminator is appended, and empty input succeeds with count zero even with empty output. A mathematical encoded size exceeding usize/capacity is `short_output`. + +Unicode scalar/byte rules were checked against [RFC 3629 §3/§4](https://www.rfc-editor.org/rfc/rfc3629.html#section-3). Base64 alphabet/padding and the deliberate strict unused-bit policy follow [RFC 4648 §3.5/§4](https://www.rfc-editor.org/rfc/rfc4648.html#section-3.5). Hex lowercase output is an explicit Aji choice; decode also accepts uppercase public vectors. + +## Verifier implications + +No new abstract state, transfer function, diagnostic code or trusted exemption. Existing call, slice initialization/lifetime, bounds, shared/exclusive alias and enum payload/match rules apply. Size guards do not discharge alias checks. Overlap rejects; proven disjoint `split_at` siblings from one allocation work. All results are ordinary Copy values, with existing qualified type/constructor/pattern syntax and no must-use rule. + +## Interpreter / runtime implications + +No runtime primitive or profile change. Ordinary source branches, shifts/masks, fixed frame arrays, slice accesses and enums implement the algorithms. UTF-8 checks remaining capacity before continuation accesses and restricted second-byte ranges before scalar assembly. Validation advances only by a successful 1..4-byte count bounded by the remaining slice. + +Hex encode checks `src.len <= dst.len / 2` before multiplying. Base64 encode checks whole groups against `dst.len / 4`, then tail capacity before summing. This avoids overflow in `src.len + 2`, group multiplication or output offsets. Decode first validates digits/groups/padding/unused bits, computes the bounded decoded count, then checks capacity before writing. Padding is never interpreted as a data symbol. + +Reference work is O(input length), with constant auxiliary storage: a 16- or 64-byte alphabet and/or 256-byte inverse map. Frame storage is explicit source; no heap or hidden cursor exists. All functions declare `effects []`, are deterministic in both profiles and do not produce bounds/arithmetic/cast/shift traps for valid slices. Malformed/truncated input and capacity failure are ordinary results. Fuel exhaustion remains an environment outcome; destination preservation covers returned errors, not interruption mid-operation. + +## AIR changes + +None. Algorithms use existing calls, arithmetic, arrays, ownership/borrows and `enum.make`/`enum.switch`; the normal combined feature closure is emitted. There is no opcode, type kind, instruction contract, feature registry entry or altered format-0 meaning. Three new registry entries embed safe source through the existing frontend and verifier. + +## Valid example + +```aji +module example +import std.utf8; + +fn first(src: slice) -> u32 +effects [] +{ + match std.utf8.next(ref src) { + std.utf8.NextResult::ok(scalar, count) => { return scalar; } + std.utf8.NextResult::end => { return 0; } + std.utf8.NextResult::invalid_input => { return 0; } + } +} +``` + +`examples/std/text.aji` combines hex decoding, UTF-8 validation, Base64 encoding and scalar decoding, returning 8364 (U+20AC). Its conformance copy is `text_example.aji`, and the API reference includes that checked program. `text_utf8_iteration.aji` demonstrates explicit offsets and four scalar widths. `text_disjoint.aji` encodes/decodes between disjoint halves of one allocation. + +## Rejected example + +```aji +module example +import std.encoding.hex; + +fn main() -> u8 +effects [] +{ + var buf: [u8; 4] = zero; + let result = std.encoding.hex.decode(mut buf, ref buf); + return 0; +} +``` + +Existing `E2101` reports the conflicting borrow and call argument conflict; `text_hex_alias.aji` captures both. Base64 encode has the same negative test. Wrong result payloads and passing the hex result as a Base64 result reject with `E7005`; imported modules keep distinct enum identities. + +## Diagnostics impact + +No new codes. Wrong operands/payloads use `E7005` (AIR payload test `E1001`); missing/unknown imports use `E7002`; incomplete result matches use `E7004`; conflicting input/output borrows use `E2101`. Source diagnostic types and provenance retain public paths. Invalid byte sequences are returned variants, not compiler diagnostics or traps. Existing enum wildcard/duplicate rules continue unchanged. + +## Spec integration + +- Spec 16 §2: five-module registry and stable bundled source paths. +- Spec 16 §2.5–§2.7: UTF-8 scalar/offset rules, codec signatures, capacity/validation/mutation, complexity, safety and compatibility. +- Spec 15 §13: provenance refers to the registry table; no new syntax/lowering rule. +- Reference/Quick Reference/bundle navigation: on-demand API contracts and checked example, with existing result handling. +- Plan STD-2a/2b and Q-030: this scope is complete only after checks; supplied-buffer formatting remains pending. + +## Compatibility and migration + +AIR format 0, source syntax, existing APIs, verifier/runtime rules and capability/effect contracts retain their meanings. Unknown imports now recognize three additional compiler-pinned modules; no filesystem/network/package resolution or dependencies are introduced. Each module is self-contained and uses full standard type paths. Lexicographic composition, collision suffixes and stable diagnostics work at four-component paths; unit tests cover all five imports in different orders and directory names. No migration is required. Q-027's empty byte literal gap remains; empty fixtures use zero-length slices. + +## Agent complexity impact + +- New concepts: scalar-level UTF-8 with explicit consumed count/validation offset; caller-output codec operations; strict canonical Base64 acceptance. No owning string/iterator or borrowed aggregate. +- New verifier state: none. No additional lifetime, alias, allocation, capability, cleanup or concurrency obligation. +- New syntax/instructions: none. Six function names and six ordinary Copy enum names are read on demand; nested standard paths use the existing parser/linker. +- Interactions: existing enum payloads/exhaustiveness, slices/sub-slices/disjoint splits, frame arrays, checked arithmetic/short-circuit guards, compiler-pinned imports and fuel. +- Repairability: a returned decode failure has no partial output state; empty input and valid zero-length output are explicit; UTF-8 error offsets identify a sequence start. Callers must still handle/check Copy results under existing rules. No measured model capability reduction is claimed. +- Existing primitives suffice; pure source avoids a runtime codec trusted boundary. Scalar/offset iteration and fixed tables avoid adding iterator machinery, generics or allocation contracts. +- New source diagnostics: zero. Quick Reference adds a routing paragraph; complete signatures, malformed-input/capacity policy and a checked example stay in on-demand `library/std.md`. + +Measured against STD-1b (`6397a31`) with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source`: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference (`QUICK.md`, includes navigation) | 6,082 → 6,163 (+1.3%) | 6,102 → 6,184 (+1.3%) | 6,272 → 6,356 (+1.3%) | +| Other source docs | 33,628 → 36,042 (+7.2%) | 33,718 → 36,159 (+7.2%) | 34,572 → 37,048 (+7.2%) | +| Full source docs without AIR | 39,710 → 42,205 (+6.3%) | 39,820 → 42,343 (+6.3%) | 40,844 → 43,404 (+6.3%) | +| AIR docs in the source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 | + +Standalone AIR stays 160,797 bytes, 48 sections and 19 files. Incremental source growth is below the 10% warning threshold. The on-demand library page grows from 4,223/4,229/4,367 to 6,644/6,677/6,849 tokens: six APIs require scalar validity, first-sequence versus whole-input handling, exact error offsets, canonical byte acceptance, capacity priority and unchanged-output contracts, plus one checked composition example. Quick Reference only adds a routing paragraph and changes the navigation row; catalogs remain on demand. + +Cumulatively since the pre-stdlib source baseline in RFC 0016, source docs excluding AIR grow from 33,981 to 42,205 cl100k tokens (+24.2%), crossing the 20% review line. This growth is explicit for owner review: the five-module library has 35 functions and 13 result enums, all algorithm contracts live on demand, and there is no new verifier state, syntax or AIR documentation. The Quick Reference grows from 5,511 to 6,163 (+11.8%); future increments should split/selectively expose library references instead of extending its catalog. Documentation growth is not evidence of model capability compression; API/read/repair costs still need empirical review. + +Branch checks: build, unit/Quick Reference checks, full conformance (529 passed, zero failed/pending), formatting, source coverage (72/72), agent-reference and hosted file/stdin/TCP smoke pass. The executable text example returns 8364 without grants. Twenty-four new tests cover all 256 single bytes for UTF-8, 139 fixed valid and 608 malformed/prefixed scalar-sequence cases, four-width explicit iteration, 276 independent valid vectors per encoding (including empty and every single byte), 242 malformed hex and 296 malformed Base64 vectors, every relevant capacity, untouched suffixes, invalid-input precedence, noncanonical pad bits, proven disjoint same-allocation operations, alias rejection and module/type collision rules. Source runs compare with hand-written AIR scalar/encoded-byte fixtures; AIR payload typing rejects with `E1001`. All run tests execute twice for determinism. Unit checks compare canonical lowering for all five imports in different orders/directories and preserve all bundled source paths without heap/capability/intrinsic instructions. + +## Alternatives considered + +Replacement decoding hides malformed input; streaming recovery needs a separate explicit state contract. Silent partial output makes post-failure byte validity caller-dependent. Permissive Base64, URL-safe switches and optional padding multiply accepted forms; they can be separate independently justified APIs later. Hidden growing strings/iterators need allocation and lifetime features beyond this step. Returning a borrow or aggregate iterator is unnecessary when a scalar and consumed count suffice. Runtime intrinsics add trusted code for operations safe source can already express. + +## Unresolved questions + +Q-030 records the codec policy as resolved on this branch. Streaming UTF-8/codecs, URL-safe Base64, Unicode normalization/properties, owning strings, generic results and must-use values remain separate work. STD-2b still needs a minimal formatting contract; this RFC does not claim formatting is implemented. diff --git a/docs/rfcs/0020-supplied-buffer-integer-formatting.md b/docs/rfcs/0020-supplied-buffer-integer-formatting.md new file mode 100644 index 0000000..67502c8 --- /dev/null +++ b/docs/rfcs/0020-supplied-buffer-integer-formatting.md @@ -0,0 +1,83 @@ +# RFC 0020: Supplied-buffer integer formatting + +Status: Implemented +Scope: STD-2b, safe standard source; language 0.1 and AIR format 0 unchanged +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +This branch contains the proposed spec, implementation and tests. Owner acceptance remains separate from branch implementation. + +## Motivation and contract + +Bounded CLI/storage records need decimal integer text without allocating or parsing format strings. Four monomorphic `std.fmt.write_u64/i64/usize/isize` functions and one Copy `WriteResult { ok(usize), short_output }` suffice. Full contracts are integrated in spec 16 §2.8; the registry adds `std.fmt` at `std/fmt.aji`. + +Output is exact decimal ASCII, with a sign only for negative values, no leading zeroes except zero itself, and no terminator. A successful count includes the sign; only the output prefix changes. Insufficient capacity, including an empty destination, returns `short_output` before writing and preserves the whole destination. All values are supported, including signed minima. Existing byte copy and explicit caller offsets compose records. Each call's failure guarantee does not roll back earlier successful calls. + +The increment improves deterministic behavior, explicit failure and implementation simplicity. Model Capability Compression remains an empirical hypothesis. General format strings, radix switches, floats, wider integers, text parsing, owning strings and writer protocols are outside this step. + +## Memory and verifier invariant + +Only the provided exclusive initialized slice is written, within its bounds. No borrow escapes, owner/resource is consumed, heap is allocated or authority/task is created. Existing initialization, call, shared/exclusive alias, lifetime, bounds and enum rules enforce this invariant. Live conflicting borrows reject even for a call that would return short output. No new verifier state, transfer function or privilege exists. + +## Runtime and deterministic behavior + +Safe source counts decimal digits by unsigned division before checking capacity. Signed magnitude is computed as unsigned `-(value + 1) + 1` on the negative path, avoiding direct negation of the signed minimum; nonnegative signed values convert directly. The sign is counted before capacity checking. Successful writes fill the digits from right to left, preserving the suffix. No temporary digit buffer, table or heap is needed; auxiliary scalar storage is constant and work is O(decimal digit count). + +All functions declare `effects []` and use ordinary integer operations, slices, branches and enums. No AIR instruction/feature, trusted implementation, runtime rule or profile distinction is added. Bounds, arithmetic and checked conversions are valid for every input value and supplied slice. Interpreter fuel exhaustion remains an environment outcome, outside the returned-error preservation guarantee. + +## Valid example + +```aji +module example +import std.fmt; +fn main() -> std.fmt.WriteResult effects [] { + var text: [u8; 3] = zero; + return std.fmt.write_i64(mut text, -42); +} +``` + +This produces bytes `-42` and `ok(3)`. `examples/std/format.aji` and its conformance copy compose `value=-42 count=7` with explicit offsets and return 17. Independent scalar fixtures check all capacities, untouched guard/suffix bytes, zero, signed minima, unsigned maxima and decimal/binary boundaries. A disjoint split with a live borrow of the other half is valid. + +## Rejected example and diagnostics + +```aji +module example +import std.fmt; +fn main() -> u8 effects [] { + var text: [u8; 4] = zero; + ref held = text; + let result = std.fmt.write_i64(mut text[0..0], -1); + return held[0]; +} +``` + +The conflicting exclusive borrow rejects with existing `E2101`, despite short capacity. Wrong destination/value/enum payload types use `E7005`; unknown/missing imports use `E7002`; incomplete matches use `E7004`. No new code or diagnostic envelope is needed. The result is Copy and introduces no must-use rule. A hand-written AIR result fixture checks the ordinary enum payload/count independently of source lowering. + +## Compatibility and spec integration + +Spec 16 §2 and §2.8 add the sixth closed-registry module and complete formatting contract. Spec 15 §13 resolution stays unchanged; Q-031 records the decision. Reference, Quick Reference navigation, examples and plan STD-2b expose the API through the existing source bundle. Existing source/AIR and library APIs preserve their meanings; importing grants no authority. Canonical ordering, collision handling and source provenance use existing linking; unit checks cover all six modules in different orders/directories. No migration is required. + +## Agent complexity impact + +- New concepts: a supplied-buffer decimal writer and its byte count; the existing explicit capacity/result convention is reused. +- New verifier state, syntax, AIR instructions, effects, capabilities and diagnostics: zero. +- API additions: four scalar function names and one ordinary Copy enum, documented on demand. Smaller widths explicitly convert to an appropriate writer. There is no generic specialization, retained offset or cleanup obligation. +- Interactions: target-width integers, checked conversion, signed limits, slice offsets, exclusive borrows, exhaustive enum matches and interpreter fuel. +- Repairability: a short write preserves every destination byte, all numeric inputs are valid, and exact byte count exposes the next caller offset. Whole-record transactionality is not implied. +- Existing primitives suffice; a runtime formatter or format-string language would add complexity without improving this contract. + +Measured against the completed STD-2a worktree with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source`: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference | 6,163 → 6,220 (+0.9%) | 6,184 → 6,241 (+0.9%) | 6,356 → 6,415 (+0.9%) | +| Other source docs | 36,042 → 37,128 (+3.0%) | 36,159 → 37,248 (+3.0%) | 37,048 → 38,154 (+3.0%) | +| Full source docs without AIR | 42,205 → 43,348 (+2.7%) | 42,343 → 43,489 (+2.7%) | 43,404 → 44,569 (+2.7%) | +| AIR docs in source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 | + +Standalone AIR remains 160,797 bytes, 48 sections and 19 files. The on-demand library page grows from 6,644/6,677/6,849 to 7,730/7,766/7,955 tokens: the decimal grammar, signed/target limits, capacity/failure and append composition are explicit, with one checked complete example. Quick Reference grows by only a routing sentence. Cumulative source growth from the pre-stdlib 33,981 cl100k baseline is +27.6% (43,348); Quick Reference grows from 5,511 to 6,220 (+12.9%). The existing 20% review crossing stays explicit for owner review, without claiming model capability compression. Future library-reference splitting/selective reading remains the plan; this change adds no source grammar or AIR documentation. + +Branch checks: `zig build`, `zig build test`, full conformance (544 passed, zero failed/pending), `zig fmt --check build.zig build.zig.zon src tools tests/extended`, source coverage (72/72), agent-reference and hosted file/stdin/TCP smoke pass. The executable formatting example returns 17 without grants. Fifteen new conformance files (seven source runs, seven source rejections, one AIR run) cover 523 unsigned and 984 signed independent decimal vectors, each through both fixed/target-width APIs and all capacities 0..22. All source runs execute twice for deterministic outcomes. Target-width vectors guard conversions against the target limits; the reference interpreter currently runs air64. Zero/min/max, powers of ten/two and neighbors, every small magnitude, seeded inputs, untouched guard/suffix bytes, short-output alias rejection, names/types/payloads, exhaustive matches, disjoint live borrows and source/AIR result equivalence pass. Canonical import order/provenance checks cover all six modules without heap/capability/intrinsic instructions. + +## Alternatives and remaining work + +An unchecked signed negation fails at the minimum value. Writing before discovering short capacity creates partial record state. Returning only a count/sentinel hides failure, and returning an output borrow adds unnecessary lifetime state. A format-string parser, radix/configuration object, public sizing helpers or synonymous append variants multiply APIs. Decimal writers plus existing copy and explicit offsets suffice for this step. Owning collections still depend on general modules, generics and `linear_aggregates`; completing STD-2b does not remove those gates. diff --git a/docs/rfcs/0021-package-source-modules.md b/docs/rfcs/0021-package-source-modules.md new file mode 100644 index 0000000..66bec24 --- /dev/null +++ b/docs/rfcs/0021-package-source-modules.md @@ -0,0 +1,118 @@ +# RFC 0021: Explicit package source modules + +Status: Implemented +Scope: STD-3 / P6-3; source language 0.1, AIR format 0 unchanged +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +The branch contains the proposed normative text, implementation and tests. Only the language owner changes RFC acceptance status. + +## Motivation and decision + +Reusable library types need module identity, local name binding and explicit compiler inputs before generics or owning collections can have stable contracts. Extend the existing compiler-pinned standard import mechanism to an explicit source provider. The CLI obtains this provider solely from a selected manifest's `[modules]` map; the frontend accepts source bytes and diagnostic paths, without filesystem access. General package dependency resolution is separate work. + +Spec 12 §1.3 defines the manifest and loading contract; spec 15 §14 defines the graph and namespace rules. The standard registry remains compiler-pinned and cannot be shadowed. Every declaration and field is available through a direct import. All reachable declarations, including unused helpers, lower and verify. There are no aliases, re-exports, visibility modifiers or executable module initialization. + +Imports form an acyclic graph. Header mismatch, duplicate imports/mappings and cycles reject; unreachable mapped files must be readable explicit inputs but are not parsed. Fixed limits are 1,024 mapped modules, graph depth 256, 1 MiB manifest and 64 MiB aggregate source snapshot. Cached graph heights count shared tails toward the depth limit. Modules append in lexicographic order, declarations in source order, using existing collision-free AIR mangling. Entry AIR names remain unchanged; only its unqualified `main` is the entry. + +Each module sees its own short names and directly imported full names. Linked transitive declarations do not become name-visible. A function can return a type inferred by its caller without the caller importing that type's module, but explicitly naming/constructing it requires a direct import. Qualified names resolve independently of local values with the same prefix. Module identity is carried separately from diagnostic filenames, so identical file labels cannot alter binding. Imported function `main` is an ordinary qualified function. + +Qualified struct literals use `app.model.Pair { left: 20, right: 22 }`, retaining the existing uppercase-final-component and condition-brace grammar rules. `task.spawn(s, app.work.run, args)` resolves a static function and emits the existing `task.spawn` instruction with its actual mangled AIR name. Built-in namespaces remain reserved for provider bindings; legacy entry names and built-in precedence stay compatible. + +## Memory, ownership and concurrency invariant + +Importing does not create authority, allocate program heap, retain borrows, share mutable storage, change resource consumption or introduce implicit cleanup. Every cross-module call has the same explicit signature and ownership/effect obligations as a local call. Named linear arguments still require `move`; mutable borrows remain exclusive and within lifetime; task lends remain unavailable until join; all linear values/resources are consumed on every path. + +## Verifier rule + +The frontend binds nominal types and static functions, then submits one combined ordinary AIR module. The existing type, call, initialization, alias, lifetime, resource, effect, Send/Share and task transfer functions apply unchanged. Imported code is never trusted simply because it is imported. Every reachable function is checked even if unused. No new verifier state, transfer function, AIR instruction or feature is introduced; the combined module declares existing feature dependency closure. Format-0 meaning is unchanged. + +## Runtime rule and deterministic behavior + +No runtime module loader, dispatch, initialization or new primitive exists. The interpreter executes ordinary mangled function calls, struct/enum operations and structured tasks. The same explicit source bytes and bindings produce identical canonical AIR across mapping/import orders, directories, diagnostic filenames and execution profiles. First graph errors follow source import order. Imported diagnostics and traps name the supplied source file. Existing interpreter fuel, deterministic scheduler and hosted profiles remain unchanged. + +The CLI snapshots explicit package input files relative to the selected manifest directory. Portable `.aji` paths reject absolute paths, empty/dot/parent components, backslashes, colons and NUL. Descent keeps directory handles open and uses no-follow opens; source leaves must be regular files, checked before open and again on their handles. Symlinks, directories and static pipes reject rather than execute or block on input. These checks do not promise an atomic filesystem snapshot under concurrent writes; compilation is deterministic from the bytes actually read. Legacy manifests without `[modules]` retain their loading contract. + +Check/lower/report select source inputs without instantiating grants. Run/explore merge only explicitly selected manifest grants and command-line overrides. A file-only command never discovers a manifest. `lower --stats` compares entry source bytes against the combined AIR; it is explicitly not a whole-package compression metric. + +## Valid examples + +`examples/modules/aji.toml` maps `app.model` to `model.aji`. The model defines a plain Copy struct and an ordinary function: + +```aji +module app.model +struct Pair { left: u64, right: u64 } +fn total(pair: Pair) -> u64 effects [] { return pair.left + pair.right; } +``` + +```aji +module app.entry +import app.model; +fn main() -> u64 effects [] { + let pair = app.model.Pair { left: 20, right: 22 }; + return app.model.total(pair); +} +``` + +`aji run --fuel 1000000 --manifest examples/modules/aji.toml` returns 42 without grants. Source conformance also passes an owner with explicit `move` to an imported disposal function and lends disjoint slices to two qualified task workers. The latter has a hand-written AIR twin and deterministic/stress schedule coverage. + +## Rejected examples and diagnostics + +With the same mapping, constructing `app.model.Pair` without a direct `import app.model;` is `E7002`; linking it through another module does not grant name visibility. Repeatedly lending one mutable buffer to qualified workers rejects with the existing race code: + +```aji +module app.entry +import app.workers; +fn main() -> u64 effects [task.spawn] { + var buf: [u64; 2] = zero; + { + mut s = buf; + scope sc { + let a = task.spawn(sc, app.workers.bump, s); + let b = task.spawn(sc, app.workers.bump, s); + task.join(move a); + task.join(move b); + } + } + return buf[0]; +} +``` + +The independently checked fixture rejects `E4101`. Borrow conflicts reject `E2101`; omitted owner moves use `E7003`; absent declared effects use `E3101`. Names/imports use `E7002`; graph/header/duplicate/input-depth errors use `E7006`; source syntax uses `E7001` with expected/found fields at the imported source. Type mismatch remains `E7005`/`E1001`. CLI manifest/path/I/O/budget errors use stderr and exit 2 before verification; source rejection uses JSON Lines and exit 1. No new diagnostic code or envelope is added. + +## Compatibility and integration + +Spec 15 §2, §5, §7, §11, §13–§14 and spec 12 §1 integrate the rules. Reference grammar, Quick Reference, source bundle, Q-032 and both implementation plans track the increment. The six standard modules still expose 39 functions and 14 ordinary enums, with no API change. Existing file-only, AIR-only, standard-only and legacy-manifest programs preserve meaning and lowering. Previously unknown package names become valid only with explicit inputs. Short names remain local; distinct module types are nominally different. No migration or semantics-changing flag is needed. + +## Agent complexity impact + +- New concepts: explicit module-to-file inputs, module-local short names, direct qualified visibility and an acyclic source graph. All declarations are available; there is no separate export list or privacy state. +- Source forms: existing `import path;`, qualified calls/types/enum variants extend to package modules; qualified struct literals and a qualified static worker are supported. Manifest adds one `[modules]` map. No new source keyword, lifetime/ownership syntax, AIR syntax, effect, capability or diagnostic code. +- Frontend state: module identity on spans, direct-import scope table, graph visit/cache/depth state and existing nominal type/static signature binding. Verifier/runtime state: none. +- Interactions: structs/enums/arrays, local functions, std imports, collision handling, borrow projections, owner moves, effectful calls, task return types and lent buffers. Imported files remain explicit untrusted source inputs through the ordinary verifier. +- Repairability: missing imports, cycles, header mismatch and inaccessible members have stable diagnostics; imported source locations point to the actual repair file. No ambient resolution, transitive namespace effects, initialization order or privileged library magic must be reasoned about. +- Existing AIR primitives suffice. Textual source concatenation would lose scope and nominal identity; a runtime loader or a new AIR module instruction would add trusted complexity without improving this contract. Generics and linear aggregates remain independent prerequisites for owning containers. + +The source bundle adds an on-demand `language/modules.md` containing the two normative contracts; Quick Reference gives the manifest, one checked source example and navigation. No additional AIR documentation is needed. Measurements and final checks are recorded below. + +## Alternatives and remaining work + +Convention-based file lookup, parent manifest search and environment paths hide compiler inputs. Transitive visibility or import aliases add ambiguous bindings; private/public modifiers and re-exports add concepts before the minimal library need demands them. Lazy runtime loading adds authority and initialization ordering. Dependency fetching and lockfiles require their own package tooling contract. STD-4/P6-4 next addresses deterministic generics and structural constraints; owning collections also require a separate vertical linear-aggregates feature. + +## Documentation measurements + +Measured against STD-2b with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source`: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference | 6,220 → 6,501 (+4.5%) | 6,241 → 6,522 (+4.5%) | 6,415 → 6,704 (+4.5%) | +| Other source docs | 37,128 → 38,822 (+4.6%) | 37,248 → 38,940 (+4.5%) | 38,154 → 39,889 (+4.5%) | +| Full source docs without AIR | 43,348 → 45,323 (+4.6%) | 43,489 → 45,462 (+4.5%) | 44,569 → 46,593 (+4.5%) | +| AIR docs in source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 | + +Standalone AIR remains 160,797 bytes, 48 sections and 19 files. The new module page is 1,566/1,567/1,599 tokens; library/std.md remains 7,730/7,766/7,955. Front-door growth is 281/281/289 tokens. The precise graph, type binding, input bounds and package loading contracts live on demand. Cumulative cl100k growth since pre-stdlib is 33,981 → 45,323 (+33.4%) for full source docs and 5,511 → 6,501 (+18.0%) for Quick Reference. The existing 20% source-doc review crossing remains explicit for owner review. The additional cost buys deterministic modules and nominal types for reusable libraries; it does not establish empirical Model Capability Compression. API-reference splitting and selective reading remain necessary as std grows. + +## Branch validation + +`zig build`, `zig build test`, full conformance (579 passed, zero failed/pending), `zig fmt --check build.zig build.zig.zon src tools tests/extended`, source coverage (76/76), agent-reference, hosted file/stdin/TCP smoke and package CLI integration (36 checks) pass. The module example returns 42. The 35 added conformance cases include source runs/rejections, two hand-written AIR tests and the checked Quick Reference example. All source runs check canonical repeat lowering and deterministic repeat execution. Qualified workers additionally pass 32 schedule-stress seeds across quanta 1, 2 and 7; mutable lends, explicit joins and repeated-lend rejection use existing rules. + +Unit checks cover provider/import-order independence, nominal types when diagnostic file labels coincide, imported syntax/unused-function verifier provenance, bounded shared-tail graphs and names longer than the built-in path buffer. Conformance covers local binding collisions, imported `main`, qualified types/struct fields/enums, lack of short/transitive names, effect/owner/alias/race rejection, header mismatch, duplicate maps/imports/members, cycles, syntax, absent inputs and unreachable malformed sources. CLI checks cover all five commands, grants and overrides, hosted result/output behavior, source trap locations, no ambient manifest discovery, forbidden path components, leaf/ancestor/entry symlinks, nonregular files and aggregate source limits. The integration script is included in CI. No private held-out evaluation material was consulted or changed. diff --git a/docs/rfcs/0022-explicit-source-generics.md b/docs/rfcs/0022-explicit-source-generics.md new file mode 100644 index 0000000..1aa1883 --- /dev/null +++ b/docs/rfcs/0022-explicit-source-generics.md @@ -0,0 +1,103 @@ +# RFC 0022: Explicit source generics and Copy option/result + +Status: Implemented +Scope: STD-4 / P6-4; source language 0.1, AIR format 0 unchanged +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +This branch contains proposed normative text, implementation and tests. Owner acceptance remains separate from branch implementation. + +## Motivation and contract + +General modules supply reusable nominal types; generic functions/types now remove monomorphic duplication without adding runtime dispatch or inferred authority. Spec 15 §15 defines explicit specialization of functions, structs and enums. Spec 16 §2.9 adds std.option/std.result. Q-033 records the previously unspecified syntax/checking/constraint decisions. Source grammar and Quick Reference are updated in the same change. + +Declarations use `` or ``; function/worker/constructor/pattern applications use `::<...>`, while type annotations use `Name<...>`. Arguments are always explicit, ordered and complete. There are no traits, defaults, overloads, const/lifetime/effect parameters or argument inference. Qualified applications preserve direct-import visibility and module-local binding. Generic main is forbidden. Existing channel.make spelling is unchanged. + +Headers, signature names/arity, structural constraints, duplicate declarations/parameters/fields/variants, effects and trusted restrictions are checked even on unused templates. Bodies are checked as concrete required specializations; accepting an unused body does not prove it works for arbitrary types. All ordinary non-generic reachable declarations still verify even if unused. The frontend does not guess missing moves, effects, authority or cleanup. + +Copy, Send and Share reuse ordinary type rules. Format-0 Freeze means IslandSafe plain graph content; Local describes context-bound task/scope/shield/guard/storage and explicitly specified wrapper/aggregate propagation, not the complement of Send. These queries provide no operations: Copy does not promise arithmetic, ordering or equality for every concrete type. Unknown/duplicate constraints reject E7006; an unsatisfied property is E7005 at the application with parameter/constraint/found fields. Generic arguments, including phantom arguments, must be well formed by ordinary type rules. + +## Preserved memory and concurrency invariant + +Every emitted specialization obeys existing ownership, initialization, bounds, alias, lifetime, resource, Send/Share, task and effect rules. No borrow escapes, resource duplicates, cleanup disappears or mutable sharing becomes implicit because its type came from a parameter. Named owners/resources still require explicit move and consumption on every path. Task lends remain unavailable until join and disjoint mutable slices remain independent. No implicit heap allocation, refcount, destructor or detached task is introduced. + +Generic functions can transfer individual owners with explicit move; generic aggregate fields still cannot hold them. Copy-only Option/Result reject owners/resources/endpoints/borrows. A generic Cell> still hits the reserved linear_aggregates gate (E0006). Owning option/result and containers remain STD-5/6 work. + +## Verifier and AIR rule + +An AST specialization pass substitutes concrete types before existing lowering. Every required specialization becomes an ordinary named struct/enum or static function. No generic opcode, AIR type constructor, AIR feature or new verifier transfer state is introduced. The ordinary combined AIR verifier remains authoritative for memory/effects/tasks; source constraints use its structural property queries and type well-formedness rules. Concrete headers, parameter types and public effects are preserved. The AIR feature header is the existing dependency closure of emitted code, without fictitious runtime features for phantom type arguments. + +The finite-layout check is repaired to follow array elements, as well as direct nominal members. Arrays cannot hide a by-value recursive aggregate under the existing E1003 contract (spec 07 §8.3). Positive and rejected AIR/source fixtures cover this. Before lowering concrete generic bodies, the same layout query rejects cycles, avoiding recursive lowering of zero-initialized cyclic types. This closes an implementation gap without extending format-0 semantics. + +## Runtime and deterministic behavior + +There is no generic representation, runtime loader, dynamic dispatch or new interpreter primitive. Concrete calls, enum payloads, struct fields, owned values, borrows and workers run under the existing deterministic interpreter and scheduler. Compiler memory used to specialize templates does not allocate program heap or grant authority. + +A key consists of declaration kind, defining module/name and ordered structural concrete argument identities, independent of import/provider order, diagnostic file labels and short/qualified spelling. Nominal module types remain distinct. Same-key recursion reuses a pending instance; expanding recursion is bounded. Instances append in sorted key order after ordinary declarations, with types before functions. AIR names use lowercase SHA-256 key bytes with smallest unused numeric suffixes, assigned in sorted key order against original/generated names. Full keys determine identity; hashes do not. This handles collisions without order-dependent naming. Source diagnostics preserve template provenance, and display names show readable concrete source types/functions rather than internal encoded identifiers. + +Fixed compiler limits are 8 parameters per declaration, 4,096 generated declarations, active expansion depth 64, structural type traversal depth 64 and canonical key length 16,384 bytes. Limits reject E7006; they are not runtime fuel or semantics-changing flags. Recursively spelled applied type keys avoid repeated hex expansion; output AIR names remain compact. Existing monomorphic input preserves canonical AIR. Source from-returns retain the existing unimplemented outcome; Q-034 tracks their missing lifetime/binding implementation rather than inventing a contract here. + +## Valid example + +```aji +module demo.generic +import std.option; +fn identity(value: T) -> T effects [] { return value; } +fn main() -> u64 effects [] { + let value = std.option.Option::::some(identity::(42)); + match value { + std.option.Option::::some(n) => { return n; } + std.option.Option::::none => { return 0; } + } +} +``` + +The checked examples/std/generics.aji returns 42 without grants. The registry includes Option { some(T), none } and Result { ok(T), err(E) }, with is_some/is_ok classification helpers declaring effects []. Matching is ordinary exhaustive enum matching, not intrinsic outcome shorthand. No implicit unwrap, default, conversion or must-use rule is added. + +Additional runnable source fixtures swap two exclusive scalar borrows, read through a generic shared parameter, transfer an owner to a generic identity with explicit move and take it exactly once, invoke generic effectful code with an entry capability, specialize a qualified package template with a caller's nominal type, recurse with one cached instance, and lend disjoint buffers to specialized workers. + +## Rejected examples and diagnostic impact + +```aji +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>(); } +``` + +This rejects E7005 at the argument application, identifying T, Copy and own. Missing arguments, arity, generic entry, duplicate/unknown properties, shadowed parameters and expansion limits use E7006. Missing/inaccessible templates/types use E7002; malformed syntax uses E7001. Existing E7003, E2101, E3101 and E4101 reject missing moves, alias conflicts, omitted effects and duplicate task lends. Incomplete option/result matches remain E7004. Unsupported linear aggregate members still use E0006; recursive layout uses E1003. There is no new diagnostic code or envelope. Errors and traps in imported generic bodies retain the template file/line. + +For example, passing mut a twice to swap:: rejects E2101, and passing the same slice to two live specialized workers rejects E4101. Send>, Share, Freeze> and Local reject rather than silently changing behavior. Unknown signature types or trusted clauses in unused templates reject, while unused body operations are deliberately not concretely checked until instantiated. + +## Compatibility and integration + +Spec 15 §13/§14 distinguish complete ordinary declarations from templates under §15; source grammar, type property reference and spec 01 overview point to the explicit forms. The source bundle includes an on-demand language/generics.md; std signatures/constraints are in library/std.md. Two safe embedded modules add two enum templates and two helper templates; the existing six modules, 39 monomorphic functions and 14 enums retain contracts. No package discovery, ambient authority or dependency fetch is added. + +Previously invalid explicit source generic syntax becomes valid; monomorphic source/AIR and legacy channel.make remain compatible. Fixing array layout recursion rejects previously misaccepted but normatively invalid AIR. Existing unsupported from-return behavior remains visible and separately tracked. STD-4 completes the generic/structural-specialization task on this branch; full Phase 6 and owning containers remain incomplete. The owner adopted this implemented contract with the intermediate std merge (2026-10-07). + +## Agent complexity impact + +- New concepts: ordered explicit type parameters/arguments, concrete specialization versus unused-body checking, structural property requirements and bounded compile-time expansion. +- New source forms: declaration parameter lists, optional property lists, applied type names and explicit expression/pattern specialization. Existing qualified names, fields, variants, casts and static worker operands compose with them. No new keyword, trait search, lifetime syntax, runtime instruction, effect, capability or diagnostic code. +- Frontend state: template environment, canonical instance cache/pending markers, argument obligations, depth/key/count budgets, stable names and resolved internal references. Verifier transfer state/runtime state: unchanged. Structural queries and finite layout traversal reuse ordinary types. +- Interactions: nominal modules, nested structs/enums/arrays, casts, builtin channel type arguments, Copy aggregates, individual linear arguments, exclusive/shared borrows, effectful calls and structured tasks. No argument inference hides ownership or contract choices. +- Repairability: explicit parameter/property/found fields and template source locations support direct repairs. Missing moves/effects and forbidden payloads keep existing codes. Readable display names accompany compact generated AIR names. Successful unused-template checking is explicitly limited, avoiding a false universal guarantee. +- Existing AIR primitives suffice. Manual per-type duplication makes API contracts drift; runtime dictionaries/trait dispatch add trusted semantics; inference and overload search add ambiguity; arbitrary user properties need a separate contract. Generic source templates address this step without expanding those mechanisms. + +Measurements and final branch validation are recorded below. Documentation growth is a cost, not evidence of Model Capability Compression; public general conformance/integration fixtures do not decide benchmark semantics and private held-out tasks were not inspected. + +Measured with `tools/agent_bundle_tokens.py --source`, relative to STD-3 (`c96199e`): + +| Group | cl100k | o200k | Qwen2.5 | +|---|---:|---:|---:| +| Quick Reference | 6,501 → 6,948 (+6.9%) | 6,522 → 6,972 (+6.9%) | 6,704 → 7,172 (+7.0%) | +| Other source docs | 38,822 → 41,086 (+5.8%) | 38,940 → 41,212 (+5.8%) | 39,889 → 42,228 (+5.9%) | +| Full source docs excluding AIR | 45,323 → 48,034 (+6.0%) | 45,462 → 48,184 (+6.0%) | 46,593 → 49,400 (+6.0%) | +| On-demand library/std.md | 7,730 → 8,380 (+8.4%) | 7,766 → 8,417 (+8.4%) | 7,955 → 8,621 (+8.4%) | +| AIR reference | 42,454 → 42,454 (+0.0%) | 42,602 → 42,602 (+0.0%) | 43,827 → 43,827 (+0.0%) | + +The new on-demand language/generics.md is 1,324 / 1,329 / 1,371 tokens. AIR stays 160,797 bytes (48 sections from 19 files). Cumulative cl100k source growth from the pre-stdlib baseline is 33,981 → 48,034 (+41.3%); Quick Reference is 5,511 → 6,948 (+26.1%). The existing >20% owner-review requirement still applies. This RFC explains the cost: explicit instantiation/header/body rules, five structural queries and bounded deterministic specialization must be visible to an agent. Quick Reference exceeds the 4–6k target; future catalogs should remain on demand and the front door needs a separate consolidation review. No measured compression benefit is asserted. + +## Branch validation + +`zig build`, `zig build test`, `zig build conformance`, `zig build agent-reference`, the repository-wide `zig fmt --check` and `git diff --check` pass. Full conformance: 640 passed, 0 failed, 0 pending (61 added cases). Source coverage: 82/82 constructs, including six generic forms, with 155 run/accept and 225 rejected source fixtures. Generic worker/lend tests also pass 32 schedule seeds with stress quanta 1, 2 and 7 plus their default quantum 1,000. + +`tests/hosted/source_generics.py` passes 20 CLI checks, `source_modules.py` passes 36 existing package checks, and hosted smoke passes file, stdin, scoped-access and real TCP checks. The generic CLI checks include canonical lower/reverify/run equivalence, explicit package loading with caller-defined nominal types, readable errors and imported-template error/trap provenance. Scheduler/conformance runs use explicit fuel rather than wall-clock cutoffs. diff --git a/docs/rfcs/0023-linear-aggregates.md b/docs/rfcs/0023-linear-aggregates.md new file mode 100644 index 0000000..8d80d44 --- /dev/null +++ b/docs/rfcs/0023-linear-aggregates.md @@ -0,0 +1,68 @@ +# RFC 0023: Whole-value linear aggregates + +Status: Implemented +Scope: STD-5, vertical source/AIR/verifier/interpreter phase; AIR format 0 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation + +Resources need explicit compositional ownership. The preserved invariant is that every normal path consumes each nested owner/resource exactly once, never hides allocation/destruction and never leaves a partial object. Q-035 resolves the scope in spec 03 §25, spec 07a contracts and source spec 15 §16. Ownership type graphs are acyclic; iref graph edges remain opaque. Dynamic linear buffers, partial moves and bulk resource cleanup require a separate collection storage contract. + +## Verifier and runtime + +Structural linearity flows through struct/enum/fixed-array members. Constructors move inputs; whole unpack/enum take move complete components; ordinary copying/overwriting and freeing linear contents reject. Whole-value availability and existing alias/task-loan state suffice. own.pack failure returns the original value; value.swap returns the replaced value, leaving an initialized place. Interpreter handle transfer, explicit budgets, fuel and race checks are deterministic, with no destructor. Existing diagnostics are reused; no new effect/capability/trap is added. + +## Valid and rejected examples + +Valid source constructs an owned field, unpacks the struct and calls own.take exactly once. Rejected counterparts copy a linear field, move one value twice, leak a component or consume an aggregate while borrowed. AIR/source fixtures cover both, plus allocation failure, enum none/some, arrays, exchange and task transfer. The checked positive example is examples/std/owning-option.aji. The following minimal pair exposes the ownership repair: + + +```aji +struct Item { owner: own } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let item = Item { owner: move owner }; + let (part) = struct.unpack(move item); + return own.take(move part); +} +``` + +Replacing `(part)` with `(_)` and returning `42` MUST reject E3002: the component is still owned. Repair by consuming it explicitly, as above. Copying `item.owner` MUST reject E1001; passing `item` to unpack without move MUST reject E7003. The AIR counterparts are linear/struct.air, copy.air, field.air and leak.air; source twins live in source/linear/ and source/quickref/linear.aji. + +## Compatibility + +linear_aggregates was reserved; previously accepted Copy modules retain canonical spelling and ownership behavior. Individual own> borrowing now follows its already-specified array place type rather than being misrepresented as a repeated own_array slice; a baseline-feature AIR regression covers this runtime correction. New instructions are additive under the registered feature. Guard/task-transfer gates, transitive channel_transfer restrictions, second-class borrows and IslandSafe graph contents remain unchanged. Owning option/result use explicit ordinary enum matching; classification helpers retain Copy constraints. Source diagnostics for forbidden Result borrow payloads now come from ordinary member validation (E1001 rather than the removed enum Copy constraint E7005). Owner acceptance remains separate from branch implementation. + +## Agent complexity impact + +New concepts: structural whole-value linearity, exhaustive unpacking, failure returning ownership and replacement returning old ownership. New verifier transfer state: none; ordinary availability/borrow state applies to aggregates. New source forms: ordered array literal and aggregate unpack calls with ordered multi-binding; existing move/match/outcome/borrow syntax composes. Five new AIR operation families expose transfers which Copy-only primitives cannot express. array.make also resolves Q-025: Copy-only frame stores and splat cannot assemble distinct linear elements, so this operation provides a new ownership transfer rather than solely syntax sugar. No per-field holes, implicit drop, trait inference, new effects or capabilities. Explicit errors retain direct repairs. Source/AIR/Quick Reference growth and final verification are recorded below; no MCC benefit is assumed from implementation or fixtures. + + +## Instruction and diagnostic contract + +Spec 07a gives operand/result types, ownership transfer, memory/synchronization, capabilities/effects, traps and verifier state for all five families. New operations require the published linear_aggregates feature and full dependency closure; own.pack additionally requires heap, and array forms require arrays. Existing format-0 constructs retain meanings; new opcodes extend only previously unsupported cases. own.pack carries T explicitly to account for differently sized owning handles without runtime guessing. + +No new diagnostic code is added. E1001 covers illegal copying, member/storage types and overwrite/free; E1003 covers cyclic ownership type graphs; E2001/E2002 cover use/repeated consumption; E3002 covers missing consumption; E2101/E4101 preserve alias/task-loan exclusion; E5002 covers complete continuation/variant shape; E7003/E7005/E7006 retain explicit move and source shape checks. Guards, task handles/scopes and borrows retain separate gates. Atomic cells continue to reject ordinary exchange through an atomic pointee (E4202). Normal paths require consumption; traps terminate without hidden resource cleanup, under the existing profile contract. + +The runtime transfers handles in initialized values, returns the original on failed allocation and performs exchange as one instruction. Borrowed SSA roots retain identity across whole replacement and tracing collection, including enum tags and fixed arrays. This uses internal frame-backed cells, not a new source allocation or verifier state. Structural Send/Share and synchronized-cell/channel rules remain authoritative; a task loan excludes exchange until join. Allocation charges and fuel/scheduler choices stay deterministic. + +## Validation + +Required build, unit tests, formatter check, source coverage and agent-reference checks pass (88/88 source constructs). Full conformance and forced-collection schedule stress pass; source/linear/task, channel and task_loan_join run 32 seeds per stress quantum. A 1,000-exchange loop with an eight-byte authority verifies explicit consumption, bounded live ownership and collection relocation. Long interpreter memory tests, hosted filesystem/stdin/TCP smoke and source CLI integration also pass. Canonical parsing/printing covers the new families; CLI integration covers success/failure ownership, imported nominal generic payloads, run/check/report/explore and ordinary diagnostic repair. Existing module and generic CLI suites pass (36 and 20 checks); new linear CLI integration passes 49 checks. File and Arc member fixtures explicitly borrow their fields through named bindings, following the existing intrinsic API. A payload-free owning Option that is never consumed still rejects E3002. + +## Measured documentation cost + +Relative to STD-4, using tools/agent_bundle_tokens.py --source after zig build agent-reference: + +| Group | cl100k | o200k | Qwen2.5 | +|---|---:|---:|---:| +| Quick Reference | 6,948 → 7,225 (+4.0%) | 6,972 → 7,251 (+4.0%) | 7,172 → 7,455 (+3.9%) | +| Other source docs | 41,086 → 42,364 (+3.1%) | 41,212 → 42,496 (+3.1%) | 42,228 → 43,548 (+3.1%) | +| Full source without AIR | 48,034 → 49,589 (+3.2%) | 48,184 → 49,747 (+3.2%) | 49,400 → 51,003 (+3.2%) | +| AIR docs | 42,454 → 43,966 (+3.6%) | 42,602 → 44,114 (+3.5%) | 43,827 → 45,403 (+3.6%) | + +AIR grows from 160,797 to 168,336 bytes (+4.7%), 19 files and 49 selected sections. New on-demand language/linear-aggregates.md is 1,133 cl100k tokens; library/std.md is 8,398. Quick Reference exceeds its 4–6k target. This growth buys explicit complete ownership transfer and recoverable allocation ownership, rather than per-field holes/destruction state. Cumulative full source growth from the pre-stdlib 33,981-token baseline is approximately 45.9%; front-door consolidation remains separately needed. Documentation growth and successful fixtures do not establish MCC improvement. No private held-out tasks or former smoke M/C guided this design or validation. + +## Next boundary + +Q-036 remains open for STD-6: dynamic storage needs initialized length, move extraction, failure-preserving growth and explicit drain before free. This RFC completes whole-value aggregates, not Vec or Std 0.1. Bulk frame/region/repeated heap storage remains Copy-only; recursive owning type graphs remain rejected. Those limits are explicit rather than implemented with partial-state heuristics or implicit destructors. diff --git a/docs/rfcs/0024-linear-buffers-and-vectors.md b/docs/rfcs/0024-linear-buffers-and-vectors.md new file mode 100644 index 0000000..e8b8fef --- /dev/null +++ b/docs/rfcs/0024-linear-buffers-and-vectors.md @@ -0,0 +1,63 @@ +# RFC 0024: Initialized linear buffers and safe vectors + +Status: Implemented +Scope: STD-6a storage / STD-6b Vec; vertical Phase 6, additive AIR format 0 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation and invariant + +Resolve Q-036 before promising Vec or Vec>. A uniquely owned buffer exposes exactly its contiguous initialized prefix. Every nested linear element is owned once; unused capacity holds no observable value. No holes, implicit destructor or hidden growth is introduced. Whole-value aggregates and Copy-only own.array cannot represent dynamic initialized storage and moving extraction. + +## Decision + +Spec 03 §26, spec 07a buffer contracts and source §17 define buffer, exact-capacity allocation, explicit reserve, bounded push, LIFO pop, child prefix view and empty-only recoverable free. Growth charges the new allocation before releasing the old authority; failure preserves state. Full push returns the supplied value, nonempty free returns the original buffer. Ordinary linearity forces cleanup on every normal path without verifier length facts. Safe std.vec wrappers provide new/len/capacity/reserve/push/pop/free/get/replace. More collections remain separate work. + +## Verifier and runtime rules + +Whole availability and existing child-borrow/task-loan provenance suffice. buffer content must be complete, owning type graphs acyclic and Send/Share structural. Metadata-changing operations require exclusive access even on a dynamic no-op. Views expose only initialized values and use existing slice bounds/Copy access/exchange. The deterministic interpreter transfers complete values, preserves identity across tracing collection and accounts old/new allocation peaks. No new effect/capability/trap/diagnostic or synchronization policy is added. + +## Generic transfer + +A complete Copy binding inside a specialized generic body may be spelled move, retaining ordinary Copy availability. Linear specializations transfer once. Ordinary monomorphic move of Copy still rejects. This narrowly specified source rule lets one safe container implementation serve Copy and linear elements without overloads/type-case metaprogramming. It adds no AIR instruction or verifier ownership state. + +## Valid and rejected examples + +A valid program explicitly allocates Vec>, pushes with a mutable borrow, pops, own.takes the returned owner and frees the empty vector. Rejected examples leak a returned value, free/discard a nonempty vector, mutate/reserve while a view/task loan is live, duplicate an owner, copy a linear element or store borrowed/task-bound content. Checked AIR/source fixtures and a runnable example accompany implementation. + +## Compatibility and scope + +New type/opcodes belong to linear_buffers; baseline own/own_array/region operations retain semantics. New source cases extend previously rejected forms. Existing generic Copy code without move lowers identically; non-generic invalid Copy moves keep E7006. Q-034 from-returns, channel_transfer, guard/task gates and recursive ownership remain restricted. The owner adopted this implemented contract with the intermediate std merge (2026-10-07). Deque/maps/heaps are not completed by this increment. + +## Agent complexity impact + +New concepts: a contiguous initialized prefix, explicit capacity/peak-growth charge, ownership returned on full/nonempty and generic complete-value transfer. New verifier semantic state: none; primitive prefix state is runtime internal, with existing borrows/availability. New source syntax forms: none; buffer wrapper/typed allocator/builtin borrow binding compose existing forms. New diagnostics/effects/capabilities/traps: none. Eight operation names and eight AIR opcodes (len/capacity share a metadata-read contract), safe Vec wrapper signatures and their failure payloads replace opaque container behavior. Existing Copy storage cannot express resource extraction or cleanup obligations. Measured bundle costs and validation are recorded below; no MCC benefit is claimed without measurement. + +The initial interpreter stores only the initialized prefix in its traced host representation; user-visible capacity is charged independently. Its push copies the prefix internally (O(length)); this increment makes no native Vec performance claim. A future backend may reserve physical backing while preserving the exact authority/failure contract. + +The checked source example in Quick Reference §14 is a complete valid allocate/push/pop/drain/free program. The following rejects E2101 even when capacity does not grow: + +```aji +fn bad(b: mut>, heap: cap) -> void effects [mem.alloc] { + ref values = buffer.view(b); + buffer.reserve(b, 0usize, heap) or trap; +} +``` + +Missing move rejects E7003; duplicated owners reject E2002; omitted failure payload cleanup rejects E3002; a get specialization with an owner rejects E7005. Every instruction's operand/result/continuation types, ownership and memory transfer, capability/effect and runtime behavior are normative in spec 07a. AIR/source fixtures also cover empty/full, nested buffers, allocation overflow, failure preservation, old/new authority release, file closing and sender cleanup, task loans, borrowed content and recursive owning types. + +### Measured reference costs + +Relative to STD-5/RFC 0023, measured with the repository tool (offline tokenizers): + +| Bundle | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---:|---:|---:| +| Quick Reference | 7,225 → 7,667 | 7,251 → 7,697 | 7,455 → 7,902 | +| Other source docs | 42,364 → 44,717 | 42,496 → 44,850 | 43,548 → 45,932 | +| Full source excluding AIR | 49,589 → 52,384 | 49,747 → 52,547 | 51,003 → 53,834 | +| AIR reference in source bundle | 43,966 → 45,520 | 44,114 → 45,667 | 45,403 → 46,981 | + +New on-demand language/buffers.md: 1,175 cl100k tokens. library/std.md: 9,432. AIR standalone: 168,336 → 175,736 bytes (+4.4%), 19 files / 50 sections. Source output has 15 source files plus the AIR file. Full source cl100k growth is +5.6% relative to STD-5 and +54.2% since the 33,981-token pre-stdlib baseline. Quick Reference remains above the 4–6k target; the new prefix/returned-ownership contracts are necessary for one verified generic resource container and cannot be expressed by existing Copy-only dynamic storage. This cumulative cost is explicitly presented for owner review, not claimed as compression. Front-door consolidation and empirical MCC evaluation remain separate work. + +### Validation + +The implementation checks unit and parser/serializer round-trip tests, full AIR/source conformance, forced collection and schedule stress, extended interpreter memory tests, hosted OS smoke, package/generic/linear/buffer CLI integration, formatting, source construct coverage and generated reference bundles. Dedicated buffer fixtures cover 56 cases including the Quick Reference example; exact final check counts are recorded in the commit description. No held-out corpus or former smoke-task semantic tuning is involved. diff --git a/docs/rfcs/0025-owning-deque.md b/docs/rfcs/0025-owning-deque.md new file mode 100644 index 0000000..058da0a --- /dev/null +++ b/docs/rfcs/0025-owning-deque.md @@ -0,0 +1,51 @@ +# RFC 0025: Safe owning deque + +Status: Implemented +Scope: STD-6c deque increment, ordinary safe library source +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Decision and invariant + +Spec 16 §2.11 defines one deque API using the existing initialized buffer and Option. A ring has capacity initialized option slots, a head and a logical length. Exactly the occupied ring range contains some; all other slots contain none. This represents vacancy with complete values, preserving whole-value ownership without holes or new primitives. Representation fields remain ordinarily visible; manual construction/mutation must preserve the documented invariant. + +Eleven functions cover construction, metadata, explicit reserve, both ends, moving pop, empty-only free, Copy get and complete replace. Push never grows. Full push/out-of-bounds replace return the input; nonempty free returns the whole queue. Allocation failure preserves physical slots and metadata. Successful growth charges old+new capacity, fills new none slots, rotates old slots using complete exchanges and resets head without changing order. Index calculations avoid head+offset overflow. No destructor closes user resources. + +## Verifier and runtime rules + +Existing complete aggregate/enum moves and value.swap preserve exactly one owner per element. Borrow scopes, task loans, Send/Share and Copy constraints apply without special cases. The library never returns a borrow. Only new/reserve require explicit mem.alloc effect/capability; vacancy slots include the Option tag in their charge. The deterministic interpreter executes ordinary AIR with existing budgets/fuel; no opcode/runtime/feature or synchronization change is needed. Existing E7003/E2002/E3002/E2101/E4101/E7005 diagnostics cover bad moves, leaks, aliases, task loans and constraints. Valid calls are trap-free except execution limits; malformed manually modified representations have no weakened verifier or safety rules. Existing source/AIR/API semantics remain compatible. + +## Examples and validation + +The runnable deque example pushes a front/back owner, pops in FIFO order, explicitly consumes each owner and frees the empty queue. Rejected examples omit a move/cleanup, duplicate ownership, call Copy get with an owner or retain a borrow/task loan across mutation. Fixtures independently model ring order, wrapped growth, full/empty/zero capacity, repeated reuse, success/error budget release, files and channel endpoints. New/reserve charge Option slots; tests must not assume Vec's T-only accounting. Ordinary unit/conformance, collection/schedule stress for deque cases, CLI canonical lowering/manifest/hosted checks and reference bundle checks accompany the implementation. + +## Agent complexity impact + +New language concepts, syntax, instructions, verifier state and diagnostics: none. Library concepts: two ends and the documented ring invariant. The API reuses Vec's returned-ownership naming, effects and explicit specialization; no overload/trait/reflection or implicit allocation/destruction is introduced. Existing primitives suffice. Full API/contracts live in the on-demand library page rather than another long Quick Reference tutorial. Measured Quick/Source/AIR bundle costs and final validation follow; no empirical MCC benefit is claimed. This increment completes STD-6c deque; maps/sets/heaps remain STD-6d and Std 0.1 is not complete. + +The checked [owning example](../../examples/std/deque.aji) uses only safe ordinary source. This call rejects E7003 because a named owner must move: + +```aji +fn bad(q: mut>>, item: own) -> void effects [] { + let result = std.deque.push_back::>(q, item); + trap; +} +``` + +### Reference bundle measurement + +Relative to STD-6a/b, with the repository's three tokenizers: + +| Bundle | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---:|---:|---:| +| Quick Reference | 7,667 → 7,747 | 7,697 → 7,778 | 7,902 → 7,982 | +| Other source docs | 44,717 → 46,246 | 44,850 → 46,376 | 45,932 → 47,467 | +| Full source excluding AIR | 52,384 → 53,993 | 52,547 → 54,154 | 53,834 → 55,449 | +| AIR reference in source bundle | 45,520 → 45,520 | 45,667 → 45,667 | 46,981 → 46,981 | + +The library page is 10,961 cl100k tokens; standalone AIR remains 175,736 bytes / 19 files / 50 sections. Full source growth is +3.1% relative to buffer/Vec, +58.9% since the 33,981-token pre-stdlib baseline. Quick Reference adds one short paragraph (+1.0%) rather than a new tutorial; the full ring invariant/API/accounting lives on demand. Cumulative growth and the existing front-door target overrun remain for owner review. This cost is justified by a resource-safe reusable ring using existing verifier-visible operations; documentation growth itself proves no compression benefit. No held-out corpus or task-specific semantic change was used. + +### Checked implementation + +Eleven generic functions and five result enums use only existing safe source/AIR. The interpreter/backend/verifier are unchanged; the compiler embeds one extra source module. Independent Python deque vectors exercise 128 operations over four seeds with every logical element checked; growth covers all 71 small capacity/head/length combinations including empty/full/wrapped queues. Owners, files, senders, shared workers, failure ownership, cross-authority refunds and tag-inclusive quota checks pass. Invalid caller metadata cannot make free normally discard a nested owner. Borrow/task/Copy/move/leak rejections have stable existing codes. + +Validation passed full unit/conformance, focused per-instruction collection and 12-seed schedule stress (four quanta), canonical source/AIR and package/hosted CLI checks, source coverage, independent oracle checks, Zig formatting and reference bundle generation. Final counts are recorded in the commit. No native performance claim is made; construction/growth retains the interpreter's prefix-copy overhead. diff --git a/docs/rfcs/0026-standard-hash-foundation.md b/docs/rfcs/0026-standard-hash-foundation.md new file mode 100644 index 0000000..8c6c135 --- /dev/null +++ b/docs/rfcs/0026-standard-hash-foundation.md @@ -0,0 +1,40 @@ +# RFC 0026: Non-cryptographic hash foundation + +Status: Implemented +Scope: STD-6d.1 pure library; next map contract remains a design proposal +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Decision + +Spec 16 §2.12 registers std.hash and four monomorphic safe functions: fresh and extend for FNV-1a 64 and Castagnoli CRC-32C. Integer state is explicit; CRC continuation takes the finalized checksum, not an internal inverted register. This avoids a state/context/finalize API while supporting chunked I/O. Every input byte participates. Empty chunks are identities, arbitrary numeric continuation states are valid, and serialized integer order is explicit. Constants and public vectors are checked against [RFC 9923](https://www.rfc-editor.org/rfc/rfc9923.html#section-2) and [RFC 3720 B.4](https://www.rfc-editor.org/rfc/rfc3720.html#appendix-B.4). Neither algorithm provides authentication or adversarial collision resistance. + +FNV implements XOR plus explicit wrapping multiplication. CRC uses eight reflected bit steps per byte, deliberately avoiding table storage/runtime magic in this initial implementation. Both cost O(bytes) work and O(1) state; no native throughput claim. Larger/specialized hashes or accelerated CRC would require separate evidence while retaining this recurrence. + +## Borrow and compatibility checklist + +Invariant: input remains unchanged, no ownership transfers and no borrow escapes. Existing immutable slice bounds/exclusion verify the source; no verifier state, runtime/GC rule, effect, capability, diagnostic, opcode or feature is added. Safe source lowers to existing AIR and deterministic/hosted results agree. Only interpreter fuel/environment limits can interrupt valid calls. [Valid example](../../examples/std/hash.aji) hashes chunks and explicitly serializes the CRC. Holding a mutable element while hashing its parent rejects E2101; wrong argument types/imports/monomorphic specialization use existing E7005/E7002/E7006. Existing source/AIR/API meanings remain unchanged. + +## Map follow-through + +The [owning map proposal](../design/hash-map.md) fixes returned-value ownership, capacity, tombstones, exact collision handling and failure-preserving explicit rehash. No map API is registered in this increment. It proposes U64Map first, since current source type parameters cannot provide user hashing/equality operations. A checked storage prerequisite demonstrates that a struct with Copy key/state fields and Option supports observational metadata access for owning V; a linear key/value enum would not. Both tags are explicitly charged. General HashMap remains Q-037 and the STD-6d collection gate stays open. A byte hash must not be substituted for original key equality; no map-specific trait/compiler magic is introduced. + +## Agent complexity impact + +New language/verifier/runtime/syntax/diagnostic concepts: none. Four functions and one numeric continuation convention; no context lifetime, implicit seed, method, overload, trait or reflection. Ordinary source operations suffice. Full recurrence and usage stay on demand; Quick Reference adds only discovery guidance. The future map draft stays outside normative source/AIR bundles. Bundle growth is measured below; no empirical Model Capability Compression benefit or task-specific semantic change is claimed. No private held-out corpus was accessed. + +## Validation + +Conformance covers empty/high-bit/all single-byte inputs, boundary lengths, published numeric vectors, every split of representative inputs, byte-at-a-time continuation and arbitrary state. An independent Python oracle uses arbitrary-precision FNV and forward-polynomial CRC with reflected input/output, structurally distinct from the library's right-shift CRC. It validates 286 inputs / 1,144 fresh/continuation results. Immutable sub-slice bounds/reborrow, shared workers, alias/type/import rejections, canonical AIR, local-name/import-order independence, explicit packages and hosted/isolated execution are checked. Unit tests and full conformance pass; the final suite includes the checked owning storage prerequisite. All eleven hash fixtures pass with collection before every instruction and 12 schedule seeds over four quanta; the owning slot prerequisite also passes per-instruction collection. Source/package/hosted CLI checks pass (84), source coverage is 95/95, and formatting/reference generation pass. Final conformance count is recorded in the commit. These checks add no new verifier or runtime rule. + +## Reference bundle measurement + +Relative to RFC 0025 Deque, using the three repository tokenizers: + +| Bundle | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---:|---:|---:| +| Quick Reference | 7,747 → 7,806 | 7,778 → 7,837 | 7,982 → 8,043 | +| Other source docs | 46,246 → 47,475 | 46,376 → 47,616 | 47,467 → 48,802 | +| Full source excluding AIR | 53,993 → 55,281 | 54,154 → 55,453 | 55,449 → 56,845 | +| AIR reference in source bundle | 45,520 → 45,520 | 45,667 → 45,667 | 46,981 → 46,981 | + +Full source growth is +2.4% relative to Deque and +62.7% since the 33,981-token pre-stdlib baseline. Quick Reference adds discovery guidance (+0.8%); library/std.md is 12,190 cl100k tokens. Standalone AIR stays 175,736 bytes / 19 files / 50 sections. The map draft is excluded from both bundles. Cumulative growth and the existing Quick Reference target overrun remain for owner review; the cost is justified by reusable exact byte/checksum contracts with no language/verifier-state expansion. Documentation size is not evidence of compression benefit. diff --git a/docs/rfcs/0027-explicit-error-values.md b/docs/rfcs/0027-explicit-error-values.md new file mode 100644 index 0000000..5e3d17e --- /dev/null +++ b/docs/rfcs/0027-explicit-error-values.md @@ -0,0 +1,83 @@ +# RFC 0027: Explicit built-in error values + +Status: Implemented +Scope: STD-6d.2 prerequisite; vertical Phase 6, additive AIR format 0 +Language version: 0.1 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation + +A library must reject overflowing allocation sizes before allocation. Built-in errors could previously only arrive from runtime operations. Artificially allocating to obtain an error would obscure authority and failure behavior. Explicit construction makes pure validation implementable and preserves a single error vocabulary. + +## Precise invariant + +An error value is Copy data. Creating, copying, returning or matching it never confers authority, consumes a resource or proves that an operation happened. Runtime operations keep their existing outcome contracts. + +## Normative rule changes + +Spec 05 §14 specifies pure construction of every frozen registered variant of alloc_error, cap_error and io_error. Spec 07a and the AIR grammar add `error.const B.variant`. Spec 15 §6 extends the existing source variant expression to those built-in families. The registry adds `error_values`, depending on the full feature closure defining all three families. + +## Verifier implications + +Validate static family/tag and result uses; define one available Copy value. No new abstract state, ownership, alias, resource or concurrency rule. Validation is constant time over the fixed variant registry. + +## Interpreter / runtime implications + +Bind a built-in family/tag deterministically, consuming ordinary fuel, without program allocation, I/O or capability acquisition. Error data already has a runtime representation. Real allocation failure remains separately specified. + +## AIR changes + +`error.const` takes a registered error family and variant as static operands, no SSA inputs or payloads, and has one result of that family's type. It has no ownership, borrow, memory or concurrency effects, requires no effects/capabilities and has no instruction-specific traps. The feature declaration is mandatory. This is not syntax sugar: no existing pure instruction constructs a built-in error. `enum.make` retains its declared-enum contract. + +## Valid example + +```aji +fn overflow() -> alloc_error effects [] { + return alloc_error::budget_exceeded; +} +``` + +## Rejected example + +```aji +fn forge() -> cap effects [] { + return alloc_error::budget_exceeded; +} +``` + +Expected diagnostic: E7005; equivalent AIR is E1001. Missing feature is E0006, unknown AIR family/tag E0004, payload syntax E0001. Unknown source variant is E7002, payload arity E7005. No new diagnostic codes. + +## Spec integration + +Spec 05 §14, 07 §8.9, 07a Values, 08 §3, 15 §6; reference AIR grammar and feature registry; both agent bundle manifests and Quick Reference. Q-038 is resolved by these contracts. + +## Compatibility and migration + +Additive feature in format 0. Existing type/variant meanings, enum.make, fallible operations and authority rules remain frozen. Older implementations reject modules declaring error_values through normal feature negotiation. No migration for existing source or AIR. + +## Agent complexity impact + +One coherent semantic block: constructing ordinary error data. One feature and AIR instruction, no new source syntax form, diagnostics, verifier state or ownership concepts. Existing Enum::variant syntax and exhaustive matching suffice. Explicit preflight failures reduce the need for ad hoc error enums or artificial runtime calls. No empirical MCC benefit is claimed. Dependencies define the error data vocabulary, not ambient authority. Measured Quick Reference, source and AIR bundle growth and validation are recorded below when checks finish. + +## Alternatives considered + +Changing enum.make would alter frozen baseline semantics. A new library-specific overflow enum would force different allocation error handling. Harvesting runtime errors through fake allocations changes failure/authority behavior. A payload-free constant is the smallest explicit primitive covering existing error families. + +## Unresolved questions + +None for this feature. General map key hashing/equality remains Q-037. + +## Validation and measured documentation budget + +`zig build`, `zig build test` and formatting pass. All 32 error-value conformance cases pass normally and with collection before every instruction; all 17 registered tags are exercised directly in AIR and through exhaustive source matches. `tests/hosted/source_errors.py` passes 26 CLI checks, including canonical lowering, matching source/AIR run records, hosted execution and zero-allocation/zero-entry-authority audit reports. Source coverage is 96/96. The full working-tree regression also includes the developing map consumer. + +Relative to RFC 0026, excluding the uncommitted map library contract from the generated source library page: + +| Group | cl100k | o200k | Qwen2.5 | +|---|---|---|---| +| Quick Reference | 7,806 → 7,863 | 7,837 → 7,894 | 8,043 → 8,102 | +| Other source docs | 47,475 → 48,061 | 47,616 → 48,204 | 48,802 → 49,419 | +| Full source excluding AIR | 55,281 → 55,924 | 55,453 → 56,098 | 56,845 → 57,521 | +| AIR inside source bundle | 45,520 → 46,300 | 45,667 → 46,451 | 46,981 → 47,800 | + +Standalone AIR grows from 175,736 to 179,282 bytes, 19 files / 51 sections. Incremental full source growth is 1.2%; cumulative growth since the pre-stdlib cl100k baseline 33,981 is 64.6%, above the existing review line. The cost is justified by a necessary pure validation primitive with no new source form, authority or ownership concepts. Detailed contracts remain on demand; documentation growth is not evidence of MCC improvement. diff --git a/docs/rfcs/0028-owning-numeric-map.md b/docs/rfcs/0028-owning-numeric-map.md new file mode 100644 index 0000000..218d3e6 --- /dev/null +++ b/docs/rfcs/0028-owning-numeric-map.md @@ -0,0 +1,73 @@ +# RFC 0028: Safe owning numeric-key map + +Status: Implemented +Scope: STD-6d.2, safe standard source; general-key gate remains Q-037 +Language version: 0.1 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## 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 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>. + +## 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, 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 (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. diff --git a/docs/rfcs/0029-static-function-parameters.md b/docs/rfcs/0029-static-function-parameters.md new file mode 100644 index 0000000..3da85bd --- /dev/null +++ b/docs/rfcs/0029-static-function-parameters.md @@ -0,0 +1,74 @@ +# RFC 0029: Explicit static function parameters + +Status: Implemented +Scope: vertical Phase 6 source specialization prerequisite for general collections +Language version: 0.1 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation + +General maps/sets, ordered heaps and algorithms need user operations without map-specific compiler logic. Copy/Send/Share properties supply no hash/equality/order. Static named functions are the smallest general facility reusing existing AIR calls and verification. They preserve explicit authority, effects and ownership. + +## Precise invariant + +A selected source function has exactly the declared parameter/return types and effect set. Selection grants no authority. It is part of nominal instance identity and has no runtime representation or captured state. All linear transfers and borrows are checked by ordinary AIR verification. + +## Normative rule changes + +Spec 15 §18 and the source grammar define callable contracts in generic declarations and explicit `fn path` arguments. Existing type-only generic syntax/meaning remains unchanged. Declaration, signature, storage, expression and worker rules are integrated in the same phase. Q-039 records the contract; general collections remain Q-037 until implemented. + +## Verifier implications + +No new AIR verifier state or transfer function. Specialization checks exact callable signatures/effect sets and emits ordinary named call/worker operands. Existing ownership, loan, effects, Send/Share, capability and bounded layout verification decides whether the resulting program is valid. + +## Interpreter / runtime implications + +No new runtime state, instruction, allocation, capability, dispatch or destructor. Existing deterministic call/task semantics and fuel apply. Selected operation bodies remain visible AIR. + +## AIR changes + +None; ordinary static call/task operands suffice. Positive AIR equivalents and negative ordinary effect/ownership examples demonstrate the existing boundary. No existing opcode meaning changes and no new instruction is introduced as sugar. + +## Valid example + +`apply T effects []>` can call F with complete transfer; `apply::` selects a named pure function. Borrowed comparators, owning transforms, explicit effectful capability operations and task workers compose with the same mechanism. + +## Rejected example + +A `fn(ref) -> u64 effects []` parameter rejects a mem.alloc function, wrong return type or mut parameter with E7005. Selected functions cannot be stored/returned as values (E7006), forged from capabilities or resolved through unimported modules (E7002). Ordinary missing effects, invalid moves/loans and resource leaks remain rejected after substitution. + +## Diagnostics impact + +No new codes. E7001 syntax, E7002 inaccessible names, E7005 argument/signature/effect mismatch, E7006 forbidden use/limits; existing AIR codes apply after lowering. Diagnostics retain caller argument and template body provenance. Callable mismatch records include the parameter, selected function and expected/found contracts. + +## Compatibility and migration + +Additive explicit source syntax. AIR format 0 and all registered feature meanings remain unchanged. Existing type-only generics, instance identities, capabilities and effect contracts retain meaning. No borrowed returns, methods, traits, overload search, captures or argument inference are added. + +## Agent complexity impact + +One concept: a compile-time named function with an exact contract. Two composed source forms: callable generic declaration and explicit fn argument. No runtime or verifier state, diagnostic code or AIR feature. Frontend state adds callable contracts to the existing bounded environment/cache, with selected function identity in type/function keys. Exact effects avoid variance and effect shims; normal explicit arguments/moves make ownership repairable. Existing AIR primitives suffice, while manual per-key algorithm duplication cannot express a reusable general source container. The facility also serves ordering and transforms, beyond maps. The measured source growth is recorded below; the AIR bundle is unchanged. No empirical MCC benefit is claimed. + +## Alternatives considered + +Numeric-only wrappers do not meet the general collection gate. Hash-only identity is incorrect under collisions. Runtime function pointers/closures, trait dictionaries, reflection and type-name conventions require more semantics or hide operation selection. Implicit structural hashing fixes one policy and leaves user ordering/equality unresolved. Exact static contracts use existing calls and public effect declarations. + +## Unresolved questions + +Q-037 remains open for the complete generic map/set library contract. A dense initialized entry buffer plus Copy probe-index metadata permits borrowed arbitrary owning keys without default keys or borrowed enum payloads; that storage design will be specified separately. + +## Branch validation + +The complete regression corpus passes 912 tests; the two subsequently added recursive/cyclic-contract cases pass in the focused 51-case corpus. All 51 static-function/source/AIR/Quick Reference cases also pass with collection before every instruction and 12 schedule seeds under stress quanta 1, 2, 7 and the test quantum. Unit tests, Quick Reference checking, formatting, reference-bundle generation and source coverage pass. CLI integration covers 25 source/AIR/package/hosted/report/explore/diagnostic checks; existing generic (20) and numeric-map (76) CLI checks pass. Type-argument traversal for built-in allocation/channel calls remains covered by the existing container corpus. No wall-clock run limit is used. + +## Documentation budget + +Relative to RFC 0028 (all counts exclude generated AIR from the full source group): + +| Bundle group | cl100k_base before → after | o200k_base before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference | 7,863 → 8,051 | 7,894 → 8,082 | 8,102 → 8,300 | +| Other source docs | 50,079 → 51,002 | 50,223 → 51,150 | 51,509 → 52,468 | +| Full source | 57,942 → 59,053 | 58,117 → 59,232 | 59,611 → 60,768 | + +cl100k growth is +2.4% / +1.8% / +1.9%, respectively. The on-demand generics page is 2,194 cl100k tokens. AIR remains 179,282 bytes / 19 files / 51 sections and 46,300 cl100k tokens in the source bundle. No AIR normative material is added to bundle.txt because ordinary instructions retain their contracts. Cumulative source growth from the pre-stdlib 33,981-token baseline is +73.8%; the rationale is a general operation-selection mechanism needed for arbitrary collection keys and ordering, rather than per-container compiler rules. The Quick Reference remains above its 4–6k target; consolidation/selective reading is separate work. Documentation/fixtures alone are not evidence of an empirical MCC improvement. diff --git a/docs/rfcs/0030-owning-general-key-map.md b/docs/rfcs/0030-owning-general-key-map.md new file mode 100644 index 0000000..d7e76a7 --- /dev/null +++ b/docs/rfcs/0030-owning-general-key-map.md @@ -0,0 +1,57 @@ +# RFC 0030: Safe owning general-key hash map + +Status: Implemented +Scope: STD-6d.4, ordinary safe library source after RFC 0029 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation + +Arbitrary keys need exact equality and explicit hash policy. Numeric-key U64Map cannot represent bytes/structs/owners by digest alone. Static functions supply reusable typed operations without container-specific language rules. + +## Invariant and normative changes + +Spec 16 §2.14 defines std.hashmap.HashMap, dense initialized complete entries and Copy probe metadata. Every live entry has one reachable occupied bucket; cached hashes and equality agree. Keys and values may both own resources, with no vacancy key/default allocation. The registry/reference/API changes land together. + +## Verifier rule + +No new transfer function. Complete buffer transfer/pop/exchange, borrowed fields, exact callable contracts, normal effects/capabilities, Copy/Send/Share and ownership verification apply. Representation/hash-law preconditions are explicit, as for existing containers. No manual unsafe implementation is allowed. + +## Runtime and deterministic behavior + +Ordinary AIR. Probes are bounded; replacement/full/removal/free return complete owners. Allocation failure rolls back temporary empty storage, preserving old buffers/metadata/pop order. Explicit peak charges include both layouts and separately owned payloads. Removal swaps the last dense entry into a hole and repairs Copy indices. Rehash uses cached hashes after allocation succeeds; no recoverable failure follows the first old-buffer mutation. Normal profiles agree; fuel/callback traps are abnormal outcomes. + +## Valid and rejected examples + +A struct key containing an owner and a Copy identity field supplies pure ref-key hash/equality functions; insert transfers it with an owned value, removal/pop returns both for explicit consumption. Copy-value lookup does not need Copy keys. Missing moves, leaked full/replacement/pop/nonempty-free results, illegal aliases/loans, Copy lookup of owning V and sharing non-Share contents reject through existing codes. Mismatched static policy identities reject E7005. + +## Diagnostics / compatibility / AIR + +No new diagnostic, opcode, AIR feature or runtime boundary. Existing E7003/E2002/E3002/E2101/E4101/E7005/E4002 and ordinary call/effect checks apply. The new module is additive; std.map.U64Map and every existing API retain meaning. No implicit growth, destructor, retained borrow or authority is introduced. Spec 15 §17 clarifies the existing distinction between a Copy value bound in frame storage and internal storage/scope/guard/shield handles; ordinary Copy loading is unchanged. + +## Agent complexity impact + +No new language concept, syntax or verifier/runtime state beyond already specified static operations. Ten functions match the numeric-map operation set; four explicit arguments name type/hash/equality policies, and linear replacement returns both old resources. Algebraic hash/equality and visible dense/index invariants add documentation obligations, which are kept on demand and measured below. Existing safe primitives suffice without borrowing enum payloads or partial moves. No MCC or throughput benefit is claimed from fixtures. + +## Alternatives + +Digest identity loses collisions. Per-key duplication loses general reuse. A vacant Option table cannot observe owning keys through existing Copy enum switching. Two dense/probe buffers need no default key, borrowed enum feature, private representation privilege or unsafe pointer. + +## Validation gate + +Independent dictionary/model traces, exact collisions, tombstones/wrap, full replacement, moving-hole repair, zero capacity, complete owners/files/senders, allocation rollback/peak/refunds, immutable/exclusive/task loans, nominal policies, invalid representation safety, source/AIR/profile/package consistency and GC/schedule stress are required before completion. HashSet and BinaryHeap remain separate increments. + +## Documentation budget + +Relative to the static-operation prerequisite (RFC 0029), all full-source counts exclude AIR: + +| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after | +|---|---|---|---| +| Quick Reference | 8,051 → 8,124 | 8,082 → 8,156 | 8,300 → 8,374 | +| Other source | 51,002 → 53,363 | 51,150 → 53,537 | 52,468 → 54,845 | +| Full source | 59,053 → 61,487 | 59,232 → 61,693 | 60,768 → 63,219 | + +cl100k growth is +0.9% / +4.6% / +4.1%. library/std.md is 16,504 cl100k tokens. AIR remains 179,282 bytes / 19 files / 51 sections (46,300 cl100k in the source bundle). No normative AIR material is needed. Full source growth from the pre-stdlib 33,981-token baseline is +80.9%; the justification is a general owning-key map meeting the original HashMap> gate, exact failure/resource contracts and a separate numeric API retained for compatibility. The Quick Reference has one compact paragraph; policies/invariants/accounting stay on demand. Selective reference reading/consolidation remains separate work; no empirical MCC benefit is claimed. + +## Validation result + +The complete conformance corpus passes 947 cases, including 33 general-map cases. Unit tests, Quick Reference checking, formatting, reference-bundle generation, source coverage (104/104 constructs) and 55 CLI/source/AIR/profile/package/provenance checks pass. Independent Python dict/dense-order oracles cover 192 public operations across Copy and owning-value traces, checking every key and complete returned owners. Tests cover owning byte-buffer keys, owning key/value replacement/full returns, files, sender task transfer, shared lookups, exact allocation peaks, both reserve-failure phases, new-allocation rollback, cross-authority refunds and invalid-metadata nonempty free. The focused collection-before-every-step/scheduler-stress process has completed: all 33 general-map cases pass, including both independent owning/Copy model traces; scheduled fixtures run 12 seeds under quanta 1, 2, 7 and their own quantum. The process used no wall-clock termination. Subsequent set/heap regression passes the full 1007-case corpus. General key-policy/storage validation is complete on this branch (Q-037); The owner adopted this implemented contract with the intermediate std merge (2026-10-07). diff --git a/docs/rfcs/0031-owning-general-key-set.md b/docs/rfcs/0031-owning-general-key-set.md new file mode 100644 index 0000000..f826375 --- /dev/null +++ b/docs/rfcs/0031-owning-general-key-set.md @@ -0,0 +1,48 @@ +# RFC 0031: Safe owning general-key hash set + +Status: Implemented +Scope: STD-6d.5, safe library source after RFCs 0029/0030 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation and normative changes + +General maps provide exact explicit hash/equality and complete owning keys. Spec 16 §2.15 adds std.hashset without set-specific language machinery. Duplicate insertion returns the original input and retains the existing representative, exposing resource ownership without hidden destructors. + +## Preserved invariant + +The underlying general map's dense/probe invariant holds with bool values true. Every live K has one owned occurrence; equal keys are unique. Keys/hash/equality remain stable. Duplicate/full/failing-growth paths preserve stored entries/buckets and return input ownership as specified. + +## Verifier rule + +No new transfer function: complete struct/enum/buffer moves, exact static callable contracts, borrow/task-loan exclusion, bounds, effects, Copy/Send/Share and explicit consumption apply. All code is ordinary safe Aji. + +## Runtime and deterministic behavior + +Nine wrappers use existing map AIR calls, without runtime dispatch, allocation beyond explicit new/reserve or cleanup. Normal failure preserves all old state; peak charges/refunds and deterministic pop order follow the map. User callback traps/fuel are abnormal outcomes. + +## Valid and rejected examples + +An owning byte/struct key is moved into insert. Duplicate/full returns the original key for explicit consumption. A successful remove/pop returns the stored key; nonempty free returns the set. Missing moves, ignored owning results, bad aliases/task loans, invalid effect/policy bindings and sharing non-Share keys reject through existing diagnostics. + +The [owning example](../../examples/std/hashset.aji) allocates one slot and one payload with a 67-byte grant, inserts the complete key, pops/unpacks/takes it and frees the empty set. [Owning duplicates](../../tests/conformance/source/hashset/owner.aji) return the incoming payload and retain the original. [A leaked duplicate](../../tests/conformance/source/hashset/present_leak.aji) rejects with E3002; [missing move](../../tests/conformance/source/hashset/missing_move.aji) rejects with E7003; [a file key shared with a worker](../../tests/conformance/source/hashset/not_share.aji) rejects with E4002. + +## Diagnostics / compatibility / AIR + +No new code, opcode, AIR feature, source syntax or verifier/runtime state. Existing source/type/availability/alias/effect/Send/Share diagnostics apply. Registry addition is additive and imports grant no authority; old APIs retain meaning. + +## Agent complexity impact + +No additional language concept beyond explicit static policy arguments. Nine operations omit value lookup and replacement alternatives; duplicate handling clearly distinguishes stored and returned owner. An extra membership check reuses the map and its stable callback laws, avoiding a new primitive or overwrite/destructor rule. Full API/representation/accounting stays on demand; measured bundle growth and executable validation are recorded below. No empirical MCC result is claimed. + +No new syntax form, diagnostic or verifier state. Relative to RFC 0030, cl100k Quick Reference grows 8,124 → 8,201 (+0.9%); other source documentation 53,363 → 54,798 (+2.7%); full source excluding AIR 61,487 → 62,999 (+2.5%). The on-demand std reference is 17,939 tokens. Corresponding o200k counts are 8,234 / 54,977 / 63,211; qwen2.5 counts are 8,451 / 56,295 / 64,746. AIR remains 179,282 bytes, 19 files and 51 sections; its source-bundle copy remains 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k source growth from the 33,981-token pre-std baseline is +85.4%. The increase buys explicit duplicate ownership, nine signatures and representation/failure/quota laws; mandatory Quick Reference stays at one short paragraph. No language expansion or measured compression benefit is claimed. + +## Validation gate + +Copy/owning/byte keys, duplicate/full preservation, collisions, pop/remove order, zero capacity, growth failure/refunds/peak, rejected leaks/moves/loans/policy/effects, independent Python set traces, source/AIR/package/profile checks, GC/scheduler stress and documentation budgets are required. BinaryHeap and I/O/path remain following increments. + + +## Validation result + +Full conformance passes 973/973, including 26 set fixtures. All runtime set fixtures pass collection before every instruction, including both independent model traces; shared lookup runs 12 schedule seeds under quanta 1, 2, 7 and its own quantum. Existing compilation checks reject owner leaks, missing moves, bad borrows/task loans, wrong nominal policies, missing effects and non-Share file keys. Copy and owning key traces use independent Python set/representative/dense-order oracles for 80 operations, checking every domain key after every operation. Duplicate input/stored representative and complete probe metadata, owning byte keys, files, full/remove/pop/nonempty-free ownership, zero/overflow, both failure phases, rollback, exact peaks and cross-authority refunds are covered. + +Unit/Quick Reference checks, formatting, hosted smoke, agent-reference generation, source coverage (106/106 constructs) and 53 CLI checks pass. CLI checks compare source/AIR results, hosted execution, explicit package policies, reordered imports, report/audit and callback provenance. AIR and source syntax remain unchanged. The separate general-map full GC/stress process subsequently completed with all 33 cases passing, without wall-clock termination. BinaryHeap and I/O/path remain subsequent work. diff --git a/docs/rfcs/0032-owning-binary-heap.md b/docs/rfcs/0032-owning-binary-heap.md new file mode 100644 index 0000000..1ed00aa --- /dev/null +++ b/docs/rfcs/0032-owning-binary-heap.md @@ -0,0 +1,48 @@ +# RFC 0032: Safe owning binary heap + +Status: Implemented +Scope: STD-6d.6, safe library source after RFCs 0024/0029 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation and normative changes + +Spec 16 §2.16 supplies a bounded priority queue for arbitrary complete T with one explicit pure ref-value ordering operation. Copy and owning values share the same API and safe implementation. Ownership, allocation/failure and ordering contracts are visible to the verifier and caller. + +## Preserved invariant + +Dense entries own each live T exactly once. A Copy index permutation and inverse positions describe the heap; no child precedes its parent. Unused capacity owns no T. Callback laws are a stable strict weak order. Full push and every returned allocation failure preserve all state, and returned resources are explicitly consumed. + +## Verifier / runtime rules + +No new transfer function or runtime rule. Existing complete buffer/aggregate moves, exchange, ref/mut exclusion, task loans, exact static callable contracts, bounds, effects, Copy/Send/Share and consumption apply. Indices sift while owners remain in initialized storage; complete pop/exchange repairs a dense hole. All code is safe Aji lowering to ordinary AIR. Callback/fuel traps are abnormal; normal failures preserve layout/extraction order and refund recorded allocation authorities. + +## Valid and rejected examples + +An owning record orders by a Copy priority field. Push consumes the record; full returns it; pop moves it out for complete unpack and explicit resource consumption; nonempty free returns the whole heap. A Copy heap may peek; attempting peek of an owning T, ignoring full/pop/nonempty-free owners, missing move, borrowing across mutation/task loans, mismatched ordering policies/effects or sharing non-Share resources MUST reject through existing diagnostics. Executable examples and validation results are recorded below. + +The [checked owning example](../../examples/std/heap.aji) moves a priority/owner record into one slot, pops/unpacks/takes the payload and frees the empty heap with a 40-byte grant. [Owning peek](../../tests/conformance/source/heap/peek_owner.aji) rejects E7005; [a leaked full return](../../tests/conformance/source/heap/full_leak.aji) rejects E3002; [a live task loan](../../tests/conformance/source/heap/loan.aji) rejects E4101. [Corrupt indices](../../tests/conformance/source/heap/invalid_indices.aji) trap T0008 through ordinary bounds checks, preserving safe-code memory safety. + +## Diagnostics / compatibility / AIR + +No new diagnostic, instruction, AIR feature, source syntax or verifier/runtime state. E7003/E7005, E3002, E2101/E4101, E3101 and E4001/E4002 remain ordinary checks. Addition of std.heap is compatible with existing modules and AIR format 0; imports grant no authority. No implicit allocation/destructor or unsafe/trusted boundary is introduced. + +## Agent complexity impact + +One strict-weak-order precondition, already expressible with static operation selection, plus an explicit priority-queue invariant. Eight operations mirror existing bounded containers; no inferred comparator, convenience auto-growth, borrowed-return facility or stable-sort concept. The Copy-only peek restriction follows existing lookup contracts. Dense/Copy-index storage avoids a new owner-swapping primitive, borrowed enum payloads or holes. Verifier state and syntax are unchanged; Quick Reference and full source documentation growth are measured below. No empirical MCC benefit is claimed. + +Measured cl100k growth from RFC 0031: Quick Reference 8,201 → 8,284 (+1.0%); other source documentation 54,798 → 56,770 (+3.6%); full source excluding AIR 62,999 → 65,054 (+3.3%). library/std.md is 19,911 tokens. o200k groups are 8,317 / 56,955 / 65,272; qwen2.5 groups 8,534 / 58,278 / 66,812. AIR stays 179,282 bytes / 19 files / 51 sections; its source-bundle copy stays 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k growth over the 33,981 pre-std baseline is +91.4%, justified by the owning priority queue and explicit ordering/representation/failure/budget contracts. No new language form, verifier state or diagnostic; the Quick Reference has one short paragraph and full contracts stay on demand. Existing primitives suffice without changing AIR. + +## Alternatives + +Copy-only array heaps fail the owning resource gate. A vacancy/default T loses generality. Direct swapping owners could use extra scratch rotations, but adds transient value movement and proof complexity. Two initialized buffers make permutation swaps and complete extraction explicit with a documented 16-byte per-capacity metadata cost on air64. Opaque runtime collection magic enlarges the trusted boundary unnecessarily. + +## Validation gate + +Independent Python priority-queue traces; ascending/descending order, duplicate priorities, complete owning/files/endpoint values, dense-hole repair, empty/zero/full, capacity overflow, both allocation failure phases, exact peak/refunds/cross-authority accounting, rejected leaks/aliases/loans/Copy/effect/policies; source/AIR/package/profile consistency; GC and scheduler stress; unit/Quick Reference, formatting, full conformance, source coverage and reference budgets. I/O/path remain subsequent increments. + + +## Validation result + +All 1007 conformance cases pass, including 34 heap fixtures. All runtime heap fixtures pass collection before every instruction; shared read-only lookup, sender heap transfer and task-loan restoration run 12 seeds under quanta 1, 2, 7 and their own quantum. Independent Python heapq oracles cover 160 min/Copy and max/owning operations; sorted oracles check all 120 permutations of five elements. Tests cover duplicate priorities, dense-hole repair, direct own, owning byte buffers, files/endpoints, returned full/pop/nonempty-free ownership, empty/zero/overflow, both growth failure phases, complete layout preservation, exact peak/refund and cross-authority accounting, absence of full-push callbacks and bounds traps for invalid representation. Existing diagnostics reject leaks/missing move/Copy/aliases/loans/effects/policies/non-Share sharing. + +Unit/Quick Reference, formatting, hosted smoke, bundle generation, 109/109 source coverage constructs and 70 CLI checks pass. CLI checks compare source/AIR/profile/package behavior, reordered imports, audit output, selected-comparator provenance and std bounds-trap locations. The separate general-map GC/stress process also completed with 33/33, closing Q-037. Collections STD-6d are implemented and validated on this branch; Std 0.1, I/O/path and system adapters remain unfinished. diff --git a/docs/rfcs/0033-bounded-io-foundation.md b/docs/rfcs/0033-bounded-io-foundation.md new file mode 100644 index 0000000..cd2f252 --- /dev/null +++ b/docs/rfcs/0033-bounded-io-foundation.md @@ -0,0 +1,46 @@ +# RFC 0033: Explicit bounded I/O composition + +Status: Implemented +Scope: STD-7a, safe std.io foundation before buffered adapters and paths +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation and normative changes + +Spec 16 §2.17 adds six concrete functions composing existing console/file/TCP reads and file writes. Runtime writes already have all-or-error success contracts, so this increment adds no write alias or broad protocol hierarchy. Exact reads and bounded copies need reusable loops with explicit partial progress and no implicit allocation/authority. + +## Preserved invariant + +Only caller-supplied destination/scratch slices are accessed within their bounds. Mutable resources remain borrowed and owned by their caller on every normal return. No buffer, file or stream is allocated, opened, closed or retained. Confirmed counts never exceed supplied capacities/limits. Errors do not imply rollback of prior reads/writes or atomic failure of external I/O. + +## Verifier and runtime rules + +No new transfer function or runtime rule: ordinary ref/mut, disjoint slices, resource borrowing, task loans, exact typed/effect calls and checked arithmetic/bounds suffice. The underlying intrinsic supplies authority through cap, mut> or mut. Spec 11 still defines deterministic/hosted outcomes, blocking, fuel and errors. There is no timer, background task, ambient grant or new error variant. + +## Valid and rejected examples + +The caller opens read/write files with explicit capabilities, lends both and a fixed scratch slice to copy_file with a limit, handles eof/limit/err, and explicitly closes both on every path. Exact readers report completed prefix length on EOF/error. Aliased buffers, wrong resource modes/capability kinds, missing public effects, active task loans and closing a lent resource reject through existing diagnostics. Executable fixtures and validation results are recorded below. + +The [copy example](../../examples/std/io.aji) lends two files and a fixed three-byte frame buffer, handles all results and explicitly closes resources. [Exact file reading](../../tests/conformance/source/io/file.aji) validates prefix/suffix/guard preservation. [Wrong mode](../../tests/conformance/source/io/wrong_mode.aji) rejects E7005; [missing effect](../../tests/conformance/source/io/missing_effect.aji) rejects E3101; [a live task loan](../../tests/conformance/source/io/loan.aji) rejects E4101. No callback or hidden resource cleanup is needed. + +## Diagnostics / compatibility / AIR + +No new instruction, AIR feature, syntax, verifier/runtime state or diagnostic. Existing type/capability, effect, alias/task-loan and resource-consumption checks apply. Built-in io_error.invalid_input represents unusable nonempty copy with zero scratch capacity, without performing an intrinsic. Imports grant no authority and all existing APIs/AIR meaning are unchanged. + +## Agent complexity impact + +Six concrete signatures carry exact io.read/fs.read/net.read/fs.write effects; no effect inference, unions of unrelated effects, callbacks, type erasure or reader trait is needed. EOF and filled-buffer/limit are distinct because no extra byte is consumed to discover EOF. Read and copy error records distinguish confirmed progress from external I/O that may have partially failed. This is a library contract, not a new language concept. Existing safe primitives suffice. Quick Reference/source budgets are measured below; no empirical MCC benefit is claimed. + +Measured cl100k growth from RFC 0032: Quick Reference 8,284 → 8,350 (+0.8%); other source documentation 56,770 → 58,473 (+3.0%); full source excluding AIR 65,054 → 66,823 (+2.7%). library/std.md is 21,614 tokens. Corresponding o200k groups are 8,384 / 58,664 / 67,048; qwen2.5 groups are 8,600 / 59,988 / 68,588. AIR remains 179,282 bytes / 19 files / 51 sections; its source-bundle copy remains 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k growth over the pre-std 33,981-token baseline is +96.6%, justified by explicit partial-progress, authority, EOF/limit and cleanup contracts. No new syntax, diagnostic or verifier/runtime state is introduced; detailed contracts stay on demand. No empirical compression benefit is claimed. + +## Validation gate + +Empty/exact/short input, preserved guard/suffix bytes, limits at/below/above EOF, small scratch chunks, append mode, zero scratch/limit, supplied destination counts, fragmented TCP and task loan restoration; rejected effects/modes/kinds/aliases/loans/close; independent public byte-vector oracle, source/AIR/package/profile/provenance and hosted read/write errors; GC/schedule stress and required repository/bundle checks. Buffered owning reader/writer and lexical paths remain required by STD-7. + + +## Validation result + +All 1027 conformance cases pass, including 20 I/O fixtures. Runtime fixtures pass collection before every instruction; fragmented TCP and restored task loans run 12 seeds under quanta 1, 2, 7 and their own quantum. Independent Python byte-prefix/count oracles cover 162 exact/bounded reads and 250 copy/append combinations with empty/exact/short inputs, guard/suffix bytes, limits, cursor tails and scratch capacities. Tests reject wrong modes/kinds, missing effects, active aliases/task loans and closing a borrowed resource with existing codes. Maximum usize limit and exact EOF at limit are covered without overflow or probing past the bound. + +Hosted tests exercise an actual stdin read error (directory → invalid_input) and a child-only file-size quota causing a partial second write: read=4, confirmed_written=2, actual output length=3. Source code explicitly consumes both files and checks the input cursor tail; no wall-clock timeout, global host configuration change or result-file write under that quota is used. The result confirms why failed writes cannot promise rollback/exact output counts. + +Unit/Quick Reference, formatting, hosted smoke, reference generation, 111/111 source coverage constructs and 55 CLI checks pass. CLI checks compare source/AIR/profile/package results, reordered imports, audit output and caller diagnostic provenance. AIR semantics and source syntax remain unchanged. The foundation is complete on this branch; buffered owning reader/writer, lexical paths and Std 0.1 remain required future work. diff --git a/docs/rfcs/0034-owning-buffered-files.md b/docs/rfcs/0034-owning-buffered-files.md new file mode 100644 index 0000000..8e50628 --- /dev/null +++ b/docs/rfcs/0034-owning-buffered-files.md @@ -0,0 +1,48 @@ +# RFC 0034: Owning bounded file reader and writer + +Status: Implemented +Scope: STD-7b, safe std.io.reader / std.io.writer after RFCs 0024/0033 +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation and normative integration + +Spec 16 §2.18 adds concrete file adapters with fixed-capacity initialized byte buffers. They reduce repeated refill/flush code while keeping file ownership, allocation, effects, failure and cleanup explicit. Existing linear aggregates/buffers suffice without a reader trait, hidden destructor or new instruction. + +## Preserved invariant + +The adapter owns exactly one file and one initialized buffer. Reader offsets delimit its unread prefix; writer used count delimits pending bytes. A failed writer retains its first I/O error and prevents further writes/flush retries because failed external writes may have written an unknown prefix. All normal outcomes transfer complete resources or retain them in the adapter; no resource is implicitly closed. + +## Verifier rule + +No new abstract state/transfer function. Ordinary whole-value struct/enum moves, resource borrowing, buffer views, disjoint slices, effects/capabilities, alias/task loans, Copy/Send/Share and consumption checks apply. Fields remain visible with a documented caller invariant, as for existing safe collections. Invalid representation may trap through checked bounds/arithmetic but cannot bypass memory safety. + +## Runtime / deterministic behavior + +Only new allocates, with explicit mem.alloc authority, charging capacity bytes. A failed new returns the original unchanged file with alloc_error. Existing spec 11 I/O/blocking/fuel/profile behavior applies. Reader refill/cached copies and writer room-making flushes are ordinary safe source. Finish frees Copy storage and returns the file; unread/failed finish returns the complete adapter. Discard explicitly abandons buffered bytes, frees storage and returns the file plus counts/error state. No sync/close is hidden. + +## Valid and rejected examples + +The caller moves a file into new, explicitly consumes constructor failure, lends the adapter for reads/writes, handles finish returning the file or complete adapter, and closes the returned file. Discard reports unread/pending byte counts. Ignoring owning new/finish/discard outcomes, missing moves, invalid modes/effects, alias/task loans and sharing file-bearing adapters reject through existing diagnostics. The [copy example](../../examples/std/buffered_io.aji) consumes every constructor/finish result and closes returned files. [Unread finish](../../tests/conformance/source/buffered_io/unread_finish.aji) returns/reuses the complete reader; [explicit discard](../../tests/conformance/source/buffered_io/writer_discard.aji) reports abandoned pending bytes and refunds storage. [Ignoring a constructor failure](../../tests/conformance/source/buffered_io/new_error_leak.aji) and [ignoring failed finish](../../tests/conformance/source/buffered_io/finish_error_leak.aji) reject E3002. [Aliasing the cached bytes](../../tests/conformance/source/buffered_io/writer_alias.aji) rejects E2101; [sharing a file-bearing adapter](../../tests/conformance/source/buffered_io/not_share.aji) rejects E4002. + +## Diagnostics / compatibility / AIR + +No new diagnostic, syntax, AIR opcode/feature or verifier/runtime rule. Existing E7003/E7005/E3002/E2101/E4101/E3101/E4002 and resource availability checks apply. Two pinned modules are additive; old std.io APIs and AIR meanings retain their contracts. No implicit allocation, cleanup, authority, timeout, task or unsafe/trusted boundary. + +## Agent complexity impact + +Five operations per concrete adapter: reader new/read/read_exact/finish/discard; writer new/write/flush/finish/discard. Known file modes keep exact fs.read/fs.write effects. Writer failure state distinguishes acceptance into an owned buffer from confirmation of external output and prohibits an unsound automatic retry. No language/verifier state is added. Full representation/failure contracts stay on demand; measured Quick Reference/source budgets follow. Existing primitives suffice, and no empirical MCC improvement is claimed. + +## Validation gate + +Independent read/segmented-write byte oracles, capacities including zero, refill/flush/exact EOF, preserved guards, empty/full pending storage, constructor failure ownership/refunds, unread/failed finish, explicit discard, files transferred to tasks and restored loans, rejected ownership/type/effect/alias/Share cases. Hosted read error, externally partial write, no retry after error, source/AIR/package/import-order/profile/provenance checks, GC/scheduler stress and required repository/bundle checks. Paths and other system modules remain subsequent work. + + +Measured cl100k growth from RFC 0033: Quick Reference 8,350 → 8,445 (+1.1%); other source documentation 58,473 → 61,223 (+4.7%); full source excluding AIR 66,823 → 69,668 (+4.3%). library/std.md is 24,364 tokens. Corresponding o200k groups are 8,478 / 61,408 / 69,886; qwen2.5 groups are 8,695 / 62,738 / 71,433. AIR remains 179,282 bytes / 19 files / 51 sections; its source-bundle copy remains 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k growth over the pre-std 33,981-token baseline is +105.0%, justified for owner review by visible prefetch/cursor, acceptance/partial-write, first-error and explicit resource cleanup contracts. Quick Reference remains beyond the 4–6k target; front-door consolidation/selective reading remains separate work. This increment adds no language syntax, diagnostic or verifier/runtime state and claims no empirical MCC improvement. + +## Validation result + +All 34 buffered adapter conformance cases pass, including collection before every instruction. Owning reader/writer transfers and restored reader loans run 12 schedule seeds under quanta 1, 2, 7 and their own quantum. Independent Python byte oracles cover 48 complete read streams, 64 exact prefixes and 96 segmented writes over empty/exact/short inputs, zero and nonzero storage, multiple refills/flushes and preserved destination guards. Fixtures cover unread finish/discard cursor behavior, no EOF probe at finish, lazy full-cache flush, explicit discard, maximum capacity, constructor failure ownership and allocation refunds to narrowed authorities. Existing diagnostics reject missing moves, resource/result leaks, wrong mode/kind/effects, aliases, active task loans and non-Share references. + +On Linux, 89 CLI checks pass: source/AIR/package/profile parity, reordered imports, pure audit and caller diagnostic provenance, a real file read fault (/proc/self/mem at unreadable offset zero), and four partial external write traces. A child-only three-byte file quota causes room-making, previous-call pending, explicit flush and capacity-zero direct write errors. The parent then raises the child's quota before the program attempts another write/empty write/flush/finish; the file remains exactly abc and the first error/pending bytes are preserved. This detects forbidden retry even when a later external write would succeed. Constructor/finish/discard failures retain complete owners, and the program explicitly closes returned files and verifies quota refunds. Tests use fuel and pipe handshakes, no wall-clock timeout or global host configuration change. macOS runs the portable checks/partial quota cases; read-fault and raised-quota retry probes are Linux-specific. + +Unit/Quick Reference, formatting, hosted smoke, 115/115 source coverage constructs and reference generation pass. Full repository conformance passes with 1061 cases, zero failures and zero pending. The buffered file adapter gate is complete on this branch. Lexical paths and Std 0.1 remain required subsequent work. diff --git a/docs/rfcs/0035-caller-buffer-lexical-paths.md b/docs/rfcs/0035-caller-buffer-lexical-paths.md new file mode 100644 index 0000000..f6a41a9 --- /dev/null +++ b/docs/rfcs/0035-caller-buffer-lexical-paths.md @@ -0,0 +1,46 @@ +# RFC 0035: Caller-buffer lexical paths + +Status: Implemented +Scope: STD-7c, std.path after owning buffered files +Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. + +## Motivation and spec integration + +Spec 16 §2.19 adds six pure path operations on bytes with one portable slash syntax. Paths are frequent CLI/storage data; normalization/join/component loops should be reusable without hidden allocations, host state or a larger authority surface. Spec 16 and reference/std.md contain the normative contracts; this record explains them. + +## Preserved invariant and verifier rule + +Output writes remain within the supplied exclusive slice, successful output preserves its suffix, and every returned input/size/capacity error preserves the entire destination. Input borrows only read; no borrow escapes, file/resource is consumed or capability is gained. Component queries return bounded Copy index ranges, keeping lifetime/bounds decisions visible in the caller. Ordinary borrow, bounds, Copy/Send/Share, task loans and effect checks apply without new verifier state. + +## Runtime / deterministic behavior + +Only safe source algorithms: validation and final-size measurement precede emission. Reverse scanning cancels components with pending parents; a second reverse pass writes retained components into the exact final prefix. Capacity is measured after cancellation, so a short destination can hold a result whose raw input was long. No heap/scratch allocation, platform branch, filesystem access, symlink interpretation or current directory. `/` is the separator in every profile. NUL rejects in writers; non-UTF-8/backslash bytes remain ordinary data. Primitive filesystem capability/path checks are unchanged and still mandatory. + +## Valid and rejected examples + +Join /data/a with ../b into a caller array, handle WriteResult, then use the resulting slice with an explicit fs capability. Normalization alone cannot authorize the path. Disjoint slices within one allocation are valid; overlapping source/output, task-loaned output and wrong scalar/slice types reject through existing diagnostics. The [pure example](../../examples/std/path.aji) joins into caller storage and borrows its component ranges. [A one-byte canceled result](../../tests/conformance/source/path/canceled_capacity.aji) and [disjoint slices](../../tests/conformance/source/path/disjoint.aji) are valid. [Overlapping slices](../../tests/conformance/source/path/overlap.aji) reject E2101; [a live task loan](../../tests/conformance/source/path/loan.aji) rejects E4101. [Authority](../../tests/conformance/source/path/authority.aji) remains independently enforced, and [reusing a range on a shorter input](../../tests/conformance/source/path/range_bounds.aji) traps T0008 through ordinary bounds checking. + +## Diagnostics / AIR / compatibility + +No new diagnostic, source syntax, AIR instruction/feature/meaning, verifier/runtime state or trusted boundary. Existing E7002/E7005/E2101/E4101 apply. WriteResult variants are ordinary Copy data; insufficient output and malformed input do not trap or mutate output. All existing paths/fs grants/source/AIR contracts retain their meaning. Q-034 is neither expanded nor silently inferred: callers explicitly borrow a returned Range from their own path. + +## Agent complexity impact + +Six supported operations: is_absolute/basename/parent/extension/normalize/join. One separator syntax and one destination-first writing result. Queries report raw bounded offsets without borrowed returns; writing reports final prefix size and has an unchanged-output error contract. No agent needs platform-specific normalization, hidden allocation or lifetime inference. Existing primitives suffice; no language concepts, verifier state, syntax forms or diagnostics are added. Full edge rules stay on demand. Measured Quick Reference/source bundle budgets follow; no empirical MCC benefit is claimed. + +## Alternatives considered + +Host-dependent paths would make deterministic fixtures/platform reasoning harder and disagree with the existing runtime slash syntax. Borrowed query returns would require a separate vertical lifetime feature before safe source can use them. Requiring raw-input-sized output would fail ordinary cancellation cases unnecessarily. In-place mutation would need explicit overlap semantics and would violate the current exclusive-output/shared-input contract. Adding an opaque path opcode is unnecessary. + +## Validation gate + +Independent forward-stack byte oracle; empty/root/relative/absolute, repeated separators, dot/parent cancellation, root saturation, hidden/multiple/trailing extensions, non-UTF-8/backslash/NUL, exact/short capacities, late malformed input, suffix preservation, disjoint same-allocation slices and small canceled-result output. Rejected aliases/types/imports/task loans; valid task transfer/restored loans; source/AIR/package/profile/provenance/audit and authority checks; GC/scheduler stress, full conformance, unit/Quick Reference, formatting, source coverage and documentation budget. STD-7 completes only after this gate; STD-8 and the broader roadmap remain required. + + +Measured cl100k growth from RFC 0034: Quick Reference 8,445 → 8,518 (+0.9%); other source documentation 61,223 → 63,296 (+3.4%); full source excluding AIR 69,668 → 71,814 (+3.1%). library/std.md is 26,437 tokens. Corresponding o200k groups are 8,552 / 63,497 / 72,049; qwen2.5 groups are 8,768 / 64,821 / 73,589. AIR remains 179,282 bytes / 19 files / 51 sections; its source-bundle copy remains 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k growth over pre-std 33,981 is +111.3%, justified for owner review by visible byte syntax, cancellation/root, range/capacity and authority contracts. Quick Reference is beyond its 4–6k target; front-door consolidation/selective reading remains separate work. No new syntax, diagnostic or verifier/runtime state is added, and no empirical MCC improvement is claimed. + +## Validation result + +All 1079 repository conformance cases pass, including 18 path fixtures. The independent Python forward-stack oracle covers 132 paths with queries/idempotence and every short/exact/extra output capacity, 49 joins and four malformed pairs. All 255 non-NUL bytes are additionally tested. Fixtures cover one-byte canceled outputs, late malformed input winning over short capacity (including ignored base), suffix/guard preservation, raw ranges, no borrowed-return inference, disjoint same-allocation slices, aliases, task loans, wrong types/imports and independent filesystem authority. Reused ranges retain normal runtime bounds checks, with T0008 on a shorter unrelated path. + +68 CLI/source/AIR/package/profile/provenance/audit checks pass. Pure APIs use no entry grants, heap allocation or unsafe sites. Lowered AIR and source agree; reordered imports/package loading/name collisions are deterministic. Hosted cases cover arbitrary byte components and actual denied-file authority independently of normalization. Unit/Quick Reference, formatting, 117/117 source coverage constructs and reference generation pass. All 18 path fixtures pass the collection-before-every-step gate; scheduled fixtures pass 12 seeds under quanta 1, 2, 7 and their own quantum. The oracle batches preserve every vector/capacity while ending literal frames between batches, bounding collector roots. STD-7c and the intermediate STD-0..7 foundation are complete. STD-8 and Std 0.1 remain unfinished. diff --git a/docs/spec/01-language-overview.md b/docs/spec/01-language-overview.md index 05db3e5..8552f1d 100644 --- a/docs/spec/01-language-overview.md +++ b/docs/spec/01-language-overview.md @@ -94,10 +94,10 @@ Every trap has a stable code in the `T0xxx` range of [`../reference/error-codes. ## 7. Generics -Aji supports monomorphized generics. +Aji supports explicit monomorphized generics (source contract: spec 15 §15). Calls use `swap::(mut a, mut b)`; type annotations use `Pair`. ```aji -fn swap(a: mut, b: mut) { ... } +fn swap(a: mut, b: mut) -> void effects [] { ... } ``` Version 0.1 does not require user-defined traits/typeclasses. Generic constraints use compiler-known structural properties such as `Copy`, `Send`, `Share`, `Freeze` and `Local`. diff --git a/docs/spec/03-memory-model.md b/docs/spec/03-memory-model.md index 1ed7dc2..d3162f3 100644 --- a/docs/spec/03-memory-model.md +++ b/docs/spec/03-memory-model.md @@ -252,7 +252,7 @@ Invariants: 3. **No dangling access.** Heap and region memory is reached only through second-class borrows, which cannot outlive the owner (heap) or the region generation (regions). There are no runtime generation checks. 4. **Bounded memory.** Every allocation is charged against a budget held by the authority object of the capability. The budget limits the bytes that are **live at the same time**. 5. **Shared quota.** Copies of a capability refer to one authority object and share one budget; narrowing creates a child budget whose charges also count against every ancestor. -6. **No hidden destruction of linear values.** `own.free`, `own.take`, `region.reset` and `region.destroy` can never make a linear value disappear: until `linear_aggregates` is specified, values stored in `own`, `own_array` and region allocations MUST NOT transitively contain linear values (resources, owners, regions). +6. **No hidden destruction of linear values.** `own.free`, `own.take`, `region.reset` and `region.destroy` can never make a linear value disappear: Copy-only allocations retain this restriction. Feature `linear_aggregates` permits individual `own` content with ownership-preserving `own.pack`/`own.take` (§25); own.free and bulk arrays/regions cannot destroy linear content. ### 18.1 Budget semantics @@ -313,7 +313,7 @@ Both are linear and not copyable; as members of aggregates they need `linear_agg Heap memory is always initialized, so no initialization tracking is needed. `own.free` or `own.take` while a borrow of the owner is live is `E2101`. `own.take` is the inverse of `own.new` (`T → own → T`); an `own_array` has no `take`, since a runtime-sized array is not an SSA value. -`T` in `own` and `own_array` must be a value type; a linear `T` (for example `own>` or `own>`) needs `linear_aggregates` (`E0006` reason `feature_not_declared`), which will define extraction and destruction of nested linear values. An owner is passed to a function by value (moving it) or by borrow (lending it), exactly like a resource. +`T` in baseline `own` and in `own_array` must be Copy. Linear `T` in individual `own` needs `linear_aggregates` (`E0006` reason `feature_not_declared`), whose whole-value extraction/allocation rules are §25; bulk linear heap arrays remain unsupported. An owner is passed to a function by value (moving it) or by borrow (lending it), exactly like a resource. ## 20. Regions in AIR (feature `regions`) @@ -370,7 +370,7 @@ Decision record: RFC 0014. Depends on `heap` and its closure. - `island`: a graph owner; linear; `Send`, not `Share`. - `iref`: an opaque `{graph identity, slot}`; copyable, `IslandSafe`, `Send`, `Share`. -Graph owners may be parameters, returns, block arguments, channel elements and mutex contents. They may not be aggregate members (`linear_aggregates` stays reserved). +Graph owners may be parameters, returns, block arguments, channel elements and mutex contents. Their membership in aggregates requires `linear_aggregates` (§25); it does not weaken IslandSafe graph-content rules. **Identity.** A graph's identity comes from a per-execution counter and is never reused. A handle cannot be built from, cast to or inspected as an integer. @@ -445,3 +445,28 @@ The count is not a user atomic: no memory ordering is chosen by the program. Eac | `frozen.release` | − the graph | | `island.destroy` | − the graph | + +## 25. Linear aggregates in AIR + +Feature `linear_aggregates` permits resources, owners, regions, graph owners, atomic cells, channel endpoints and mutexes as struct fields, enum payloads and fixed-array elements. Borrows/storage, task/scope/shield and guards MUST NOT become aggregate members; their existing gates remain. A declared aggregate or fixed array is linear exactly when any transitive member is linear. All variants contribute to an enum's class, including a payload-free variant. Copy remains structural. Ownership type graphs through aggregate members and owning wrappers MUST be acyclic (E1003); `iref` graph edges remain opaque. This initial feature does not add partial moves, holes, automatic cleanup or dynamic linear buffers. + +Construction (`struct.make`, `enum.make`, `array.make`) MUST consume every linear input exactly once and produce one complete owned value. Every normal path MUST transfer or fully unpack that value; no nested resource may disappear. Copy projections of a live linear struct are allowed, but projecting a linear field with `struct.get`, or duplicating a linear value with `copy`, `load`, `local.load`, `array.splat` or `slice.copy`, MUST reject E1001. Ordinary `store` MUST NOT overwrite linear content. Borrowed fields/elements use existing exclusive/shared alias and task-loan rules; `value.swap` exchanges a complete initialized value with an explicitly supplied replacement and returns the previous value. No field is ever uninitialized. + +`struct.unpack` and `array.unpack` consume their whole operand and deliver every field/element in declaration/index order to one continuation. `enum.take` consumes its whole enum and delivers the selected payload to an exhaustive variant continuation. It MUST have every variant exactly once and no default. Payload-free variants still consume the enum. Copy operands may also be unpacked; they remain available. Existing `enum.switch` remains observational and MUST NOT read a linear enum. Existing linear diagnostics E2001/E2002/E3001/E3002 apply to moved, repeated or missing consumption, with E2101/E4101 for live borrows/task loans. + +Among heap/frame/region storage forms, only individual `own` may hold linear aggregate content in this phase; channels and mutexes retain their existing complete-value transfer rules. `own.pack` explicitly moves a value into an individually owned allocation: on failure, the error continuation receives both alloc_error and the original complete value. `own.take` consumes the owner, frees the allocation and returns its complete content, including all nested owners/resources. `own.free` MUST reject E1001 when content is linear. Repeated heap arrays, region allocations and frame locals MUST remain Copy-only; bulk freeing cannot destroy resources. Dynamic linear buffers require a separate feature/API with an explicit drain contract. Existing heap/region operations on Copy values retain their semantics. + +Verifier state is whole-value availability, existing borrow provenance and initialization, with no per-field moved state. Structural Send/Share still apply, so transfer to workers/channels/mutexes requires their ordinary rules. The deterministic interpreter moves existing handles, performs swaps as one instruction and uses existing allocation budgets/fuel; it performs no user cleanup on normal paths or traps. AIR format 0 remains compatible: previously unsupported feature/type/opcode cases gain meanings; previously accepted Copy modules keep identical behavior. + + +## 26. Dynamic initialized buffers + +Feature `linear_buffers` adds the linear complete value `buffer`, accounted handle size 24 bytes. T MUST be a complete value with ordinary linear_aggregates member rules: no borrow/storage/function-bound content. Ownership type graphs through buffer wrappers MUST be acyclic (E1003). `buffer` is Send exactly when T is Send and Share exactly when T is Share, like own_array. Local propagates through T; no guard/task/channel-transfer gate is weakened. + +A buffer uniquely owns capacity C and a contiguous initialized prefix of length L, 0 ≤ L ≤ C. Only [0,L) is observable. Every live linear element is owned exactly once inside that prefix. There are no observable holes, default values, implicit destructors or partially moved fields. Constructors start with L=0. Push/pop change the prefix by one complete value; pop is LIFO. Views borrow precisely the prefix. Metadata changes, growth and consumption obey ordinary exclusive alias and task-loan rules; a live view excludes those operations, even when a dynamic branch would perform no change. + +Allocation charges C × accounted_size(T), using checked arithmetic and the named mem.alloc authority. Overflows/authority exhaustion return alloc_error::budget_exceeded. Zero capacity is valid and charged zero. Capacity is a target usize, not a format-0 fixed-array type length. Growth to C' > C allocates explicitly from the supplied authority: it MUST charge the complete new capacity before releasing the old charge to its original authority. Thus peak live charges include both allocations. Success transfers all initialized values and changes capacity/authority; failure preserves length, capacity, contents and old authority exactly. A request ≤ C succeeds without mutation/allocation, but public effects/capability requirements remain explicit. Unused capacity contains no user value and cannot be borrowed. + +Push requires no allocation effect or capability: if L` is **linear**, `Send` and `Share`, and not copyable. - It may appear where graph owners may (spec 03 §22): SSA values, parameters, returns, block arguments, channel elements and mutex contents. -- As an aggregate member or as the contents of `local`, `own` or a region it needs `linear_aggregates` (`E0006`). +- As an aggregate member or individual own content it needs `linear_aggregates` (spec 03 §25; E0006 without it). Frame/bulk-region/heap-array content remains Copy-only. - It is not `IslandSafe` (`E2111`). - Size and alignment equal those of `T`. @@ -556,7 +556,7 @@ Example: two workers square the two halves of one buffer in parallel; both loans | integers, `bool`, built-in enums | yes | yes | | `cap` (every kind) | yes | yes — the authority object is shared and its host side is synchronized | | `file<…>`, `listener`, `stream` | yes | no | -| `own`, `own_array` | if `T` is | if `T` is | +| `own`, `own_array`, `buffer` | if `T` is | if `T` is | | `region` | yes | no — allocation through a shared borrow mutates the region | | `ref` | if `T` is `Share` | if `T` is `Share` | | `mut` | if `T` is `Send` | no | @@ -718,7 +718,7 @@ Decision record: RFC 0012. Depends on `cancellation`, `heap`. | `sender` | a sending endpoint | linear | | `receiver` | the receiving endpoint, exactly one per channel | linear | -Endpoints may be block arguments, function parameters and return values, and may be moved into tasks. They may not be aggregate members (reserved `linear_aggregates`) or heap contents. Channels are MPSC: several receivers are the reserved feature `receiver_dup`. +Endpoints may be block arguments, function parameters and return values, and may be moved into tasks. Aggregate membership and individual own content require `linear_aggregates` (spec 03 §25); bulk heap arrays remain Copy-only. Channels are MPSC: several receivers are the reserved feature `receiver_dup`. **Element rules** for `T` (also used by `mutex`, §40): @@ -857,4 +857,3 @@ Common properties: - *Exact coverage, normative litmus corpus only.* For every test of `reference/concurrency-litmus.md`, the outcomes observed under exhaustive exploration equal the oracle's allowed set: `observed_exhaustive = allowed` (§20.5). - *Weak reads.* A read whose ordering is not `seq_cst` may read any write the model allows. The choice is a draw from the schedule generator (§36.2) and counts in `schedule.choices`. - *No weak access.* A run with no non-`seq_cst` access makes no extra draw, and every read reads the latest write. - diff --git a/docs/spec/05-effects-and-capabilities.md b/docs/spec/05-effects-and-capabilities.md index b858766..62fe0a2 100644 --- a/docs/spec/05-effects-and-capabilities.md +++ b/docs/spec/05-effects-and-capabilities.md @@ -289,3 +289,15 @@ atomic.new, atomic.take → no effect For compare-exchange, the operation is non-`seq_cst` if either ordering is. A missing atom is `E3101`. If `atomic.weak` is not among the transitive effects of `@main`, every atomic access is `seq_cst`, and every execution of the safe program is explainable as an SC interleaving (spec 04 §22). + +## 14. Explicit error values (feature `error_values`) + +An error is Copy data, not authority or proof that an operation occurred. Safe code MAY create any registered payload-free variant of `alloc_error` (spec 03 §18), `cap_error` (§10) or `io_error` (spec 06 §7). Creating an error MUST NOT allocate, perform I/O, narrow a capability, change resource state or grant authority. Actual fallible operations retain their specified outcome rules. + +In AIR, `%e = error.const B.variant` has two static operands: a built-in error family `B` and one of its registered variant names. It takes no SSA operands or payloads and produces exactly one Copy value of type `B`. The module MUST declare `error_values` and its full dependency closure (`capabilities`, `effects`, `heap`, `ownership`, `resources`). These dependencies make all three existing error families available; they grant no capabilities. + +The verifier MUST validate the family and variant (`E0004` for an unknown name in text), result uses (`E1001` for a type mismatch) and feature declaration (`E0006`). Its transfer function introduces one available Copy value; it changes no ownership, borrow, memory, concurrency or authority state. Effects and capabilities required: none. Instruction-specific traps: none. The interpreter deterministically binds the selected family/tag as ordinary built-in error data; the instruction consumes normal fuel. The payload syntax is not permitted (`E0001`). + +Source uses the existing variant expression `alloc_error::budget_exceeded`, `cap_error::not_subset` or `io_error::invalid_input`, lowering to `error.const`; the frontend MUST include the feature closure. Every registered variant is constructible; errors cannot be converted into capabilities. Source rejects unknown variants with `E7002`, payloads with `E7005`, and wrong result types with `E7005`. + +Valid: a pure function returning `alloc_error::budget_exceeded` before overflowing an allocation size. Rejected: returning that value from a function returning `cap` (`E7005` / AIR `E1001`). Existing `enum.make` remains restricted to declared enums. This is an additive format-0 feature; no existing instruction, error tag, fallible outcome or authority rule changes. diff --git a/docs/spec/06-resources-and-errors.md b/docs/spec/06-resources-and-errors.md index eb1ba2f..7e9701c 100644 --- a/docs/spec/06-resources-and-errors.md +++ b/docs/spec/06-resources-and-errors.md @@ -87,7 +87,7 @@ The mode of a file is part of its type, so using a file in the wrong mode is a v Resource types are **linear** and **authority-bearing** (spec 05 §10.1): not copyable (`copy` is `E1001`), not zeroable, not comparable, not serializable. -In format 0, resource types MUST NOT appear as struct fields, enum payloads or array elements; that requires the reserved feature `linear_aggregates` (`E0006` reason `feature_not_declared` without it). They may appear as function parameters, return types, block parameters and as operands of borrow instructions. +Resource types as struct fields, enum payloads or fixed-array elements require `linear_aggregates` (spec 03 §25) (`E0006` reason `feature_not_declared` without it). They may appear as function parameters, return types, block parameters and as operands of borrow instructions. ### 6.2 Consumption diff --git a/docs/spec/07-air.md b/docs/spec/07-air.md index 3535477..7ce2177 100644 --- a/docs/spec/07-air.md +++ b/docs/spec/07-air.md @@ -222,7 +222,7 @@ Features describe what the implementation must understand. They grant no authori - Integer types, `bool`, `void` and `never` are built in. `usize`/`isize` are distinct from all fixed-width types; their width comes from the target description (spec 09 §9). - `type @T = struct { … }` and `type @T = enum { … }` declare nominal aggregate types. An aggregate MUST NOT contain itself by value, directly or through other aggregates (`E1003`). -- Every type defined in this section is copyable. Types added later under §8.7 (for example `Own` in Phase 1) may be move-only or linear; that does not change the types defined here. +- Baseline aggregate types are Copy. Under `linear_aggregates`, newly permitted linear members make structs/enums/fixed arrays linear structurally (spec 03 §25); baseline Copy aggregates retain their semantics. - `void` is only valid as a function return type. A `void` function returns with `ret` without operand; a call to it MUST NOT bind a result. A `never` function MUST NOT contain `ret`. ### 8.4 Reserved @@ -258,6 +258,8 @@ Any other change to format 0 — a different meaning, typing rule, trap behavior `cap` (feature `capabilities`) is an opaque, copyable, authority-bearing value type; `K` is a registered capability kind ([`../reference/capabilities.md`](../reference/capabilities.md)). Built-in enums such as `cap_error` and `io_error` are spelled without `@`, have registered variants and are used with `enum.switch %v, …` like declared enums. Rules: spec 05 §9–§12. +Feature `error_values`: `%e = error.const alloc_error.budget_exceeded` creates ordinary Copy error data without authority or effects (spec 05 §14); `enum.make` remains a declared-enum instruction. + Feature `resources`: `file`, `file`, `file`, `listener`, `stream` are linear, authority-bearing resource types (spec 06 §6). Feature `heap`: `own` and `own_array` (linear owners, `T` a value type) and the built-in enum `alloc_error`. Feature `regions`: `region` (linear). Rules: spec 03 §18–§21. Linear values — resources, owners and regions — follow the consumption rules of spec 06 §6.2–§6.3. @@ -289,6 +291,6 @@ Feature membership: `local`, `ref`, `mut` and the `from` clause belong **Second-class rule.** Storage and borrow types MUST NOT appear as struct fields, enum payloads, array elements or the `T` of another storage or borrow type (`E1001`). A storage type MUST NOT appear as a function parameter, return type or block parameter (`E1001`). A borrow type MAY appear as a function parameter and, with `from`, as a return type (spec 08 §11.3). As a block parameter type it requires the reserved feature `borrow_joins` (spec 08 §11.6). -All value types of format 0 and Phase 1 are copyable. Move-only values arrive with `heap` in Phase 2. +Baseline value types are Copy; owners/resources and feature-gated linear aggregates obey whole-value consumption (spec 03 §25). Syntax additions (reference/air-text.ebnf): `-> type from %param` on function signatures, the type forms above, and `%a, %b = op` for instructions specified with two results (`slice.split`; `atomic.cmpxchg` with feature `atomics`, spec 04 §42). diff --git a/docs/spec/07a-air-instructions.md b/docs/spec/07a-air-instructions.md index 556307a..125a72d 100644 --- a/docs/spec/07a-air-instructions.md +++ b/docs/spec/07a-air-instructions.md @@ -6,7 +6,7 @@ This file covers the format-0 baseline (Phase 0) and the features `ownership` an ## Common contract for format version 0 -All format-version-0 instructions operate on copyable values only. Unless an entry says otherwise: +The baseline instructions operate on Copy values; feature-specific contracts below specify linear ownership. Unless an entry says otherwise: | Field | Value | |---|---| @@ -22,6 +22,15 @@ Notation: `T` is the type suffix of the opcode; `I` ranges over integer types; ` ## Values +### `error.const B.variant` (feature `error_values`) + +- Static operands: built-in error family `B` and its registered payload-free variant; no SSA operands. +- Result: one Copy value of type `B`. +- Ownership/borrow/memory/concurrency transitions: none; effects and capabilities required: none; traps: none. +- Verifier transfer: define one available Copy value. Unknown family/variant: `E0004`; undeclared feature: `E0006`; incompatible result use: `E1001`. Payload syntax: `E0001`. +- Interpreter: bind the built-in family/tag deterministically, using normal fuel; no program allocation or authority acquisition. +- Complete contract and source syntax: spec 05 §14. `enum.make` is unchanged. + ### `const.T lit` - Operands: an integer literal (`T` ∈ `I`) or `true`/`false` (`T` = `bool`). @@ -309,3 +318,46 @@ Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (capture - every entry of `files`: always `{"encoding":"base64","data":"…"}`, since file contents are arbitrary bytes. Base64 is RFC 4648 with padding. Two records are equal exactly when their bytes are equal. When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap. + +## Linear aggregates (`linear_aggregates`) + +These contracts specialize ownership of newly enabled linear member types; baseline Copy instructions keep their prior semantics. All instructions require `linear_aggregates`; an array type also requires `arrays`, and `own.pack` also requires `heap`. Existing feature dependency closures apply. + +### `array.make array(%v0, …, %vN-1)` + +Operands MUST be exactly N complete values of T (E1001). Result is array. Linear inputs are consumed, each exactly once; Copy inputs remain available. Memory, synchronization, effects, capabilities and traps: none. Interpreter assembles elements in order. Verifier marks a linear result available. Normal SSA/size/argument limits apply. + +### `struct.unpack @S %value, next -> @block` and `array.unpack array %value, next -> @block` + +Operand MUST have the named struct/array type. No SSA result; the sole continuation MUST have all field/element parameters of exactly those types in order (E5002 counts, E1001 types). The whole linear operand is consumed and linear parameters become available; Copy operands remain available. Memory, synchronization, effects, capabilities and traps: none. Interpreter transfers every component and jumps. Block-parameter/size limits apply; there are no ignored components. + +### `enum.take @E %value, Variant -> @block, …` + +Operand MUST be the named enum type; every variant MUST appear exactly once with no default (E5002). No SSA result; target payload types/counts follow ordinary enum.switch rules. It consumes a linear operand and transfers its selected complete payload; Copy operands remain available. Memory, synchronization, effects, capabilities and traps: none. Interpreter selects the tag deterministically. Existing enum.switch MUST reject E1001 for a linear enum. + +### `%old = value.swap %borrow, %replacement` + +Operands MUST be mut and T; T MUST be an initialized value, never a borrow/storage/function-bound value (E1001). Result T. A linear replacement is consumed; a linear result becomes available. The borrowed place remains initialized with the complete replacement. Reads/writes: the whole place; exclusive alias and task-loan rules apply (E2101/E4101). Synchronization, effects, capabilities and traps: none; swapping an atomic cell through an ordinary borrow remains forbidden (E4202). Interpreter exchanges whole values in one instruction, retaining existing race instrumentation. + +### `own.pack T %value, %cap, ok -> @success, err -> @failure` + +Operands MUST be complete T and cap (E1001/E3201); T may be Copy or linear. No SSA result; success receives own, failure receives (alloc_error,T) (E5002/E1001). Linear input is consumed on both edges; success owns it inside the allocation, failure owns the same original value. Memory: new allocation initialized with the complete value on success; none on failure. Effects: mem.alloc. Capability: explicit bounded mem.alloc. Synchronization/traps: none; ordinary alloc_error failure reasons/budget rules apply. Interpreter transfers handles without duplicating ownership and charges/frees the same accounted bytes as own.new/own.take. + + +## Dynamic buffers (`linear_buffers`) + +These instructions add no concurrency effects. Metadata access uses existing shared/exclusive race and task-loan checks; views carry child provenance. Valid buffer states MUST NOT trap; allocation failure is an outcome, while execution limits retain spec 11 behavior. + +All operations require linear_buffers and its full dependency closure (arrays, capabilities, effects, heap, linear_aggregates, ownership, resources). buffer content and lifetime rules are spec 03 §26. T MUST be a complete value. Counts/indices are usize. All continuations receive exactly the listed parameters (E5002 count, E1001 types), with no SSA result for terminators. New operations add no traps, except existing borrowed-index bounds checks applied to a view. No synchronization is performed. + +| Instruction | Operands/result or continuations | Ownership/memory/transfer | Effects/capabilities | +|---|---|---|---| +| `buffer.new T %capacity, %cap, ok -> @ok, err -> @err` | usize, cap; ok(buffer), err(alloc_error) | new initialized empty prefix; no consumed input; successful result owned | mem.alloc, explicit mem.alloc cap | +| `%n = buffer.len %borrow` / `%n = buffer.capacity %borrow` | ref> or mut> → usize | shared metadata read through live borrow, no consumption | — | +| `buffer.reserve %borrow, %capacity, %cap, ok -> @ok, err -> @err` | mut>, usize, cap; ok(), err(alloc_error) | exclusive metadata/storage access; charge new backing before releasing old; failure preserves buffer; borrow remains live on both edges | mem.alloc, explicit mem.alloc cap | +| `buffer.push %borrow, %value, ok -> @ok, err -> @err` | mut>, T; ok(), err(T) | exclusive access; linear input consumed on both edges; success appends, failure returns original value; borrow remains live | — | +| `buffer.pop %borrow, ok -> @ok, err -> @err` | mut>; ok(T), err() | exclusive access; success removes/owns last value; empty preserves prefix; borrow remains live | — | +| `%view = buffer.view %borrow` | ref> → slice; mut> → slice_mut | child borrow of initialized prefix, same shared/exclusive mode and provenance; MUST explicitly end; no ownership transferred | — | +| `buffer.free %buffer, ok -> @ok, err -> @err` | buffer; ok(), err(buffer) | linear handle consumed on both edges; empty frees/releases charge, nonempty returns same complete buffer; live descendant borrows/task loans reject | — | + +Verifier transfer uses existing whole-value availability for new/free and returned linear block parameters, and useThrough/child provenance for borrowed operations. Length/capacity/view are shared/exclusive access as declared above; all modifying operations require exclusive access even for an empty/full/no-op dynamic case (E2101/E4101). Runtime observes L/C, updates the initialized prefix atomically per instruction and selects the corresponding continuation deterministically. Allocation overflow/exhaustion selects err(alloc_error); no user value is destroyed by a failing operation. Local/borrow/task-bound element types, mismatches and copy/overwrite of linear contents reject E1001; cyclic ownership rejects E1003. Existing resource-leak/repeated-consumption errors apply. No new diagnostic/effect/capability/trap is introduced. diff --git a/docs/spec/08-verifier.md b/docs/spec/08-verifier.md index d137023..142a78e 100644 --- a/docs/spec/08-verifier.md +++ b/docs/spec/08-verifier.md @@ -47,6 +47,8 @@ resource state ## 4. Ownership state machine +For `error.const` (feature `error_values`, spec 05 §14), verification introduces one available Copy value of the selected built-in error type. It MUST NOT alter authority, resource, memory, borrow or concurrency state. The static family/tag and ordinary result-use typing MUST be checked. + Representative states: ```text @@ -120,6 +122,7 @@ The **accounted size** of a type is a normative, platform-independent metric of | enum | `tag + ` the largest sum over one variant's payload, where `tag` is the smallest of 1, 2, 4, 8 bytes that can hold the index of every variant | | `ref`, `mut` | 8 | | `slice`, `slice_mut` | 16 | +| `buffer` (linear_buffers) | 24 | `void`, `never` and storage types (`local`) are not materializable values and have no accounted size; the `T` inside a storage type does. diff --git a/docs/spec/12-packages-and-build.md b/docs/spec/12-packages-and-build.md index 4f608cc..82bf1c6 100644 --- a/docs/spec/12-packages-and-build.md +++ b/docs/spec/12-packages-and-build.md @@ -4,7 +4,7 @@ A package contains an `aji.toml` manifest. Decision record for capability grants: RFC 0010. -1. **A manifest requests; the operator grants.** The author of a package writes `[capabilities]`. Authority is granted only when someone explicitly runs the program with that manifest (`aji run --manifest`). Building, verifying or installing never grants anything (spec 05 §6). +1. **A manifest requests; the operator grants.** The author of a package writes `[capabilities]`. Authority is granted only when someone explicitly runs the program with that manifest (`aji run --manifest` or `aji explore --manifest`). Building, verifying or installing never grants anything (spec 05 §6). 2. **Same model as `--grant`.** One entry per `@main` capability parameter: `parameter = "kind[:scope]"`. All instantiation rules apply unchanged (missing, mismatched, unknown, invalid scope; mandatory `mem.alloc` budget in the deterministic profile). 3. **The operator has the last word.** A command-line `--grant P=…` replaces the manifest entry for `P`, for example to point a scope at another directory. It never silently adds parameters: an unknown parameter is still `unknown_parameter`. 4. **Strict parsing.** Unknown sections, unknown keys and duplicate keys are errors, so a typo cannot silently drop or misplace authority. @@ -42,10 +42,31 @@ aji run --manifest aji.toml [--grant P=KIND[:SCOPE]]... [other run options] - The module is the manifest's `entry`; a file argument is not allowed together with `--manifest`. - Grants are the manifest's `[capabilities]` entries, each replaced by a `--grant` for the same parameter if given. -- `aji check` and `aji report` do not read manifests. +- `aji check`, `aji lower` and `aji report` read a manifest only with explicit `--manifest PATH`, selecting its entry and module inputs without granting program authority. `aji explore --manifest PATH` uses its entry/module inputs and grants with the same override rules as run. Manifest errors (unreadable file, syntax, unknown section or key, duplicate key, missing `name`/`version`/`entry`, malformed grant string) are reported before verification as a usage error (exit code 2) with a message naming the line. Structured manifest diagnostics belong to the package tooling of Phase 8. +### 1.3 Package source mapping + +An optional `[modules]` table maps dotted source module names to manifest-relative `.aji` file paths: + +```toml +[package] +name = "record-tool" +version = "0.1.0" +entry = "src/main.aji" + +[modules] +app.model = "src/model.aji" +app.work = "src/work.aji" +``` + +Mapping keys MUST be ASCII identifier components separated by dots and MUST NOT occupy standard/built-in namespaces (spec 15 §14). Duplicate keys remain manifest errors. With this section present, `entry` is required and MUST name `.aji` source; entry/mapped paths MUST be nonempty portable relative paths with `/` separators and no empty, `.` or `..` component, backslash, colon or NUL. They MUST end in `.aji`. Every directory component and source file MUST be opened without following symlinks, relative to the selected manifest directory; that directory is the operator-selected root. Directory/file handles stay open while descending/reading to avoid substituting an ancestor with a symlink. Nonregular sources MUST be rejected. Unsupported safe no-follow behavior MUST fail rather than silently read outside the package. + +The loader MUST read entry first, then mapped files in lexicographic module-name order into fixed compilation inputs. All mapped files are explicit build inputs and MUST be readable even if unreachable; only the reachable graph is parsed/linked (spec 15 §14). No source is executed during loading. The manifest is limited to 1 MiB, at most 1,024 mapped modules and the total source snapshot to 64 MiB. Invalid bindings/paths, unavailable files, symlinks, input limits and other I/O errors use the existing usage/I/O error contract (exit 2 before verification); source graph/name/type errors are verification rejection (exit 1, JSON diagnostics). Manifests without `[modules]` retain their entry-loading contract. + +Commands accept one file or `--manifest PATH`, never both. Check/lower/report never grant program authority; run/explore instantiate only with explicitly selected manifest grants and command-line overrides. No implicit manifest discovery is allowed. + ## 2. Reproducibility Given the same: diff --git a/docs/spec/15-source-language.md b/docs/spec/15-source-language.md index 25ea57b..caefdb3 100644 --- a/docs/spec/15-source-language.md +++ b/docs/spec/15-source-language.md @@ -29,7 +29,7 @@ It MUST NOT hide: Rules: -1. Lowering is a pure function of the source: the same module gives byte-identical canonical AIR (spec 07 §8.5). +1. Lowering is a pure function of its explicit source inputs: the same module graph gives byte-identical canonical AIR (spec 07 §8.5). 2. No source construct admits a program whose AIR the verifier rejects. Errors the verifier would find are reported with the verifier's code (§9). 3. `.aji` 0.1 covers the published features of Phases 0–3 and nothing else. 4. Every construct has **one canonical spelling**. There are no alternative forms of the same operation. @@ -58,6 +58,7 @@ effects [io.read, io.write] ``` - A file holds one module: `module `, then type and function declarations in any order. +- Between the module header and declarations, `import ;` imports a standard (§13) or explicitly supplied package module (§14). `import` is contextual at this position; it remains an ordinary identifier elsewhere. - `//` starts a line comment. - Function `f` lowers to `@f`; type `T` to `@T`. - **Signature.** `fn name(params) -> type`, then optionally `from p` for a borrow return (spec 08 §11.3), then the line `effects [...]`, then the body block. @@ -75,7 +76,7 @@ The AIR spellings are used (spec 07 §8): - integers `u8`…`u128`, `usize`, `i8`…`i128`, `isize`; `bool`, `void`, `never`; - named types; - `ref`, `mut`, `slice`, `slice_mut`; -- `own`, `own_array`, `region`; +- `own`, `own_array`, `buffer` (§17), `region`; - `cap`; - `file`, `listener`, `stream`; - `task`, `sender`, `receiver`, `mutex`; @@ -158,7 +159,7 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass 6A has no destructuring: no `let Point { x, y } = p`, no nested patterns, guards or or-patterns. -**Calls.** `f(args)` calls a function of the module. Built-in operations are called by their AIR names (§7, §8). Arguments are evaluated left to right. +**Calls.** `f(args)` calls a local function; a directly imported function uses its full path (§13–§14). Built-in operations are called by their AIR names (§7, §8). Arguments are evaluated left to right. **Borrows and places.** A place is: @@ -178,7 +179,7 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass | `s.len` | `slice.len`, or the static length of an array | | `s[a..b]` | a sub-slice (`slice.sub` with start `a`, length `b - a`); a borrow, so it is bound or passed, never a value | | `let (left, right) = s.split_at(k);` | `slice.split`: two disjoint borrows of `s`. Besides `atomic.compare_exchange` (§12), the only multi-result binding. There is no general tuple destructuring. | -| `slice.copy(mut dst, ref src)` | `slice.copy`, the only copy form | +| `slice.copy(mut dst, ref src)` | primitive `slice.copy`; insufficient capacity traps. Recoverable byte copy is `std.bytes.copy` (spec 16 §2.4). | **Writes.** @@ -198,7 +199,7 @@ The value is evaluated first, then the place is borrowed for the store and the b **Arrays and byte strings.** -- `[e; N]` evaluates `e` once and copies the value N times (`array.splat`). The element must be copyable; a linear element is `E7006`. +- `[e; N]` evaluates `e` once and copies the value N times (`array.splat`). The element must be copyable; a linear element rejects (E1001 for the §16 surface). - `b"…"` is an immutable `[u8; N]` value held in frame storage, written there byte by byte, with no heap. The escapes are exactly `\n \r \t \\ \" \0 \xNN`. - Used where a `slice` is expected, it is borrowed for the operation. @@ -234,10 +235,11 @@ match io.stdin_read(input, mut buf) { - **Match kinds.** The parser decides the kind of a `match` from its arms: `Enum::Variant` arms make an enum match, integer literals and `_` an integer match, and bare outcome names (`ok`, `err`, `closed`, `cancelled`, `pending`) an outcome match. Outcome names are not enum patterns. In an outcome match the scrutinee MUST be a fallible operation (`E7006` otherwise). Each outcome is matched exactly once: a repeated one is `E7006`, an unknown one `E7002`, a wrong number of bound names `E7005`. A fallible operation outside an outcome match or `or trap` is `E7006`. - **Outcome values.** `err(e)` binds the real error value (`alloc_error`, `cap_error`, `io_error`). These built-in enums are matched like declared ones: `alloc_error::out_of_memory`, exhaustive, no `_`. A borrow bound by an outcome (the `ok(item)` of `region.new`) ends at the end of its arm. A borrow bound by `let item = region.new(arena, v) or trap;` ends at the end of the enclosing block. +- **Error construction.** Every registered built-in error variant is also a payload-free expression, e.g. `let e = alloc_error::budget_exceeded;`. It lowers to `error.const` with feature `error_values` and its dependency closure (spec 05 §14), requires no effects or capabilities and changes no resource state. Unknown variants are `E7002`, payload arguments `E7005`; errors are Copy data and cannot confer authority. - **Rebinding.** A value that comes back on an edge is rebound by the name in its arm: `closed(v)`, `pending(rx)`, `cancelled(t)`. If that name is a variable (`var`) of the value's type, the value becomes the variable's new value. A receiver kept in `var r` is closed with `match channel.close_receiver(move r) { ok => …, pending(r) => … }` and received from again. - **`or trap`.** `op(args) or trap` is the expression of the `ok` value, or of `void`. Every other outcome traps (`T0001`). It is the only shorthand. - **Enums.** A `match` over a value of an enum type has exactly one arm per variant, each written `Enum::Variant(names…)` (`Enum::Variant` without payload). It must be exhaustive (`E7004` lists the missing variants), and `_` is not allowed (`E7006`), so a new variant cannot slip through silently. Payload names are bound only inside their arm (they are the arm block's parameters in AIR). It lowers to `enum.switch`. -- **Integers.** A `match` over an integer has literal arms and exactly one `_` arm, which is required (`E7004`). It lowers to `switch`. +- **Integers.** A `match` over an integer has literal arms and exactly one `_` arm, which is required (`E7004`). Pattern values MUST fit the scrutinee type (`E7005`); different spellings of the same value are duplicate arms (`E7006`). It lowers to `switch` with canonical decimal literals, without source suffixes or separators. - **Booleans** use `if`. - **As expressions.** `match` and `if` are expressions when their arms yield values (§4). Every arm must have the type of the others, or diverge. - **Source map.** The switch maps to the `match`; each arm's code and its branch to the join map to that arm. @@ -253,7 +255,7 @@ scope s { **`scope s { … }`** is `task.scope.begin` and `task.scope.end`, at every normal exit of the block. Inside it: -- `task.spawn(s, f, args)` spawns `f` (a function of the module) into the scope `s`. Arguments are passed like call arguments: a named linear value is `move`d (`E7003`). A borrow argument is lent until the join (spec 04 §34), so it is a borrow binding passed by name (`mut part = buf;` … `task.spawn(s, f, part)`). A borrow or byte string written inline is `E7006`, because a temporary would have to end right after the spawn. The first operand must be the scope (`E7005`); +- `task.spawn(s, f, args)` spawns `f` (a local or directly imported qualified function, §14) into the scope `s`. Arguments are passed like call arguments: a named linear value is `move`d (`E7003`). A borrow argument is lent until the join (spec 04 §34), so it is a borrow binding passed by name (`mut part = buf;` … `task.spawn(s, f, part)`). A borrow or byte string written inline is `E7006`, because a temporary would have to end right after the spawn. The first operand must be the scope (`E7005`); - `task.join(move t)` joins; its value is the task's result (`task` gives `T`); - a task that is not joined at an exit is `E4301`. @@ -361,7 +363,7 @@ Passing the region itself is `E7005`; the frontend never creates a temporary reg **Container borrows are explicit, as for regions.** `.root`, `.at` and `island.alloc` take a named borrow binding of the graph's owner (`mut g = isl;`), which outlives the borrows derived from it. Passing the owner itself is `E7005`, with a hint. A container borrow written inline is `E7006`. `island.at`, `frozen.at` and `arc.at` appear only as the place of a `ref`/`mut` binding (`E7006` elsewhere). -**Linear aggregates.** A struct or enum with a linear field (`own`, `region`, a resource) needs the reserved feature `linear_aggregates`. The frontend lowers it as written and the AIR is rejected (`E0006`) until that feature is published. +**Linear aggregates.** A struct, enum or fixed array with linear members follows §16 and spec 03 §25. The frontend declares `linear_aggregates` and lowers complete explicit ownership transfers. A byte string or array used where a `slice` is expected is materialized in frame storage and borrowed for the operation. @@ -425,10 +427,13 @@ Its diagnostics keep their AIR codes, reported at the source location. | `aji lower --stats file.aji` | source and AIR size, expansion ratios and the two `mechanical_air_eliminated` metrics below | | `aji lower --annotate file.aji` | the same with `; line:col-line:col` source spans before each instruction (not canonical; for debugging) | -Lowering is deterministic: the same source and compiler give byte-identical AIR, and the lowered AIR is canonical (parse → print reproduces it). The conformance runner checks both for every accepted `.aji` test. +`check`, `lower`, `report`, `run` and `explore` also accept `--manifest PATH` for explicit package inputs (§14, spec 12 §1.3). Check/lower/report do not instantiate grants. + +Lowering is deterministic: the same source inputs and compiler give byte-identical AIR, and the lowered AIR is canonical (parse → print reproduces it). The conformance runner checks both for every accepted `.aji` test. **Size metrics** (`--stats`, non-normative tooling with a fixed definition): +- With `--manifest`, source sizes count the entry file only; AIR sizes count the combined module. These ratios MUST NOT be interpreted as whole-package compression. - Sizes count code only: non-empty lines that are not comments (`//` in source, `;` in AIR), each with its newline. - `mechanical_air_eliminated_raw` = 1 − `source_bytes` / `air_bytes`: how much of the AIR text the author did not write. This is the main engineering metric. - `mechanical_air_eliminated_normalized` = 1 − `source_bytes` / `air_bytes_normalized`: the same against AIR in which every byte-string materialization counts as one logical constant operation. Such a materialization is the instructions from the string's `local.zero` to its final `borrow.end`, a store per non-zero byte, because format 0 has no byte-array constant. It is replaced by the single notional line ` const.bytes %, `, where `` is the canonical spelling: printable ASCII as is, otherwise the escapes `\n \r \t \0 \\ \" \xNN`. The storage's `local.alloc` is real frame storage and stays. No other instruction is normalized. The rule is the same for every program, and `byte_string_constants` reports how many were replaced. @@ -466,3 +471,116 @@ Other rules: - `*c` and any other ordinary read of a cell is `E4202`. - Effects are declared by the programmer (spec 05 §13). + +## 13. Built-in standard modules + +The compiler MUST provide the standard modules listed in spec 16 §2, pinned to its own version. An import of `std` or a `std.*` path MUST resolve only against that closed registry: no file-system search, environment variable, network fetch, package manifest, or build extension participates. Unknown modules are `E7002`; duplicate imports are `E7006`. Imports MUST precede declarations; a misplaced import or missing semicolon is `E7001`. + +An imported standard function is called by its full path, for example `std.bytes.equal(ref a, ref b)`. An unknown member or a call without the corresponding import is `E7002`. Importing a module MUST NOT introduce unqualified names or aliases. Qualified standard calls MUST NOT resolve through a local binding named `std`. User functions with the same short name remain independent. Standard functions are ordinary function calls: their argument types, borrows, moves, effects and failure contracts follow the existing rules. Type arguments on these monomorphic functions are rejected (`E7006`, §15). + +Lowering MUST append the complete non-generic type and function declarations of the imported modules after the program's declarations, in lexicographic module order and source declaration order within each module. For a type or function `f` in module `m`, the AIR name starts as `__aji_` plus `m` with dots replaced by underscores, then `_f`. If that name collides with a program type/function or a previously linked standard declaration, the compiler MUST append the smallest positive decimal suffix `_1`, `_2`, … that is unused. Qualified source calls MUST use the resulting AIR name. This is name mangling, not an extension to the format-0 identifier grammar. Generic templates follow §15. The imported source is parsed and lowered as ordinary safe `.aji` and the combined AIR MUST pass the same verifier. No runtime dispatch or new AIR instruction is introduced. The feature header is the dependency closure of the combined module, including unused imported functions. + +Imports grant no authority, perform no runtime initialization and allocate no program heap memory. Merely importing a module does not add effects to the caller's contract; calling an effectful function would require its declared effects under the usual call rule. + +Canonical AIR MUST be independent of import order, working directory and execution profile for a fixed compiler and program. Source diagnostics and traps inside a standard function MUST identify its stable repository-relative source path (spec 16 §2) and its original line/column, rather than the program's path. `aji lower --annotate` MUST include that path on annotations for imported instructions. AIR locations remain available as in §10. + +Standard enum types are named by their full path, for example `std.bytes.ReadU32`. In type annotations, constructors and match patterns, that path MUST resolve only to a type from an explicitly imported standard module. An unknown module/type or missing import is `E7002`. Importing a module MUST NOT introduce short type names. Standard declarations with the same short names as user types remain distinct. + +A constructor or pattern is written `std.bytes.ReadU32::ok(value)` or `std.bytes.ReadU32::short_input`. Constructors, payload typing and exhaustive enum matches obey §5/§6 without a library-specific exception. A wrong payload or variant from another enum is `E7005`, an unknown variant `E7002`, a missing arm `E7004`, and duplicate/wildcard enum arms `E7006`. These are ordinary Copy enum values; this increment does not add a must-use or linear-result rule. Source type diagnostics MUST name standard types by their public qualified source path, including inside compound types; AIR output still uses the generated identifiers. Library source uses the same full type paths in signatures, constructors and matches. Standard types lower with the collision-free naming rule above; their declarations precede function declarations as in §2. + +The standard registry exports ordinary structs/enums and their generic templates (§15). Qualified named types and enum variants introduce no member methods, reflection, dependency resolution or aliases. Generic standard forms use §15. Package modules and qualified struct literals are specified in §14. + +## 14. Package source modules + +### 14.1 Explicit inputs and graph + +The frontend MUST take an entry source and an explicit mapping of module names to source bytes and diagnostic file paths. Its compilation MUST be a pure function of those inputs and compiler version. The CLI supplies the mapping only from an explicitly selected manifest's `[modules]` (spec 12 §1.3); a file-only invocation has no package mapping and MUST NOT discover a manifest. No parent search, directory scan, environment search path, network access, dependency fetch or build script participates. Standard imports continue to use §13's compiler-pinned registry and MUST NOT be shadowed by the package mapping. + +Each mapped source MUST declare exactly its mapped module name. An imported source need not define `main`; only the entry's unqualified `main` is the program entry. A module's own function named `main` is an ordinary qualified function. All top-level declarations and fields are available through explicit import; no visibility modifier or re-export is introduced. Modules have no executable top-level initialization. + +Imports form an acyclic directed graph. The linker MUST parse each reachable module once, reject self-import/cycles, duplicate imports, duplicate mappings and mismatched headers with `E7006`, and unknown imports with `E7002`. Source syntax errors in a package module use `E7001` at that module's file/line/column. Imports are visited in source order for first-error selection; all complete non-generic declarations of reachable modules, including unused functions, enter verification; templates follow §15. Unreachable mapped source is not parsed or linked. Compiler input limits are 1,024 mapped modules and import depth 256; exceeding them is `E7006`. These are fixed implementation input limits, not runtime fuel or semantics-changing flags. + +Module names use source paths. The first component of a package mapping MUST NOT be `std` or a namespace of a built-in operation (`slice`, `own`, `buffer`, `region`, `cap`, `task`, `channel`, `mutex`, `island`, `frozen`, `arc`, `atomic`, or the first component of a registered intrinsic). Such a mapping is `E7006` (a manifest error at the CLI). Root source names retain their existing grammar; duplicate entry/module identity is rejected when imported. + +### 14.2 Names and types + +A module sees its own functions and types by short name, and declarations of directly imported modules by full path. Imports MUST NOT inject short names, aliases or transitive visibility. An entry outside reserved built-in namespaces can also qualify its own declarations with its module name; built-in operations retain precedence. An inaccessible or unknown function/type/member is `E7002`, even if a different module linked the declaration. Qualified names resolve by module identity, independently of local bindings with the same prefix. A value may have a type inferred from a directly imported function contract without importing that type's defining module; spelling the type or its constructors by name still requires a direct import. Module-local calls MUST NOT capture an entry's similarly named function; named types from different modules are nominally distinct. + +Type annotations and wrappers use qualified types, for example `app.model.Pair`, `ref` and `[app.model.Pair; 2]`. Enum construction/patterns use `app.model.Result::ok(value)`. Qualified struct construction is `app.model.Pair { a: 1, b: 2 }`, with existing field typing/completeness and ownership rules. The final component must begin with an uppercase ASCII letter, as for current short-name struct literals. Struct literals remain forbidden in unparenthesized conditions, where `{` starts a block. This adds no methods, reflection or permission to store forbidden borrowed values in aggregates; linear members follow §16. Generic forms are specified separately in §15. + +A qualified named function MAY be passed as the function operand of `task.spawn(scope, app.work.run, ...)`. Existing Send/effect/structured-lifetime rules still apply; there is no function value, dynamic dispatch or detached task. All other calls use the existing argument, borrow, move, failure and effect rules. + +### 14.3 AIR, safety and compatibility + +Entry declarations retain their existing AIR names. Imported declarations use §13's collision-free mangling, with all reachable standard/package modules appended in lexicographic module order and source order within each module. Type declarations still precede functions. Valid canonical AIR MUST be independent of import order, mapping order, directory/profile and source file paths for identical source bytes and module bindings. Whole-graph AIR feature closure is explicit as before. Source provenance MUST use each imported source's supplied file path; the CLI supplies its manifest-relative path. AST module identity is distinct from a diagnostic path, so coinciding file labels cannot change name resolution. + +The combined AIR MUST pass the ordinary verifier and runs as a single format-0 module. There is no new opcode, AIR feature, verifier state, runtime primitive, initialization, implicit heap allocation or authority. Existing enum/struct layout, alias, initialization, borrow, ownership, resource, task and effect transfer functions apply across module calls unchanged. All return/cleanup paths remain explicit; imported code is not trusted by virtue of its module. Existing file-only and standard-only programs retain their lowering and behavior. Package imports require the new explicit mapping; previous unknown import paths become valid only when supplied. + +## 15. Explicit source generics + +### 15.1 Declarations and applications + +Functions, structs and enums MAY declare 1–8 type parameters immediately after their name, e.g. `fn identity(value: T) -> T effects [] { return value; }`, `struct Pair { left: T, right: T }`, `enum Option { some(T), none }`. Parameters MUST be distinct uppercase identifiers, MUST NOT shadow a visible type/builtin type, and have no default. Constraints are optional compiler-known `Copy`, `Send`, `Share`, `Freeze` or `Local`, joined by `+`; repeated/unknown constraints are `E7006`. Generic `main` is forbidden (`E7006`). No user traits, overloads, type inference, const/lifetime/effect parameters or specialization overrides are introduced. + +Every generic use MUST supply exactly its ordered arguments (type arguments here; static function arguments in §18). Type annotations use `Pair`; expression applications use `identity::(42)`, `Pair:: { left: 20, right: 22 }` and `Option::::some(42)`. Enum patterns use `Option::::some(value)` and `Option::::none`. The `::<...>` spelling separates generic application from comparisons; bare `f(...)` is outside the expression grammar. Qualified forms obey §14's direct-import rules. `task.spawn(s, worker::, ...)` statically specializes the worker; this creates no function value. Existing `channel.make(...)` retains its spelling and single type argument. + +Type parameters are substituted in types, casts, declarations, explicit applications and enum/struct constructors/patterns, including nested templates. A parameter used as a constructor requires its own explicit concrete type arguments if that concrete type is generic; type parameters are types, not values or operations; static function parameters are separately defined in §18. Type arguments MUST be concrete source types after substitution, excluding `void` and `never`. Ordinary type-position, layout, ownership and capability restrictions still apply to every emitted specialization; generics MUST NOT bypass the member restrictions; linear members require §16, and borrowed aggregate members remain forbidden. + +Templates are parsed and declaration parameter/constraint/duplicate rules, signature type names/arity, effects and the prohibition of trusted clauses are checked even if unused. Generic bodies are type/ownership/effect checked for each required concrete specialization, not abstractly proved for all possible arguments. An unused template body has no emitted code and no runtime effects; successful checking does not claim it is valid for every future instantiation. All non-generic declarations in reachable modules continue to be verified even if unused. A missing generic type argument or wrong arity is `E7006`; unknown/inaccessible templates/types use `E7002`; an unsatisfied constraint is `E7005` at the application, with `parameter`, `constraint` and `found` metadata. Body failures point at template source. + +### 15.2 Structural constraints + +Constraints are requirements on concrete types, not compiler authority to infer effects or repair ownership. `Copy` follows existing value duplication: scalars, built-in enums, capabilities, `iref` and aggregates of Copy values; borrows and linear values are not Copy. `Send` and `Share` use exactly spec 04 §35. In format 0, `Freeze` is exactly `IslandSafe` (spec 03 §22): plain content accepted by deep graph conversion, including `iref`; it does not promise conversion of owners/resources/wrappers. `Local` identifies context-bound `task`, `scope`, `shield` and `guard` (and internal local storage); it propagates through borrows, own/own_array/buffer/mutex wrappers and arrays/aggregates containing Local content. Scalars, authority, resources, regions, endpoints and graph owners/handles are not Local. Local is not the complement of Send. No unsafe/manual property declarations are added. + +A type can satisfy several constraints; each requirement MUST be checked. Constraints add no operations or trait dispatch: a body using arithmetic with `T: Copy` still requires an arithmetic-compatible concrete specialization. Effects, `from`, `move`, lends and cleanup remain explicit in every specialization. + +### 15.3 Deterministic monomorphization and safety + +A specialization is keyed by template module identity, declaration kind/name and the ordered structural identity of concrete arguments. Named arguments use nominal defining-module identity, independent of source filename, short/qualified spelling or import/provider order. Each key MUST emit at most one concrete declaration; repeated same-key recursion reuses it. Type-specialization cycles still obey ordinary finite-layout rules. Expanding specialization is bounded by 4,096 generated declarations and active expansion depth 64 (`E7006`), with structural type traversal bounded at depth 64. These are fixed compiler input limits, not runtime fuel or semantic flags. + +Non-generic declarations retain their AIR names and order. Generated types and functions append in lexicographic specialization-key order within their categories. Their AIR identifier starts with `__aji_g_` followed by lowercase SHA-256 of the canonical key bytes; collisions with original names or earlier keys in sorted order receive the smallest unused `_1`, `_2`, … suffix. The canonical key is `type:` or `fn:`, full defining-module/declaration path, and ordered `<...>` arguments. Named arguments use full nominal paths, applied arguments recursively spell their template/arguments, arrays spell `[T;N]` with decimal N, wrappers/cap/file spell `name`; argument separators are commas without whitespace. Full keys, not hashes, determine identity and reuse. Keys are limited to 16,384 bytes (`E7006`). Every required body lowers to existing format-0 constructs, and the combined module MUST pass the ordinary verifier. There is no new AIR instruction/feature, verifier transfer state, runtime dispatch, implicit allocation/refcount/destructor, effect inference or authority. Source provenance retains template locations and the locations of supplied argument types. Generic borrow/owner/task contracts use the existing runtime/interpreter rules unchanged. Existing monomorphic source and AIR retain meaning and canonical lowering. The finite-layout verifier now visits array elements as well as direct nominal members, closing a prior E1003 implementation gap without changing the normative no-recursive-value rule. Existing unimplemented source `from`-returns remain unimplemented; specialization retains their contract rather than inventing borrow lifetimes. + +## 16. Source linear aggregates + +Structs, enums and fixed arrays with linear members MUST obey spec 03 §25. Constructors consume linear inputs with explicit `move`; whole aggregate calls/returns/bindings also require `move` on named values. No partial field move is allowed. Copy fields may be read without consumption. `let (a, b, …) = struct.unpack(move value);` and `let (a, b, …) = array.unpack(move value);` bind all fields/elements in order, including a one-element parenthesized binding. `_` is allowed only for Copy components; a linear ignored component MUST reject E3002 through the ordinary verifier. Array literals `[e0, e1, …]` use complete ordered inputs; repeated `[e;N]` remains Copy-only. Existing argument/block limits bound unpacking. + +`match move value { Enum::Variant(payload) => … }` exhaustively consumes a linear enum and lowers to enum.take. Ordinary Copy matches keep enum.switch. An arm MUST consume or transfer each linear payload, including those named `_`; there is no automatic destructor. Unused payload-free variants still consume the linear enum. + +`value.swap(mut place, move replacement)` returns the previous complete value and stores the replacement; it lowers to value.swap with the existing borrow scope. The same spelling accepts Copy replacements without move. The caller MUST explicitly consume a returned linear value. `match own.pack(move value, heap) { ok(owner) => …, err(error, value) => … }` makes allocation authority/failure explicit and preserves ownership on both outcomes; `or trap` retains ordinary abnormal-path semantics. own.new/own.array/region storage and local storage remain Copy-only; own.take extracts whole linear content and own.free cannot destroy it. + +The frontend MUST declare linear_aggregates plus its dependencies whenever any emitted aggregate has linear members or any of the new operations is emitted. Existing Source/AIR diagnostics and deterministic behavior apply. This phase does not implement partial moves, borrowed aggregates, dynamic linear buffers or source from-returns. + + +## 17. Source dynamic buffers + +`buffer` is the linear initialized-prefix owner of spec 03 §26. Built-ins use ordinary explicit borrows, moves and outcome matches: `buffer.new(capacity, heap)`, `buffer.len(b)`, `buffer.capacity(b)`, `buffer.reserve(b, capacity, heap)`, `buffer.push(b, move value)`, `buffer.pop(b)` and `buffer.free(move owner)`. Except new/free, b MUST be a named ref/mut> binding, borrowed first from an owner or aggregate field. Mutating operations require mut. len/capacity accept ref or mut. new/reserve declare mem.alloc explicitly. push requires no heap capability and never grows implicitly. + +Outcomes: new has ok(buffer)/err(alloc_error); reserve has ok()/err(alloc_error); push has ok()/err(original_value); pop has ok(value)/err(); free has ok()/err(original_buffer). Ordinary exhaustive outcome matching/or trap applies. A returned linear value MUST be explicitly consumed. `ref values = buffer.view(b);` binds a shared slice from ref or mut b; `mut values = buffer.view(b);` requires mut b and binds an exclusive slice. The child borrow lasts for its explicit lexical scope and never escapes through an aggregate. This is a primitive borrow binding like graph access, not a general function returning a borrow (Q-034 remains open). Existing indexing/value.swap provides Copy reading and complete linear element exchange. Views expose only the initialized prefix; mutation/growth/free while a view or task loan is live MUST reject even on a dynamically full/empty/no-op branch. + +A specialized generic body MAY use `move name` to express complete value transfer for a type parameter. If its concrete binding is Copy, lowering passes the existing Copy value and it remains available; if linear, ordinary transfer/availability applies. This rule applies to complete Copy bindings inside a specialized generic body, not borrows or internal storage/scope/guard/shield handles. A Copy value bound in frame storage remains a Copy value and is loaded normally when transferred. Outside a specialized generic body, move of a Copy value remains E7006. No AIR ownership rule changes and no implicit destructor/allocation is added. This makes one generic container body correct for both Copy and linear contents; ordinary borrow/effect/type constraints still apply to every specialization. + +The frontend MUST emit linear_buffers and its full dependencies for buffer types/operations. Existing syntax suffices apart from admitting the buffer wrapper and the typed built-in allocator with the existing channel.make type-argument form. General methods, borrowed aggregate storage, recursive ownership and from-return calls are not added. + +## 18. Static function parameters + +Generic structs, enums and functions MAY declare a static function parameter alongside type parameters: `F: fn(ref) -> u64 effects []`. This is a compile-time contract, not a value type. Its ordered parameter types, return type and complete flat effect set MUST be explicit. Static function parameter names MUST be uppercase, distinct, and MUST NOT shadow a visible type or function. All types are checked/substituted like ordinary function signatures; all effect atoms MUST be registered and unique. Borrow returns and `from` contracts are outside this increment (Q-034). A callable parameter MUST NOT carry structural property constraints or be used as a type. The existing maximum of eight generic parameters counts both kinds. + +An explicit argument is `fn path`, or `fn path::` for a generic function. The path MUST resolve to a directly accessible declared source function. Built-in operation names, runtime values and captures are not function arguments. `fn F` forwards an already bound static parameter; it cannot be specialized again. A type argument in a function position or a function argument in a type position is `E7005`. Wrong generic arity remains `E7006`; unknown/inaccessible functions remain `E7002`. Signature/effect mismatch diagnostics include `parameter`, `function`, `expected` and `found` contracts. + +After substitution, the selected function MUST have exactly the declared ordered parameter/return types and effect set (`E7005`). Effect order is irrelevant; widening/narrowing of effects or borrow types is not implicit. Exact effect contracts avoid effect shims and ensure that specialization cannot infer effects away from a public contract. Capabilities are ordinary explicit arguments; selecting a function grants no authority. A borrowed input retains ordinary read/exclusive access rules, and linear arguments retain explicit moves and consumption obligations. + +The bound name MAY occur only as a direct call target or named `task.spawn` worker; normal arguments and explicit moves/borrows still apply. It MUST NOT escape into storage, aggregates, returns or runtime expressions (`E7006`). It MUST NOT be shadowed by a runtime binding in a specialized body or its signature (`E7006`). Static parameters have no runtime representation, capture environment, destructor, heap allocation or indirect dispatch. They are not inferred. Templates remain subject to the header/body distinction of §15. + +Function identity, including explicit specialization arguments and defining module, MUST participate in the instance identity of both functions and types. In canonical keys a static argument spells `fn ` followed by the full defining-module/function path, including canonical `<...>` arguments when specialized. Thus two container types with different bound hash/equality functions are nominally distinct, even when their storage layouts agree. Linking retains direct-import restrictions and caller-site provenance for explicit arguments. Limits remain depth 64, 4,096 specializations and 16,384-byte instance keys, including argument/contract resolution; unresolved cyclic contracts MUST reject with `E7006`, never recurse without a bound. + +Lowering MUST replace each bound call/worker with an ordinary named AIR function operand. No new AIR instruction, type, effect, capability, feature or verifier state is added: ordinary `call`, task checking, effects, borrows and ownership validate every resulting specialization. Existing AIR format-0 semantics and type-only source generics are unchanged. AIR equivalence and source rejection tests MUST cover static selection, nominal policy identity, authority, ownership, effects, imports and workers. + +```aji +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { + return F(move value); +} +// In main: apply::(42u64) +``` + +General collections MAY use these explicit contracts for hash/equality/order operations. Their algebraic laws remain library preconditions; no compiler magic infers hashing or equality. This facility alone does not complete HashMap/HashSet or resolve their storage/API invariants. diff --git a/docs/spec/16-standard-library.md b/docs/spec/16-standard-library.md new file mode 100644 index 0000000..9048cfe --- /dev/null +++ b/docs/spec/16-standard-library.md @@ -0,0 +1,399 @@ +# 16. Standard Library + +## 1. Contract + +The standard library SHOULD make CLI programs, storage components, network services and structured concurrent programs possible without external source dependencies. Scope and sequencing are tracked in `docs/plan/standard-library.md`; that roadmap does not imply that unimplemented APIs are available. + +Standard APIs MUST expose allocation, authority, effects, ownership transfer and recoverable failure in their public contracts. Safe library source MUST pass the ordinary verifier. Unsafe or foreign implementations MUST use an explicit audited trusted boundary under spec 13; they MUST NOT masquerade as verified source. The library MUST NOT obtain ambient host authority. + +APIs SHOULD offer one canonical operation for a common need, small documentation requirements, bounded memory behavior and stable repair guidance (spec 14 §8). Resource cleanup remains explicit. Pure byte/path transformations do not grant authority over files or sockets. + +## 2. Bootstrap module registry + +The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.hash`, `std.hashmap`, `std.hashset`, `std.heap`, `std.io`, `std.io.reader`, `std.io.writer`, `std.map`, `std.math`, `std.option`, `std.path`, `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/hashmap.aji`, `std/hashset.aji`, `std/heap.aji`, `std/io.aji`, `std/io/reader.aji`, `std/io/writer.aji`, `std/map.aji`, `std/math.aji`, `std/option.aji`, `std/path.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`. Modules other than std.io/std.io.reader/std.io.writer implement deterministic algorithms in every profile and have no concurrency effects; std.io/std.io.reader/std.io.writer follow the profile I/O/blocking rules in §2.17–§2.18 and spec 11. Modules other than std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap and std.io/std.io.reader/std.io.writer declare effects [] and allocate no heap memory. std.io declares only the concrete I/O effects in §2.17 and allocates no heap storage. std.io.reader/std.io.writer declare mem.alloc only on new and the concrete file effects in §2.18 on read/write/flush/finish; their other operations allocate no heap. std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11, §2.13–§2.16); their other functions allocate no heap. Ordinary interpreter fuel limits apply. + +### 2.1 `std.math` + +- `min_u64(a: u64, b: u64) -> u64` returns the smaller operand. +- `max_u64(a: u64, b: u64) -> u64` returns the larger operand. +- `clamp_u64(value: u64, lower: u64, upper: u64) -> u64` returns `lower` below the range, `upper` above it, or `value` inside it. The inclusive range MUST satisfy `lower <= upper`; violation traps `T0002` before returning a value. + +These are monomorphic functions, not a generic arithmetic facility. Checked/wrapping operators retain their existing semantics (spec 02); importing this module does not alter them. + +#### 2.1.1 Recoverable unsigned arithmetic + +For `T` equal to `u64` or `usize`, `checked_add_T(a: T, b: T)`, `checked_sub_T(a: T, b: T)` and `checked_mul_T(a: T, b: T)` return `std.math.U64Result` or `std.math.UsizeResult`, respectively: + +```aji +enum U64Result { ok(u64), overflow } +enum UsizeResult { ok(usize), overflow } +``` + +Each operation MUST return `ok(value)` exactly when its mathematical result is representable in T, and `overflow` otherwise. Unsigned subtraction underflow is `overflow`. A successful zero is distinct from overflow. `usize` uses the target pointer width (spec 02); no fixed-width maximum or implicit cast is allowed. These functions MUST NOT trap for any scalar operands, apart from the execution environment's fuel limit, including multiplication by zero. They allocate no heap and declare `effects []`. + +The functions use ordinary Copy enums and the existing integer and enum rules, with no new verifier/runtime primitive. Failure is handled by an exhaustive qualified enum match; no must-use rule or intrinsic outcome shorthand is added. Normal `+`, `-`, `*` still trap on overflow; wrapping uses `+%`, `-%`, `*%`. The library MUST NOT add synonymous wrapping wrappers for these operators. Signed arithmetic and other widths are outside this monomorphic increment; general numeric APIs require separate contracts. + +### 2.2 `std.bytes` + +Inputs are byte slices, not encoded text. No UTF-8 validation or locale interpretation occurs. Read-only parameters are `slice`. + +- `equal(a, b) -> bool`: true exactly when lengths and all bytes agree. +- `compare(a, b) -> i8`: unsigned-byte lexicographic comparison; returns exactly `-1`, `0` or `1`. The shorter of two matching prefixes sorts first. +- `find(data, byte: u8) -> usize`: index of the first occurrence; `data.len` when absent. A found index is valid only for the searched slice and exactly when the result is less than its length. Indexing retains the ordinary bounds-check rules (`T0008` for an absent result used as an index). +- `starts_with(data, prefix) -> bool`, `ends_with(data, suffix) -> bool`: true for matching prefixes/suffixes, including empty ones; false when the candidate is longer than `data`. +- `fill(dst: slice_mut, byte: u8) -> void`: writes every byte of `dst`, including zero writes for an empty slice. + +The library MUST NOT read or write outside a passed slice and MUST NOT retain or return any borrow. The verifier enforces existing shared/exclusive borrowing, lifetime and bounds rules; there is no library privilege or new transfer function. Read-only functions only read their slices; `fill` writes only its exclusive slice. None consumes an owner or resource. These operations MUST NOT trap for valid byte slices and scalar operands, apart from the execution environment's fuel limit. + +### 2.3 Endian reads and writes in `std.bytes` + +The library provides `read_u16_le`, `read_u16_be`, `read_u32_le`, `read_u32_be`, `read_u64_le`, `read_u64_be`, and the corresponding `write_` functions. Width/order are part of the function name; no native-endian default exists. `le` is least-significant byte first; `be` is most-significant byte first. These functions operate on the beginning of the passed slice. To use an offset, pass an explicit sub-slice. There is no cursor state or alignment requirement. + +Public result enums: + +```aji +enum ReadU16 { ok(u16), short_input } +enum ReadU32 { ok(u32), short_input } +enum ReadU64 { ok(u64), short_input } +enum WriteResult { ok, short_output } +``` + +These declarations belong to `std.bytes` and are named with that prefix (spec 15 §13). For width `W` and byte count `N = W / 8`: + +- `read_uW_ORDER(src: slice) -> std.bytes.ReadUW` MUST return `short_input` when `src.len < N`, without reading elements. Otherwise it MUST return `ok(value)` decoded from exactly the first N bytes. Extra bytes MUST NOT affect the result. `value = Σ src[i] × 2^(8i)` for LE and `Σ src[i] × 2^(8(N-1-i))` for BE, for `0 <= i < N`. +- `write_uW_ORDER(dst: slice_mut, value: uW) -> std.bytes.WriteResult` MUST return `short_output` when `dst.len < N` and leave every destination byte unchanged. Otherwise it MUST write exactly the first N bytes in the selected order, leave the remaining bytes unchanged and return `ok`. + +Short slices are recoverable enum results, not traps. A successful zero value is distinct from a short input. These APIs declare `effects []`, allocate no heap, retain no borrow and consume no owner/resource. They have no concurrency or authority requirements beyond the ordinary slice borrow contract. All capacity checks precede all accesses/mutations. Valid slices and values MUST NOT produce bounds, arithmetic, cast or shift traps; interpreter fuel exhaustion remains an environment outcome. + +The verifier uses the existing enum payload, call, shared/exclusive borrow, lifetime and bounds rules. There is no new transfer function, runtime primitive or AIR feature. Ordinary enum construction and exhaustive `enum.switch` lower the result handling. Existing `E7002`, `E7004`, `E7005`, `E7006`, `E2101` cover invalid names/matches/calls and aliasing. The behavior is identical in deterministic and hosted profiles. Existing AIR and the existing nine library operations retain their semantics; imported source receives additional declarations pinned to the compiler version. + +### 2.4 Bounded copy, substring search and splitting + +`std.bytes.copy(dst: slice_mut, src: slice) -> std.bytes.WriteResult` MUST return `short_output` when `dst.len < src.len`, leaving every destination byte unchanged and reading no source elements. Otherwise it MUST copy exactly `src.len` bytes into the beginning of `dst`, preserve remaining destination bytes and return `ok`. Empty input succeeds, including with an empty output. Capacity is checked before any copy. Source/destination overlap MUST be rejected by the existing shared/exclusive alias rules (`E2101`), even if the output is short or the slices are empty. This operation is not an overlap-safe move. + +`std.bytes.find_slice(data: slice, needle: slice) -> std.bytes.FindResult` returns an ordinary Copy enum: + +```aji +enum FindResult { found(usize), not_found } +``` + +It MUST return `found(index)` for the least index at which all needle bytes match, or `not_found` if there is no match. A found index satisfies `index <= data.len` and `needle.len <= data.len - index`. An empty needle MUST return `found(0)` for any data, including empty data, without reading elements. A needle longer than the data MUST return `not_found` without reading elements. Offsets are relative to the passed slice; a found index is an offset, not necessarily an index of a readable element. Search only reads shared slices, retains no borrow and never mutates its input. The reference implementation uses constant auxiliary storage and at most O(data.len × needle.len) byte comparisons; interpreter fuel still bounds execution. + +Splitting at the first byte-string separator uses `find_slice`, then the existing explicit sub-slice or `split_at` forms (spec 15 §6). On `found(index)`, the left part is `data[0..index]`, the separator `data[index..index + separator.len]` and the right part `data[index + separator.len..data.len]`. On `not_found` the caller chooses how to handle an absent separator. An empty separator yields an empty left part and the whole data as the right part; repeated splitting with an empty separator needs a caller-defined progress rule. There is no standard split iterator, returned aggregate of borrows or hidden cursor. Single-byte splitting MAY use the existing `find` length sentinel, checked before slicing. + +Both functions declare `effects []`, allocate no heap, retain no borrow and consume no owner/resource. Valid slices MUST NOT produce bounds or integer traps; fuel exhaustion remains an environment outcome. The invariant is existing shared-read/exclusive-write access within the supplied slices, with no partial mutation on a short-output result. Existing call, alias, lifetime, initialization, capacity/bounds and enum transfer functions apply, with no new privilege, diagnostic code, AIR feature or runtime rule. Deterministic and hosted profiles behave identically. Existing APIs and AIR format 0 retain their contracts. + +### 2.5 UTF-8 + +`std.utf8` interprets UTF-8 as the shortest encoding of Unicode scalar values 0..0x10FFFF excluding 0xD800..0xDFFF, following RFC 3629 §3/§4. Unassigned scalar values, noncharacters, NUL and U+FEFF are valid. No normalization, replacement decoding, locale handling or BOM removal occurs. + +```aji +enum NextResult { ok(u32, usize), end, invalid_input } +enum ValidateResult { ok, invalid_input(usize) } +``` + +- `next(src: slice) -> std.utf8.NextResult` MUST return `end` exactly when src is empty. Otherwise it MUST decode only the first scalar: `ok(value, byte_count)` with 1..4 consumed bytes, or `invalid_input` if the first sequence is malformed or truncated. Trailing bytes after a successful first sequence MUST NOT affect that result. Iteration uses an explicit caller offset and a sub-slice, without retained cursor state or borrows. +- `validate(src: slice) -> std.utf8.ValidateResult` MUST return `ok` for a wholly valid sequence, including empty input. Otherwise it MUST return `invalid_input(offset)` at the beginning of the first malformed or truncated sequence, relative to src, after the maximal valid prefix. The offset identifies the sequence's leading byte, not necessarily the bad continuation byte. + +ASCII bytes 00..7F are single-byte scalars. Multi-byte leading bytes are C2..DF, E0..EF and F0..F4 with two, three or four total bytes, respectively. Continuations MUST be 80..BF; the second byte MUST be A0..BF after E0, 80..9F after ED, 90..BF after F0 and 80..8F after F4. These conditions reject overlong forms, surrogates and out-of-range scalars. Invalid input is a result, never replacement text or a trap. Validation and explicit iteration use O(src.len) work and constant auxiliary storage. + +### 2.6 Supplied-buffer encodings + +Both `std.encoding.hex` and `std.encoding.base64` export these ordinary Copy enums, distinct between modules: + +```aji +enum EncodeResult { ok(usize), short_output } +enum DecodeResult { ok(usize), invalid_input, short_output } +``` + +Each module provides `encode(dst: slice_mut, src: slice) -> EncodeResult` and `decode(dst: slice_mut, src: slice) -> DecodeResult`, with fully qualified result types. `ok(count)` MUST report the number of output bytes. Successful operations MUST write exactly the output prefix and leave remaining destination bytes unchanged; no terminator is appended. Empty input MUST succeed with `ok(0)` for any capacity, including zero. + +Encoding MUST check full output capacity before writing. If the mathematical encoded length exceeds either usize or output capacity, it MUST return `short_output`, leaving the entire destination unchanged; guards MUST avoid intermediate overflow. Decoding MUST validate the entire input before any destination write. Malformed input MUST return `invalid_input`, even with insufficient output capacity. Valid input with insufficient capacity MUST return `short_output`. Both error results MUST leave the entire destination unchanged. Ordinary shared/exclusive alias rules (`E2101`) apply even on failure paths; overlapping input/output is not allowed. Guarantees about unchanged output apply to returned errors, not interpreter fuel exhaustion mid-operation. + +#### 2.6.1 Hex + +`std.encoding.hex.encode` MUST produce two lowercase ASCII hexadecimal digits per byte, most-significant nibble first, with mathematical length 2 × src.len. `decode` MUST accept exactly even-length sequences of ASCII digits 0..9, a..f or A..F, interpreting each pair as one byte. Mixed case is accepted. Odd lengths, separators, prefixes, whitespace and other bytes are `invalid_input`. There is no padding. + +#### 2.6.2 Base64 + +`std.encoding.base64` uses RFC 4648 §4's standard alphabet `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`, with `=` padding, no line breaks and zero unused bits. Encoded length is 4 × ceil(src.len / 3). Implementations MUST check that this length fits without overflowing an intermediate such as an unconditional `src.len + 2`. + +Decoding MUST accept only canonical standard Base64: input length divisible by four; alphabet symbols in every unpadded position; zero, one or two padding symbols only at the end; and zero unused low bits (four low bits in the second symbol for `==`, two low bits in the third for `=`). Padding is required for incomplete final groups, and omitted for complete groups. Whitespace, URL-safe `-`/`_`, extra/misplaced padding, incomplete groups and nonzero unused bits are `invalid_input`. Empty input is canonical. Invalid-input precedence and unchanged-output guarantees are those of §2.6. + +### 2.7 Text/encoding safety and compatibility + +Sections 2.5/2.6 use safe source, ordinary calls, integer operations, slices, local fixed-size tables and enums. They declare `effects []`, allocate no heap, retain no borrow and consume no owner/resource. Work is O(input length) with constant auxiliary storage. The preserved invariant is shared-read/exclusive-write access within supplied initialized slices, no escaping borrow and no mutation on returned encoding errors. Existing verifier call/alias/lifetime/bounds/initialization/enum rules and deterministic interpreter behavior apply without a privilege, new transfer function, diagnostic, AIR feature or runtime primitive. Valid slices MUST NOT produce bounds, arithmetic, cast or shift traps; malformed bytes and capacity failure are results. Deterministic and hosted profiles behave identically. Existing APIs, source syntax and AIR format 0 retain their contracts. + +### 2.8 Supplied-buffer integer formatting + +`std.fmt` provides `write_u64`, `write_i64`, `write_usize` and `write_isize`. Each takes `(dst: slice_mut, value: T)` with the named integer type T, and returns `std.fmt.WriteResult`, an ordinary Copy enum: + +```aji +enum WriteResult { ok(usize), short_output } +``` + +The functions MUST produce the exact ASCII decimal representation of value: `0` for zero, no leading zeroes otherwise, and a leading `-` exactly for negative signed values. No plus sign, whitespace, padding, locale transformation or terminator is written. `usize`/`isize` use the target pointer width (spec 09 §9); all values, including signed minima and unsigned maxima, MUST be supported. + +When dst can hold the complete representation, the function MUST write exactly that prefix, preserve every remaining byte and return `ok(count)` with its length, including any sign. Otherwise it MUST return `short_output` and leave the entire destination unchanged. Empty output always fails, including for zero. Capacity MUST be checked before any write. To append, the caller passes a sub-slice at an explicit offset and advances it only after success; no implicit cursor, returned borrow, growable string or format-string language is introduced. Text copying uses `std.bytes.copy`; byte-to-hex encoding remains `std.encoding.hex`. + +The preserved invariant is exclusive writes only within the supplied initialized slice, no escaping borrow, and no partial mutation on returned failure. Functions declare `effects []`, allocate no heap, use constant scalar auxiliary storage and O(decimal digit count) work. Existing call, initialization, alias, lifetime, bounds and enum verifier rules apply; conflicting live borrows MUST reject even on short output. No new verifier state, runtime rule, diagnostic, AIR feature or authority is added. Valid slices and every scalar value MUST NOT produce arithmetic, cast or bounds traps; interpreter fuel exhaustion remains an environment outcome and is outside the returned-error preservation guarantee. Behavior is identical in deterministic and hosted profiles. Existing APIs, source syntax and AIR format 0 retain their contracts. + +### 2.9 Option and result + +The compiler registry MUST also include `std.option` and `std.result`. They declare ordinary generic enums: + +```aji +enum Option { some(T), none } +enum Result { ok(T), err(E) } +``` + +`std.option.is_some(value: Option) -> bool` and `std.result.is_ok(value: Result) -> bool` declare `effects []`, allocate no heap and classify the active variant. They neither extract nor implicitly consume any payload. Call them using spec 15 §15's explicit expression arguments, e.g. `std.option.is_some::(value)`. Types/constructors/patterns are fully qualified and require a direct import; exhaustive matches extract payloads through ordinary enum rules. `none` still requires a type argument. `err(E)` is an ordinary enum variant, not the intrinsic outcome shorthand. + +Option/Result accept ordinary complete value payloads, including owners/resources/endpoints under linear_aggregates (spec 03 §25, source §16). Their class is structural: an owning specialization is linear even when the active variant is none or a Copy error. It MUST be explicitly moved and exhaustively consumed; unused linear payloads reject E3002. Borrow/storage/function-bound payloads remain forbidden by ordinary member/type rules. is_some/is_ok retain Copy constraints and MUST reject E7005 for linear arguments; they do not consume a resource merely to classify it. Match an owning value explicitly instead. Existing Copy specializations retain behavior. No implicit unwrap/default/conversion or cleanup is added. + + +### 2.10 Explicit owning vectors + +Compiler-pinned `std.vec` MUST provide `Vec { storage: buffer }` and ordinary result enums: NewResult { ok(Vec), err(alloc_error) }, PushResult { ok, full(T) }, ReserveResult { ok, err(alloc_error) }, FreeResult { ok, not_empty(Vec) }, ReplaceResult { ok(T), out_of_bounds(T) }. All payloads follow ordinary complete-value/linearity rules; no implicit destruction occurs. Fields are ordinary visible source fields, not an opaque trusted container. + +Public functions use explicit `::` specialization: new(capacity:usize,heap:cap)→NewResult; len(value:ref>)→usize; capacity(value:ref>)→usize; reserve(value:mut>,capacity:usize,heap:cap)→ReserveResult; push(value:mut>,item:T)→PushResult; pop(value:mut>)→std.option.Option; free(value:Vec)→FreeResult; get(value:ref>,index:usize)→std.option.Option; replace(value:mut>,index:usize,item:T)→ReplaceResult. Only new/reserve declare effects [mem.alloc]; all other functions declare effects []. + +These are safe `.aji` wrappers over spec 03 §26. new chooses exact initial capacity, reserve chooses a minimum capacity without shrinking, and push never grows implicitly. len/capacity observe initialized length/backing capacity. pop removes the last complete value, returning none for empty. A full push returns the original item. get copies an in-bounds Copy item or returns none. replace exchanges an in-bounds initialized element and returns the previous item; out_of_bounds returns the original supplied item and preserves the vector. free releases only an empty vector; otherwise it returns the same vector. Returned owning result specializations need exhaustive match move; Copy results use ordinary matching. Callers drain and explicitly consume resource payloads before freeing. + +Capacity/allocation failure, alias/task exclusion, deterministic profiles and diagnostics are those of buffer primitives and ordinary enum/call rules. Valid complete values include owners/files/endpoints; no collection bypasses Send/Share or channel_transfer gates. Imports grant no authority. HashMap/HashSet/BinaryHeap, owning strings and general borrowed function returns remain separate increments of STD-6. + +### 2.11 Explicit owning deques + +The compiler-pinned registry MUST include safe `std.deque` (`std/deque.aji`). Its ordinary type is `Deque { storage: buffer>, head: usize, length: usize }`, always linear. It exports `NewResult { ok(Deque), err(alloc_error) }`, `PushResult { ok, full(T) }`, `ReserveResult { ok, err(alloc_error) }`, `FreeResult { ok, not_empty(Deque) }` and `ReplaceResult { ok(T), out_of_bounds(T) }`. + +For a valid deque of capacity C, the backing buffer MUST have C initialized Option slots. For C=0, head=length=0; otherwise head` specialization: + +| Function | Parameters | Result / contract | +|---|---|---| +| new | capacity: usize, heap: cap | NewResult; exact capacity, empty queue | +| len / capacity | value: ref> | usize; logical length / capacity | +| reserve | value: mut>, capacity: usize, heap: cap | ReserveResult; no shrink; successful growth preserves logical order and sets head=0 | +| push_front / push_back | value: mut>, item: T | PushResult; insert at selected end, or full(original_item) with entire deque unchanged | +| pop_front / pop_back | value: mut> | std.option.Option; remove/move selected end, or none with empty deque unchanged | +| free | value: Deque | FreeResult; empty frees all backing storage; nonempty returns same deque unchanged | +| get | value: ref>, index: usize | std.option.Option; copy logical element, or none out of bounds | +| replace | value: mut>, index: usize, item: T | ReplaceResult; return old logical element after complete exchange, or out_of_bounds(original_item) without mutation | + +Only new/reserve declare effects [mem.alloc] and require cap. Each slot charges accounted_size(Option) (the enum tag plus its largest payload), including free none slots. Growth uses buffer.reserve's old+new allocation peak; an allocation error MUST preserve head, length, capacity, every slot and ownership. After successful allocation the library initializes new slots to none and rotates the old ring using complete value.swap operations, with no second allocation. Requests≤C succeed without mutation. New/growth perform O(capacity) slot work; end operations, get/replace and metadata use constant slot work; freeing an empty deque drains its none slots in O(capacity). These are library slot-operation counts; the reference interpreter currently copies the initialized prefix in buffer.push, so construction/growth can have higher host cost. No native backend performance guarantee is added. Fuel exhaustion/traps are abnormal execution outcomes, outside returned-error preservation guarantees. + +A full push and out-of-bounds replace return the exact original item. Callers MUST consume returned linear payloads. A nonempty free MUST NOT pop, close or destroy user elements; callers pop/consume all elements first. Empty free explicitly consumes only internal none slots before freeing its buffer. Ownership never escapes through a borrowed result. Valid calls add no program trap beyond the environment's execution limits. Existing linear availability, borrow/task-loan, bounds, generic Copy/Send/Share, effects and allocation rules verify the library as ordinary source; no new verifier state, AIR feature/opcode, runtime primitive, diagnostic, effect or authority is added. AIR format 0 and existing APIs retain meaning. Owners, files and channel endpoints follow the same rules as Vec; map/set/heap collections remain separate work. + +### 2.12 `std.hash`: non-cryptographic bytes and checksums + +The compiler registry MUST include `std.hash`, implemented in ordinary safe source. It exports exactly four monomorphic functions, all `effects []`: + +| Function | Contract | +|---|---| +| `fnv1a64(data: slice) -> u64` | FNV-1a 64, initial state `0xcbf29ce484222325` | +| `fnv1a64_extend(state: u64, data: slice) -> u64` | continue from the supplied FNV state | +| `crc32c(data: slice) -> u32` | reflected CRC-32C (Castagnoli), initial/final XOR `0xffffffff` | +| `crc32c_extend(checksum: u32, data: slice) -> u32` | continue from a finalized checksum, undoing and reapplying the final XOR | + +FNV MUST process each byte in slice order by XOR with its zero-extended value, then multiplication by `0x100000001b3` modulo 2^64. CRC results MUST equal this recurrence: start with `checksum XOR 0xffffffff`, XOR each zero-extended byte into the low bits, and perform eight steps: shift right once, XOR `0x82f63b78` exactly when the previous low bit was one. Return the state XOR `0xffffffff`. `crc32c(data)` is `crc32c_extend(0, data)`. These numeric results do not depend on target byte order or pointer width; serialization uses explicit std.bytes endian operations. CRC-32C is distinct from IEEE CRC-32. FNV and CRC definitions follow [RFC 9923 §§2,5](https://www.rfc-editor.org/rfc/rfc9923.html#section-2) and [RFC 3720 Appendix B.4](https://www.rfc-editor.org/rfc/rfc3720.html#appendix-B.4), respectively; the rules above specify the API's numeric convention. + +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 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 hashing/equality (Q-037). Entry has key: u64 and value: V. Ten operations use explicit `::` specialization: + +| Function | Result | +|---|---| +| `new(capacity: usize, heap: cap)` | NewResult: ok(U64Map), err(alloc_error) | +| `len(map: ref>) -> usize` | live entries | +| `capacity(map: ref>) -> usize` | maximum live entries | +| `reserve(map: mut>, capacity: usize, heap: cap)` | ReserveResult: ok, err(alloc_error) | +| `insert(map: mut>, key: u64, value: V)` | InsertResult: inserted, replaced(V), full(V) | +| `contains(map: ref>, key: u64) -> bool` | exact presence | +| `get(map: ref>, key: u64) -> std.option.Option` | copy of value, or none | +| `remove(map: mut>, key: u64) -> std.option.Option` | moving extraction, or none | +| `pop(map: mut>) -> std.option.Option>` | first occupied physical slot, or none | +| `free(map: U64Map)` | FreeResult: ok, not_empty(U64Map) | + +Representation: U64Map has storage: buffer> and length: usize. Slot has key: u64, state: SlotState and value: std.option.Option; 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; 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 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 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. + +### 2.14 `std.hashmap`: bounded owning general-key map + +The registry MUST include std.hashmap at std/hashmap.aji, ordinary safe source. `HashMap` binds explicit static `H: fn(ref) -> u64 effects []` and `E: fn(ref,ref) -> bool effects []` (spec 15 §18). K/V MAY be Copy, owners, files or endpoints under ordinary member/Send/Share rules. An applied type uses `HashMap`; functions use `::`. Distinct operation identities are distinct nominal map types. Entry has key: K and value: V; both are returned/transferred completely, never implicitly destroyed. + +The caller MUST supply deterministic, stable hashing and equality for live keys: E is an equivalence relation, and E(a,b) implies H(a)=H(b). Equality decides identity even when hashes collide. A stored key MUST NOT be modified in a way that changes its hash/equality; normal exclusive access rules still apply. These algebraic laws are explicit library preconditions, not compiler-proved properties. Hash/equality receive only shared key borrows, no capability or hidden state. User callback traps and fuel exhaustion are abnormal outcomes, outside returned-error preservation. + +Ten operations are specialized by the four ordered arguments above (get additionally requires V: Copy): + +| Operation | Result / transfer | +|---|---| +| new(capacity: usize, heap: cap) | NewResult: ok(HashMap), err(alloc_error) | +| len(map: ref>) -> usize | live entry count | +| capacity(map: ref>) -> usize | maximum live entries | +| reserve(map: mut>, capacity: usize, heap: cap) | ReserveResult: ok, err(alloc_error) | +| insert(map: mut>, key: K, value: V) | InsertResult: inserted, replaced(Entry), full(Entry) | +| contains(map: ref>, key: ref) -> bool | presence by actual key equality | +| get(map: ref>, key: ref) -> std.option.Option | copied value; no K: Copy requirement | +| remove(map: mut>, key: ref) -> std.option.Option> | moves complete stored key/value out | +| pop(map: mut>) -> std.option.Option> | moves the last dense entry out | +| free(map: HashMap) | FreeResult: ok, not_empty(HashMap) | + +Only new/reserve declare effects [mem.alloc] and require explicit heap authority; all other functions declare effects [] and perform no heap allocation. Insert is bounded, never grows. Replacement succeeds at full capacity and returns the previous complete key/value; the supplied equivalent key becomes the stored key. A new key when full returns the exact supplied key/value with all storage unchanged. Missing removal leaves storage unchanged. Callers MUST consume owning replaced/full/remove/pop/not_empty payloads explicitly. No borrowed value/cursor escapes. + +Representation: HashMap has entries: buffer>, buckets: buffer. StoredEntry has hash: u64, key: K, value: V. Bucket has hash: u64, index: usize, state: BucketState (empty/deleted/occupied). For capacity N, entries.capacity=N, entries.len=L≤N; buckets.capacity=buckets.len=2N. Every dense entry [0,L) has one occupied bucket whose hash/index agree; no other bucket owns or refers to a live entry. Cached hash equals H(key); live keys are pairwise unequal by E. Each occupied bucket is reachable by the probing rule. Keys/values have no vacancy sentinel or default value. Manual representation construction/mutation MUST preserve this invariant; invalid representations retain ordinary memory/ownership safety but may trap or violate map behavior. + +Probe start is the unsigned u64 hash modulo the bucket count. Advance wraps without overflow, and at most bucket count probes occur. Lookup skips deleted and stops at empty/end; occupied hash equality is only a filter before E. Insert remembers the first deleted/empty slot but searches for an existing equal key before choosing it, including when full. Zero capacity never performs modulo and returns full on insert. Deleted-only tables remain bounded and reusable. + +Removal exchanges the last dense entry into the removed entry's position when needed and repairs that moved entry's occupied bucket by its cached hash/index. Thus the initialized prefix always contains complete values; no uninitialized hole or partial move is introduced. pop consumes the last dense entry and marks its bucket deleted without invoking H/E. Pop order is reverse current dense order (insertion appends; replacement retains position; removal may exchange the last entry into a hole). This is deterministic for the history, not sorted order. Successful reserve preserves dense/pop order and clears tombstones. Nonempty free returns the entire map unchanged, based on actual entries.len, not forgeable length metadata. Empty free explicitly drains only Copy bucket metadata and frees both buffers; it cannot normally discard a key/value, even with invalid bucket metadata. + +New checks 2N overflow, allocates the empty entry buffer, then the fully initialized bucket buffer. A returned second-allocation failure MUST free the temporary empty entry buffer and refund its recorded authority. Reserve≤N is an unchanged no-op with its declared mut/effect/capability requirements. Growth MUST allocate/initialize a new bucket buffer before calling ownership-preserving buffer.reserve on the dense entries. Any returned failure MUST free temporary metadata, preserve both original buffers, every key/value/hash/index/state and pop order, and refund all temporary charges. After entries reserve succeeds, only cached hashes are used to rebuild the new buckets; no further recoverable allocation or callback occurs. Swap in the new buckets and explicitly free the old Copy metadata buffer. Peak quota includes old/new entry buffers, old/new bucket buffers and separately charged user owners. All old storage refunds go to their recorded authorities, even when growth uses another capability. Arithmetic/allocation-size overflow returns alloc_error.budget_exceeded; no shrink occurs. + +Each StoredEntry slot charges hash plus full K/V slot sizes, including uninitialized capacity; each Bucket charges hash, usize and state tag. Unused capacity reserves bytes but contains no live K/V. There is no tag/default key allocation and no implicit destruction. Existing initialized buffers, aggregate transfer/exchange, borrows/task loans, bounds, effects, Copy/Send/Share and quota verification suffice; no new AIR instruction/feature, source form, verifier/runtime state or diagnostic is added. Generic callback contracts are RFC 0029. Valid bookkeeping does not trap with a valid representation and successful callbacks. Existing API/AIR meanings remain unchanged, including std.map.U64Map. Deterministic/hosted behavior agrees. Probe operations are O(N) worst-case plus callback work, pop/removal repair O(N), reserve O(N²) worst-case collision work; buffer-prefix interpreter copying may add host cost. No adversarial collision or native throughput promise is made. + +### 2.15 `std.hashset`: bounded owning general-key set + +The registry MUST include std.hashset at std/hashset.aji, ordinary safe source. HashSet binds the same exact pure ref-key hash/equality contracts and stable algebraic laws as std.hashmap (§2.14), with explicit type/application arguments `K,fn hash,fn equal`. It owns complete arbitrary K, including owning byte buffers, structs, resources and endpoints subject to existing member/Send/Share rules. Its representation is one field map: std.hashmap.HashMap, with every live value true; all underlying dense/probe invariants apply. No default key, implicit destruction or library access privilege is added. + +Nine operations use the three ordered arguments above: + +| Operation | Result / transfer | +|---|---| +| new(capacity: usize, heap: cap) | NewResult: ok(HashSet), err(alloc_error) | +| len(set: ref>) -> usize | live count | +| capacity(set: ref>) -> usize | maximum live keys | +| reserve(set: mut>, capacity: usize, heap: cap) | ReserveResult: ok, err(alloc_error) | +| insert(set: mut>, key: K) | InsertResult: inserted, present(original_input_K), full(original_input_K) | +| contains(set: ref>, key: ref) -> bool | exact membership | +| remove(set: mut>, key: ref) -> std.option.Option | moving extraction of the stored key | +| pop(set: mut>) -> std.option.Option | moving extraction of last dense key | +| free(set: HashSet) | FreeResult: ok, not_empty(HashSet) | + +Only new/reserve declare mem.alloc and take explicit heap authority. Insert checks membership before transferring to the underlying map: duplicate insertion MUST preserve the existing stored key and every entry/bucket, returning the exact input key as present, even when full. New-key full also preserves the set and returns its exact input. This gives one canonical insert contract; replacement requires explicit remove/insert by the caller. No automatic growth occurs. Owning present/full/remove/pop/not_empty results MUST be consumed. contains returns no borrow. Missing remove and nonempty free preserve all state. Pop order is the underlying reverse current dense order; removal may move the last key to a hole, and reserve preserves the order. + +New/reserve failure, peak quota/refund, zero capacity, probing, collision equality, callback/fuel traps and visible representation invariants are exactly §2.14's rules. Each capacity slot charges hash plus complete K plus bool, and two buckets: for K=u64, N charges 51N bytes; separately owned K allocations remain separately charged. insert MAY evaluate H/E for membership and again for bounded map insertion; these pure stable operations grant no authority and cannot be inferred away. Once membership says absent, map replacement is unreachable under the valid representation/hash/equality laws; invalid laws may trap under ordinary abnormal-path semantics. + +Existing buffers/aggregates/borrows, static callable identity, effects, Copy/Send/Share and ownership verification suffice. No new syntax, diagnostic, feature/opcode, verifier/runtime state, implicit allocation/destructor or trusted boundary is added. Deterministic/hosted behavior agrees and existing APIs/AIR meanings remain unchanged. Worst-case insertion/membership/removal/pop is O(N) plus callback work; growth is O(N²) worst-case collision work with existing interpreter prefix-copy costs. No sorted output, adversarial collision bound or native throughput promise is added. + +### 2.16 `std.heap`: bounded owning binary heap + +The registry MUST include std.heap at std/heap.aji, ordinary safe source. `BinaryHeap` binds an explicit static `B: fn(ref,ref) -> bool effects []` (spec 15 §18), applied as `BinaryHeap` and `::`. T MAY contain owners, files or endpoints under ordinary member/Send/Share rules. Distinct bound operations give distinct nominal heap types. No default T, captured environment, runtime dispatch or implicit cleanup is added. + +B(a,b) means a MUST precede b. B MUST be a stable strict weak order on live values: irreflexive and transitive, with transitive incomparability. Equivalent values have neither B(a,b) nor B(b,a); their extraction order is deterministic for a fixed operation sequence but MUST NOT be assumed stable. Changing a live value's relative order violates the representation precondition. Pure callbacks grant no authority; callback traps/fuel exhaustion are abnormal outcomes, with no returned-state preservation promise. + +Eight operations use the two ordered arguments above; peek additionally requires T: Copy: + +| Operation | Result / transfer | +|---|---| +| new(capacity: usize, heap: cap) | NewResult: ok(BinaryHeap), err(alloc_error) | +| len(value: ref>) -> usize | live count | +| capacity(value: ref>) -> usize | maximum live count | +| reserve(value: mut>, capacity: usize, heap: cap) | ReserveResult: ok, err(alloc_error) | +| push(value: mut>, item: T) | PushResult: ok, full(original_input_T) | +| peek(value: ref>) -> std.option.Option | Copy root value, or none | +| pop(value: mut>) -> std.option.Option | moving extraction of root, or none | +| free(value: BinaryHeap) | FreeResult: ok, not_empty(BinaryHeap) | + +Only new/reserve declare mem.alloc and take explicit allocation authority. Push is bounded: full MUST preserve all state, return the exact input and evaluate no ordering callback; it never grows. Successful push/pop MUST restore the heap invariant; pop returns the root that preceded the operation, or none without mutation when empty. Peek copies only Copy T and retains no borrow. Nonempty free MUST return the complete unchanged heap. Every owning full/pop/not_empty result MUST be explicitly consumed. + +The visible representation is `BinaryHeap { entries: buffer>, indices: buffer }`, `Entry { position: usize, value: T }`. Both initialized lengths are L and capacities N, with L≤N. Indices form a permutation of 0..L; entries[indices[p]].position MUST equal p. For every nonroot p, B(value_at(p),value_at((p-1)/2)) MUST be false. Values are owned exactly once in the initialized dense prefix; unused capacity contains no live T. Copy indices permit sifting without copying owners, holes, temporary default values or borrowed enum payloads. Caller construction/mutation MUST preserve the complete invariant. + +Push appends a complete entry and its Copy index, then sifts upward by swapping Copy indices and repairing positions. Pop removes the final Copy index, installs it at the root when nonempty, then sifts downward: compare the children, choose right only when it strictly precedes left, and swap only when the chosen child strictly precedes its parent. After ordering, pop the last dense entry; if it is not the removed root, exchange it into that dense hole and repair its Copy heap index using its recorded position. Return the complete removed T. Bounds and parent/child arithmetic MUST be checked before accesses; the nonleaf condition p reserves 24N bytes, with separately owned payloads charged independently. Peak growth includes old/new entries, old/new indices and all user-owned allocations. Refunds follow each buffer's recorded authority, including growth through a different capability. Arithmetic/allocation-size overflow returns alloc_error.budget_exceeded. + +Existing buffer/aggregate transfer/exchange, static contracts, borrow/task-loan exclusion, bounds, effects, Copy/Send/Share and resource verification suffice. Valid representations/successful callbacks do not trap during bookkeeping. Existing source/AIR meanings are unchanged; no new syntax, diagnostic, AIR feature/instruction, verifier/runtime state or trusted boundary is added. Deterministic/hosted behavior agrees. Abstract push/pop perform O(log L) comparisons and index swaps, peek is O(1), reserve copies O(L); interpreter prefix-copy/GC costs may add host work. No native-throughput or stable tie-order promise is made. + +### 2.17 `std.io`: bounded I/O foundation + +The registry MUST include std.io at std/io.aji, ordinary safe source. Six concrete functions compose existing borrowed-resource/capability I/O with caller-supplied slices. They MUST NOT allocate heap storage, open/close resources, retain borrows, infer effects or gain authority through import. Existing primitive writes already report all bytes written on success; no redundant write alias is added. + +ReadError has completed: usize / error: io_error. ReadExactResult has ok, eof(usize), err(ReadError). ReadToEndResult has eof(usize), full(usize), err(ReadError). CopyError has read: usize / confirmed_written: usize / error: io_error; CopyResult has eof(usize), limit(usize), err(CopyError). All are ordinary Copy data, never authority. + +| Function arguments | Result | Effects | +|---|---|---| +| read_exact_stdin(input: cap, destination: slice_mut) | ReadExactResult | io.read | +| read_exact_file(input: mut>, destination: slice_mut) | ReadExactResult | fs.read | +| read_exact_stream(input: mut, destination: slice_mut) | ReadExactResult | net.read | +| read_to_end_file(input: mut>, destination: slice_mut) | ReadToEndResult | fs.read | +| copy_file(input: mut>, output: mut>, scratch: slice_mut, limit: usize) | CopyResult | fs.read, fs.write | +| copy_file_append(input: mut>, output: mut>, scratch: slice_mut, limit: usize) | CopyResult | fs.read, fs.write | + +Exact reads loop over the unfilled suffix until destination.len successful bytes have been read (ok), an intrinsic reports zero (eof(completed)), or a read errors (err with the previous successful byte count and unchanged error). Empty exact destination returns ok without an intrinsic. EOF leaves the remaining destination unchanged. On a returned read error, only the completed successful prefix is guaranteed; contents of the attempted suffix follow the primitive and are not additionally promised by this wrapper. Bytes outside the destination MUST remain unchanged. Every count increment MUST be bounded by the remaining capacity. + +read_to_end_file loops until zero (eof(completed)), destination capacity is reached (full(destination.len)), or a read errors (same prefix/error contract). Empty destination returns full(0) without I/O. Full does not establish that unread bytes remain or that EOF was reached: the function MUST NOT read/discard an extra byte to distinguish those states. Neither reader changes or retains caller resource ownership. + +Copies use scratch chunks bounded by min(scratch.len, limit-completed). Successful reads are followed by fs.write_all; reaching zero returns eof(completed), reaching limit returns limit(completed) without probing EOF. Thus exact EOF at limit returns limit, not eof. A read error returns both counts equal to the previously confirmed completed chunks. A write error returns read including the just-read chunk and confirmed_written counting only earlier successful writes. The failed write MAY have externally written a prefix; confirmed_written is a lower bound, not an exact failed-output count or rollback promise. The input has advanced through confirmed successful reads. Counts MUST NOT exceed limit or overflow. EOF/error retain both borrowed resources for explicit caller cleanup. + +limit=0 MUST return limit(0) without I/O, including with empty scratch. Empty scratch with positive limit MUST return err(CopyError{read:0,confirmed_written:0,error:io_error.invalid_input}) without I/O. Scratch contents after the call are unspecified; bytes outside its slice MUST remain unchanged. Functions do not allocate, grow, sync or close; the caller explicitly supplies all grants, slices, limits and final resource consumption. Effects/mut/task-loan requirements apply even to no-op paths. Append copies use the existing append resource semantics. + +Existing type, effect/capability, borrow/task-loan, resource availability, bounds and outcome checks apply without new diagnostics or verifier/runtime state. Operations use ordinary AIR and spec 11 profile behavior; no unsafe/trusted boundary, syntax/opcode/feature, implicit cleanup, timeout or existing semantic change is introduced. Blocking/fuel remain environment outcomes. Returned failures are explicit ordinary enums, never exceptions. Successful work is linear in read bytes plus intrinsic calls; caller capacities/limits and fuel bound work. Buffered adapters are specified in §2.18; lexical paths remain a subsequent STD-7 increment. + +### 2.18 `std.io.reader` / `std.io.writer`: owning bounded file adapters + +The registry MUST include std.io.reader at std/io/reader.aji and std.io.writer at std/io/writer.aji, ordinary safe source with concrete file modes. They MUST NOT open/close files, sync, retain caller borrows, grow implicitly, infer effects or acquire authority through import. Each owns one file and one fixed-capacity initialized buffer. Only new declares mem.alloc and accepts explicit allocation authority; byte storage charges capacity bytes, including unused capacity. Capacity zero is valid and uses direct primitive reads/writes. Constructor failure MUST return the exact original file with alloc_error, without I/O or resource consumption. + +Reader is `{ file: file, storage: buffer, begin: usize, end: usize }`, with fully initialized length=capacity=N and 0≤begin≤end≤N. Bytes begin..end are unread prefetched data; the underlying file cursor has advanced through those bytes. Writer is `{ file: file, storage: buffer, used: usize, failed: std.option.Option }`, with fully initialized length=capacity=N and 0≤used≤N. Bytes 0..used are pending accepted data; failed is none or the first failed external-write error. Neither adapter's file/storage may be independently used, consumed or mutated in a way that violates these logical invariants. Ordinary visible fields grant no representation privilege. + +Reader types: NewError{file:file,error:alloc_error}; NewResult{ok(Reader),err(NewError)}; ReadResult{ok(usize),err(io_error)}; FinishResult{ok(file),unread(Reader)}; Discarded{file:file,unread:usize}. Writer types: NewError{file:file,error:alloc_error}; NewResult{ok(Writer),err(NewError)}; WriteError{accepted:usize,error:io_error}; WriteResult{ok,err(WriteError)}; FlushResult{ok,err(io_error)}; FinishError{writer:Writer,error:io_error}; FinishResult{ok(file),err(FinishError)}; Discarded{file:file,pending:usize,failed:std.option.Option}. Every file/adapter-bearing result is linear and MUST be explicitly consumed. + +| Module operation | Result | Effects | +|---|---|---| +| reader.new(input: file, capacity: usize, heap: cap) | NewResult | mem.alloc | +| reader.read(input: mut, destination: slice_mut) | ReadResult | fs.read | +| reader.read_exact(input: mut, destination: slice_mut) | std.io.ReadExactResult | fs.read | +| reader.finish(input: Reader) | FinishResult | none | +| reader.discard(input: Reader) | Discarded | none | +| writer.new(output: file, capacity: usize, heap: cap) | NewResult | mem.alloc | +| writer.write(output: mut, bytes: slice) | WriteResult | fs.write | +| writer.flush(output: mut) | FlushResult | fs.write | +| writer.finish(output: Writer) | FinishResult | fs.write | +| writer.discard(output: Writer) | Discarded | none | + +Reader.read returns at most destination.len bytes. Empty destination returns ok(0) without I/O or consuming cached data; it does not establish EOF. If cached bytes exist, copy min(unread,destination.len) and advance begin, without refilling during that call. Otherwise, for N>0, refill the whole storage using fs.read, then return one cached prefix; a successful zero refill returns ok(0) as EOF. With N=0 delegate one primitive read directly to the destination. Refill errors retain the file/storage and existing offsets, returning the original io_error with no guessed external cursor rollback. Bytes outside the destination remain unchanged. read_exact composes read over destination suffixes and uses §2.17's completed-prefix/EOF/error contract, with no borrow escaping. + +Reader.finish MUST return unread(the complete unchanged Reader) when begin0, copy as much as fits, flushing a full buffer only to make room for further input. If a call ends with a full buffer, retain it until a later write/flush/finish. On a room-making flush error, return WriteError with the number of this call's input bytes already accepted and the original error; the unaccepted suffix remains caller-owned. Buffered pending bytes remain in Writer, including accepted bytes from earlier calls. With N=0, delegate fs.write_all directly: failure has accepted=0, though an external prefix MAY have been written. No count exceeds input.len or overflows. + +Writer.flush on a healthy empty buffer returns ok without I/O. On a successful external write, used becomes zero. On any external write failure, used/data remain unchanged and failed becomes some(the first error); no automatic retry/reset is allowed. Once failed is some(error), every write (including empty) MUST return err with accepted=0 and that error, and every flush MUST return err(error), without I/O or buffer mutation. Unknown partial external writes make retrying pending data unsound. Writer.finish first flushes: success drains/frees storage and returns the file; error returns FinishError with the complete unchanged failed Writer and original error. Finish does not sync or close. Writer.discard explicitly abandons buffered pending bytes, drains/frees storage and returns the file, used count and failure state; pending on failure MAY overlap an already externally written prefix and is not an exact loss count. + +Effects, moves and mut/task-loan requirements apply on no-op/cached/failure paths. Existing aggregate/buffer moves, resource borrowing, alias exclusion, bounds/arithmetic, effect/capability and Copy/Send/Share rules verify all safe code; files make adapters non-Share and ordinary Send checks govern task transfer. Deterministic/hosted behavior follows existing profile primitives. No new AIR meaning, instruction/feature, syntax, diagnostic, verifier/runtime state, unsafe boundary, implicit destructor or cancellation policy is introduced. Invalid representation may trap through existing checked operations, preserving memory safety. Valid bookkeeping does not trap for a valid invariant/conforming primitives. Work is linear in initialized/copy/drained bytes plus I/O calls, with existing interpreter prefix-copy/GC costs. Std 0.1 remains unfinished. + +### 2.19 `std.path`: caller-buffer lexical paths + +The registry MUST include std.path at std/path.aji as ordinary safe source. All six supported operations declare effects [], allocate no heap, retain/return no borrow and grant no filesystem authority. Paths use the same byte separator `/` in every profile, independent of host platform. Backslash, colon and non-UTF-8 bytes are ordinary component bytes; there is no drive/UNC, symlink, filesystem lookup or current-directory interpretation. Lexical normalization MUST NOT be used as a capability-containment or symlink-resolution check; every filesystem operation still validates its path and granted scope independently. + +Range is Copy `{ start: usize, end: usize }`. For a query on path, 0≤start≤end≤path.len; the caller takes ref path[start..end] under ordinary bounds/borrow rules. Empty ranges are valid. Query functions accept every byte slice, including NUL, and perform no normalization or validity claim. WriteResult is Copy `{ ok(usize), invalid_input, size_overflow, short_output }`. Both writing functions MUST reject NUL anywhere in either input with invalid_input, including an ignored base when child is absolute. Invalid input takes precedence over output-size overflow, which takes precedence over short output. Every returned error MUST leave the complete destination unchanged. Success writes exactly the reported canonical prefix and preserves the destination suffix. No NUL terminator is written. Aliased inputs/output MUST reject under existing borrowing rules; explicitly disjoint slices of the same allocation are permitted. + +| Function arguments | Result | +|---|---| +| is_absolute(path: slice) | bool: nonempty and first byte `/` | +| basename(path: slice) | Range of the last nonempty component, ignoring trailing separators; empty/root-only input returns 0..0 | +| parent(path: slice) | Range of the raw prefix before basename, trimming the separator run before it; rooted input retains at least its first `/`; empty/relative single component returns 0..0 | +| extension(path: slice) | Range after the final dot in basename, excluding the dot; absent/leading-only/trailing dot and `.`/`..` return the empty range at basename.end | +| normalize(destination: slice_mut, path: slice) | WriteResult | +| join(destination: slice_mut, base: slice, child: slice) | WriteResult | + +Component queries preserve original byte offsets and do not collapse interior separator runs or dot components. For example basename(b"a//b///") is 3..4 and parent is 0..1; basename(b"///") is 0..0 and parent is 0..1; parent(b"a/../b") is 0..4. Extension(b".profile") is 8..8, extension(b".profile.json") selects json, and extension(b"a..b") selects b. Empty extension makes no distinction between no dot and an empty suffix after a trailing dot. A returned Range is ordinary data, not a proof that it applies to some different/mutated path. + +Normalize MUST collapse separator runs, remove `.` components and trailing separators, and cancel each ordinary component followed by `..`. Relative unmatched `..` components MUST be preserved at the beginning. Rooted `..` above `/` MUST be ignored. Empty or reduced-empty relative input becomes `.`; root-only/reduced-empty rooted input becomes `/`. All leading separators collapse to one root; there is no special meaning for exactly two. Dot bytes embedded in other names are ordinary bytes. Examples: a//b/../c/ → a/c; a/../../b → ../b; /../../a → /a; ../a/.. → ..; a/.. → . . Normalization is idempotent. + +Join MUST normalize child alone when child is absolute; otherwise normalize the component sequence of base followed by child, as if separated by one `/`, without making an empty base into an artificial root. An empty child normalizes base; both empty become `.`. Relative child `..` may cancel base components; an absolute child replaces base. Examples: /data/a joined with ../b → /data/b; a joined with /b → /b; empty base joined with a → a. These are byte algorithms only: a successfully normalized relative path is still invalid for current filesystem primitives, and a normalized absolute result may still lie outside the caller's authority. + +Writing operations MUST validate input and determine final normalized length before mutation. Capacity need only accommodate the final prefix, not canceled components or raw concatenation; joining/normalization MUST NOT demand hidden scratch/heap storage. The safe reference algorithm scans components backward, tracking pending parent components, measures retained bytes/separators with checked arithmetic, then emits the retained components backward into the already-validated prefix. Pending relative parents become the leading `..` components; rooted excess parents are dropped. No combined raw input length is required. Input-size/length/cursor arithmetic MUST avoid overflow; size_overflow is ordinary data, not a trap. For conforming slices, returned errors/success do not trap except ordinary fuel exhaustion. + +Existing slices, Copy structs/enums, checked bounds/arithmetic, exclusive-output/shared-input loans, effects and task Send/Share rules suffice. No owner/resource is consumed and no loan escapes. Valid/rejected calls use existing E7002/E7005/E2101/E4101; malformed bytes and insufficient capacity are ordinary WriteResult variants, not verifier diagnostics. No new syntax, AIR meaning/instruction/feature, verifier/runtime state or unsafe/trusted boundary is introduced. Query work is O(path.len); writing work is O(base.len+child.len+output.len) with fixed frame state and existing interpreter costs. Current source borrow-return limitations (Q-034) remain unchanged. Filesystem/system gaps and the Std 0.1 exit examples remain subsequent work. diff --git a/docs/spec/README.md b/docs/spec/README.md index d8c4c4e..1c97eb1 100644 --- a/docs/spec/README.md +++ b/docs/spec/README.md @@ -25,6 +25,7 @@ The specification is split by semantic domain. Rationale for major decisions liv | [13-contracts-and-unsafe.md](13-contracts-and-unsafe.md) | Normative draft | Contracts, proof status and unsafe boundaries | | [14-agent-efficiency.md](14-agent-efficiency.md) | Normative draft (design objectives) | Agent efficiency, Model Capability Compression, design review requirement | | [15-source-language.md](15-source-language.md) | Normative draft | The agent-facing source language `.aji` 0.1 (Phase 6A), lowering to AIR | +| [16-standard-library.md](16-standard-library.md) | Normative draft | Standard library contracts and built-in pure modules | ## Reading order diff --git a/examples/modules/aji.toml b/examples/modules/aji.toml new file mode 100644 index 0000000..9265c04 --- /dev/null +++ b/examples/modules/aji.toml @@ -0,0 +1,7 @@ +[package] +name = "module-example" +version = "0.1.0" +entry = "main.aji" + +[modules] +app.model = "model.aji" diff --git a/examples/modules/main.aji b/examples/modules/main.aji new file mode 100644 index 0000000..68f4d69 --- /dev/null +++ b/examples/modules/main.aji @@ -0,0 +1,9 @@ +module app.entry +import app.model; + +fn main() -> u64 +effects [] +{ + let pair = app.model.Pair { left: 20, right: 22 }; + return app.model.total(pair); +} diff --git a/examples/modules/model.aji b/examples/modules/model.aji new file mode 100644 index 0000000..b794fcd --- /dev/null +++ b/examples/modules/model.aji @@ -0,0 +1,7 @@ +module app.model + +struct Pair { left: u64, right: u64 } + +fn total(pair: Pair) -> u64 +effects [] +{ return pair.left + pair.right; } diff --git a/examples/std/bounded.aji b/examples/std/bounded.aji new file mode 100644 index 0000000..e8652b4 --- /dev/null +++ b/examples/std/bounded.aji @@ -0,0 +1,35 @@ +module demo.bounded +import std.bytes; +import std.math; + +fn encode(dst: slice_mut, data: slice) -> usize +effects [] +{ + match std.math.checked_add_usize(data.len, 1) { + std.math.UsizeResult::ok(total) => { + if total > dst.len { return 0; } + match std.bytes.copy(mut dst, ref data) { + std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; } + std.bytes.WriteResult::short_output => { return 0; } + } + } + std.math.UsizeResult::overflow => { return 0; } + } +} + +fn main() -> usize +effects [] +{ + var buf: [u8; 16] = [165; 16]; + let size = encode(mut buf, b"key=value"); + assert(size == 10); + assert(buf[9] == 0 and buf[10] == 165); + match std.bytes.find_slice(ref buf[0..size - 1], b"=") { + std.bytes.FindResult::found(index) => { + assert(std.bytes.equal(ref buf[0..index], b"key")); + assert(std.bytes.equal(ref buf[index + 1..size - 1], b"value")); + } + std.bytes.FindResult::not_found => { trap; } + } + return size; +} diff --git a/examples/std/buffered_io.aji b/examples/std/buffered_io.aji new file mode 100644 index 0000000..31713a8 --- /dev/null +++ b/examples/std/buffered_io.aji @@ -0,0 +1,46 @@ +module demo.buffered_io +import std.io.reader; +import std.io.writer; + +fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc] { + let input = fs.open_read(src,b"/in/data") or trap; + let output = fs.create(dst,b"/out/data") or trap; + let reader = match std.io.reader.new(move input,3usize,heap) { + std.io.reader.NewResult::ok(value) => { move value }, + std.io.reader.NewResult::err(error) => { + let (file,error) = struct.unpack(move error); + fs.close(move file) or trap; fs.close(move output) or trap; return 0; + } + }; + let writer = match std.io.writer.new(move output,3usize,heap) { + std.io.writer.NewResult::ok(value) => { move value }, + std.io.writer.NewResult::err(error) => { + let (file,error) = struct.unpack(move error); + fs.close(move file) or trap; + let (file,unread) = struct.unpack(std.io.reader.discard(move reader)); fs.close(move file) or trap; return 0; + } + }; + var failed: bool = false; var count: usize = 0; var bytes: [u8;2] = [0u8;2]; + { mut input = reader; mut output = writer; loop { + match std.io.reader.read(input,mut bytes) { + std.io.reader.ReadResult::err(error) => { failed = true; break; }, + std.io.reader.ReadResult::ok(n) => { + if n == 0usize { break; } + match std.io.writer.write(output,ref bytes[0usize..n]) { + std.io.writer.WriteResult::ok => { count = count + n; }, + std.io.writer.WriteResult::err(error) => { failed = true; break; } + } + } + } + } } + let (file,unread) = struct.unpack(std.io.reader.discard(move reader)); fs.close(move file) or trap; + match std.io.writer.finish(move writer) { + std.io.writer.FinishResult::ok(file) => { fs.close(move file) or trap; }, + std.io.writer.FinishResult::err(error) => { + let (writer,error) = struct.unpack(move error); + let (file,pending,error) = struct.unpack(std.io.writer.discard(move writer)); + fs.close(move file) or trap; return 0; + } + } + if failed { return 0; } return count as! u64; +} diff --git a/examples/std/bytes.aji b/examples/std/bytes.aji new file mode 100644 index 0000000..9c97054 --- /dev/null +++ b/examples/std/bytes.aji @@ -0,0 +1,14 @@ +module demo.standard +import std.bytes; +import std.math; + +fn main() -> u64 +effects [] +{ + var data: [u8; 4] = zero; + std.bytes.fill(mut data, 65); + assert(std.bytes.equal(ref data, b"AAAA")); + let index = std.bytes.find(ref data, 65); + if index < data.len { assert(data[index] == 65); } + return std.math.clamp_u64(42, 0, 100); +} diff --git a/examples/std/deque.aji b/examples/std/deque.aji new file mode 100644 index 0000000..9c7ebbe --- /dev/null +++ b/examples/std/deque.aji @@ -0,0 +1,50 @@ +module example.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(2, heap); + let first = own.new(7u64, heap) or trap; + let last = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { + mut q = value; + pushed::>(std.deque.push_front::>(q, move first)); + pushed::>(std.deque.push_back::>(q, move last)); + let a = front::>(q); + assert(own.take(move a) == 7u64); + let b = back::>(q); + answer = own.take(move b); + } + released::>(move value); + return answer; +} diff --git a/examples/std/endian.aji b/examples/std/endian.aji new file mode 100644 index 0000000..bf33485 --- /dev/null +++ b/examples/std/endian.aji @@ -0,0 +1,16 @@ +module demo.endian +import std.bytes; + +fn main() -> u32 +effects [] +{ + var wire: [u8; 6] = zero; + match std.bytes.write_u32_be(mut wire[1..5], 0x12345678) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + match std.bytes.read_u32_be(ref wire[1..5]) { + std.bytes.ReadU32::ok(value) => { return value; } + std.bytes.ReadU32::short_input => { return 0; } + } +} diff --git a/examples/std/format.aji b/examples/std/format.aji new file mode 100644 index 0000000..43c8d81 --- /dev/null +++ b/examples/std/format.aji @@ -0,0 +1,29 @@ +module demo.format +import std.bytes; +import std.fmt; + +fn main() -> usize +effects [] +{ + var record: [u8; 24] = [165; 24]; + match std.bytes.copy(mut record, b"value=") { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + var offset: usize = 6; + match std.fmt.write_i64(mut record[offset..record.len], -42) { + std.fmt.WriteResult::ok(count) => { offset = offset + count; } + std.fmt.WriteResult::short_output => { return 0; } + } + match std.bytes.copy(mut record[offset..record.len], b" count=") { + std.bytes.WriteResult::ok => { offset = offset + 7; } + std.bytes.WriteResult::short_output => { return 0; } + } + match std.fmt.write_usize(mut record[offset..record.len], 7) { + std.fmt.WriteResult::ok(count) => { offset = offset + count; } + std.fmt.WriteResult::short_output => { return 0; } + } + assert(std.bytes.equal(ref record[0..offset], b"value=-42 count=7")); + for i in offset..record.len { assert(record[i] == 165); } + return offset; +} diff --git a/examples/std/generics.aji b/examples/std/generics.aji new file mode 100644 index 0000000..96594af --- /dev/null +++ b/examples/std/generics.aji @@ -0,0 +1,12 @@ +module demo.generic +import std.option; + +fn identity(value: T) -> T effects [] { return value; } + +fn main() -> u64 effects [] { + let value = std.option.Option::::some(identity::(42)); + match value { + std.option.Option::::some(n) => { return n; } + std.option.Option::::none => { return 0; } + } +} diff --git a/examples/std/hash.aji b/examples/std/hash.aji new file mode 100644 index 0000000..939b2fd --- /dev/null +++ b/examples/std/hash.aji @@ -0,0 +1,19 @@ +module example.hash +import std.hash; +import std.bytes; + +fn main() -> u64 effects [] { + let prefix = std.hash.crc32c(b"1234"); + let checksum = std.hash.crc32c_extend(prefix, b"56789"); + assert(checksum == 0xe3069283u32); + assert(checksum == std.hash.crc32c(b"123456789")); + let first = std.hash.fnv1a64(b"foo"); + assert(std.hash.fnv1a64_extend(first, b"bar") == 0x85944171f73967e8u64); + var wire: [u8; 4] = zero; + match std.bytes.write_u32_le(mut wire, checksum) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { trap; } + } + assert(std.bytes.equal(ref wire, b"\x83\x92\x06\xe3")); + return 42; +} diff --git a/examples/std/hashmap.aji b/examples/std/hashmap.aji new file mode 100644 index 0000000..06269cd --- /dev/null +++ b/examples/std/hashmap.aji @@ -0,0 +1,35 @@ +module demo.hashmap +import std.hashmap; +import std.option; + +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } + +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = match std.hashmap.new::,fn hash,fn equal>(1,heap) { + std.hashmap.NewResult::,fn hash,fn equal>::ok(value) => { move value }, + std.hashmap.NewResult::,fn hash,fn equal>::err(error) => { trap; } + }; + let value = own.new(42u64,heap) or trap; + { mut q = map; + match std.hashmap.insert::,fn hash,fn equal>(q,Key { id: 7 },move value) { + std.hashmap.InsertResult::>::inserted => {} + std.hashmap.InsertResult::>::replaced(old) => { trap; } + std.hashmap.InsertResult::>::full(returned) => { trap; } + } + let key = Key { id: 7 }; + match std.hashmap.remove::,fn hash,fn equal>(q,ref key) { + std.option.Option::>>::some(entry) => { + let (stored_key,owner) = struct.unpack(move entry); + assert(stored_key.id == 7u64); assert(own.take(move owner) == 42u64); + } + std.option.Option::>>::none => { trap; } + } + } + match std.hashmap.free::,fn hash,fn equal>(move map) { + std.hashmap.FreeResult::,fn hash,fn equal>::ok => {} + std.hashmap.FreeResult::,fn hash,fn equal>::not_empty(returned) => { trap; } + } + return 42; +} diff --git a/examples/std/hashset.aji b/examples/std/hashset.aji new file mode 100644 index 0000000..510843d --- /dev/null +++ b/examples/std/hashset.aji @@ -0,0 +1,34 @@ +module demo.hashset +import std.hashset; +import std.option; + +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } + +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = match std.hashset.new::(1,heap) { + std.hashset.NewResult::::ok(value) => { move value }, + std.hashset.NewResult::::err(error) => { trap; } + }; + let key = Key { id: 7, owner: own.new(42u64,heap) or trap }; + { mut q = set; + match std.hashset.insert::(q,move key) { + std.hashset.InsertResult::::inserted => {} + std.hashset.InsertResult::::present(returned) => { trap; } + std.hashset.InsertResult::::full(returned) => { trap; } + } + match std.hashset.pop::(q) { + std.option.Option::::some(key) => { + let (id,owner) = struct.unpack(move key); + assert(id == 7u64); assert(own.take(move owner) == 42u64); + } + std.option.Option::::none => { trap; } + } + } + match std.hashset.free::(move set) { + std.hashset.FreeResult::::ok => {} + std.hashset.FreeResult::::not_empty(returned) => { trap; } + } + return 42; +} diff --git a/examples/std/heap.aji b/examples/std/heap.aji new file mode 100644 index 0000000..227a267 --- /dev/null +++ b/examples/std/heap.aji @@ -0,0 +1,32 @@ +module demo.heap +import std.heap; +import std.option; + +struct Item { priority: u64, owner: own } +fn before(a: ref, b: ref) -> bool effects [] { return a.priority < b.priority; } + +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = match std.heap.new::(1,heap) { + std.heap.NewResult::::ok(value) => { move value }, + std.heap.NewResult::::err(error) => { trap; } + }; + let item = Item { priority: 7, owner: own.new(42u64,heap) or trap }; + { mut q = value; + match std.heap.push::(q,move item) { + std.heap.PushResult::::ok => {} + std.heap.PushResult::::full(returned) => { trap; } + } + match std.heap.pop::(q) { + std.option.Option::::some(item) => { + let (priority,owner) = struct.unpack(move item); + assert(priority == 7u64); assert(own.take(move owner) == 42u64); + } + std.option.Option::::none => { trap; } + } + } + match std.heap.free::(move value) { + std.heap.FreeResult::::ok => {} + std.heap.FreeResult::::not_empty(returned) => { trap; } + } + return 42; +} diff --git a/examples/std/io.aji b/examples/std/io.aji new file mode 100644 index 0000000..7ca57a2 --- /dev/null +++ b/examples/std/io.aji @@ -0,0 +1,18 @@ +module demo.io +import std.io; + +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; + let output = fs.create(dst,b"/out/data") or trap; + var scratch: [u8;3] = [0u8;3]; + let count = match std.io.copy_file(mut input,mut output,mut scratch,42usize) { + std.io.CopyResult::eof(count) => { count }, + std.io.CopyResult::limit(count) => { count }, + std.io.CopyResult::err(error) => { + fs.close(move input) or trap; fs.close(move output) or trap; + return 0; + } + }; + fs.close(move input) or trap; fs.close(move output) or trap; + return count as! u64; +} diff --git a/examples/std/map.aji b/examples/std/map.aji new file mode 100644 index 0000000..c7c8ff5 --- /dev/null +++ b/examples/std/map.aji @@ -0,0 +1,30 @@ +module example.map +import std.map; +import std.option; +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.map.new::>(1, heap) { + std.map.NewResult::>::err(error) => { trap; } + std.map.NewResult::>::ok(map) => { + let owner = own.new(42u64, heap) or trap; + { mut q = map; + match std.map.insert::>(q, 7, move owner) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(old) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + } + var answer: u64 = 0; + { mut q = map; + match std.map.remove::>(q, 7) { + std.option.Option::>::none => { trap; } + std.option.Option::>::some(value) => { answer = own.take(move value); } + } + } + match std.map.free::>(move map) { + std.map.FreeResult::>::ok => {} + std.map.FreeResult::>::not_empty(returned) => { trap; } + } + return answer; + } + } +} diff --git a/examples/std/owning-option.aji b/examples/std/owning-option.aji new file mode 100644 index 0000000..56e5cf8 --- /dev/null +++ b/examples/std/owning-option.aji @@ -0,0 +1,12 @@ +module test.linear +import std.option; +fn replace(value: mut>>) -> std.option.Option> effects [] { + return value.swap(mut value, std.option.Option::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + var value: std.option.Option> = std.option.Option::>::some(move owner); + let old = replace(mut value); + match move value { std.option.Option::>::none => {}, std.option.Option::>::some(extra) => { own.free(move extra); } } + match move old { std.option.Option::>::some(part) => { return own.take(move part); } std.option.Option::>::none => { return 0; } } +} diff --git a/examples/std/path.aji b/examples/std/path.aji new file mode 100644 index 0000000..3efc552 --- /dev/null +++ b/examples/std/path.aji @@ -0,0 +1,21 @@ +module demo.path +import std.path; +import std.bytes; + +fn main() -> u64 effects [] { + var bytes: [u8;32] = [255u8;32]; + let count = match std.path.join(mut bytes,b"/data/sub",b"../file.tar") { + std.path.WriteResult::ok(count) => { count }, + std.path.WriteResult::invalid_input => { return 0; }, + std.path.WriteResult::size_overflow => { return 0; }, + std.path.WriteResult::short_output => { return 0; } + }; + { ref path = bytes[0usize..count]; + assert(std.bytes.equal(path,b"/data/file.tar")); + let base = std.path.basename(path); let parent = std.path.parent(path); let extension = std.path.extension(path); + assert(std.bytes.equal(ref path[base.start..base.end],b"file.tar")); + assert(std.bytes.equal(ref path[parent.start..parent.end],b"/data")); + assert(std.bytes.equal(ref path[extension.start..extension.end],b"tar")); + } + return 42; +} diff --git a/examples/std/static_functions.aji b/examples/std/static_functions.aji new file mode 100644 index 0000000..e6206a0 --- /dev/null +++ b/examples/std/static_functions.aji @@ -0,0 +1,6 @@ +module demo.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { + return F(move value); +} +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/examples/std/text.aji b/examples/std/text.aji new file mode 100644 index 0000000..16f6ced --- /dev/null +++ b/examples/std/text.aji @@ -0,0 +1,31 @@ +module demo.text +import std.bytes; +import std.encoding.hex; +import std.encoding.base64; +import std.utf8; + +fn main() -> u32 +effects [] +{ + var utf8: [u8; 3] = zero; + match std.encoding.hex.decode(mut utf8, b"E282AC") { + std.encoding.hex.DecodeResult::ok(count) => { assert(count == 3); } + std.encoding.hex.DecodeResult::invalid_input => { return 0; } + std.encoding.hex.DecodeResult::short_output => { return 0; } + } + match std.utf8.validate(ref utf8) { + std.utf8.ValidateResult::ok => {} + std.utf8.ValidateResult::invalid_input(offset) => { return 0; } + } + var encoded: [u8; 4] = zero; + match std.encoding.base64.encode(mut encoded, ref utf8) { + std.encoding.base64.EncodeResult::ok(count) => { assert(count == 4); } + std.encoding.base64.EncodeResult::short_output => { return 0; } + } + assert(std.bytes.equal(ref encoded, b"4oKs")); + match std.utf8.next(ref utf8) { + std.utf8.NextResult::ok(scalar, count) => { assert(count == 3); return scalar; } + std.utf8.NextResult::end => { return 0; } + std.utf8.NextResult::invalid_input => { return 0; } + } +} diff --git a/examples/std/vector.aji b/examples/std/vector.aji new file mode 100644 index 0000000..9dac2eb --- /dev/null +++ b/examples/std/vector.aji @@ -0,0 +1,37 @@ +module example.vector +import std.vec; +import std.option; + +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.vec.new::>(1, heap) { + std.vec.NewResult::>::ok(value) => { + let owner = own.new(42u64, heap) or trap; + { + mut v = value; + match std.vec.push::>(v, move owner) { + std.vec.PushResult::>::ok => {} + std.vec.PushResult::>::full(returned) => { + own.free(move returned); + trap; + } + } + } + var answer: u64 = 0; + { + mut v = value; + match std.vec.pop::>(v) { + std.option.Option::>::some(item) => { + answer = own.take(move item); + } + std.option.Option::>::none => { trap; } + } + } + match std.vec.free::>(move value) { + std.vec.FreeResult::>::ok => {} + std.vec.FreeResult::>::not_empty(returned) => { trap; } + } + return answer; + } + std.vec.NewResult::>::err(e) => { trap; } + } +} diff --git a/src/air/features.zig b/src/air/features.zig index 271c855..19d937e 100644 --- a/src/air/features.zig +++ b/src/air/features.zig @@ -31,10 +31,12 @@ pub const registry = [_]Feature{ .{ .name = "channel_transfer", .depends = &.{ "cancellation", "capabilities", "channels", "effects", "heap", "ownership", "resources", "tasks" }, .status = .reserved, .phase = null }, .{ .name = "channels", .depends = &.{ "cancellation", "capabilities", "effects", "heap", "ownership", "resources", "tasks" }, .status = .published, .phase = 3 }, .{ .name = "effects", .depends = &.{}, .status = .published, .phase = 2 }, + .{ .name = "error_values", .depends = &.{ "capabilities", "effects", "heap", "ownership", "resources" }, .status = .published, .phase = 6 }, .{ .name = "guard_transfer", .depends = &.{ "cancellation", "effects", "ownership", "sync", "tasks" }, .status = .reserved, .phase = null }, .{ .name = "heap", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .published, .phase = 2 }, .{ .name = "islands", .depends = &.{ "capabilities", "effects", "heap", "ownership", "resources" }, .status = .published, .phase = 4 }, - .{ .name = "linear_aggregates", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .reserved, .phase = null }, + .{ .name = "linear_aggregates", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .published, .phase = 6 }, + .{ .name = "linear_buffers", .depends = &.{ "arrays", "capabilities", "effects", "heap", "linear_aggregates", "ownership", "resources" }, .status = .published, .phase = 6 }, .{ .name = "ownership", .depends = &.{}, .status = .published, .phase = 1 }, .{ .name = "receiver_dup", .depends = &.{ "cancellation", "capabilities", "channels", "effects", "heap", "ownership", "resources", "tasks" }, .status = .reserved, .phase = null }, .{ .name = "regions", .depends = &.{ "capabilities", "effects", "heap", "ownership", "resources" }, .status = .published, .phase = 2 }, @@ -49,7 +51,7 @@ pub const registry = [_]Feature{ }; /// Features implemented by this toolchain, sorted. -pub const supported = [_][]const u8{ "arc", "arrays", "atomics", "cancellation", "capabilities", "channels", "effects", "heap", "islands", "ownership", "regions", "resources", "sync", "tasks", "unsafe" }; +pub const supported = [_][]const u8{ "arc", "arrays", "atomics", "cancellation", "capabilities", "channels", "effects", "error_values", "heap", "islands", "linear_aggregates", "linear_buffers", "ownership", "regions", "resources", "sync", "tasks", "unsafe" }; pub const Reason = enum { unknown_feature, diff --git a/src/air/module.zig b/src/air/module.zig index e8b10d3..c3e6b85 100644 --- a/src/air/module.zig +++ b/src/air/module.zig @@ -82,6 +82,7 @@ pub const Type = union(enum) { // Features `heap` and `regions` (spec 03 §18–§20). own: *const Type, own_array: *const Type, + buffer: *const Type, region, // Feature `tasks` (spec 04 §33). scope, @@ -109,7 +110,7 @@ pub const Type = union(enum) { return switch (a) { .int => |x| b.int == x, .named => |x| b.named == x, - .local, .ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.eql(b.inner().?), + .local, .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.eql(b.inner().?), .region, .scope, .shield => true, .array => |x| x.len == b.array.len and x.elem.eql(b.array.elem), .cap => |k| b.cap == k, @@ -122,7 +123,7 @@ pub const Type = union(enum) { /// Element or pointee type of storage, borrow and slice types. pub fn inner(t: Type) ?Type { return switch (t) { - .local, .ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.*, + .local, .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.*, .array => |a| a.elem, else => null, }; @@ -139,7 +140,7 @@ pub const Type = union(enum) { /// Linear values: consumed exactly once (spec 06 §6.2–§6.3). pub fn isLinear(t: Type) bool { return switch (t) { - .resource, .own, .own_array, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .atomic => true, + .resource, .own, .own_array, .buffer, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .atomic => true, else => false, }; } @@ -173,7 +174,7 @@ pub const Type = union(enum) { /// Linear resources are neither values nor borrows: they are moved. pub fn isValue(t: Type) bool { return switch (t) { - .void, .never, .local, .ref, .mut, .slice, .slice_mut, .resource, .own, .own_array, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .atomic => false, + .void, .never, .local, .ref, .mut, .slice, .slice_mut, .resource, .own, .own_array, .buffer, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .atomic => false, else => true, }; } @@ -290,6 +291,9 @@ pub const Op = union(enum) { store: struct { borrow: ValueId, value: ValueId }, // Feature `arrays`. array_splat: struct { ty: Type, value: ValueId }, + array_make: struct { ty: Type, args: []const ValueId }, + aggregate_unpack: struct { ty: Type, value: ValueId, next: u32 }, + value_swap: struct { borrow: ValueId, value: ValueId }, borrow_index: struct { borrow: ValueId, index: ValueId, proven: bool, unchecked: bool = false }, slice_make: ValueId, slice_len: ValueId, @@ -302,6 +306,8 @@ pub const Op = union(enum) { assume: ValueId, @"const": struct { ty: Type, bits: u128 }, + /// Pure built-in error data (feature error_values, spec 05 §14). + error_const: struct { which: authority.Builtin, variant: u32 }, copy: ValueId, arith: struct { op: ArithOp, mode: ArithMode, ty: IntType, a: ValueId, b: ValueId }, bit: struct { op: BitOp, ty: Type, a: ValueId, b: ValueId }, @@ -318,6 +324,7 @@ pub const Op = union(enum) { @"switch": struct { ty: IntType, value: ValueId, cases: []const Case, default: Target }, /// `ty` is a declared enum (`.named`) or a built-in enum (`.builtin`). enum_switch: struct { ty: Type, value: ValueId, arms: []const Arm, default: ?Target }, + enum_take: struct { ty: Type, value: ValueId, arms: []const Arm, default: ?Target }, /// Fallible narrowing (spec 05 §10.4): continues at `ok` with the new /// capability or at `err` with a `cap_error`, as block parameters. cap_narrow: struct { form: []const u8, cap: ValueId, args: []const ValueId, ok: u32, err: u32 }, @@ -327,6 +334,7 @@ pub const Op = union(enum) { // Features `heap` and `regions` (spec 03 §19–§20). Allocations are // fallible terminators delivering to `ok`/`err` block parameters. own_new: struct { value: ValueId, cap: ValueId, ok: u32, err: u32 }, + own_pack: struct { ty: Type, value: ValueId, cap: ValueId, ok: u32, err: u32 }, own_array: struct { n: ValueId, value: ValueId, cap: ValueId, ok: u32, err: u32 }, own_take: ValueId, own_free: ValueId, @@ -335,6 +343,15 @@ pub const Op = union(enum) { region_array: struct { region: ValueId, n: ValueId, value: ValueId, ok: u32, err: u32 }, region_reset: ValueId, region_destroy: ValueId, + // Feature linear_buffers (spec 03 §26). + buffer_new: struct { ty: Type, n: ValueId, cap: ValueId, ok: u32, err: u32 }, + buffer_len: ValueId, + buffer_capacity: ValueId, + buffer_view: ValueId, + buffer_reserve: struct { borrow: ValueId, n: ValueId, cap: ValueId, ok: u32, err: u32 }, + buffer_push: struct { borrow: ValueId, value: ValueId, ok: u32, err: u32 }, + buffer_pop: struct { value: ValueId, ok: u32, err: u32 }, + buffer_free: struct { value: ValueId, ok: u32, err: u32 }, // Feature `tasks` (spec 04 §33). task_scope_begin, task_spawn: struct { scope: ValueId, callee: u32, args: []const ValueId }, @@ -408,10 +425,18 @@ pub const Op = union(enum) { return buf[0..n]; } - pub fn isTerminator(op: Op) bool { + pub fn bufferTargets(op: Op) ?struct { ok: u32, err: u32 } { return switch (op) { - .br, .cbr, .@"switch", .enum_switch, .cap_narrow, .ret, .trap => true, - .own_new, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => true, + inline .buffer_new, .buffer_reserve, .buffer_push, .buffer_pop, .buffer_free => |x| .{ .ok = x.ok, .err = x.err }, + else => null, + }; + } + + pub fn isTerminator(op: Op) bool { + if (op.bufferTargets() != null) return true; + return switch (op) { + inline .br, .cbr, .@"switch", .enum_switch, .enum_take, .aggregate_unpack, .cap_narrow, .ret, .trap => true, + inline .own_new, .own_pack, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => true, .task_check_cancel, .task_join_cancel, .channel_make, .channel_send, .channel_recv, .channel_close_receiver, .select, .mutex_lock => true, .intrinsic => |x| x.ok != null, else => false, @@ -461,6 +486,24 @@ pub const Module = struct { return false; } + /// Whole-value linearity; well-formed nominal ownership graphs are acyclic. + pub fn isLinearType(m: Module, t: Type) bool { + if (t.isLinear()) return true; + return switch (t) { + .array => |a| m.isLinearType(a.elem), + .named => |i| switch (m.types[i].kind) { + .@"struct" => |fs| for (fs) |f| { + if (m.isLinearType(f.ty)) break true; + } else false, + .@"enum" => |vs| blk: { + for (vs) |v| for (v.payload) |p| if (m.isLinearType(p)) break :blk true; + break :blk false; + }, + }, + else => false, + }; + } + /// Variant names and payloads of a declared or built-in enum type. pub fn variantCount(m: Module, t: Type) usize { return switch (t) { @@ -503,7 +546,22 @@ pub const Module = struct { /// of terminators are included. pub fn forEachUse(op: Op, ctx: anytype, comptime f: fn (@TypeOf(ctx), ValueId) void) void { switch (op) { - .@"const", .trap => {}, + .buffer_new => |x| { + f(ctx, x.n); + f(ctx, x.cap); + }, + .buffer_reserve => |x| { + f(ctx, x.borrow); + f(ctx, x.n); + f(ctx, x.cap); + }, + .buffer_push => |x| { + f(ctx, x.borrow); + f(ctx, x.value); + }, + inline .buffer_pop, .buffer_free => |x| f(ctx, x.value), + .buffer_len, .buffer_capacity, .buffer_view => |v| f(ctx, v), + .@"const", .error_const, .trap => {}, .copy, .assert => |v| f(ctx, v), .arith => |x| { f(ctx, x.a); @@ -533,7 +591,7 @@ pub fn forEachUse(op: Op, ctx: anytype, comptime f: fn (@TypeOf(ctx), ValueId) v for (x.cases) |c| for (c.target.args) |v| f(ctx, v); for (x.default.args) |v| f(ctx, v); }, - .enum_switch => |x| { + inline .enum_switch, .enum_take => |x| { f(ctx, x.value); if (x.default) |d| for (d.args) |v| f(ctx, v); }, @@ -542,7 +600,7 @@ pub fn forEachUse(op: Op, ctx: anytype, comptime f: fn (@TypeOf(ctx), ValueId) v for (x.args) |v| f(ctx, v); }, .intrinsic => |x| for (x.args) |v| f(ctx, v), - .own_new => |x| { + inline .own_new, .own_pack => |x| { f(ctx, x.value); f(ctx, x.cap); }, @@ -630,6 +688,12 @@ pub fn forEachUse(op: Op, ctx: anytype, comptime f: fn (@TypeOf(ctx), ValueId) v f(ctx, x.value); }, .array_splat => |x| f(ctx, x.value), + .array_make => |x| for (x.args) |v| f(ctx, v), + .aggregate_unpack => |x| f(ctx, x.value), + .value_swap => |x| { + f(ctx, x.borrow); + f(ctx, x.value); + }, .borrow_index => |x| { f(ctx, x.borrow); f(ctx, x.index); @@ -654,12 +718,17 @@ pub fn forEachUse(op: Op, ctx: anytype, comptime f: fn (@TypeOf(ctx), ValueId) v /// `ok`/`err` targets of a fallible allocation terminator. pub fn allocTargets(op: Op) ?struct { ok: u32, err: u32 } { return switch (op) { - inline .own_new, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => |x| .{ .ok = x.ok, .err = x.err }, + inline .own_new, .own_pack, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => |x| .{ .ok = x.ok, .err = x.err }, else => null, }; } pub fn successors(op: Op, buf: *std.ArrayList(u32), gpa: std.mem.Allocator) std.mem.Allocator.Error!void { + if (op.bufferTargets()) |t| { + try buf.append(gpa, t.ok); + try buf.append(gpa, t.err); + return; + } switch (op) { .br => |t| try buf.append(gpa, t.block), .cbr => |x| { @@ -670,10 +739,11 @@ pub fn successors(op: Op, buf: *std.ArrayList(u32), gpa: std.mem.Allocator) std. for (x.cases) |c| try buf.append(gpa, c.target.block); try buf.append(gpa, x.default.block); }, - .enum_switch => |x| { + inline .enum_switch, .enum_take => |x| { for (x.arms) |a| try buf.append(gpa, a.block); if (x.default) |d| try buf.append(gpa, d.block); }, + .aggregate_unpack => |x| try buf.append(gpa, x.next), .cap_narrow => |x| { try buf.append(gpa, x.ok); try buf.append(gpa, x.err); @@ -682,7 +752,7 @@ pub fn successors(op: Op, buf: *std.ArrayList(u32), gpa: std.mem.Allocator) std. try buf.append(gpa, ok); try buf.append(gpa, x.err.?); }, - inline .own_new, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => |x| { + inline .own_new, .own_pack, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => |x| { try buf.append(gpa, x.ok); try buf.append(gpa, x.err); }, diff --git a/src/air/parse.zig b/src/air/parse.zig index 4e4c9ff..a10d22d 100644 --- a/src/air/parse.zig +++ b/src/air/parse.zig @@ -560,7 +560,7 @@ const Parser = struct { boxed.* = inner; return if (eql(t.text, "own")) .{ .own = boxed } else .{ .own_array = boxed }; } - const Wrapper = enum { task, sender, receiver, mutex, guard, island, frozen, arc, iref, atomic }; + const Wrapper = enum { task, sender, receiver, mutex, guard, island, frozen, arc, iref, atomic, buffer }; if (std.meta.stringToEnum(Wrapper, t.text)) |which| { try p.requireFeature(switch (which) { .task => "tasks", @@ -569,6 +569,7 @@ const Parser = struct { .island, .frozen, .iref => "islands", .arc => "arc", .atomic => "atomics", + .buffer => "linear_buffers", }, t.span, t.text); _ = try p.expect(.lt, "`<`"); // Element rules (spec 04 §38.1) are checked by the type stage. @@ -587,6 +588,7 @@ const Parser = struct { .arc => .{ .arc = boxed }, .iref => .{ .iref = boxed }, .atomic => .{ .atomic = boxed }, + .buffer => .{ .buffer = boxed }, }; } if (eql(t.text, "cap")) { @@ -640,7 +642,7 @@ const Parser = struct { }; } - /// Resources inside aggregates need the reserved feature `linear_aggregates`. + /// Resources inside aggregates need the feature `linear_aggregates`. fn gateLinearMember(p: *Parser, t: air.Type, span: Span) Error!void { if (t == .guard) return p.requireFeature("guard_transfer", span, "lock guard as a member"); if (t.isTaskBound()) return p.requireFeature("task_transfer", span, "task handle or scope as a member"); @@ -871,6 +873,20 @@ const Parser = struct { const head = parts[0]; const op: air.Op = op: { + if (eql(op_tok.text, "error.const")) { + try p.requireFeature("error_values", op_tok.span, op_tok.text); + const t = try p.expect(.word, "built-in error family and variant"); + const dot = std.mem.indexOfScalar(u8, t.text, '.') orelse return p.fail(t, "`B.variant`"); + const b = std.meta.stringToEnum(authority.Builtin, t.text[0..dot]) orelse { + try p.report("E0004", t.span, "unknown built-in error family", &.{.{ .name = "name", .value = .{ .str = t.text[0..dot] } }}); + return error.SyntaxError; + }; + const variant = b.variantIndex(t.text[dot + 1 ..]) orelse { + try p.report("E0004", t.span, "unknown built-in error variant", &.{.{ .name = "name", .value = .{ .str = t.text[dot + 1 ..] } }}); + return error.SyntaxError; + }; + break :op .{ .error_const = .{ .which = b, .variant = variant } }; + } if (eql(head, "const") and parts.len == 2) { if (eql(parts[1], "bool")) { const lit = try p.expect(.word, "`true` or `false`"); @@ -909,6 +925,59 @@ const Parser = struct { const it = std.meta.stringToEnum(air.IntType, parts[2]) orelse return p.unknownOpcode(op_tok); break :op .{ .cast = .{ .mode = mode, .to = it, .a = try p.useValue() } }; } + if (std.mem.startsWith(u8, op_tok.text, "buffer.")) { + try p.requireFeature("linear_buffers", op_tok.span, op_tok.text); + const Name = enum { new, len, capacity, view, reserve, push, pop, free }; + const name = std.meta.stringToEnum(Name, op_tok.text[7..]) orelse return p.unknownOpcode(op_tok); + switch (name) { + .new => { + const ty = try p.parseType(); + const n, const cap = try p.twoOperands(); + const ok, const err = try p.okErr(); + break :op .{ .buffer_new = .{ .ty = ty, .n = n, .cap = cap, .ok = ok, .err = err } }; + }, + .len => break :op .{ .buffer_len = try p.useValue() }, + .capacity => break :op .{ .buffer_capacity = try p.useValue() }, + .view => break :op .{ .buffer_view = try p.useValue() }, + .reserve => { + const borrow, const n = try p.twoOperands(); + _ = try p.expect(.comma, "`,`"); + const cap = try p.useValue(); + const ok, const err = try p.okErr(); + break :op .{ .buffer_reserve = .{ .borrow = borrow, .n = n, .cap = cap, .ok = ok, .err = err } }; + }, + .push => { + const borrow, const value = try p.twoOperands(); + const ok, const err = try p.okErr(); + break :op .{ .buffer_push = .{ .borrow = borrow, .value = value, .ok = ok, .err = err } }; + }, + .pop, .free => { + const value = try p.useValue(); + const ok, const err = try p.okErr(); + break :op if (name == .pop) .{ .buffer_pop = .{ .value = value, .ok = ok, .err = err } } else .{ .buffer_free = .{ .value = value, .ok = ok, .err = err } }; + }, + } + } + if (eql(op_tok.text, "array.make")) { + try p.requireFeature("linear_aggregates", op_tok.span, op_tok.text); + const ty = try p.parseType(); + break :op .{ .array_make = .{ .ty = ty, .args = try p.valueList() } }; + } + if (eql(op_tok.text, "struct.unpack") or eql(op_tok.text, "array.unpack")) { + try p.requireFeature("linear_aggregates", op_tok.span, op_tok.text); + const ty: air.Type = if (eql(op_tok.text, "struct.unpack")) .{ .named = try p.typeRef(.@"struct") } else try p.parseType(); + if (eql(op_tok.text, "array.unpack") and ty != .array) try p.report("E1001", op_tok.span, "array.unpack requires an array type", &.{}); + const v = try p.useValue(); + _ = try p.expect(.comma, "`,`"); + _ = try p.expectWord("next"); + _ = try p.expect(.arrow, "`->`"); + break :op .{ .aggregate_unpack = .{ .ty = ty, .value = v, .next = try p.blockRef() } }; + } + if (eql(op_tok.text, "value.swap")) { + try p.requireFeature("linear_aggregates", op_tok.span, op_tok.text); + const a, const b = try p.twoOperands(); + break :op .{ .value_swap = .{ .borrow = a, .value = b } }; + } if (eql(op_tok.text, "struct.make")) { const decl = try p.typeRef(.@"struct"); break :op .{ .struct_make = .{ .decl = decl, .args = try p.valueList() } }; @@ -962,7 +1031,9 @@ const Parser = struct { _ = try p.expect(.arrow, "`->`"); break :op .{ .@"switch" = .{ .ty = it, .value = value, .cases = cases.items, .default = try p.target() } }; } - if (eql(op_tok.text, "enum.switch")) { + if (eql(op_tok.text, "enum.switch") or eql(op_tok.text, "enum.take")) { + const taking = eql(op_tok.text, "enum.take"); + if (taking) try p.requireFeature("linear_aggregates", op_tok.span, op_tok.text); // A declared enum (`@E`) or a built-in enum (`cap_error`). const ety: air.Type = if (p.peek().tag == .word) blk: { const t = p.next(); @@ -990,7 +1061,7 @@ const Parser = struct { const blk = try p.blockRef(); try arms.append(p.arena, .{ .variant = variant, .block = blk, .span = span }); } - break :op .{ .enum_switch = .{ .ty = ety, .value = value, .arms = arms.items, .default = default } }; + break :op if (taking) .{ .enum_take = .{ .ty = ety, .value = value, .arms = arms.items, .default = default } } else .{ .enum_switch = .{ .ty = ety, .value = value, .arms = arms.items, .default = default } }; } if (eql(op_tok.text, "ret")) { break :op .{ .ret = if (p.peek().tag == .local) try p.useValue() else null }; @@ -1053,9 +1124,9 @@ const Parser = struct { .task_shield_begin, .channel_dup, .mutex_make, .mutex_take, .mutex_borrow => true, .island_root, .island_borrow, .island_freeze, .frozen_root, .frozen_borrow, .arc_from_frozen, .arc_clone, .arc_root, .arc_borrow, .iref_eq => true, .atomic_new, .atomic_take, .atomic_load, .atomic_rmw, .atomic_cmpxchg => true, - .@"const", .copy, .arith, .bit, .cmp, .cast, .struct_make, .struct_get, .enum_make => true, + .@"const", .error_const, .copy, .arith, .bit, .cmp, .cast, .struct_make, .struct_get, .enum_make => true, .local_alloc, .local_load, .borrow_ref, .borrow_mut, .borrow_field, .load => true, - .array_splat, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split => true, + .buffer_len, .buffer_capacity, .buffer_view, .array_splat, .array_make, .value_swap, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split => true, else => false, }; const may_bind = produces_value or op == .call or op == .intrinsic or op == .task_join; @@ -1333,14 +1404,16 @@ const Parser = struct { /// Instructions of the features `heap` and `regions` (spec 03 §19–§20). fn parseAllocOp(p: *Parser, op_tok: Token) Error!?air.Op { - const Name = enum { @"own.new", @"own.array", @"own.take", @"own.free", @"region.create", @"region.new", @"region.array", @"region.reset", @"region.destroy" }; + const Name = enum { @"own.new", @"own.pack", @"own.array", @"own.take", @"own.free", @"region.create", @"region.new", @"region.array", @"region.reset", @"region.destroy" }; const name = std.meta.stringToEnum(Name, op_tok.text) orelse return null; try p.requireFeature(if (std.mem.startsWith(u8, op_tok.text, "own.")) "heap" else "regions", op_tok.span, op_tok.text); switch (name) { - .@"own.new" => { + .@"own.new", .@"own.pack" => { + if (name == .@"own.pack") try p.requireFeature("linear_aggregates", op_tok.span, op_tok.text); + const pack_ty: air.Type = if (name == .@"own.pack") try p.parseType() else .void; const v, const c = try p.twoOperands(); const ok, const err = try p.okErr(); - return .{ .own_new = .{ .value = v, .cap = c, .ok = ok, .err = err } }; + return if (name == .@"own.pack") .{ .own_pack = .{ .ty = pack_ty, .value = v, .cap = c, .ok = ok, .err = err } } else .{ .own_new = .{ .value = v, .cap = c, .ok = ok, .err = err } }; }, .@"own.array" => { const n, const v = try p.twoOperands(); diff --git a/src/air/print.zig b/src/air/print.zig index 5e31fde..bc66c06 100644 --- a/src/air/print.zig +++ b/src/air/print.zig @@ -115,7 +115,7 @@ pub fn printType(m: air.Module, t: air.Type, w: *Writer) Writer.Error!void { .cap => |k| try w.print("cap<{s}>", .{air.authority.kinds[k].name}), .builtin => |b| try w.writeAll(@tagName(b)), .resource => |r| try w.writeAll(r.text()), - .own, .own_array => |inner| { + .own, .own_array, .buffer => |inner| { try w.print("{s}<", .{@tagName(t)}); try printType(m, inner.*, w); try w.writeByte('>'); @@ -179,6 +179,7 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error! }, else => unreachable, }, + .error_const => |x| try w.print("error.const {s}.{s}", .{ @tagName(x.which), x.which.variants()[x.variant] }), .copy => |v| { try w.writeAll("copy "); try value(f, v, w); @@ -209,6 +210,19 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error! try w.print("cast.{s}.{s} ", .{ @tagName(x.mode), @tagName(x.to) }); try value(f, x.a, w); }, + .array_make => |x| { + try w.writeAll("array.make "); + try printType(m, x.ty, w); + try values(f, x.args, w); + }, + .aggregate_unpack => |x| { + try w.writeAll(if (x.ty == .array) "array.unpack " else "struct.unpack "); + try printType(m, x.ty, w); + try w.writeByte(' '); + try value(f, x.value, w); + try w.print(", next -> @{s}", .{f.blocks[x.next].name}); + }, + .value_swap => |x| try two(f, w, "value.swap", x.borrow, x.value), .struct_make => |x| { try w.print("struct.make @{s}", .{m.types[x.decl].name}); try values(f, x.args, w); @@ -251,8 +265,8 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error! try w.writeAll(", default -> "); try target(f, x.default, w); }, - .enum_switch => |x| { - try w.writeAll("enum.switch "); + inline .enum_switch, .enum_take => |x| { + try w.writeAll(if (op == .enum_take) "enum.take " else "enum.switch "); try printType(m, x.ty, w); try w.writeByte(' '); try value(f, x.value, w); @@ -310,8 +324,39 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error! try values(f, x.args, w); if (x.ok) |ok| try w.print(", ok -> @{s}, err -> @{s}", .{ f.blocks[ok].name, f.blocks[x.err.?].name }); }, - .own_new => |x| { - try two(f, w, "own.new", x.value, x.cap); + .buffer_new => |x| { + try w.writeAll("buffer.new "); + try printType(m, x.ty, w); + try w.print(" %{s}, %{s}", .{ f.values[x.n].name, f.values[x.cap].name }); + try okErr(f, w, x.ok, x.err); + }, + inline .buffer_len, .buffer_capacity, .buffer_view => |v, tag| try one(f, w, switch (tag) { + .buffer_len => "buffer.len", + .buffer_capacity => "buffer.capacity", + .buffer_view => "buffer.view", + else => unreachable, + }, v), + .buffer_reserve => |x| { + try w.print("buffer.reserve %{s}, %{s}, %{s}", .{ f.values[x.borrow].name, f.values[x.n].name, f.values[x.cap].name }); + try okErr(f, w, x.ok, x.err); + }, + .buffer_push => |x| { + try two(f, w, "buffer.push", x.borrow, x.value); + try okErr(f, w, x.ok, x.err); + }, + inline .buffer_pop, .buffer_free => |x, tag| { + try one(f, w, if (tag == .buffer_pop) "buffer.pop" else "buffer.free", x.value); + try okErr(f, w, x.ok, x.err); + }, + inline .own_new, .own_pack => |x, tag| { + if (tag == .own_pack) { + try w.writeAll("own.pack "); + try printType(m, x.ty, w); + try w.writeByte(' '); + try value(f, x.value, w); + try w.writeAll(", "); + try value(f, x.cap, w); + } else try two(f, w, "own.new", x.value, x.cap); try okErr(f, w, x.ok, x.err); }, .own_array => |x| { @@ -635,3 +680,103 @@ test "round-trip of ownership and arrays forms" { \\ ); } + +test "round-trip whole-value linear operations" { + try roundTrip( + \\module test.linear + \\air 0 + \\lang 0.1 + \\features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] + \\type @Maybe = enum { some(own), none } + \\fn @main(%heap: cap) -> u64 + \\effects [mem.alloc] + \\entry: + \\ %n = const.u64 42 + \\ own.pack u64 %n, %heap, ok -> @got, err -> @failed + \\got(%owner: own): + \\ %items = array.make array,1>(%owner) + \\ array.unpack array,1> %items, next -> @element + \\element(%part: own): + \\ %slot = enum.make @Maybe.some(%part) + \\ %empty = enum.make @Maybe.none() + \\ %borrow = borrow.mut %slot + \\ %old = value.swap %borrow, %empty + \\ borrow.end %borrow + \\ enum.take @Maybe %slot, some -> @extra, none -> @replaced + \\extra(%extra_owner: own): + \\ own.free %extra_owner + \\ enum.take @Maybe %old, some -> @answer, none -> @no_answer + \\replaced: + \\ enum.take @Maybe %old, some -> @answer, none -> @no_answer + \\answer(%answer_owner: own): + \\ %value = own.take %answer_owner + \\ ret %value + \\no_answer: + \\ ret %n + \\failed(%e: alloc_error, %original: u64): + \\ ret %n + ); +} + +test "round-trip explicit error values" { + try roundTrip( + \\module test.errors + \\air 0 + \\lang 0.1 + \\features [resources, ownership, heap, error_values, effects, capabilities] + \\fn @main() -> alloc_error + \\effects [] + \\entry: + \\ %io = error.const io_error.invalid_input + \\ %cap = error.const cap_error.not_subset + \\ %e = error.const alloc_error.budget_exceeded + \\ ret %e + ); +} + +test "round-trip initialized buffers" { + try roundTrip( + \\module test.buffers + \\ air 0 + \\ lang 0.1 + \\ features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] + \\fn @main(%heap: cap) -> u64 + \\effects [mem.alloc] + \\entry: + \\ %capacity = const.usize 1 + \\ %n = const.u64 42 + \\ buffer.new own %capacity, %heap, ok -> @made, err -> @failed + \\made(%data: buffer>): + \\ own.new %n, %heap, ok -> @owned, err -> @owner_failed + \\owned(%owner: own): + \\ %b = borrow.mut %data + \\ buffer.push %b, %owner, ok -> @pushed, err -> @full + \\full(%returned: own): + \\ trap + \\pushed: + \\ %next_capacity = const.usize 2 + \\ buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed + \\grown: + \\ %length = buffer.len %b + \\ %capacity_after = buffer.capacity %b + \\ %view = buffer.view %b + \\ borrow.end %view + \\ buffer.pop %b, ok -> @popped, err -> @empty + \\popped(%part: own): + \\ %answer = own.take %part + \\ borrow.end %b + \\ buffer.free %data, ok -> @done, err -> @nonempty + \\nonempty(%original: buffer>): + \\ trap + \\done: + \\ ret %answer + \\empty: + \\ trap + \\failed(%error: alloc_error): + \\ trap + \\owner_failed(%owner_error: alloc_error): + \\ trap + \\reserve_failed(%reserve_error: alloc_error): + \\ trap + ); +} diff --git a/src/check.zig b/src/check.zig index 67bd137..d551a1d 100644 --- a/src/check.zig +++ b/src/check.zig @@ -30,8 +30,12 @@ pub const Report = struct { /// Checks a `.aji` module (frontend, then the AIR pipeline, with every /// diagnostic at its source location) or a text AIR module. pub fn checkFile(arena: std.mem.Allocator, file_name: []const u8, source: []const u8) !Report { + return checkWithModules(arena, file_name, source, &.{}); +} + +pub fn checkWithModules(arena: std.mem.Allocator, file_name: []const u8, source: []const u8, sources: []const frontend.modules.Source) !Report { if (!std.mem.endsWith(u8, file_name, ".aji")) return checkAir(arena, file_name, source); - const lowered = switch (try frontend.compile(arena, file_name, source)) { + const lowered = switch (try frontend.compileWithModules(arena, file_name, source, sources)) { .ok => |o| o, .err => |d| return .{ .status = .rejected, .diagnostics = try arena.dupe(diag.Diagnostic, &.{d}) }, .unimplemented => |what| return .{ .status = .unimplemented, .diagnostics = &.{}, .missing_stage = what }, @@ -73,7 +77,7 @@ pub fn checkLowered(arena: std.mem.Allocator, file_name: []const u8, lowered: fr for (r.diagnostics) |d| { const m = try frontend.mapDiagnostic(arena, d, file_name, lowered.lines); const dup = for (mapped.items) |prev| { - if (prev.code == m.code and prev.span.?.line == m.span.?.line and prev.span.?.col == m.span.?.col) break true; + if (prev.code == m.code and std.mem.eql(u8, prev.span.?.file, m.span.?.file) and prev.span.?.line == m.span.?.line and prev.span.?.col == m.span.?.col) break true; } else false; if (!dup) try mapped.append(arena, m); } @@ -109,3 +113,179 @@ test "malformed lowered AIR is an internal compiler error" { try std.testing.expectEqualStrings("E0001", d.fields[0].value.str); try std.testing.expect(d.span.?.line == 5 or d.span.?.line == 4); } + +test "standard imports lower identically in either order" { + var a = std.heap.ArenaAllocator.init(std.testing.allocator); + defer a.deinit(); + const arena = a.allocator(); + const body = "fn main() -> u64\neffects []\n{ return std.math.min_u64(7, 11); }\n"; + const first = try checkFile(arena, "a.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.math;\nimport std.bytes;\nimport std.utf8;\nimport std.fmt;\nimport std.encoding.hex;\nimport std.encoding.base64;\n", body })); + const second = try checkFile(arena, "/another/directory/b.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.encoding.base64;\nimport std.encoding.hex;\nimport std.bytes;\nimport std.math;\nimport std.fmt;\nimport std.utf8;\n", body })); + try std.testing.expectEqual(Status.accepted, first.status); + try std.testing.expectEqual(Status.accepted, second.status); + try std.testing.expectEqualStrings(first.lowered.?.air, second.lowered.?.air); + // Imported code enters the ordinary verifier with its original locations. + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/bytes.aji:") != null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/utf8.aji:") != null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/fmt.aji:") != null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/encoding/hex.aji:") != null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/encoding/base64.aji:") != null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "intrinsic ") == null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "own.") == null); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "cap<") == null); +} + +test "standard source provenance maps diagnostics to the library file" { + var a = std.heap.ArenaAllocator.init(std.testing.allocator); + defer a.deinit(); + const arena = a.allocator(); + const report = try checkFile(arena, "client.aji", "module t\nimport std.math;\nfn main() -> u64\neffects []\n{ return std.math.clamp_u64(5, 9, 4); }\n"); + try std.testing.expectEqual(Status.accepted, report.status); + const lowered = report.lowered.?; + const assertion = std.mem.indexOf(u8, lowered.air, " assert ").?; + const line: u32 = @intCast(std.mem.count(u8, lowered.air[0..assertion], "\n") + 1); + const d = try frontend.mapDiagnostic(arena, .{ + .code = diag.lookup("E2101").?, + .span = .{ .file = "client.aji", .line = line, .col = 5 }, + .message = "test mapping", + }, "client.aji", lowered.lines); + try std.testing.expectEqualStrings("std/math.aji", d.span.?.file); + try std.testing.expectEqual(@as(u32, 20), d.span.?.line); +} + +test "standard type diagnostics use the public source name" { + var a = std.heap.ArenaAllocator.init(std.testing.allocator); + defer a.deinit(); + const arena = a.allocator(); + const cases = [_]struct { body: []const u8, found: []const u8 }{ + .{ .body = "let value: u16 = std.bytes.read_u16_le(b\"xx\");", .found = "std.bytes.ReadU16" }, + .{ .body = "let values = [std.bytes.ReadU16::ok(42); 2]; let value: [u16; 2] = values;", .found = "array" }, + }; + for (cases) |case| { + const source = try std.fmt.allocPrint(arena, "module t\nimport std.bytes;\nfn main() -> u8\neffects []\n{{ {s} return 0; }}\n", .{case.body}); + const report = try checkFile(arena, "client.aji", source); + try std.testing.expectEqual(Status.rejected, report.status); + try std.testing.expectEqualStrings("E7005", report.diagnostics[0].code.id); + const found = for (report.diagnostics[0].fields) |field| { + if (std.mem.eql(u8, field.name, "found")) break field.value.str; + } else return error.TestUnexpectedResult; + try std.testing.expectEqualStrings(case.found, found); + } +} + +test "package module order, nominal names and diagnostic paths are independent" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const a: frontend.modules.Source = .{ .name = "app.a", .file = "same.aji", .source = "module app.a\nstruct Pair { value: u64 }\nfn value(p: Pair) -> u64 effects [] { return p.value; }\n" }; + const b: frontend.modules.Source = .{ .name = "app.b", .file = "same.aji", .source = "module app.b\nimport app.a;\nfn value() -> u64 effects [] { return app.a.value(app.a.Pair { value: 42 }); }\n" }; + const body = "fn main() -> u64 effects [] { return app.b.value(); }\n"; + const first = try checkWithModules(arena, "root.aji", "module app.entry\nimport app.a;\nimport app.b;\n" ++ body, &.{ a, b }); + const second = try checkWithModules(arena, "/elsewhere/root.aji", "module app.entry\nimport app.b;\nimport app.a;\n" ++ body, &.{ b, a }); + try std.testing.expectEqual(Status.accepted, first.status); + try std.testing.expectEqual(Status.accepted, second.status); + try std.testing.expectEqualStrings(first.lowered.?.air, second.lowered.?.air); + try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; same.aji:") != null); + const bad = try checkWithModules(arena, "root.aji", "module app.entry\nimport app.b;\nfn main() -> u64 effects [] { let p: app.a.Pair = app.a.Pair { value: 42 }; return 0; }", &.{ a, b }); + try std.testing.expectEqualStrings("E7002", bad.diagnostics[0].code.id); +} + +test "module syntax and verifier errors retain imported source provenance" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const root = "module app.entry\nimport app.lib;\nfn main() -> u64 effects [] { return 42; }"; + const syntax = try checkWithModules(arena, "entry.aji", root, &.{.{ .name = "app.lib", .file = "src/lib.aji", .source = "module app.lib\nfn broken(" }}); + try std.testing.expectEqualStrings("E7001", syntax.diagnostics[0].code.id); + try std.testing.expectEqualStrings("src/lib.aji", syntax.diagnostics[0].span.?.file); + try std.testing.expectEqualStrings("expected", syntax.diagnostics[0].fields[0].name); + const alias = try checkWithModules(arena, "entry.aji", root, &.{.{ .name = "app.lib", .file = "src/lib.aji", .source = "module app.lib\nfn broken() -> u8 effects [] { var b: [u8; 4] = zero; ref held = b; b[0] = 1; return held[0]; }" }}); + try std.testing.expectEqualStrings("E2101", alias.diagnostics[0].code.id); + try std.testing.expectEqualStrings("src/lib.aji", alias.diagnostics[0].span.?.file); +} + +test "module graph depth is bounded even with a cached shared tail" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + var sources: std.ArrayList(frontend.modules.Source) = .empty; + for (0..257) |i| { + const name = try std.fmt.allocPrint(arena, "app.m{d}", .{i}); + const source = if (i == 256) try std.fmt.allocPrint(arena, "module {s}\n", .{name}) else try std.fmt.allocPrint(arena, "module {s}\nimport app.m{d};\n", .{ name, i + 1 }); + try sources.append(arena, .{ .name = name, .file = name, .source = source }); + } + const prefix = "module app.entry\nimport app.m200;\nimport app.m0;\nfn main() -> u64 effects [] { return 42; }"; + const excessive = try checkWithModules(arena, "root.aji", prefix, sources.items); + try std.testing.expectEqualStrings("E7006", excessive.diagnostics[0].code.id); + const valid = try checkWithModules(arena, "root.aji", "module app.entry\nimport app.m1;\nfn main() -> u64 effects [] { return 42; }", sources.items); + try std.testing.expectEqual(Status.accepted, valid.status); + const many = try arena.alloc(frontend.modules.Source, 1025); + @memset(many, sources.items[0]); + const limited = try checkWithModules(arena, "root.aji", prefix, many); + try std.testing.expectEqualStrings("E7006", limited.diagnostics[0].code.id); +} + +test "qualified module names are not limited by builtin path storage" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const component = try arena.alloc(u8, 300); + @memset(component, 'a'); + const name = try std.fmt.allocPrint(arena, "app.{s}", .{component}); + const source = try std.fmt.allocPrint(arena, "module {s}\nstruct Pair {{ value: u64 }}\nfn total(p: Pair) -> u64 effects [] {{ return p.value; }}", .{name}); + const entry = try std.fmt.allocPrint(arena, "module app.entry\nimport {s};\nfn main() -> u64 effects [] {{ return {s}.total({s}.Pair {{ value: 42 }}); }}", .{ name, name, name }); + const checked = try checkWithModules(arena, "root.aji", entry, &.{.{ .name = name, .file = "lib.aji", .source = source }}); + try std.testing.expectEqual(Status.accepted, checked.status); +} + +test "generic specialization deduplicates nominal keys independent of module order and provenance" { + var state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer state.deinit(); + const arena = state.allocator(); + const lib: frontend.modules.Source = .{ .name = "app.lib", .file = "lib.aji", .source = "module app.lib\nfn id(value: T) -> T effects [] { return value; }" }; + const prefix = "module app.entry\n"; + const body = "struct Pair { value: u64 }\nfn main() -> u64 effects [] { let p = app.lib.id::(Pair { value: 42 }); let a = app.lib.id::(p.value); return app.lib.id::(a); }"; + const first = try checkWithModules(arena, "entry.aji", prefix ++ "import app.lib;\nimport std.option;\n" ++ body, &.{lib}); + var moved = lib; + moved.file = "elsewhere/lib.aji"; + const second_source = try std.mem.replaceOwned(u8, arena, prefix ++ "import std.option;\nimport app.lib;\n" ++ body, "id::", "id::"); + const second = try checkWithModules(arena, "elsewhere/entry.aji", second_source, &.{moved}); + try std.testing.expectEqual(Status.accepted, first.status); + try std.testing.expectEqual(Status.accepted, second.status); + try std.testing.expectEqualStrings(first.lowered.?.air, second.lowered.?.air); + try std.testing.expectEqual(@as(usize, 3), first.module.?.functions.len); + try std.testing.expectEqual(@as(usize, 1), first.module.?.types.len); + const bad = try checkWithModules(arena, "entry.aji", prefix ++ "import app.lib;\nfn main() -> u64 effects [] { return app.lib.id::>(0); }", &.{lib}); + try std.testing.expectEqualStrings("E7005", bad.diagnostics[0].code.id); + try std.testing.expectEqualStrings("constraint", bad.diagnostics[0].fields[1].name); + const provenance = try checkWithModules(arena, "entry.aji", prefix ++ "import app.lib;\nfn main() -> u64 effects [] { return app.lib.id::(42); }", &.{.{ .name = "app.lib", .file = "lib.aji", .source = "module app.lib\nfn id(value: T) -> T effects [] { return missing(value); }" }}); + try std.testing.expectEqualStrings("lib.aji", provenance.diagnostics[0].span.?.file); +} + +test "generic specialization count and parameter limits reject before lowering" { + var state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer state.deinit(); + const arena = state.allocator(); + var source: std.ArrayList(u8) = .empty; + try source.appendSlice(arena, "module app.entry\nfn marker() -> u64 effects [] { return 0; }\nfn main() -> u64 effects [] {\n"); + for (1..4098) |n| try source.appendSlice(arena, try std.fmt.allocPrint(arena, "marker::<[u8; {d}]>();\n", .{n})); + try source.appendSlice(arena, "return 42; }"); + const result = try frontend.compile(arena, "limit.aji", source.items); + try std.testing.expect(result == .err); + try std.testing.expectEqualStrings("E7006", result.err.code.id); + const params = try frontend.compile(arena, "limit.aji", "module app.entry\nfn marker() -> u64 effects [] { return 0; }\nfn main() -> u64 effects [] { return 42; }"); + try std.testing.expectEqualStrings("E7006", params.err.code.id); +} + +test "generic AIR names avoid source collisions and diagnostic names stay readable" { + var state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer state.deinit(); + const arena = state.allocator(); + const source = "module app.entry\nfn id(value: T) -> T effects [] { return value; }\nfn __aji_g_65d38d1a36ba3736939a86561ed8e7371f3c6dcce26722dd7876102d750f7052() -> u64 effects [] { return 0; }\nfn main() -> u64 effects [] { return id::(42); }"; + const result = try checkFile(arena, "collision.aji", source); + try std.testing.expectEqual(Status.accepted, result.status); + try std.testing.expect(std.mem.indexOf(u8, result.lowered.?.air, "call @__aji_g_65d38d1a36ba3736939a86561ed8e7371f3c6dcce26722dd7876102d750f7052_1(") != null); + const arity = try checkFile(arena, "arity.aji", "module app.entry\nfn id(value: T) -> T effects [] { return value; }\nfn main() -> u64 effects [] { return id::(); }"); + try std.testing.expectEqualStrings("E7005", arity.diagnostics[0].code.id); + try std.testing.expectEqualStrings("app.entry.id", arity.diagnostics[0].fields[0].value.str); +} diff --git a/src/frontend.zig b/src/frontend.zig index 24aa0d3..2f87cf2 100644 --- a/src/frontend.zig +++ b/src/frontend.zig @@ -8,6 +8,9 @@ pub const lex = @import("frontend/lex.zig"); pub const ast = @import("frontend/ast.zig"); pub const parse = @import("frontend/parse.zig"); pub const lower_mod = @import("frontend/lower.zig"); +pub const generics = @import("frontend/generics.zig"); +pub const modules = @import("frontend/modules.zig"); +pub const stdlib = @import("frontend/stdlib.zig"); pub const Span = ast.Span; @@ -20,6 +23,10 @@ pub const Compiled = union(enum) { }; pub fn compile(arena: std.mem.Allocator, file: []const u8, source: []const u8) std.mem.Allocator.Error!Compiled { + return compileWithModules(arena, file, source, &.{}); +} + +pub fn compileWithModules(arena: std.mem.Allocator, file: []const u8, source: []const u8, sources: []const modules.Source) std.mem.Allocator.Error!Compiled { const parsed = try parse.parse(arena, source); const m = switch (parsed) { .ok => |m| m, @@ -33,19 +40,27 @@ pub fn compile(arena: std.mem.Allocator, file: []const u8, source: []const u8) s }), } }, }; - return switch (try lower_mod.lower(arena, m)) { + const linked = try modules.link(arena, m, sources); + const result = switch (linked) { + .ok => |combined| switch (try generics.specialize(arena, combined)) { + .ok => |concrete| try lower_mod.lower(arena, concrete), + .err => |p| lower_mod.Result{ .err = p }, + }, + .err => |p| lower_mod.Result{ .err = p }, + }; + return switch (result) { .ok => |o| .{ .ok = o }, .err => |p| blk: { const fields = try arena.alloc(diag.Field, p.fields.len); for (p.fields, fields) |pf, *f| f.* = .{ .name = pf.name, .value = .{ .str = pf.value } }; break :blk .{ .err = .{ .code = diag.lookup(p.code).?, - .span = .{ .file = file, .line = p.span.start.line, .col = p.span.start.col }, + .span = .{ .file = p.span.file orelse file, .line = p.span.start.line, .col = p.span.start.col }, .message = p.message, .fields = fields, } }; }, - .unimplemented => |u| .{ .unimplemented = try std.fmt.allocPrint(arena, "{s}:{d}:{d}: {s}", .{ file, u.span.start.line, u.span.start.col, u.construct }) }, + .unimplemented => |u| .{ .unimplemented = try std.fmt.allocPrint(arena, "{s}:{d}:{d}: {s}", .{ u.span.file orelse file, u.span.start.line, u.span.start.col, u.construct }) }, }; } @@ -60,7 +75,7 @@ pub fn mapDiagnostic(arena: std.mem.Allocator, d: diag.Diagnostic, file: []const fields[d.fields.len + 1] = .{ .name = "air_col", .value = .{ .int = sp.col } }; out.fields = fields; const src: ?Span = if (sp.line >= 1 and sp.line <= lines.len) lines[sp.line - 1] else null; - out.span = .{ .file = file, .line = if (src) |s| s.start.line else 1, .col = if (src) |s| s.start.col else 1 }; + out.span = .{ .file = if (src) |s| s.file orelse file else file, .line = if (src) |s| s.start.line else 1, .col = if (src) |s| s.start.col else 1 }; return out; } diff --git a/src/frontend/ast.zig b/src/frontend/ast.zig index 350d769..050421c 100644 --- a/src/frontend/ast.zig +++ b/src/frontend/ast.zig @@ -6,13 +6,16 @@ const lex = @import("lex.zig"); pub const Pos = lex.Pos; -pub const Span = struct { start: Pos, end: Pos }; +pub const Span = struct { start: Pos, end: Pos, file: ?[]const u8 = null, namespace: ?[]const u8 = null, resolved: bool = false }; pub const Type = struct { span: Span, kind: union(enum) { /// A built-in or declared type name (`u8`, `bool`, `region`, `Pair`). name: []const u8, + applied: struct { name: []const u8, args: []const Type }, + /// Static generic argument, never a runtime type (spec 15 §18). + function_ref: struct { name: []const u8, args: []const Type = &.{} }, /// `[T; N]`. array: struct { elem: *const Type, len: u64 }, /// `ref`, `own`, `sender`, … (`wrapper` names the constructor). @@ -54,6 +57,8 @@ pub const CastMode = enum { widen, checked, wrap }; pub const Expr = struct { span: Span, + /// Complete Copy transfer is admitted only in a specialized template body. + generic_transfer: bool = false, kind: Kind, pub const Kind = union(enum) { @@ -62,7 +67,8 @@ pub const Expr = struct { bytes: []const u8, name: []const u8, /// `Enum::Variant` (applied to payload arguments by a `call`). - variant: struct { @"enum": []const u8, name: []const u8 }, + variant: struct { @"enum": []const u8, name: []const u8, type_args: []const Type = &.{} }, + specialize: struct { base: *const Expr, args: []const Type }, neg: *const Expr, not: *const Expr, deref: *const Expr, @@ -70,13 +76,14 @@ pub const Expr = struct { move: []const u8, binary: struct { op: BinOp, l: *const Expr, r: *const Expr }, cast: struct { mode: CastMode, e: *const Expr, ty: Type }, - /// `callee(args)`; `type_arg` only for `channel.make`. + /// `callee(args)`; `type_arg` for `channel.make` / `buffer.new`. call: struct { callee: *const Expr, type_arg: ?Type, args: []const Expr }, field: struct { e: *const Expr, name: []const u8 }, /// `e[lo]` or `e[lo..hi]`. index: struct { e: *const Expr, lo: *const Expr, hi: ?*const Expr }, - struct_lit: struct { name: []const u8, fields: []const FieldInit }, + struct_lit: struct { name: []const u8, fields: []const FieldInit, type_args: []const Type = &.{} }, array_rep: struct { e: *const Expr, len: u64 }, + array_list: []const Expr, or_trap: *const Expr, if_expr: *const If, match_expr: *const Match, @@ -97,7 +104,7 @@ pub const Pattern = struct { int: []const u8, /// A variant with its enum (`Shape::Rect(w, h)`) or an outcome /// (`ok(n)`, `closed`; `qualifier == null`), with bound names. - ctor: struct { qualifier: ?[]const u8, name: []const u8, binds: []const []const u8 }, + ctor: struct { qualifier: ?[]const u8, name: []const u8, binds: []const []const u8, type_args: []const Type = &.{} }, }, }; @@ -139,7 +146,7 @@ pub const Select = struct { pub const Stmt = struct { span: Span, kind: union(enum) { - let: struct { names: []const []const u8, ty: ?Type, e: Expr }, + let: struct { names: []const []const u8, ty: ?Type, e: Expr, tuple: bool = false }, /// `init == null` is `= zero`. @"var": struct { name: []const u8, ty: Type, init: ?Expr }, assign: struct { place: Expr, e: Expr }, @@ -166,8 +173,16 @@ pub const Field = struct { name: []const u8, ty: Type, span: Span }; pub const Variant = struct { name: []const u8, payload: []const Type, span: Span }; +pub const FunctionContract = struct { params: []const Type, ret: Type, effects: []const []const u8 }; +pub const TypeParam = struct { name: []const u8, constraints: []const []const u8, span: Span, callable: ?*const FunctionContract = null }; +pub const Requirement = struct { ty: Type, parameter: []const u8, property: []const u8, span: Span }; + pub const TypeDecl = struct { + generics: []const TypeParam = &.{}, name: []const u8, + /// Linker-chosen AIR identifier for a qualified imported type. + air_name: ?[]const u8 = null, + display_name: ?[]const u8 = null, span: Span, kind: union(enum) { @"struct": []const Field, @"enum": []const Variant }, }; @@ -175,7 +190,11 @@ pub const TypeDecl = struct { pub const Param = struct { name: []const u8, ty: Type, span: Span }; pub const FnDecl = struct { + generics: []const TypeParam = &.{}, name: []const u8, + /// Linker-chosen AIR identifier for a qualified imported function. + air_name: ?[]const u8 = null, + display_name: ?[]const u8 = null, span: Span, params: []const Param, ret: Type, @@ -187,6 +206,14 @@ pub const FnDecl = struct { pub const Module = struct { name: []const u8, + imports: []const Import = &.{}, + scopes: []const ModuleScope = &.{}, + requirements: []const Requirement = &.{}, types: []const TypeDecl, functions: []const FnDecl, }; + +pub const Import = struct { path: []const u8, span: Span }; + +/// Source name resolution stays separate from diagnostic file paths. +pub const ModuleScope = struct { name: []const u8, entry: bool, qualified_self: bool = true, imports: []const Import }; diff --git a/src/frontend/generics.zig b/src/frontend/generics.zig new file mode 100644 index 0000000..d18df8f --- /dev/null +++ b/src/frontend/generics.zig @@ -0,0 +1,638 @@ +//! Explicit, bounded monomorphization before ordinary AIR lowering. +const std = @import("std"); +const ast = @import("ast.zig"); +const lower = @import("lower.zig"); +const authority = @import("../air/authority.zig"); +const A = std.mem.Allocator; +const Error = error{ OutOfMemory, InvalidGeneric }; +pub const Result = union(enum) { ok: ast.Module, err: lower.Problem }; +const Env = struct { params: []const ast.TypeParam = &.{}, args: []const ast.Type = &.{} }; +const Instance = struct { key: []const u8, name: []const u8, air_name: []const u8, signature: ?ast.FnDecl = null, decl: union(enum) { pending, ty: ast.TypeDecl, function: ast.FnDecl } = .pending }; + +pub fn specialize(arena: A, module: ast.Module) A.Error!Result { + var g: Generator = .{ .arena = arena, .m = module }; + const out = g.run() catch |err| switch (err) { + error.OutOfMemory => return error.OutOfMemory, + error.InvalidGeneric => return .{ .err = g.problem.? }, + }; + return .{ .ok = out }; +} + +const Generator = struct { + arena: A, + m: ast.Module, + instances: std.ArrayList(Instance) = .empty, + requirements: std.ArrayList(ast.Requirement) = .empty, + depth: usize = 0, + type_depth: usize = 0, + problem: ?lower.Problem = null, + + fn fail(g: *Generator, code: []const u8, span: ast.Span, message: []const u8, name: []const u8) Error { + g.problem = .{ .code = code, .span = span, .message = message, .fields = try g.arena.dupe(lower.Problem.Field, &.{.{ .name = "name", .value = name }}) }; + return error.InvalidGeneric; + } + + fn bound(g: *Generator, name: []const u8, span: ast.Span) ?[]const u8 { + if (span.resolved) return name; + const origin = span.namespace orelse g.m.name; + for (g.m.scopes) |scope| if (std.mem.eql(u8, scope.name, origin)) { + if (std.mem.lastIndexOfScalar(u8, name, '.')) |at| { + const owner = name[0..at]; + if (std.mem.eql(u8, owner, origin)) return if (!scope.qualified_self) null else if (scope.entry) name[at + 1 ..] else name; + for (scope.imports) |imp| if (std.mem.eql(u8, imp.path, owner)) return name; + return null; + } + if (scope.entry) return name; + for (g.m.types) |t| if (local(t.name, origin, name)) return t.name; + for (g.m.functions) |f| if (local(f.name, origin, name)) return f.name; + return null; + }; + return name; + } + + fn typeDecl(g: *Generator, name: []const u8, span: ast.Span) ?ast.TypeDecl { + const n = g.bound(name, span) orelse return null; + for (g.m.types) |t| if (std.mem.eql(u8, t.name, n)) return t; + return null; + } + fn function(g: *Generator, name: []const u8, span: ast.Span) ?ast.FnDecl { + const n = g.bound(name, span) orelse return null; + for (g.m.functions) |f| if (std.mem.eql(u8, f.name, n)) return f; + return null; + } + + fn checkBinding(g: *Generator, name: []const u8, span: ast.Span, env: Env) Error!void { + for (env.params) |p| if (p.callable != null and std.mem.eql(u8, p.name, name)) return g.fail("E7006", span, "runtime binding shadows a static function parameter", name); + } + + fn boundFunction(env: Env, name: []const u8) ?ast.Type { + for (env.params, env.args) |p, arg| if (p.callable != null and std.mem.eql(u8, p.name, name)) return arg; + return null; + } + + fn functionArgument(g: *Generator, arg: ast.Type, env: Env) Error!ast.Type { + const f = arg.kind.function_ref; + var out = arg; + if (boundFunction(env, f.name)) |bound_arg| { + if (f.args.len != 0) return g.fail("E7006", arg.span, "bound static function cannot be specialized again", f.name); + out.kind = bound_arg.kind; + } else { + const target = g.function(f.name, arg.span) orelse return g.fail("E7002", arg.span, "unknown or inaccessible static function", f.name); + const name = if (target.generics.len != 0) + try g.instantiate(false, target, f.args, env, arg.span) + else blk: { + if (f.args.len != 0) return g.fail("E7006", arg.span, "non-generic function does not take static arguments", f.name); + break :blk target.name; + }; + out.kind = .{ .function_ref = .{ .name = name } }; + } + out.span.resolved = true; + return out; + } + + fn sameType(g: *Generator, a: ast.Type, b: ast.Type) Error!bool { + var left: std.ArrayList(u8) = .empty; + var right: std.ArrayList(u8) = .empty; + try g.identity(a, &left); + try g.identity(b, &right); + return std.mem.eql(u8, left.items, right.items); + } + + fn contractText(g: *Generator, contract: ast.FunctionContract, env: Env) Error![]const u8 { + var out: std.ArrayList(u8) = .empty; + try out.appendSlice(g.arena, "fn("); + for (contract.params, 0..) |p, i| { + if (i != 0) try out.append(g.arena, ','); + try g.identity(try g.ty(p, env), &out); + } + try out.appendSlice(g.arena, ") -> "); + try g.identity(try g.ty(contract.ret, env), &out); + try out.appendSlice(g.arena, " effects ["); + for (contract.effects, 0..) |effect, i| { + if (i != 0) try out.append(g.arena, ','); + try out.appendSlice(g.arena, effect); + } + try out.append(g.arena, ']'); + return out.items; + } + + fn functionMismatch(g: *Generator, parameter: []const u8, contract: ast.FunctionContract, selected: ast.FnDecl, arg: ast.Type, env: Env, message: []const u8) Error { + const params = try g.arena.alloc(ast.Type, selected.params.len); + for (selected.params, params) |p, *t| t.* = p.ty; + g.problem = .{ .code = "E7005", .span = arg.span, .message = message, .fields = try g.arena.dupe(lower.Problem.Field, &.{ + .{ .name = "parameter", .value = parameter }, + .{ .name = "function", .value = selected.display_name orelse selected.name }, + .{ .name = "expected", .value = try g.contractText(contract, env) }, + .{ .name = "found", .value = try g.contractText(.{ .params = params, .ret = selected.ret, .effects = selected.effects }, .{}) }, + }) }; + return error.InvalidGeneric; + } + + fn checkFunctionArgument(g: *Generator, parameter: []const u8, contract: ast.FunctionContract, arg: ast.Type, env: Env) Error!void { + const name = arg.kind.function_ref.name; + const selected = if (g.function(name, arg.span)) |f| f else blk: { + for (g.instances.items) |instance| if (std.mem.eql(u8, instance.name, name)) { + break :blk instance.signature orelse return g.fail("E7006", arg.span, "cyclic static function contract resolution", parameter); + }; + return g.fail("E7002", arg.span, "unknown static function specialization", name); + }; + if (selected.params.len != contract.params.len or selected.from != null) return g.functionMismatch(parameter, contract, selected, arg, env, "static function parameter count or return contract mismatch"); + for (contract.params, selected.params) |expected, actual| { + if (!try g.sameType(try g.ty(expected, env), try g.ty(actual.ty, .{}))) return g.functionMismatch(parameter, contract, selected, arg, env, "static function parameter type mismatch"); + } + if (!try g.sameType(try g.ty(contract.ret, env), try g.ty(selected.ret, .{}))) return g.functionMismatch(parameter, contract, selected, arg, env, "static function return type mismatch"); + if (selected.effects.len != contract.effects.len) return g.functionMismatch(parameter, contract, selected, arg, env, "static function effect set mismatch"); + for (contract.effects) |expected| { + for (selected.effects) |actual| { + if (std.mem.eql(u8, expected, actual)) break; + } else return g.functionMismatch(parameter, contract, selected, arg, env, "static function effect set mismatch"); + } + } + + fn validate(g: *Generator, name: []const u8, params: []const ast.TypeParam, span: ast.Span) Error!void { + if (params.len > 8) return g.fail("E7006", span, "generic declaration limit or generic entry", name); + for (params, 0..) |p, i| { + if (!std.ascii.isUpper(p.name[0]) or g.typeDecl(p.name, p.span) != null or builtin(p.name)) return g.fail("E7006", p.span, "type parameter must be uppercase and not shadow a visible type", p.name); + for (params[0..i]) |previous| if (std.mem.eql(u8, p.name, previous.name)) return g.fail("E7006", p.span, "duplicate type parameter", p.name); + if (p.callable) |c| { + if (p.constraints.len != 0 or g.function(p.name, p.span) != null) return g.fail("E7006", p.span, "invalid static function parameter", p.name); + for (c.params) |t| try g.headerType(t, params, 0); + try g.headerType(c.ret, params, 0); + if (c.ret.kind == .wrapped) { + const w = c.ret.kind.wrapped.wrapper; + if (std.mem.eql(u8, w, "ref") or std.mem.eql(u8, w, "mut") or std.mem.eql(u8, w, "slice") or std.mem.eql(u8, w, "slice_mut")) return g.fail("E7006", c.ret.span, "static function contracts do not support borrowed returns", p.name); + } + for (c.effects, 0..) |effect, j| { + if (authority.effectIndex(effect) == null) return g.fail("E0006", p.span, "unknown effect in static function contract", effect); + for (c.effects[0..j]) |prev| if (std.mem.eql(u8, prev, effect)) return g.fail("E7006", p.span, "duplicate effect in static function contract", effect); + } + } + for (p.constraints, 0..) |c, j| { + if (std.meta.stringToEnum(Property, c) == null) return g.fail("E7006", p.span, "unknown structural constraint", c); + for (p.constraints[0..j]) |previous| if (std.mem.eql(u8, c, previous)) return g.fail("E7006", p.span, "duplicate structural constraint", c); + } + } + } + + fn headerType(g: *Generator, t: ast.Type, params: []const ast.TypeParam, depth: usize) Error!void { + if (depth >= 64) return g.fail("E7006", t.span, "type traversal exceeds depth 64", "type"); + switch (t.kind) { + .name => |n| { + for (params) |p| if (std.mem.eql(u8, n, p.name)) { + if (p.callable != null) return g.fail("E7006", t.span, "static function parameter is not a type", n); + return; + }; + if (g.typeDecl(n, t.span)) |d| { + if (d.generics.len != 0) return g.fail("E7006", t.span, "template type needs explicit arguments", n); + } else if (!builtin(n)) return g.fail("E7002", t.span, "unknown template signature type", n); + }, + .applied => |x| { + const d = g.typeDecl(x.name, t.span) orelse return g.fail("E7002", t.span, "unknown template signature type", x.name); + if (d.generics.len == 0 or d.generics.len != x.args.len) return g.fail("E7006", t.span, "template type argument count mismatch", x.name); + for (d.generics, x.args) |p, arg| try g.headerArgument(p, arg, params, depth + 1); + }, + .array => |a| try g.headerType(a.elem.*, params, depth + 1), + .wrapped => |w| try g.headerType(w.inner.*, params, depth + 1), + .cap => |k| if (authority.kindIndex(k) == null) return g.fail("E7002", t.span, "unknown capability kind", k), + .file => |mode| if (!(std.mem.eql(u8, mode, "read") or std.mem.eql(u8, mode, "write") or std.mem.eql(u8, mode, "append"))) return g.fail("E7002", t.span, "unknown file mode", mode), + .function_ref => return g.fail("E7006", t.span, "static functions are not runtime types", "fn"), + } + } + + fn headerArgument(g: *Generator, expected: ast.TypeParam, arg: ast.Type, params: []const ast.TypeParam, depth: usize) Error!void { + if (depth >= 64) return g.fail("E7006", arg.span, "generic argument traversal exceeds depth 64", expected.name); + if (expected.callable == null) { + if (arg.kind == .function_ref) return g.fail("E7005", arg.span, "expected a type argument, found a static function", expected.name); + return g.headerType(arg, params, depth); + } + if (arg.kind != .function_ref) return g.fail("E7005", arg.span, "expected an explicit static function argument", expected.name); + const f = arg.kind.function_ref; + for (params) |parameter| if (std.mem.eql(u8, parameter.name, f.name) and parameter.callable != null) { + if (f.args.len != 0) return g.fail("E7006", arg.span, "bound static function cannot be specialized again", f.name); + return; + }; + const target = g.function(f.name, arg.span) orelse return g.fail("E7002", arg.span, "unknown or inaccessible static function", f.name); + if (target.generics.len != f.args.len) return g.fail("E7006", arg.span, "static function argument count mismatch", f.name); + for (target.generics, f.args) |p, a| try g.headerArgument(p, a, params, depth + 1); + } + + fn run(g: *Generator) Error!ast.Module { + var generic = false; + for (g.m.types, 0..) |t, i| { + for (g.m.types[0..i]) |previous| if (std.mem.eql(u8, t.name, previous.name)) return g.fail("E7006", t.span, "type defined twice", t.name); + try g.validate(t.name, t.generics, t.span); + switch (t.kind) { + .@"struct" => |fs| for (fs, 0..) |f, j| { + for (fs[0..j]) |prev| if (std.mem.eql(u8, f.name, prev.name)) return g.fail("E7006", f.span, "duplicate template field", f.name); + }, + .@"enum" => |vs| { + if (vs.len == 0) return g.fail("E7006", t.span, "enum needs a variant", t.name); + for (vs, 0..) |v, j| for (vs[0..j]) |prev| if (std.mem.eql(u8, v.name, prev.name)) return g.fail("E7006", v.span, "duplicate template variant", v.name); + }, + } + if (t.generics.len != 0) switch (t.kind) { + .@"struct" => |fs| for (fs) |field| try g.headerType(field.ty, t.generics, 0), + .@"enum" => |vs| for (vs) |v| for (v.payload) |payload_type| try g.headerType(payload_type, t.generics, 0), + }; + generic = generic or t.generics.len != 0; + } + for (g.m.functions, 0..) |f, i| { + for (g.m.functions[0..i]) |previous| if (std.mem.eql(u8, f.name, previous.name)) return g.fail("E7006", f.span, "function defined twice", f.name); + if (f.generics.len != 0 and std.mem.eql(u8, f.name, "main")) return g.fail("E7006", f.span, "entry cannot be generic", f.name); + try g.validate(f.name, f.generics, f.span); + if (f.generics.len != 0) { + if (f.trusted != null) return g.fail("E7006", f.span, "trusted is not available in source templates", f.name); + for (f.effects) |effect| if (authority.effectIndex(effect) == null) return g.fail("E0006", f.span, "unknown effect in template contract", effect); + for (f.params, 0..) |p, j| { + try g.checkBinding(p.name, p.span, .{ .params = f.generics }); + for (f.params[0..j]) |prev| if (std.mem.eql(u8, p.name, prev.name)) return g.fail("E7006", p.span, "duplicate value parameter", p.name); + try g.headerType(p.ty, f.generics, 0); + } + try g.headerType(f.ret, f.generics, 0); + } + generic = generic or f.generics.len != 0; + } + if (!generic and !usesGenerics(ast.Module, g.m)) return g.m; + var types: std.ArrayList(ast.TypeDecl) = .empty; + var functions: std.ArrayList(ast.FnDecl) = .empty; + for (g.m.types) |t| if (t.generics.len == 0) try types.append(g.arena, try g.walk(ast.TypeDecl, t, .{})); + for (g.m.functions) |f| if (f.generics.len == 0) try functions.append(g.arena, try g.walk(ast.FnDecl, f, .{})); + std.mem.sort(Instance, g.instances.items, {}, struct { + fn less(_: void, a: Instance, b: Instance) bool { + return std.mem.lessThan(u8, a.key, b.key); + } + }.less); + for (g.instances.items, 0..) |*instance, i| { + const base = instance.air_name; + var candidate = base; + var suffix: usize = 0; + while (g.originalAirUsed(candidate) or usedAir(g.instances.items[0..i], candidate)) { + suffix += 1; + candidate = try std.fmt.allocPrint(g.arena, "{s}_{d}", .{ base, suffix }); + } + instance.air_name = candidate; + switch (instance.decl) { + .ty => |*t| t.air_name = candidate, + .function => |*f| f.air_name = candidate, + .pending => unreachable, + } + } + for (g.instances.items) |instance| switch (instance.decl) { + .ty => |t| try types.append(g.arena, t), + .function => |f| try functions.append(g.arena, f), + .pending => unreachable, + }; + var out = g.m; + out.types = types.items; + out.functions = functions.items; + out.requirements = g.requirements.items; + return out; + } + + fn instantiate(g: *Generator, comptime is_type: bool, template: if (is_type) ast.TypeDecl else ast.FnDecl, raw: []const ast.Type, env: Env, span: ast.Span) Error![]const u8 { + if (g.depth >= 64) return g.fail("E7006", span, "generic argument or contract resolution exceeds depth 64", template.name); + g.depth += 1; + defer g.depth -= 1; + if (template.generics.len == 0 or template.generics.len != raw.len) return g.fail("E7006", span, "explicit type argument count does not match declaration", template.name); + const args = try g.arena.alloc(ast.Type, raw.len); + var key: std.ArrayList(u8) = .empty; + try key.appendSlice(g.arena, if (is_type) "type:" else "fn:"); + const owner = template.span.namespace orelse g.m.name; + if (std.mem.indexOfScalar(u8, template.name, '.') == null) try key.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{owner})); + try key.appendSlice(g.arena, template.name); + try key.append(g.arena, '<'); + for (template.generics, raw, args, 0..) |p, arg, *out, i| { + if (p.callable != null) { + if (arg.kind != .function_ref) return g.fail("E7005", arg.span, "expected an explicit static function argument", p.name); + out.* = try g.functionArgument(arg, env); + } else { + if (arg.kind == .function_ref) return g.fail("E7005", arg.span, "expected a type argument, found a static function", p.name); + out.* = try g.ty(arg, env); + } + if (out.kind == .name and (std.mem.eql(u8, out.kind.name, "void") or std.mem.eql(u8, out.kind.name, "never"))) return g.fail("E7005", span, "generic arguments must be concrete non-void types", template.name); + if (i != 0) try key.append(g.arena, ','); + try g.identity(out.*, &key); + } + try key.append(g.arena, '>'); + if (key.items.len > 16384) return g.fail("E7006", span, "canonical specialization key exceeds 16384 bytes", template.name); + for (g.instances.items) |instance| if (std.mem.eql(u8, instance.key, key.items)) return instance.name; + if (g.instances.items.len >= 4096) return g.fail("E7006", span, "generic specialization exceeds fixed compiler limit", template.name); + const hex = try g.arena.alloc(u8, key.items.len * 2); + for (key.items, 0..) |b, i| { + hex[2 * i] = "0123456789abcdef"[b >> 4]; + hex[2 * i + 1] = "0123456789abcdef"[b & 15]; + } + const base = try std.fmt.allocPrint(g.arena, "__aji_g_{s}", .{hex}); + var air_name: []const u8 = base; + var suffix: usize = 0; + while (g.airUsed(air_name)) { + suffix += 1; + air_name = try std.fmt.allocPrint(g.arena, "{s}_{d}", .{ base, suffix }); + } + const name = if (std.mem.eql(u8, owner, g.m.name)) air_name else try std.fmt.allocPrint(g.arena, "{s}.{s}", .{ owner, air_name }); + var digest: [32]u8 = undefined; + std.crypto.hash.sha2.Sha256.hash(key.items, &digest, .{}); + const digest_hex = try g.arena.alloc(u8, 64); + for (digest, 0..) |b, i| { + digest_hex[2 * i] = "0123456789abcdef"[b >> 4]; + digest_hex[2 * i + 1] = "0123456789abcdef"[b & 15]; + } + const final_air = try std.fmt.allocPrint(g.arena, "__aji_g_{s}", .{digest_hex}); + const index = g.instances.items.len; + try g.instances.append(g.arena, .{ .key = key.items, .name = name, .air_name = final_air }); + const concrete_env: Env = .{ .params = template.generics, .args = args }; + if (!is_type) { + var signature = template; + signature.params = try g.walk([]const ast.Param, template.params, concrete_env); + signature.ret = try g.ty(template.ret, concrete_env); + signature.generics = &.{}; + signature.name = name; + g.instances.items[index].signature = signature; + } + for (template.generics, args) |p, arg| { + if (p.callable) |c| { + try g.checkFunctionArgument(p.name, c.*, arg, concrete_env); + } else try g.requirements.append(g.arena, .{ .ty = arg, .parameter = p.name, .property = "", .span = span }); + } + for (template.generics, args) |p, arg| for (p.constraints) |property| try g.requirements.append(g.arena, .{ .ty = arg, .parameter = p.name, .property = property, .span = span }); + var body_template = template; + body_template.generics = &.{}; + var concrete = try g.walk(@TypeOf(template), body_template, concrete_env); + concrete.generics = &.{}; + concrete.name = name; + concrete.air_name = final_air; + concrete.display_name = key.items[if (is_type) 5 else 3..]; + g.instances.items[index].decl = if (is_type) .{ .ty = concrete } else .{ .function = concrete }; + return name; + } + + fn airUsed(g: *Generator, name: []const u8) bool { + for (g.m.types) |t| if (std.mem.eql(u8, t.air_name orelse t.name, name) or std.mem.eql(u8, t.name, name) or std.mem.eql(u8, shortName(t.name), name)) return true; + for (g.m.functions) |f| if (std.mem.eql(u8, f.air_name orelse f.name, name) or std.mem.eql(u8, f.name, name) or std.mem.eql(u8, shortName(f.name), name)) return true; + for (g.instances.items) |instance| if (std.mem.eql(u8, shortName(instance.name), name)) return true; + return false; + } + + fn originalAirUsed(g: *Generator, name: []const u8) bool { + for (g.m.types) |t| if (std.mem.eql(u8, t.air_name orelse t.name, name)) return true; + for (g.m.functions) |f| if (std.mem.eql(u8, f.air_name orelse f.name, name)) return true; + return false; + } + fn instanceTypeKey(g: *Generator, name: []const u8) ?[]const u8 { + for (g.instances.items) |instance| if (std.mem.eql(u8, instance.name, name) and std.mem.startsWith(u8, instance.key, "type:")) return instance.key; + return null; + } + + fn identity(g: *Generator, t: ast.Type, out: *std.ArrayList(u8)) Error!void { + switch (t.kind) { + .name => |name| { + if (g.typeDecl(name, t.span)) |d| { + if (std.mem.indexOfScalar(u8, d.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name})); + try out.appendSlice(g.arena, d.name); + } else if (g.instanceTypeKey(name)) |key| { + try out.appendSlice(g.arena, key[5..]); + } else try out.appendSlice(g.arena, name); + }, + .array => |a| { + try out.appendSlice(g.arena, "["); + try g.identity(a.elem.*, out); + try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, ";{d}]", .{a.len})); + }, + .wrapped => |w| { + try out.appendSlice(g.arena, w.wrapper); + try out.append(g.arena, '<'); + try g.identity(w.inner.*, out); + try out.append(g.arena, '>'); + }, + .cap => |k| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "cap<{s}>", .{k})), + .file => |mode| try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "file<{s}>", .{mode})), + .applied => unreachable, + .function_ref => |f| { + try out.appendSlice(g.arena, "fn "); + const instance_key = for (g.instances.items) |instance| { + if (std.mem.eql(u8, instance.name, f.name)) break instance.key; + } else null; + if (instance_key) |key| { + try out.appendSlice(g.arena, key[3..]); + } else { + if (std.mem.indexOfScalar(u8, f.name, '.') == null) try out.appendSlice(g.arena, try std.fmt.allocPrint(g.arena, "{s}.", .{g.m.name})); + try out.appendSlice(g.arena, f.name); + } + }, + } + if (out.items.len > 16384) return g.fail("E7006", t.span, "canonical specialization key exceeds 16384 bytes", "type"); + } + + fn named(g: *Generator, name: []const u8, args: []const ast.Type, span: ast.Span, env: Env) Error!ast.Type { + return g.ty(.{ .span = span, .kind = if (args.len == 0) .{ .name = name } else .{ .applied = .{ .name = name, .args = args } } }, env); + } + + fn ty(g: *Generator, input: ast.Type, env: Env) Error!ast.Type { + if (g.type_depth >= 64) return g.fail("E7006", input.span, "structural type depth exceeds 64", "type"); + g.type_depth += 1; + defer g.type_depth -= 1; + var t = input; + switch (input.kind) { + .name => |name| { + for (env.params, env.args) |p, arg| if (std.mem.eql(u8, name, p.name)) { + if (p.callable != null) return g.fail("E7006", input.span, "static function parameter is not a type", name); + return arg; + }; + if (g.typeDecl(name, input.span)) |d| { + if (d.generics.len != 0) return g.fail("E7006", input.span, "generic type needs explicit arguments", name); + t.kind.name = d.name; + t.span.resolved = true; + } else if (!builtin(name) and !g.generated(name)) return g.fail("E7002", input.span, "unknown or inaccessible type", name); + }, + .applied => |x| { + const d = g.typeDecl(x.name, input.span) orelse return g.fail("E7002", input.span, "unknown or inaccessible generic type", x.name); + t.kind = .{ .name = try g.instantiate(true, d, x.args, env, input.span) }; + t.span.resolved = true; + }, + .array => |a| t.kind.array.elem = try g.box(ast.Type, try g.ty(a.elem.*, env)), + .wrapped => |w| t.kind.wrapped.inner = try g.box(ast.Type, try g.ty(w.inner.*, env)), + .cap, .file => {}, + .function_ref => return g.fail("E7006", input.span, "static functions are not runtime types", "fn"), + } + return t; + } + + fn generated(g: *Generator, name: []const u8) bool { + for (g.instances.items) |instance| if (std.mem.eql(u8, instance.name, name)) return true; + return false; + } + + fn expression(g: *Generator, e: ast.Expr, env: Env) Error!ast.Expr { + var out = e; + if (e.kind == .move and env.params.len != 0) out.generic_transfer = true; + switch (e.kind) { + .name => |name| if (boundFunction(env, name) != null) return g.fail("E7006", e.span, "static function parameter is only a call target or named worker", name), + .specialize => |x| { + const name = path(g.arena, x.base.*) catch return error.OutOfMemory; + if (name) |n| if (boundFunction(env, n) != null) return g.fail("E7006", e.span, "bound static function cannot be specialized again", n); + const d = g.function(name orelse return g.fail("E7006", e.span, "generic worker or call must be named", "function"), e.span) orelse return g.fail("E7002", e.span, "unknown or inaccessible generic function", name.?); + out.kind = .{ .name = try g.instantiate(false, d, x.args, env, e.span) }; + out.span.resolved = true; + return out; + }, + .call => |x| { + out.kind.call.type_arg = try g.walk(?ast.Type, x.type_arg, env); + const callee_name = try path(g.arena, x.callee.*); + if (callee_name) |name| if (boundFunction(env, name)) |arg| { + out.kind.call.callee = try g.box(ast.Expr, selectedExpr(x.callee.*, arg)); + out.kind.call.args = try g.walk([]const ast.Expr, x.args, env); + return out; + }; + if (x.callee.kind != .specialize and x.callee.kind != .variant) if (try path(g.arena, x.callee.*)) |name| if (g.function(name, x.callee.span)) |d| { + if (d.generics.len != 0) return g.fail("E7006", e.span, "generic function needs explicit arguments", name); + }; + out.kind.call.callee = try g.box(ast.Expr, try g.expression(x.callee.*, env)); + const args = try g.arena.alloc(ast.Expr, x.args.len); + for (x.args, args, 0..) |arg, *target, i| { + if (i == 1 and callee_name != null and std.mem.eql(u8, callee_name.?, "task.spawn")) { + if (try path(g.arena, arg)) |name| if (boundFunction(env, name)) |selected| { + target.* = selectedExpr(arg, selected); + continue; + }; + } + target.* = try g.expression(arg, env); + } + out.kind.call.args = args; + return out; + }, + .variant => |x| { + const t = try g.named(x.@"enum", x.type_args, e.span, env); + if (t.kind != .name) return g.fail("E7005", e.span, "enum constructor requires a named type", x.@"enum"); + out.kind.variant.@"enum" = t.kind.name; + out.kind.variant.type_args = &.{}; + out.span.resolved = t.span.resolved; + return out; + }, + .struct_lit => |x| { + const t = try g.named(x.name, x.type_args, e.span, env); + if (t.kind != .name) return g.fail("E7005", e.span, "struct constructor requires a named type", x.name); + out.kind.struct_lit.name = t.kind.name; + out.kind.struct_lit.type_args = &.{}; + out.kind.struct_lit.fields = try g.walk([]const ast.FieldInit, x.fields, env); + out.span.resolved = t.span.resolved; + return out; + }, + else => {}, + } + out.kind = try g.walk(ast.Expr.Kind, e.kind, env); + return out; + } + + fn box(g: *Generator, comptime T: type, value: T) A.Error!*const T { + const out = try g.arena.create(T); + out.* = value; + return out; + } + + fn walk(g: *Generator, comptime T: type, value: T, env: Env) Error!T { + if (T == ast.Type) return g.ty(value, env); + if (T == ast.Expr) return g.expression(value, env); + if (T == ast.Pattern) { + var out = value; + if (value.kind == .ctor) for (value.kind.ctor.binds) |name| try g.checkBinding(name, value.span, env); + if (value.kind == .ctor) if (value.kind.ctor.qualifier) |q| { + const t = try g.named(q, value.kind.ctor.type_args, value.span, env); + if (t.kind != .name) return g.fail("E7005", value.span, "enum pattern requires a named type", q); + out.kind.ctor.qualifier = t.kind.name; + out.kind.ctor.type_args = &.{}; + out.span.resolved = t.span.resolved; + }; + return out; + } + if (T == ast.Param) try g.checkBinding(value.name, value.span, env); + if (T == ast.Select) for (value.cancelled_binds) |name| try g.checkBinding(name, value.span, env); + if (T == ast.Stmt) switch (value.kind) { + .let => |x| for (x.names) |name| try g.checkBinding(name, value.span, env), + inline .@"var", .borrow, .@"for", .scope, .lock => |x| try g.checkBinding(x.name, value.span, env), + else => {}, + }; + if (T == ast.Span) return value; + switch (@typeInfo(T)) { + .@"struct" => |info| { + var out = value; + inline for (info.field_names, info.field_types) |name, FieldType| @field(out, name) = try g.walk(FieldType, @field(value, name), env); + return out; + }, + .@"union" => switch (value) { + inline else => |payload, tag| return @unionInit(T, @tagName(tag), try g.walk(@TypeOf(payload), payload, env)), + }, + .optional => |info| return if (value) |v| try g.walk(info.child, v, env) else null, + .pointer => |info| { + if (info.child == u8) return value; + if (info.size == .slice) { + const out = try g.arena.alloc(info.child, value.len); + for (value, out) |v, *target| target.* = try g.walk(info.child, v, env); + return out; + } + return try g.box(info.child, try g.walk(info.child, value.*, env)); + }, + else => return value, + } + } +}; + +pub const Property = enum { Copy, Send, Share, Freeze, Local }; +fn local(full: []const u8, owner: []const u8, short: []const u8) bool { + return full.len == owner.len + short.len + 1 and std.mem.startsWith(u8, full, owner) and full[owner.len] == '.' and std.mem.eql(u8, full[owner.len + 1 ..], short); +} +fn builtin(name: []const u8) bool { + const names = [_][]const u8{ "u8", "u16", "u32", "u64", "u128", "usize", "i8", "i16", "i32", "i64", "i128", "isize", "bool", "void", "never", "region", "stream", "listener", "alloc_error", "cap_error", "io_error" }; + for (names) |n| if (std.mem.eql(u8, n, name)) return true; + return false; +} +fn path(arena: A, e: ast.Expr) A.Error!?[]const u8 { + return switch (e.kind) { + .name => |name| name, + .field => |f| if (try path(arena, f.e.*)) |base| try std.fmt.allocPrint(arena, "{s}.{s}", .{ base, f.name }) else null, + else => null, + }; +} + +fn usesGenerics(comptime T: type, value: T) bool { + if (T == ast.Type) if (value.kind == .applied or value.kind == .function_ref) return true; + if (T == ast.Expr) switch (value.kind) { + .specialize => return true, + .variant => |x| if (x.type_args.len != 0) return true, + .struct_lit => |x| if (x.type_args.len != 0) return true, + else => {}, + }; + if (T == ast.Pattern) if (value.kind == .ctor and value.kind.ctor.type_args.len != 0) return true; + switch (@typeInfo(T)) { + .@"struct" => |info| { + inline for (info.field_names, info.field_types) |name, FT| if (usesGenerics(FT, @field(value, name))) return true; + }, + .@"union" => switch (value) { + inline else => |payload| return usesGenerics(@TypeOf(payload), payload), + }, + .optional => |info| return if (value) |v| usesGenerics(info.child, v) else false, + .pointer => |info| { + if (info.child == u8) return false; + if (info.size == .slice) { + for (value) |v| if (usesGenerics(info.child, v)) return true; + } else return usesGenerics(info.child, value.*); + }, + else => {}, + } + return false; +} + +fn selectedExpr(original: ast.Expr, arg: ast.Type) ast.Expr { + var out = original; + out.kind = .{ .name = arg.kind.function_ref.name }; + out.span.resolved = true; + return out; +} + +fn shortName(name: []const u8) []const u8 { + return if (std.mem.lastIndexOfScalar(u8, name, '.')) |at| name[at + 1 ..] else name; +} + +fn usedAir(instances: []const Instance, name: []const u8) bool { + for (instances) |instance| if (std.mem.eql(u8, instance.air_name, name)) return true; + return false; +} diff --git a/src/frontend/lower.zig b/src/frontend/lower.zig index f4cddd3..a1d3a2a 100644 --- a/src/frontend/lower.zig +++ b/src/frontend/lower.zig @@ -50,6 +50,7 @@ pub const Ty = union(enum) { slice_mut: *const Ty, own: *const Ty, own_array: *const Ty, + buffer: *const Ty, region, /// `cap`: the kind. cap: []const u8, @@ -81,7 +82,7 @@ pub const Ty = union(enum) { /// Linear: consumed exactly once, by `move` (spec 15 §5). fn isLinear(t: Ty) bool { return switch (t) { - .own, .own_array, .region, .resource, .task, .sender, .receiver, .scope, .mutex, .guard, .shield, .island, .frozen, .arc, .atomic => true, + .own, .own_array, .buffer, .region, .resource, .task, .sender, .receiver, .scope, .mutex, .guard, .shield, .island, .frozen, .arc, .atomic => true, else => false, }; } @@ -92,7 +93,7 @@ pub const Ty = union(enum) { .int => |x| std.mem.eql(u8, x, b.int), .named => |i| i == b.named, .array => |x| x.len == b.array.len and x.elem.eql(b.array.elem), - .ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.eql(inner(b).?), + .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.eql(inner(b).?), .cap => |k| std.mem.eql(u8, k, b.cap), .builtin => |e| e == b.builtin, .resource => |r| r == b.resource, @@ -102,7 +103,7 @@ pub const Ty = union(enum) { fn inner(t: Ty) ?Ty { return switch (t) { - .ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.*, + .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| x.*, .array => |a| a.elem, else => null, }; @@ -263,7 +264,7 @@ const Rest = struct { const LoopAst = struct { cond: ?ast.Expr, body: ast.Block, step: ?[]const u8 }; -const FnSig = struct { params: []const Ty, ret: Ty }; +const FnSig = struct { params: []const Ty, ret: Ty, air_name: []const u8, display_name: []const u8 }; const Lowerer = struct { arena: Allocator, @@ -315,6 +316,43 @@ const Lowerer = struct { scope_binding_start: usize = 0, fns: std.ArrayList(FnOut) = .empty, + linear_enabled: bool = false, + + fn probeType(l: *Lowerer, t: ast.Type) ?Ty { + const previous = l.problem; + defer l.problem = previous; + return l.typeOf(t) catch null; + } + fn needsLinearType(l: *Lowerer, t: Ty, depth: usize) bool { + if (depth > l.m.types.len + 32) return false; + if (t == .named) return l.isLinear(t); + if (t.inner()) |inner| { + if ((t == .array or t == .own or t == .own_array or t == .slice or t == .slice_mut) and l.isLinear(inner)) return true; + return l.needsLinearType(inner, depth + 1); + } + return false; + } + fn isLinear(l: *Lowerer, t: Ty) bool { + return l.linearAt(t, 0); + } + fn linearAt(l: *Lowerer, t: Ty, depth: usize) bool { + if (t.isLinear()) return true; + if (depth > l.m.types.len + 32) return false; + return switch (t) { + .array => |a| l.linearAt(a.elem, depth + 1), + .named => |i| switch (l.m.types[i].kind) { + .@"struct" => |fs| for (fs) |f| { + if (l.probeType(f.ty)) |ty| if (l.linearAt(ty, depth + 1)) break true; + } else false, + .@"enum" => |vs| blk: { + for (vs) |v| for (v.payload) |p| if (l.probeType(p)) |ty| if (l.linearAt(ty, depth + 1)) break :blk true; + break :blk false; + }, + }, + else => false, + }; + } + fn fail(l: *Lowerer, code: []const u8, span: Span, message: []const u8, fields: []const Problem.Field) Error { // `fields` usually points at a temporary array: keep a copy. l.problem = .{ .code = code, .span = span, .message = message, .fields = try l.arena.dupe(Problem.Field, fields) }; @@ -327,14 +365,22 @@ const Lowerer = struct { } fn tyText(l: *Lowerer, t: Ty) []const u8 { + return l.typeText(t, false); + } + + fn diagnosticTyText(l: *Lowerer, t: Ty) []const u8 { + return l.typeText(t, true); + } + + fn typeText(l: *Lowerer, t: Ty, source_names: bool) []const u8 { return switch (t) { .int => |x| x, .bool => "bool", .void => "void", .never => "never", - .named => |i| l.typeNames[i], - .array => |a| std.fmt.allocPrint(l.arena, "array<{s}, {d}>", .{ l.tyText(a.elem), a.len }) catch "array", - .ref, .mut, .slice, .slice_mut, .own, .own_array, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| std.fmt.allocPrint(l.arena, "{s}<{s}>", .{ @tagName(t), l.tyText(x.*) }) catch "borrow", + .named => |i| if (source_names and l.m.types[i].air_name != null) (l.m.types[i].display_name orelse l.m.types[i].name) else l.typeNames[i], + .array => |a| std.fmt.allocPrint(l.arena, "array<{s}, {d}>", .{ l.typeText(a.elem, source_names), a.len }) catch "array", + .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |x| std.fmt.allocPrint(l.arena, "{s}<{s}>", .{ @tagName(t), l.typeText(x.*, source_names) }) catch "borrow", .scope => "scope", .shield => "shield", .region => "region", @@ -382,7 +428,9 @@ const Lowerer = struct { try l.out.append(l.arena, '\n'); try l.lines.append(l.arena, span); if (span) |s| if (std.mem.startsWith(u8, text, " ")) { - try l.annotated.appendSlice(l.arena, try l.fmt(" ; {d}:{d}-{d}:{d}\n", .{ s.start.line, s.start.col, s.end.line, s.end.col })); + if (s.file) |file| { + try l.annotated.appendSlice(l.arena, try l.fmt(" ; {s}:{d}:{d}-{d}:{d}\n", .{ file, s.start.line, s.start.col, s.end.line, s.end.col })); + } else try l.annotated.appendSlice(l.arena, try l.fmt(" ; {d}:{d}-{d}:{d}\n", .{ s.start.line, s.start.col, s.end.line, s.end.col })); }; try l.annotated.appendSlice(l.arena, text); try l.annotated.append(l.arena, '\n'); @@ -394,14 +442,14 @@ const Lowerer = struct { const names = try l.arena.alloc([]const u8, l.m.types.len); for (l.m.types, names, 0..) |t, *n, i| { for (l.m.types[0..i]) |prev| if (std.mem.eql(u8, prev.name, t.name)) return l.fail("E7006", t.span, "type defined twice", &.{.{ .name = "name", .value = t.name }}); - n.* = try l.fmt("@{s}", .{t.name}); + n.* = try l.fmt("@{s}", .{t.air_name orelse t.name}); } l.typeNames = names; for (l.m.functions) |f| { if (l.sigs.contains(f.name)) return l.fail("E7006", f.span, "function defined twice", &.{.{ .name = "name", .value = f.name }}); const ps = try l.arena.alloc(Ty, f.params.len); for (f.params, ps) |p, *t| t.* = try l.typeOf(p.ty); - try l.sigs.put(l.arena, f.name, .{ .params = ps, .ret = try l.typeOf(f.ret) }); + try l.sigs.put(l.arena, f.name, .{ .params = ps, .ret = try l.typeOf(f.ret), .air_name = f.air_name orelse f.name, .display_name = f.display_name orelse f.name }); } if (!l.sigs.contains("main")) return l.fail("E7002", .{ .start = .{ .line = 1, .col = 1 }, .end = .{ .line = 1, .col = 1 } }, "the module has no `main` function", &.{.{ .name = "name", .value = "main" }}); @@ -411,6 +459,7 @@ const Lowerer = struct { // closure of what the lowered AIR uses (spec 15 §9). var type_lines: std.ArrayList(Inst) = .empty; for (l.m.types) |t| try type_lines.append(l.arena, .{ .text = try l.typeDeclText(t), .span = t.span }); + try l.checkRequirements(); for (l.m.functions) |f| try l.fns.append(l.arena, try l.function(f)); var features: std.ArrayList(u8) = .empty; @@ -427,6 +476,82 @@ const Lowerer = struct { for (l.fns.items) |f| try l.emitFunction(f); } + fn airType(l: *Lowerer, t: Ty) Error!air_module.Type { + return switch (t) { + .int => |n| .{ .int = std.meta.stringToEnum(air_module.IntType, n).? }, + .named => |i| .{ .named = i }, + .cap => |k| .{ .cap = authority.kindIndex(k).? }, + .builtin => |b| .{ .builtin = b }, + .resource => |r| .{ .resource = r }, + .array => |a| blk: { + const out = try l.arena.create(air_module.Type.Array); + out.* = .{ .elem = try l.airType(a.elem), .len = a.len }; + break :blk .{ .array = out }; + }, + inline .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .task, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .iref, .atomic => |inner, tag| blk: { + const out = try l.arena.create(air_module.Type); + out.* = try l.airType(inner.*); + break :blk @unionInit(air_module.Type, @tagName(tag), out); + }, + .bool => .bool, + .void => .void, + .never => .never, + .region => .region, + .scope => .scope, + .shield => .shield, + }; + } + + fn checkRequirements(l: *Lowerer) Error!void { + const types = try l.arena.alloc(air_module.TypeDecl, l.m.types.len); + for (l.m.types, types, 0..) |d, *out, index| { + out.* = .{ .name = d.air_name orelse d.name, .span = .{ .line = @intCast(index + 1), .col = 1 }, .kind = undefined }; + switch (d.kind) { + .@"struct" => |fs| { + const fields = try l.arena.alloc(air_module.Field, fs.len); + for (fs, fields) |f, *target| target.* = .{ .name = f.name, .ty = try l.airType(try l.typeOf(f.ty)) }; + out.kind = .{ .@"struct" = fields }; + }, + .@"enum" => |vs| { + const variants = try l.arena.alloc(air_module.Variant, vs.len); + for (vs, variants) |v, *target| { + const payload = try l.arena.alloc(air_module.Type, v.payload.len); + for (v.payload, payload) |t, *p| p.* = try l.airType(try l.typeOf(t)); + target.* = .{ .name = v.name, .payload = payload }; + } + out.kind = .{ .@"enum" = variants }; + }, + } + } + for (l.m.types, 0..) |_, i| if (l.isLinear(.{ .named = @intCast(i) })) { + l.linear_enabled = true; + }; + const m: air_module.Module = .{ .name = l.m.name, .format_version = 0, .lang = .{ 0, 1 }, .features = &.{"linear_aggregates"}, .types = types, .functions = &.{} }; + var layout_context: @import("../verifier.zig").Context = .{ .arena = l.arena, .file = "", .module = m }; + try verifier_types.checkFiniteLayouts(&layout_context); + if (layout_context.diags.items.len != 0) { + const d = l.m.types[layout_context.diags.items[0].span.?.line - 1]; + return l.fail("E1003", d.span, "aggregate type contains itself by value", &.{.{ .name = "type", .value = d.display_name orelse d.name }}); + } + for (l.m.requirements) |r| { + const ty = try l.typeOf(r.ty); + const t = try l.airType(ty); + if (!boundedType(m, t, 0)) return l.fail("E7006", r.span, "constraint type traversal is cyclic or exceeds depth 64", &.{}); + if (r.property.len == 0) { + var context: @import("../verifier.zig").Context = .{ .arena = l.arena, .file = "", .module = m }; + try verifier_types.checkTypeArgument(&context, .{ .line = 1, .col = 1 }, t); + if (context.diags.items.len != 0) return l.fail("E7005", r.span, "generic argument is not a well-formed concrete type", &.{ .{ .name = "parameter", .value = r.parameter }, .{ .name = "found", .value = l.diagnosticTyText(ty) } }); + continue; + } + const ok = if (std.mem.eql(u8, r.property, "Copy")) verifier_types.isCopy(m, t) else if (std.mem.eql(u8, r.property, "Send")) verifier_types.isSend(m, t) else if (std.mem.eql(u8, r.property, "Share")) verifier_types.isShare(m, t) else if (std.mem.eql(u8, r.property, "Freeze")) verifier_types.isIslandSafe(m, t) else verifier_types.isLocalType(m, t); + if (!ok) return l.fail("E7005", r.span, "generic argument does not satisfy structural constraint", &.{ + .{ .name = "parameter", .value = r.parameter }, + .{ .name = "constraint", .value = r.property }, + .{ .name = "found", .value = l.diagnosticTyText(ty) }, + }); + } + } + /// The features the lowered AIR uses directly; the header is their /// dependency closure (spec 15 §9). `effects` is always declared. const UseFeature = enum { capabilities, resources, unsafe }; @@ -443,10 +568,21 @@ const Lowerer = struct { } var roots: std.ArrayList([]const u8) = .empty; try roots.append(l.arena, "effects"); + var signatures = l.sigs.valueIterator(); + while (signatures.next()) |f| { + for (f.params) |t| if (l.needsLinearType(t, 0)) { + l.linear_enabled = true; + }; + if (l.needsLinearType(f.ret, 0)) l.linear_enabled = true; + } + if (l.linear_enabled) try roots.append(l.arena, "linear_aggregates"); const Rule = struct { []const u8, []const []const u8 }; const rules = [_]Rule{ .{ "arrays", &.{ "array<", "slice", "array.splat", "borrow.index" } }, .{ "ownership", &.{ "local.", "borrow.", " load ", "= load ", "store ", "ref<", "mut<" } }, + .{ "linear_buffers", &.{ "buffer<", "buffer." } }, + .{ "error_values", &.{"error.const "} }, + .{ "linear_aggregates", &.{ "array.make ", "struct.unpack ", "array.unpack ", "enum.take ", "value.swap ", "own.pack " } }, .{ "heap", &.{ "own.", "own<", "own_array<", "alloc_error" } }, .{ "regions", &.{"region"} }, .{ "capabilities", &.{ "cap<", "cap.narrow", "cap_error" } }, @@ -477,7 +613,7 @@ const Lowerer = struct { /// `type @T = struct { … }` / `enum { … }` in canonical form. fn typeDeclText(l: *Lowerer, t: ast.TypeDecl) Error![]const u8 { var w: std.ArrayList(u8) = .empty; - try w.appendSlice(l.arena, try l.fmt("type @{s} = ", .{t.name})); + try w.appendSlice(l.arena, try l.fmt("type @{s} = ", .{t.air_name orelse t.name})); switch (t.kind) { .@"struct" => |fields| { try w.appendSlice(l.arena, "struct {"); @@ -515,12 +651,14 @@ const Lowerer = struct { fn typeOf(l: *Lowerer, t: ast.Type) Error!Ty { switch (t.kind) { + .applied => return l.fail("E7002", t.span, "unknown generic type", &.{}), + .function_ref => return l.fail("E7006", t.span, "static functions are not runtime types", &.{}), .name => |n| { if (isIntName(n)) return .{ .int = n }; if (std.mem.eql(u8, n, "bool")) return .bool; if (std.mem.eql(u8, n, "void")) return .void; if (std.mem.eql(u8, n, "never")) return .never; - for (l.m.types, 0..) |d, i| if (std.mem.eql(u8, d.name, n)) return .{ .named = @intCast(i) }; + if (l.enumOrStruct(n, t.span)) |ty| return ty; if (std.mem.eql(u8, n, "region")) return .region; if (std.meta.stringToEnum(authority.Builtin, n)) |b| return .{ .builtin = b }; if (std.mem.eql(u8, n, "stream")) return .{ .resource = .stream }; @@ -529,7 +667,7 @@ const Lowerer = struct { }, .array => |a| return l.arrayOf(try l.memberType(a.elem.*), a.len), .wrapped => |w| { - const Wr = enum { ref, mut, slice, slice_mut, own, own_array, task, sender, receiver, mutex, island, frozen, arc, iref, atomic }; + const Wr = enum { ref, mut, slice, slice_mut, own, own_array, buffer, task, sender, receiver, mutex, island, frozen, arc, iref, atomic }; const which = std.meta.stringToEnum(Wr, w.wrapper) orelse return l.notYet(t.span, "this type (later layers)"); const in = try l.typeOf(w.inner.*); return switch (which) { @@ -539,6 +677,7 @@ const Lowerer = struct { .slice_mut => l.wrap(.slice_mut, in), .own => l.wrap(.own, in), .own_array => l.wrap(.own_array, in), + .buffer => l.wrap(.buffer, in), .task => l.wrap(.task, in), .sender => l.wrap(.sender, in), .receiver => l.wrap(.receiver, in), @@ -547,7 +686,7 @@ const Lowerer = struct { .frozen => l.wrap(.frozen, in), .arc => l.wrap(.arc, in), .iref => l.wrap(.iref, in), - .atomic => if (atomicScalar(in)) l.wrap(.atomic, in) else l.fail("E7005", t.span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.tyText(in) }}), + .atomic => if (atomicScalar(in)) l.wrap(.atomic, in) else l.fail("E7005", t.span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(in) }}), }; }, .cap => |k| { @@ -583,7 +722,7 @@ const Lowerer = struct { for (f.effects) |e| if (std.mem.eql(u8, e, "unsafe")) l.uses.insert(.unsafe); var header: std.ArrayList(u8) = .empty; - try header.appendSlice(l.arena, try l.fmt("fn @{s}(", .{f.name})); + try header.appendSlice(l.arena, try l.fmt("fn @{s}(", .{sig.air_name})); for (f.params, sig.params, 0..) |p, t, i| { // Parameters keep their source names: `@main` capabilities are granted by name. const v = p.name; @@ -867,7 +1006,10 @@ const Lowerer = struct { fn stmt(l: *Lowerer, s: ast.Stmt) Error!void { switch (s.kind) { .let => |x| { - if (x.names.len == 2) { + if (x.e.kind == .call) if (pathOf(x.e.kind.call.callee.*)) |p| if (std.mem.eql(u8, p, "struct.unpack") or std.mem.eql(u8, p, "array.unpack")) return l.unpackLet(s, x.names, x.e, x.tuple); + if (x.tuple and x.names.len == 1) return l.fail("E7006", s.span, "a single parenthesized binding requires aggregate unpack", &.{}); + if (x.names.len != 1) { + if (x.e.kind != .call or x.names.len != 2) return l.fail("E7006", s.span, "this multi-binding requires aggregate unpack", &.{}); if (pathOf(x.e.kind.call.callee.*)) |p| if (std.mem.eql(u8, p, "atomic.compare_exchange")) return l.compareExchangeLet(s, x.names, x.e); return l.splitLet(s, x.names, x.e); } @@ -897,7 +1039,7 @@ const Lowerer = struct { if (v.ty.isBorrow()) return l.fail("E7006", x.e.span, "bind a borrow with `ref name = place;` or `mut name = place;`", &.{}); // Linear values (owners, regions, resources, endpoints, tasks, // mutexes) are borrowed in place, never moved to frame storage. - if (l.addressable.contains(x.names[0]) and !v.ty.isLinear()) { + if (l.addressable.contains(x.names[0]) and !l.isLinear(v.ty)) { const st = try l.storageFor(x.names[0], v.ty, s.span); try l.emit(try l.fmt("local.store %{s}, %{s}", .{ st, v.name }), s.span); try l.bindings.append(l.arena, .{ .name = x.names[0], .mutable = false, .value = st, .ty = v.ty, .kind = .storage }); @@ -906,7 +1048,7 @@ const Lowerer = struct { .@"var" => |x| { const ty = try l.typeOf(x.ty); if (ty.isBorrow()) return l.fail("E7006", s.span, "a `var` holds a value; bind a borrow with `ref` or `mut`", &.{}); - if (l.addressable.contains(x.name) and !ty.isLinear()) { + if (l.addressable.contains(x.name) and !l.isLinear(ty)) { const st = try l.storageFor(x.name, ty, s.span); if (x.init) |e| { const v = try l.consuming(e, ty); @@ -945,6 +1087,7 @@ const Lowerer = struct { const scope_start = l.scopeBindingStart(); for (l.bindings.items[scope_start..]) |b| if (b.kind == .borrow and std.mem.eql(u8, b.name, x.name)) return l.fail("E7006", s.span, "a borrow of this name is already active in this scope", &.{.{ .name = "name", .value = x.name }}); + if (x.place.kind == .call) if (pathOf(x.place.kind.call.callee.*)) |p| if (std.mem.eql(u8, p, "buffer.view")) return l.bufferView(s, x.name, x.mutable, x.place); if (x.place.kind == .call) if (pathOf(x.place.kind.call.callee.*)) |p| if (std.mem.endsWith(u8, p, ".at")) return l.graphAccess(s, x.name, x.mutable, x.place); const p = try l.uncheckedPlace(x.place, x.mutable, x.unchecked, s.span); @@ -967,7 +1110,7 @@ const Lowerer = struct { try l.term(try l.retText(v), s.span); } } else { - if (l.ret != .void) return l.fail("E7005", s.span, "`return` without a value in a function that returns one", &.{.{ .name = "expected", .value = l.tyText(l.ret) }}); + if (l.ret != .void) return l.fail("E7005", s.span, "`return` without a value in a function that returns one", &.{.{ .name = "expected", .value = l.diagnosticTyText(l.ret) }}); try l.endScopes(0, s.span); try l.term("ret", s.span); } @@ -1014,7 +1157,7 @@ const Lowerer = struct { fn checkTy(l: *Lowerer, span: Span, found: Ty, want: Ty) Error!void { if (found == .never or found.eql(want)) return; - return l.fail("E7005", span, "type mismatch", &.{ .{ .name = "expected", .value = l.tyText(want) }, .{ .name = "found", .value = l.tyText(found) } }); + return l.fail("E7005", span, "type mismatch", &.{ .{ .name = "expected", .value = l.diagnosticTyText(want) }, .{ .name = "found", .value = l.diagnosticTyText(found) } }); } /// `while cond { body }` (cond null: `loop { body }`). Carried state: @@ -1069,7 +1212,7 @@ const Lowerer = struct { const depth = l.bindings.items.len; defer l.bindings.shrinkRetainingCapacity(depth); const ty = l.peekType(lo) orelse l.peekType(hi) orelse return l.fail("E7007", lo.span, "the type of the range cannot be determined; add a suffix such as `0usize`", &.{}); - if (ty != .int) return l.fail("E7005", lo.span, "a range needs an integer type", &.{.{ .name = "found", .value = l.tyText(ty) }}); + if (ty != .int) return l.fail("E7005", lo.span, "a range needs an integer type", &.{.{ .name = "found", .value = l.diagnosticTyText(ty) }}); const a = try l.expr(lo, ty); try l.checkTy(lo.span, a.ty, ty); const b = try l.expr(hi, ty); @@ -1099,14 +1242,60 @@ const Lowerer = struct { /// The type of an expression without lowering it, where it follows /// from names, suffixes, casts and calls; null otherwise. + fn sourceScope(l: *Lowerer, span: Span) ?ast.ModuleScope { + const name = span.namespace orelse l.m.name; + for (l.m.scopes) |scope| if (std.mem.eql(u8, scope.name, name)) return scope; + return null; + } + + fn boundName(l: *Lowerer, name: []const u8, span: Span) ?[]const u8 { + if (span.resolved) return name; + const scope = l.sourceScope(span) orelse return name; + if (std.mem.lastIndexOfScalar(u8, name, '.')) |at| { + const owner = name[0..at]; + if (std.mem.eql(u8, owner, scope.name)) return if (!scope.qualified_self) null else if (scope.entry) name[at + 1 ..] else name; + for (scope.imports) |imp| if (std.mem.eql(u8, imp.path, owner)) return name; + return null; + } + if (scope.entry) return name; + for (l.m.types) |t| if (localName(t.name, scope.name, name)) return t.name; + for (l.m.functions) |f| if (localName(f.name, scope.name, name)) return f.name; + return null; + } + + fn functionSig(l: *Lowerer, name: []const u8, span: Span) ?FnSig { + return l.sigs.get(l.boundName(name, span) orelse return null); + } + + fn calleeSig(l: *Lowerer, e: ast.Expr) ?FnSig { + const name = expressionPath(l.arena, e) catch return null; + return l.functionSig(name orelse return null, e.span); + } + + fn moduleCall(l: *Lowerer, e: ast.Expr) Error!?[]const u8 { + if (e.kind != .field) return null; + const name = try expressionPath(l.arena, e) orelse return null; + if (standardPath(e)) return name; + if (pathOf(e) != null) return null; + const owner = name[0..std.mem.lastIndexOfScalar(u8, name, '.').?]; + for (l.m.scopes) |scope| if (std.mem.eql(u8, owner, scope.name)) return name; + if (l.sourceScope(e.span)) |scope| for (scope.imports) |imp| if (std.mem.eql(u8, owner, imp.path)) return name; + var root = e; + while (root.kind == .field) root = root.kind.field.e.*; + if (root.kind == .name and l.lookup(root.kind.name) == null) return name; + return null; + } + fn peekType(l: *Lowerer, e: ast.Expr) ?Ty { return switch (e.kind) { + .specialize => null, .int => |x| if (parse_mod.intSuffix(x.text)) |s| Ty{ .int = s } else null, .boolean => .bool, .name => |n| if (l.lookup(n)) |b| b.ty else null, .deref => |x| if (l.peekType(x.*)) |t| t.inner() else null, .index => |x| if (x.hi == null) (if (l.peekType(x.e.*)) |t| elemOf(t) else null) else null, .array_rep => |x| if (l.peekType(x.e.*)) |t| (l.arrayOf(t, x.len) catch null) else null, + .array_list => |xs| if (xs.len != 0) (if (l.peekType(xs[0])) |t| (l.arrayOf(t, xs.len) catch null) else null) else null, .neg => |x| l.peekType(x.*), .not => .bool, .cast => |x| l.typeOfNoFail(x.ty), @@ -1116,13 +1305,13 @@ const Lowerer = struct { else => l.peekType(x.l.*) orelse l.peekType(x.r.*), }, .call => |x| switch (x.callee.kind) { - .name => |n| if (l.sigs.get(n)) |sig| sig.ret else null, - .variant => |v| l.enumType(v.@"enum"), - else => if (pathOf(x.callee.*)) |p| l.peekPath(p, x.args) else null, + .name => |n| if (l.functionSig(n, e.span)) |sig| sig.ret else null, + .variant => |v| l.enumType(v.@"enum", e.span), + else => if (l.calleeSig(x.callee.*)) |sig| sig.ret else if (pathOf(x.callee.*)) |p| l.peekPath(p, x.args) else null, }, .move => |n| if (l.lookup(n)) |b| b.ty else null, - .variant => |v| l.enumType(v.@"enum"), - .struct_lit => |x| l.enumOrStruct(x.name), + .variant => |v| l.enumType(v.@"enum", e.span), + .struct_lit => |x| l.enumOrStruct(x.name, e.span), .field => |x| blk: { if (std.mem.eql(u8, x.name, "len")) break :blk Ty{ .int = "usize" }; var base = l.peekType(x.e.*) orelse break :blk null; @@ -1196,8 +1385,7 @@ const Lowerer = struct { }, }, .call => |x| blk: { - if (x.callee.kind != .name) break :blk null; - const sig = l.sigs.get(x.callee.kind.name) orelse break :blk null; + const sig = l.calleeSig(x.callee.*) orelse break :blk null; for (x.args, 0..) |a, i| { const pt: ?Ty = if (i < sig.params.len) sig.params[i] else null; if (l.useIn(n, a, pt)) |t| break :blk t; @@ -1215,27 +1403,30 @@ const Lowerer = struct { fn typeOfNoFail(l: *Lowerer, t: ast.Type) ?Ty { return switch (t.kind) { - .name => |n| if (isIntName(n)) Ty{ .int = n } else if (std.mem.eql(u8, n, "bool")) .bool else l.enumOrStruct(n), + .name => |n| if (isIntName(n)) Ty{ .int = n } else if (std.mem.eql(u8, n, "bool")) .bool else if (std.meta.stringToEnum(authority.Builtin, n)) |b| Ty{ .builtin = b } else l.enumOrStruct(n, t.span), else => null, }; } - fn enumOrStruct(l: *Lowerer, n: []const u8) ?Ty { + fn enumOrStruct(l: *Lowerer, name: []const u8, span: Span) ?Ty { + const n = l.boundName(name, span) orelse return null; for (l.m.types, 0..) |d, i| if (std.mem.eql(u8, d.name, n)) return .{ .named = @intCast(i) }; return null; } - fn enumType(l: *Lowerer, n: []const u8) ?Ty { - const t = l.enumOrStruct(n) orelse return null; + fn enumType(l: *Lowerer, n: []const u8, span: Span) ?Ty { + if (std.meta.stringToEnum(authority.Builtin, n)) |b| return .{ .builtin = b }; + const t = l.enumOrStruct(n, span) orelse return null; return if (l.m.types[t.named].kind == .@"enum") t else null; } fn expr(l: *Lowerer, e: ast.Expr, want: ?Ty) Error!Value { switch (e.kind) { + .specialize => return l.fail("E7006", e.span, "explicit type arguments require a generic function", &.{}), .int => |x| { const ty: Ty = if (parse_mod.intSuffix(x.text)) |s| .{ .int = s } else want orelse return l.fail("E7007", e.span, "the type of this integer literal cannot be determined; add a suffix such as `0u64` or a type annotation", &.{}); - if (ty != .int) return l.fail("E7005", e.span, "an integer literal where another type is expected", &.{.{ .name = "expected", .value = l.tyText(ty) }}); + if (ty != .int) return l.fail("E7005", e.span, "an integer literal where another type is expected", &.{.{ .name = "expected", .value = l.diagnosticTyText(ty) }}); const v = parse_mod.parseIntText(x.text) orelse return l.fail("E7001", e.span, "malformed integer literal", &.{}); const n = ty.int; const bits = intBits(n); @@ -1251,7 +1442,7 @@ const Lowerer = struct { }, .deref => |x| { const r = try l.expr(x.*, null); - const in = r.ty.inner() orelse return l.fail("E7005", e.span, "`*` reads through a borrow", &.{.{ .name = "found", .value = l.tyText(r.ty) }}); + const in = r.ty.inner() orelse return l.fail("E7005", e.span, "`*` reads through a borrow", &.{.{ .name = "found", .value = l.diagnosticTyText(r.ty) }}); if (r.ty == .slice or r.ty == .slice_mut or in == .array) return l.fail("E7006", e.span, "read slice and array elements with `s[i]`, not `*`", &.{}); // The verifier's code (spec 15 §1 rule 2, spec 04 §28). if (in == .atomic) return l.fail("E4202", e.span, "an atomic cell is read only by atomic operations: use `atomic.load(r, ordering)`", &.{}); @@ -1264,6 +1455,18 @@ const Lowerer = struct { try l.endNow(p.ends, e.span); return v; }, + .array_list => |xs| { + if (xs.len == 0 or xs.len > 64) return l.fail("E7006", e.span, "array literal requires 1..64 complete elements", &.{}); + var ty: ?Ty = if (want) |w| if (w == .array) w.array.elem else null else null; + var names: std.ArrayList(u8) = .empty; + for (xs, 0..) |x, i| { + const v = try l.consuming(x, ty); + if (ty) |t| try l.checkTy(x.span, v.ty, t) else ty = v.ty; + try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); + } + const at = try l.arrayOf(ty.?, xs.len); + return l.def("arr", at, try l.fmt("array.make {s}({s})", .{ l.tyText(at), names.items }), e.span); + }, .array_rep => |x| { const want_elem: ?Ty = if (want) |w| (if (w == .array) w.array.elem else null) else null; const v = try l.expr(x.e.*, want_elem); @@ -1301,7 +1504,7 @@ const Lowerer = struct { if (to != .int) return l.fail("E7005", x.ty.span, "casts convert between integer types", &.{}); const from = l.peekType(x.e.*) orelse to; const v = try l.expr(x.e.*, from); - if (v.ty != .int) return l.fail("E7005", x.e.span, "casts convert between integer types", &.{.{ .name = "found", .value = l.tyText(v.ty) }}); + if (v.ty != .int) return l.fail("E7005", x.e.span, "casts convert between integer types", &.{.{ .name = "found", .value = l.diagnosticTyText(v.ty) }}); // `as` widens without loss, by the verifier's own rule (spec 02 §2). if (x.mode == .widen) { const a = std.meta.stringToEnum(air_module.IntType, v.ty.int).?; @@ -1332,7 +1535,8 @@ const Lowerer = struct { .or_trap => |x| return l.orTrap(e, x.*), .move => |n| { const b = l.lookup(n) orelse return l.unknown(e.span, n); - if (!b.ty.isLinear()) return l.fail("E7006", e.span, "`move` applies to linear values; copyable values are passed plainly", &.{ .{ .name = "name", .value = n }, .{ .name = "type", .value = l.tyText(b.ty) } }); + if (!l.isLinear(b.ty) and !(e.generic_transfer and b.ty != .void and b.ty != .never and !b.ty.isBorrow() and b.ty != .task and b.ty != .scope and b.ty != .guard and b.ty != .shield)) return l.fail("E7006", e.span, "`move` applies to linear values; copyable values are passed plainly", &.{ .{ .name = "name", .value = n }, .{ .name = "type", .value = l.diagnosticTyText(b.ty) } }); + if (b.kind == .storage) return l.def(n, b.ty, try l.fmt("local.load %{s}", .{b.value}), e.span); return .{ .name = b.value, .ty = b.ty }; }, } @@ -1411,28 +1615,54 @@ const Lowerer = struct { } fn call(l: *Lowerer, e: ast.Expr, callee: ast.Expr, args: []const ast.Expr) Error!Value { + if (pathOf(callee)) |p| { + if (std.mem.eql(u8, p, "buffer.len") or std.mem.eql(u8, p, "buffer.capacity")) { + if (args.len != 1) return l.fail("E7005", e.span, "buffer metadata read takes one named borrow", &.{}); + const b = try l.bufferBorrow(args[0], false); + return l.def("size", .{ .int = "usize" }, try l.fmt("{s} %{s}", .{ p, b.name }), e.span); + } + if (std.mem.eql(u8, p, "buffer.view")) return l.fail("E7006", e.span, "bind a buffer view with ref/mut name = buffer.view(borrow)", &.{}); + } + if (pathOf(callee)) |path| if (std.mem.eql(u8, path, "value.swap")) { + if (args.len != 2 or args[0].kind != .borrow or !args[0].kind.borrow.mutable) return l.fail("E7006", e.span, "value.swap requires mut place and replacement", &.{}); + const b = args[0].kind.borrow; + const p = try l.placeBorrow(b.place.*, true, false, e.span); + if (p.v.ty != .mut) return l.fail("E7005", e.span, "value.swap requires mut", &.{}); + const ty = p.v.ty.inner().?; + const replacement = try l.consuming(args[1], ty); + try l.checkTy(args[1].span, replacement.ty, ty); + const result = try l.def("old", ty, try l.fmt("value.swap %{s}, %{s}", .{ p.v.name, replacement.name }), e.span); + try l.endNow(p.ends, e.span); + l.linear_enabled = true; + return result; + }; if (callee.kind == .variant) return l.variantValue(e, callee.kind.variant.@"enum", callee.kind.variant.name, args); + if (try l.moduleCall(callee)) |name| { + // Reuse ordinary call typing/borrowing/lowering, including E7002. + const owned_name = try l.arena.dupe(u8, name); + return l.call(e, .{ .span = callee.span, .kind = .{ .name = owned_name } }, args); + } if (pathOf(callee)) |p| { if (std.mem.eql(u8, p, "slice.copy")) return l.sliceCopy(e, args); if (l.fallible(p) != null) return l.fail("E7006", e.span, "a fallible operation is handled with `match` over its outcomes or with `or trap`", &.{.{ .name = "operation", .value = p }}); if (std.mem.eql(u8, p, "own.take")) { if (args.len != 1) return l.fail("E7005", e.span, "`own.take` takes one owner", &.{}); const o = try l.consuming(args[0], null); - if (o.ty != .own) return l.fail("E7005", args[0].span, "`own.take` takes an `own`", &.{.{ .name = "found", .value = l.tyText(o.ty) }}); + if (o.ty != .own) return l.fail("E7005", args[0].span, "`own.take` takes an `own`", &.{.{ .name = "found", .value = l.diagnosticTyText(o.ty) }}); return l.def("v", o.ty.own.*, try l.fmt("own.take %{s}", .{o.name}), e.span); } if (std.mem.eql(u8, p, "own.free") or std.mem.eql(u8, p, "region.destroy")) { if (args.len != 1) return l.fail("E7005", e.span, "this operation takes one linear value", &.{}); const o = try l.consuming(args[0], null); const ok = if (std.mem.eql(u8, p, "own.free")) (o.ty == .own or o.ty == .own_array) else o.ty == .region; - if (!ok) return l.fail("E7005", args[0].span, if (std.mem.eql(u8, p, "own.free")) "`own.free` takes an `own` or `own_array`" else "`region.destroy` takes a region", &.{.{ .name = "found", .value = l.tyText(o.ty) }}); + if (!ok) return l.fail("E7005", args[0].span, if (std.mem.eql(u8, p, "own.free")) "`own.free` takes an `own` or `own_array`" else "`region.destroy` takes a region", &.{.{ .name = "found", .value = l.diagnosticTyText(o.ty) }}); try l.emit(try l.fmt("{s} %{s}", .{ p, o.name }), e.span); return .{ .name = "", .ty = .void }; } if (std.mem.eql(u8, p, "region.reset")) { if (args.len != 1 or args[0].kind != .name) return l.fail("E7005", e.span, "`region.reset` takes the region by name", &.{}); const r = l.lookup(args[0].kind.name) orelse return l.unknown(args[0].span, args[0].kind.name); - if (r.ty != .region) return l.fail("E7005", args[0].span, "`region.reset` takes a region", &.{.{ .name = "found", .value = l.tyText(r.ty) }}); + if (r.ty != .region) return l.fail("E7005", args[0].span, "`region.reset` takes a region", &.{.{ .name = "found", .value = l.diagnosticTyText(r.ty) }}); try l.emit(try l.fmt("region.reset %{s}", .{r.value}), e.span); return .{ .name = "", .ty = .void }; } @@ -1472,8 +1702,8 @@ const Lowerer = struct { try l.emit(try l.fmt("assume %{s}", .{v.name}), e.span); return .{ .name = "", .ty = .void }; } - const sig = l.sigs.get(name) orelse return l.unknown(callee.span, name); - if (args.len != sig.params.len) return l.fail("E7005", e.span, "wrong number of arguments", &.{ .{ .name = "function", .value = name }, .{ .name = "expected", .value = try l.fmt("{d}", .{sig.params.len}) }, .{ .name = "found", .value = try l.fmt("{d}", .{args.len}) } }); + const sig = l.functionSig(name, callee.span) orelse return l.unknown(callee.span, name); + if (args.len != sig.params.len) return l.fail("E7005", e.span, "wrong number of arguments", &.{ .{ .name = "function", .value = sig.display_name }, .{ .name = "expected", .value = try l.fmt("{d}", .{sig.params.len}) }, .{ .name = "found", .value = try l.fmt("{d}", .{args.len}) } }); var arg_names: std.ArrayList(u8) = .empty; var temps: std.ArrayList([]const u8) = .empty; for (args, sig.params, 0..) |a, pt, i| { @@ -1481,7 +1711,7 @@ const Lowerer = struct { try l.checkTy(a.span, v.ty, pt); try arg_names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } - const text = try l.fmt("call @{s}({s})", .{ name, arg_names.items }); + const text = try l.fmt("call @{s}({s})", .{ sig.air_name, arg_names.items }); defer l.endNowIfLive(temps.items, e.span) catch {}; if (sig.ret == .void or sig.ret == .never) { try l.emit(text, e.span); @@ -1491,39 +1721,44 @@ const Lowerer = struct { } return .{ .name = "", .ty = .void }; } - return l.def(name, sig.ret, text, e.span); + return l.def(if (callee.span.resolved) "generic_call" else if (std.mem.startsWith(u8, name, "std.")) "std_call" else if (std.mem.indexOfScalar(u8, name, '.') != null) "module_call" else name, sig.ret, text, e.span); } /// `Name { f: e, … }`: every field exactly once; initializers are /// evaluated in declaration order, so the AIR does not depend on the /// order the fields are written in (spec 15 §5). fn structLit(l: *Lowerer, e: ast.Expr, name: []const u8, inits: []const ast.FieldInit) Error!Value { - const t = l.enumOrStruct(name) orelse return l.fail("E7002", e.span, "unknown type", &.{.{ .name = "name", .value = name }}); + const t = l.enumOrStruct(name, e.span) orelse return l.fail("E7002", e.span, "unknown type", &.{.{ .name = "name", .value = name }}); const d = l.m.types[t.named]; - if (d.kind != .@"struct") return l.fail("E7005", e.span, "`Name { … }` constructs a struct; this is an enum (use `Enum::Variant`)", &.{.{ .name = "type", .value = name }}); + if (d.kind != .@"struct") return l.fail("E7005", e.span, "`Name { … }` constructs a struct; this is an enum (use `Enum::Variant`)", &.{.{ .name = "type", .value = d.display_name orelse name }}); const fields = d.kind.@"struct"; for (inits, 0..) |fi, i| { for (inits[0..i]) |prev| if (std.mem.eql(u8, prev.name, fi.name)) return l.fail("E7006", fi.span, "field given twice", &.{.{ .name = "field", .value = fi.name }}); const known = for (fields) |f| { if (std.mem.eql(u8, f.name, fi.name)) break true; } else false; - if (!known) return l.fail("E7002", fi.span, "no such field", &.{ .{ .name = "type", .value = name }, .{ .name = "field", .value = fi.name } }); + if (!known) return l.fail("E7002", fi.span, "no such field", &.{ .{ .name = "type", .value = d.display_name orelse name }, .{ .name = "field", .value = fi.name } }); } var args: std.ArrayList(u8) = .empty; for (fields, 0..) |f, i| { const fi = for (inits) |x| { if (std.mem.eql(u8, x.name, f.name)) break x; - } else return l.fail("E7006", e.span, "missing field", &.{ .{ .name = "type", .value = name }, .{ .name = "field", .value = f.name } }); + } else return l.fail("E7006", e.span, "missing field", &.{ .{ .name = "type", .value = d.display_name orelse name }, .{ .name = "field", .value = f.name } }); const ft = try l.typeOf(f.ty); - const v = try l.expr(fi.e, ft); + const v = try l.consuming(fi.e, ft); try l.checkTy(fi.e.span, v.ty, ft); try args.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } - return l.def("s", t, try l.fmt("struct.make @{s}({s})", .{ name, args.items }), e.span); + return l.def("s", t, try l.fmt("struct.make {s}({s})", .{ l.tyText(t), args.items }), e.span); } fn variantValue(l: *Lowerer, e: ast.Expr, enum_name: []const u8, variant: []const u8, args: []const ast.Expr) Error!Value { - const t = l.enumType(enum_name) orelse return l.fail("E7002", e.span, "unknown enum", &.{.{ .name = "name", .value = enum_name }}); + const t = l.enumType(enum_name, e.span) orelse return l.fail("E7002", e.span, "unknown enum", &.{.{ .name = "name", .value = enum_name }}); + if (t == .builtin) { + _ = t.builtin.variantIndex(variant) orelse return l.fail("E7002", e.span, "no such variant", &.{ .{ .name = "enum", .value = enum_name }, .{ .name = "variant", .value = variant } }); + if (args.len != 0) return l.fail("E7005", e.span, "built-in error variants have no payload", &.{.{ .name = "variant", .value = variant }}); + return l.def("e", t, try l.fmt("error.const {s}.{s}", .{ enum_name, variant }), e.span); + } const vs = l.m.types[t.named].kind.@"enum"; const v = for (vs) |x| { if (std.mem.eql(u8, x.name, variant)) break x; @@ -1532,22 +1767,22 @@ const Lowerer = struct { var names: std.ArrayList(u8) = .empty; for (args, v.payload, 0..) |a, pt, i| { const ty = try l.typeOf(pt); - const av = try l.expr(a, ty); + const av = try l.consuming(a, ty); try l.checkTy(a.span, av.ty, ty); try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", av.name })); } - return l.def("e", t, try l.fmt("enum.make @{s}.{s}({s})", .{ enum_name, variant, names.items }), e.span); + return l.def("e", t, try l.fmt("enum.make {s}.{s}({s})", .{ l.tyText(t), variant, names.items }), e.span); } /// `v.f` on a struct value: `struct.get` (borrows come in layer 4). fn fieldValue(l: *Lowerer, e: ast.Expr, base: ast.Expr, name: []const u8) Error!Value { var bt = l.peekType(base) orelse return l.fail("E7007", base.span, "the type of this expression cannot be determined", &.{}); if (bt.isBorrow()) bt = bt.inner().?; - const d = l.decl(bt) orelse return l.fail("E7005", e.span, "field access on a value that is not a struct", &.{.{ .name = "found", .value = l.tyText(bt) }}); - if (d.kind != .@"struct") return l.fail("E7005", e.span, "field access on an enum; use `match`", &.{.{ .name = "type", .value = d.name }}); + const d = l.decl(bt) orelse return l.fail("E7005", e.span, "field access on a value that is not a struct", &.{.{ .name = "found", .value = l.diagnosticTyText(bt) }}); + if (d.kind != .@"struct") return l.fail("E7005", e.span, "field access on an enum; use `match`", &.{.{ .name = "type", .value = d.display_name orelse d.name }}); const f = for (d.kind.@"struct") |x| { if (std.mem.eql(u8, x.name, name)) break x; - } else return l.fail("E7002", e.span, "no such field", &.{ .{ .name = "type", .value = d.name }, .{ .name = "field", .value = name } }); + } else return l.fail("E7002", e.span, "no such field", &.{ .{ .name = "type", .value = d.display_name orelse d.name }, .{ .name = "field", .value = name } }); // Through a borrow: borrow the field and load it. if (l.rootBinding(base)) |rb| if (rb.kind == .borrow) { const p = try l.placeBorrow(e, false, false, e.span); @@ -1556,7 +1791,7 @@ const Lowerer = struct { return v; }; const v = try l.expr(base, bt); - return l.def(name, try l.typeOf(f.ty), try l.fmt("struct.get @{s}.{s}, %{s}", .{ d.name, name, v.name }), e.span); + return l.def(name, try l.typeOf(f.ty), try l.fmt("struct.get @{s}.{s}, %{s}", .{ d.air_name orelse d.name, name, v.name }), e.span); } /// One branch of a conditional or `match`: where it ended (null if it @@ -1572,7 +1807,7 @@ const Lowerer = struct { const vt: Ty = if (a.value) |v| v.ty else .void; if (vt == .never) continue; if (result_ty) |prev| { - if (!prev.eql(vt)) return l.fail("E7005", a.span, try l.fmt("the branches of this `{s}` have different types", .{what}), &.{ .{ .name = "expected", .value = l.tyText(prev) }, .{ .name = "found", .value = l.tyText(vt) } }); + if (!prev.eql(vt)) return l.fail("E7005", a.span, try l.fmt("the branches of this `{s}` have different types", .{what}), &.{ .{ .name = "expected", .value = l.diagnosticTyText(prev) }, .{ .name = "found", .value = l.diagnosticTyText(vt) } }); } else result_ty = vt; }; if (result_ty == null) { @@ -1606,26 +1841,28 @@ const Lowerer = struct { if (m.kind == .outcome) return l.outcomeMatch(m, want); const st = l.peekType(m.scrutinee) orelse return l.fail("E7007", m.scrutinee.span, "the type of this value cannot be determined", &.{}); if (st == .builtin) return l.builtinMatch(m, st.builtin, want); - const sv = try l.expr(m.scrutinee, st); + const sv = try l.consuming(m.scrutinee, st); const depth = l.bindings.items.len; const vars = try l.carriedLive(depth, m.span, .{ .match = m }); const before = try l.snapshot(); var ends: std.ArrayList(ArmEnd) = .empty; if (l.decl(st)) |d| { - if (d.kind != .@"enum") return l.fail("E7005", m.scrutinee.span, "`match` over a struct; use field access", &.{.{ .name = "type", .value = d.name }}); + if (d.kind != .@"enum") return l.fail("E7005", m.scrutinee.span, "`match` over a struct; use field access", &.{.{ .name = "type", .value = d.display_name orelse d.name }}); const vs = d.kind.@"enum"; const blocks = try l.arena.alloc(usize, m.arms.len); var head: std.ArrayList(u8) = .empty; - try head.appendSlice(l.arena, try l.fmt("enum.switch @{s} %{s}", .{ d.name, sv.name })); + try head.appendSlice(l.arena, try l.fmt("{s} {s} %{s}", .{ if (l.isLinear(st)) "enum.take" else "enum.switch", l.tyText(st), sv.name })); for (m.arms, blocks, 0..) |arm, *blk, i| { if (arm.pattern.kind != .ctor or arm.pattern.kind.ctor.qualifier == null) - return l.fail("E7006", arm.pattern.span, "an arm of a `match` over an enum names one variant as `Enum::Variant`; `_` is not allowed", &.{.{ .name = "enum", .value = d.name }}); + return l.fail("E7006", arm.pattern.span, "an arm of a `match` over an enum names one variant as `Enum::Variant`; `_` is not allowed", &.{.{ .name = "enum", .value = d.display_name orelse d.name }}); const c = arm.pattern.kind.ctor; - if (!std.mem.eql(u8, c.qualifier.?, d.name)) return l.fail("E7005", arm.pattern.span, "variant of a different enum", &.{ .{ .name = "expected", .value = d.name }, .{ .name = "found", .value = c.qualifier.? } }); + const pattern_type = l.enumType(c.qualifier.?, arm.pattern.span); + if (std.mem.indexOfScalar(u8, c.qualifier.?, '.') != null and pattern_type == null) return l.unknown(arm.pattern.span, c.qualifier.?); + if (pattern_type == null or !Ty.eql(st, pattern_type.?)) return l.fail("E7005", arm.pattern.span, "variant of a different enum", &.{ .{ .name = "expected", .value = d.display_name orelse d.name }, .{ .name = "found", .value = c.qualifier.? } }); const vi = for (vs, 0..) |v, k| { if (std.mem.eql(u8, v.name, c.name)) break k; - } else return l.fail("E7002", arm.pattern.span, "no such variant", &.{ .{ .name = "enum", .value = d.name }, .{ .name = "variant", .value = c.name } }); + } else return l.fail("E7002", arm.pattern.span, "no such variant", &.{ .{ .name = "enum", .value = d.display_name orelse d.name }, .{ .name = "variant", .value = c.name } }); for (m.arms[0..i]) |prev| if (std.mem.eql(u8, prev.pattern.kind.ctor.name, c.name)) return l.fail("E7006", arm.pattern.span, "variant matched twice", &.{.{ .name = "variant", .value = c.name }}); if (c.binds.len != vs[vi].payload.len) return l.fail("E7005", arm.pattern.span, "the pattern binds a different number of payload values", &.{ .{ .name = "variant", .value = c.name }, .{ .name = "expected", .value = try l.fmt("{d}", .{vs[vi].payload.len}) } }); blk.* = try l.newBlock(try l.fmt("case_{s}", .{c.name})); @@ -1659,7 +1896,7 @@ const Lowerer = struct { return l.mergeArms(m.span, "match", ends.items, vars, before, "endmatch"); } - if (st != .int) return l.fail("E7005", m.scrutinee.span, "`match` needs an enum or integer value; use `if` for booleans", &.{.{ .name = "found", .value = l.tyText(st) }}); + if (st != .int) return l.fail("E7005", m.scrutinee.span, "`match` needs an enum or integer value; use `if` for booleans", &.{.{ .name = "found", .value = l.diagnosticTyText(st) }}); var head: std.ArrayList(u8) = .empty; try head.appendSlice(l.arena, try l.fmt("switch.{s} %{s}, ", .{ st.int, sv.name })); const blocks = try l.arena.alloc(usize, m.arms.len); @@ -1675,11 +1912,19 @@ const Lowerer = struct { .int => |text| { const neg = text[0] == '-'; const mag = parse_mod.parseIntText(if (neg) text[1..] else text) orelse return l.fail("E7001", arm.pattern.span, "malformed integer pattern", &.{}); + const width = intBits(st.int); + const negative = neg and mag != 0; + const signed = isSigned(st.int); + const limit: u128 = if (signed) (@as(u128, 1) << @intCast(width - 1)) - @as(u128, if (negative) 0 else 1) else if (width == 128) std.math.maxInt(u128) else (@as(u128, 1) << @intCast(width)) - 1; + if ((negative and !signed) or mag > limit) return l.fail("E7005", arm.pattern.span, "integer pattern out of range for its scrutinee type", &.{ .{ .name = "type", .value = st.int }, .{ .name = "literal", .value = text } }); const bits: u128 = if (neg) (0 -% mag) else mag; for (seen.items) |prev| if (prev == bits) return l.fail("E7006", arm.pattern.span, "integer matched twice", &.{.{ .name = "value", .value = text }}); try seen.append(l.arena, bits); blk.* = try l.newBlock("case"); - try head.appendSlice(l.arena, try l.fmt("{s} -> @{s}(), ", .{ text, l.blocks.items[blk.*].name })); + // AIR uses canonical decimal literals without source + // suffixes/separators. Validate range before formatting + // rather than truncating a pattern's bit representation. + try head.appendSlice(l.arena, try l.fmt("{s}{d} -> @{s}(), ", .{ if (neg and mag != 0) "-" else "", mag, l.blocks.items[blk.*].name })); }, .ctor => return l.fail("E7005", arm.pattern.span, "an arm of a `match` over an integer is an integer literal or `_`", &.{}), } @@ -1740,6 +1985,7 @@ const Lowerer = struct { /// without lowering it. fn peekPath(l: *Lowerer, p: []const u8, args: []const ast.Expr) ?Ty { const eq = std.mem.eql; + if (eq(u8, p, "buffer.len") or eq(u8, p, "buffer.capacity")) return .{ .int = "usize" }; if ((eq(u8, p, "own.take") or eq(u8, p, "task.join")) and args.len == 1) return if (l.peekType(args[0])) |t| t.inner() else null; if (eq(u8, p, "task.cancelled")) return .bool; if (std.mem.startsWith(u8, p, "atomic.") and args.len >= 1) { @@ -1756,8 +2002,8 @@ const Lowerer = struct { if (eq(u8, p, "arc.from_frozen") and args.len == 1) return if (l.peekType(args[0])) |t| (if (t == .frozen) l.wrap(.arc, t.inner().?) catch null else null) else null; if (eq(u8, p, "arc.clone") and args.len == 1) return if (l.peekType(args[0])) |t| (if (t == .arc) t else if (t.inner()) |in| (if (in == .arc) in else null) else null) else null; if (eq(u8, p, "channel.dup") and args.len == 1) return if (l.peekType(args[0])) |t| (if (t == .sender) t else if (t.inner()) |in| (if (in == .sender) in else null) else null) else null; - if (eq(u8, p, "task.spawn") and args.len >= 2 and args[1].kind == .name) { - const sig = l.sigs.get(args[1].kind.name) orelse return null; + if (eq(u8, p, "task.spawn") and args.len >= 2) { + const sig = l.calleeSig(args[1]) orelse return null; return l.wrap(.task, sig.ret) catch null; } return null; @@ -1856,7 +2102,7 @@ const Lowerer = struct { /// written `move x` (spec 15 §5). Use after move, double consumption and /// leaks are the verifier's (E2001, E2002, E3001, E3002). fn consuming(l: *Lowerer, e: ast.Expr, want: ?Ty) Error!Value { - if (e.kind == .name) if (l.lookup(e.kind.name)) |b| if (b.ty.isLinear() and b.kind == .ssa) + if (e.kind == .name) if (l.lookup(e.kind.name)) |b| if (l.isLinear(b.ty) and b.kind == .ssa) return l.fail("E7003", e.span, "a linear value is consumed here: write `move` to transfer it, or borrow it with `ref`/`mut`", &.{ .{ .name = "name", .value = e.kind.name }, .{ .name = "suggestion", .value = try l.fmt("move {s}", .{e.kind.name}) } }); return l.expr(e, want); } @@ -1920,8 +2166,10 @@ const Lowerer = struct { .ssa => { // A linear value (owner, region) is borrowed in place. const bt: ?Ty = switch (b.ty) { + .named, .array => if (l.isLinear(b.ty)) (if (mutable) try l.wrap(.mut, b.ty) else try l.wrap(.ref, b.ty)) else null, .own => |in| if (mutable) try l.wrap(.mut, in.*) else try l.wrap(.ref, in.*), .own_array => |in| if (mutable) try l.wrap(.slice_mut, in.*) else try l.wrap(.slice, in.*), + .buffer => if (mutable) try l.wrap(.mut, b.ty) else try l.wrap(.ref, b.ty), .region => if (mutable) try l.wrap(.mut, .region) else try l.wrap(.ref, .region), .resource, .mutex, .sender, .receiver, .task, .island => if (mutable) try l.wrap(.mut, b.ty) else try l.wrap(.ref, b.ty), .frozen, .arc => if (mutable) return l.fail("E7005", place.span, "frozen graphs and arcs are immutable: borrow them with `ref`", &.{.{ .name = "name", .value = n }}) else try l.wrap(.ref, b.ty), @@ -1948,13 +2196,13 @@ const Lowerer = struct { .field => |f| { const base = try l.placeRaw(f.e.*, mutable, span); const st = base.v.ty.inner() orelse return l.fail("E7005", place.span, "field of a value that is not a struct", &.{}); - const d = l.decl(st) orelse return l.fail("E7005", place.span, "field of a value that is not a struct", &.{.{ .name = "found", .value = l.tyText(st) }}); + const d = l.decl(st) orelse return l.fail("E7005", place.span, "field of a value that is not a struct", &.{.{ .name = "found", .value = l.diagnosticTyText(st) }}); if (d.kind != .@"struct") return l.fail("E7005", place.span, "field of an enum; use `match`", &.{}); const fd = for (d.kind.@"struct") |x| { if (std.mem.eql(u8, x.name, f.name)) break x; - } else return l.fail("E7002", place.span, "no such field", &.{ .{ .name = "type", .value = d.name }, .{ .name = "field", .value = f.name } }); + } else return l.fail("E7002", place.span, "no such field", &.{ .{ .name = "type", .value = d.display_name orelse d.name }, .{ .name = "field", .value = f.name } }); const ft = try l.typeOf(fd.ty); - const v = try l.def(f.name, if (base.v.ty.isMutBorrow()) try l.wrap(.mut, ft) else try l.wrap(.ref, ft), try l.fmt("borrow.field @{s}.{s}, %{s}", .{ d.name, f.name, base.v.name }), span); + const v = try l.def(f.name, if (base.v.ty.isMutBorrow()) try l.wrap(.mut, ft) else try l.wrap(.ref, ft), try l.fmt("borrow.field @{s}.{s}, %{s}", .{ d.air_name orelse d.name, f.name, base.v.name }), span); return .{ .v = v, .ends = try l.concat(base.ends, v.name) }; }, .index => |x| { @@ -1963,7 +2211,7 @@ const Lowerer = struct { const base = try l.placeRaw(x.e.*, mutable, span); l.unchecked = outer_unchecked; const bt = base.v.ty; - const elem = elemOf(bt) orelse return l.fail("E7005", place.span, "indexing needs an array or a slice", &.{.{ .name = "found", .value = l.tyText(bt) }}); + const elem = elemOf(bt) orelse return l.fail("E7005", place.span, "indexing needs an array or a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(bt) }}); if (x.hi) |hi| { // `s[a..b]`: slice.sub with start a and length b - a (checked). var sl = base.v; @@ -2040,13 +2288,37 @@ const Lowerer = struct { else => null, }; if (arr) |n| return l.def("len", .{ .int = "usize" }, try l.fmt("const.usize {d}", .{n}), e.span); - if (bt != .slice and bt != .slice_mut) return l.fail("E7005", e.span, "`.len` needs an array or a slice", &.{.{ .name = "found", .value = l.tyText(bt) }}); + if (bt != .slice and bt != .slice_mut) return l.fail("E7005", e.span, "`.len` needs an array or a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(bt) }}); const s_ = try l.expr(base, bt); return l.def("len", .{ .int = "usize" }, try l.fmt("slice.len %{s}", .{s_.name}), e.span); } /// `let (left, right) = s.split_at(k);`: two disjoint borrows of `s`, /// bound for the rest of the block (spec 15 §5). + fn unpackLet(l: *Lowerer, s: ast.Stmt, names: []const []const u8, e: ast.Expr, tuple: bool) Error!void { + if (!tuple or s.kind.let.ty != null or e.kind.call.args.len != 1) return l.fail("E7006", s.span, "unpack requires a parenthesized complete binding and one argument", &.{}); + const v = try l.consuming(e.kind.call.args[0], null); + const operation = pathOf(e.kind.call.callee.*).?; + var components: std.ArrayList(Ty) = .empty; + if (std.mem.eql(u8, operation, "struct.unpack") and v.ty == .named and l.m.types[v.ty.named].kind == .@"struct") { + for (l.m.types[v.ty.named].kind.@"struct") |f| try components.append(l.arena, try l.typeOf(f.ty)); + } else if (std.mem.eql(u8, operation, "array.unpack") and v.ty == .array) { + if (v.ty.array.len > 64) return l.fail("E7006", s.span, "unpack exceeds 64 block parameters", &.{}); + for (0..@intCast(v.ty.array.len)) |_| try components.append(l.arena, v.ty.array.elem); + } else return l.fail("E7005", e.span, "unpack needs the corresponding struct or array", &.{}); + if (names.len != components.items.len or names.len > 64) return l.fail("E7005", s.span, "unpack must bind every component", &.{}); + const next = try l.newBlock("unpacked"); + for (names, components.items, 0..) |n, t, i| { + for (names[0..i]) |previous| if (!std.mem.eql(u8, n, "_") and std.mem.eql(u8, n, previous)) return l.fail("E7006", s.span, "duplicate unpack binding", &.{}); + const pn = try l.freshName(if (std.mem.eql(u8, n, "_")) "unused" else n); + try l.blocks.items[next].params.append(l.arena, .{ .name = pn, .ty = t }); + if (!std.mem.eql(u8, n, "_")) try l.bindings.append(l.arena, .{ .name = n, .value = pn, .ty = t, .mutable = false }); + } + try l.term(try l.fmt("{s} {s} %{s}, next -> @{s}", .{ operation, l.tyText(v.ty), v.name, l.blocks.items[next].name }), s.span); + l.cur = next; + l.linear_enabled = true; + } + fn splitLet(l: *Lowerer, s: ast.Stmt, names: []const []const u8, e: ast.Expr) Error!void { if (e.kind != .call or e.kind.call.callee.kind != .field or !std.mem.eql(u8, e.kind.call.callee.kind.field.name, "split_at") or e.kind.call.args.len != 1) return l.fail("E7006", e.span, "`let (a, b) = …` is only for `s.split_at(k)`", &.{}); @@ -2054,7 +2326,7 @@ const Lowerer = struct { const rb = l.rootBinding(base) orelse return l.fail("E7002", base.span, "unknown name", &.{}); const mutable = rb.ty.isMutBorrow() or rb.kind == .storage and rb.mutable; const p = try l.placeBorrow(base, mutable, true, s.span); - if (p.v.ty != .slice and p.v.ty != .slice_mut) return l.fail("E7005", base.span, "`split_at` splits a slice", &.{.{ .name = "found", .value = l.tyText(p.v.ty) }}); + if (p.v.ty != .slice and p.v.ty != .slice_mut) return l.fail("E7005", base.span, "`split_at` splits a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(p.v.ty) }}); const k = try l.expr(e.kind.call.args[0], .{ .int = "usize" }); try l.checkTy(e.kind.call.args[0].span, k.ty, .{ .int = "usize" }); const left = try l.freshName(names[0]); @@ -2072,9 +2344,9 @@ const Lowerer = struct { var temps: std.ArrayList([]const u8) = .empty; const d = try l.argument(args[0], null, &temps); const src = try l.argument(args[1], null, &temps); - if (d.ty != .slice_mut) return l.fail("E7005", args[0].span, "`slice.copy` writes to `mut dst` (a `slice_mut`)", &.{.{ .name = "found", .value = l.tyText(d.ty) }}); - if (src.ty != .slice and src.ty != .slice_mut) return l.fail("E7005", args[1].span, "`slice.copy` reads from `ref src` (a `slice`)", &.{.{ .name = "found", .value = l.tyText(src.ty) }}); - if (!d.ty.inner().?.eql(src.ty.inner().?)) return l.fail("E7005", args[1].span, "`slice.copy` copies between slices of the same element type", &.{ .{ .name = "expected", .value = l.tyText(d.ty.inner().?) }, .{ .name = "found", .value = l.tyText(src.ty.inner().?) } }); + if (d.ty != .slice_mut) return l.fail("E7005", args[0].span, "`slice.copy` writes to `mut dst` (a `slice_mut`)", &.{.{ .name = "found", .value = l.diagnosticTyText(d.ty) }}); + if (src.ty != .slice and src.ty != .slice_mut) return l.fail("E7005", args[1].span, "`slice.copy` reads from `ref src` (a `slice`)", &.{.{ .name = "found", .value = l.diagnosticTyText(src.ty) }}); + if (!d.ty.inner().?.eql(src.ty.inner().?)) return l.fail("E7005", args[1].span, "`slice.copy` copies between slices of the same element type", &.{ .{ .name = "expected", .value = l.diagnosticTyText(d.ty.inner().?) }, .{ .name = "found", .value = l.diagnosticTyText(src.ty.inner().?) } }); try l.emit(try l.fmt("slice.copy %{s}, %{s}", .{ d.name, src.name }), e.span); try l.endNow(temps.items, e.span); return .{ .name = "", .ty = .void }; @@ -2154,6 +2426,7 @@ const Lowerer = struct { .field => |x| try l.markExpr(x.e.*), .struct_lit => |x| for (x.fields) |f| try l.markExpr(f.e), .array_rep => |x| try l.markExpr(x.e.*), + .array_list => |xs| for (xs) |x| try l.markExpr(x), .if_expr => |x| { try l.markExpr(x.cond); try l.markBlock(x.then); @@ -2183,7 +2456,7 @@ const Lowerer = struct { fn fallible(l: *Lowerer, path: []const u8) ?void { _ = l; - const ops = [_][]const u8{ "own.new", "own.array", "region.create", "region.new", "region.array", "cap.narrow.budget", "cap.narrow.prefix", "channel.make", "channel.send", "channel.recv", "channel.close_receiver", "task.check_cancel", "task.join_cancel", "island.create", "island.alloc", "arc.new" }; + const ops = [_][]const u8{ "buffer.new", "buffer.reserve", "buffer.push", "buffer.pop", "buffer.free", "own.new", "own.pack", "own.array", "region.create", "region.new", "region.array", "cap.narrow.budget", "cap.narrow.prefix", "channel.make", "channel.send", "channel.recv", "channel.close_receiver", "task.check_cancel", "task.join_cancel", "island.create", "island.alloc", "arc.new" }; for (ops) |o| if (std.mem.eql(u8, o, path)) return {}; if (authority.intrinsicIndex(path)) |i| if (authority.intrinsics[i].fallible) return {}; return null; @@ -2207,7 +2480,7 @@ const Lowerer = struct { const br = a.kind.borrow; if (br.mutable) return l.fail("E7005", a.span, "atomic operations take `ref` of the cell, never `mut`", &.{}); const b = try l.bindingOf(br.place.*, "an atomic cell"); - if (b.ty != .atomic) return l.fail("E7005", a.span, "an atomic operation takes `ref` of an `atomic`", &.{.{ .name = "found", .value = l.tyText(b.ty) }}); + if (b.ty != .atomic) return l.fail("E7005", a.span, "an atomic operation takes `ref` of an `atomic`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}); const r = try l.def(br.place.kind.name, try l.wrap(.ref, b.ty), try l.fmt("borrow.ref %{s}", .{b.value}), a.span); try temps.append(l.arena, r.name); return r; @@ -2215,7 +2488,7 @@ const Lowerer = struct { const b = try l.bindingOf(a, "an atomic cell"); if (b.ty == .atomic) return l.fail("E7005", a.span, "pass the cell as `ref a` (or a `ref` binding of it): atomic operations go through a shared borrow", &.{.{ .name = "suggestion", .value = try l.fmt("ref {s}", .{a.kind.name}) }}); if (b.ty == .ref and b.ty.inner().? == .atomic) return .{ .name = b.value, .ty = b.ty }; - return l.fail("E7005", a.span, "an atomic operation takes a `ref>`", &.{.{ .name = "found", .value = l.tyText(b.ty) }}); + return l.fail("E7005", a.span, "an atomic operation takes a `ref>`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}); } fn atomicCall(l: *Lowerer, e: ast.Expr, p: []const u8, args: []const ast.Expr) Error!Value { @@ -2223,13 +2496,13 @@ const Lowerer = struct { if (eq(u8, p, "atomic.new")) { if (args.len != 1) return l.fail("E7005", e.span, "`atomic.new` takes the initial value", &.{}); const v = try l.expr(args[0], null); - if (!atomicScalar(v.ty)) return l.fail("E7005", args[0].span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.tyText(v.ty) }}); + if (!atomicScalar(v.ty)) return l.fail("E7005", args[0].span, "atomic needs bool or an integer of at most 64 bits", &.{.{ .name = "found", .value = l.diagnosticTyText(v.ty) }}); return l.def("atomic", try l.wrap(.atomic, v.ty), try l.fmt("atomic.new %{s}", .{v.name}), e.span); } if (eq(u8, p, "atomic.take")) { if (args.len != 1) return l.fail("E7005", e.span, "`atomic.take` takes one cell", &.{}); const c = try l.consuming(args[0], null); - if (c.ty != .atomic) return l.fail("E7005", args[0].span, "`atomic.take` takes an `atomic`", &.{.{ .name = "found", .value = l.tyText(c.ty) }}); + if (c.ty != .atomic) return l.fail("E7005", args[0].span, "`atomic.take` takes an `atomic`", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }}); return l.def("v", c.ty.inner().?, try l.fmt("atomic.take %{s}", .{c.name}), e.span); } if (eq(u8, p, "atomic.fence")) { @@ -2258,7 +2531,7 @@ const Lowerer = struct { return .{ .name = "", .ty = .void }; } const op: []const u8 = if (eq(u8, p, "atomic.swap")) "xchg" else p["atomic.".len..]; - if ((eq(u8, op, "add.wrap") or eq(u8, op, "sub.wrap")) and t != .int) return l.fail("E7005", args[1].span, "`atomic.add.wrap` and `atomic.sub.wrap` need an integer cell", &.{.{ .name = "found", .value = l.tyText(t) }}); + if ((eq(u8, op, "add.wrap") or eq(u8, op, "sub.wrap")) and t != .int) return l.fail("E7005", args[1].span, "`atomic.add.wrap` and `atomic.sub.wrap` need an integer cell", &.{.{ .name = "found", .value = l.diagnosticTyText(t) }}); const v = try l.def("old", t, try l.fmt("atomic.{s}.{s} %{s}, %{s}", .{ op, ord, c.name, operand.name }), e.span); try l.endNow(temps.items, e.span); return v; @@ -2304,7 +2577,7 @@ const Lowerer = struct { return v; } if ((b.ty == .mut or (b.ty == .ref and !mutable)) and std.meta.activeTag(b.ty.inner().?) == tag) return .{ .name = b.value, .ty = b.ty }; - return l.fail("E7005", a.span, try l.fmt("{s} is expected here", .{what}), &.{.{ .name = "found", .value = l.tyText(b.ty) }}); + return l.fail("E7005", a.span, try l.fmt("{s} is expected here", .{what}), &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}); } /// The task and channel operations that are plain calls; null for any @@ -2318,13 +2591,12 @@ const Lowerer = struct { if (eq(p, "task.spawn")) { if (args.len < 2) return l.fail("E7005", e.span, "`task.spawn` takes a scope, a function and its arguments", &.{}); const sb = try l.bindingOf(args[0], "a task scope"); - if (sb.ty != .scope) return l.fail("E7005", args[0].span, "`task.spawn` spawns into a scope: `scope s { … task.spawn(s, f, …) … }`", &.{.{ .name = "found", .value = l.tyText(sb.ty) }}); + if (sb.ty != .scope) return l.fail("E7005", args[0].span, "`task.spawn` spawns into a scope: `scope s { … task.spawn(s, f, …) … }`", &.{.{ .name = "found", .value = l.diagnosticTyText(sb.ty) }}); const scope_name = sb.value; - if (args[1].kind != .name) return l.fail("E7005", args[1].span, "the function to spawn is named", &.{}); - const fname = args[1].kind.name; - const sig = l.sigs.get(fname) orelse return l.unknown(args[1].span, fname); + const fname = try expressionPath(l.arena, args[1]) orelse return l.fail("E7005", args[1].span, "the function to spawn is named", &.{}); + const sig = l.functionSig(fname, args[1].span) orelse return l.unknown(args[1].span, fname); const fargs = args[2..]; - if (fargs.len != sig.params.len) return l.fail("E7005", e.span, "wrong number of arguments", &.{ .{ .name = "function", .value = fname }, .{ .name = "expected", .value = try l.fmt("{d}", .{sig.params.len}) }, .{ .name = "found", .value = try l.fmt("{d}", .{fargs.len}) } }); + if (fargs.len != sig.params.len) return l.fail("E7005", e.span, "wrong number of arguments", &.{ .{ .name = "function", .value = sig.display_name }, .{ .name = "expected", .value = try l.fmt("{d}", .{sig.params.len}) }, .{ .name = "found", .value = try l.fmt("{d}", .{fargs.len}) } }); var names: std.ArrayList(u8) = .empty; for (fargs, sig.params, 0..) |a, pt, i| { // A borrow is lent to the task until its join, so it is bound @@ -2334,12 +2606,12 @@ const Lowerer = struct { try l.checkTy(a.span, v.ty, pt); try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } - return try l.def("t", try l.wrap(.task, sig.ret), try l.fmt("task.spawn %{s}, @{s}({s})", .{ scope_name, fname, names.items }), e.span); + return try l.def("t", try l.wrap(.task, sig.ret), try l.fmt("task.spawn %{s}, @{s}({s})", .{ scope_name, sig.air_name, names.items }), e.span); } if (eq(p, "task.join")) { if (args.len != 1) return l.fail("E7005", e.span, "`task.join` takes one task", &.{}); const t = try l.consuming(args[0], null); - if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join` takes a `task`", &.{.{ .name = "found", .value = l.tyText(t.ty) }}); + if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join` takes a `task`", &.{.{ .name = "found", .value = l.diagnosticTyText(t.ty) }}); const rt = t.ty.task.*; if (rt == .void) { try l.emit(try l.fmt("task.join %{s}", .{t.name}), e.span); @@ -2350,7 +2622,7 @@ const Lowerer = struct { if (eq(p, "task.cancel")) { if (args.len != 1) return l.fail("E7005", e.span, "`task.cancel` takes one task, by name", &.{}); const b = try l.bindingOf(args[0], "a task"); - if (b.ty != .task) return l.fail("E7005", args[0].span, "`task.cancel` takes a `task`", &.{.{ .name = "found", .value = l.tyText(b.ty) }}); + if (b.ty != .task) return l.fail("E7005", args[0].span, "`task.cancel` takes a `task`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}); try l.emit(try l.fmt("task.cancel %{s}", .{b.value}), e.span); return .{ .name = "", .ty = .void }; } @@ -2376,7 +2648,7 @@ const Lowerer = struct { if (args.len != 1) return l.fail("E7005", e.span, "this operation takes one graph owner", &.{}); const o = try l.consuming(args[0], null); const want: std.meta.Tag(Ty) = if (eq(p, "island.freeze")) .island else .frozen; - if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, if (want == .island) "`island.freeze` takes an `island`" else "`arc.from_frozen` takes a `frozen`", &.{.{ .name = "found", .value = l.tyText(o.ty) }}); + if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, if (want == .island) "`island.freeze` takes an `island`" else "`arc.from_frozen` takes a `frozen`", &.{.{ .name = "found", .value = l.diagnosticTyText(o.ty) }}); const out = if (want == .island) try l.wrap(.frozen, o.ty.inner().?) else try l.wrap(.arc, o.ty.inner().?); return try l.def(if (want == .island) "frozen" else "arc", out, try l.fmt("{s} %{s}", .{ p, o.name }), e.span); } @@ -2384,7 +2656,7 @@ const Lowerer = struct { if (args.len != 1) return l.fail("E7005", e.span, "this operation takes one graph owner", &.{}); const o = try l.consuming(args[0], null); const want: std.meta.Tag(Ty) = if (eq(p, "island.destroy")) .island else if (eq(p, "frozen.release")) .frozen else .arc; - if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, "this operation takes another graph owner", &.{ .{ .name = "operation", .value = p }, .{ .name = "found", .value = l.tyText(o.ty) } }); + if (std.meta.activeTag(o.ty) != want) return l.fail("E7005", args[0].span, "this operation takes another graph owner", &.{ .{ .name = "operation", .value = p }, .{ .name = "found", .value = l.diagnosticTyText(o.ty) } }); try l.emit(try l.fmt("{s} %{s}", .{ p, o.name }), e.span); return .{ .name = "", .ty = .void }; } @@ -2398,7 +2670,7 @@ const Lowerer = struct { return v; } if (b.ty == .ref and b.ty.inner().? == .arc) return try l.def("arc", b.ty.inner().?, try l.fmt("arc.clone %{s}", .{b.value}), e.span); - return l.fail("E7005", args[0].span, "`arc.clone` takes an `arc`", &.{.{ .name = "found", .value = l.tyText(b.ty) }}); + return l.fail("E7005", args[0].span, "`arc.clone` takes an `arc`", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}); } if (eq(p, "island.at") or eq(p, "frozen.at") or eq(p, "arc.at")) return l.fail("E7006", e.span, "a graph access is a borrow: bind it with `ref x = island.at(g, r);` or `mut x = island.at(g, r);`", &.{}); @@ -2411,13 +2683,13 @@ const Lowerer = struct { if (eq(p, "mutex.take")) { if (args.len != 1) return l.fail("E7005", e.span, "`mutex.take` takes one mutex", &.{}); const m = try l.consuming(args[0], null); - if (m.ty != .mutex) return l.fail("E7005", args[0].span, "`mutex.take` takes a `mutex`", &.{.{ .name = "found", .value = l.tyText(m.ty) }}); + if (m.ty != .mutex) return l.fail("E7005", args[0].span, "`mutex.take` takes a `mutex`", &.{.{ .name = "found", .value = l.diagnosticTyText(m.ty) }}); return try l.def("v", m.ty.mutex.*, try l.fmt("mutex.take %{s}", .{m.name}), e.span); } if (eq(p, "channel.close_sender")) { if (args.len != 1) return l.fail("E7005", e.span, "`channel.close_sender` takes one sender", &.{}); const tx = try l.consuming(args[0], null); - if (tx.ty != .sender) return l.fail("E7005", args[0].span, "`channel.close_sender` takes a `sender`", &.{.{ .name = "found", .value = l.tyText(tx.ty) }}); + if (tx.ty != .sender) return l.fail("E7005", args[0].span, "`channel.close_sender` takes a `sender`", &.{.{ .name = "found", .value = l.diagnosticTyText(tx.ty) }}); try l.emit(try l.fmt("channel.close_sender %{s}", .{tx.name}), e.span); return .{ .name = "", .ty = .void }; } @@ -2439,8 +2711,8 @@ const Lowerer = struct { try temps.append(l.arena, v.name); break :blk v; }, - .ref => if (b.ty.ref.* == .mutex) .{ .name = b.value, .ty = b.ty } else return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.tyText(b.ty) }}), - else => return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.tyText(b.ty) }}), + .ref => if (b.ty.ref.* == .mutex) .{ .name = b.value, .ty = b.ty } else return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}), + else => return l.fail("E7005", place.span, "`lock` needs a mutex", &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}), }; const elem = mr.ty.ref.mutex.*; const depth = l.bindings.items.len; @@ -2611,7 +2883,7 @@ const Lowerer = struct { /// scope, task, shield or guard, at any depth. Endpoints inside are the /// reserved `channel_transfer`, left to the verifier (`E0006`). fn elementRule(l: *Lowerer, t: Ty, span: Span, what: []const u8) Error!void { - if (try l.forbiddenIn(t, 0)) |bad| return l.fail("E7005", span, try l.fmt("{s} contains no borrow, scope, task, shield or guard", .{what}), &.{ .{ .name = "type", .value = l.tyText(t) }, .{ .name = "found", .value = l.tyText(bad) } }); + if (try l.forbiddenIn(t, 0)) |bad| return l.fail("E7005", span, try l.fmt("{s} contains no borrow, scope, task, shield or guard", .{what}), &.{ .{ .name = "type", .value = l.diagnosticTyText(t) }, .{ .name = "found", .value = l.diagnosticTyText(bad) } }); } fn forbiddenIn(l: *Lowerer, t: Ty, depth: u32) Error!?Ty { @@ -2619,7 +2891,7 @@ const Lowerer = struct { return switch (t) { .ref, .mut, .slice, .slice_mut, .scope, .task, .shield, .guard => t, .array => |a| l.forbiddenIn(a.elem, depth + 1), - .own, .own_array, .mutex => |x| l.forbiddenIn(x.*, depth + 1), + .own, .own_array, .buffer, .mutex => |x| l.forbiddenIn(x.*, depth + 1), .named => |i| blk: { const d = l.m.types[i]; switch (d.kind) { @@ -2641,12 +2913,37 @@ const Lowerer = struct { const tag = std.meta.stringToEnum(std.meta.Tag(Ty), owner).?; if (std.meta.activeTag(b.ty) == tag) return l.fail("E7005", a.span, try l.fmt("this takes a borrow of the {s}, not the owner: bind `{s} g = {s};` in an enclosing block and pass `g`", .{ owner, if (mutable) "mut" else "ref", a.kind.name }), &.{.{ .name = "name", .value = a.kind.name }}); const ok = (b.ty == .ref or (b.ty == .mut and !mutable) or (b.ty == .mut and mutable)) and std.meta.activeTag(b.ty.inner().?) == tag; - if (!ok or (mutable and b.ty != .mut)) return l.fail("E7005", a.span, try l.fmt("a {s} borrow of an `{s}` is expected here", .{ if (mutable) "`mut`" else "`ref` or `mut`", owner }), &.{.{ .name = "found", .value = l.tyText(b.ty) }}); + if (!ok or (mutable and b.ty != .mut)) return l.fail("E7005", a.span, try l.fmt("a {s} borrow of an `{s}` is expected here", .{ if (mutable) "`mut`" else "`ref` or `mut`", owner }), &.{.{ .name = "found", .value = l.diagnosticTyText(b.ty) }}); return .{ .name = b.value, .ty = b.ty }; } - /// `ref x = island.at(g, r);` / `mut x = island.at(g, r);`, and - /// `frozen.at`, `arc.at` (`ref` only): a child borrow of `g`. + /// Buffer operations require an explicit named borrow of the handle. + fn bufferBorrow(l: *Lowerer, e: ast.Expr, mutable: bool) Error!Value { + if (e.kind == .name) if (l.lookup(e.kind.name)) |b| { + if ((b.ty == .mut or (!mutable and b.ty == .ref)) and b.ty.inner().? == .buffer) return .{ .name = b.value, .ty = b.ty }; + }; + return l.fail("E7005", e.span, if (mutable) "bind a named mut> first" else "bind a named ref/mut> first", &.{}); + } + + fn bufferView(l: *Lowerer, s: ast.Stmt, name_: []const u8, mutable: bool, place: ast.Expr) Error!void { + const args = place.kind.call.args; + if (args.len != 1) return l.fail("E7005", place.span, "buffer.view takes one named buffer borrow", &.{}); + const parent = try l.bufferBorrow(args[0], mutable); + // A shared view from a mutable parent uses an explicit shared reborrow. + var borrow = parent; + var shared_end: ?[]const u8 = null; + if (!mutable and parent.ty == .mut) { + borrow = try l.def("buffer_ref", try l.wrap(.ref, parent.ty.inner().?), try l.fmt("borrow.ref %{s}", .{parent.name}), place.span); + shared_end = borrow.name; + } + const ty = if (mutable) try l.wrap(.slice_mut, parent.ty.inner().?.buffer.*) else try l.wrap(.slice, parent.ty.inner().?.buffer.*); + const view = try l.def(name_, ty, try l.fmt("buffer.view %{s}", .{borrow.name}), place.span); + if (shared_end) |n| try l.scopeEnds(&.{n}, s.span); + try l.scopeEnds(&.{view.name}, s.span); + try l.bindings.append(l.arena, .{ .name = name_, .mutable = false, .value = view.name, .ty = ty, .kind = .borrow }); + } + + /// Graph access binds a child borrow of its named graph borrow. fn graphAccess(l: *Lowerer, s: ast.Stmt, name: []const u8, mutable: bool, place: ast.Expr) Error!void { const ac = place.kind.call; const p = pathOf(ac.callee.*).?; @@ -2655,7 +2952,7 @@ const Lowerer = struct { if (ac.args.len != 2) return l.fail("E7005", place.span, "`.at` takes the graph's borrow binding and an `iref`", &.{}); const g = try l.graphBorrow(ac.args[0], owner, mutable); const r = try l.expr(ac.args[1], null); - if (r.ty != .iref) return l.fail("E7005", ac.args[1].span, "an `iref` is expected here", &.{.{ .name = "found", .value = l.tyText(r.ty) }}); + if (r.ty != .iref) return l.fail("E7005", ac.args[1].span, "an `iref` is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(r.ty) }}); const op = if (std.mem.eql(u8, owner, "island")) "island.borrow" else if (std.mem.eql(u8, owner, "frozen")) "frozen.borrow" else "arc.borrow"; const target = r.ty.inner().?; const v = try l.def(name, if (mutable) try l.wrap(.mut, target) else try l.wrap(.ref, target), try l.fmt("{s} %{s}, %{s}", .{ op, g.name, r.name }), s.span); @@ -2685,14 +2982,14 @@ const Lowerer = struct { const want: Ty = if (o == .bytes) try l.wrap(.slice, .{ .int = "u8" }) else try l.wrap(.slice_mut, .{ .int = "u8" }); if (o == .buffer and a.kind == .bytes) return l.fail("E7005", a.span, "this operand is a buffer the operation writes: pass `mut buf`", &.{}); const v = try l.argument(a, want, temps); - if (!v.ty.eql(want)) return l.fail("E7005", a.span, if (o == .bytes) "bytes are passed as a borrow: `ref buf`, `ref buf[a..b]` or a byte string `b\"…\"`" else "a buffer is passed as `mut buf` or `mut buf[a..b]`", &.{ .{ .name = "expected", .value = l.tyText(want) }, .{ .name = "found", .value = l.tyText(v.ty) } }); + if (!v.ty.eql(want)) return l.fail("E7005", a.span, if (o == .bytes) "bytes are passed as a borrow: `ref buf`, `ref buf[a..b]` or a byte string `b\"…\"`" else "a buffer is passed as `mut buf` or `mut buf[a..b]`", &.{ .{ .name = "expected", .value = l.diagnosticTyText(want) }, .{ .name = "found", .value = l.diagnosticTyText(v.ty) } }); break :blk v; }, .borrowed => |rs| try l.resourceOperand(a, rs, temps), .consumed => |rs| blk: { const v = try l.consuming(a, null); if (v.ty != .resource or std.mem.indexOfScalar(authority.Resource, rs, v.ty.resource) == null) - return l.fail("E7005", a.span, "this operation consumes a resource of another type", &.{ .{ .name = "operation", .value = x.name }, .{ .name = "found", .value = l.tyText(v.ty) } }); + return l.fail("E7005", a.span, "this operation consumes a resource of another type", &.{ .{ .name = "operation", .value = x.name }, .{ .name = "found", .value = l.diagnosticTyText(v.ty) } }); break :blk v; }, }; @@ -2714,7 +3011,7 @@ const Lowerer = struct { else => null, }; if (r == null or std.mem.indexOfScalar(authority.Resource, rs, r.?) == null) - return l.fail("E7005", a.span, "this operation needs a resource of another type", &.{ .{ .name = "expected", .value = expected }, .{ .name = "found", .value = l.tyText(b.ty) } }); + return l.fail("E7005", a.span, "this operation needs a resource of another type", &.{ .{ .name = "expected", .value = expected }, .{ .name = "found", .value = l.diagnosticTyText(b.ty) } }); if (b.ty == .mut) return .{ .name = b.value, .ty = b.ty }; const v = try l.def(a.kind.name, try l.wrap(.mut, b.ty), try l.fmt("borrow.mut %{s}", .{b.value}), a.span); try temps.append(l.arena, v.name); @@ -2729,7 +3026,7 @@ const Lowerer = struct { fn expectCap(l: *Lowerer, a: ast.Expr, kind: []const u8) Error!Value { const c = try l.expr(a, null); - if (c.ty != .cap) return l.fail("E7005", a.span, "a capability is expected here", &.{ .{ .name = "expected", .value = try l.fmt("cap<{s}>", .{kind}) }, .{ .name = "found", .value = l.tyText(c.ty) } }); + if (c.ty != .cap) return l.fail("E7005", a.span, "a capability is expected here", &.{ .{ .name = "expected", .value = try l.fmt("cap<{s}>", .{kind}) }, .{ .name = "found", .value = l.diagnosticTyText(c.ty) } }); return c; } @@ -2755,6 +3052,45 @@ const Lowerer = struct { }.n; const alloc_err: Ty = .{ .builtin = .alloc_error }; const usize_ty: Ty = .{ .int = "usize" }; + if (std.mem.eql(u8, path, "buffer.new")) { + try want(l, e.span, args, 2, path); + const source_ty = e.kind.call.type_arg orelse return l.fail("E7005", e.span, "buffer.new needs an explicit content type", &.{}); + const ty = try l.typeOf(source_ty); + const n = try l.expr(args[0], usize_ty); + try l.checkTy(args[0].span, n.ty, usize_ty); + const cap = try l.expectCap(args[1], "mem.alloc"); + return .{ .text = try l.fmt("buffer.new {s} %{s}, %{s}", .{ l.tyText(ty), n.name, cap.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{try l.wrap(.buffer, ty)} }, .{ .role = "err", .params = &.{alloc_err} } }) }; + } + if (std.mem.eql(u8, path, "buffer.free")) { + try want(l, e.span, args, 1, path); + const v = try l.consuming(args[0], null); + if (v.ty != .buffer) return l.fail("E7005", e.span, "buffer.free consumes a buffer", &.{}); + return .{ .text = try l.fmt("buffer.free %{s}", .{v.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "err", .params = &.{v.ty} } }) }; + } + if (std.mem.eql(u8, path, "buffer.push") or std.mem.eql(u8, path, "buffer.pop") or std.mem.eql(u8, path, "buffer.reserve")) { + const is_push = std.mem.eql(u8, path, "buffer.push"); + const is_pop = std.mem.eql(u8, path, "buffer.pop"); + try want(l, e.span, args, if (is_push) 2 else if (is_pop) 1 else 3, path); + const b = try l.bufferBorrow(args[0], true); + const ty = b.ty.inner().?.buffer.*; + if (is_push) { + const v = try l.consuming(args[1], ty); + try l.checkTy(args[1].span, v.ty, ty); + return .{ .text = try l.fmt("buffer.push %{s}, %{s}", .{ b.name, v.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "err", .params = &.{ty} } }) }; + } + if (is_pop) return .{ .text = try l.fmt("buffer.pop %{s}", .{b.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{ty} }, .{ .role = "err", .params = &.{} } }) }; + const n = try l.expr(args[1], usize_ty); + try l.checkTy(args[1].span, n.ty, usize_ty); + const cap = try l.expectCap(args[2], "mem.alloc"); + return .{ .text = try l.fmt("buffer.reserve %{s}, %{s}, %{s}", .{ b.name, n.name, cap.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "err", .params = &.{alloc_err} } }) }; + } + if (std.mem.eql(u8, path, "own.pack")) { + try want(l, e.span, args, 2, path); + const v = try l.consuming(args[0], null); + const c = try l.expectCap(args[1], "mem.alloc"); + l.linear_enabled = true; + return .{ .text = try l.fmt("own.pack {s} %{s}, %{s}", .{ l.tyText(v.ty), v.name, c.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{try l.wrap(.own, v.ty)} }, .{ .role = "err", .params = &.{ alloc_err, v.ty } } }) }; + } if (std.mem.eql(u8, path, "own.new")) { try want(l, e.span, args, 2, path); const v = try l.consuming(args[0], null); @@ -2822,7 +3158,7 @@ const Lowerer = struct { if (std.mem.eql(u8, path, "task.join_cancel")) { try want(l, e.span, args, 1, path); const t = try l.consuming(args[0], null); - if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join_cancel` takes a `task`", &.{.{ .name = "found", .value = l.tyText(t.ty) }}); + if (t.ty != .task) return l.fail("E7005", args[0].span, "`task.join_cancel` takes a `task`", &.{.{ .name = "found", .value = l.diagnosticTyText(t.ty) }}); const rt = t.ty.task.*; const ok: []const Ty = if (rt == .void) &.{} else &.{rt}; return .{ .text = try l.fmt("task.join.cancel %{s}", .{t.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = ok }, .{ .role = "cancelled", .params = &.{t.ty} } }) }; @@ -2856,23 +3192,23 @@ const Lowerer = struct { if (std.mem.eql(u8, path, "channel.close_receiver")) { try want(l, e.span, args, 1, path); const rx = try l.consuming(args[0], null); - if (rx.ty != .receiver) return l.fail("E7005", args[0].span, "`channel.close_receiver` takes a `receiver`", &.{.{ .name = "found", .value = l.tyText(rx.ty) }}); + if (rx.ty != .receiver) return l.fail("E7005", args[0].span, "`channel.close_receiver` takes a `receiver`", &.{.{ .name = "found", .value = l.diagnosticTyText(rx.ty) }}); return .{ .text = try l.fmt("channel.close_receiver %{s}", .{rx.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "pending", .params = &.{rx.ty} } }) }; } if (std.mem.eql(u8, path, "cap.narrow.prefix")) { try want(l, e.span, args, 2, path); const c = try l.expr(args[0], null); - if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.tyText(c.ty) }}); + if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }}); var temps: std.ArrayList([]const u8) = .empty; const bytes = try l.wrap(.slice, .{ .int = "u8" }); const p = try l.argument(args[1], bytes, &temps); - if (!p.ty.eql(bytes)) return l.fail("E7005", args[1].span, "the path is a byte string or a `ref` borrow of bytes", &.{.{ .name = "found", .value = l.tyText(p.ty) }}); + if (!p.ty.eql(bytes)) return l.fail("E7005", args[1].span, "the path is a byte string or a `ref` borrow of bytes", &.{.{ .name = "found", .value = l.diagnosticTyText(p.ty) }}); return .{ .text = try l.fmt("cap.narrow.prefix %{s}, %{s}", .{ c.name, p.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{c.ty} }, .{ .role = "err", .params = &.{.{ .builtin = .cap_error }} } }), .temps = temps.items }; } if (std.mem.eql(u8, path, "cap.narrow.budget")) { try want(l, e.span, args, 2, path); const c = try l.expr(args[0], null); - if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.tyText(c.ty) }}); + if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }}); const n = try l.expr(args[1], usize_ty); try l.checkTy(args[1].span, n.ty, usize_ty); return .{ .text = try l.fmt("cap.narrow.budget %{s}, %{s}", .{ c.name, n.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{c.ty} }, .{ .role = "err", .params = &.{.{ .builtin = .cap_error }} } }) }; @@ -3048,17 +3384,15 @@ fn elemOf(t: Ty) ?Ty { /// `cap.narrow.budget`; null for anything else. fn pathOf(e: ast.Expr) ?[]const u8 { const known = [_][]const u8{ - "slice.copy", "own.new", "own.array", "own.take", "own.free", - "region.create", "region.new", "region.array", "region.reset", "region.destroy", - "cap.narrow.budget", "cap.narrow.prefix", "task.spawn", "task.join", "task.cancel", - "task.cancelled", "channel.make", "channel.dup", "channel.send", "channel.recv", - "channel.close_sender", "channel.close_receiver", "mutex.make", "mutex.take", "task.check_cancel", - "task.join_cancel", "island.create", "island.alloc", "island.root", "island.at", - "island.freeze", "island.destroy", "frozen.root", "frozen.at", "frozen.release", - "arc.from_frozen", "arc.new", "arc.clone", "arc.release", "arc.root", - "arc.at", "atomic.new", "atomic.take", "atomic.load", "atomic.store", - "atomic.swap", "atomic.add.wrap", "atomic.sub.wrap", "atomic.and", "atomic.or", - "atomic.xor", "atomic.compare_exchange", "atomic.fence", + "buffer.new", "buffer.len", "buffer.capacity", "buffer.reserve", "buffer.push", "buffer.pop", "buffer.view", "buffer.free", + "struct.unpack", "array.unpack", "value.swap", "own.pack", "slice.copy", "own.new", "own.array", "own.take", + "own.free", "region.create", "region.new", "region.array", "region.reset", "region.destroy", "cap.narrow.budget", "cap.narrow.prefix", + "task.spawn", "task.join", "task.cancel", "task.cancelled", "channel.make", "channel.dup", "channel.send", "channel.recv", + "channel.close_sender", "channel.close_receiver", "mutex.make", "mutex.take", "task.check_cancel", "task.join_cancel", "island.create", "island.alloc", + "island.root", "island.at", "island.freeze", "island.destroy", "frozen.root", "frozen.at", "frozen.release", "arc.from_frozen", + "arc.new", "arc.clone", "arc.release", "arc.root", "arc.at", "atomic.new", "atomic.take", "atomic.load", + "atomic.store", "atomic.swap", "atomic.add.wrap", "atomic.sub.wrap", "atomic.and", "atomic.or", "atomic.xor", "atomic.compare_exchange", + "atomic.fence", }; var buf: [64]u8 = undefined; const text = dotted(e, &buf) orelse return null; @@ -3086,6 +3420,13 @@ fn dotted(e: ast.Expr, buf: []u8) ?[]const u8 { } } +fn standardPath(e: ast.Expr) bool { + if (e.kind != .field) return false; + var root = e; + while (root.kind == .field) root = root.kind.field.e.*; + return root.kind == .name and std.mem.eql(u8, root.kind.name, "std"); +} + fn box(arena: Allocator, e: ast.Expr) Error!*const ast.Expr { const b = try arena.create(ast.Expr); b.* = e; @@ -3152,7 +3493,7 @@ fn exprReads(e: ast.Expr, name: []const u8, skip: ?Span) bool { return switch (e.kind) { .name => |n| std.mem.eql(u8, n, name), .move => |n| std.mem.eql(u8, n, name), - .int, .boolean, .bytes, .variant => false, + .int, .boolean, .bytes, .variant, .specialize => false, .neg, .not, .deref, .or_trap => |x| exprReads(x.*, name, skip), .borrow => |x| exprReads(x.place.*, name, skip), .binary => |x| exprReads(x.l.*, name, skip) or exprReads(x.r.*, name, skip), @@ -3169,6 +3510,9 @@ fn exprReads(e: ast.Expr, name: []const u8, skip: ?Span) bool { break :blk false; }, .array_rep => |x| exprReads(x.e.*, name, skip), + .array_list => |xs| for (xs) |x| { + if (exprReads(x, name, skip)) break true; + } else false, .if_expr => |x| ifReads(x.*, name, skip), .match_expr => |x| blk: { if (exprReads(x.scrutinee, name, skip)) break :blk true; @@ -3213,7 +3557,7 @@ const After = struct { } return switch (e.kind) { .name, .move => |n| w.seen and std.mem.eql(u8, n, w.name), - .int, .boolean, .bytes, .variant => false, + .int, .boolean, .bytes, .variant, .specialize => false, .neg, .not, .deref, .or_trap => |x| w.expr(x.*), .borrow => |x| w.expr(x.place.*), .binary => |x| w.expr(x.l.*) or w.expr(x.r.*), @@ -3230,6 +3574,9 @@ const After = struct { break :blk false; }, .array_rep => |x| w.expr(x.e.*), + .array_list => |xs| for (xs) |x| { + if (w.expr(x)) break true; + } else false, .if_expr => |x| w.ifExpr(x.*), .match_expr => |x| blk: { if (w.expr(x.scrutinee)) break :blk true; @@ -3388,6 +3735,9 @@ fn exprAssigns(e: ast.Expr, name: []const u8) bool { .field => |x| exprAssigns(x.e.*, name), .index => |x| exprAssigns(x.e.*, name) or exprAssigns(x.lo.*, name) or (if (x.hi) |h| exprAssigns(h.*, name) else false), .array_rep => |x| exprAssigns(x.e.*, name), + .array_list => |xs| for (xs) |x| { + if (exprAssigns(x, name)) break true; + } else false, else => false, }; } @@ -3418,3 +3768,30 @@ fn selectAssigns(x: ast.Select, name: []const u8) bool { for (x.cancelled_binds) |b| if (std.mem.eql(u8, b, name)) return true; return exprAssigns(x.cancelled, name); } + +fn localName(full: []const u8, module: []const u8, short: []const u8) bool { + return full.len == module.len + 1 + short.len and std.mem.startsWith(u8, full, module) and full[module.len] == '.' and std.mem.eql(u8, full[module.len + 1 ..], short); +} + +fn expressionPath(arena: Allocator, e: ast.Expr) Allocator.Error!?[]const u8 { + return switch (e.kind) { + .name => |name| name, + .field => |field| if (try expressionPath(arena, field.e.*)) |base| try std.fmt.allocPrint(arena, "{s}.{s}", .{ base, field.name }) else null, + else => null, + }; +} + +// Bound property queries before invoking recursive verifier derivations. +fn boundedType(m: air_module.Module, t: air_module.Type, depth: usize) bool { + if (depth >= 64) return false; + if (t == .named) return switch (m.types[t.named].kind) { + .@"struct" => |fs| for (fs) |f| { + if (!boundedType(m, f.ty, depth + 1)) break false; + } else true, + .@"enum" => |vs| blk: { + for (vs) |v| for (v.payload) |p| if (!boundedType(m, p, depth + 1)) break :blk false; + break :blk true; + }, + }; + return if (t.inner()) |inner| boundedType(m, inner, depth + 1) else true; +} diff --git a/src/frontend/modules.zig b/src/frontend/modules.zig new file mode 100644 index 0000000..092b8de --- /dev/null +++ b/src/frontend/modules.zig @@ -0,0 +1,152 @@ +//! Pure linking of explicit source inputs; no filesystem or authority. +const std = @import("std"); +const ast = @import("ast.zig"); +const parse = @import("parse.zig"); +const lower = @import("lower.zig"); +const stdlib = @import("stdlib.zig"); +const authority = @import("../air/authority.zig"); + +pub const Source = stdlib.Source; +pub const Result = union(enum) { ok: ast.Module, err: lower.Problem }; +const Error = error{ OutOfMemory, InvalidSource }; +const Node = struct { module: ast.Module, active: bool, height: usize = 0 }; + +pub fn reserved(name: []const u8) bool { + const first = if (std.mem.indexOfScalar(u8, name, '.')) |at| name[0..at] else name; + for ([_][]const u8{ "std", "slice", "buffer", "own", "region", "cap", "task", "channel", "mutex", "island", "frozen", "arc", "atomic" }) |word| { + if (std.mem.eql(u8, first, word)) return true; + } + for (authority.intrinsics) |intrinsic| { + const at = std.mem.indexOfScalar(u8, intrinsic.name, '.').?; + if (std.mem.eql(u8, first, intrinsic.name[0..at])) return true; + } + return false; +} + +pub fn link(arena: std.mem.Allocator, entry: ast.Module, sources: []const Source) std.mem.Allocator.Error!Result { + var g: Graph = .{ .arena = arena, .sources = sources }; + const span: ast.Span = if (entry.functions.len != 0) entry.functions[0].span else .{ .start = .{ .line = 1, .col = 1 }, .end = .{ .line = 1, .col = 1 } }; + const combined = g.run(entry, span) catch |err| switch (err) { + error.OutOfMemory => return error.OutOfMemory, + error.InvalidSource => return .{ .err = g.problem.? }, + }; + return .{ .ok = combined }; +} + +const Graph = struct { + arena: std.mem.Allocator, + sources: []const Source, + nodes: std.ArrayList(Node) = .empty, + problem: ?lower.Problem = null, + + fn fail(g: *Graph, code: []const u8, span: ast.Span, message: []const u8, name: []const u8) Error { + g.problem = .{ .code = code, .span = span, .message = message, .fields = g.arena.dupe(lower.Problem.Field, &.{.{ .name = "name", .value = name }}) catch return error.OutOfMemory }; + return error.InvalidSource; + } + + fn run(g: *Graph, entry: ast.Module, span: ast.Span) Error!ast.Module { + if (g.sources.len > 1024) return g.fail("E7006", span, "more than 1024 mapped modules", entry.name); + for (g.sources, 0..) |source, i| { + if (reserved(source.name)) return g.fail("E7006", span, "package mapping uses a reserved namespace", source.name); + for (g.sources[0..i]) |previous| if (std.mem.eql(u8, previous.name, source.name)) return g.fail("E7006", span, "module mapped twice", source.name); + } + try g.nodes.append(g.arena, .{ .module = entry, .active = true }); + const root_height = try g.imports(entry, 0); + g.nodes.items[0].height = root_height; + g.nodes.items[0].active = false; + std.mem.sort(Node, g.nodes.items[1..], {}, struct { + fn less(_: void, a: Node, b: Node) bool { + return std.mem.lessThan(u8, a.module.name, b.module.name); + } + }.less); + var types: std.ArrayList(ast.TypeDecl) = .empty; + var functions: std.ArrayList(ast.FnDecl) = .empty; + var scopes: std.ArrayList(ast.ModuleScope) = .empty; + try types.appendSlice(g.arena, entry.types); + try functions.appendSlice(g.arena, entry.functions); + for (g.nodes.items, 0..) |node, i| { + const m = node.module; + try scopes.append(g.arena, .{ .name = m.name, .entry = i == 0, .qualified_self = i != 0 or !reserved(m.name), .imports = m.imports }); + if (i == 0) continue; + for (m.types) |t| { + var qualified = t; + qualified.name = try std.fmt.allocPrint(g.arena, "{s}.{s}", .{ m.name, t.name }); + qualified.air_name = try airName(g.arena, m.name, t.name, types.items, functions.items); + try types.append(g.arena, qualified); + } + for (m.functions) |f| { + var qualified = f; + qualified.name = try std.fmt.allocPrint(g.arena, "{s}.{s}", .{ m.name, f.name }); + qualified.air_name = try airName(g.arena, m.name, f.name, types.items, functions.items); + try functions.append(g.arena, qualified); + } + } + var result = entry; + result.types = types.items; + result.functions = functions.items; + result.scopes = scopes.items; + return result; + } + + fn imports(g: *Graph, m: ast.Module, depth: usize) Error!usize { + var height: usize = 0; + for (m.imports, 0..) |imp, i| { + for (m.imports[0..i]) |previous| if (std.mem.eql(u8, imp.path, previous.path)) return g.fail("E7006", imp.span, "module imported twice", imp.path); + height = @max(height, 1 + try g.visit(imp, depth + 1)); + } + return height; + } + + fn visit(g: *Graph, imp: ast.Import, depth: usize) Error!usize { + for (g.nodes.items) |node| if (std.mem.eql(u8, node.module.name, imp.path)) { + if (node.active) return g.fail("E7006", imp.span, "cyclic module import", imp.path); + if (depth + node.height > 256) return g.fail("E7006", imp.span, "module import depth exceeds 256", imp.path); + return node.height; + }; + if (depth > 256) return g.fail("E7006", imp.span, "module import depth exceeds 256", imp.path); + const source = for (stdlib.registry) |source| { + if (std.mem.eql(u8, source.name, imp.path)) break source; + } else for (g.sources) |source| { + if (std.mem.eql(u8, source.name, imp.path)) break source; + } else return g.fail("E7002", imp.span, "unknown module in explicit source mapping", imp.path); + const m = switch (try parse.parseWithFile(g.arena, source.source, source.file)) { + .ok => |m| m, + .err => |failure| { + g.problem = .{ + .code = if (std.mem.startsWith(u8, source.name, "std.")) "E7900" else "E7001", + .span = .{ .start = failure.pos, .end = failure.pos, .file = source.file, .namespace = source.name }, + .message = try std.fmt.allocPrint(g.arena, "expected {s}", .{failure.expected}), + .fields = try g.arena.dupe(lower.Problem.Field, &.{ .{ .name = "expected", .value = failure.expected }, .{ .name = "found", .value = failure.found } }), + }; + return error.InvalidSource; + }, + }; + if (!std.mem.eql(u8, m.name, source.name)) return g.fail("E7006", .{ .start = .{ .line = 1, .col = 1 }, .end = .{ .line = 1, .col = 1 }, .file = source.file, .namespace = source.name }, "module header differs from its mapped name", source.name); + const index = g.nodes.items.len; + try g.nodes.append(g.arena, .{ .module = m, .active = true }); + const height = try g.imports(m, depth); + g.nodes.items[index].height = height; + g.nodes.items[index].active = false; + return g.nodes.items[index].height; + } +}; + +fn airName(arena: std.mem.Allocator, module: []const u8, name: []const u8, types: []const ast.TypeDecl, functions: []const ast.FnDecl) std.mem.Allocator.Error![]const u8 { + const base = try std.fmt.allocPrint(arena, "__aji_{s}_{s}", .{ module, name }); + for (base) |*c| if (c.* == '.') { + c.* = '_'; + }; + var candidate: []const u8 = base; + var suffix: usize = 0; + while (used(types, functions, candidate)) { + suffix += 1; + candidate = try std.fmt.allocPrint(arena, "{s}_{d}", .{ base, suffix }); + } + return candidate; +} + +fn used(types: []const ast.TypeDecl, functions: []const ast.FnDecl, name: []const u8) bool { + for (types) |t| if (std.mem.eql(u8, t.air_name orelse t.name, name)) return true; + for (functions) |f| if (std.mem.eql(u8, f.air_name orelse f.name, name)) return true; + return false; +} diff --git a/src/frontend/parse.zig b/src/frontend/parse.zig index 1d9fbd3..6822d3a 100644 --- a/src/frontend/parse.zig +++ b/src/frontend/parse.zig @@ -15,8 +15,12 @@ pub const Failure = struct { pos: lex.Pos, expected: []const u8, found: []const pub const Result = union(enum) { ok: ast.Module, err: Failure }; pub fn parse(arena: Allocator, src: []const u8) Allocator.Error!Result { + return parseWithFile(arena, src, null); +} + +pub fn parseWithFile(arena: Allocator, src: []const u8, file: ?[]const u8) Allocator.Error!Result { const tokens = try lex.tokenize(arena, src); - var p: Parser = .{ .arena = arena, .tokens = try arena.dupe(Token, tokens) }; + var p: Parser = .{ .arena = arena, .tokens = try arena.dupe(Token, tokens), .file = file }; const m = p.module() catch |e| switch (e) { error.Syntax => return .{ .err = p.failure.? }, error.OutOfMemory => return error.OutOfMemory, @@ -31,6 +35,8 @@ const Parser = struct { tokens: []Token, pos: usize = 0, failure: ?Failure = null, + file: ?[]const u8 = null, + module_name: ?[]const u8 = null, /// Struct literals are not allowed where a `{` starts a block (conditions). no_struct: bool = false, @@ -99,7 +105,7 @@ const Parser = struct { } fn span(p: *Parser, start: lex.Pos) ast.Span { - return .{ .start = start, .end = p.prevEnd() }; + return .{ .start = start, .end = p.prevEnd(), .file = p.file, .namespace = p.module_name }; } fn box(p: *Parser, comptime T: type, v: T) Error!*const T { @@ -113,6 +119,14 @@ const Parser = struct { fn module(p: *Parser) Error!ast.Module { _ = try p.expectWord("module"); const name = try p.path(); + p.module_name = name; + var imports: std.ArrayList(ast.Import) = .empty; + while (p.atWord("import")) { + const start = p.next().pos; + const path_name = try p.path(); + _ = try p.expect(.semicolon, "`;` after import"); + try imports.append(p.arena, .{ .path = path_name, .span = p.span(start) }); + } var types: std.ArrayList(ast.TypeDecl) = .empty; var fns: std.ArrayList(ast.FnDecl) = .empty; while (p.peek().tag != .eof) { @@ -122,7 +136,7 @@ const Parser = struct { try fns.append(p.arena, try p.fnDecl()); } else return p.fail(p.peek(), "`struct`, `enum` or `fn`"); } - return .{ .name = name, .types = types.items, .functions = fns.items }; + return .{ .name = name, .imports = imports.items, .types = types.items, .functions = fns.items }; } fn path(p: *Parser) Error![]const u8 { @@ -142,6 +156,7 @@ const Parser = struct { const is_struct = p.atWord("struct"); _ = p.next(); const name = try p.ident("type name"); + const generics = try p.typeParams(); _ = try p.expect(.l_brace, "`{`"); if (is_struct) { var fields: std.ArrayList(ast.Field) = .empty; @@ -155,7 +170,7 @@ const Parser = struct { _ = p.next(); } _ = try p.expect(.r_brace, "`}`"); - return .{ .name = name, .span = p.span(start), .kind = .{ .@"struct" = fields.items } }; + return .{ .name = name, .generics = generics, .span = p.span(start), .kind = .{ .@"struct" = fields.items } }; } var vs: std.ArrayList(ast.Variant) = .empty; while (p.peek().tag != .r_brace) { @@ -176,12 +191,13 @@ const Parser = struct { _ = p.next(); } _ = try p.expect(.r_brace, "`}`"); - return .{ .name = name, .span = p.span(start), .kind = .{ .@"enum" = vs.items } }; + return .{ .name = name, .generics = generics, .span = p.span(start), .kind = .{ .@"enum" = vs.items } }; } fn fnDecl(p: *Parser) Error!ast.FnDecl { const start = p.next().pos; // `fn` const name = try p.ident("function name"); + const generics = try p.typeParams(); _ = try p.expect(.l_paren, "`(`"); var params: std.ArrayList(ast.Param) = .empty; while (p.peek().tag != .r_paren) { @@ -219,7 +235,7 @@ const Parser = struct { trusted = t.text; } const body = try p.block(); - return .{ .name = name, .span = p.span(start), .params = params.items, .ret = ret, .from = from, .effects = effects.items, .trusted = trusted, .body = body }; + return .{ .name = name, .generics = generics, .span = p.span(start), .params = params.items, .ret = ret, .from = from, .effects = effects.items, .trusted = trusted, .body = body }; } // ------------------------------------------------------------ types @@ -238,21 +254,98 @@ const Parser = struct { const t = p.peek(); if (t.tag != .ident) return p.fail(t, "a type"); _ = p.next(); - if (p.peek().tag != .lt) return .{ .span = p.span(start), .kind = .{ .name = t.text } }; - _ = p.next(); - if (std.mem.eql(u8, t.text, "cap")) { - const k = try p.path(); + const name = if (p.peek().tag == .dot) try p.pathTail(t.text) else t.text; + if (p.peek().tag != .lt) return .{ .span = p.span(start), .kind = .{ .name = name } }; + if (std.mem.eql(u8, name, "cap") or std.mem.eql(u8, name, "file")) { + _ = p.next(); + const value = try p.path(); try p.closeAngle(); - return .{ .span = p.span(start), .kind = .{ .cap = k } }; + return .{ .span = p.span(start), .kind = if (std.mem.eql(u8, name, "cap")) .{ .cap = value } else .{ .file = value } }; } - if (std.mem.eql(u8, t.text, "file")) { - const m = try p.ident("`read`, `write` or `append`"); - try p.closeAngle(); - return .{ .span = p.span(start), .kind = .{ .file = m } }; + const args = try p.typeArgs(); + const wrappers = [_][]const u8{ "ref", "mut", "slice", "slice_mut", "own", "own_array", "buffer", "task", "sender", "receiver", "mutex", "island", "frozen", "arc", "iref", "atomic" }; + for (wrappers) |wrapper| if (std.mem.eql(u8, name, wrapper)) { + if (args.len != 1) return p.fail(t, "one wrapper type argument"); + return .{ .span = p.span(start), .kind = .{ .wrapped = .{ .wrapper = name, .inner = try p.box(ast.Type, args[0]) } } }; + }; + return .{ .span = p.span(start), .kind = .{ .applied = .{ .name = name, .args = args } } }; + } + + fn typeArgs(p: *Parser) Error![]const ast.Type { + _ = try p.expect(.lt, "`<`"); + var args: std.ArrayList(ast.Type) = .empty; + try args.append(p.arena, try p.genericArg()); + while (p.peek().tag == .comma) { + _ = p.next(); + try args.append(p.arena, try p.genericArg()); } - const inner = try p.typeExpr(); try p.closeAngle(); - return .{ .span = p.span(start), .kind = .{ .wrapped = .{ .wrapper = t.text, .inner = try p.box(ast.Type, inner) } } }; + return args.items; + } + + fn genericArg(p: *Parser) Error!ast.Type { + if (!p.atWord("fn")) return p.typeExpr(); + const start = p.next().pos; + const name = try p.path(); + var args: []const ast.Type = &.{}; + if (p.peek().tag == .colon_colon) { + _ = p.next(); + args = try p.typeArgs(); + } + return .{ .span = p.span(start), .kind = .{ .function_ref = .{ .name = name, .args = args } } }; + } + + fn functionContract(p: *Parser) Error!ast.FunctionContract { + _ = try p.expectWord("fn"); + _ = try p.expect(.l_paren, "`(` in static function contract"); + var params: std.ArrayList(ast.Type) = .empty; + while (p.peek().tag != .r_paren) { + try params.append(p.arena, try p.typeExpr()); + if (p.peek().tag != .comma) break; + _ = p.next(); + } + _ = try p.expect(.r_paren, "`)`"); + _ = try p.expect(.arrow, "`->`"); + const ret = try p.typeExpr(); + _ = try p.expectWord("effects"); + _ = try p.expect(.l_bracket, "`[`"); + var effects: std.ArrayList([]const u8) = .empty; + while (p.peek().tag != .r_bracket) { + try effects.append(p.arena, try p.path()); + if (p.peek().tag != .comma) break; + _ = p.next(); + } + _ = try p.expect(.r_bracket, "`]`"); + return .{ .params = params.items, .ret = ret, .effects = effects.items }; + } + + fn typeParams(p: *Parser) Error![]const ast.TypeParam { + if (p.peek().tag != .lt) return &.{}; + _ = p.next(); + var params: std.ArrayList(ast.TypeParam) = .empty; + while (true) { + const start = p.peek().pos; + const name = try p.ident("a type parameter"); + var constraints: std.ArrayList([]const u8) = .empty; + var callable: ?*const ast.FunctionContract = null; + if (p.peek().tag == .colon) { + _ = p.next(); + if (p.atWord("fn")) { + callable = try p.box(ast.FunctionContract, try p.functionContract()); + } else { + try constraints.append(p.arena, try p.ident("a structural property")); + while (p.peek().tag == .plus) { + _ = p.next(); + try constraints.append(p.arena, try p.ident("a structural property")); + } + } + } + try params.append(p.arena, .{ .name = name, .constraints = constraints.items, .span = p.span(start), .callable = callable }); + if (p.peek().tag != .comma) break; + _ = p.next(); + } + try p.closeAngle(); + return params.items; } // ------------------------------------------------------------ statements @@ -279,11 +372,14 @@ const Parser = struct { if (isWord(t, "let")) { _ = p.next(); var names: std.ArrayList([]const u8) = .empty; - if (p.peek().tag == .l_paren) { + const tuple = p.peek().tag == .l_paren; + if (tuple) { _ = p.next(); - try names.append(p.arena, try p.ident("a name")); - _ = try p.expect(.comma, "`,`"); - try names.append(p.arena, try p.ident("a name")); + while (p.peek().tag != .r_paren) { + try names.append(p.arena, if (p.peek().tag == .underscore) p.next().text else try p.ident("a name")); + if (p.peek().tag != .comma) break; + _ = p.next(); + } _ = try p.expect(.r_paren, "`)`"); } else try names.append(p.arena, try p.ident("a name")); var ty: ?ast.Type = null; @@ -294,7 +390,7 @@ const Parser = struct { _ = try p.expect(.eq, "`=`"); const e = try p.expr(); _ = try p.expect(.semicolon, "`;`"); - return .{ .span = p.span(start), .kind = .{ .let = .{ .names = names.items, .ty = ty, .e = e } } }; + return .{ .span = p.span(start), .kind = .{ .let = .{ .names = names.items, .ty = ty, .e = e, .tuple = tuple } } }; } const unchecked_borrow = isWord(p.peekAt(1), "unchecked") and p.peekAt(2).tag == .ident and p.peekAt(3).tag == .eq; if ((isWord(t, "ref") or isWord(t, "mut")) and ((p.peekAt(1).tag == .ident and p.peekAt(2).tag == .eq) or unchecked_borrow)) { @@ -485,12 +581,17 @@ const Parser = struct { if (t.tag != .ident) return p.fail(t, "a pattern (`Enum::Variant`, an outcome, an integer or `_`)"); _ = p.next(); var qualifier: ?[]const u8 = null; - var name = t.text; + var name = try p.pathTail(t.text); + var type_args: []const ast.Type = &.{}; + if (p.peek().tag == .colon_colon and p.peekAt(1).tag == .lt) { + _ = p.next(); + type_args = try p.typeArgs(); + } if (p.peek().tag == .colon_colon) { _ = p.next(); - qualifier = t.text; + qualifier = name; name = try p.ident("a variant name"); - } + } else if (!std.mem.eql(u8, name, t.text)) return p.fail(p.peek(), "`::` after enum path"); var binds: std.ArrayList([]const u8) = .empty; if (p.peek().tag == .l_paren) { _ = p.next(); @@ -505,7 +606,7 @@ const Parser = struct { } _ = try p.expect(.r_paren, "`)`"); } - return .{ .span = p.span(start), .kind = .{ .ctor = .{ .qualifier = qualifier, .name = name, .binds = binds.items } } }; + return .{ .span = p.span(start), .kind = .{ .ctor = .{ .qualifier = qualifier, .name = name, .binds = binds.items, .type_args = type_args } } }; } // ------------------------------------------------------------ expressions @@ -618,6 +719,20 @@ const Parser = struct { var e = try p.primary(); while (true) { switch (p.peek().tag) { + .colon_colon => { + _ = p.next(); + if (p.peek().tag == .lt) { + const base = try p.box(ast.Expr, e); + const args = try p.typeArgs(); + e = .{ .span = p.span(start), .kind = .{ .specialize = .{ .base = base, .args = args } } }; + continue; + } + const base = if (e.kind == .specialize) e.kind.specialize.base.* else e; + const name = try p.exprPath(base) orelse return p.fail(p.peek(), "an enum name before `::`"); + const type_args: []const ast.Type = if (e.kind == .specialize) e.kind.specialize.args else &.{}; + const variant = try p.ident("a variant name"); + e = .{ .span = p.span(start), .kind = .{ .variant = .{ .@"enum" = name, .name = variant, .type_args = type_args } } }; + }, .dot => { _ = p.next(); // After `.` a keyword is a member name (`task.cancelled`). @@ -627,7 +742,7 @@ const Parser = struct { const base = try p.box(ast.Expr, e); e = .{ .span = p.span(start), .kind = .{ .field = .{ .e = base, .name = name } } }; // `channel.make(…)`: the only explicit type argument. - if (std.mem.eql(u8, name, "make") and p.peek().tag == .lt and e.kind.field.e.kind == .name and std.mem.eql(u8, e.kind.field.e.kind.name, "channel")) { + if (p.peek().tag == .lt and e.kind.field.e.kind == .name and ((std.mem.eql(u8, name, "make") and std.mem.eql(u8, e.kind.field.e.kind.name, "channel")) or (std.mem.eql(u8, name, "new") and std.mem.eql(u8, e.kind.field.e.kind.name, "buffer")))) { _ = p.next(); const ty = try p.typeExpr(); try p.closeAngle(); @@ -636,6 +751,16 @@ const Parser = struct { e = .{ .span = p.span(start), .kind = .{ .call = .{ .callee = callee, .type_arg = ty, .args = args } } }; } }, + .l_brace => { + if (p.no_struct) return e; + const base = if (e.kind == .specialize) e.kind.specialize.base.* else e; + const name = try p.exprPath(base) orelse return e; + const type_args: []const ast.Type = if (e.kind == .specialize) e.kind.specialize.args else &.{}; + const last = if (std.mem.lastIndexOfScalar(u8, name, '.')) |at| name[at + 1 ..] else name; + if (!std.ascii.isUpper(last[0])) return e; + e = try p.structLiteral(start, name); + e.kind.struct_lit.type_args = type_args; + }, .l_paren => { const args = try p.callArgs(); const callee = try p.box(ast.Expr, e); @@ -677,6 +802,45 @@ const Parser = struct { return args.items; } + fn pathTail(p: *Parser, first: []const u8) Error![]const u8 { + if (p.peek().tag != .dot) return first; + var name: std.ArrayList(u8) = .empty; + try name.appendSlice(p.arena, first); + while (p.peek().tag == .dot) { + _ = p.next(); + try name.append(p.arena, '.'); + try name.appendSlice(p.arena, try p.ident("a name after `.`")); + } + return name.items; + } + + fn exprPath(p: *Parser, e: ast.Expr) Error!?[]const u8 { + return switch (e.kind) { + .name => |name| name, + .field => |field| blk: { + const parent = try p.exprPath(field.e.*) orelse break :blk null; + break :blk try std.fmt.allocPrint(p.arena, "{s}.{s}", .{ parent, field.name }); + }, + else => null, + }; + } + + fn structLiteral(p: *Parser, start: lex.Pos, name: []const u8) Error!ast.Expr { + _ = try p.expect(.l_brace, "`{`"); + var fields: std.ArrayList(ast.FieldInit) = .empty; + while (p.peek().tag != .r_brace) { + const fs = p.peek().pos; + const fname = try p.ident("a field name"); + _ = try p.expect(.colon, "`:`"); + const fe = try p.expr(); + try fields.append(p.arena, .{ .name = fname, .span = p.span(fs), .e = fe }); + if (p.peek().tag != .comma) break; + _ = p.next(); + } + _ = try p.expect(.r_brace, "`}`"); + return .{ .span = p.span(start), .kind = .{ .struct_lit = .{ .name = name, .fields = fields.items } } }; + } + fn primary(p: *Parser) Error!ast.Expr { const start = p.peek().pos; const t = p.peek(); @@ -702,6 +866,17 @@ const Parser = struct { .l_bracket => { _ = p.next(); const e = try p.expr(); + if (p.peek().tag != .semicolon) { + var items: std.ArrayList(ast.Expr) = .empty; + try items.append(p.arena, e); + while (p.peek().tag == .comma) { + _ = p.next(); + if (p.peek().tag == .r_bracket) break; + try items.append(p.arena, try p.expr()); + } + _ = try p.expect(.r_bracket, "`]`"); + return .{ .span = p.span(start), .kind = .{ .array_list = items.items } }; + } _ = try p.expect(.semicolon, "`;` in `[e; N]`"); const n = try p.expect(.int, "array length"); _ = try p.expect(.r_bracket, "`]`"); @@ -733,27 +908,15 @@ const Parser = struct { }; return .{ .span = p.span(start), .kind = .{ .match_expr = try p.box(ast.Match, .{ .scrutinee = scrut, .arms = as, .span = p.span(start), .kind = kind }) } }; } - if (isKeyword(t.text)) return p.fail(t, "an expression"); + if (isKeyword(t.text) and !(isWord(t, "struct") and p.peekAt(1).tag == .dot and isWord(p.peekAt(2), "unpack"))) return p.fail(t, "an expression"); _ = p.next(); - if (p.peek().tag == .colon_colon) { + if (p.peek().tag == .colon_colon and p.peekAt(1).tag != .lt) { _ = p.next(); const v = try p.ident("a variant name"); return .{ .span = p.span(start), .kind = .{ .variant = .{ .@"enum" = t.text, .name = v } } }; } if (p.peek().tag == .l_brace and !p.no_struct and std.ascii.isUpper(t.text[0])) { - _ = p.next(); - var fields: std.ArrayList(ast.FieldInit) = .empty; - while (p.peek().tag != .r_brace) { - const fs = p.peek().pos; - const fname = try p.ident("a field name"); - _ = try p.expect(.colon, "`:`"); - const fe = try p.expr(); - try fields.append(p.arena, .{ .name = fname, .span = p.span(fs), .e = fe }); - if (p.peek().tag != .comma) break; - _ = p.next(); - } - _ = try p.expect(.r_brace, "`}`"); - return .{ .span = p.span(start), .kind = .{ .struct_lit = .{ .name = t.text, .fields = fields.items } } }; + return p.structLiteral(start, t.text); } return .{ .span = p.span(start), .kind = .{ .name = t.text } }; }, diff --git a/src/frontend/stdlib.zig b/src/frontend/stdlib.zig new file mode 100644 index 0000000..feb2f54 --- /dev/null +++ b/src/frontend/stdlib.zig @@ -0,0 +1,25 @@ +//! Compiler-pinned safe source modules. General linking lives in modules.zig. + +pub const Source = struct { name: []const u8, file: []const u8, source: []const u8 }; + +pub const registry = [_]Source{ + .{ .name = "std.bytes", .file = "std/bytes.aji", .source = @embedFile("std_bytes_aji") }, + .{ .name = "std.deque", .file = "std/deque.aji", .source = @embedFile("std_deque_aji") }, + .{ .name = "std.encoding.base64", .file = "std/encoding/base64.aji", .source = @embedFile("std_encoding_base64_aji") }, + .{ .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.hashmap", .file = "std/hashmap.aji", .source = @embedFile("std_hashmap_aji") }, + .{ .name = "std.hashset", .file = "std/hashset.aji", .source = @embedFile("std_hashset_aji") }, + .{ .name = "std.heap", .file = "std/heap.aji", .source = @embedFile("std_heap_aji") }, + .{ .name = "std.io", .file = "std/io.aji", .source = @embedFile("std_io_aji") }, + .{ .name = "std.io.reader", .file = "std/io/reader.aji", .source = @embedFile("std_io_reader_aji") }, + .{ .name = "std.io.writer", .file = "std/io/writer.aji", .source = @embedFile("std_io_writer_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.path", .file = "std/path.aji", .source = @embedFile("std_path_aji") }, + .{ .name = "std.result", .file = "std/result.aji", .source = @embedFile("std_result_aji") }, + .{ .name = "std.utf8", .file = "std/utf8.aji", .source = @embedFile("std_utf8_aji") }, + .{ .name = "std.vec", .file = "std/vec.aji", .source = @embedFile("std_vec_aji") }, +}; diff --git a/src/interp/machine.zig b/src/interp/machine.zig index 9ec38c8..dca42d7 100644 --- a/src/interp/machine.zig +++ b/src/interp/machine.zig @@ -76,6 +76,16 @@ pub const Value = union(enum) { iref: struct { id: u64, slot: u32 }, /// `atomic`: index into the machine's atomic cells (spec 04 §42). atomic: u32, + buffer: *Buffer, + + pub const Buffer = struct { + // The interpreter stores only the initialized prefix. Capacity is + // charged to Aji authority independently of this host representation; + // push's Value-array bookkeeping does not allocate from that authority. + cell: *Cell, + capacity: u64, + elem: air.Type, + }; /// The guarded value is a separate cell, so a place borrowed through a /// guard points at an ordinary cell. @@ -109,6 +119,9 @@ pub const Value = union(enum) { pub const Cell = struct { value: Value, ty: air.Type, + /// An SSA root borrowed in place; its frame outlives every loan. + backing: ?struct { values: []Value, index: u32 } = null, + owner_array: bool = false, /// Accesses seen by the race detector (`Options.detect_races`). shadow: ?*race.Shadow = null, }; @@ -341,6 +354,7 @@ const Copier = struct { mutexes: std.AutoHashMapUnmanaged(*Value.MutexCell, *Value.MutexCell) = .empty, payloads: std.AutoHashMapUnmanaged([*]Value, []Value) = .empty, graphs: std.AutoHashMapUnmanaged(*Value.Graph, *Value.Graph) = .empty, + buffers: std.AutoHashMapUnmanaged(*Value.Buffer, *Value.Buffer) = .empty, fn value(c: *Copier, v: Value) std.mem.Allocator.Error!Value { return switch (v) { @@ -348,6 +362,7 @@ const Copier = struct { .array => |xs| .{ .array = try c.items(xs) }, .local => |cl| .{ .local = try c.cell(cl) }, .own => |cl| .{ .own = try c.cell(cl) }, + .buffer => |b| .{ .buffer = try c.buffer(b) }, .place => |p| .{ .place = try c.place(p) }, .slice => |sl| .{ .slice = .{ .place = try c.place(sl.place), .start = sl.start, .len = sl.len } }, .mutex => |mc| .{ .mutex = try c.mutex(mc) }, @@ -374,10 +389,20 @@ const Copier = struct { const n = try c.to.create(Value.Cell); try c.cells.put(c.tmp, old, n); n.* = .{ .value = .void, .ty = old.ty, .shadow = if (old.shadow) |sh| try sh.copy(c.to) else null }; + n.owner_array = old.owner_array; + if (old.backing) |b| n.backing = .{ .values = try c.items(b.values), .index = b.index }; n.value = try c.value(old.value); return n; } + fn buffer(c: *Copier, old: *Value.Buffer) std.mem.Allocator.Error!*Value.Buffer { + if (c.buffers.get(old)) |n| return n; + const n = try c.to.create(Value.Buffer); + try c.buffers.put(c.tmp, old, n); + n.* = .{ .cell = try c.cell(old.cell), .capacity = old.capacity, .elem = old.elem }; + return n; + } + fn mutex(c: *Copier, old: *Value.MutexCell) std.mem.Allocator.Error!*Value.MutexCell { if (c.mutexes.get(old)) |n| return n; const n = try c.to.create(Value.MutexCell); @@ -821,6 +846,7 @@ const Machine = struct { .bool => .{ .boolean = c.bits != 0 }, else => unreachable, }), + .error_const => |x| return bind(vals, inst.result, .{ .builtin = .{ .which = x.which, .variant = x.variant } }), .copy => |v| return bind(vals, inst.result, vals[v]), .arith => |x| { const bits = arith(x.op, x.mode, x.ty, vals[x.a].int.bits, vals[x.b].int.bits) catch |e| return .{ .trap = kindOf(e) }; @@ -858,6 +884,13 @@ const Machine = struct { return bind(vals, inst.result, .{ .int = .{ .ty = x.to, .bits = bits } }); }, .assert => |v| return if (vals[v].boolean) .next else .{ .trap = .assert }, + .buffer_new, .buffer_len, .buffer_capacity, .buffer_view, .buffer_reserve, .buffer_push, .buffer_pop, .buffer_free => return m.execBuffer(f, vals, inst), + .array_make => |x| return bind(vals, inst.result, .{ .array = try m.gatherMut(vals, x.args) }), + .aggregate_unpack => |x| { + const fields = if (x.ty == .array) vals[x.value].array else vals[x.value].aggregate.fields; + for (f.blocks[x.next].params, fields) |p, v| vals[p.value] = v; + return .{ .jump = x.next }; + }, .struct_make => |x| return bind(vals, inst.result, .{ .aggregate = .{ .decl = x.decl, .variant = 0, @@ -877,7 +910,7 @@ const Machine = struct { for (x.cases) |c| if (c.bits == v) return m.jump(f, vals, c.target); return m.jump(f, vals, x.default); }, - .enum_switch => |x| { + inline .enum_switch, .enum_take => |x| { const variant: u32, const fields: []const Value = switch (vals[x.value]) { .aggregate => |agg| .{ agg.variant, agg.fields }, .builtin => |b| .{ b.variant, &.{} }, @@ -934,13 +967,13 @@ const Machine = struct { .task_check_cancel, .task_join_cancel, .task_shield_begin, .task_shield_end => return m.execCancellation(f, vals, inst), .channel_make, .channel_dup, .channel_send, .channel_recv, .channel_close_sender, .channel_close_receiver, .select => return m.execChannel(f, vals, inst), .mutex_make, .mutex_take, .mutex_lock, .mutex_borrow, .mutex_unlock => return m.execMutex(f, vals, inst), - .own_new, .own_array, .own_take, .own_free, .region_create, .region_new, .region_array, .region_reset, .region_destroy => return m.execAlloc(f, vals, {}, inst), + inline .own_new, .own_pack, .own_array, .own_take, .own_free, .region_create, .region_new, .region_array, .region_reset, .region_destroy => return m.execAlloc(f, vals, {}, inst), .island_create, .island_alloc, .island_root, .island_borrow, .island_freeze, .island_destroy, .frozen_root, .frozen_borrow, .frozen_release, .arc_from_frozen, .arc_new, .arc_clone, .arc_release, .arc_root, .arc_borrow, .iref_eq => return m.execGraph(f, vals, inst), .atomic_new, .atomic_take, .atomic_load, .atomic_store, .atomic_rmw, .atomic_cmpxchg, .atomic_fence => return m.execAtomic(vals, inst), .intrinsic => |x| return m.intrinsic(f, vals, inst, x), .ret => |v| return .{ .ret = if (v) |x| vals[x] else .void }, .trap => return .{ .trap = .explicit }, - .local_alloc, .local_store, .local_zero, .local_load, .borrow_ref, .borrow_mut, .borrow_field, .borrow_end, .load, .store, .array_splat, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split, .slice_copy, .guard, .assume => return m.execMemory(vals, inst), + .local_alloc, .local_store, .local_zero, .local_load, .borrow_ref, .borrow_mut, .borrow_field, .borrow_end, .load, .store, .array_splat, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split, .slice_copy, .value_swap, .guard, .assume => return m.execMemory(vals, inst), } } @@ -968,7 +1001,7 @@ const Machine = struct { const ch = endpointOf(vals[arm.endpoint]); if ((if (arm.value == null) m.recvState(ch) else m.sendState(ch)) != .none) break true; } else false, - .mutex_lock => |x| !vals[x.mutex].mutex.locked, + .mutex_lock => |x| !mutexOf(vals[x.mutex]).locked, else => unreachable, }; } @@ -976,7 +1009,7 @@ const Machine = struct { fn endpointOf(v: Value) u32 { return switch (v) { .sender, .receiver => |c| c, - .place => |p| endpointOf(p.cell.value), + .place => |p| endpointOf(placePtr(p).*), else => unreachable, }; } @@ -1453,7 +1486,7 @@ const Machine = struct { fn mutexOf(v: Value) *Value.MutexCell { return switch (v) { .mutex => |mc| mc, - .place => |p| mutexOf(p.cell.value), + .place => |p| mutexOf(placePtr(p).*), else => unreachable, }; } @@ -1501,7 +1534,7 @@ const Machine = struct { } fn placePtr(p: Value.Place) *Value { - var v = &p.cell.value; + var v = if (p.cell.backing) |b| &b.values[b.index] else &p.cell.value; for (p.path) |i| v = switch (v.*) { .aggregate => |a| &a.fields[i], .array => |items| &items[i], @@ -1567,7 +1600,7 @@ const Machine = struct { fn resourceOf(v: Value) u32 { return switch (v) { .resource => |hd| hd, - .place => |p| p.cell.value.resource, + .place => |p| placePtr(p).resource, else => unreachable, }; } @@ -1752,6 +1785,93 @@ const Machine = struct { } } + fn bufferOf(v: Value) *Value.Buffer { + return switch (v) { + .buffer => |b| b, + .place => |p| bufferOf(placePtr(p).*), + else => unreachable, + }; + } + + fn execBuffer(m: *Machine, f: air.Function, vals: []Value, inst: air.Inst) !Step { + switch (inst.op) { + .buffer_new => |x| { + const capacity = usize_(vals[x.n]); + const size = budget.accountedSize(m.module, x.ty, 0).?; + const bytes = std.math.mul(u64, capacity, size) catch null; + const authority_ = vals[x.cap].cap; + if (!m.charge(authority_, bytes)) return allocFailed(f, vals, x.err); + const cell = try m.heap().create(Value.Cell); + cell.* = .{ .value = .{ .array = &.{} }, .ty = .void }; + const b = try m.heap().create(Value.Buffer); + b.* = .{ .cell = cell, .capacity = capacity, .elem = x.ty }; + try m.owners.put(m.heap(), cell, .{ .authority = authority_, .bytes = bytes.? }); + vals[f.blocks[x.ok].params[0].value] = .{ .buffer = b }; + return .{ .jump = x.ok }; + }, + .buffer_len, .buffer_capacity => |v| { + const b = bufferOf(vals[v]); + if (try m.raceCheck(b.cell, &.{}, false)) |r| return r; + return bind(vals, inst.result, .{ .int = .{ .ty = .usize, .bits = if (inst.op == .buffer_len) b.cell.value.array.len else b.capacity } }); + }, + .buffer_view => |v| { + const b = bufferOf(vals[v]); + if (try m.raceCheck(b.cell, &.{}, false)) |r| return r; + return bind(vals, inst.result, .{ .slice = .{ .place = .{ .cell = b.cell, .path = &.{} }, .start = 0, .len = b.cell.value.array.len } }); + }, + .buffer_reserve => |x| { + const b = bufferOf(vals[x.borrow]); + if (try m.raceCheck(b.cell, &.{}, true)) |r| return r; + const capacity = usize_(vals[x.n]); + if (capacity <= b.capacity) return .{ .jump = x.ok }; + const size = budget.accountedSize(m.module, b.elem, 0).?; + const bytes = std.math.mul(u64, capacity, size) catch null; + const authority_ = vals[x.cap].cap; + if (!m.charge(authority_, bytes)) return allocFailed(f, vals, x.err); + const old = m.owners.get(b.cell).?; + m.uncharge(old.authority, old.bytes); + try m.owners.put(m.heap(), b.cell, .{ .authority = authority_, .bytes = bytes.? }); + b.capacity = capacity; + return .{ .jump = x.ok }; + }, + .buffer_push => |x| { + const b = bufferOf(vals[x.borrow]); + if (try m.raceCheck(b.cell, &.{}, true)) |r| return r; + const old = b.cell.value.array; + if (old.len == b.capacity) { + vals[f.blocks[x.err].params[0].value] = vals[x.value]; + return .{ .jump = x.err }; + } + const items = try m.heap().alloc(Value, old.len + 1); + @memcpy(items[0..old.len], old); + items[old.len] = try m.deepCopy(vals[x.value]); + b.cell.value = .{ .array = items }; + return .{ .jump = x.ok }; + }, + .buffer_pop => |x| { + const b = bufferOf(vals[x.value]); + if (try m.raceCheck(b.cell, &.{}, true)) |r| return r; + const old = b.cell.value.array; + if (old.len == 0) return .{ .jump = x.err }; + vals[f.blocks[x.ok].params[0].value] = old[old.len - 1]; + b.cell.value = .{ .array = old[0 .. old.len - 1] }; + return .{ .jump = x.ok }; + }, + .buffer_free => |x| { + const b = bufferOf(vals[x.value]); + if (try m.raceCheck(b.cell, &.{}, true)) |r| return r; + if (b.cell.value.array.len != 0) { + vals[f.blocks[x.err].params[0].value] = vals[x.value]; + return .{ .jump = x.err }; + } + const allocation = m.owners.fetchRemove(b.cell).?.value; + m.uncharge(allocation.authority, allocation.bytes); + return .{ .jump = x.ok }; + }, + else => unreachable, + } + } + fn allocFailed(f: air.Function, vals: []Value, err: u32) Step { vals[f.blocks[err].params[0].value] = .{ .builtin = .{ .which = .alloc_error, .variant = 0 } }; return .{ .jump = err }; @@ -1761,6 +1881,19 @@ const Machine = struct { fn execAlloc(m: *Machine, f: air.Function, vals: []Value, types_of: anytype, inst: air.Inst) !Step { _ = types_of; switch (inst.op) { + .own_pack => |x| { + const a = vals[x.cap].cap; + const bytes = budget.accountedSize(m.module, x.ty, 0); + if (!m.charge(a, bytes)) { + vals[f.blocks[x.err].params[1].value] = vals[x.value]; + return allocFailed(f, vals, x.err); + } + const cell = try m.heap().create(Value.Cell); + cell.* = .{ .value = try m.deepCopy(vals[x.value]), .ty = x.ty }; + try m.owners.put(m.heap(), cell, .{ .authority = a, .bytes = bytes.? }); + vals[f.blocks[x.ok].params[0].value] = .{ .own = cell }; + return .{ .jump = x.ok }; + }, .own_new => |x| { const v = vals[x.value]; const bytes = m.valueBytes(vals[x.value]); @@ -1780,7 +1913,7 @@ const Machine = struct { const items = try m.heap().alloc(Value, n); for (items) |*it| it.* = try m.deepCopy(vals[x.value]); const cell = try m.heap().create(Value.Cell); - cell.* = .{ .value = .{ .array = items }, .ty = .void }; + cell.* = .{ .value = .{ .array = items }, .ty = .void, .owner_array = true }; try m.owners.put(m.heap(), cell, .{ .authority = a, .bytes = bytes.? }); vals[f.blocks[x.ok].params[0].value] = .{ .own = cell }; return .{ .jump = x.ok }; @@ -1949,6 +2082,20 @@ const Machine = struct { return @truncate(v.int.bits); } + fn ssaCell(m: *Machine, vals: []Value, index: u32) !*Value.Cell { + for (vals) |v| { + const cell: ?*Value.Cell = switch (v) { + .place => |p| p.cell, + .slice => |s| s.place.cell, + else => null, + }; + if (cell) |c| if (c.backing) |b| if (b.values.ptr == vals.ptr and b.index == index) return c; + } + const cell = try m.heap().create(Value.Cell); + cell.* = .{ .value = .void, .ty = .void, .backing = .{ .values = vals, .index = index } }; + return cell; + } + fn execMemory(m: *Machine, vals: []Value, inst: air.Inst) std.mem.Allocator.Error!Step { switch (inst.op) { .local_alloc => |t| { @@ -1973,22 +2120,9 @@ const Machine = struct { }, .borrow_ref, .borrow_mut => |v| return bind(vals, inst.result, switch (vals[v]) { .local => |c| .{ .place = .{ .cell = c, .path = &.{} } }, - // A borrowed resource: a place whose cell holds the handle. - // Owners: the heap cell itself; arrays are borrowed as slices. - .own => |cell| switch (cell.value) { - .array => |items| .{ .slice = .{ .place = .{ .cell = cell, .path = &.{} }, .start = 0, .len = items.len } }, - else => .{ .place = .{ .cell = cell, .path = &.{} } }, - }, - .region => |r| blk: { - const cell = try m.heap().create(Value.Cell); - cell.* = .{ .value = .{ .region = r }, .ty = .void }; - break :blk .{ .place = .{ .cell = cell, .path = &.{} } }; - }, - .resource => |hd| blk: { - const cell = try m.heap().create(Value.Cell); - cell.* = .{ .value = .{ .resource = hd }, .ty = .void }; - break :blk .{ .place = .{ .cell = cell, .path = &.{} } }; - }, + .own => |cell| if (cell.owner_array) .{ .slice = .{ .place = .{ .cell = cell, .path = &.{} }, .start = 0, .len = cell.value.array.len } } else .{ .place = .{ .cell = cell, .path = &.{} } }, + .aggregate, .array, .resource, .region => .{ .place = .{ .cell = try m.ssaCell(vals, v), .path = &.{} } }, + .graph => if (inst.op == .borrow_mut) .{ .place = .{ .cell = try m.ssaCell(vals, v), .path = &.{} } } else vals[v], else => |x| x, }), .borrow_field => |x| return bind(vals, inst.result, .{ .place = try m.extend(asPlace(vals[x.borrow]), x.field) }), @@ -2004,6 +2138,13 @@ const Machine = struct { placePtr(p).* = try m.deepCopy(vals[x.value]); return .next; }, + .value_swap => |x| { + const p = asPlace(vals[x.borrow]); + if (try m.raceCheck(p.cell, p.path, true)) |r| return r; + const old = placePtr(p).*; + placePtr(p).* = try m.deepCopy(vals[x.value]); + return bind(vals, inst.result, old); + }, .array_splat => |x| { const items = try m.heap().alloc(Value, x.ty.array.len); for (items) |*it| it.* = try m.deepCopy(vals[x.value]); @@ -2202,7 +2343,7 @@ pub fn writeValue(module: air.Module, v: Value, s: *std.json.Stringify) std.Io.W }, // Storage and borrows cannot be returned from `@main` (spec 08 §11.3). .local, .place, .slice => try s.write(null), - .resource, .own, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .graph, .iref, .atomic => try s.write(null), + .resource, .own, .buffer, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .graph, .iref, .atomic => try s.write(null), // A capability is opaque: only its kind is shown, never its identity. .cap => { try s.beginObject(); diff --git a/src/main.zig b/src/main.zig index 9e328a2..e78d7d3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -17,10 +17,10 @@ const usage = \\usage: aji [args] \\ \\commands: - \\ check [--report unsafe] + \\ check [--report unsafe] \\ parse and verify a text AIR module; the unsafe report \\ lists trusted boundaries and unsafe operations - \\ run [--fuel N] [--grant P=KIND[:SCOPE]]... + \\ run [--fuel N] [--grant P=KIND[:SCOPE]]... \\ verify, then run @main and print the run record; \\ --fuel stops after N executed instructions; \\ --grant binds capability parameter P of @main @@ -29,16 +29,16 @@ const usage = \\ --seed N; scheduler: --quantum N, --task-limit N, \\ --schedule-seed N; --profile hosted uses the real OS and \\ writes the record only to --result-file PATH - \\ lower [--annotate | --stats] + \\ lower [--annotate | --stats] \\ print the canonical AIR a source module lowers to; \\ --annotate adds source spans as comments (not canonical); \\ --stats prints source/AIR size and expansion ratio - \\ explore [--max-runs N] [--grant P=KIND[:SCOPE]]... + \\ explore [--max-runs N] [--grant P=KIND[:SCOPE]]... \\ run @main under every schedule and weak-memory choice \\ (depth first, up to N runs, default 100000) and print the \\ distinct outcomes; "complete" is true when the whole \\ choice tree was explored (spec 04 §20.5) - \\ report verify, then print the audit report (spec 10 §6.1) + \\ report verify, then print the audit report (spec 10 §6.1) \\ codes list diagnostic codes as JSON Lines \\ features print supported AIR format, language version and features \\ explain show one diagnostic code @@ -76,32 +76,43 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s return .accepted; } if (std.mem.eql(u8, cmd, "report")) { - if (args.len != 3) return usageError("report takes exactly one file"); - const path = args[2]; - const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| { - std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err }); - return .usage; - }; - const result = try aji.check.checkAir(arena, path, source); + const from_manifest = args.len == 4 and std.mem.eql(u8, args[2], "--manifest"); + if (args.len != 3 and !from_manifest) return usageError("report takes a file or --manifest PATH"); + const input = try readInput(arena, io, args[args.len - 1], from_manifest) orelse return .usage; + const result = try aji.check.checkWithModules(arena, input.path, input.source, input.modules); for (result.diagnostics) |d| { try d.writeJson(out); try out.writeByte('\n'); } + if (result.status == .unimplemented) return .unimplemented; const module = result.module orelse return .rejected; try aji.report.write(arena, module, out); try out.writeByte('\n'); return .accepted; } if (std.mem.eql(u8, cmd, "lower")) { - const annotate = args.len == 4 and std.mem.eql(u8, args[2], "--annotate"); - const stats = args.len == 4 and std.mem.eql(u8, args[2], "--stats"); - if (args.len != 3 and !annotate and !stats) return usageError("lower takes [--annotate | --stats] and one .aji file"); - const path = args[args.len - 1]; - const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| { - std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err }); - return .usage; - }; - switch (try aji.frontend.compile(arena, path, source)) { + var annotate = false; + var stats = false; + var manifest_path: ?[]const u8 = null; + var rest = args[2..]; + while (rest.len != 0) { + if (std.mem.eql(u8, rest[0], "--annotate") and !annotate and !stats) { + annotate = true; + rest = rest[1..]; + } else if (std.mem.eql(u8, rest[0], "--stats") and !annotate and !stats) { + stats = true; + rest = rest[1..]; + } else if (std.mem.eql(u8, rest[0], "--manifest") and rest.len >= 2 and manifest_path == null) { + manifest_path = rest[1]; + rest = rest[2..]; + } else break; + } + if ((manifest_path != null and rest.len != 0) or (manifest_path == null and rest.len != 1)) return usageError("lower takes [--annotate | --stats] and a file or --manifest PATH"); + const input = try readInput(arena, io, manifest_path orelse rest[0], manifest_path != null) orelse return .usage; + const path = input.path; + const source = input.source; + if (manifest_path != null and !std.mem.endsWith(u8, path, ".aji")) return usageError("lower requires a .aji entry"); + switch (try aji.frontend.compileWithModules(arena, path, source, input.modules)) { .ok => |o| { if (stats) { // How much mechanical work the frontend took over. @@ -190,12 +201,16 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s var result_file: ?[]const u8 = null; var rest = args[2..]; var unsafe_report = false; - if (std.mem.eql(u8, cmd, "check") and rest.len == 3 and std.mem.eql(u8, rest[0], "--report")) { + if (std.mem.eql(u8, cmd, "check") and rest.len >= 3 and std.mem.eql(u8, rest[0], "--report")) { if (!std.mem.eql(u8, rest[1], "unsafe")) return usageError("--report takes unsafe"); unsafe_report = true; rest = rest[2..]; } var manifest_path: ?[]const u8 = null; + if (std.mem.eql(u8, cmd, "check") and rest.len >= 2 and std.mem.eql(u8, rest[0], "--manifest")) { + manifest_path = rest[1]; + rest = rest[2..]; + } while (std.mem.eql(u8, cmd, "run") and rest.len >= 2) { const flag = rest[0]; const value = rest[1]; @@ -229,46 +244,18 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s rest = rest[2..]; } options.world.files = files.items; - var path: []const u8 = undefined; + var input: aji.source_package.Input = undefined; if (manifest_path) |mp| { - // spec 12 §1.2: the module is the manifest's entry; its grants - // are applied, each replaced by a --grant for the same parameter. if (rest.len != 0) return usageError("a file argument cannot be combined with --manifest"); - const text = std.Io.Dir.cwd().readFileAlloc(io, mp, arena, .limited(1 << 20)) catch |err| { - std.debug.print("aji: cannot read {s}: {t}\n", .{ mp, err }); - return .usage; - }; - const m = switch (try aji.manifest.parse(arena, text)) { - .ok => |m| m, - .err => |e| { - std.debug.print("aji: manifest {s}:{d}: {s}\n", .{ mp, e.line, e.message }); - return .usage; - }, - }; - const entry = m.entry orelse { - std.debug.print("aji: manifest {s}: [package] entry is required for aji run\n", .{mp}); - return .usage; - }; - path = try std.fs.path.join(arena, &.{ std.fs.path.dirname(mp) orelse ".", entry }); - var merged: std.ArrayList(aji.interp.Grant) = .empty; - for (m.grants) |g| { - const overridden = for (grants.items) |cg| { - if (std.mem.eql(u8, cg.parameter, g.parameter)) break true; - } else false; - if (!overridden) try merged.append(arena, .{ .parameter = g.parameter, .kind = g.kind, .scope = g.scope }); - } - try merged.appendSlice(arena, grants.items); - options.grants = merged.items; + input = try readInput(arena, io, mp, true) orelse return .usage; + options.grants = try mergeGrants(arena, input.grants, grants.items); } else { - if (rest.len != 1) return usageError("check and run take exactly one file"); - path = rest[0]; + if (rest.len != 1) return usageError("check and run take a file or --manifest PATH"); + input = try readInput(arena, io, rest[0], false) orelse return .usage; options.grants = grants.items; } - const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| { - std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err }); - return .usage; - }; - const report = try aji.check.checkFile(arena, path, source); + const path = input.path; + const report = try aji.check.checkWithModules(arena, path, input.source, input.modules); for (report.diagnostics) |d| { try d.writeJson(out); try out.writeByte('\n'); @@ -335,21 +322,22 @@ fn explore(arena: std.mem.Allocator, io: std.Io, argv: []const []const u8, out: var max_runs: u64 = 100_000; var grants: std.ArrayList(aji.interp.Grant) = .empty; var rest = argv; + var manifest_path: ?[]const u8 = null; while (rest.len >= 2) { if (std.mem.eql(u8, rest[0], "--max-runs")) { max_runs = std.fmt.parseInt(u64, rest[1], 10) catch return usageError("--max-runs takes a positive integer"); } else if (std.mem.eql(u8, rest[0], "--grant")) { try grants.append(arena, parseGrant(rest[1]) orelse return usageError("--grant takes =[:]")); + } else if (std.mem.eql(u8, rest[0], "--manifest") and manifest_path == null) { + manifest_path = rest[1]; } else break; rest = rest[2..]; } - if (rest.len != 1) return usageError("explore takes exactly one file"); - const path = rest[0]; - const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| { - std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err }); - return .usage; - }; - const report = try aji.check.checkFile(arena, path, source); + if ((manifest_path != null and rest.len != 0) or (manifest_path == null and rest.len != 1)) return usageError("explore takes a file or --manifest PATH"); + const input = try readInput(arena, io, manifest_path orelse rest[0], manifest_path != null) orelse return .usage; + const all_grants = try mergeGrants(arena, input.grants, grants.items); + const path = input.path; + const report = try aji.check.checkWithModules(arena, path, input.source, input.modules); for (report.diagnostics) |d| { try d.writeJson(out); try out.writeByte('\n'); @@ -366,7 +354,7 @@ fn explore(arena: std.mem.Allocator, io: std.Io, argv: []const []const u8, out: defer run_arena.deinit(); var ex: aji.interp.Explore = .{ .prefix = prefix.items }; const outcome = aji.interp.run(run_arena.allocator(), module, "main", .{ - .grants = grants.items, + .grants = all_grants, .quantum = std.math.maxInt(u64), .explore = &ex, }) catch |err| switch (err) { @@ -442,7 +430,7 @@ fn writeRecord(arena: std.mem.Allocator, module: aji.air.Module, outcome: aji.in try out.writeAll(text[0 .. text.len - 1]); var j: std.json.Stringify = .{ .writer = out }; try out.writeAll(",\"source_location\":"); - try j.write(.{ .file = path, .line = s.start.line, .col = s.start.col }); + try j.write(.{ .file = s.file orelse path, .line = s.start.line, .col = s.start.col }); try out.writeAll("}"); } @@ -479,3 +467,42 @@ test parseGrant { try std.testing.expect(parseGrant("out=io.write").?.scope == null); try std.testing.expect(parseGrant("io.write") == null); } + +test "standard library trap record identifies the bundled source" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const allocator = arena.allocator(); + const report = try aji.check.checkFile(allocator, "client.aji", "module t\nimport std.math;\nfn main() -> u64\neffects []\n{ return std.math.clamp_u64(5, 9, 4); }\n"); + try std.testing.expectEqual(aji.check.Status.accepted, report.status); + const module = report.module.?; + const outcome = try aji.interp.run(allocator, module, "main", .{ .fuel = 10000 }); + try std.testing.expect(outcome == .trapped); + var output: std.Io.Writer.Allocating = .init(allocator); + try writeRecord(allocator, module, outcome, null, report, "client.aji", &output.writer); + const record = try std.json.parseFromSlice(std.json.Value, allocator, output.written(), .{}); + const location = record.value.object.get("source_location").?.object; + try std.testing.expectEqualStrings("std/math.aji", location.get("file").?.string); + try std.testing.expectEqual(@as(i64, 20), location.get("line").?.integer); +} + +fn readInput(arena: std.mem.Allocator, io: std.Io, path: []const u8, from_manifest: bool) !?aji.source_package.Input { + return switch (if (from_manifest) try aji.source_package.load(arena, io, path) else try aji.source_package.single(arena, io, path)) { + .ok => |input| input, + .err => |err| blk: { + std.debug.print("aji: {s}:{d}: {s}\n", .{ err.path, err.line, err.message }); + break :blk null; + }, + }; +} + +fn mergeGrants(arena: std.mem.Allocator, baseline: []const aji.manifest.Grant, overrides: []const aji.interp.Grant) ![]const aji.interp.Grant { + var result: std.ArrayList(aji.interp.Grant) = .empty; + for (baseline) |grant| { + const replaced = for (overrides) |override| { + if (std.mem.eql(u8, grant.parameter, override.parameter)) break true; + } else false; + if (!replaced) try result.append(arena, .{ .parameter = grant.parameter, .kind = grant.kind, .scope = grant.scope }); + } + try result.appendSlice(arena, overrides); + return result.items; +} diff --git a/src/manifest.zig b/src/manifest.zig index b2ea80d..60fda01 100644 --- a/src/manifest.zig +++ b/src/manifest.zig @@ -6,13 +6,18 @@ //! drop or misplace authority. const std = @import("std"); +const modules = @import("frontend/modules.zig"); pub const Grant = struct { parameter: []const u8, kind: []const u8, scope: ?[]const u8 }; +pub const ModuleBinding = struct { name: []const u8, file: []const u8, line: u32 }; + pub const Manifest = struct { name: []const u8, version: []const u8, entry: ?[]const u8, + modules: []const ModuleBinding = &.{}, + has_modules: bool = false, /// `[capabilities]` in file order. grants: []const Grant, }; @@ -46,14 +51,32 @@ fn isKey(s: []const u8) bool { return true; } +fn isModuleName(name: []const u8) bool { + var parts = std.mem.splitScalar(u8, name, '.'); + while (parts.next()) |part| { + if (part.len == 0 or !(std.ascii.isAlphabetic(part[0]) or part[0] == '_')) return false; + for (part[1..]) |ch| if (!(std.ascii.isAlphanumeric(ch) or ch == '_')) return false; + } + return name.len != 0; +} + +pub fn sourcePath(path: []const u8) bool { + if (!std.mem.endsWith(u8, path, ".aji") or std.mem.indexOfAny(u8, path, "\\:\x00") != null) return false; + var parts = std.mem.splitScalar(u8, path, '/'); + while (parts.next()) |part| if (part.len == 0 or std.mem.eql(u8, part, ".") or std.mem.eql(u8, part, "..")) return false; + return true; +} + pub fn parse(arena: std.mem.Allocator, text: []const u8) !Result { - const Section = enum { none, package, capabilities, metadata }; + const Section = enum { none, package, capabilities, metadata, modules }; var section: Section = .none; - var seen_sections: [3]bool = .{ false, false, false }; + var seen_sections: [4]bool = @splat(false); var name: ?[]const u8 = null; var version: ?[]const u8 = null; var entry: ?[]const u8 = null; var grants: std.ArrayList(Grant) = .empty; + var bindings: std.ArrayList(ModuleBinding) = .empty; + var entry_line: u32 = 0; var keys: std.StringHashMapUnmanaged(void) = .empty; var lines = std.mem.splitScalar(u8, text, '\n'); @@ -74,7 +97,7 @@ pub fn parse(arena: std.mem.Allocator, text: []const u8) !Result { } const eq = std.mem.indexOfScalar(u8, line, '=') orelse return fail(arena, line_no, "expected key = \"value\"", .{}); const key = std.mem.trim(u8, line[0..eq], " \t"); - if (!isKey(key)) return fail(arena, line_no, "malformed key", .{}); + if (!(if (section == .modules) isModuleName(key) else isKey(key))) return fail(arena, line_no, "malformed key", .{}); const value = (try parseString(arena, std.mem.trim(u8, line[eq + 1 ..], " \t"))) orelse return fail(arena, line_no, "value of {s} must be a string \"...\" (escapes \\\", \\\\, \\n), optionally followed by a # comment", .{key}); if (section == .none) return fail(arena, line_no, "key {s} outside a section", .{key}); @@ -89,15 +112,29 @@ pub fn parse(arena: std.mem.Allocator, text: []const u8) !Result { version = value; } else if (std.mem.eql(u8, key, "entry")) { entry = value; + entry_line = line_no; } else return fail(arena, line_no, "unknown key {s} in [package]", .{key}); }, .capabilities => try grants.append(arena, parseGrantValue(key, value) orelse return fail(arena, line_no, "grant {s} must be \"kind[:scope]\"", .{key})), + .modules => { + if (modules.reserved(key)) return fail(arena, line_no, "reserved module namespace {s}", .{key}); + if (!sourcePath(value)) return fail(arena, line_no, "module {s} needs a portable relative .aji path", .{key}); + if (bindings.items.len >= 1024) return fail(arena, line_no, "at most 1024 modules are allowed", .{}); + try bindings.append(arena, .{ .name = key, .file = value, .line = line_no }); + }, .metadata => {}, .none => unreachable, } } + const has_modules = seen_sections[3]; + if (has_modules) { + const source_entry = entry orelse return fail(arena, line_no, "[modules] requires an entry .aji source", .{}); + if (!sourcePath(source_entry)) return fail(arena, entry_line, "[modules] requires a portable relative entry .aji path", .{}); + } return .{ .ok = .{ + .modules = bindings.items, + .has_modules = has_modules, .name = name orelse return fail(arena, line_no, "[package] name is required", .{}), .version = version orelse return fail(arena, line_no, "[package] version is required", .{}), .entry = entry, @@ -177,3 +214,23 @@ test "strict parsing" { try expectErr("[package]\nname = \"a\"\nversion = \"1\"\n[capabilities]\nout = \":x\"\n", 5); // empty kind try expectErr("[package]\nname = \"a\"\n", 3); // missing version: reported at the end of the file } + +test "explicit package module mapping and portable paths" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const prefix = "[package]\nname = \"a\"\nversion = \"1\"\nentry = \"src/main.aji\"\n[modules]\n"; + const good = try parse(arena, prefix ++ "app.model = \"src/model.aji\"\n"); + try std.testing.expect(good == .ok); + try std.testing.expectEqualStrings("app.model", good.ok.modules[0].name); + try std.testing.expect(good.ok.has_modules); + for ([_][]const u8{ + "app.model = \"../model.aji\"", "app.model = \"/model.aji\"", "app.model = \"src//model.aji\"", + "app.model = \"src/./model.aji\"", "app.model = \"src/model.air\"", "app.model = \"C:/model.aji\"", + "std.bytes = \"model.aji\"", "task.work = \"model.aji\"", "io.work = \"model.aji\"", + "app..model = \"model.aji\"", "app.0model = \"model.aji\"", "app-model = \"model.aji\"", + }) |line| try expectErr(try std.mem.concat(arena, u8, &.{ prefix, line }), 6); + try expectErr(prefix ++ "app.model = \"model.aji\"\napp.model = \"other.aji\"", 7); + try expectErr("[package]\nname = \"a\"\nversion = \"1\"\nentry = \"main.air\"\n[modules]\n", 4); + for ([_][]const u8{ "src\\model.aji", "a\x00.aji", "src/../a.aji", "src/.aji/../b.aji" }) |path| try std.testing.expect(!sourcePath(path)); +} diff --git a/src/report.zig b/src/report.zig index df78a21..1066eda 100644 --- a/src/report.zig +++ b/src/report.zig @@ -64,7 +64,7 @@ fn analyze(arena: std.mem.Allocator, m: air.Module, f: air.Function) !FnInfo { _ = try addOnce(arena, &info.intrinsics, reg.name); if (reg.effect) |e| _ = try addOnce(arena, &info.direct, e); }, - .own_new, .own_array, .region_new, .region_array, .region_create, .channel_make, .island_create, .island_alloc, .arc_new => { + .buffer_new, .buffer_reserve, .own_new, .own_pack, .own_array, .region_new, .region_array, .region_create, .channel_make, .island_create, .island_alloc, .arc_new => { info.allocations += 1; _ = try addOnce(arena, &info.direct, "mem.alloc"); }, diff --git a/src/root.zig b/src/root.zig index 172b5e9..7db8416 100644 --- a/src/root.zig +++ b/src/root.zig @@ -18,6 +18,7 @@ pub const check = @import("check.zig"); pub const frontend = @import("frontend.zig"); pub const report = @import("report.zig"); pub const manifest = @import("manifest.zig"); +pub const source_package = @import("source_package.zig"); test { @import("std").testing.refAllDecls(@This()); diff --git a/src/source_package.zig b/src/source_package.zig new file mode 100644 index 0000000..af35ea9 --- /dev/null +++ b/src/source_package.zig @@ -0,0 +1,91 @@ +//! Explicit manifest source snapshot. No source is executed here. +const std = @import("std"); +const manifest = @import("manifest.zig"); +const frontend = @import("frontend.zig"); + +pub const Input = struct { + path: []const u8, + source: []const u8, + modules: []const frontend.modules.Source = &.{}, + grants: []const manifest.Grant = &.{}, +}; +pub const Failure = struct { path: []const u8, line: u32 = 0, message: []const u8 }; +pub const Result = union(enum) { ok: Input, err: Failure }; +const source_limit: usize = 64 << 20; + +fn fail(arena: std.mem.Allocator, path: []const u8, err: anyerror) std.mem.Allocator.Error!Result { + if (err == error.OutOfMemory) return error.OutOfMemory; + return .{ .err = .{ .path = path, .message = try std.fmt.allocPrint(arena, "cannot read source: {t}", .{err}) } }; +} + +pub fn single(arena: std.mem.Allocator, io: std.Io, path: []const u8) std.mem.Allocator.Error!Result { + const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(source_limit)) catch |err| return fail(arena, path, err); + return .{ .ok = .{ .path = path, .source = source } }; +} + +pub fn load(arena: std.mem.Allocator, io: std.Io, path: []const u8) std.mem.Allocator.Error!Result { + const text = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(1 << 20)) catch |err| return fail(arena, path, err); + const m = switch (try manifest.parse(arena, text)) { + .ok => |m| m, + .err => |err| return .{ .err = .{ .path = path, .line = err.line, .message = err.message } }, + }; + const entry = m.entry orelse return .{ .err = .{ .path = path, .message = "[package] entry is required" } }; + const parent = std.fs.path.dirname(path) orelse "."; + const entry_path = try std.fs.path.join(arena, &.{ parent, entry }); + if (!m.has_modules) { + var result = try single(arena, io, entry_path); + if (result == .ok) result.ok.grants = m.grants; + return result; + } + const root = std.Io.Dir.cwd().openDir(io, parent, .{}) catch |err| return fail(arena, parent, err); + defer root.close(io); + const source = readSource(arena, io, root, entry, source_limit) catch |err| return fail(arena, entry, err); + var remaining = source_limit - source.len; + const bindings = try arena.dupe(manifest.ModuleBinding, m.modules); + std.mem.sort(manifest.ModuleBinding, bindings, {}, struct { + fn less(_: void, a: manifest.ModuleBinding, b: manifest.ModuleBinding) bool { + return std.mem.lessThan(u8, a.name, b.name); + } + }.less); + var sources: std.ArrayList(frontend.modules.Source) = .empty; + for (bindings) |binding| { + const bytes = readSource(arena, io, root, binding.file, remaining) catch |err| return fail(arena, binding.file, err); + remaining -= bytes.len; + try sources.append(arena, .{ .name = binding.name, .file = binding.file, .source = bytes }); + } + return .{ .ok = .{ .path = entry_path, .source = source, .modules = sources.items, .grants = m.grants } }; +} + +fn readSource(arena: std.mem.Allocator, io: std.Io, root: std.Io.Dir, path: []const u8, limit: usize) ![]const u8 { + std.debug.assert(manifest.sourcePath(path)); + var dirs: std.ArrayList(std.Io.Dir) = .empty; + defer for (dirs.items) |dir| dir.close(io); + var current = root; + var parts = std.mem.splitScalar(u8, path, '/'); + while (parts.next()) |part| { + if (parts.peek() != null) { + const next = try current.openDir(io, part, .{ .follow_symlinks = false }); + dirs.append(arena, next) catch |err| { + next.close(io); + return err; + }; + current = next; + continue; + } + // Avoid opening a static pipe/device; the opened handle is checked too. + if ((try current.statFile(io, part, .{ .follow_symlinks = false })).kind != .file) return error.NotRegularSource; + const file = try current.openFile(io, part, .{ .follow_symlinks = false, .allow_directory = false }); + defer file.close(io); + const stat = try file.stat(io); + if (stat.kind != .file) return error.NotRegularSource; + if (stat.size > limit) return error.StreamTooLong; + var reader = file.reader(io, &.{}); + const bytes = reader.interface.allocRemaining(arena, .limited(limit + 1)) catch |err| switch (err) { + error.ReadFailed => return reader.err.?, + else => return err, + }; + if (bytes.len > limit) return error.StreamTooLong; + return bytes; + } + unreachable; +} diff --git a/src/verifier/borrow.zig b/src/verifier/borrow.zig index 3e16a72..9e6e3e7 100644 --- a/src/verifier/borrow.zig +++ b/src/verifier/borrow.zig @@ -191,7 +191,7 @@ const Walker = struct { /// Linear values: resources, owners and regions (spec 06 §6, spec 03 §19–§20). fn isResource(w: *Walker, v: ValueId) bool { - return w.types[v].isLinear(); + return w.c.module.isLinearType(w.types[v]); } /// A non-consuming use of resource `v` (a borrow of it). @@ -242,6 +242,11 @@ pub fn overlap(a: []const Seg, b: []const Seg) bool { const Edge = struct { target: u32, args: []const ValueId }; fn edges(op: air.Op, out: *std.ArrayList(Edge), arena: std.mem.Allocator) !void { + if (op.bufferTargets()) |t| { + try out.append(arena, .{ .target = t.ok, .args = &.{} }); + try out.append(arena, .{ .target = t.err, .args = &.{} }); + return; + } switch (op) { .br => |t| try out.append(arena, .{ .target = t.block, .args = t.args }), .cbr => |x| { @@ -252,10 +257,11 @@ fn edges(op: air.Op, out: *std.ArrayList(Edge), arena: std.mem.Allocator) !void for (x.cases) |c| try out.append(arena, .{ .target = c.target.block, .args = c.target.args }); try out.append(arena, .{ .target = x.default.block, .args = x.default.args }); }, - .enum_switch => |x| { + inline .enum_switch, .enum_take => |x| { for (x.arms) |a| try out.append(arena, .{ .target = a.block, .args = &.{} }); if (x.default) |d| try out.append(arena, .{ .target = d.block, .args = d.args }); }, + .aggregate_unpack => |x| try out.append(arena, .{ .target = x.next, .args = &.{} }), .cap_narrow => |x| { try out.append(arena, .{ .target = x.ok, .args = &.{} }); try out.append(arena, .{ .target = x.err, .args = &.{} }); @@ -264,7 +270,7 @@ fn edges(op: air.Op, out: *std.ArrayList(Edge), arena: std.mem.Allocator) !void try out.append(arena, .{ .target = ok, .args = &.{} }); try out.append(arena, .{ .target = x.err.?, .args = &.{} }); }, - .own_new, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => { + inline .own_new, .own_pack, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => { const t = air.allocTargets(op).?; try out.append(arena, .{ .target = t.ok, .args = &.{} }); try out.append(arena, .{ .target = t.err, .args = &.{} }); @@ -302,7 +308,7 @@ fn checkFunction(c: *Context, f: air.Function, types: []const air.Type) !void { .parent = null, }; // Linear parameters were moved in: the function owns them (spec 06 §6.3). - if (p.ty.isLinear()) w.live[p.value] = true; + if (c.module.isLinearType(p.ty)) w.live[p.value] = true; } const dom = try ssa.dominators(c.arena, f); @@ -318,7 +324,7 @@ fn checkFunction(c: *Context, f: air.Function, types: []const air.Type) !void { const blk = f.blocks[b]; // Linear block parameters own their argument from here on; the // parameter of a region allocation's `ok` target is a live borrow. - for (blk.params) |p| if (p.ty.isLinear() or (p.ty.isBorrow() and w.info[p.value] != null)) { + for (blk.params) |p| if (c.module.isLinearType(p.ty) or (p.ty.isBorrow() and w.info[p.value] != null)) { w.live[p.value] = true; w.dead[p.value] = .none; }; @@ -337,19 +343,19 @@ fn checkFunction(c: *Context, f: air.Function, types: []const air.Type) !void { for (out.items) |e| { @memcpy(w.live, base); @memcpy(w.dead, base_dead); - for (e.args) |a| if (types[a].isLinear()) try w.consume(a, .moved); + for (e.args) |a| if (c.module.isLinearType(types[a])) try w.consume(a, .moved); // A linear parameter of the target that is still live on this // edge would be overwritten: that instance leaks. Parameters are // not part of the incoming state; they come alive in the block. for (f.blocks[e.target].params) |p| { - if (p.ty.isLinear() and w.live[p.value]) try w.report("E3002", "linear value not consumed before it is redefined", p.value, null); + if (c.module.isLinearType(p.ty) and w.live[p.value]) try w.report("E3002", "linear value not consumed before it is redefined", p.value, null); w.live[p.value] = false; } if (entry_state[e.target]) |expected| { if (!std.mem.eql(bool, expected, w.live) and !reported_join[e.target]) { reported_join[e.target] = true; for (expected, w.live, 0..) |a, x, v| if (a != x) { - const is_res = types[v].isLinear(); + const is_res = c.module.isLinearType(types[v]); try c.report(if (is_res) "E3002" else "E2105", f.blocks[e.target].span, if (is_res) "resource state differs between edges into this block" else "borrow state differs between edges into this block", &.{ .{ .name = "function", .value = .{ .str = f.name } }, .{ .name = "block", .value = .{ .str = f.blocks[e.target].name } }, @@ -384,7 +390,7 @@ fn step(w: *Walker, inst: air.Inst) !void { }, .borrow_field => |x| try w.derive(inst.result.?, x.borrow, .{ .field = x.field }), .borrow_index => |x| try w.derive(inst.result.?, x.borrow, .elem), - .slice_make => |v| try w.derive(inst.result.?, v, null), + .buffer_view, .slice_make => |v| try w.derive(inst.result.?, v, null), .slice_sub => |x| try w.derive(inst.result.?, x.slice, .elem), .slice_split => |x| { const l = inst.result.?; @@ -433,7 +439,49 @@ fn step(w: *Walker, inst: air.Inst) !void { w.live[r] = true; }; }, - .own_free, .own_take => |v| try w.consume(v, .closed), + inline .struct_make, .enum_make, .array_make => |x| { + for (x.args) |v| if (w.isResource(v)) try w.consume(v, .moved); + if (inst.result) |r| { + if (w.isResource(r)) w.live[r] = true; + } + }, + .struct_get => |x| { + if (w.isResource(x.a)) { + _ = try w.resourceUsable(x.a); + try w.access(x.a, &.{.{ .field = x.field }}, .shared, null, x.a); + } + }, + .aggregate_unpack => |x| { + if (w.isResource(x.value)) try w.consume(x.value, .moved); + }, + .enum_take => |x| { + if (w.isResource(x.value)) try w.consume(x.value, .moved); + }, + .buffer_new => {}, + .buffer_len, .buffer_capacity => |v| try w.useThrough(v, .shared), + .buffer_reserve => |x| try w.useThrough(x.borrow, .exclusive), + .buffer_push => |x| { + try w.useThrough(x.borrow, .exclusive); + if (w.isResource(x.value)) try w.consume(x.value, .moved); + }, + .buffer_pop => |x| try w.useThrough(x.value, .exclusive), + .buffer_free => |x| try w.consume(x.value, .moved), + .own_pack => |x| { + if (w.isResource(x.value)) try w.consume(x.value, .moved); + }, + .value_swap => |x| { + try w.useThrough(x.borrow, .exclusive); + if (w.isResource(x.value)) try w.consume(x.value, .moved); + if (inst.result) |r| { + if (w.isResource(r)) w.live[r] = true; + } + }, + .own_free, .own_take => |v| { + try w.consume(v, .closed); + if (inst.result) |r| { + if (w.isResource(r)) w.live[r] = true; + } + }, .task_scope_begin => w.live[inst.result.?] = true, .task_spawn => |x| { try noWaitUnderLock(w, "task.spawn"); diff --git a/src/verifier/budget.zig b/src/verifier/budget.zig index f3b8b3d..720a00e 100644 --- a/src/verifier/budget.zig +++ b/src/verifier/budget.zig @@ -33,6 +33,7 @@ pub fn accountedSize(m: air.Module, t: air.Type, depth: usize) ?u64 { .atomic => |inner| accountedSize(m, inner.*, depth + 1), .mutex => |inner| std.math.add(u64, 8, accountedSize(m, inner.*, depth + 1) orelse return null) catch null, .own_array => 16, + .buffer => 24, .slice, .slice_mut => 16, .builtin => |b| tagSize(b.variants().len), .array => |a| std.math.mul(u64, a.len, accountedSize(m, a.elem, depth + 1) orelse return null) catch null, @@ -87,6 +88,7 @@ pub fn check(c: *verifier.Context) !void { for (b.insts) |inst| switch (inst.op) { .call => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len), .struct_make => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len), + .array_make => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len), .enum_make => |x| try limit(c, inst.span, "arguments per call", Limits.params, x.args.len), .@"switch" => |x| try limit(c, inst.span, "cases per switch", Limits.cases, x.cases.len), else => {}, @@ -150,7 +152,7 @@ fn checkValueSizes(c: *verifier.Context) !void { for (b.params) |p| try v.visit(b.span, p.ty); for (b.insts) |inst| switch (inst.op) { .local_alloc => |t| try v.visit(inst.span, t), - .array_splat => |x| try v.visit(inst.span, x.ty), + inline .array_splat, .array_make, .aggregate_unpack, .own_pack, .buffer_new => |x| try v.visit(inst.span, x.ty), else => {}, }; } diff --git a/src/verifier/cfg.zig b/src/verifier/cfg.zig index 3e6eb93..fc05b43 100644 --- a/src/verifier/cfg.zig +++ b/src/verifier/cfg.zig @@ -53,7 +53,8 @@ fn checkTerminator(c: *Context, f: air.Function, inst: air.Inst) !void { } try arity(c, f, inst.span, x.default); }, - .enum_switch => |x| { + inline .enum_switch, .enum_take => |x| { + if (inst.op == .enum_take and x.default != null) try invalid(c, f, inst.span, "enum.take cannot have a default", null); const m = c.module; for (x.arms, 0..) |arm, i| { for (x.arms[0..i]) |prev| if (prev.variant == arm.variant) @@ -74,6 +75,38 @@ fn checkTerminator(c: *Context, f: air.Function, inst: air.Inst) !void { } } }, + .aggregate_unpack => |x| { + const n: usize = switch (x.ty) { + .array => |a| @intCast(a.len), + .named => |i| if (c.module.types[i].kind == .@"struct") c.module.types[i].kind.@"struct".len else 0, + else => 0, + }; + try paramCount(c, f, inst.span, x.next, n, "unpack target must receive every component"); + }, + .buffer_new => |x| { + try paramCount(c, f, inst.span, x.ok, 1, "buffer.new success takes buffer"); + try paramCount(c, f, inst.span, x.err, 1, "buffer.new failure takes alloc_error"); + }, + .buffer_reserve => |x| { + try paramCount(c, f, inst.span, x.ok, 0, "buffer.reserve success takes no values"); + try paramCount(c, f, inst.span, x.err, 1, "buffer.reserve failure takes alloc_error"); + }, + .buffer_push => |x| { + try paramCount(c, f, inst.span, x.ok, 0, "buffer.push success takes no values"); + try paramCount(c, f, inst.span, x.err, 1, "buffer.push failure returns value"); + }, + .buffer_pop => |x| { + try paramCount(c, f, inst.span, x.ok, 1, "buffer.pop success takes value"); + try paramCount(c, f, inst.span, x.err, 0, "buffer.pop empty takes no values"); + }, + .buffer_free => |x| { + try paramCount(c, f, inst.span, x.ok, 0, "buffer.free success takes no values"); + try paramCount(c, f, inst.span, x.err, 1, "buffer.free nonempty returns buffer"); + }, + .own_pack => |x| { + try paramCount(c, f, inst.span, x.ok, 1, "own.pack success takes owner"); + try paramCount(c, f, inst.span, x.err, 2, "own.pack failure takes error and original value"); + }, // `ok` receives the narrowed capability, `err` the `cap_error` (spec 05 §10.4). .cap_narrow => |x| { try paramCount(c, f, inst.span, x.ok, 1, "cap.narrow `ok` target takes exactly one parameter"); diff --git a/src/verifier/effects.zig b/src/verifier/effects.zig index 7fd0bb8..7813870 100644 --- a/src/verifier/effects.zig +++ b/src/verifier/effects.zig @@ -57,7 +57,7 @@ pub fn check(c: *Context) !void { .atomic_store => |x| try needAtomic(c, f, inst, x.ord != .seq_cst), .atomic_rmw => |x| try needAtomic(c, f, inst, x.ord != .seq_cst), .atomic_cmpxchg => |x| try needAtomic(c, f, inst, x.success != .seq_cst or x.failure != .seq_cst), - .own_new, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => if (!contains(f.effects, "mem.alloc")) { + .buffer_new, .buffer_reserve, .own_new, .own_pack, .own_array, .region_create, .region_new, .region_array, .island_create, .island_alloc, .arc_new => if (!contains(f.effects, "mem.alloc")) { try c.report("E3101", inst.span, "allocation requires the effect mem.alloc", &.{ .{ .name = "function", .value = .{ .str = f.name } }, .{ .name = "effect", .value = .{ .str = "mem.alloc" } }, diff --git a/src/verifier/types.zig b/src/verifier/types.zig index f8ce92a..0696667 100644 --- a/src/verifier/types.zig +++ b/src/verifier/types.zig @@ -23,6 +23,10 @@ pub fn check(c: *Context) !void { fn checkDeclarations(c: *Context) !void { const m = c.module; + if (m.declares("linear_aggregates")) { + try checkFiniteLayouts(c); + if (c.diags.items.len != 0) return; + } for (m.types) |d| switch (d.kind) { .@"struct" => |fs| for (fs) |fld| try wellFormed(c, d.span, fld.ty, .member, d.name), .@"enum" => |vs| for (vs) |v| for (v.payload) |t| try wellFormed(c, d.span, t, .member, d.name), @@ -44,19 +48,24 @@ fn checkDeclarations(c: *Context) !void { for (b.params) |p| try wellFormed(c, b.span, p.ty, .block_param, f.name); for (b.insts) |inst| switch (inst.op) { .local_alloc => |t| try wellFormed(c, inst.span, t, .member, f.name), - .array_splat => |x| try wellFormed(c, inst.span, x.ty, .member, f.name), + inline .array_splat, .array_make, .aggregate_unpack, .own_pack, .buffer_new => |x| try wellFormed(c, inst.span, x.ty, .param, f.name), else => {}, }; } } - // E1003: an aggregate that contains itself by value has no finite size. + try checkFiniteLayouts(c); +} + +/// E1003 applies through arrays as well as direct nominal members. +pub fn checkFiniteLayouts(c: *Context) !void { + const m = c.module; const state = try c.arena.alloc(enum { white, grey, black }, m.types.len); @memset(state, .white); for (0..m.types.len) |i| try visitDecl(c, state, @intCast(i)); } -fn visitDecl(c: *Context, state: anytype, i: u32) !void { +fn visitDecl(c: *Context, state: anytype, i: u32) std.mem.Allocator.Error!void { if (state[i] == .black) return; if (state[i] == .grey) { const d = c.module.types[i]; @@ -66,12 +75,21 @@ fn visitDecl(c: *Context, state: anytype, i: u32) !void { } state[i] = .grey; switch (c.module.types[i].kind) { - .@"struct" => |fs| for (fs) |f| if (f.ty == .named) try visitDecl(c, state, f.ty.named), - .@"enum" => |vs| for (vs) |v| for (v.payload) |t| if (t == .named) try visitDecl(c, state, t.named), + .@"struct" => |fs| for (fs) |f| try visitValue(c, state, f.ty), + .@"enum" => |vs| for (vs) |v| for (v.payload) |t| try visitValue(c, state, t), } state[i] = .black; } +fn visitValue(c: *Context, state: anytype, t: Type) std.mem.Allocator.Error!void { + switch (t) { + .named => |i| try visitDecl(c, state, i), + .array => |a| try visitValue(c, state, a.elem), + .own, .own_array, .buffer, .sender, .receiver, .mutex, .ref, .mut, .slice, .slice_mut, .guard, .task, .local => |inner| if (c.module.declares("linear_aggregates")) try visitValue(c, state, inner.*), + else => {}, + } +} + const Position = enum { member, param, ret, block_param, borrowed }; /// Where a type may appear (spec 07 §8.3, §8.8): @@ -85,9 +103,11 @@ fn wellFormed(c: *Context, span: air.Span, t: Type, pos: Position, owner: []cons .void, .never => pos == .ret, .local => false, .ref, .mut, .slice, .slice_mut => pos != .member and pos != .borrowed, - .resource, .own, .own_array, .region, .scope, .task, .shield, .sender, .receiver, .mutex, .guard, .island, .frozen, .arc, .atomic => pos != .member, + .scope, .task, .shield, .guard => pos != .member, + .resource, .own, .own_array, .buffer, .region, .sender, .receiver, .mutex, .island, .frozen, .arc, .atomic => pos != .member or c.module.declares("linear_aggregates"), else => true, }; + if (t == .own_array and c.module.declares("linear_aggregates") and c.module.isLinearType(t.own_array.*)) try c.report("E1001", span, "dynamic heap arrays require Copy content", &.{}); // An atomic cell holds an AtomicScalar (spec 04 §23). if (t == .atomic and !isAtomicScalar(t.atomic.*)) try c.report("E1001", span, "atomic needs bool or an integer of at most 64 bits", &.{ .{ .name = "in", .value = .{ .str = owner } }, @@ -117,6 +137,16 @@ fn wellFormed(c: *Context, span: air.Span, t: Type, pos: Position, owner: []cons }, owner); } +/// Validate a phantom or used source generic argument by ordinary type rules. +pub fn checkTypeArgument(c: *Context, span: air.Span, t: Type) !void { + try wellFormed(c, span, t, .param, "generic argument"); + try argumentLengths(c, span, t); +} +fn argumentLengths(c: *Context, span: air.Span, t: Type) !void { + if (t == .array and (t.array.len == 0 or t.array.len > (1 << 32))) try c.report("E1001", span, "array length outside format-0 range", &.{}); + if (t.inner()) |inner| try argumentLengths(c, span, inner); +} + /// `local.alloc` results are checked separately: their own type is storage. fn zeroable(m: air.Module, t: Type) bool { return switch (t) { @@ -228,6 +258,7 @@ const FnCtx = struct { fn resultType(m: air.Module, op: air.Op) ?Type { return switch (op) { .@"const" => |x| x.ty, + .error_const => |x| .{ .builtin = x.which }, .arith => |x| .{ .int = x.ty }, .bit => |x| x.ty, .cmp => .bool, @@ -236,7 +267,7 @@ fn resultType(m: air.Module, op: air.Op) ?Type { .struct_get => |x| m.types[x.decl].kind.@"struct"[x.field].ty, .enum_make => |x| .{ .named = x.decl }, .call => |x| m.functions[x.callee].ret, - .slice_len => .{ .int = .usize }, + .slice_len, .buffer_len, .buffer_capacity => .{ .int = .usize }, .task_scope_begin => .scope, .task_cancelled => .bool, .task_shield_begin => .shield, @@ -246,7 +277,7 @@ fn resultType(m: air.Module, op: air.Op) ?Type { if (reg.fallible or reg.results.len == 0) break :blk .void; break :blk intrinsicResult(reg.results[0]); }, - .array_splat => |x| x.ty, + inline .array_splat, .array_make => |x| x.ty, else => null, }; } @@ -338,6 +369,35 @@ fn checkIntrinsic(fc: *FnCtx, inst: air.Inst, x: @FieldType(air.Op, "intrinsic") } } +/// Structural Copy query for source constraints; borrows remain second-class. +pub fn isCopy(m: air.Module, t: Type) bool { + return switch (t) { + .int, .bool, .builtin, .cap, .iref => true, + .array => |a| isCopy(m, a.elem), + .named => |i| aggregateAll(m, i, isCopy), + else => false, + }; +} + +/// Local is context-bound state, not the complement of Send (spec 15 §15). +pub fn isLocalType(m: air.Module, t: Type) bool { + return switch (t) { + .local, .task, .scope, .shield, .guard => true, + .ref, .mut, .slice, .slice_mut, .own, .own_array, .buffer, .mutex => |inner| isLocalType(m, inner.*), + .array => |a| isLocalType(m, a.elem), + .named => |i| switch (m.types[i].kind) { + .@"struct" => |fs| for (fs) |f| { + if (isLocalType(m, f.ty)) break true; + } else false, + .@"enum" => |vs| blk: { + for (vs) |v| for (v.payload) |p| if (isLocalType(m, p)) break :blk true; + break :blk false; + }, + }, + else => false, + }; +} + /// `Send` (spec 04 §35): may move to another task. pub fn isSend(m: air.Module, t: Type) bool { return switch (t) { @@ -346,7 +406,7 @@ pub fn isSend(m: air.Module, t: Type) bool { .island, .frozen, .arc, .iref => true, // Every access to a cell is an atomic operation (spec 04 §23). .atomic => true, - .own, .own_array, .mutex => |inner| isSend(m, inner.*), + .own, .own_array, .buffer, .mutex => |inner| isSend(m, inner.*), .ref, .slice => |inner| isShare(m, inner.*), .mut, .slice_mut => |inner| isSend(m, inner.*), .array => |a| isSend(m, a.elem), @@ -363,7 +423,7 @@ pub fn isShare(m: air.Module, t: Type) bool { // Its owner may mutate it: freeze to share (spec 04 §35). .island => false, .resource, .region, .mut, .slice_mut, .scope, .task, .shield, .guard, .sender, .receiver, .local, .void, .never => false, - .own, .own_array, .ref, .slice => |inner| isShare(m, inner.*), + .own, .own_array, .buffer, .ref, .slice => |inner| isShare(m, inner.*), // The lock synchronizes access (spec 04 §35, §40). .mutex => |inner| isSend(m, inner.*), .array => |a| isShare(m, a.elem), @@ -543,6 +603,17 @@ fn checkSelect(fc: *FnCtx, inst: air.Inst, x: @FieldType(air.Op, "select")) !voi _ = f; } +fn bufferElement(fc: *FnCtx, span: air.Span, v: air.ValueId, mutable: bool) !?Type { + const t = fc.typeOf(v); + if ((t == .mut or (!mutable and t == .ref)) and t.inner().? == .buffer) return t.inner().?.buffer.*; + try fc.kindError(span, v, if (mutable) "mut>" else "ref> or mut>"); + return null; +} + +pub fn complete(t: Type) bool { + return t != .void and t != .never and t != .local and !t.isBorrow() and !t.isTaskBound() and t != .guard; +} + fn boxed(arena: std.mem.Allocator, t: Type) !*const Type { const b = try arena.create(Type); b.* = t; @@ -559,7 +630,8 @@ fn derivedType(fc: *FnCtx, op: air.Op) !?Type { .copy => |v| return fc.ty[v], .local_alloc => |inner| return .{ .local = try boxed(a, inner) }, .local_load => |v| fc.ty[v] orelse return null, - .borrow_ref, .borrow_mut, .load, .slice_make => |v| fc.ty[v] orelse return null, + .buffer_view, .borrow_ref, .borrow_mut, .load, .slice_make => |v| fc.ty[v] orelse return null, + .value_swap => |x| fc.ty[x.borrow] orelse return null, .borrow_field => |x| fc.ty[x.borrow] orelse return null, .borrow_index => |x| fc.ty[x.borrow] orelse return null, .slice_sub => |x| fc.ty[x.slice] orelse return null, @@ -580,10 +652,13 @@ fn derivedType(fc: *FnCtx, op: air.Op) !?Type { }; const invalid: Type = .void; return switch (op) { + .buffer_view => if ((t == .ref or t == .mut) and t.inner().? == .buffer) (if (t == .mut) .{ .slice_mut = try boxed(a, t.inner().?.buffer.*) } else .{ .slice = try boxed(a, t.inner().?.buffer.*) }) else invalid, + .value_swap => if (t == .mut) t.mut.* else invalid, .local_load => if (t == .local) t.local.* else invalid, .borrow_ref => switch (t) { .local, .ref, .mut => .{ .ref = try boxed(a, t.inner().?) }, - .resource, .region, .task, .scope, .sender, .receiver, .mutex, .island, .frozen, .arc, .atomic => .{ .ref = try boxed(a, t) }, + .named, .array => if (m.isLinearType(t)) .{ .ref = try boxed(a, t) } else invalid, + .resource, .region, .task, .scope, .sender, .receiver, .mutex, .buffer, .island, .frozen, .arc, .atomic => .{ .ref = try boxed(a, t) }, .own => |inner| .{ .ref = inner }, .own_array => |inner| .{ .slice = inner }, .slice, .slice_mut => .{ .slice = try boxed(a, t.inner().?) }, @@ -591,7 +666,8 @@ fn derivedType(fc: *FnCtx, op: air.Op) !?Type { }, .borrow_mut => switch (t) { .local, .mut => .{ .mut = try boxed(a, t.inner().?) }, - .resource, .region, .task, .scope, .sender, .receiver, .island => .{ .mut = try boxed(a, t) }, + .named, .array => if (m.isLinearType(t)) .{ .mut = try boxed(a, t) } else invalid, + .resource, .region, .task, .scope, .sender, .receiver, .buffer, .island => .{ .mut = try boxed(a, t) }, .own => |inner| .{ .mut = inner }, .own_array => |inner| .{ .slice_mut = inner }, .slice_mut => .{ .slice_mut = try boxed(a, t.inner().?) }, @@ -719,11 +795,13 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { const span = inst.span; switch (inst.op) { .@"const", .trap => {}, - .copy => |v| if (!fc.typeOf(v).isValue()) try fc.c.report("E1001", span, "only value types can be copied", &.{ + .error_const => |x| if (x.variant >= x.which.variants().len) try fc.c.report("E1001", span, "invalid built-in error variant", &.{}), + .copy => |v| if (!fc.typeOf(v).isValue() or m.isLinearType(fc.typeOf(v))) try fc.c.report("E1001", span, "only value types can be copied", &.{ .{ .name = "function", .value = .{ .str = f.name } }, .{ .name = "found", .value = .{ .str = try fc.c.typeName(fc.typeOf(v)) } }, }), - .local_alloc, .slice_len => {}, + .local_alloc => |t| if (m.isLinearType(t)) try fc.c.report("E1001", span, "frame storage requires Copy content", &.{}), + .slice_len => {}, .local_store => |x| { const t = fc.typeOf(x.local); if (t != .local) return fc.kindError(span, x.local, "local"); @@ -737,7 +815,9 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { .{ .name = "found", .value = .{ .str = try fc.c.typeName(t.local.*) } }, }); }, - .local_load => |v| if (fc.typeOf(v) != .local) try fc.kindError(span, v, "local"), + .local_load => |v| { + if (fc.typeOf(v) != .local) try fc.kindError(span, v, "local"); + }, .borrow_ref => |v| if (resultOf(fc, inst) == .void) try fc.kindError(span, v, "local, a resource, ref, mut, slice or slice_mut"), .borrow_mut => |v| if (resultOf(fc, inst) == .void) try fc.kindError(span, v, "local, a resource, mut or slice_mut"), .borrow_field => |x| if (resultOf(fc, inst) == .void) try fc.kindError(span, x.borrow, "ref or mut of the named struct"), @@ -745,12 +825,68 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { .load => |v| { if (atomicPointee(fc.typeOf(v))) return ordinaryAtomicAccess(fc, span, v, "atomic.load"); if (resultOf(fc, inst) == .void) try fc.kindError(span, v, "ref or mut"); + if (m.isLinearType(resultOf(fc, inst))) try fc.c.report("E1001", span, "load cannot copy linear content; exchange or unpack", &.{}); }, .store => |x| { const t = fc.typeOf(x.borrow); if (atomicPointee(t)) return ordinaryAtomicAccess(fc, span, x.borrow, "atomic.store"); if (t != .mut) return fc.kindError(span, x.borrow, "mut"); try fc.expectValue(span, x.value, t.mut.*); + if (m.isLinearType(t.mut.*)) try fc.c.report("E1001", span, "store cannot overwrite linear content; use value.swap", &.{}); + }, + .value_swap => |x| { + const t = fc.typeOf(x.borrow); + if (atomicPointee(t)) return ordinaryAtomicAccess(fc, span, x.borrow, "atomic operations"); + if (t != .mut) return fc.kindError(span, x.borrow, "mut"); + try fc.expectValue(span, x.value, t.mut.*); + if (!complete(t.mut.*)) try fc.kindError(span, x.value, "a complete value"); + }, + .buffer_new => |x| { + try fc.expectValue(span, x.n, .{ .int = .usize }); + try fc.expectAllocCap(span, x.cap); + if (!complete(x.ty)) return fc.kindError(span, x.n, "complete buffer content"); + try fc.expectParams(span, x.ok, &.{.{ .buffer = try boxed(fc.c.arena, x.ty) }}); + try fc.expectParams(span, x.err, &.{.{ .builtin = .alloc_error }}); + }, + .buffer_len, .buffer_capacity, .buffer_view => |v| { + _ = try bufferElement(fc, span, v, false); + }, + .buffer_reserve => |x| { + _ = try bufferElement(fc, span, x.borrow, true); + try fc.expectValue(span, x.n, .{ .int = .usize }); + try fc.expectAllocCap(span, x.cap); + try fc.expectParams(span, x.err, &.{.{ .builtin = .alloc_error }}); + }, + .buffer_push => |x| { + const t = try bufferElement(fc, span, x.borrow, true) orelse return; + try fc.expectValue(span, x.value, t); + try fc.expectParams(span, x.err, &.{t}); + }, + .buffer_pop => |x| { + const t = try bufferElement(fc, span, x.value, true) orelse return; + try fc.expectParams(span, x.ok, &.{t}); + }, + .buffer_free => |x| { + const t = fc.typeOf(x.value); + if (t != .buffer) return fc.kindError(span, x.value, "buffer"); + try fc.expectParams(span, x.err, &.{t}); + }, + .array_make => |x| { + if (x.ty != .array) return fc.c.report("E1001", span, "array.make needs an array type", &.{}); + if (x.args.len != x.ty.array.len) return fc.c.report("E1001", span, "array.make requires every element", &.{}); + for (x.args) |arg| try fc.expectValue(span, arg, x.ty.array.elem); + }, + .aggregate_unpack => |x| { + try fc.expectValue(span, x.value, x.ty); + switch (x.ty) { + .array => |a| for (f.blocks[x.next].params) |p| { + if (!p.ty.eql(a.elem)) try fc.mismatch(span, try fc.c.valueName(f, p.value), a.elem, p.ty); + }, + .named => |i| if (m.types[i].kind == .@"struct") { + for (f.blocks[x.next].params, m.types[i].kind.@"struct") |p, field| if (!p.ty.eql(field.ty)) try fc.mismatch(span, try fc.c.valueName(f, p.value), field.ty, p.ty); + } else try fc.c.report("E1001", span, "unpack requires a struct or array", &.{}), + else => try fc.c.report("E1001", span, "unpack requires a struct or array", &.{}), + } }, .array_splat => |x| { if (x.ty != .array) return fc.c.report("E1001", span, "array.splat needs an array type", &.{ @@ -758,6 +894,7 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { .{ .name = "found", .value = .{ .str = try fc.c.typeName(x.ty) } }, }); try fc.expectValue(span, x.value, x.ty.array.elem); + if (m.isLinearType(x.ty.array.elem)) try fc.c.report("E1001", span, "array.splat cannot duplicate linear elements", &.{}); }, .borrow_index => |x| { if (resultOf(fc, inst) == .void) return fc.kindError(span, x.borrow, "a borrow of an array, or a slice"); @@ -775,6 +912,7 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { }, .slice_copy => |x| { const d = fc.typeOf(x.dst); + if (d == .slice_mut and m.isLinearType(d.inner().?)) return fc.c.report("E1001", span, "slice.copy cannot copy linear elements", &.{}); if (d != .slice_mut) return fc.kindError(span, x.dst, "slice_mut"); const s = fc.typeOf(x.src); if (!s.isSlice() or !s.inner().?.eql(d.inner().?)) return fc.kindError(span, x.src, try std.fmt.allocPrint(fc.c.arena, "slice<{s}> or slice_mut<{s}>", .{ try fc.c.typeName(d.inner().?), try fc.c.typeName(d.inner().?) })); @@ -807,7 +945,10 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { for (fields, tys) |fld, *t| t.* = fld.ty; try fc.expectArgs(span, x.args, tys); }, - .struct_get => |x| try fc.expectValue(span, x.a, .{ .named = x.decl }), + .struct_get => |x| { + try fc.expectValue(span, x.a, .{ .named = x.decl }); + if (m.isLinearType(m.types[x.decl].kind.@"struct"[x.field].ty)) try fc.c.report("E1001", span, "linear fields require whole unpack or borrowed exchange", &.{}); + }, .enum_make => |x| try fc.expectArgs(span, x.args, m.types[x.decl].kind.@"enum"[x.variant].payload), .call => |x| { const callee = m.functions[x.callee]; @@ -837,7 +978,9 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { for (x.cases) |case| try fc.expectTarget(case.span, case.target); try fc.expectTarget(span, x.default); }, - .enum_switch => |x| { + inline .enum_switch, .enum_take => |x| { + if (inst.op == .enum_take and x.ty != .named) try fc.c.report("E1001", span, "enum.take requires a declared enum", &.{}); + if (inst.op == .enum_switch and m.isLinearType(x.ty)) try fc.c.report("E1001", span, "linear enums require enum.take", &.{}); try fc.expectValue(span, x.value, x.ty); for (x.arms) |arm| { const params = f.blocks[arm.block].params; @@ -848,21 +991,32 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { if (x.default) |d| try fc.expectTarget(span, d); }, .intrinsic => |x| try checkIntrinsic(fc, inst, x), + .own_pack => |x| { + try fc.expectAllocCap(span, x.cap); + try fc.expectValue(span, x.value, x.ty); + if (!complete(x.ty)) return fc.kindError(span, x.value, "a complete value"); + try fc.expectParams(span, x.ok, &.{.{ .own = try boxed(fc.c.arena, x.ty) }}); + try fc.expectParams(span, x.err, &.{ .{ .builtin = .alloc_error }, x.ty }); + }, .own_new => |x| { try fc.expectAllocCap(span, x.cap); const t = fc.typeOf(x.value); - if (!t.isValue()) return fc.kindError(span, x.value, "a value type"); + if (!t.isValue() or m.isLinearType(t)) return fc.kindError(span, x.value, "a Copy value type"); try fc.expectOkErr(span, x.ok, x.err, .{ .own = try boxed(fc.c.arena, t) }); }, .own_array => |x| { try fc.expectValue(span, x.n, .{ .int = .usize }); try fc.expectAllocCap(span, x.cap); const t = fc.typeOf(x.value); - if (!t.isValue()) return fc.kindError(span, x.value, "a value type"); + if (!t.isValue() or m.isLinearType(t)) return fc.kindError(span, x.value, "a Copy value type"); try fc.expectOkErr(span, x.ok, x.err, .{ .own_array = try boxed(fc.c.arena, t) }); }, .own_take => |v| if (fc.typeOf(v) != .own) try fc.kindError(span, v, "own"), - .own_free => |v| if (fc.typeOf(v) != .own and fc.typeOf(v) != .own_array) try fc.kindError(span, v, "own or own_array"), + .own_free => |v| { + const t = fc.typeOf(v); + if (t != .own and t != .own_array) return fc.kindError(span, v, "own or own_array"); + if (m.isLinearType(t.inner().?)) try fc.c.report("E1001", span, "own.free cannot destroy linear content; use own.take", &.{}); + }, .region_create => |x| { try fc.expectAllocCap(span, x.cap); try fc.expectOkErr(span, x.ok, x.err, .region); @@ -870,14 +1024,14 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void { .region_new => |x| { try fc.expectRegionRef(span, x.region); const t = fc.typeOf(x.value); - if (!t.isValue()) return fc.kindError(span, x.value, "a value type"); + if (!t.isValue() or m.isLinearType(t)) return fc.kindError(span, x.value, "a Copy value type"); try fc.expectOkErr(span, x.ok, x.err, .{ .mut = try boxed(fc.c.arena, t) }); }, .region_array => |x| { try fc.expectRegionRef(span, x.region); try fc.expectValue(span, x.n, .{ .int = .usize }); const t = fc.typeOf(x.value); - if (!t.isValue()) return fc.kindError(span, x.value, "a value type"); + if (!t.isValue() or m.isLinearType(t)) return fc.kindError(span, x.value, "a Copy value type"); try fc.expectOkErr(span, x.ok, x.err, .{ .slice_mut = try boxed(fc.c.arena, t) }); }, .region_reset, .region_destroy => |v| if (fc.typeOf(v) != .region) try fc.kindError(span, v, "region"), diff --git a/std/README.md b/std/README.md new file mode 100644 index 0000000..abedacb --- /dev/null +++ b/std/README.md @@ -0,0 +1,57 @@ +# Aji standard library + +Nineteen compiler-pinned modules implemented in ordinary safe `.aji`. Imports compile through the normal frontend and verifier. Modules are embedded with the compiler; an installed compiler needs no runtime std search path. + +| Modules | Purpose | +|---|---| +| `std.math`, `std.bytes`, `std.hash` | checked arithmetic, byte operations, endian reads/writes, non-cryptographic hashes | +| `std.utf8`, `std.encoding.hex`, `std.encoding.base64`, `std.fmt` | validation, caller-buffer encoding and decimal formatting | +| `std.option`, `std.result` | explicit generic result values | +| `std.vec`, `std.deque`, `std.map`, `std.hashmap`, `std.hashset`, `std.heap` | owning collections with explicit allocation, growth and draining | +| `std.io`, `std.io.reader`, `std.io.writer` | bounded I/O and owning buffered file adapters | +| `std.path` | pure lexical paths and caller-buffer normalization/join | + +Owning collections support resources such as files and channel endpoints. Allocation requires explicit authority; resources must be consumed explicitly. Importing a module grants no capabilities. STD-0..7 is the intermediate foundation; remaining Std 0.1 system APIs and integration examples are tracked in the [plan](../docs/plan/standard-library.md). + +```aji +module example +import std.bytes; +import std.math; + +fn main() -> u64 +effects [] +{ + var data: [u8; 4] = zero; + std.bytes.fill(mut data, 65); + assert(std.bytes.equal(ref data, b"AAAA")); + return std.math.min_u64(42, 100); +} +``` + +Run `zig build`, then `zig-out/bin/aji run --fuel 1000000 examples/std/bytes.aji`. No grants are needed for the pure modules. `zig build conformance -- --filter source/std` exercises the library; the full suite also checks the Quick Reference example. + +Endian APIs read/write u16/u32/u64 in LE/BE order. Reads return `std.bytes.ReadU16`, `ReadU32` or `ReadU64` (`ok(value)` / `short_input`); writes return `std.bytes.WriteResult` (`ok` / `short_output`). A short write leaves the entire destination unchanged. Pass a sub-slice for an offset. [Endian example](../examples/std/endian.aji) returns 305419896 and needs no grants. + +`std.bytes.copy` reuses `WriteResult` and preserves the whole destination on short output. `find_slice` returns `FindResult::found(index)` / `not_found`; explicit slices compose a split without returned borrows. `std.math.checked_add/sub/mul_u64` and the `_usize` forms return typed `ok(value)` / `overflow` enums; wrapping stays with `+%`, `-%`, `*%`. The [bounded example](../examples/std/bounded.aji) returns 10 without grants. + +`std.utf8.next/validate` use Unicode scalar values and explicit byte offsets. `std.encoding.hex` and `std.encoding.base64` encode/decode into caller-provided buffers; malformed input and short capacity are enum results, with no destination mutation on returned errors. Hex emits lowercase and accepts mixed case. Base64 is canonical, padded and uses the standard alphabet. The [text example](../examples/std/text.aji) returns 8364 without grants. + +`std.fmt.write_u64/i64/usize/isize` write decimal ASCII into supplied buffers with `WriteResult::ok(count)` / `short_output`. Counts include a negative sign; short output stays unchanged, suffixes stay unchanged on success and no terminator is written. The [formatting example](../examples/std/format.aji) composes `value=-42 count=7` with explicit offsets and returns 17 without grants. + +The compiler uses its embedded copy, so rebuild after editing these files. An installed compiler needs neither this checkout nor a runtime std search path. Standard enum types use fully qualified names in signatures, constructors and matches. Package imports and imported struct literals use explicit manifest mappings ([example](../examples/modules/aji.toml), spec 15 §14). Explicit generics and whole-value owning option/result templates are implemented; std.vec uses the initialized buffer contract with explicit reserve, bounded push and empty-only free. + +[API reference](../docs/reference/std.md) · [Specification](../docs/spec/16-standard-library.md) · [Plan](../docs/plan/standard-library.md) · [Import RFC](../docs/rfcs/0016-standard-library-bootstrap.md) · [Endian RFC](../docs/rfcs/0017-standard-endian-results.md) · [Bounded operations RFC](../docs/rfcs/0018-bounded-standard-operations.md) · [Text RFC](../docs/rfcs/0019-standard-text-encodings.md) + +[Formatting RFC](../docs/rfcs/0020-supplied-buffer-integer-formatting.md) + +`std.option.Option` and `std.result.Result` use explicit specialization and ordinary exhaustive enum matching. `is_some::`/`is_ok::` classify variants without allocation. [Generic example](../examples/std/generics.aji) returns 42; owners/resources are supported by linear_aggregates with exhaustive `match move`; borrows remain invalid members. The classification helpers keep Copy constraints. + +STD-5 supports whole-value owning structs/enums/fixed arrays and individual own content. STD-6a/b adds initialized buffer and std.vec; no bulk operation hides nested cleanup. + +`std.vec` provides nine generic functions over Copy/owning values, including files and channel endpoints. Explicit new/reserve require allocation authority; push never grows, free requires empty contents. [Vector example](../examples/std/vector.aji) and [RFC 0024](../docs/rfcs/0024-linear-buffers-and-vectors.md). + +`std.deque` provides eleven generic functions for a bounded owning ring, including push/pop at both ends. Allocation is explicit in new/reserve; failed growth, full push and nonempty free preserve the queue. Slots hold Option and include its tag in the charge. Users drain/consume their elements before free. [Deque example](../examples/std/deque.aji) and [RFC 0025](../docs/rfcs/0025-owning-deque.md). + +`std.hash` provides FNV-1a 64 and Castagnoli CRC-32C, with one fresh and one continuation function per algorithm. It reads byte slices with effects [], no allocation or authority; numeric results and chunking are deterministic. These are non-cryptographic algorithms and hashes never establish key equality. [Hash example](../examples/std/hash.aji) returns 42 without grants. `std.map` supports numeric keys; `std.hashmap` and `std.hashset` use explicit static hash/equality operations, and `std.heap` uses an explicit static order. Complete ownership, failure and cleanup contracts are in the [API reference](../docs/reference/std.md). + +`std.io` composes exact/bounded reads and limited copies into caller storage. `std.io.reader`/`std.io.writer` own a file and a fixed buffer, with explicit finish/discard; a failed writer preserves its first error and never retries. `std.path` uses slash-separated bytes in every profile; lexical success grants no filesystem authority. [Path example](../examples/std/path.aji) returns 42 without grants. diff --git a/std/bytes.aji b/std/bytes.aji new file mode 100644 index 0000000..57eab6b --- /dev/null +++ b/std/bytes.aji @@ -0,0 +1,212 @@ +module std.bytes + +fn equal(a: slice, b: slice) -> bool +effects [] +{ + if a.len != b.len { return false; } + for i in 0..a.len { + if a[i] != b[i] { return false; } + } + return true; +} + +fn compare(a: slice, b: slice) -> i8 +effects [] +{ + var i: usize = 0; + while i < a.len and i < b.len { + if a[i] < b[i] { return -1; } + if a[i] > b[i] { return 1; } + i = i + 1; + } + if a.len < b.len { return -1; } + if a.len > b.len { return 1; } + return 0; +} + +fn find(data: slice, byte: u8) -> usize +effects [] +{ + for i in 0..data.len { + if data[i] == byte { return i; } + } + return data.len; +} + +fn starts_with(data: slice, prefix: slice) -> bool +effects [] +{ + if prefix.len > data.len { return false; } + for i in 0..prefix.len { + if data[i] != prefix[i] { return false; } + } + return true; +} + +fn ends_with(data: slice, suffix: slice) -> bool +effects [] +{ + if suffix.len > data.len { return false; } + let start = data.len - suffix.len; + for i in 0..suffix.len { + if data[start + i] != suffix[i] { return false; } + } + return true; +} + +fn fill(dst: slice_mut, byte: u8) -> void +effects [] +{ + for i in 0..dst.len { dst[i] = byte; } +} + +// Endian results contain a value only on success. +enum ReadU16 { ok(u16), short_input } +enum ReadU32 { ok(u32), short_input } +enum ReadU64 { ok(u64), short_input } +enum WriteResult { ok, short_output } + +fn read_u16_le(src: slice) -> std.bytes.ReadU16 +effects [] +{ + if src.len < 2 { return std.bytes.ReadU16::short_input; } + let value: u16 = (src[0] as u16) | ((src[1] as u16) << 8); + return std.bytes.ReadU16::ok(value); +} + +fn write_u16_le(dst: slice_mut, value: u16) -> std.bytes.WriteResult +effects [] +{ + if dst.len < 2 { return std.bytes.WriteResult::short_output; } + dst[0] = value as% u8; + dst[1] = (value >> 8) as% u8; + return std.bytes.WriteResult::ok; +} + +fn read_u16_be(src: slice) -> std.bytes.ReadU16 +effects [] +{ + if src.len < 2 { return std.bytes.ReadU16::short_input; } + let value: u16 = ((src[0] as u16) << 8) | (src[1] as u16); + return std.bytes.ReadU16::ok(value); +} + +fn write_u16_be(dst: slice_mut, value: u16) -> std.bytes.WriteResult +effects [] +{ + if dst.len < 2 { return std.bytes.WriteResult::short_output; } + dst[0] = (value >> 8) as% u8; + dst[1] = value as% u8; + return std.bytes.WriteResult::ok; +} + +fn read_u32_le(src: slice) -> std.bytes.ReadU32 +effects [] +{ + if src.len < 4 { return std.bytes.ReadU32::short_input; } + let value: u32 = (src[0] as u32) | ((src[1] as u32) << 8) | ((src[2] as u32) << 16) | ((src[3] as u32) << 24); + return std.bytes.ReadU32::ok(value); +} + +fn write_u32_le(dst: slice_mut, value: u32) -> std.bytes.WriteResult +effects [] +{ + if dst.len < 4 { return std.bytes.WriteResult::short_output; } + dst[0] = value as% u8; + dst[1] = (value >> 8) as% u8; + dst[2] = (value >> 16) as% u8; + dst[3] = (value >> 24) as% u8; + return std.bytes.WriteResult::ok; +} + +fn read_u32_be(src: slice) -> std.bytes.ReadU32 +effects [] +{ + if src.len < 4 { return std.bytes.ReadU32::short_input; } + let value: u32 = ((src[0] as u32) << 24) | ((src[1] as u32) << 16) | ((src[2] as u32) << 8) | (src[3] as u32); + return std.bytes.ReadU32::ok(value); +} + +fn write_u32_be(dst: slice_mut, value: u32) -> std.bytes.WriteResult +effects [] +{ + if dst.len < 4 { return std.bytes.WriteResult::short_output; } + dst[0] = (value >> 24) as% u8; + dst[1] = (value >> 16) as% u8; + dst[2] = (value >> 8) as% u8; + dst[3] = value as% u8; + return std.bytes.WriteResult::ok; +} + +fn read_u64_le(src: slice) -> std.bytes.ReadU64 +effects [] +{ + if src.len < 8 { return std.bytes.ReadU64::short_input; } + let value: u64 = (src[0] as u64) | ((src[1] as u64) << 8) | ((src[2] as u64) << 16) | ((src[3] as u64) << 24) | ((src[4] as u64) << 32) | ((src[5] as u64) << 40) | ((src[6] as u64) << 48) | ((src[7] as u64) << 56); + return std.bytes.ReadU64::ok(value); +} + +fn write_u64_le(dst: slice_mut, value: u64) -> std.bytes.WriteResult +effects [] +{ + if dst.len < 8 { return std.bytes.WriteResult::short_output; } + dst[0] = value as% u8; + dst[1] = (value >> 8) as% u8; + dst[2] = (value >> 16) as% u8; + dst[3] = (value >> 24) as% u8; + dst[4] = (value >> 32) as% u8; + dst[5] = (value >> 40) as% u8; + dst[6] = (value >> 48) as% u8; + dst[7] = (value >> 56) as% u8; + return std.bytes.WriteResult::ok; +} + +fn read_u64_be(src: slice) -> std.bytes.ReadU64 +effects [] +{ + if src.len < 8 { return std.bytes.ReadU64::short_input; } + let value: u64 = ((src[0] as u64) << 56) | ((src[1] as u64) << 48) | ((src[2] as u64) << 40) | ((src[3] as u64) << 32) | ((src[4] as u64) << 24) | ((src[5] as u64) << 16) | ((src[6] as u64) << 8) | (src[7] as u64); + return std.bytes.ReadU64::ok(value); +} + +fn write_u64_be(dst: slice_mut, value: u64) -> std.bytes.WriteResult +effects [] +{ + if dst.len < 8 { return std.bytes.WriteResult::short_output; } + dst[0] = (value >> 56) as% u8; + dst[1] = (value >> 48) as% u8; + dst[2] = (value >> 40) as% u8; + dst[3] = (value >> 32) as% u8; + dst[4] = (value >> 24) as% u8; + dst[5] = (value >> 16) as% u8; + dst[6] = (value >> 8) as% u8; + dst[7] = value as% u8; + return std.bytes.WriteResult::ok; +} + +fn copy(dst: slice_mut, src: slice) -> std.bytes.WriteResult +effects [] +{ + if dst.len < src.len { return std.bytes.WriteResult::short_output; } + slice.copy(mut dst, ref src); + return std.bytes.WriteResult::ok; +} + +enum FindResult { found(usize), not_found } + +fn find_slice(data: slice, needle: slice) -> std.bytes.FindResult +effects [] +{ + if needle.len == 0 { return std.bytes.FindResult::found(0); } + if needle.len > data.len { return std.bytes.FindResult::not_found; } + let last = data.len - needle.len; + var start: usize = 0; + loop { + if std.bytes.equal(ref data[start..start + needle.len], ref needle) { + return std.bytes.FindResult::found(start); + } + if start == last { break; } + start = start + 1; + } + return std.bytes.FindResult::not_found; +} diff --git a/std/deque.aji b/std/deque.aji new file mode 100644 index 0000000..0b9ed7b --- /dev/null +++ b/std/deque.aji @@ -0,0 +1,200 @@ +module std.deque +import std.option; + +struct Deque { storage: buffer>, head: usize, length: usize } +enum NewResult { ok(Deque), err(alloc_error) } +enum PushResult { ok, full(T) } +enum ReserveResult { ok, err(alloc_error) } +enum FreeResult { ok, not_empty(Deque) } +enum ReplaceResult { ok(T), out_of_bounds(T) } + +fn new(capacity: usize, heap: cap) -> NewResult +effects [mem.alloc] +{ + match buffer.new>(capacity, heap) { + ok(storage) => { + { + mut slots = storage; + for index in 0usize..capacity { + let empty = std.option.Option::::none; + buffer.push(slots, move empty) or trap; + } + } + return NewResult::::ok(Deque:: { storage: move storage, head: 0, length: 0 }); + } + err(error) => { return NewResult::::err(error); } + } +} + +fn len(value: ref>) -> usize effects [] { + return value.length; +} + +fn capacity(value: ref>) -> usize effects [] { + ref slots = value.storage; + return buffer.capacity(slots); +} + +fn reserve(value: mut>, capacity: usize, heap: cap) -> ReserveResult +effects [mem.alloc] +{ + let head = value.head; + mut storage = value.storage; + let old_capacity = buffer.capacity(storage); + if capacity <= old_capacity { return ReserveResult::ok; } + match buffer.reserve(storage, capacity, heap) { + ok() => {} + err(error) => { return ReserveResult::err(error); } + } + for index in old_capacity..capacity { + let empty = std.option.Option::::none; + buffer.push(storage, move empty) or trap; + } + if head != 0usize { + // Three reversals rotate the original slots left by head. + mut slots = buffer.view(storage); + for pass in 0usize..3usize { + var first: usize = 0; + var stop: usize = head; + if pass == 1usize { first = head; stop = old_capacity; } + if pass == 2usize { stop = old_capacity; } + while first < stop { + stop = stop - 1; + if first < stop { + let empty = std.option.Option::::none; + let left = value.swap(mut slots[first], move empty); + let right = value.swap(mut slots[stop], move left); + let hole = value.swap(mut slots[first], move right); + match move hole { + std.option.Option::::none => {} + std.option.Option::::some(unexpected) => { trap; } + } + } + first = first + 1; + } + } + } + value.head = 0; + return ReserveResult::ok; +} + +fn push_back(value: mut>, item: T) -> PushResult effects [] { + let length = value.length; + let head = value.head; + mut storage = value.storage; + let capacity = buffer.capacity(storage); + if length == capacity { return PushResult::::full(move item); } + let room = capacity - head; + let index = if length < room { head + length } else { length - room }; + mut slots = buffer.view(storage); + let next = std.option.Option::::some(move item); + let previous = value.swap(mut slots[index], move next); + match move previous { + std.option.Option::::none => {} + std.option.Option::::some(unexpected) => { trap; } + } + value.length = length + 1; + return PushResult::::ok; +} + +fn push_front(value: mut>, item: T) -> PushResult effects [] { + let length = value.length; + let head = value.head; + mut storage = value.storage; + let capacity = buffer.capacity(storage); + if length == capacity { return PushResult::::full(move item); } + let index = if head == 0usize { capacity - 1 } else { head - 1 }; + mut slots = buffer.view(storage); + let next = std.option.Option::::some(move item); + let previous = value.swap(mut slots[index], move next); + match move previous { + std.option.Option::::none => {} + std.option.Option::::some(unexpected) => { trap; } + } + value.head = index; + value.length = length + 1; + return PushResult::::ok; +} + +fn pop_front(value: mut>) -> std.option.Option effects [] { + let length = value.length; + if length == 0usize { return std.option.Option::::none; } + let head = value.head; + mut storage = value.storage; + let capacity = buffer.capacity(storage); + mut slots = buffer.view(storage); + let empty = std.option.Option::::none; + let previous = value.swap(mut slots[head], move empty); + value.length = length - 1; + if length == 1usize { value.head = 0; } + else { value.head = if head == capacity - 1 { 0usize } else { head + 1 }; } + match move previous { + std.option.Option::::some(item) => { return std.option.Option::::some(move item); } + std.option.Option::::none => { trap; } + } +} + +fn pop_back(value: mut>) -> std.option.Option effects [] { + let length = value.length; + if length == 0usize { return std.option.Option::::none; } + let head = value.head; + mut storage = value.storage; + let capacity = buffer.capacity(storage); + let offset = length - 1; + let room = capacity - head; + let index = if offset < room { head + offset } else { offset - room }; + mut slots = buffer.view(storage); + let empty = std.option.Option::::none; + let previous = value.swap(mut slots[index], move empty); + value.length = offset; + if length == 1usize { value.head = 0; } + match move previous { + std.option.Option::::some(item) => { return std.option.Option::::some(move item); } + std.option.Option::::none => { trap; } + } +} + +fn free(value: Deque) -> FreeResult effects [] { + if value.length != 0usize { return FreeResult::::not_empty(move value); } + let (storage, head, length) = struct.unpack(move value); + { + mut slots = storage; + while buffer.len(slots) != 0usize { + let empty = buffer.pop(slots) or trap; + match move empty { + std.option.Option::::none => {} + std.option.Option::::some(unexpected) => { trap; } + } + } + } + buffer.free(move storage) or trap; + return FreeResult::::ok; +} + +fn get(value: ref>, index: usize) -> std.option.Option effects [] { + if index >= value.length { return std.option.Option::::none; } + let head = value.head; + ref storage = value.storage; + let room = buffer.capacity(storage) - head; + let position = if index < room { head + index } else { index - room }; + ref slots = buffer.view(storage); + match slots[position] { + std.option.Option::::some(item) => { return std.option.Option::::some(item); } + std.option.Option::::none => { trap; } + } +} + +fn replace(value: mut>, index: usize, item: T) -> ReplaceResult effects [] { + if index >= value.length { return ReplaceResult::::out_of_bounds(move item); } + let head = value.head; + mut storage = value.storage; + let room = buffer.capacity(storage) - head; + let position = if index < room { head + index } else { index - room }; + mut slots = buffer.view(storage); + let next = std.option.Option::::some(move item); + let previous = value.swap(mut slots[position], move next); + match move previous { + std.option.Option::::some(old) => { return ReplaceResult::::ok(move old); } + std.option.Option::::none => { trap; } + } +} diff --git a/std/encoding/base64.aji b/std/encoding/base64.aji new file mode 100644 index 0000000..a6c7c8f --- /dev/null +++ b/std/encoding/base64.aji @@ -0,0 +1,76 @@ +module std.encoding.base64 + +enum EncodeResult { ok(usize), short_output } +enum DecodeResult { ok(usize), invalid_input, short_output } + +fn encode(dst: slice_mut, src: slice) -> std.encoding.base64.EncodeResult +effects [] +{ + let groups = src.len / 3; + let rest = src.len % 3; + if groups > dst.len / 4 { return std.encoding.base64.EncodeResult::short_output; } + let full = groups * 4; + if rest != 0 and dst.len - full < 4 { return std.encoding.base64.EncodeResult::short_output; } + let count = full + if rest == 0 { 0usize } else { 4usize }; + let alphabet = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + var i: usize = 0; + var out: usize = 0; + while src.len - i >= 3 { + let a = src[i]; let b = src[i + 1]; let c = src[i + 2]; + dst[out] = alphabet[(a >> 2) as! usize]; + dst[out + 1] = alphabet[(((a & 3) << 4) | (b >> 4)) as! usize]; + dst[out + 2] = alphabet[(((b & 15) << 2) | (c >> 6)) as! usize]; + dst[out + 3] = alphabet[(c & 63) as! usize]; + i = i + 3; out = out + 4; + } + if rest != 0 { + let a = src[i]; + let b: u8 = if rest == 2 { src[i + 1] } else { 0u8 }; + dst[out] = alphabet[(a >> 2) as! usize]; + dst[out + 1] = alphabet[(((a & 3) << 4) | (b >> 4)) as! usize]; + dst[out + 2] = if rest == 2 { alphabet[((b & 15) << 2) as! usize] } else { 61u8 }; + dst[out + 3] = 61; + } + return std.encoding.base64.EncodeResult::ok(count); +} + +fn decode(dst: slice_mut, src: slice) -> std.encoding.base64.DecodeResult +effects [] +{ + if src.len % 4 != 0 { return std.encoding.base64.DecodeResult::invalid_input; } + if src.len == 0 { return std.encoding.base64.DecodeResult::ok(0); } + let alphabet = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + var values: [u8; 256] = [255; 256]; + for i in 0..alphabet.len { values[alphabet[i] as! usize] = i as! u8; } + var padding: usize = 0; + if src[src.len - 1] == 61 { + padding = 1; + if src[src.len - 2] == 61 { padding = 2; } + } + for i in 0..src.len - padding { + if values[src[i] as! usize] == 255 { return std.encoding.base64.DecodeResult::invalid_input; } + } + if padding == 2 and (values[src[src.len - 3] as! usize] & 15) != 0 { + return std.encoding.base64.DecodeResult::invalid_input; + } + if padding == 1 and (values[src[src.len - 2] as! usize] & 3) != 0 { + return std.encoding.base64.DecodeResult::invalid_input; + } + let groups = src.len / 4; + let count = groups * 3 - padding; + if count > dst.len { return std.encoding.base64.DecodeResult::short_output; } + for group in 0..groups { + let i = group * 4; let out = group * 3; + let a = values[src[i] as! usize]; let b = values[src[i + 1] as! usize]; + dst[out] = (a << 2) | (b >> 4); + if out + 1 < count { + let c = values[src[i + 2] as! usize]; + dst[out + 1] = (b << 4) | (c >> 2); + if out + 2 < count { + let d = values[src[i + 3] as! usize]; + dst[out + 2] = (c << 6) | d; + } + } + } + return std.encoding.base64.DecodeResult::ok(count); +} diff --git a/std/encoding/hex.aji b/std/encoding/hex.aji new file mode 100644 index 0000000..fbb6c2c --- /dev/null +++ b/std/encoding/hex.aji @@ -0,0 +1,41 @@ +module std.encoding.hex + +enum EncodeResult { ok(usize), short_output } +enum DecodeResult { ok(usize), invalid_input, short_output } + +fn encode(dst: slice_mut, src: slice) -> std.encoding.hex.EncodeResult +effects [] +{ + if src.len > dst.len / 2 { return std.encoding.hex.EncodeResult::short_output; } + let count = src.len * 2; + let alphabet = b"0123456789abcdef"; + for i in 0..src.len { + let byte = src[i]; + dst[i * 2] = alphabet[(byte >> 4) as! usize]; + dst[i * 2 + 1] = alphabet[(byte & 15) as! usize]; + } + return std.encoding.hex.EncodeResult::ok(count); +} + +fn decode(dst: slice_mut, src: slice) -> std.encoding.hex.DecodeResult +effects [] +{ + if src.len % 2 != 0 { return std.encoding.hex.DecodeResult::invalid_input; } + var digits: [u8; 256] = [255; 256]; + for value in 0u8..10u8 { digits[(value + 48) as! usize] = value; } + for value in 0u8..6u8 { + digits[(value + 65) as! usize] = value + 10; + digits[(value + 97) as! usize] = value + 10; + } + for i in 0..src.len { + if digits[src[i] as! usize] == 255 { return std.encoding.hex.DecodeResult::invalid_input; } + } + let count = src.len / 2; + if count > dst.len { return std.encoding.hex.DecodeResult::short_output; } + for i in 0..count { + let high = digits[src[i * 2] as! usize]; + let low = digits[src[i * 2 + 1] as! usize]; + dst[i] = (high << 4) | low; + } + return std.encoding.hex.DecodeResult::ok(count); +} diff --git a/std/fmt.aji b/std/fmt.aji new file mode 100644 index 0000000..b182fda --- /dev/null +++ b/std/fmt.aji @@ -0,0 +1,103 @@ +module std.fmt + +enum WriteResult { ok(usize), short_output } + +fn write_u64(dst: slice_mut, value: u64) -> std.fmt.WriteResult +effects [] +{ + var magnitude: u64 = value; + var count: usize = 1; + var remaining: u64 = magnitude; + while remaining >= 10 { + remaining = remaining / 10; + count = count + 1; + } + if dst.len < count { return std.fmt.WriteResult::short_output; } + var position: usize = count; + loop { + position = position - 1; + dst[position] = (magnitude % 10) as! u8 + 48; + magnitude = magnitude / 10; + if magnitude == 0 { break; } + } + return std.fmt.WriteResult::ok(count); +} + +fn write_i64(dst: slice_mut, value: i64) -> std.fmt.WriteResult +effects [] +{ + let negative = value < 0; + var magnitude: u64 = 0; + if negative { + magnitude = (-(value + 1)) as! u64 + 1; + } else { + magnitude = value as! u64; + } + var count: usize = 1; + var remaining: u64 = magnitude; + while remaining >= 10 { + remaining = remaining / 10; + count = count + 1; + } + if negative { count = count + 1; } + if dst.len < count { return std.fmt.WriteResult::short_output; } + if negative { dst[0] = 45; } + var position: usize = count; + loop { + position = position - 1; + dst[position] = (magnitude % 10) as! u8 + 48; + magnitude = magnitude / 10; + if magnitude == 0 { break; } + } + return std.fmt.WriteResult::ok(count); +} + +fn write_usize(dst: slice_mut, value: usize) -> std.fmt.WriteResult +effects [] +{ + var magnitude: usize = value; + var count: usize = 1; + var remaining: usize = magnitude; + while remaining >= 10 { + remaining = remaining / 10; + count = count + 1; + } + if dst.len < count { return std.fmt.WriteResult::short_output; } + var position: usize = count; + loop { + position = position - 1; + dst[position] = (magnitude % 10) as! u8 + 48; + magnitude = magnitude / 10; + if magnitude == 0 { break; } + } + return std.fmt.WriteResult::ok(count); +} + +fn write_isize(dst: slice_mut, value: isize) -> std.fmt.WriteResult +effects [] +{ + let negative = value < 0; + var magnitude: usize = 0; + if negative { + magnitude = (-(value + 1)) as! usize + 1; + } else { + magnitude = value as! usize; + } + var count: usize = 1; + var remaining: usize = magnitude; + while remaining >= 10 { + remaining = remaining / 10; + count = count + 1; + } + if negative { count = count + 1; } + if dst.len < count { return std.fmt.WriteResult::short_output; } + if negative { dst[0] = 45; } + var position: usize = count; + loop { + position = position - 1; + dst[position] = (magnitude % 10) as! u8 + 48; + magnitude = magnitude / 10; + if magnitude == 0 { break; } + } + return std.fmt.WriteResult::ok(count); +} diff --git a/std/hash.aji b/std/hash.aji new file mode 100644 index 0000000..071cd22 --- /dev/null +++ b/std/hash.aji @@ -0,0 +1,30 @@ +module std.hash + +fn fnv1a64(data: slice) -> u64 effects [] { + return std.hash.fnv1a64_extend(0xcbf29ce484222325u64, data); +} + +fn fnv1a64_extend(state: u64, data: slice) -> u64 effects [] { + var hash: u64 = state; + for index in 0usize..data.len { + hash = (hash ^ (data[index] as u64)) *% 0x100000001b3u64; + } + return hash; +} + +fn crc32c(data: slice) -> u32 effects [] { + return std.hash.crc32c_extend(0u32, data); +} + +fn crc32c_extend(checksum: u32, data: slice) -> u32 effects [] { + var state: u32 = checksum ^ 0xffffffffu32; + for index in 0usize..data.len { + state = state ^ (data[index] as u32); + for bit in 0usize..8usize { + let low = state & 1u32; + state = state >> 1; + if low != 0u32 { state = state ^ 0x82f63b78u32; } + } + } + return state ^ 0xffffffffu32; +} diff --git a/std/hashmap.aji b/std/hashmap.aji new file mode 100644 index 0000000..c8f45bc --- /dev/null +++ b/std/hashmap.aji @@ -0,0 +1,268 @@ +module std.hashmap +import std.option; + +struct StoredEntry { hash: u64, key: K, value: V } +struct Entry { key: K, value: V } +enum BucketState { empty, deleted, occupied } +struct Bucket { hash: u64, index: usize, state: BucketState } +struct HashMap) -> u64 effects [], E: fn(ref, ref) -> bool effects []> { entries: buffer>, buckets: buffer } +enum NewResult) -> u64 effects [], E: fn(ref, ref) -> bool effects []> { ok(HashMap), err(alloc_error) } +enum ReserveResult { ok, err(alloc_error) } +enum InsertResult { inserted, replaced(Entry), full(Entry) } +enum FreeResult) -> u64 effects [], E: fn(ref, ref) -> bool effects []> { ok, not_empty(HashMap) } + +fn new) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> NewResult effects [mem.alloc] { + let maximum = 0usize -% 1usize; + if capacity > maximum / 2usize { return NewResult::::err(alloc_error::budget_exceeded); } + match buffer.new>(capacity, heap) { + err(error) => { return NewResult::::err(error); } + ok(entries) => { + match buffer.new(capacity * 2usize, heap) { + err(error) => { buffer.free(move entries) or trap; return NewResult::::err(error); } + ok(buckets) => { + { mut output = buckets; + for index in 0usize..capacity * 2usize { + buffer.push(output, Bucket { hash: 0, index: 0, state: BucketState::empty }) or trap; + } + } + return NewResult::::ok(HashMap:: { entries: move entries, buckets: move buckets }); + } + } + } + } +} + +fn len) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: ref>) -> usize effects [] { + ref entries = map.entries; return buffer.len(entries); +} + +fn capacity) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: ref>) -> usize effects [] { + ref entries = map.entries; return buffer.capacity(entries); +} + +fn insert) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: mut>, key: K, value: V) -> InsertResult effects [] { + var count: usize = 0; + { ref index = map.buckets; count = buffer.len(index); } + if count == 0usize { return InsertResult::::full(Entry:: { key: move key, value: move value }); } + let incoming = Entry:: { key: move key, value: move value }; + let hash = H(ref incoming.key); + var position: usize = (hash % (count as! u64)) as! usize; + var chosen: usize = count; + var found: bool = false; + var entry_index: usize = 0; + { ref index = map.buckets; ref buckets = buffer.view(index); + ref storage = map.entries; ref entries = buffer.view(storage); + for probe in 0usize..count { + ref bucket = buckets[position]; + var stop: bool = false; + match bucket.state { + BucketState::occupied => { + if bucket.hash == hash { + if E(ref entries[bucket.index].key, ref incoming.key) { found = true; entry_index = bucket.index; } + } + } + BucketState::deleted => { if chosen == count { chosen = position; } } + BucketState::empty => { if chosen == count { chosen = position; } stop = true; } + } + if found or stop { break; } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + } + if found { + let (key, value) = struct.unpack(move incoming); + mut storage = map.entries; mut entries = buffer.view(storage); + let previous = value.swap(mut entries[entry_index], StoredEntry:: { hash: hash, key: move key, value: move value }); + let (old_hash, old_key, old_value) = struct.unpack(move previous); + return InsertResult::::replaced(Entry:: { key: move old_key, value: move old_value }); + } + var length: usize = 0; + { ref storage = map.entries; + length = buffer.len(storage); + if length == buffer.capacity(storage) { return InsertResult::::full(move incoming); } + } + if chosen == count { trap; } + let (key, value) = struct.unpack(move incoming); + { mut storage = map.entries; + buffer.push(storage, StoredEntry:: { hash: hash, key: move key, value: move value }) or trap; + } + { mut index = map.buckets; mut buckets = buffer.view(index); + buckets[chosen] = Bucket { hash: hash, index: length, state: BucketState::occupied }; + } + return InsertResult::::inserted; +} + +fn contains) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: ref>, key: ref) -> bool effects [] { + ref index = map.buckets; let count = buffer.len(index); + if count == 0usize { return false; } + let hash = H(key); + var position: usize = (hash % (count as! u64)) as! usize; + ref buckets = buffer.view(index); ref storage = map.entries; ref entries = buffer.view(storage); + for probe in 0usize..count { + ref bucket = buckets[position]; + match bucket.state { + BucketState::occupied => { if bucket.hash == hash { if E(ref entries[bucket.index].key, key) { return true; } } } + BucketState::deleted => {} + BucketState::empty => { return false; } + } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + return false; +} + +fn get) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: ref>, key: ref) -> std.option.Option effects [] { + ref index = map.buckets; let count = buffer.len(index); + if count == 0usize { return std.option.Option::::none; } + let hash = H(key); + var position: usize = (hash % (count as! u64)) as! usize; + ref buckets = buffer.view(index); ref storage = map.entries; ref entries = buffer.view(storage); + for probe in 0usize..count { + ref bucket = buckets[position]; + match bucket.state { + BucketState::occupied => { if bucket.hash == hash { if E(ref entries[bucket.index].key, key) { return std.option.Option::::some(entries[bucket.index].value); } } } + BucketState::deleted => {} + BucketState::empty => { return std.option.Option::::none; } + } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + return std.option.Option::::none; +} + +fn remove) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: mut>, key: ref) -> std.option.Option> effects [] { + var count: usize = 0; + { ref index = map.buckets; count = buffer.len(index); } + if count == 0usize { return std.option.Option::>::none; } + let hash = H(key); + var position: usize = (hash % (count as! u64)) as! usize; + var found: bool = false; + var entry_index: usize = 0; + { ref index = map.buckets; ref buckets = buffer.view(index); + ref storage = map.entries; ref entries = buffer.view(storage); + for probe in 0usize..count { + ref bucket = buckets[position]; + var stop: bool = false; + match bucket.state { + BucketState::occupied => { if bucket.hash == hash { if E(ref entries[bucket.index].key, key) { found = true; entry_index = bucket.index; } } } + BucketState::deleted => {} + BucketState::empty => { stop = true; } + } + if found or stop { break; } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + } + if not found { return std.option.Option::>::none; } + { mut index = map.buckets; mut buckets = buffer.view(index); buckets[position].state = BucketState::deleted; } + mut storage = map.entries; + let last = buffer.pop(storage) or trap; + let last_index = buffer.len(storage); + if entry_index == last_index { + let (old_hash, old_key, old_value) = struct.unpack(move last); + return std.option.Option::>::some(Entry:: { key: move old_key, value: move old_value }); + } + let last_hash = last.hash; + let removed = { mut entries = buffer.view(storage); value.swap(mut entries[entry_index], move last) }; + { mut index = map.buckets; mut buckets = buffer.view(index); + var next: usize = (last_hash % (count as! u64)) as! usize; + var repaired: bool = false; + for probe in 0usize..count { + mut bucket = buckets[next]; + match bucket.state { + BucketState::occupied => { + if bucket.hash == last_hash and bucket.index == last_index { bucket.index = entry_index; repaired = true; } + } + BucketState::deleted => {} + BucketState::empty => { trap; } + } + if repaired { break; } + next = if next == count - 1usize { 0usize } else { next + 1usize }; + } + if not repaired { trap; } + } + let (old_hash, old_key, old_value) = struct.unpack(move removed); + return std.option.Option::>::some(Entry:: { key: move old_key, value: move old_value }); +} + +fn pop) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: mut>) -> std.option.Option> effects [] { + var last_index: usize = 0; + var hash: u64 = 0; + { ref storage = map.entries; + let length = buffer.len(storage); + if length == 0usize { return std.option.Option::>::none; } + last_index = length - 1usize; + ref entries = buffer.view(storage); hash = entries[last_index].hash; + } + { mut index = map.buckets; + let count = buffer.len(index); + if count == 0usize { trap; } + mut buckets = buffer.view(index); + var position: usize = (hash % (count as! u64)) as! usize; + var found: bool = false; + for probe in 0usize..count { + mut bucket = buckets[position]; + match bucket.state { + BucketState::occupied => { if bucket.hash == hash and bucket.index == last_index { bucket.state = BucketState::deleted; found = true; } } + BucketState::empty => { trap; } + BucketState::deleted => {} + } + if found { break; } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + if not found { trap; } + } + mut storage = map.entries; let entry = buffer.pop(storage) or trap; + let (old_hash, key, value) = struct.unpack(move entry); + return std.option.Option::>::some(Entry:: { key: move key, value: move value }); +} + +fn free) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: HashMap) -> FreeResult effects [] { + var length: usize = 0; + { ref storage = map.entries; length = buffer.len(storage); } + if length != 0usize { return FreeResult::::not_empty(move map); } + let (entries, buckets) = struct.unpack(move map); + buffer.free(move entries) or trap; + { mut index = buckets; while buffer.len(index) != 0usize { let unused = buffer.pop(index) or trap; } } + buffer.free(move buckets) or trap; + return FreeResult::::ok; +} + +fn reserve) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: mut>, capacity: usize, heap: cap) -> ReserveResult effects [mem.alloc] { + { ref entries = map.entries; if capacity <= buffer.capacity(entries) { return ReserveResult::ok; } } + let maximum = 0usize -% 1usize; + if capacity > maximum / 2usize { return ReserveResult::err(alloc_error::budget_exceeded); } + match buffer.new(capacity * 2usize, heap) { + err(error) => { return ReserveResult::err(error); } + ok(next) => { + { mut index = next; + for i in 0usize..capacity * 2usize { buffer.push(index, Bucket { hash: 0, index: 0, state: BucketState::empty }) or trap; } + } + { mut entries = map.entries; + match buffer.reserve(entries, capacity, heap) { + ok() => {} + err(error) => { + { mut index = next; while buffer.len(index) != 0usize { let unused = buffer.pop(index) or trap; } } + buffer.free(move next) or trap; + return ReserveResult::err(error); + } + } + } + { ref storage = map.entries; ref entries = buffer.view(storage); + mut index = next; let count = buffer.len(index); mut buckets = buffer.view(index); + for i in 0usize..entries.len { + let hash = entries[i].hash; + var position: usize = (hash % (count as! u64)) as! usize; + var found: bool = false; + for probe in 0usize..count { + { ref bucket = buckets[position]; match bucket.state { BucketState::empty => { found = true; }, BucketState::deleted => { trap; }, BucketState::occupied => {} } } + if found { break; } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + if not found { trap; } + buckets[position] = Bucket { hash: hash, index: i, state: BucketState::occupied }; + } + } + let previous = value.swap(mut map.buckets, move next); + { mut index = previous; while buffer.len(index) != 0usize { let unused = buffer.pop(index) or trap; } } + buffer.free(move previous) or trap; + return ReserveResult::ok; + } + } +} diff --git a/std/hashset.aji b/std/hashset.aji new file mode 100644 index 0000000..5ac26f8 --- /dev/null +++ b/std/hashset.aji @@ -0,0 +1,67 @@ +module std.hashset +import std.hashmap; +import std.option; + +struct HashSet) -> u64 effects [], E: fn(ref,ref) -> bool effects []> { map: std.hashmap.HashMap } +enum NewResult) -> u64 effects [], E: fn(ref,ref) -> bool effects []> { ok(HashSet), err(alloc_error) } +enum ReserveResult { ok, err(alloc_error) } +enum InsertResult { inserted, present(K), full(K) } +enum FreeResult) -> u64 effects [], E: fn(ref,ref) -> bool effects []> { ok, not_empty(HashSet) } + +fn new) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> NewResult effects [mem.alloc] { + match std.hashmap.new::(capacity,heap) { + std.hashmap.NewResult::::ok(map) => { return NewResult::::ok(HashSet:: { map: move map }); } + std.hashmap.NewResult::::err(error) => { return NewResult::::err(error); } + } +} + +fn len) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: ref>) -> usize effects [] { return std.hashmap.len::(ref set.map); } +fn capacity) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: ref>) -> usize effects [] { return std.hashmap.capacity::(ref set.map); } + +fn reserve) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: mut>,capacity: usize,heap: cap) -> ReserveResult effects [mem.alloc] { + match std.hashmap.reserve::(mut set.map,capacity,heap) { + std.hashmap.ReserveResult::ok => { return ReserveResult::ok; } + std.hashmap.ReserveResult::err(error) => { return ReserveResult::err(error); } + } +} + +fn insert) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: mut>,key: K) -> InsertResult effects [] { + let incoming = std.hashmap.Entry:: { key: move key, value: true }; + if std.hashmap.contains::(ref set.map,ref incoming.key) { + let (key,value) = struct.unpack(move incoming); return InsertResult::::present(move key); + } + let (key,value) = struct.unpack(move incoming); + match std.hashmap.insert::(mut set.map,move key,true) { + std.hashmap.InsertResult::::inserted => { return InsertResult::::inserted; } + std.hashmap.InsertResult::::full(entry) => { let (key,value) = struct.unpack(move entry); return InsertResult::::full(move key); } + std.hashmap.InsertResult::::replaced(entry) => { trap; } + } +} + +fn contains) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: ref>,key: ref) -> bool effects [] { return std.hashmap.contains::(ref set.map,key); } + +fn remove) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: mut>,key: ref) -> std.option.Option effects [] { + match std.hashmap.remove::(mut set.map,key) { + std.option.Option::>::some(entry) => { + let (key,value) = struct.unpack(move entry); return std.option.Option::::some(move key); + } + std.option.Option::>::none => { return std.option.Option::::none; } + } +} + +fn pop) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: mut>) -> std.option.Option effects [] { + match std.hashmap.pop::(mut set.map) { + std.option.Option::>::some(entry) => { + let (key,value) = struct.unpack(move entry); return std.option.Option::::some(move key); + } + std.option.Option::>::none => { return std.option.Option::::none; } + } +} + +fn free) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: HashSet) -> FreeResult effects [] { + let (map) = struct.unpack(move set); + match std.hashmap.free::(move map) { + std.hashmap.FreeResult::::ok => { return FreeResult::::ok; } + std.hashmap.FreeResult::::not_empty(map) => { return FreeResult::::not_empty(HashSet:: { map: move map }); } + } +} diff --git a/std/heap.aji b/std/heap.aji new file mode 100644 index 0000000..5170245 --- /dev/null +++ b/std/heap.aji @@ -0,0 +1,129 @@ +module std.heap +import std.option; + +struct Entry { position: usize, value: T } +struct BinaryHeap,ref) -> bool effects []> { entries: buffer>, indices: buffer } +enum NewResult,ref) -> bool effects []> { ok(BinaryHeap), err(alloc_error) } +enum ReserveResult { ok, err(alloc_error) } +enum PushResult { ok, full(T) } +enum FreeResult,ref) -> bool effects []> { ok, not_empty(BinaryHeap) } + +fn new,ref) -> bool effects []>(capacity: usize,heap: cap) -> NewResult effects [mem.alloc] { + match buffer.new>(capacity,heap) { + err(error) => { return NewResult::::err(error); } + ok(entries) => { + match buffer.new(capacity,heap) { + err(error) => { buffer.free(move entries) or trap; return NewResult::::err(error); } + ok(indices) => { return NewResult::::ok(BinaryHeap:: { entries: move entries, indices: move indices }); } + } + } + } +} + +fn len,ref) -> bool effects []>(value: ref>) -> usize effects [] { + ref entries = value.entries; return buffer.len(entries); +} + +fn capacity,ref) -> bool effects []>(value: ref>) -> usize effects [] { + ref entries = value.entries; return buffer.capacity(entries); +} + +fn reserve,ref) -> bool effects []>(value: mut>,capacity: usize,heap: cap) -> ReserveResult effects [mem.alloc] { + { ref entries = value.entries; if capacity <= buffer.capacity(entries) { return ReserveResult::ok; } } + match buffer.new(capacity,heap) { + err(error) => { return ReserveResult::err(error); } + ok(next) => { + { ref old = value.indices; ref indices = buffer.view(old); mut output = next; + for i in 0usize..indices.len { buffer.push(output,indices[i]) or trap; } + } + { mut entries = value.entries; + match buffer.reserve(entries,capacity,heap) { + ok() => {} + err(error) => { + { mut index = next; while buffer.len(index) != 0usize { let unused = buffer.pop(index) or trap; } } + buffer.free(move next) or trap; return ReserveResult::err(error); + } + } + } + let old = value.swap(mut value.indices,move next); + { mut index = old; while buffer.len(index) != 0usize { let unused = buffer.pop(index) or trap; } } + buffer.free(move old) or trap; return ReserveResult::ok; + } + } +} + +fn push,ref) -> bool effects []>(value: mut>,item: T) -> PushResult effects [] { + var position: usize = 0; + { ref entries = value.entries; position = buffer.len(entries); + if position == buffer.capacity(entries) { return PushResult::::full(move item); } + } + { mut entries = value.entries; buffer.push(entries,Entry:: { position: position, value: move item }) or trap; } + { mut indices = value.indices; buffer.push(indices,position) or trap; } + while position != 0usize { + let parent = (position - 1usize) / 2usize; + var child_index: usize = 0; var parent_index: usize = 0; + { ref storage = value.indices; ref indices = buffer.view(storage); child_index = indices[position]; parent_index = indices[parent]; } + var earlier: bool = false; + { ref storage = value.entries; ref entries = buffer.view(storage); earlier = B(ref entries[child_index].value,ref entries[parent_index].value); } + if not earlier { break; } + { mut storage = value.indices; mut indices = buffer.view(storage); indices[parent] = child_index; indices[position] = parent_index; } + { mut storage = value.entries; mut entries = buffer.view(storage); entries[child_index].position = parent; entries[parent_index].position = position; } + position = parent; + } + return PushResult::::ok; +} + +fn peek,ref) -> bool effects []>(value: ref>) -> std.option.Option effects [] { + ref index = value.indices; + if buffer.len(index) == 0usize { return std.option.Option::::none; } + ref indices = buffer.view(index); ref storage = value.entries; ref entries = buffer.view(storage); + return std.option.Option::::some(entries[indices[0]].value); +} + +fn pop,ref) -> bool effects []>(value: mut>) -> std.option.Option effects [] { + var length: usize = 0; var removed: usize = 0; + { ref storage = value.indices; length = buffer.len(storage); + if length == 0usize { return std.option.Option::::none; } + ref indices = buffer.view(storage); removed = indices[0]; + } + var replacement: usize = 0; + { mut storage = value.indices; replacement = buffer.pop(storage) or trap; } + length = length - 1usize; + if length != 0usize { + { mut storage = value.indices; mut indices = buffer.view(storage); indices[0] = replacement; } + { mut storage = value.entries; mut entries = buffer.view(storage); entries[replacement].position = 0usize; } + var position: usize = 0; + while position < length / 2usize { + let left = position * 2usize + 1usize; let right = left + 1usize; + var child: usize = left; var child_index: usize = 0; var parent_index: usize = 0; + { ref index = value.indices; ref indices = buffer.view(index); + ref storage = value.entries; ref entries = buffer.view(storage); + if right < length { if B(ref entries[indices[right]].value,ref entries[indices[left]].value) { child = right; } } + child_index = indices[child]; parent_index = indices[position]; + } + var earlier: bool = false; + { ref storage = value.entries; ref entries = buffer.view(storage); earlier = B(ref entries[child_index].value,ref entries[parent_index].value); } + if not earlier { break; } + { mut storage = value.indices; mut indices = buffer.view(storage); indices[position] = child_index; indices[child] = parent_index; } + { mut storage = value.entries; mut entries = buffer.view(storage); entries[child_index].position = position; entries[parent_index].position = child; } + position = child; + } + } + mut storage = value.entries; + let last = buffer.pop(storage) or trap; + if removed == length { + let (position,item) = struct.unpack(move last); return std.option.Option::::some(move item); + } + let position = last.position; + let old = { mut entries = buffer.view(storage); value.swap(mut entries[removed],move last) }; + { mut storage = value.indices; mut indices = buffer.view(storage); indices[position] = removed; } + let (position,item) = struct.unpack(move old); return std.option.Option::::some(move item); +} + +fn free,ref) -> bool effects []>(value: BinaryHeap) -> FreeResult effects [] { + var length: usize = 0; + { ref entries = value.entries; length = buffer.len(entries); } + if length != 0usize { return FreeResult::::not_empty(move value); } + let (entries,indices) = struct.unpack(move value); + buffer.free(move entries) or trap; buffer.free(move indices) or trap; return FreeResult::::ok; +} diff --git a/std/io.aji b/std/io.aji new file mode 100644 index 0000000..798c49d --- /dev/null +++ b/std/io.aji @@ -0,0 +1,123 @@ +module std.io + +struct ReadError { completed: usize, error: io_error } +enum ReadExactResult { ok, eof(usize), err(ReadError) } +enum ReadToEndResult { eof(usize), full(usize), err(ReadError) } +struct CopyError { read: usize, confirmed_written: usize, error: io_error } +enum CopyResult { eof(usize), limit(usize), err(CopyError) } + +fn read_exact_stdin(input: cap,destination: slice_mut) -> ReadExactResult effects [io.read] { + var completed: usize = 0; + while completed < destination.len { + mut suffix = destination[completed..destination.len]; + match io.stdin_read(input,suffix) { + ok(count) => { + assert(count <= suffix.len); + if count == 0usize { return ReadExactResult::eof(completed); } + completed = completed + count; + } + err(error) => { return ReadExactResult::err(ReadError { completed: completed, error: error }); } + } + } + return ReadExactResult::ok; +} + +fn read_exact_file(input: mut>,destination: slice_mut) -> ReadExactResult effects [fs.read] { + var completed: usize = 0; + while completed < destination.len { + mut suffix = destination[completed..destination.len]; + match fs.read(input,suffix) { + ok(count) => { + assert(count <= suffix.len); + if count == 0usize { return ReadExactResult::eof(completed); } + completed = completed + count; + } + err(error) => { return ReadExactResult::err(ReadError { completed: completed, error: error }); } + } + } + return ReadExactResult::ok; +} + +fn read_exact_stream(input: mut,destination: slice_mut) -> ReadExactResult effects [net.read] { + var completed: usize = 0; + while completed < destination.len { + mut suffix = destination[completed..destination.len]; + match net.recv(input,suffix) { + ok(count) => { + assert(count <= suffix.len); + if count == 0usize { return ReadExactResult::eof(completed); } + completed = completed + count; + } + err(error) => { return ReadExactResult::err(ReadError { completed: completed, error: error }); } + } + } + return ReadExactResult::ok; +} + +fn read_to_end_file(input: mut>,destination: slice_mut) -> ReadToEndResult effects [fs.read] { + var completed: usize = 0; + while completed < destination.len { + mut suffix = destination[completed..destination.len]; + match fs.read(input,suffix) { + ok(count) => { + assert(count <= suffix.len); + if count == 0usize { return ReadToEndResult::eof(completed); } + completed = completed + count; + } + err(error) => { return ReadToEndResult::err(ReadError { completed: completed, error: error }); } + } + } + return ReadToEndResult::full(completed); +} + +fn copy_file(input: mut>,output: mut>,scratch: slice_mut,limit: usize) -> CopyResult effects [fs.read,fs.write] { + if limit == 0usize { return CopyResult::limit(0usize); } + if scratch.len == 0usize { return CopyResult::err(CopyError { read: 0usize, confirmed_written: 0usize, error: io_error::invalid_input }); } + var completed: usize = 0; + while completed < limit { + let remaining = limit - completed; + let capacity = if scratch.len < remaining { scratch.len } else { remaining }; + var count: usize = 0; + { mut chunk = scratch[0usize..capacity]; + match fs.read(input,chunk) { + ok(read) => { assert(read <= capacity); count = read; } + err(error) => { return CopyResult::err(CopyError { read: completed, confirmed_written: completed, error: error }); } + } + } + if count == 0usize { return CopyResult::eof(completed); } + { ref chunk = scratch[0usize..count]; + match fs.write_all(output,chunk) { + ok() => {} + err(error) => { return CopyResult::err(CopyError { read: completed + count, confirmed_written: completed, error: error }); } + } + } + completed = completed + count; + } + return CopyResult::limit(completed); +} + +fn copy_file_append(input: mut>,output: mut>,scratch: slice_mut,limit: usize) -> CopyResult effects [fs.read,fs.write] { + if limit == 0usize { return CopyResult::limit(0usize); } + if scratch.len == 0usize { return CopyResult::err(CopyError { read: 0usize, confirmed_written: 0usize, error: io_error::invalid_input }); } + var completed: usize = 0; + while completed < limit { + let remaining = limit - completed; + let capacity = if scratch.len < remaining { scratch.len } else { remaining }; + var count: usize = 0; + { mut chunk = scratch[0usize..capacity]; + match fs.read(input,chunk) { + ok(read) => { assert(read <= capacity); count = read; } + err(error) => { return CopyResult::err(CopyError { read: completed, confirmed_written: completed, error: error }); } + } + } + if count == 0usize { return CopyResult::eof(completed); } + { ref chunk = scratch[0usize..count]; + match fs.write_all(output,chunk) { + ok() => {} + err(error) => { return CopyResult::err(CopyError { read: completed + count, confirmed_written: completed, error: error }); } + } + } + completed = completed + count; + } + return CopyResult::limit(completed); +} diff --git a/std/io/reader.aji b/std/io/reader.aji new file mode 100644 index 0000000..349175f --- /dev/null +++ b/std/io/reader.aji @@ -0,0 +1,69 @@ +module std.io.reader +import std.io; + +struct Reader { file: file, storage: buffer, begin: usize, end: usize } +struct NewError { file: file, error: alloc_error } +enum NewResult { ok(Reader), err(NewError) } +enum ReadResult { ok(usize), err(io_error) } +enum FinishResult { ok(file), unread(Reader) } +struct Discarded { file: file, unread: usize } + +fn new(input: file,capacity: usize,heap: cap) -> NewResult effects [mem.alloc] { + match buffer.new(capacity,heap) { + err(error) => { return NewResult::err(NewError { file: move input, error: error }); } + ok(storage) => { + { mut output = storage; for i in 0usize..capacity { buffer.push(output,0u8) or trap; } } + return NewResult::ok(Reader { file: move input, storage: move storage, begin: 0usize, end: 0usize }); + } + } +} + +fn read(input: mut,destination: slice_mut) -> ReadResult effects [fs.read] { + if destination.len == 0usize { return ReadResult::ok(0usize); } + var capacity: usize = 0; + { ref storage = input.storage; capacity = buffer.len(storage); } + if capacity == 0usize { + mut file = input.file; + match fs.read(file,destination) { ok(count) => { return ReadResult::ok(count); }, err(error) => { return ReadResult::err(error); } } + } + if input.begin == input.end { + var count: usize = 0; + { mut file = input.file; mut storage = input.storage; mut bytes = buffer.view(storage); + match fs.read(file,bytes) { ok(read) => { assert(read <= capacity); count = read; }, err(error) => { return ReadResult::err(error); } } + } + input.begin = 0usize; input.end = count; + if count == 0usize { return ReadResult::ok(0usize); } + } + let available = input.end - input.begin; + let count = if destination.len < available { destination.len } else { available }; + { ref storage = input.storage; ref bytes = buffer.view(storage); + for i in 0usize..count { destination[i] = bytes[input.begin + i]; } + } + input.begin = input.begin + count; return ReadResult::ok(count); +} + +fn read_exact(input: mut,destination: slice_mut) -> std.io.ReadExactResult effects [fs.read] { + var completed: usize = 0; + while completed < destination.len { + mut suffix = destination[completed..destination.len]; + match read(input,suffix) { + ReadResult::ok(count) => { assert(count <= suffix.len); if count == 0usize { return std.io.ReadExactResult::eof(completed); } completed = completed + count; } + ReadResult::err(error) => { return std.io.ReadExactResult::err(std.io.ReadError { completed: completed, error: error }); } + } + } + return std.io.ReadExactResult::ok; +} + +fn finish(input: Reader) -> FinishResult effects [] { + if input.begin < input.end { return FinishResult::unread(move input); } + let (file,storage,begin,end) = struct.unpack(move input); + { mut bytes = storage; while buffer.len(bytes) != 0usize { let unused = buffer.pop(bytes) or trap; } } + buffer.free(move storage) or trap; return FinishResult::ok(move file); +} + +fn discard(input: Reader) -> Discarded effects [] { + let (file,storage,begin,end) = struct.unpack(move input); + let unread = end - begin; + { mut bytes = storage; while buffer.len(bytes) != 0usize { let unused = buffer.pop(bytes) or trap; } } + buffer.free(move storage) or trap; return Discarded { file: move file, unread: unread }; +} diff --git a/std/io/writer.aji b/std/io/writer.aji new file mode 100644 index 0000000..21291de --- /dev/null +++ b/std/io/writer.aji @@ -0,0 +1,74 @@ +module std.io.writer +import std.option; + +struct Writer { file: file, storage: buffer, used: usize, failed: std.option.Option } +struct NewError { file: file, error: alloc_error } +enum NewResult { ok(Writer), err(NewError) } +struct WriteError { accepted: usize, error: io_error } +enum WriteResult { ok, err(WriteError) } +enum FlushResult { ok, err(io_error) } +struct FinishError { writer: Writer, error: io_error } +enum FinishResult { ok(file), err(FinishError) } +struct Discarded { file: file, pending: usize, failed: std.option.Option } + +fn new(output: file,capacity: usize,heap: cap) -> NewResult effects [mem.alloc] { + match buffer.new(capacity,heap) { + err(error) => { return NewResult::err(NewError { file: move output, error: error }); } + ok(storage) => { + { mut bytes = storage; for i in 0usize..capacity { buffer.push(bytes,0u8) or trap; } } + return NewResult::ok(Writer { file: move output, storage: move storage, used: 0usize, failed: std.option.Option::::none }); + } + } +} + +fn write(output: mut,bytes: slice) -> WriteResult effects [fs.write] { + match output.failed { std.option.Option::::some(error) => { return WriteResult::err(WriteError { accepted: 0usize, error: error }); }, std.option.Option::::none => {} } + if bytes.len == 0usize { return WriteResult::ok; } + var capacity: usize = 0; + { ref storage = output.storage; capacity = buffer.len(storage); } + if capacity == 0usize { + var error_value: io_error = io_error::other; var failed: bool = false; + { mut file = output.file; match fs.write_all(file,bytes) { ok() => {}, err(error) => { error_value = error; failed = true; } } } + if failed { output.failed = std.option.Option::::some(error_value); return WriteResult::err(WriteError { accepted: 0usize, error: error_value }); } + return WriteResult::ok; + } + var accepted: usize = 0; + while accepted < bytes.len { + if output.used == capacity { + match flush(output) { FlushResult::ok => {}, FlushResult::err(error) => { return WriteResult::err(WriteError { accepted: accepted, error: error }); } } + } + let available = capacity - output.used; let remaining = bytes.len - accepted; + let count = if available < remaining { available } else { remaining }; + { mut storage = output.storage; mut target = buffer.view(storage); + for i in 0usize..count { target[output.used + i] = bytes[accepted + i]; } + } + output.used = output.used + count; accepted = accepted + count; + } + return WriteResult::ok; +} + +fn flush(output: mut) -> FlushResult effects [fs.write] { + match output.failed { std.option.Option::::some(error) => { return FlushResult::err(error); }, std.option.Option::::none => {} } + if output.used == 0usize { return FlushResult::ok; } + var error_value: io_error = io_error::other; var failed: bool = false; + { mut file = output.file; ref storage = output.storage; ref bytes = buffer.view(storage); ref pending = bytes[0usize..output.used]; + match fs.write_all(file,pending) { ok() => {}, err(error) => { error_value = error; failed = true; } } + } + if failed { output.failed = std.option.Option::::some(error_value); return FlushResult::err(error_value); } + output.used = 0usize; return FlushResult::ok; +} + +fn finish(output: Writer) -> FinishResult effects [fs.write] { + var error_value: io_error = io_error::other; var failure: bool = false; + { mut value = output; match flush(value) { FlushResult::ok => {}, FlushResult::err(error) => { error_value = error; failure = true; } } } + if failure { return FinishResult::err(FinishError { writer: move output, error: error_value }); } + let (file,storage,used,failed) = struct.unpack(move output); + { mut bytes = storage; while buffer.len(bytes) != 0usize { let unused = buffer.pop(bytes) or trap; } } + buffer.free(move storage) or trap; return FinishResult::ok(move file); +} + +fn discard(output: Writer) -> Discarded effects [] { + let (file,storage,used,failed) = struct.unpack(move output); + { mut bytes = storage; while buffer.len(bytes) != 0usize { let unused = buffer.pop(bytes) or trap; } } + buffer.free(move storage) or trap; return Discarded { file: move file, pending: used, failed: failed }; +} diff --git a/std/map.aji b/std/map.aji new file mode 100644 index 0000000..9893cd5 --- /dev/null +++ b/std/map.aji @@ -0,0 +1,283 @@ +module std.map +import std.hash; +import std.option; + +struct Slot { key: u64, state: SlotState, value: std.option.Option } +enum SlotState { empty, deleted, occupied } +struct U64Map { storage: buffer>, length: usize } +struct Entry { key: u64, value: V } +enum NewResult { ok(U64Map), err(alloc_error) } +enum ReserveResult { ok, err(alloc_error) } +enum InsertResult { inserted, replaced(V), full(V) } +enum FreeResult { ok, not_empty(U64Map) } + +fn new(capacity: usize, heap: cap) -> NewResult effects [mem.alloc] { + let maximum = 0usize -% 1usize; + if capacity > maximum / 2usize { return NewResult::::err(alloc_error::budget_exceeded); } + let count = capacity * 2usize; + match buffer.new>(count, heap) { + ok(storage) => { + { mut slots = storage; + for index in 0usize..count { + let empty = Slot:: { key: 0, state: SlotState::empty, value: std.option.Option::::none }; + buffer.push(slots, move empty) or trap; + } + } + return NewResult::::ok(U64Map:: { storage: move storage, length: 0 }); + } + err(error) => { return NewResult::::err(error); } + } +} + +fn len(map: ref>) -> usize effects [] { return map.length; } +fn capacity(map: ref>) -> usize effects [] { + ref storage = map.storage; + return buffer.capacity(storage) / 2usize; +} + +fn insert(map: mut>, key: u64, value: V) -> InsertResult effects [] { + mut storage = map.storage; + let count = buffer.capacity(storage); + if count == 0usize { return InsertResult::::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::::some(move value); + let previous = value.swap(mut slot.value, move replacement); + match move previous { + std.option.Option::::some(old) => { return InsertResult::::replaced(move old); } + std.option.Option::::none => { trap; } + } + } + if stop { break; } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + if map.length == count / 2usize { return InsertResult::::full(move value); } + if chosen == count { trap; } + mut slot = slots[chosen]; + let replacement = std.option.Option::::some(move value); + let previous = value.swap(mut slot.value, move replacement); + match move previous { + std.option.Option::::none => {} + std.option.Option::::some(unexpected) => { trap; } + } + slot.key = key; + slot.state = SlotState::occupied; + map.length = map.length + 1usize; + return InsertResult::::inserted; +} + +fn contains(map: ref>, 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(map: ref>, key: u64) -> std.option.Option effects [] { + ref storage = map.storage; + let count = buffer.capacity(storage); + if count == 0usize { return std.option.Option::::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::::some(value) => { return std.option.Option::::some(value); } + std.option.Option::::none => { trap; } + } + } + } + SlotState::empty => { return std.option.Option::::none; } + SlotState::deleted => {} + } + } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + return std.option.Option::::none; +} + +fn remove(map: mut>, key: u64) -> std.option.Option effects [] { + mut storage = map.storage; + let count = buffer.capacity(storage); + if count == 0usize { return std.option.Option::::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::::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::::some(value) => { return std.option.Option::::some(move value); } + std.option.Option::::none => { trap; } + } + } + } + SlotState::empty => { return std.option.Option::::none; } + SlotState::deleted => {} + } + } + position = if position == count - 1usize { 0usize } else { position + 1usize }; + } + return std.option.Option::::none; +} + +fn pop(map: mut>) -> std.option.Option> effects [] { + if map.length == 0usize { return std.option.Option::>::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::::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::::some(value) => { + return std.option.Option::>::some(Entry:: { key: key, value: move value }); + } + std.option.Option::::none => { trap; } + } + } + SlotState::empty => {} + SlotState::deleted => {} + } + } + trap; +} + +fn free(map: U64Map) -> FreeResult effects [] { + if map.length != 0usize { return FreeResult::::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::::none => {} + std.option.Option::::some(unexpected) => { trap; } + } + } + } + buffer.free(move storage) or trap; + return FreeResult::::ok; +} + +fn reserve(map: mut>, capacity: usize, heap: cap) -> 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::(capacity, heap) { + NewResult::::err(error) => { return ReserveResult::err(error); } + NewResult::::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:: { key: 0, state: SlotState::empty, value: std.option.Option::::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::::none => {} + std.option.Option::::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::(move previous) { + FreeResult::::ok => {} + FreeResult::::not_empty(unexpected) => { trap; } + } + return ReserveResult::ok; + } + } +} diff --git a/std/math.aji b/std/math.aji new file mode 100644 index 0000000..ff71f3e --- /dev/null +++ b/std/math.aji @@ -0,0 +1,71 @@ +module std.math + +fn min_u64(a: u64, b: u64) -> u64 +effects [] +{ + if a < b { return a; } + return b; +} + +fn max_u64(a: u64, b: u64) -> u64 +effects [] +{ + if a > b { return a; } + return b; +} + +fn clamp_u64(value: u64, lower: u64, upper: u64) -> u64 +effects [] +{ + assert(lower <= upper); + return std.math.min_u64(std.math.max_u64(value, lower), upper); +} + +enum U64Result { ok(u64), overflow } +enum UsizeResult { ok(usize), overflow } + +fn checked_add_u64(a: u64, b: u64) -> std.math.U64Result +effects [] +{ + let maximum = 0u64 -% 1u64; + if b > maximum - a { return std.math.U64Result::overflow; } + return std.math.U64Result::ok(a + b); +} + +fn checked_sub_u64(a: u64, b: u64) -> std.math.U64Result +effects [] +{ + if b > a { return std.math.U64Result::overflow; } + return std.math.U64Result::ok(a - b); +} + +fn checked_mul_u64(a: u64, b: u64) -> std.math.U64Result +effects [] +{ + let maximum = 0u64 -% 1u64; + if b != 0 and a > maximum / b { return std.math.U64Result::overflow; } + return std.math.U64Result::ok(a * b); +} + +fn checked_add_usize(a: usize, b: usize) -> std.math.UsizeResult +effects [] +{ + let maximum = 0usize -% 1usize; + if b > maximum - a { return std.math.UsizeResult::overflow; } + return std.math.UsizeResult::ok(a + b); +} + +fn checked_sub_usize(a: usize, b: usize) -> std.math.UsizeResult +effects [] +{ + if b > a { return std.math.UsizeResult::overflow; } + return std.math.UsizeResult::ok(a - b); +} + +fn checked_mul_usize(a: usize, b: usize) -> std.math.UsizeResult +effects [] +{ + let maximum = 0usize -% 1usize; + if b != 0 and a > maximum / b { return std.math.UsizeResult::overflow; } + return std.math.UsizeResult::ok(a * b); +} diff --git a/std/option.aji b/std/option.aji new file mode 100644 index 0000000..b29d719 --- /dev/null +++ b/std/option.aji @@ -0,0 +1,12 @@ +module std.option + +enum Option { some(T), none } + +fn is_some(value: Option) -> bool +effects [] +{ + match value { + Option::::some(payload) => { return true; } + Option::::none => { return false; } + } +} diff --git a/std/path.aji b/std/path.aji new file mode 100644 index 0000000..685724e --- /dev/null +++ b/std/path.aji @@ -0,0 +1,128 @@ +module std.path + +struct Range { start: usize, end: usize } +enum WriteResult { ok(usize), invalid_input, size_overflow, short_output } + +fn is_absolute(path: slice) -> bool effects [] { + return path.len != 0usize and path[0] == 47u8; +} + +fn basename(path: slice) -> Range effects [] { + var end: usize = path.len; + while end != 0usize and path[end - 1usize] == 47u8 { end = end - 1usize; } + if end == 0usize { return Range { start: 0usize, end: 0usize }; } + var start: usize = end; + while start != 0usize and path[start - 1usize] != 47u8 { start = start - 1usize; } + return Range { start: start, end: end }; +} + +fn parent(path: slice) -> Range effects [] { + let component = basename(path); var end: usize = component.start; + while end != 0usize and path[end - 1usize] == 47u8 { end = end - 1usize; } + if end == 0usize and is_absolute(path) { end = 1usize; } + return Range { start: 0usize, end: end }; +} + +fn extension(path: slice) -> Range effects [] { + let component = basename(path); var cursor: usize = component.end; + while cursor > component.start { + cursor = cursor - 1usize; + if path[cursor] == 46u8 { + if cursor == component.start or cursor + 1usize == component.end { break; } + return Range { start: cursor + 1usize, end: component.end }; + } + } + return Range { start: component.end, end: component.end }; +} + +// Implementation state for reverse measurement/emission; not an additional +// supported path API. No borrow is stored in it. +struct Measurement { pending: usize, length: usize, count: usize, overflow: bool } +struct Emission { pending: usize, cursor: usize } + +fn valid(path: slice) -> bool effects [] { + for i in 0usize..path.len { if path[i] == 0u8 { return false; } } + return true; +} + +fn measure(path: slice,initial: Measurement) -> Measurement effects [] { + if initial.overflow { return initial; } + var pending: usize = initial.pending; var length: usize = initial.length; + var count: usize = initial.count; var cursor: usize = path.len; + while cursor != 0usize { + while cursor != 0usize and path[cursor - 1usize] == 47u8 { cursor = cursor - 1usize; } + let end = cursor; + while cursor != 0usize and path[cursor - 1usize] != 47u8 { cursor = cursor - 1usize; } + let width = end - cursor; + if width == 0usize { break; } + if width == 1usize and path[cursor] == 46u8 { continue; } + if width == 2usize and path[cursor] == 46u8 and path[cursor + 1usize] == 46u8 { + if pending == 18446744073709551615usize { return Measurement { pending: pending, length: length, count: count, overflow: true }; } + pending = pending + 1usize; continue; + } + if pending != 0usize { pending = pending - 1usize; continue; } + if width > 18446744073709551615usize - length { return Measurement { pending: pending, length: length, count: count, overflow: true }; } + length = length + width; + if count != 0usize { + if length == 18446744073709551615usize { return Measurement { pending: pending, length: length, count: count, overflow: true }; } + length = length + 1usize; + } + count = count + 1usize; + } + return Measurement { pending: pending, length: length, count: count, overflow: false }; +} + +fn emit(destination: slice_mut,path: slice,initial: Emission) -> Emission effects [] { + var pending: usize = initial.pending; var output: usize = initial.cursor; var cursor: usize = path.len; + while cursor != 0usize { + while cursor != 0usize and path[cursor - 1usize] == 47u8 { cursor = cursor - 1usize; } + let end = cursor; + while cursor != 0usize and path[cursor - 1usize] != 47u8 { cursor = cursor - 1usize; } + let width = end - cursor; + if width == 0usize { break; } + if width == 1usize and path[cursor] == 46u8 { continue; } + if width == 2usize and path[cursor] == 46u8 and path[cursor + 1usize] == 46u8 { pending = pending + 1usize; continue; } + if pending != 0usize { pending = pending - 1usize; continue; } + assert(width <= output); output = output - width; + for i in 0usize..width { destination[output + i] = path[cursor + i]; } + if output != 0usize { output = output - 1usize; destination[output] = 47u8; } + } + return Emission { pending: pending, cursor: output }; +} + +fn join(destination: slice_mut,base: slice,child: slice) -> WriteResult effects [] { + if not valid(base) or not valid(child) { return WriteResult::invalid_input; } + let replace = is_absolute(child); let rooted = replace or is_absolute(base); + var measured: Measurement = Measurement { pending: 0usize, length: 0usize, count: 0usize, overflow: false }; + measured = measure(child,measured); if not replace { measured = measure(base,measured); } + if measured.overflow { return WriteResult::size_overflow; } + var length: usize = measured.length; var count: usize = measured.count; + if rooted { + if length == 18446744073709551615usize { return WriteResult::size_overflow; } length = length + 1usize; + } else { + for i in 0usize..measured.pending { + let added = if count == 0usize { 2usize } else { 3usize }; + if added > 18446744073709551615usize - length { return WriteResult::size_overflow; } + length = length + added; count = count + 1usize; + } + if length == 0usize { length = 1usize; } + } + if length > destination.len { return WriteResult::short_output; } + var emitted: Emission = Emission { pending: 0usize, cursor: length }; + emitted = emit(destination,child,emitted); if not replace { emitted = emit(destination,base,emitted); } + if rooted { + if measured.count == 0usize { destination[0usize] = 47u8; } else { assert(emitted.cursor == 0usize); } + } else { + var cursor: usize = emitted.cursor; + for i in 0usize..emitted.pending { + assert(cursor >= 2usize); cursor = cursor - 2usize; destination[cursor] = 46u8; destination[cursor + 1usize] = 46u8; + if cursor != 0usize { cursor = cursor - 1usize; destination[cursor] = 47u8; } + } + if count == 0usize { destination[0usize] = 46u8; } else { assert(cursor == 0usize); } + } + return WriteResult::ok(length); +} + +fn normalize(destination: slice_mut,path: slice) -> WriteResult effects [] { + let blank: [u8;1] = [0u8;1]; return join(destination,ref blank[0usize..0usize],path); +} diff --git a/std/result.aji b/std/result.aji new file mode 100644 index 0000000..d31bc63 --- /dev/null +++ b/std/result.aji @@ -0,0 +1,12 @@ +module std.result + +enum Result { ok(T), err(E) } + +fn is_ok(value: Result) -> bool +effects [] +{ + match value { + Result::::ok(payload) => { return true; } + Result::::err(error_value) => { return false; } + } +} diff --git a/std/utf8.aji b/std/utf8.aji new file mode 100644 index 0000000..e418de0 --- /dev/null +++ b/std/utf8.aji @@ -0,0 +1,49 @@ +module std.utf8 + +enum NextResult { ok(u32, usize), end, invalid_input } +enum ValidateResult { ok, invalid_input(usize) } + +fn next(src: slice) -> std.utf8.NextResult +effects [] +{ + if src.len == 0 { return std.utf8.NextResult::end; } + let lead = src[0]; + if lead < 128 { return std.utf8.NextResult::ok(lead as u32, 1); } + var count: usize = 0; + var value: u32 = 0; + var lower: u8 = 128; + var upper: u8 = 191; + if lead >= 194 and lead <= 223 { + count = 2; value = (lead & 31) as u32; + } else if lead >= 224 and lead <= 239 { + count = 3; value = (lead & 15) as u32; + if lead == 224 { lower = 160; } + if lead == 237 { upper = 159; } + } else if lead >= 240 and lead <= 244 { + count = 4; value = (lead & 7) as u32; + if lead == 240 { lower = 144; } + if lead == 244 { upper = 143; } + } else { return std.utf8.NextResult::invalid_input; } + if src.len < count { return std.utf8.NextResult::invalid_input; } + if src[1] < lower or src[1] > upper { return std.utf8.NextResult::invalid_input; } + for i in 1usize..count { + let byte = src[i]; + if byte < 128 or byte > 191 { return std.utf8.NextResult::invalid_input; } + value = (value << 6) | ((byte & 63) as u32); + } + return std.utf8.NextResult::ok(value, count); +} + +fn validate(src: slice) -> std.utf8.ValidateResult +effects [] +{ + var offset: usize = 0; + while offset < src.len { + match std.utf8.next(ref src[offset..src.len]) { + std.utf8.NextResult::ok(value, count) => { offset = offset + count; } + std.utf8.NextResult::end => { return std.utf8.ValidateResult::ok; } + std.utf8.NextResult::invalid_input => { return std.utf8.ValidateResult::invalid_input(offset); } + } + } + return std.utf8.ValidateResult::ok; +} diff --git a/std/vec.aji b/std/vec.aji new file mode 100644 index 0000000..7864257 --- /dev/null +++ b/std/vec.aji @@ -0,0 +1,77 @@ +module std.vec +import std.option; + +struct Vec { storage: buffer } +enum NewResult { ok(Vec), err(alloc_error) } +enum PushResult { ok, full(T) } +enum ReserveResult { ok, err(alloc_error) } +enum FreeResult { ok, not_empty(Vec) } +enum ReplaceResult { ok(T), out_of_bounds(T) } + +fn new(capacity: usize, heap: cap) -> NewResult +effects [mem.alloc] +{ + match buffer.new(capacity, heap) { + ok(storage) => { return NewResult::::ok(Vec:: { storage: move storage }); } + err(error) => { return NewResult::::err(error); } + } +} + +fn len(value: ref>) -> usize effects [] { + ref storage = value.storage; + return buffer.len(storage); +} + +fn capacity(value: ref>) -> usize effects [] { + ref storage = value.storage; + return buffer.capacity(storage); +} + +fn reserve(value: mut>, capacity: usize, heap: cap) -> ReserveResult +effects [mem.alloc] +{ + mut storage = value.storage; + match buffer.reserve(storage, capacity, heap) { + ok() => { return ReserveResult::ok; } + err(error) => { return ReserveResult::err(error); } + } +} + +fn push(value: mut>, item: T) -> PushResult effects [] { + mut storage = value.storage; + match buffer.push(storage, move item) { + ok() => { return PushResult::::ok; } + err(returned) => { return PushResult::::full(move returned); } + } +} + +fn pop(value: mut>) -> std.option.Option effects [] { + mut storage = value.storage; + match buffer.pop(storage) { + ok(item) => { return std.option.Option::::some(move item); } + err() => { return std.option.Option::::none; } + } +} + +fn free(value: Vec) -> FreeResult effects [] { + let (storage) = struct.unpack(move value); + match buffer.free(move storage) { + ok() => { return FreeResult::::ok; } + err(returned) => { return FreeResult::::not_empty(Vec:: { storage: move returned }); } + } +} + +fn get(value: ref>, index: usize) -> std.option.Option effects [] { + ref storage = value.storage; + if index >= buffer.len(storage) { return std.option.Option::::none; } + ref values = buffer.view(storage); + return std.option.Option::::some(values[index]); +} + +fn replace(value: mut>, index: usize, item: T) -> ReplaceResult effects [] { + mut storage = value.storage; + if index >= buffer.len(storage) { return ReplaceResult::::out_of_bounds(move item); } + mut values = buffer.view(storage); + let previous = value.swap(mut values[index], move item); + return ReplaceResult::::ok(move previous); +} diff --git a/tests/conformance/README.md b/tests/conformance/README.md index 8b84cdd..47920c0 100644 --- a/tests/conformance/README.md +++ b/tests/conformance/README.md @@ -32,6 +32,7 @@ Every test starts with a block of `;` lines. Keys: | `file` | no, repeatable | `=`: expected contents of a file written by the run | | `fuel` | no | instruction limit for `run` tests (spec 11 §7.1); default 1 000 000. Running out is a `FAIL`, never a pass | | `equivalent` | no, `.aji` `run` tests only | path, relative to `tests/conformance`, of a reference AIR program. Both are run with this test's world and grants; their run records must be byte-identical (for a trap, the trap code must match, since the record carries the AIR location; `schedule.choices` is not compared, since the scheduler's quantum counts AIR instructions and the lowered program may have a different instruction stream). The AIR texts may differ | +| `module` | no, repeatable, `.aji` only | `NAME=PATH`: explicit source provider; path is relative to `tests/conformance`. Reachable sources are linked through the ordinary frontend. Use `.aji.inc` for helper files so they are not standalone tests | | `phase` | yes | implementation phase number | | `spec` | yes | spec section that justifies the expectation | diff --git a/tests/conformance/buffers/borrowed_element.air b/tests/conformance/buffers/borrowed_element.air new file mode 100644 index 0000000..e89ff15 --- /dev/null +++ b/tests/conformance/buffers/borrowed_element.air @@ -0,0 +1,16 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @bad(%b: buffer>) -> void +effects [] +entry: + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/empty_free_leak.air b/tests/conformance/buffers/empty_free_leak.air new file mode 100644 index 0000000..0ee75cd --- /dev/null +++ b/tests/conformance/buffers/empty_free_leak.air @@ -0,0 +1,45 @@ +; expect: reject E3002 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + ret %answer +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/free_failure.air b/tests/conformance/buffers/free_failure.air new file mode 100644 index 0000000..638d603 --- /dev/null +++ b/tests/conformance/buffers/free_failure.air @@ -0,0 +1,46 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:128 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] + +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %c_1 = const.usize 1 + buffer.new own %c_1, %heap, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: buffer>): + %c_6 = const.u64 42 + own.new %c_6, %heap, ok -> @ok_7, err -> @err_9 +err_4(%err_5: alloc_error): + trap +ok_7(%ok_8: own): + %data_11 = borrow.mut %ok_3 + buffer.push %data_11, %ok_8, ok -> @ok_12, err -> @err_13 +err_9(%err_10: alloc_error): + trap +ok_12: + borrow.end %data_11 + buffer.free %ok_3, ok -> @ok_15, err -> @err_16 +err_13(%err_14: own): + trap +ok_15: + trap +err_16(%err_17: buffer>): + %c_18 = const.u64 0 + %returned_19 = borrow.mut %err_17 + buffer.pop %returned_19, ok -> @ok_20, err -> @err_22 +ok_20(%ok_21: own): + %v_23 = own.take %ok_21 + borrow.end %returned_19 + buffer.free %err_17, ok -> @ok_24, err -> @err_25 +err_22: + trap +ok_24: + ret %v_23 +err_25(%err_26: buffer>): + trap diff --git a/tests/conformance/buffers/free_return_type.air b/tests/conformance/buffers/free_return_type.air new file mode 100644 index 0000000..ffee467 --- /dev/null +++ b/tests/conformance/buffers/free_return_type.air @@ -0,0 +1,45 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: own): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/metadata_owner.air b/tests/conformance/buffers/metadata_owner.air new file mode 100644 index 0000000..e74630d --- /dev/null +++ b/tests/conformance/buffers/metadata_owner.air @@ -0,0 +1,45 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %data + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/new_count_type.air b/tests/conformance/buffers/new_count_type.air new file mode 100644 index 0000000..1d3c225 --- /dev/null +++ b/tests/conformance/buffers/new_count_type.air @@ -0,0 +1,45 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.u64 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/new_return_type.air b/tests/conformance/buffers/new_return_type.air new file mode 100644 index 0000000..610914b --- /dev/null +++ b/tests/conformance/buffers/new_return_type.air @@ -0,0 +1,45 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: own_array>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/owner.air b/tests/conformance/buffers/owner.air new file mode 100644 index 0000000..cb7adbe --- /dev/null +++ b/tests/conformance/buffers/owner.air @@ -0,0 +1,47 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:128 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/pop_return_type.air b/tests/conformance/buffers/pop_return_type.air new file mode 100644 index 0000000..9e6e717 --- /dev/null +++ b/tests/conformance/buffers/pop_return_type.air @@ -0,0 +1,20 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @bad(%b: mut>>) -> void +effects [] +entry: + buffer.pop %b, ok -> @ok, err -> @err +ok(%item: u64): + trap +err: + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/push_continuation_count.air b/tests/conformance/buffers/push_continuation_count.air new file mode 100644 index 0000000..8de8ec1 --- /dev/null +++ b/tests/conformance/buffers/push_continuation_count.air @@ -0,0 +1,45 @@ +; expect: reject E5002 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed(%unwanted: u64): + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/push_failure.air b/tests/conformance/buffers/push_failure.air new file mode 100644 index 0000000..e8cde41 --- /dev/null +++ b/tests/conformance/buffers/push_failure.air @@ -0,0 +1,38 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:8 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] + +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %c_1 = const.usize 0 + buffer.new own %c_1, %heap, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: buffer>): + %c_6 = const.u64 42 + own.new %c_6, %heap, ok -> @ok_7, err -> @err_9 +err_4(%err_5: alloc_error): + trap +ok_7(%ok_8: own): + %c_11 = const.u64 0 + %data_12 = borrow.mut %ok_3 + buffer.push %data_12, %ok_8, ok -> @ok_13, err -> @err_14 +err_9(%err_10: alloc_error): + trap +ok_13: + trap +err_14(%err_15: own): + %v_16 = own.take %err_15 + br @endmatch_17(%v_16) +endmatch_17(%answer_18: u64): + borrow.end %data_12 + buffer.free %ok_3, ok -> @ok_19, err -> @err_20 +ok_19: + ret %answer_18 +err_20(%err_21: buffer>): + trap diff --git a/tests/conformance/buffers/push_type.air b/tests/conformance/buffers/push_type.air new file mode 100644 index 0000000..8b818f1 --- /dev/null +++ b/tests/conformance/buffers/push_type.air @@ -0,0 +1,45 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %n, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.usize 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/readonly_view_push.air b/tests/conformance/buffers/readonly_view_push.air new file mode 100644 index 0000000..6ba05db --- /dev/null +++ b/tests/conformance/buffers/readonly_view_push.air @@ -0,0 +1,23 @@ +; expect: reject E2101 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @bad(%b: mut>) -> void +effects [] +entry: + %r = borrow.ref %b + %view = buffer.view %r + %item = const.u64 42 + buffer.push %b, %item, ok -> @ok, err -> @err +ok: + trap +err(%original: u64): + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/reserve_count_type.air b/tests/conformance/buffers/reserve_count_type.air new file mode 100644 index 0000000..e2b60ab --- /dev/null +++ b/tests/conformance/buffers/reserve_count_type.air @@ -0,0 +1,45 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module test.buffers + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %capacity = const.usize 1 + %n = const.u64 42 + buffer.new own %capacity, %heap, ok -> @made, err -> @failed +made(%data: buffer>): + own.new %n, %heap, ok -> @owned, err -> @owner_failed +owned(%owner: own): + %b = borrow.mut %data + buffer.push %b, %owner, ok -> @pushed, err -> @full +full(%returned: own): + trap +pushed: + %next_capacity = const.u64 2 + buffer.reserve %b, %next_capacity, %heap, ok -> @grown, err -> @reserve_failed +grown: + %length = buffer.len %b + %capacity_after = buffer.capacity %b + %view = buffer.view %b + borrow.end %view + buffer.pop %b, ok -> @popped, err -> @empty +popped(%part: own): + %answer = own.take %part + borrow.end %b + buffer.free %data, ok -> @done, err -> @nonempty +nonempty(%original: buffer>): + trap +done: + ret %answer +empty: + trap +failed(%error: alloc_error): + trap +owner_failed(%owner_error: alloc_error): + trap +reserve_failed(%reserve_error: alloc_error): + trap diff --git a/tests/conformance/buffers/reserve_failure.air b/tests/conformance/buffers/reserve_failure.air new file mode 100644 index 0000000..f4d604c --- /dev/null +++ b/tests/conformance/buffers/reserve_failure.air @@ -0,0 +1,55 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:24 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] + +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %c_1 = const.usize 1 + buffer.new own %c_1, %heap, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: buffer>): + %c_6 = const.u64 42 + own.new %c_6, %heap, ok -> @ok_7, err -> @err_9 +err_4(%err_5: alloc_error): + trap +ok_7(%ok_8: own): + %c_11 = const.u64 0 + %data_12 = borrow.mut %ok_3 + buffer.push %data_12, %ok_8, ok -> @ok_13, err -> @err_14 +err_9(%err_10: alloc_error): + trap +ok_13: + %c_16 = const.usize 2 + buffer.reserve %data_12, %c_16, %heap, ok -> @ok_17, err -> @err_18 +err_14(%err_15: own): + trap +ok_17: + trap +err_18(%err_19: alloc_error): + br @endmatch_20() +endmatch_20: + %size_21 = buffer.len %data_12 + %c_22 = const.usize 1 + %cmp_23 = eq.usize %size_21, %c_22 + assert %cmp_23 + %size_24 = buffer.capacity %data_12 + %c_25 = const.usize 1 + %cmp_26 = eq.usize %size_24, %c_25 + assert %cmp_26 + buffer.pop %data_12, ok -> @ok_27, err -> @err_29 +ok_27(%ok_28: own): + %v_30 = own.take %ok_28 + borrow.end %data_12 + buffer.free %ok_3, ok -> @ok_31, err -> @err_32 +err_29: + trap +ok_31: + ret %v_30 +err_32(%err_33: buffer>): + trap diff --git a/tests/conformance/buffers/reserve_missing_effect.air b/tests/conformance/buffers/reserve_missing_effect.air new file mode 100644 index 0000000..a8877c9 --- /dev/null +++ b/tests/conformance/buffers/reserve_missing_effect.air @@ -0,0 +1,21 @@ +; expect: reject E3101 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @bad(%b: mut>, %heap: cap) -> void +effects [] +entry: + %n = const.usize 2 + buffer.reserve %b, %n, %heap, ok -> @ok, err -> @err +ok: + trap +err(%error: alloc_error): + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/task_loan_join.air b/tests/conformance/buffers/task_loan_join.air new file mode 100644 index 0000000..6494bce --- /dev/null +++ b/tests/conformance/buffers/task_loan_join.air @@ -0,0 +1,52 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:8 +; schedules: 8 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources, tasks] + +fn @worker(%b: mut>) -> void +effects [] +entry: + %values_1 = buffer.view %b + %c_2 = const.u64 42 + %c_3 = const.usize 0 + %e_4 = borrow.index %values_1, %c_3 + store %e_4, %c_2 + borrow.end %e_4 + borrow.end %values_1 + ret + +fn @main(%heap: cap) -> u64 +effects [mem.alloc, task.spawn, task.wait] +entry: + %c_1 = const.usize 1 + buffer.new u64 %c_1, %heap, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: buffer): + %c_6 = const.u64 0 + %data_7 = borrow.mut %ok_3 + %c_8 = const.u64 0 + buffer.push %data_7, %c_8, ok -> @ok_9, err -> @err_10 +err_4(%err_5: alloc_error): + trap +ok_9: + %s_12 = task.scope.begin + %t_13 = task.spawn %s_12, @worker(%data_7) + task.join %t_13 + buffer.pop %data_7, ok -> @ok_14, err -> @err_16 +err_10(%err_11: u64): + trap +ok_14(%ok_15: u64): + task.scope.end %s_12 + borrow.end %data_7 + buffer.free %ok_3, ok -> @ok_17, err -> @err_18 +err_16: + trap +ok_17: + ret %ok_15 +err_18(%err_19: buffer): + trap diff --git a/tests/conformance/buffers/undeclared.air b/tests/conformance/buffers/undeclared.air new file mode 100644 index 0000000..57c4c49 --- /dev/null +++ b/tests/conformance/buffers/undeclared.air @@ -0,0 +1,16 @@ +; expect: reject E0006 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +fn @bad(%b: buffer) -> void +effects [] +entry: + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/vec_sender.air b/tests/conformance/buffers/vec_sender.air new file mode 100644 index 0000000..b9e6615 --- /dev/null +++ b/tests/conformance/buffers/vec_sender.air @@ -0,0 +1,151 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:256 +; schedules: 8 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +air 0 +lang 0.1 +features [arrays, cancellation, capabilities, channels, effects, heap, linear_aggregates, linear_buffers, ownership, resources, tasks] + +type @Job = struct { number: u64 } +type @__aji_std_vec_ReserveResult = enum { ok, err(alloc_error) } +type @__aji_g_030fbb9d89a7b1d26bd24ed3bdf33aeb0f973c9877aea5a3ab590df0d069cd9c = enum { some(sender<@Job>), none } +type @__aji_g_adf9ab506f225116b4e63940ab764bfcf831b362013f39a9cce1f9da40a5d25f = enum { ok, not_empty(@__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd) } +type @__aji_g_678f796d99d95f5e4ab04650d6a2af4225cf23c28867f2c8b9b7f9a6f3523c53 = enum { ok(@__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd), err(alloc_error) } +type @__aji_g_9979c1f74e57d64560456fdd7003b9a1397c206d9b6ffa0f2828572f0b21745b = enum { ok, full(sender<@Job>) } +type @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd = struct { storage: buffer> } + +fn @worker(%value: @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd) -> void +effects [task.wait] +entry: + %value_1 = borrow.mut %value + %generic_call_2 = call @__aji_g_05e8ce97baf6d44b66d79d478b43e291c51a47c06f6dd0d5b46a43d38e237a5e(%value_1) + enum.take @__aji_g_030fbb9d89a7b1d26bd24ed3bdf33aeb0f973c9877aea5a3ab590df0d069cd9c %generic_call_2, some -> @case_some_3, none -> @case_none_5 +case_some_3(%tx_4: sender<@Job>): + %tx_6 = borrow.mut %tx_4 + %c_7 = const.u64 42 + %s_8 = struct.make @Job(%c_7) + channel.send %tx_6, %s_8, ok -> @ok_9, closed -> @closed_10, cancelled -> @cancelled_12 +case_none_5: + trap +ok_9: + borrow.end %tx_6 + channel.close_sender %tx_4 + br @endmatch_14() +closed_10(%closed_11: @Job): + borrow.end %tx_6 + trap +cancelled_12(%cancelled_13: @Job): + borrow.end %tx_6 + trap +endmatch_14: + borrow.end %value_1 + %generic_call_15 = call @__aji_g_c3dfdd6f0d003fa9cc11d939d0324808c052768cff10a2925e95c10178c18f56(%value) + enum.take @__aji_g_adf9ab506f225116b4e63940ab764bfcf831b362013f39a9cce1f9da40a5d25f %generic_call_15, ok -> @case_ok_16, not_empty -> @case_not_empty_17 +case_ok_16: + br @endmatch_19() +case_not_empty_17(%returned_18: @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd): + trap +endmatch_19: + ret + +fn @main(%heap: cap) -> u64 +effects [mem.alloc, task.spawn, task.wait] +entry: + %c_1 = const.usize 1 + channel.make @Job, %c_1, %heap, ok -> @ok_2, err -> @err_5 +ok_2(%ok_3: sender<@Job>, %ok_4: receiver<@Job>): + %c_7 = const.usize 1 + %generic_call_8 = call @__aji_g_85108950b46229b59504ce70316fec0d38c98bc75d7860ef8431efa39d94328f(%c_7, %heap) + enum.take @__aji_g_678f796d99d95f5e4ab04650d6a2af4225cf23c28867f2c8b9b7f9a6f3523c53 %generic_call_8, ok -> @case_ok_9, err -> @case_err_11 +err_5(%err_6: alloc_error): + trap +case_ok_9(%value_10: @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd): + %value_13 = borrow.mut %value_10 + %generic_call_14 = call @__aji_g_cc938739a2436bdd418386dd703e9615d44ed6b51baa426156f2f300b87fff47(%value_13, %ok_3) + enum.take @__aji_g_9979c1f74e57d64560456fdd7003b9a1397c206d9b6ffa0f2828572f0b21745b %generic_call_14, ok -> @case_ok_15, full -> @case_full_16 +case_err_11(%error_12: alloc_error): + trap +case_ok_15: + br @endmatch_18() +case_full_16(%returned_17: sender<@Job>): + channel.close_sender %returned_17 + trap +endmatch_18: + borrow.end %value_13 + %s_19 = task.scope.begin + %t_20 = task.spawn %s_19, @worker(%value_10) + %rx_21 = borrow.mut %ok_4 + channel.recv %rx_21, ok -> @ok_22, closed -> @closed_24, cancelled -> @cancelled_25 +ok_22(%ok_23: @Job): + borrow.end %rx_21 + task.join %t_20 + channel.close_receiver %ok_4, ok -> @ok_26, pending -> @pending_27 +closed_24: + borrow.end %rx_21 + trap +cancelled_25: + borrow.end %rx_21 + trap +ok_26: + %number_29 = struct.get @Job.number, %ok_23 + task.scope.end %s_19 + ret %number_29 +pending_27(%pending_28: receiver<@Job>): + trap + +fn @__aji_g_c3dfdd6f0d003fa9cc11d939d0324808c052768cff10a2925e95c10178c18f56(%value: @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd) -> @__aji_g_adf9ab506f225116b4e63940ab764bfcf831b362013f39a9cce1f9da40a5d25f +effects [] +entry: + struct.unpack @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd %value, next -> @unpacked_1 +unpacked_1(%storage_2: buffer>): + buffer.free %storage_2, ok -> @ok_3, err -> @err_4 +ok_3: + %e_6 = enum.make @__aji_g_adf9ab506f225116b4e63940ab764bfcf831b362013f39a9cce1f9da40a5d25f.ok() + ret %e_6 +err_4(%err_5: buffer>): + %s_7 = struct.make @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd(%err_5) + %e_8 = enum.make @__aji_g_adf9ab506f225116b4e63940ab764bfcf831b362013f39a9cce1f9da40a5d25f.not_empty(%s_7) + ret %e_8 + +fn @__aji_g_85108950b46229b59504ce70316fec0d38c98bc75d7860ef8431efa39d94328f(%capacity: usize, %heap: cap) -> @__aji_g_678f796d99d95f5e4ab04650d6a2af4225cf23c28867f2c8b9b7f9a6f3523c53 +effects [mem.alloc] +entry: + buffer.new sender<@Job> %capacity, %heap, ok -> @ok_1, err -> @err_3 +ok_1(%ok_2: buffer>): + %s_5 = struct.make @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd(%ok_2) + %e_6 = enum.make @__aji_g_678f796d99d95f5e4ab04650d6a2af4225cf23c28867f2c8b9b7f9a6f3523c53.ok(%s_5) + ret %e_6 +err_3(%err_4: alloc_error): + %e_7 = enum.make @__aji_g_678f796d99d95f5e4ab04650d6a2af4225cf23c28867f2c8b9b7f9a6f3523c53.err(%err_4) + ret %e_7 + +fn @__aji_g_05e8ce97baf6d44b66d79d478b43e291c51a47c06f6dd0d5b46a43d38e237a5e(%value: mut<@__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd>) -> @__aji_g_030fbb9d89a7b1d26bd24ed3bdf33aeb0f973c9877aea5a3ab590df0d069cd9c +effects [] +entry: + %storage_1 = borrow.field @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd.storage, %value + buffer.pop %storage_1, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: sender<@Job>): + %e_5 = enum.make @__aji_g_030fbb9d89a7b1d26bd24ed3bdf33aeb0f973c9877aea5a3ab590df0d069cd9c.some(%ok_3) + borrow.end %storage_1 + ret %e_5 +err_4: + %e_6 = enum.make @__aji_g_030fbb9d89a7b1d26bd24ed3bdf33aeb0f973c9877aea5a3ab590df0d069cd9c.none() + borrow.end %storage_1 + ret %e_6 + +fn @__aji_g_cc938739a2436bdd418386dd703e9615d44ed6b51baa426156f2f300b87fff47(%value: mut<@__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd>, %item: sender<@Job>) -> @__aji_g_9979c1f74e57d64560456fdd7003b9a1397c206d9b6ffa0f2828572f0b21745b +effects [] +entry: + %storage_1 = borrow.field @__aji_g_ea026a1e94735341330b23660939aafc27c5ea0adb84d993a6694eb8588118dd.storage, %value + buffer.push %storage_1, %item, ok -> @ok_2, err -> @err_3 +ok_2: + %e_5 = enum.make @__aji_g_9979c1f74e57d64560456fdd7003b9a1397c206d9b6ffa0f2828572f0b21745b.ok() + borrow.end %storage_1 + ret %e_5 +err_3(%err_4: sender<@Job>): + %e_6 = enum.make @__aji_g_9979c1f74e57d64560456fdd7003b9a1397c206d9b6ffa0f2828572f0b21745b.full(%err_4) + borrow.end %storage_1 + ret %e_6 diff --git a/tests/conformance/buffers/view.air b/tests/conformance/buffers/view.air new file mode 100644 index 0000000..4411ee9 --- /dev/null +++ b/tests/conformance/buffers/view.air @@ -0,0 +1,64 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:128 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] + +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %c_1 = const.usize 2 + buffer.new u64 %c_1, %heap, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: buffer): + %data_6 = borrow.mut %ok_3 + %c_7 = const.u64 41 + buffer.push %data_6, %c_7, ok -> @ok_8, err -> @err_9 +err_4(%err_5: alloc_error): + trap +ok_8: + %values_11 = buffer.view %data_6 + %len_12 = slice.len %values_11 + %c_13 = const.usize 1 + %cmp_14 = eq.usize %len_12, %c_13 + assert %cmp_14 + %c_15 = const.usize 0 + %e_16 = borrow.index %values_11, %c_15 + %v_17 = load %e_16 + borrow.end %e_16 + %c_18 = const.u64 1 + %t_19 = add.checked.u64 %v_17, %c_18 + %c_20 = const.usize 0 + %e_21 = borrow.index %values_11, %c_20 + store %e_21, %t_19 + borrow.end %e_21 + borrow.end %values_11 + %buffer_ref_22 = borrow.ref %data_6 + %values_23 = buffer.view %buffer_ref_22 + %c_24 = const.usize 0 + %e_25 = borrow.index %values_23, %c_24 + %v_26 = load %e_25 + borrow.end %e_25 + %c_27 = const.u64 42 + %cmp_28 = eq.u64 %v_26, %c_27 + assert %cmp_28 + borrow.end %values_23 + borrow.end %buffer_ref_22 + borrow.end %data_6 + %c_29 = const.u64 0 + %data_30 = borrow.mut %ok_3 + buffer.pop %data_30, ok -> @ok_31, err -> @err_33 +err_9(%err_10: u64): + trap +ok_31(%ok_32: u64): + borrow.end %data_30 + buffer.free %ok_3, ok -> @ok_34, err -> @err_35 +err_33: + trap +ok_34: + ret %ok_32 +err_35(%err_36: buffer): + trap diff --git a/tests/conformance/buffers/view_mutation.air b/tests/conformance/buffers/view_mutation.air new file mode 100644 index 0000000..7955571 --- /dev/null +++ b/tests/conformance/buffers/view_mutation.air @@ -0,0 +1,22 @@ +; expect: reject E2101 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @bad(%b: mut>, %heap: cap) -> void +effects [mem.alloc] +entry: + %n = const.usize 0 + %view = buffer.view %b + buffer.reserve %b, %n, %heap, ok -> @ok, err -> @err +ok: + trap +err(%error: alloc_error): + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/wrong_capability.air b/tests/conformance/buffers/wrong_capability.air new file mode 100644 index 0000000..630795d --- /dev/null +++ b/tests/conformance/buffers/wrong_capability.air @@ -0,0 +1,21 @@ +; expect: reject E3201 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Dynamic buffers +module buffer.contract +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] +fn @bad(%b: mut>, %cap: cap) -> void +effects [mem.alloc] +entry: + %n = const.usize 0 + buffer.reserve %b, %n, %cap, ok -> @ok, err -> @err +ok: + trap +err(%error: alloc_error): + trap +fn @main() -> u64 +effects [] +entry: + %answer = const.u64 42 + ret %answer diff --git a/tests/conformance/buffers/zero.air b/tests/conformance/buffers/zero.air new file mode 100644 index 0000000..ecece69 --- /dev/null +++ b/tests/conformance/buffers/zero.air @@ -0,0 +1,46 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:0 +; phase: 6 +; spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, linear_buffers, ownership, resources] + +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %c_1 = const.usize 0 + buffer.new u64 %c_1, %heap, ok -> @ok_2, err -> @err_4 +ok_2(%ok_3: buffer): + %data_6 = borrow.mut %ok_3 + buffer.pop %data_6, ok -> @ok_7, err -> @err_9 +err_4(%err_5: alloc_error): + trap +ok_7(%ok_8: u64): + trap +err_9: + br @endmatch_10() +endmatch_10: + %c_11 = const.u64 42 + buffer.push %data_6, %c_11, ok -> @ok_12, err -> @err_13 +ok_12: + trap +err_13(%err_14: u64): + %c_15 = const.u64 42 + %cmp_16 = eq.u64 %err_14, %c_15 + assert %cmp_16 + br @endmatch_17() +endmatch_17: + %size_18 = buffer.len %data_6 + %c_19 = const.usize 0 + %cmp_20 = eq.usize %size_18, %c_19 + assert %cmp_20 + borrow.end %data_6 + buffer.free %ok_3, ok -> @ok_21, err -> @err_22 +ok_21: + %c_24 = const.u64 42 + ret %c_24 +err_22(%err_23: buffer): + trap diff --git a/tests/conformance/error_values/alloc_error_budget_exceeded.air b/tests/conformance/error_values/alloc_error_budget_exceeded.air new file mode 100644 index 0000000..fb47f97 --- /dev/null +++ b/tests/conformance/error_values/alloc_error_budget_exceeded.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"budget_exceeded","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> alloc_error +effects [] +entry: + %e = error.const alloc_error.budget_exceeded + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/alloc_error_out_of_memory.air b/tests/conformance/error_values/alloc_error_out_of_memory.air new file mode 100644 index 0000000..7daaea3 --- /dev/null +++ b/tests/conformance/error_values/alloc_error_out_of_memory.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"out_of_memory","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> alloc_error +effects [] +entry: + %e = error.const alloc_error.out_of_memory + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/cap_error_invalid_restriction.air b/tests/conformance/error_values/cap_error_invalid_restriction.air new file mode 100644 index 0000000..e87b1f3 --- /dev/null +++ b/tests/conformance/error_values/cap_error_invalid_restriction.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"invalid_restriction","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> cap_error +effects [] +entry: + %e = error.const cap_error.invalid_restriction + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/cap_error_not_subset.air b/tests/conformance/error_values/cap_error_not_subset.air new file mode 100644 index 0000000..40aae07 --- /dev/null +++ b/tests/conformance/error_values/cap_error_not_subset.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"not_subset","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> cap_error +effects [] +entry: + %e = error.const cap_error.not_subset + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/cap_error_unsupported_restriction.air b/tests/conformance/error_values/cap_error_unsupported_restriction.air new file mode 100644 index 0000000..791420f --- /dev/null +++ b/tests/conformance/error_values/cap_error_unsupported_restriction.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"unsupported_restriction","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> cap_error +effects [] +entry: + %e = error.const cap_error.unsupported_restriction + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/dependency.air b/tests/conformance/error_values/dependency.air new file mode 100644 index 0000000..bbb4f06 --- /dev/null +++ b/tests/conformance/error_values/dependency.air @@ -0,0 +1,12 @@ +; expect: reject E0006 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [error_values] +fn @main() -> u64 +effects [] +entry: + %x = const.u64 42 + ret %x diff --git a/tests/conformance/error_values/frozen_enum_make.air b/tests/conformance/error_values/frozen_enum_make.air new file mode 100644 index 0000000..0308327 --- /dev/null +++ b/tests/conformance/error_values/frozen_enum_make.air @@ -0,0 +1,12 @@ +; expect: reject E0001 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> alloc_error +effects [] +entry: + %e = enum.make alloc_error.budget_exceeded() + ret %e diff --git a/tests/conformance/error_values/io_error_address_in_use.air b/tests/conformance/error_values/io_error_address_in_use.air new file mode 100644 index 0000000..926ec27 --- /dev/null +++ b/tests/conformance/error_values/io_error_address_in_use.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"address_in_use","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.address_in_use + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_address_unavailable.air b/tests/conformance/error_values/io_error_address_unavailable.air new file mode 100644 index 0000000..3d92dcd --- /dev/null +++ b/tests/conformance/error_values/io_error_address_unavailable.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"address_unavailable","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.address_unavailable + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_already_exists.air b/tests/conformance/error_values/io_error_already_exists.air new file mode 100644 index 0000000..e01cf18 --- /dev/null +++ b/tests/conformance/error_values/io_error_already_exists.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"already_exists","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.already_exists + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_broken_pipe.air b/tests/conformance/error_values/io_error_broken_pipe.air new file mode 100644 index 0000000..7c65cb9 --- /dev/null +++ b/tests/conformance/error_values/io_error_broken_pipe.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"broken_pipe","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.broken_pipe + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_connection_refused.air b/tests/conformance/error_values/io_error_connection_refused.air new file mode 100644 index 0000000..a8c8514 --- /dev/null +++ b/tests/conformance/error_values/io_error_connection_refused.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"connection_refused","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.connection_refused + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_connection_reset.air b/tests/conformance/error_values/io_error_connection_reset.air new file mode 100644 index 0000000..3e75583 --- /dev/null +++ b/tests/conformance/error_values/io_error_connection_reset.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"connection_reset","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.connection_reset + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_invalid_input.air b/tests/conformance/error_values/io_error_invalid_input.air new file mode 100644 index 0000000..c1a8765 --- /dev/null +++ b/tests/conformance/error_values/io_error_invalid_input.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"invalid_input","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.invalid_input + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_no_space.air b/tests/conformance/error_values/io_error_no_space.air new file mode 100644 index 0000000..57aa0a6 --- /dev/null +++ b/tests/conformance/error_values/io_error_no_space.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"no_space","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.no_space + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_not_found.air b/tests/conformance/error_values/io_error_not_found.air new file mode 100644 index 0000000..bcfdcbf --- /dev/null +++ b/tests/conformance/error_values/io_error_not_found.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"not_found","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.not_found + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_other.air b/tests/conformance/error_values/io_error_other.air new file mode 100644 index 0000000..938e467 --- /dev/null +++ b/tests/conformance/error_values/io_error_other.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"other","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.other + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_permission_denied.air b/tests/conformance/error_values/io_error_permission_denied.air new file mode 100644 index 0000000..4726f8e --- /dev/null +++ b/tests/conformance/error_values/io_error_permission_denied.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"permission_denied","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.permission_denied + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/io_error_timed_out.air b/tests/conformance/error_values/io_error_timed_out.air new file mode 100644 index 0000000..409b2e5 --- /dev/null +++ b/tests/conformance/error_values/io_error_timed_out.air @@ -0,0 +1,14 @@ +; expect: run +; result: {"variant":"timed_out","payload":[]} +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const io_error.timed_out + %copy = copy %e + ret %copy diff --git a/tests/conformance/error_values/no_authority.air b/tests/conformance/error_values/no_authority.air new file mode 100644 index 0000000..69529db --- /dev/null +++ b/tests/conformance/error_values/no_authority.air @@ -0,0 +1,12 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> cap +effects [] +entry: + %e = error.const alloc_error.budget_exceeded + ret %e diff --git a/tests/conformance/error_values/payload.air b/tests/conformance/error_values/payload.air new file mode 100644 index 0000000..8469148 --- /dev/null +++ b/tests/conformance/error_values/payload.air @@ -0,0 +1,12 @@ +; expect: reject E0001 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> alloc_error +effects [] +entry: + %e = error.const alloc_error.budget_exceeded() + ret %e diff --git a/tests/conformance/error_values/undeclared.air b/tests/conformance/error_values/undeclared.air new file mode 100644 index 0000000..1440cb4 --- /dev/null +++ b/tests/conformance/error_values/undeclared.air @@ -0,0 +1,12 @@ +; expect: reject E0006 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, heap, ownership, resources] +fn @main() -> alloc_error +effects [] +entry: + %e = error.const alloc_error.budget_exceeded + ret %e diff --git a/tests/conformance/error_values/unknown_family.air b/tests/conformance/error_values/unknown_family.air new file mode 100644 index 0000000..f1e9136 --- /dev/null +++ b/tests/conformance/error_values/unknown_family.air @@ -0,0 +1,12 @@ +; expect: reject E0004 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> void +effects [] +entry: + %e = error.const user_error.invalid + ret diff --git a/tests/conformance/error_values/unknown_variant.air b/tests/conformance/error_values/unknown_variant.air new file mode 100644 index 0000000..f844993 --- /dev/null +++ b/tests/conformance/error_values/unknown_variant.air @@ -0,0 +1,12 @@ +; expect: reject E0004 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> alloc_error +effects [] +entry: + %e = error.const alloc_error.invalid + ret %e diff --git a/tests/conformance/error_values/wrong_family.air b/tests/conformance/error_values/wrong_family.air new file mode 100644 index 0000000..aa53bde --- /dev/null +++ b/tests/conformance/error_values/wrong_family.air @@ -0,0 +1,12 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +air 0 +lang 0.1 +features [capabilities, effects, error_values, heap, ownership, resources] +fn @main() -> io_error +effects [] +entry: + %e = error.const alloc_error.budget_exceeded + ret %e diff --git a/tests/conformance/generics/array_layout.air b/tests/conformance/generics/array_layout.air new file mode 100644 index 0000000..8c26614 --- /dev/null +++ b/tests/conformance/generics/array_layout.air @@ -0,0 +1,15 @@ +; expect: run +; result: 42 +; phase: 1 +; spec: docs/spec/07-air.md §8.3 +module demo.layout +air 0 +lang 0.1 +features [arrays, ownership] +type @Leaf = struct { value: u64 } +type @Node = struct { child: array<@Leaf, 1> } +fn @main() -> u64 +effects [] +entry: + %value = const.u64 42 + ret %value diff --git a/tests/conformance/generics/option.air b/tests/conformance/generics/option.air new file mode 100644 index 0000000..c9f088a --- /dev/null +++ b/tests/conformance/generics/option.air @@ -0,0 +1,25 @@ +; expect: run +; result: 42 +; phase: 0 +; spec: docs/spec/15-source-language.md §15; docs/spec/07a-air-instructions.md +module demo.generic +air 0 +lang 0.1 +features [] +type @Option_u64 = enum { some(u64), none } +fn @identity_u64(%value: u64) -> u64 +effects [] +entry: + ret %value +fn @main() -> u64 +effects [] +entry: + %value = const.u64 42 + %copied = call @identity_u64(%value) + %option = enum.make @Option_u64.some(%copied) + enum.switch @Option_u64 %option, some -> @present, none -> @absent +present(%payload: u64): + ret %payload +absent: + %zero = const.u64 0 + ret %zero diff --git a/tests/conformance/generics/recursive_array.air b/tests/conformance/generics/recursive_array.air new file mode 100644 index 0000000..1b28c87 --- /dev/null +++ b/tests/conformance/generics/recursive_array.air @@ -0,0 +1,13 @@ +; expect: reject E1003 +; phase: 1 +; spec: docs/spec/07-air.md §8.3 +module demo.layout +air 0 +lang 0.1 +features [arrays, ownership] +type @Node = struct { child: array<@Node, 1> } +fn @main() -> u64 +effects [] +entry: + %value = const.u64 42 + ret %value diff --git a/tests/conformance/linear/array_count.air b/tests/conformance/linear/array_count.air new file mode 100644 index 0000000..37ab316 --- /dev/null +++ b/tests/conformance/linear/array_count.air @@ -0,0 +1,12 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +fn @bad(%owner: own) -> void +effects [] +entry: + %items = array.make array,2>(%owner) + trap diff --git a/tests/conformance/linear/borrow_array.air b/tests/conformance/linear/borrow_array.air new file mode 100644 index 0000000..8526e2e --- /dev/null +++ b/tests/conformance/linear/borrow_array.air @@ -0,0 +1,12 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [arrays, capabilities, effects, linear_aggregates, ownership, resources] +fn @f(%r: ref) -> void +effects [] +entry: + %bad = array.make array, 1>(%r) + ret diff --git a/tests/conformance/linear/builtin_take.air b/tests/conformance/linear/builtin_take.air new file mode 100644 index 0000000..bdc9c9f --- /dev/null +++ b/tests/conformance/linear/builtin_take.air @@ -0,0 +1,13 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear + air 0 + lang 0.1 + features [capabilities, effects, heap, linear_aggregates, ownership, resources] +fn @bad(%error: alloc_error) -> void +effects [] +entry: + enum.take alloc_error %error, budget_exceeded -> @done, out_of_memory -> @done +done: + ret diff --git a/tests/conformance/linear/copy.air b/tests/conformance/linear/copy.air new file mode 100644 index 0000000..bfb250f --- /dev/null +++ b/tests/conformance/linear/copy.air @@ -0,0 +1,23 @@ +; expect: reject E1001 +; grant: heap=mem.alloc:64 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Pair = struct { value: own, tag: u64 } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %record = struct.make @Pair(%owner, %n) + %duplicate = copy %record + struct.unpack @Pair %record, next -> @parts +parts(%part: own, %tag: u64): + %answer = own.take %part + ret %answer +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/enum_incomplete.air b/tests/conformance/linear/enum_incomplete.air new file mode 100644 index 0000000..167eb5f --- /dev/null +++ b/tests/conformance/linear/enum_incomplete.air @@ -0,0 +1,35 @@ +; expect: reject E5002 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Maybe = enum { some(own), none } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %items = array.make array,1>(%owner) + array.unpack array,1> %items, next -> @element +element(%part: own): + %slot = enum.make @Maybe.some(%part) + %empty = enum.make @Maybe.none() + %borrow = borrow.mut %slot + %old = value.swap %borrow, %empty + borrow.end %borrow + enum.take @Maybe %slot, some -> @extra +extra(%extra_owner: own): + own.free %extra_owner + enum.take @Maybe %old, some -> @answer, none -> @no_answer +replaced: + enum.take @Maybe %old, some -> @answer, none -> @no_answer +answer(%answer_owner: own): + %value = own.take %answer_owner + ret %value +no_answer: + ret %n +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/enum_switch.air b/tests/conformance/linear/enum_switch.air new file mode 100644 index 0000000..63475f1 --- /dev/null +++ b/tests/conformance/linear/enum_switch.air @@ -0,0 +1,35 @@ +; expect: reject E1001 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Maybe = enum { some(own), none } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %items = array.make array,1>(%owner) + array.unpack array,1> %items, next -> @element +element(%part: own): + %slot = enum.make @Maybe.some(%part) + %empty = enum.make @Maybe.none() + %borrow = borrow.mut %slot + %old = value.swap %borrow, %empty + borrow.end %borrow + enum.switch @Maybe %slot, some -> @extra, none -> @replaced +extra(%extra_owner: own): + own.free %extra_owner + enum.take @Maybe %old, some -> @answer, none -> @no_answer +replaced: + enum.take @Maybe %old, some -> @answer, none -> @no_answer +answer(%answer_owner: own): + %value = own.take %answer_owner + ret %value +no_answer: + ret %n +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/exchange.air b/tests/conformance/linear/exchange.air new file mode 100644 index 0000000..d4adcb5 --- /dev/null +++ b/tests/conformance/linear/exchange.air @@ -0,0 +1,37 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:64 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Maybe = enum { some(own), none } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %items = array.make array,1>(%owner) + array.unpack array,1> %items, next -> @element +element(%part: own): + %slot = enum.make @Maybe.some(%part) + %empty = enum.make @Maybe.none() + %borrow = borrow.mut %slot + %old = value.swap %borrow, %empty + borrow.end %borrow + enum.take @Maybe %slot, some -> @extra, none -> @replaced +extra(%extra_owner: own): + own.free %extra_owner + enum.take @Maybe %old, some -> @answer, none -> @no_answer +replaced: + enum.take @Maybe %old, some -> @answer, none -> @no_answer +answer(%answer_owner: own): + %value = own.take %answer_owner + ret %value +no_answer: + ret %n +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/field.air b/tests/conformance/linear/field.air new file mode 100644 index 0000000..3ed7c0b --- /dev/null +++ b/tests/conformance/linear/field.air @@ -0,0 +1,23 @@ +; expect: reject E1001 +; grant: heap=mem.alloc:64 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Pair = struct { value: own, tag: u64 } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %record = struct.make @Pair(%owner, %n) + %bad = struct.get @Pair.value, %record + struct.unpack @Pair %record, next -> @parts +parts(%part: own, %tag: u64): + %answer = own.take %part + ret %answer +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/leak.air b/tests/conformance/linear/leak.air new file mode 100644 index 0000000..5ab5081 --- /dev/null +++ b/tests/conformance/linear/leak.air @@ -0,0 +1,21 @@ +; expect: reject E3002 +; grant: heap=mem.alloc:64 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Pair = struct { value: own, tag: u64 } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %record = struct.make @Pair(%owner, %n) + struct.unpack @Pair %record, next -> @parts +parts(%part: own, %tag: u64): + ret %tag +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/owner_copy_array.air b/tests/conformance/linear/owner_copy_array.air new file mode 100644 index 0000000..c99de2e --- /dev/null +++ b/tests/conformance/linear/owner_copy_array.air @@ -0,0 +1,28 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:8 +; phase: 6 +; spec: docs/spec/03-memory-model.md §13 +module test.linear_compat + air 0 + lang 0.1 + features [arrays, capabilities, effects, heap, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + %array = array.splat array %n + own.new %array, %heap, ok -> @got, err -> @failed +got(%owner: own>): + %borrow = borrow.mut %owner + %slice = slice.make %borrow + %zero = const.usize 0 + %element = borrow.index %slice, %zero + %answer = load %element + borrow.end %element + borrow.end %slice + borrow.end %borrow + own.free %owner + ret %answer +failed(%error: alloc_error): + ret %n diff --git a/tests/conformance/linear/pack.air b/tests/conformance/linear/pack.air new file mode 100644 index 0000000..5bb7162 --- /dev/null +++ b/tests/conformance/linear/pack.air @@ -0,0 +1,25 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:64 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [capabilities, effects, heap, linear_aggregates, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + own.pack own %owner, %heap, ok -> @packed, err -> @back +packed(%outer: own>): + %inner = own.take %outer + %answer = own.take %inner + ret %answer +back(%error: alloc_error, %original: own): + %answer2 = own.take %original + ret %answer2 +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/pack_failure.air b/tests/conformance/linear/pack_failure.air new file mode 100644 index 0000000..b9300e6 --- /dev/null +++ b/tests/conformance/linear/pack_failure.air @@ -0,0 +1,25 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:8 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [capabilities, effects, heap, linear_aggregates, ownership, resources] +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + own.pack own %owner, %heap, ok -> @packed, err -> @back +packed(%outer: own>): + %inner = own.take %outer + %answer = own.take %inner + ret %answer +back(%error: alloc_error, %original: own): + %answer2 = own.take %original + ret %answer2 +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/struct.air b/tests/conformance/linear/struct.air new file mode 100644 index 0000000..94a1289 --- /dev/null +++ b/tests/conformance/linear/struct.air @@ -0,0 +1,23 @@ +; expect: run +; result: 42 +; grant: heap=mem.alloc:64 +; phase: 6 +; spec: docs/spec/03-memory-model.md §25 +module test.linear +air 0 +lang 0.1 +features [capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Pair = struct { value: own, tag: u64 } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %record = struct.make @Pair(%owner, %n) + struct.unpack @Pair %record, next -> @parts +parts(%part: own, %tag: u64): + %answer = own.take %part + ret %answer +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/swap_leak.air b/tests/conformance/linear/swap_leak.air new file mode 100644 index 0000000..a0b00e6 --- /dev/null +++ b/tests/conformance/linear/swap_leak.air @@ -0,0 +1,35 @@ +; expect: reject E3002 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Maybe = enum { some(own), none } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %items = array.make array,1>(%owner) + array.unpack array,1> %items, next -> @element +element(%part: own): + %slot = enum.make @Maybe.some(%part) + %empty = enum.make @Maybe.none() + %borrow = borrow.mut %slot + %old = value.swap %borrow, %empty + borrow.end %borrow + enum.take @Maybe %slot, some -> @extra, none -> @replaced +extra(%extra_owner: own): + own.free %extra_owner + enum.take @Maybe %old, some -> @answer, none -> @no_answer +replaced: + ret %n +answer(%answer_owner: own): + %value = own.take %answer_owner + ret %value +no_answer: + ret %n +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/unpack_count.air b/tests/conformance/linear/unpack_count.air new file mode 100644 index 0000000..ee06a91 --- /dev/null +++ b/tests/conformance/linear/unpack_count.air @@ -0,0 +1,35 @@ +; expect: reject E5002 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear +air 0 +lang 0.1 +features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources] +type @Maybe = enum { some(own), none } +fn @main(%heap: cap) -> u64 +effects [mem.alloc] +entry: + %n = const.u64 42 + own.new %n, %heap, ok -> @got, err -> @failed +got(%owner: own): + %items = array.make array,1>(%owner) + array.unpack array,1> %items, next -> @element +element(%part: own, %other: u64): + %slot = enum.make @Maybe.some(%part) + %empty = enum.make @Maybe.none() + %borrow = borrow.mut %slot + %old = value.swap %borrow, %empty + borrow.end %borrow + enum.take @Maybe %slot, some -> @extra, none -> @replaced +extra(%extra_owner: own): + own.free %extra_owner + enum.take @Maybe %old, some -> @answer, none -> @no_answer +replaced: + enum.take @Maybe %old, some -> @answer, none -> @no_answer +answer(%answer_owner: own): + %value = own.take %answer_owner + ret %value +no_answer: + ret %n +failed(%e: alloc_error): + ret %n diff --git a/tests/conformance/linear/without_feature.air b/tests/conformance/linear/without_feature.air new file mode 100644 index 0000000..18e9ee4 --- /dev/null +++ b/tests/conformance/linear/without_feature.air @@ -0,0 +1,13 @@ +; expect: reject E0006 +; phase: 6 +; spec: docs/spec/07a-air-instructions.md Linear aggregates +module test.linear + air 0 + lang 0.1 + features [arrays, ownership] +fn @main() -> u64 +effects [] +entry: + %n = const.u64 42 + %items = array.make array(%n) + ret %n diff --git a/tests/conformance/modules/nominal_call.air b/tests/conformance/modules/nominal_call.air new file mode 100644 index 0000000..a9b3e2a --- /dev/null +++ b/tests/conformance/modules/nominal_call.air @@ -0,0 +1,21 @@ +; expect: reject E1001 +; phase: 0 +; spec: docs/spec/15-source-language.md §14.3; docs/spec/07a-air-instructions.md +module app.entry +air 0 +lang 0.1 +features [] +type @app_a_Pair = struct { value: u64 } +type @app_b_Pair = struct { value: u64 } +fn @app_a_total(%pair: @app_a_Pair) -> u64 +effects [] +entry: + %value = struct.get @app_a_Pair.value, %pair + ret %value +fn @main() -> u64 +effects [] +entry: + %value = const.u64 42 + %pair = struct.make @app_b_Pair(%value) + %result = call @app_a_total(%pair) + ret %result diff --git a/tests/conformance/modules/record.air b/tests/conformance/modules/record.air new file mode 100644 index 0000000..a911f8f --- /dev/null +++ b/tests/conformance/modules/record.air @@ -0,0 +1,24 @@ +; expect: run +; result: 42 +; phase: 0 +; spec: docs/spec/15-source-language.md §14.3; docs/spec/07a-air-instructions.md +module app.entry +air 0 +lang 0.1 +features [] +type @Pair = struct { left: u64, right: u64 } +fn @sum(%pair: @Pair) -> u64 +effects [] +entry: + %left = struct.get @Pair.left, %pair + %right = struct.get @Pair.right, %pair + %total = add.checked.u64 %left, %right + ret %total +fn @main() -> u64 +effects [] +entry: + %left = const.u64 20 + %right = const.u64 22 + %pair = struct.make @Pair(%left, %right) + %result = call @sum(%pair) + ret %result diff --git a/tests/conformance/source/buffered_io/discard_leak.aji b/tests/conformance/source/buffered_io/discard_leak.aji new file mode 100644 index 0000000..e9f9fdb --- /dev/null +++ b/tests/conformance/source/buffered_io/discard_leak.aji @@ -0,0 +1,26 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: std.io.writer.Writer) -> void effects [] { std.io.writer.discard(move q); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/empty_cached.aji b/tests/conformance/source/buffered_io/empty_cached.aji new file mode 100644 index 0000000..c714fea --- /dev/null +++ b/tests/conformance/source/buffered_io/empty_cached.aji @@ -0,0 +1,34 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1]; + { mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => {}, std.io.reader.ReadResult::err(error) => { trap; } } + exact(std.io.reader.read_exact(q,mut byte[0usize..0usize])); match std.io.reader.read(q,mut byte[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } } + let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 2usize); fs.close(move file) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/empty_reader.aji b/tests/conformance/source/buffered_io/empty_reader.aji new file mode 100644 index 0000000..77f6040 --- /dev/null +++ b/tests/conformance/source/buffered_io/empty_reader.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1]; + { mut q = value; exact(std.io.reader.read_exact(q,mut byte[0usize..0usize])); match std.io.reader.read(q,mut byte[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } } + let file = finished_reader(move value); exact(std.io.read_exact_file(mut file,mut byte)); assert(byte[0] == 97u8); fs.close(move file) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/finish_borrowed.aji b/tests/conformance/source/buffered_io/finish_borrowed.aji new file mode 100644 index 0000000..a5c2aff --- /dev/null +++ b/tests/conformance/source/buffered_io/finish_borrowed.aji @@ -0,0 +1,26 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: std.io.reader.Reader) -> void effects [fs.read] { mut file = q.file; std.io.reader.finish(move q); var bytes: [u8;1] = [0u8;1]; fs.read(file,mut bytes) or trap; trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/finish_error_leak.aji b/tests/conformance/source/buffered_io/finish_error_leak.aji new file mode 100644 index 0000000..888676d --- /dev/null +++ b/tests/conformance/source/buffered_io/finish_error_leak.aji @@ -0,0 +1,26 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: std.io.writer.Writer) -> void effects [fs.write] { match std.io.writer.finish(move q) { std.io.writer.FinishResult::ok(file) => { trap; }, std.io.writer.FinishResult::err(error) => { return; } } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/finish_no_eof_probe.aji b/tests/conformance/source/buffered_io/finish_no_eof_probe.aji new file mode 100644 index 0000000..aaa730c --- /dev/null +++ b/tests/conformance/source/buffered_io/finish_no_eof_probe.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var prefix: [u8;3] = [0u8;3]; + { mut q = value; exact(std.io.reader.read_exact(q,mut prefix)); } + let file = finished_reader(move value); exact(std.io.read_exact_file(mut file,mut prefix)); assert(prefix[0] == 100u8); assert(prefix[2] == 102u8); fs.close(move file) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/lazy_flush.aji b/tests/conformance/source/buffered_io/lazy_flush.aji new file mode 100644 index 0000000..980f3dc --- /dev/null +++ b/tests/conformance/source/buffered_io/lazy_flush.aji @@ -0,0 +1,39 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: dst=fs.write:/out +// grant: heap=mem.alloc:3 +// grant: src=fs.read:/out +// file: /out/data=abcd +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn observed(src: cap,expected: usize) -> void effects [fs.read] { + let file = fs.open_read(src,b"/out/data") or trap; var bytes: [u8;6] = [0u8;6]; match std.io.read_to_end_file(mut file,mut bytes) { std.io.ReadToEndResult::eof(n) => { assert(n == expected); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } fs.close(move file) or trap; +} +fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc] { + let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); let blank: [u8;1] = [0u8;1]; + { mut q = value; written(std.io.writer.write(q,b"abc")); written(std.io.writer.write(q,ref blank[0usize..0usize])); } observed(src,0usize); + { mut q = value; written(std.io.writer.write(q,b"d")); } observed(src,3usize); + { mut q = value; match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } } observed(src,4usize); + fs.close(finished_writer(move value)) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/loan.aji b/tests/conformance/source/buffered_io/loan.aji new file mode 100644 index 0000000..0b47da5 --- /dev/null +++ b/tests/conformance/source/buffered_io/loan.aji @@ -0,0 +1,27 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn worker(q: mut) -> void effects [fs.read] {} +fn bad(q: mut) -> void effects [fs.read,task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,q); var bytes: [u8;1] = [0u8;1]; std.io.reader.read(q,mut bytes); task.join(move t); } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/loan_join.aji b/tests/conformance/source/buffered_io/loan_join.aji new file mode 100644 index 0000000..3cb6b55 --- /dev/null +++ b/tests/conformance/source/buffered_io/loan_join.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +// schedules: 12 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn worker(q: mut) -> void effects [fs.read] { var bytes: [u8;3] = [0u8;3]; exact(std.io.reader.read_exact(q,mut bytes)); assert(bytes[0] == 97u8); } +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc,task.spawn,task.wait] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var bytes: [u8;3] = [0u8;3]; + { mut q = value; scope s { let t = task.spawn(s,worker,q); task.join(move t); exact(std.io.reader.read_exact(q,mut bytes)); } } + assert(bytes[0] == 100u8); fs.close(finished_reader(move value)) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/maximum_capacity.aji b/tests/conformance/source/buffered_io/maximum_capacity.aji new file mode 100644 index 0000000..f2c2243 --- /dev/null +++ b/tests/conformance/source/buffered_io/maximum_capacity.aji @@ -0,0 +1,36 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +// grant: dst=fs.write:/out +// file: /out/data= +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc] { + let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; + match std.io.reader.new(move input,18446744073709551615usize,heap) { std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.close(move file) or trap; } } + match std.io.writer.new(move output,18446744073709551615usize,heap) { std.io.writer.NewResult::ok(value) => { trap; }, std.io.writer.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.close(move file) or trap; } } + return 42; +} diff --git a/tests/conformance/source/buffered_io/missing_alloc_effect.aji b/tests/conformance/source/buffered_io/missing_alloc_effect.aji new file mode 100644 index 0000000..7581b04 --- /dev/null +++ b/tests/conformance/source/buffered_io/missing_alloc_effect.aji @@ -0,0 +1,26 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(file: file,heap: cap) -> std.io.reader.NewResult effects [] { return std.io.reader.new(move file,3usize,heap); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/missing_move.aji b/tests/conformance/source/buffered_io/missing_move.aji new file mode 100644 index 0000000..9cd320e --- /dev/null +++ b/tests/conformance/source/buffered_io/missing_move.aji @@ -0,0 +1,26 @@ +// expect: reject E7003 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: std.io.reader.Reader) -> void effects [] { std.io.reader.finish(q); trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/missing_read_effect.aji b/tests/conformance/source/buffered_io/missing_read_effect.aji new file mode 100644 index 0000000..cf84909 --- /dev/null +++ b/tests/conformance/source/buffered_io/missing_read_effect.aji @@ -0,0 +1,26 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: mut,dest: slice_mut) -> void effects [] { std.io.reader.read(q,dest); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/missing_write_effect.aji b/tests/conformance/source/buffered_io/missing_write_effect.aji new file mode 100644 index 0000000..b1bd0a0 --- /dev/null +++ b/tests/conformance/source/buffered_io/missing_write_effect.aji @@ -0,0 +1,26 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: mut) -> void effects [] { std.io.writer.flush(q); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/model.aji b/tests/conformance/source/buffered_io/model.aji new file mode 100644 index 0000000..f34880c --- /dev/null +++ b/tests/conformance/source/buffered_io/model.aji @@ -0,0 +1,284 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/case +// grant: dst=fs.write:/case +// grant: heap=mem.alloc:5 +// file: /case/input=abcdefgh +// file: /case/output=abcdefgh +// fuel: 2000000 +module test.buffered_model +import std.io; +import std.io.reader; +import std.io.writer; +import std.bytes; +fn prepare(contents: slice,dst: cap) -> void effects [fs.write] { + let file = fs.create(dst,b"/case/input") or trap; fs.write_all(file,contents) or trap; fs.close(move file) or trap; +} +fn reads(contents: slice,capacity: usize,chunk: usize,src: cap,dst: cap,heap: cap) -> void effects [fs.read,fs.write,mem.alloc] { + prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap; + match std.io.reader.new(move file,capacity,heap) { + std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => { + var bytes: [u8;9] = [255u8;9]; var offset: usize = 0; + { mut q = value; loop { + match std.io.reader.read(q,mut bytes[1usize..chunk+1usize]) { + std.io.reader.ReadResult::err(error) => { trap; }, std.io.reader.ReadResult::ok(count) => { + assert(count <= chunk); assert(offset + count <= contents.len); + assert(std.bytes.equal(ref bytes[1usize..count+1usize],ref contents[offset..offset+count])); + assert(bytes[0] == 255u8); for i in chunk+1usize..9usize { assert(bytes[i] == 255u8); } + offset = offset + count; if count == 0usize { break; } + } + } + } } + assert(offset == contents.len); + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.reader.FinishResult::unread(value) => { trap; } } + } + } +} +fn exact(contents: slice,capacity: usize,requested: usize,prefix: usize,full: bool,src: cap,dst: cap,heap: cap) -> void effects [fs.read,fs.write,mem.alloc] { + prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap; + match std.io.reader.new(move file,capacity,heap) { + std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => { + var bytes: [u8;12] = [255u8;12]; + { mut q = value; match std.io.reader.read_exact(q,mut bytes[1usize..requested+1usize]) { + std.io.ReadExactResult::ok => { assert(full); }, std.io.ReadExactResult::eof(n) => { assert(not full); assert(n == prefix); }, std.io.ReadExactResult::err(error) => { trap; } + } } + assert(std.bytes.equal(ref bytes[1usize..prefix+1usize],ref contents[0usize..prefix])); + assert(bytes[0] == 255u8); for i in prefix+1usize..12usize { assert(bytes[i] == 255u8); } + let (file,unread) = struct.unpack(std.io.reader.discard(move value)); fs.close(move file) or trap; + } + } +} +fn writes(contents: slice,capacity: usize,chunk: usize,flush: bool,src: cap,dst: cap,heap: cap) -> void effects [fs.read,fs.write,mem.alloc] { + let file = fs.create(dst,b"/case/output") or trap; + match std.io.writer.new(move file,capacity,heap) { + std.io.writer.NewResult::err(error) => { trap; }, std.io.writer.NewResult::ok(value) => { + var offset: usize = 0; + { mut q = value; match std.io.writer.write(q,ref contents[0usize..0usize]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } + while offset < contents.len { + let left = contents.len - offset; let count = if left < chunk { left } else { chunk }; + match std.io.writer.write(q,ref contents[offset..offset+count]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } + offset = offset + count; + if flush { match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } } + } + } + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.writer.FinishResult::err(error) => { trap; } } + } + } + let file = fs.open_read(src,b"/case/output") or trap; var bytes: [u8;12] = [255u8;12]; + match std.io.read_to_end_file(mut file,mut bytes[1usize..11usize]) { std.io.ReadToEndResult::eof(n) => { assert(n == contents.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],contents)); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + assert(bytes[0] == 255u8); assert(bytes[11] == 255u8); fs.close(move file) or trap; +} +fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc] { +let blank: [u8;1] = [0u8;1]; +reads(ref blank[0usize..0usize],0usize,1usize,src,dst,heap); +writes(ref blank[0usize..0usize],0usize,1usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],0usize,1usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],0usize,3usize,src,dst,heap); +writes(ref blank[0usize..0usize],0usize,3usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],0usize,3usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],0usize,7usize,src,dst,heap); +writes(ref blank[0usize..0usize],0usize,7usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],0usize,7usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],0usize,0usize,0usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],0usize,1usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],0usize,4usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],0usize,9usize,0usize,false,src,dst,heap); +reads(ref blank[0usize..0usize],1usize,1usize,src,dst,heap); +writes(ref blank[0usize..0usize],1usize,1usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],1usize,1usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],1usize,3usize,src,dst,heap); +writes(ref blank[0usize..0usize],1usize,3usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],1usize,3usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],1usize,7usize,src,dst,heap); +writes(ref blank[0usize..0usize],1usize,7usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],1usize,7usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],1usize,0usize,0usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],1usize,1usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],1usize,4usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],1usize,9usize,0usize,false,src,dst,heap); +reads(ref blank[0usize..0usize],2usize,1usize,src,dst,heap); +writes(ref blank[0usize..0usize],2usize,1usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],2usize,1usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],2usize,3usize,src,dst,heap); +writes(ref blank[0usize..0usize],2usize,3usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],2usize,3usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],2usize,7usize,src,dst,heap); +writes(ref blank[0usize..0usize],2usize,7usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],2usize,7usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],2usize,0usize,0usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],2usize,1usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],2usize,4usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],2usize,9usize,0usize,false,src,dst,heap); +reads(ref blank[0usize..0usize],5usize,1usize,src,dst,heap); +writes(ref blank[0usize..0usize],5usize,1usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],5usize,1usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],5usize,3usize,src,dst,heap); +writes(ref blank[0usize..0usize],5usize,3usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],5usize,3usize,true,src,dst,heap); +reads(ref blank[0usize..0usize],5usize,7usize,src,dst,heap); +writes(ref blank[0usize..0usize],5usize,7usize,false,src,dst,heap); +writes(ref blank[0usize..0usize],5usize,7usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],5usize,0usize,0usize,true,src,dst,heap); +exact(ref blank[0usize..0usize],5usize,1usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],5usize,4usize,0usize,false,src,dst,heap); +exact(ref blank[0usize..0usize],5usize,9usize,0usize,false,src,dst,heap); +reads(b"a",0usize,1usize,src,dst,heap); +writes(b"a",0usize,1usize,false,src,dst,heap); +writes(b"a",0usize,1usize,true,src,dst,heap); +reads(b"a",0usize,3usize,src,dst,heap); +writes(b"a",0usize,3usize,false,src,dst,heap); +writes(b"a",0usize,3usize,true,src,dst,heap); +reads(b"a",0usize,7usize,src,dst,heap); +writes(b"a",0usize,7usize,false,src,dst,heap); +writes(b"a",0usize,7usize,true,src,dst,heap); +exact(b"a",0usize,0usize,0usize,true,src,dst,heap); +exact(b"a",0usize,1usize,1usize,true,src,dst,heap); +exact(b"a",0usize,4usize,1usize,false,src,dst,heap); +exact(b"a",0usize,9usize,1usize,false,src,dst,heap); +reads(b"a",1usize,1usize,src,dst,heap); +writes(b"a",1usize,1usize,false,src,dst,heap); +writes(b"a",1usize,1usize,true,src,dst,heap); +reads(b"a",1usize,3usize,src,dst,heap); +writes(b"a",1usize,3usize,false,src,dst,heap); +writes(b"a",1usize,3usize,true,src,dst,heap); +reads(b"a",1usize,7usize,src,dst,heap); +writes(b"a",1usize,7usize,false,src,dst,heap); +writes(b"a",1usize,7usize,true,src,dst,heap); +exact(b"a",1usize,0usize,0usize,true,src,dst,heap); +exact(b"a",1usize,1usize,1usize,true,src,dst,heap); +exact(b"a",1usize,4usize,1usize,false,src,dst,heap); +exact(b"a",1usize,9usize,1usize,false,src,dst,heap); +reads(b"a",2usize,1usize,src,dst,heap); +writes(b"a",2usize,1usize,false,src,dst,heap); +writes(b"a",2usize,1usize,true,src,dst,heap); +reads(b"a",2usize,3usize,src,dst,heap); +writes(b"a",2usize,3usize,false,src,dst,heap); +writes(b"a",2usize,3usize,true,src,dst,heap); +reads(b"a",2usize,7usize,src,dst,heap); +writes(b"a",2usize,7usize,false,src,dst,heap); +writes(b"a",2usize,7usize,true,src,dst,heap); +exact(b"a",2usize,0usize,0usize,true,src,dst,heap); +exact(b"a",2usize,1usize,1usize,true,src,dst,heap); +exact(b"a",2usize,4usize,1usize,false,src,dst,heap); +exact(b"a",2usize,9usize,1usize,false,src,dst,heap); +reads(b"a",5usize,1usize,src,dst,heap); +writes(b"a",5usize,1usize,false,src,dst,heap); +writes(b"a",5usize,1usize,true,src,dst,heap); +reads(b"a",5usize,3usize,src,dst,heap); +writes(b"a",5usize,3usize,false,src,dst,heap); +writes(b"a",5usize,3usize,true,src,dst,heap); +reads(b"a",5usize,7usize,src,dst,heap); +writes(b"a",5usize,7usize,false,src,dst,heap); +writes(b"a",5usize,7usize,true,src,dst,heap); +exact(b"a",5usize,0usize,0usize,true,src,dst,heap); +exact(b"a",5usize,1usize,1usize,true,src,dst,heap); +exact(b"a",5usize,4usize,1usize,false,src,dst,heap); +exact(b"a",5usize,9usize,1usize,false,src,dst,heap); +reads(b"abc",0usize,1usize,src,dst,heap); +writes(b"abc",0usize,1usize,false,src,dst,heap); +writes(b"abc",0usize,1usize,true,src,dst,heap); +reads(b"abc",0usize,3usize,src,dst,heap); +writes(b"abc",0usize,3usize,false,src,dst,heap); +writes(b"abc",0usize,3usize,true,src,dst,heap); +reads(b"abc",0usize,7usize,src,dst,heap); +writes(b"abc",0usize,7usize,false,src,dst,heap); +writes(b"abc",0usize,7usize,true,src,dst,heap); +exact(b"abc",0usize,0usize,0usize,true,src,dst,heap); +exact(b"abc",0usize,1usize,1usize,true,src,dst,heap); +exact(b"abc",0usize,4usize,3usize,false,src,dst,heap); +exact(b"abc",0usize,9usize,3usize,false,src,dst,heap); +reads(b"abc",1usize,1usize,src,dst,heap); +writes(b"abc",1usize,1usize,false,src,dst,heap); +writes(b"abc",1usize,1usize,true,src,dst,heap); +reads(b"abc",1usize,3usize,src,dst,heap); +writes(b"abc",1usize,3usize,false,src,dst,heap); +writes(b"abc",1usize,3usize,true,src,dst,heap); +reads(b"abc",1usize,7usize,src,dst,heap); +writes(b"abc",1usize,7usize,false,src,dst,heap); +writes(b"abc",1usize,7usize,true,src,dst,heap); +exact(b"abc",1usize,0usize,0usize,true,src,dst,heap); +exact(b"abc",1usize,1usize,1usize,true,src,dst,heap); +exact(b"abc",1usize,4usize,3usize,false,src,dst,heap); +exact(b"abc",1usize,9usize,3usize,false,src,dst,heap); +reads(b"abc",2usize,1usize,src,dst,heap); +writes(b"abc",2usize,1usize,false,src,dst,heap); +writes(b"abc",2usize,1usize,true,src,dst,heap); +reads(b"abc",2usize,3usize,src,dst,heap); +writes(b"abc",2usize,3usize,false,src,dst,heap); +writes(b"abc",2usize,3usize,true,src,dst,heap); +reads(b"abc",2usize,7usize,src,dst,heap); +writes(b"abc",2usize,7usize,false,src,dst,heap); +writes(b"abc",2usize,7usize,true,src,dst,heap); +exact(b"abc",2usize,0usize,0usize,true,src,dst,heap); +exact(b"abc",2usize,1usize,1usize,true,src,dst,heap); +exact(b"abc",2usize,4usize,3usize,false,src,dst,heap); +exact(b"abc",2usize,9usize,3usize,false,src,dst,heap); +reads(b"abc",5usize,1usize,src,dst,heap); +writes(b"abc",5usize,1usize,false,src,dst,heap); +writes(b"abc",5usize,1usize,true,src,dst,heap); +reads(b"abc",5usize,3usize,src,dst,heap); +writes(b"abc",5usize,3usize,false,src,dst,heap); +writes(b"abc",5usize,3usize,true,src,dst,heap); +reads(b"abc",5usize,7usize,src,dst,heap); +writes(b"abc",5usize,7usize,false,src,dst,heap); +writes(b"abc",5usize,7usize,true,src,dst,heap); +exact(b"abc",5usize,0usize,0usize,true,src,dst,heap); +exact(b"abc",5usize,1usize,1usize,true,src,dst,heap); +exact(b"abc",5usize,4usize,3usize,false,src,dst,heap); +exact(b"abc",5usize,9usize,3usize,false,src,dst,heap); +reads(b"abcdefgh",0usize,1usize,src,dst,heap); +writes(b"abcdefgh",0usize,1usize,false,src,dst,heap); +writes(b"abcdefgh",0usize,1usize,true,src,dst,heap); +reads(b"abcdefgh",0usize,3usize,src,dst,heap); +writes(b"abcdefgh",0usize,3usize,false,src,dst,heap); +writes(b"abcdefgh",0usize,3usize,true,src,dst,heap); +reads(b"abcdefgh",0usize,7usize,src,dst,heap); +writes(b"abcdefgh",0usize,7usize,false,src,dst,heap); +writes(b"abcdefgh",0usize,7usize,true,src,dst,heap); +exact(b"abcdefgh",0usize,0usize,0usize,true,src,dst,heap); +exact(b"abcdefgh",0usize,1usize,1usize,true,src,dst,heap); +exact(b"abcdefgh",0usize,4usize,4usize,true,src,dst,heap); +exact(b"abcdefgh",0usize,9usize,8usize,false,src,dst,heap); +reads(b"abcdefgh",1usize,1usize,src,dst,heap); +writes(b"abcdefgh",1usize,1usize,false,src,dst,heap); +writes(b"abcdefgh",1usize,1usize,true,src,dst,heap); +reads(b"abcdefgh",1usize,3usize,src,dst,heap); +writes(b"abcdefgh",1usize,3usize,false,src,dst,heap); +writes(b"abcdefgh",1usize,3usize,true,src,dst,heap); +reads(b"abcdefgh",1usize,7usize,src,dst,heap); +writes(b"abcdefgh",1usize,7usize,false,src,dst,heap); +writes(b"abcdefgh",1usize,7usize,true,src,dst,heap); +exact(b"abcdefgh",1usize,0usize,0usize,true,src,dst,heap); +exact(b"abcdefgh",1usize,1usize,1usize,true,src,dst,heap); +exact(b"abcdefgh",1usize,4usize,4usize,true,src,dst,heap); +exact(b"abcdefgh",1usize,9usize,8usize,false,src,dst,heap); +reads(b"abcdefgh",2usize,1usize,src,dst,heap); +writes(b"abcdefgh",2usize,1usize,false,src,dst,heap); +writes(b"abcdefgh",2usize,1usize,true,src,dst,heap); +reads(b"abcdefgh",2usize,3usize,src,dst,heap); +writes(b"abcdefgh",2usize,3usize,false,src,dst,heap); +writes(b"abcdefgh",2usize,3usize,true,src,dst,heap); +reads(b"abcdefgh",2usize,7usize,src,dst,heap); +writes(b"abcdefgh",2usize,7usize,false,src,dst,heap); +writes(b"abcdefgh",2usize,7usize,true,src,dst,heap); +exact(b"abcdefgh",2usize,0usize,0usize,true,src,dst,heap); +exact(b"abcdefgh",2usize,1usize,1usize,true,src,dst,heap); +exact(b"abcdefgh",2usize,4usize,4usize,true,src,dst,heap); +exact(b"abcdefgh",2usize,9usize,8usize,false,src,dst,heap); +reads(b"abcdefgh",5usize,1usize,src,dst,heap); +writes(b"abcdefgh",5usize,1usize,false,src,dst,heap); +writes(b"abcdefgh",5usize,1usize,true,src,dst,heap); +reads(b"abcdefgh",5usize,3usize,src,dst,heap); +writes(b"abcdefgh",5usize,3usize,false,src,dst,heap); +writes(b"abcdefgh",5usize,3usize,true,src,dst,heap); +reads(b"abcdefgh",5usize,7usize,src,dst,heap); +writes(b"abcdefgh",5usize,7usize,false,src,dst,heap); +writes(b"abcdefgh",5usize,7usize,true,src,dst,heap); +exact(b"abcdefgh",5usize,0usize,0usize,true,src,dst,heap); +exact(b"abcdefgh",5usize,1usize,1usize,true,src,dst,heap); +exact(b"abcdefgh",5usize,4usize,4usize,true,src,dst,heap); +exact(b"abcdefgh",5usize,9usize,8usize,false,src,dst,heap); +return 42; +} diff --git a/tests/conformance/source/buffered_io/new_error_leak.aji b/tests/conformance/source/buffered_io/new_error_leak.aji new file mode 100644 index 0000000..8b068ab --- /dev/null +++ b/tests/conformance/source/buffered_io/new_error_leak.aji @@ -0,0 +1,27 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(file: file,heap: cap) -> void effects [mem.alloc] { + match std.io.reader.new(move file,1usize,heap) { std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { return; } } +} fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/not_share.aji b/tests/conformance/source/buffered_io/not_share.aji new file mode 100644 index 0000000..724fe68 --- /dev/null +++ b/tests/conformance/source/buffered_io/not_share.aji @@ -0,0 +1,27 @@ +// expect: reject E4002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn worker(q: ref) -> void effects [] {} +fn bad(q: ref) -> 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; } diff --git a/tests/conformance/source/buffered_io/owning_worker.aji b/tests/conformance/source/buffered_io/owning_worker.aji new file mode 100644 index 0000000..3fb13b4 --- /dev/null +++ b/tests/conformance/source/buffered_io/owning_worker.aji @@ -0,0 +1,37 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:6 +// vfs: /in/data=abcdef +// grant: dst=fs.write:/out +// file: /out/data=abcdef +// schedules: 12 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn work_read(value: std.io.reader.Reader) -> file effects [fs.read] { var bytes: [u8;6] = [0u8;6]; { mut q = value; exact(std.io.reader.read_exact(q,mut bytes)); } assert(bytes[0] == 97u8); assert(bytes[5] == 102u8); return finished_reader(move value); } +fn work_write(value: std.io.writer.Writer) -> file effects [fs.write] { { mut q = value; written(std.io.writer.write(q,b"abcdef")); } return finished_writer(move value); } +fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc,task.spawn,task.wait] { + let file = fs.open_read(src,b"/in/data") or trap; let a = reader(move file,3usize,heap); let file = fs.create(dst,b"/out/data") or trap; let b = writer(move file,3usize,heap); + scope s { let a = task.spawn(s,work_read,move a); let b = task.spawn(s,work_write,move b); fs.close(task.join(move a)) or trap; fs.close(task.join(move b)) or trap; } return 42; +} diff --git a/tests/conformance/source/buffered_io/reader.aji b/tests/conformance/source/buffered_io/reader.aji new file mode 100644 index 0000000..e54d5db --- /dev/null +++ b/tests/conformance/source/buffered_io/reader.aji @@ -0,0 +1,36 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var bytes: [u8;8] = [255u8;8]; + { mut q = value; exact(std.io.reader.read_exact(q,mut bytes[1usize..5usize])); + match std.io.reader.read_exact(q,mut bytes[5usize..8usize]) { std.io.ReadExactResult::eof(count) => { assert(count == 2usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } + } + assert(bytes[0] == 255u8); assert(bytes[1] == 97u8); assert(bytes[2] == 98u8); assert(bytes[3] == 99u8); assert(bytes[4] == 100u8); assert(bytes[5] == 101u8); assert(bytes[6] == 102u8); assert(bytes[7] == 255u8); + fs.close(finished_reader(move value)) or trap; let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/reader_alias.aji b/tests/conformance/source/buffered_io/reader_alias.aji new file mode 100644 index 0000000..e76041f --- /dev/null +++ b/tests/conformance/source/buffered_io/reader_alias.aji @@ -0,0 +1,26 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: mut) -> void effects [fs.read] { mut storage = q.storage; mut bytes = buffer.view(storage); std.io.reader.read(q,bytes); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/reader_discard.aji b/tests/conformance/source/buffered_io/reader_discard.aji new file mode 100644 index 0000000..0ac96bf --- /dev/null +++ b/tests/conformance/source/buffered_io/reader_discard.aji @@ -0,0 +1,34 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1]; + { mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => { assert(n == 1usize); }, std.io.reader.ReadResult::err(error) => { trap; } } } + let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 2usize); exact(std.io.read_exact_file(mut file,mut byte)); assert(byte[0] == 100u8); fs.close(move file) or trap; + let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/reader_new_failure.aji b/tests/conformance/source/buffered_io/reader_new_failure.aji new file mode 100644 index 0000000..bf2a969 --- /dev/null +++ b/tests/conformance/source/buffered_io/reader_new_failure.aji @@ -0,0 +1,37 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; + match std.io.reader.new(move file,4usize,heap) { + std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { + let (file,error) = struct.unpack(move error); var bytes: [u8;3] = [0u8;3]; exact(std.io.read_exact_file(mut file,mut bytes)); assert(bytes[0] == 97u8); fs.close(move file) or trap; + } + } + let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/reader_zero.aji b/tests/conformance/source/buffered_io/reader_zero.aji new file mode 100644 index 0000000..ed40eb5 --- /dev/null +++ b/tests/conformance/source/buffered_io/reader_zero.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:0 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,0usize,heap); var bytes: [u8;7] = [0u8;7]; + { mut q = value; match std.io.reader.read_exact(q,mut bytes) { std.io.ReadExactResult::eof(n) => { assert(n == 6usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } } + assert(bytes[0] == 97u8); assert(bytes[5] == 102u8); fs.close(finished_reader(move value)) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/refund_authority.aji b/tests/conformance/source/buffered_io/refund_authority.aji new file mode 100644 index 0000000..c122827 --- /dev/null +++ b/tests/conformance/source/buffered_io/refund_authority.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +// grant: dst=fs.write:/out +// file: /out/data= +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc] { + let narrow = cap.narrow.budget(heap,3usize) or trap; let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,narrow); fs.close(finished_reader(move value)) or trap; + let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,narrow); fs.close(finished_writer(move value)) or trap; + let allocation = own.new([0u8;3],narrow) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/unread_finish.aji b/tests/conformance/source/buffered_io/unread_finish.aji new file mode 100644 index 0000000..9fad481 --- /dev/null +++ b/tests/conformance/source/buffered_io/unread_finish.aji @@ -0,0 +1,41 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/in +// grant: heap=mem.alloc:3 +// vfs: /in/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1]; + { mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => { assert(n == 1usize); }, std.io.reader.ReadResult::err(error) => { trap; } } } + assert(byte[0] == 97u8); + match std.io.reader.finish(move value) { + std.io.reader.FinishResult::ok(file) => { trap; }, + std.io.reader.FinishResult::unread(value) => { + var tail: [u8;5] = [0u8;5]; { mut q = value; exact(std.io.reader.read_exact(q,mut tail)); } + assert(tail[0] == 98u8); assert(tail[4] == 102u8); fs.close(finished_reader(move value)) or trap; + } + } + let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/unread_leak.aji b/tests/conformance/source/buffered_io/unread_leak.aji new file mode 100644 index 0000000..f4c4d5a --- /dev/null +++ b/tests/conformance/source/buffered_io/unread_leak.aji @@ -0,0 +1,27 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(value: std.io.reader.Reader) -> void effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { trap; }, std.io.reader.FinishResult::unread(value) => { return; } } +} fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/writer.aji b/tests/conformance/source/buffered_io/writer.aji new file mode 100644 index 0000000..14db80b --- /dev/null +++ b/tests/conformance/source/buffered_io/writer.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: dst=fs.write:/out +// grant: heap=mem.alloc:3 +// file: /out/data=abcdef +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(dst: cap,heap: cap) -> u64 effects [fs.write,mem.alloc] { + let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); + { mut q = value; written(std.io.writer.write(q,b"ab")); written(std.io.writer.write(q,b"cd")); written(std.io.writer.write(q,b"ef")); } + fs.close(finished_writer(move value)) or trap; let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/writer_alias.aji b/tests/conformance/source/buffered_io/writer_alias.aji new file mode 100644 index 0000000..0d3b7d9 --- /dev/null +++ b/tests/conformance/source/buffered_io/writer_alias.aji @@ -0,0 +1,26 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(q: mut) -> void effects [fs.write] { ref storage = q.storage; ref bytes = buffer.view(storage); std.io.writer.write(q,bytes); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/writer_discard.aji b/tests/conformance/source/buffered_io/writer_discard.aji new file mode 100644 index 0000000..527448e --- /dev/null +++ b/tests/conformance/source/buffered_io/writer_discard.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: dst=fs.write:/out +// grant: heap=mem.alloc:3 +// file: /out/data=z +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(dst: cap,heap: cap) -> u64 effects [fs.write,mem.alloc] { + let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); } + let (file,pending,failed) = struct.unpack(std.io.writer.discard(move value)); assert(pending == 3usize); assert(not std.option.is_some::(failed)); fs.write_all(file,b"z") or trap; fs.close(move file) or trap; + let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/writer_new_failure.aji b/tests/conformance/source/buffered_io/writer_new_failure.aji new file mode 100644 index 0000000..14170fa --- /dev/null +++ b/tests/conformance/source/buffered_io/writer_new_failure.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: dst=fs.write:/out +// grant: heap=mem.alloc:3 +// file: /out/data=abc +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(dst: cap,heap: cap) -> u64 effects [fs.write,mem.alloc] { + let file = fs.create(dst,b"/out/data") or trap; + match std.io.writer.new(move file,4usize,heap) { + std.io.writer.NewResult::ok(value) => { trap; }, std.io.writer.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.write_all(file,b"abc") or trap; fs.close(move file) or trap; } + } + let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/buffered_io/writer_new_leak.aji b/tests/conformance/source/buffered_io/writer_new_leak.aji new file mode 100644 index 0000000..050d43f --- /dev/null +++ b/tests/conformance/source/buffered_io/writer_new_leak.aji @@ -0,0 +1,26 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(file: file,heap: cap) -> void effects [mem.alloc] { match std.io.writer.new(move file,3usize,heap) { std.io.writer.NewResult::ok(q) => { trap; }, std.io.writer.NewResult::err(error) => { return; } } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/writer_zero.aji b/tests/conformance/source/buffered_io/writer_zero.aji new file mode 100644 index 0000000..1c4c5ea --- /dev/null +++ b/tests/conformance/source/buffered_io/writer_zero.aji @@ -0,0 +1,32 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: dst=fs.write:/out +// grant: heap=mem.alloc:0 +// file: /out/data=abc +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn main(dst: cap,heap: cap) -> u64 effects [fs.write,mem.alloc] { + let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,0usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } } + fs.close(finished_writer(move value)) or trap; return 42; +} diff --git a/tests/conformance/source/buffered_io/wrong_kind.aji b/tests/conformance/source/buffered_io/wrong_kind.aji new file mode 100644 index 0000000..5e4a63e --- /dev/null +++ b/tests/conformance/source/buffered_io/wrong_kind.aji @@ -0,0 +1,26 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(file: file,heap: cap) -> void effects [mem.alloc] { std.io.reader.new(move file,3usize,heap); trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffered_io/wrong_mode.aji b/tests/conformance/source/buffered_io/wrong_mode.aji new file mode 100644 index 0000000..4e6ed2b --- /dev/null +++ b/tests/conformance/source/buffered_io/wrong_mode.aji @@ -0,0 +1,26 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +module test.buffered +import std.io; +import std.io.reader; +import std.io.writer; +import std.option; +fn reader(file: file,capacity: usize,heap: cap) -> std.io.reader.Reader effects [mem.alloc] { + match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } } +} +fn writer(file: file,capacity: usize,heap: cap) -> std.io.writer.Writer effects [mem.alloc] { + match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } } +} +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } } +fn finished_reader(value: std.io.reader.Reader) -> file effects [] { + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } } +} +fn finished_writer(value: std.io.writer.Writer) -> file effects [fs.write] { + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } } +} +fn bad(file: file,heap: cap) -> void effects [mem.alloc] { std.io.writer.new(move file,3usize,heap); trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffers/borrow_conflict.aji b/tests/conformance/source/buffers/borrow_conflict.aji new file mode 100644 index 0000000..e76a1b7 --- /dev/null +++ b/tests/conformance/source/buffers/borrow_conflict.aji @@ -0,0 +1,17 @@ +// expect: reject E2101 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new(1, heap) or trap; + { + mut b = data; + buffer.push(b, 42u64) or trap; + mut values = buffer.view(b); + buffer.reserve(b, 1, heap) or trap; + assert(values[0] == 42); + } + { mut b = data; let ignored = buffer.pop(b) or trap; } + buffer.free(move data) or trap; return 42; +} diff --git a/tests/conformance/source/buffers/borrowed_element.aji b/tests/conformance/source/buffers/borrowed_element.aji new file mode 100644 index 0000000..cf1201f --- /dev/null +++ b/tests/conformance/source/buffers/borrowed_element.aji @@ -0,0 +1,10 @@ +// expect: reject E1001 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn bad(heap: cap, value: ref) -> void effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + buffer.free(move data) or trap; +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffers/copy_move.aji b/tests/conformance/source/buffers/copy_move.aji new file mode 100644 index 0000000..03f142a --- /dev/null +++ b/tests/conformance/source/buffers/copy_move.aji @@ -0,0 +1,5 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main() -> u64 effects [] { let n = 42u64; return move n; } diff --git a/tests/conformance/source/buffers/copy_owner_view.aji b/tests/conformance/source/buffers/copy_owner_view.aji new file mode 100644 index 0000000..9baf459 --- /dev/null +++ b/tests/conformance/source/buffers/copy_owner_view.aji @@ -0,0 +1,9 @@ +// expect: reject E1001 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; let item = own.new(42u64, heap) or trap; + { mut b = data; buffer.push(b, move item) or trap; ref values = buffer.view(b); let copied = values[0]; own.free(move copied); } trap; +} diff --git a/tests/conformance/source/buffers/duplicate_owner.aji b/tests/conformance/source/buffers/duplicate_owner.aji new file mode 100644 index 0000000..bbd8d00 --- /dev/null +++ b/tests/conformance/source/buffers/duplicate_owner.aji @@ -0,0 +1,9 @@ +// expect: reject E2002 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(2, heap) or trap; let item = own.new(42u64, heap) or trap; + { mut b = data; buffer.push(b, move item) or trap; buffer.push(b, move item) or trap; } trap; +} diff --git a/tests/conformance/source/buffers/free_failure.aji b/tests/conformance/source/buffers/free_failure.aji new file mode 100644 index 0000000..27dbd72 --- /dev/null +++ b/tests/conformance/source/buffers/free_failure.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + let owner = own.new(42u64, heap) or trap; + { mut b = data; buffer.push(b, move owner) or trap; } + match buffer.free(move data) { + ok() => { trap; } + err(returned) => { + var answer: u64 = 0; + { mut b = returned; let value = buffer.pop(b) or trap; answer = own.take(move value); } + buffer.free(move returned) or trap; + return answer; + } + } +} diff --git a/tests/conformance/source/buffers/free_failure_leak.aji b/tests/conformance/source/buffers/free_failure_leak.aji new file mode 100644 index 0000000..087c16e --- /dev/null +++ b/tests/conformance/source/buffers/free_failure_leak.aji @@ -0,0 +1,9 @@ +// expect: reject E3002 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(0, heap) or trap; + match buffer.free(move data) { ok() => { return 42; } err(value) => { return 42; } } +} diff --git a/tests/conformance/source/buffers/generic_borrow_move.aji b/tests/conformance/source/buffers/generic_borrow_move.aji new file mode 100644 index 0000000..c4d6004 --- /dev/null +++ b/tests/conformance/source/buffers/generic_borrow_move.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn transfer(value: ref) -> ref from value effects [] { return move value; } +fn main() -> u64 effects [] { let n = 42u64; ref borrowed = n; ref result = transfer::(borrowed); return *result; } diff --git a/tests/conformance/source/buffers/generic_move.aji b/tests/conformance/source/buffers/generic_move.aji new file mode 100644 index 0000000..1643dfd --- /dev/null +++ b/tests/conformance/source/buffers/generic_move.aji @@ -0,0 +1,7 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn transfer(value: T) -> T effects [] { return move value; } +fn main() -> u64 effects [] { let n = 42u64; let answer = transfer::(n); assert(n == answer); return answer; } diff --git a/tests/conformance/source/buffers/generic_storage.aji b/tests/conformance/source/buffers/generic_storage.aji new file mode 100644 index 0000000..e7dd7d9 --- /dev/null +++ b/tests/conformance/source/buffers/generic_storage.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn transfer(value: T) -> T effects [] { + var stored: T = value; + { ref borrowed = stored; let copy = *borrowed; } + let transferred = move stored; + let still_available = stored; + return transferred; +} +fn main() -> u64 effects [] { return transfer::(42); } diff --git a/tests/conformance/source/buffers/long_reuse.aji b/tests/conformance/source/buffers/long_reuse.aji new file mode 100644 index 0000000..387d064 --- /dev/null +++ b/tests/conformance/source/buffers/long_reuse.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:16 +// fuel: 200000 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + for iteration in 0usize..2000usize { + let item = own.new(42u64, heap) or trap; + { mut b = data; buffer.push(b, move item) or trap; let popped = buffer.pop(b) or trap; assert(own.take(move popped) == 42u64); } + } + buffer.free(move data) or trap; + let answer = own.new(42u64, heap) or trap; + return own.take(move answer); +} diff --git a/tests/conformance/source/buffers/missing_move.aji b/tests/conformance/source/buffers/missing_move.aji new file mode 100644 index 0000000..0a23a00 --- /dev/null +++ b/tests/conformance/source/buffers/missing_move.aji @@ -0,0 +1,9 @@ +// expect: reject E7003 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; let item = own.new(42u64, heap) or trap; + { mut b = data; buffer.push(b, item) or trap; } trap; +} diff --git a/tests/conformance/source/buffers/nested.aji b/tests/conformance/source/buffers/nested.aji new file mode 100644 index 0000000..72a349e --- /dev/null +++ b/tests/conformance/source/buffers/nested.aji @@ -0,0 +1,21 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26 +module buffer.nested +fn main(heap: cap) -> u64 effects [mem.alloc] { + let inside = buffer.new>(1, heap) or trap; + let item = own.new(42u64, heap) or trap; + { mut b = inside; buffer.push(b, move item) or trap; } + let outer = buffer.new>>(1, heap) or trap; + { mut b = outer; buffer.push(b, move inside) or trap; } + var answer: u64 = 0; + { mut b = outer; + let recovered = buffer.pop(b) or trap; + { mut inner = recovered; let owner = buffer.pop(inner) or trap; answer = own.take(move owner); } + buffer.free(move recovered) or trap; + } + buffer.free(move outer) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/new_overflow.aji b/tests/conformance/source/buffers/new_overflow.aji new file mode 100644 index 0000000..503cb8e --- /dev/null +++ b/tests/conformance/source/buffers/new_overflow.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:18446744073709551615 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26 +module buffer.overflow +fn main(heap: cap) -> u64 effects [mem.alloc] { + match buffer.new(18446744073709551615usize, heap) { + ok(data) => { buffer.free(move data) or trap; trap; } + err(error) => { return 42; } + } +} diff --git a/tests/conformance/source/buffers/owner.aji b/tests/conformance/source/buffers/owner.aji new file mode 100644 index 0000000..6bba84a --- /dev/null +++ b/tests/conformance/source/buffers/owner.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + let owner = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { + mut b = data; + assert(buffer.len(b) == 0); + assert(buffer.capacity(b) == 1); + buffer.push(b, move owner) or trap; + assert(buffer.len(b) == 1); + buffer.reserve(b, 2, heap) or trap; + assert(buffer.capacity(b) == 2); + let value = buffer.pop(b) or trap; + answer = own.take(move value); + assert(buffer.len(b) == 0); + } + buffer.free(move data) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/push_failure.aji b/tests/conformance/source/buffers/push_failure.aji new file mode 100644 index 0000000..0a13424 --- /dev/null +++ b/tests/conformance/source/buffers/push_failure.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(0, heap) or trap; + let owner = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { + mut b = data; + match buffer.push(b, move owner) { ok() => { trap; } err(value) => { answer = own.take(move value); } } + } + buffer.free(move data) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/push_failure_leak.aji b/tests/conformance/source/buffers/push_failure_leak.aji new file mode 100644 index 0000000..803c547 --- /dev/null +++ b/tests/conformance/source/buffers/push_failure_leak.aji @@ -0,0 +1,9 @@ +// expect: reject E3002 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn bad(b: mut>>, owner: own) -> void effects [] { + match buffer.push(b, move owner) { ok() => { return; } err(value) => { return; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffers/readonly_push.aji b/tests/conformance/source/buffers/readonly_push.aji new file mode 100644 index 0000000..5b4faae --- /dev/null +++ b/tests/conformance/source/buffers/readonly_push.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn bad(b: ref>) -> void effects [] { buffer.push(b, 42u64) or trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffers/recursive.aji b/tests/conformance/source/buffers/recursive.aji new file mode 100644 index 0000000..fa3093a --- /dev/null +++ b/tests/conformance/source/buffers/recursive.aji @@ -0,0 +1,6 @@ +// expect: reject E1003 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +struct Node { children: buffer } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffers/reserve_authority.aji b/tests/conformance/source/buffers/reserve_authority.aji new file mode 100644 index 0000000..50fe4d8 --- /dev/null +++ b/tests/conformance/source/buffers/reserve_authority.aji @@ -0,0 +1,21 @@ +// expect: run +// result: 42 +// grant: first=mem.alloc:8 +// grant: second=mem.alloc:16 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26 +module buffer.authority +fn main(first: cap, second: cap) -> u64 effects [mem.alloc] { + let data = buffer.new(1, first) or trap; + { mut b = data; buffer.push(b, 42u64) or trap; buffer.reserve(b, 2, second) or trap; } + // Growth releases the original authority while data remains live. + let original_budget = own.new(7u64, first) or trap; + own.free(move original_budget); + var answer: u64 = 0; + { mut b = data; answer = buffer.pop(b) or trap; } + buffer.free(move data) or trap; + // Free releases the new authority, not the original one. + let replacement = buffer.new(2, second) or trap; + buffer.free(move replacement) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/reserve_failure.aji b/tests/conformance/source/buffers/reserve_failure.aji new file mode 100644 index 0000000..bf02a43 --- /dev/null +++ b/tests/conformance/source/buffers/reserve_failure.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:24 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + let owner = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { + mut b = data; + buffer.push(b, move owner) or trap; + match buffer.reserve(b, 2, heap) { ok() => { trap; } err(e) => {} } + assert(buffer.len(b) == 1); assert(buffer.capacity(b) == 1); + let value = buffer.pop(b) or trap; answer = own.take(move value); + } + buffer.free(move data) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/task_loan.aji b/tests/conformance/source/buffers/task_loan.aji new file mode 100644 index 0000000..5e85e5e --- /dev/null +++ b/tests/conformance/source/buffers/task_loan.aji @@ -0,0 +1,11 @@ +// expect: reject E4101 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn worker(b: mut>) -> void effects [] {} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let data = buffer.new(1, heap) or trap; + { mut b = data; scope s { let task = task.spawn(s, worker, b); buffer.reserve(b, 1usize, heap) or trap; task.join(move task); } } + buffer.free(move data) or trap; return 42; +} diff --git a/tests/conformance/source/buffers/task_loan_join.aji b/tests/conformance/source/buffers/task_loan_join.aji new file mode 100644 index 0000000..831dca7 --- /dev/null +++ b/tests/conformance/source/buffers/task_loan_join.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// schedules: 8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +fn worker(b: mut>) -> void effects [] { mut values = buffer.view(b); values[0] = 42; } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let data = buffer.new(1, heap) or trap; + var answer: u64 = 0; + { mut b = data; buffer.push(b, 0u64) or trap; + scope s { let task = task.spawn(s, worker, b); task.join(move task); answer = buffer.pop(b) or trap; } + } + buffer.free(move data) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/vec_copy.aji b/tests/conformance/source/buffers/vec_copy.aji new file mode 100644 index 0000000..31f4a5e --- /dev/null +++ b/tests/conformance/source/buffers/vec_copy.aji @@ -0,0 +1,31 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.10 +module test.vec +import std.vec; +import std.option; +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.vec.new::(1, heap) { + std.vec.NewResult::::ok(value) => { + { + mut v = value; + match std.vec.push::(v, 41u64) { std.vec.PushResult::::ok => {}, std.vec.PushResult::::full(item) => { trap; } } + match std.vec.reserve::(v, 2, heap) { std.vec.ReserveResult::ok => {}, std.vec.ReserveResult::err(e) => { trap; } } + match std.vec.replace::(v, 0, 42u64) { std.vec.ReplaceResult::::ok(old) => { assert(old == 41); }, std.vec.ReplaceResult::::out_of_bounds(item) => { trap; } } + } + { + ref v = value; + assert(std.vec.len::(v) == 1usize); assert(std.vec.capacity::(v) == 2usize); + match std.vec.get::(v, 0) { std.option.Option::::some(item) => { assert(item == 42); }, std.option.Option::::none => { trap; } } + match std.vec.get::(v, 1) { std.option.Option::::some(item) => { trap; }, std.option.Option::::none => {} } + } + var answer: u64 = 0; + { mut v = value; match std.vec.pop::(v) { std.option.Option::::some(item) => { answer = item; }, std.option.Option::::none => { trap; } } } + match std.vec.free::(move value) { std.vec.FreeResult::::ok => {}, std.vec.FreeResult::::not_empty(returned) => { trap; } } + return answer; + } + std.vec.NewResult::::err(e) => { trap; } + } +} diff --git a/tests/conformance/source/buffers/vec_file.aji b/tests/conformance/source/buffers/vec_file.aji new file mode 100644 index 0000000..9ed9ff8 --- /dev/null +++ b/tests/conformance/source/buffers/vec_file.aji @@ -0,0 +1,21 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// grant: dst=fs.write:/out +// file: /out/vector.txt=42 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +import std.vec; +import std.option; +fn main(heap: cap, dst: cap) -> u64 effects [mem.alloc, fs.write] { + match std.vec.new::>(1, heap) { + std.vec.NewResult::>::ok(value) => { + let file = fs.create(dst, b"/out/vector.txt") or trap; + { mut v = value; match std.vec.push::>(v, move file) { std.vec.PushResult::>::ok => {}, std.vec.PushResult::>::full(returned) => { fs.close(move returned) or trap; trap; } } } + { mut v = value; match std.vec.pop::>(v) { std.option.Option::>::some(item) => { fs.write_all(item, ref b"42") or trap; fs.close(move item) or trap; }, std.option.Option::>::none => { trap; } } } + match std.vec.free::>(move value) { std.vec.FreeResult::>::ok => {}, std.vec.FreeResult::>::not_empty(returned) => { trap; } } + return 42; + }, std.vec.NewResult::>::err(error) => { trap; } + } +} diff --git a/tests/conformance/source/buffers/vec_full.aji b/tests/conformance/source/buffers/vec_full.aji new file mode 100644 index 0000000..87fb548 --- /dev/null +++ b/tests/conformance/source/buffers/vec_full.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.10 +module test.vec +import std.vec; +import std.option; +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.vec.new::>(0, heap) { + std.vec.NewResult::>::ok(value) => { + let owner = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { mut v = value; match std.vec.push::>(v, move owner) { std.vec.PushResult::>::ok => { trap; }, std.vec.PushResult::>::full(returned) => { answer = own.take(move returned); } } } + match std.vec.free::>(move value) { std.vec.FreeResult::>::ok => {}, std.vec.FreeResult::>::not_empty(returned) => { trap; } } + return answer; + } + std.vec.NewResult::>::err(e) => { trap; } + } +} diff --git a/tests/conformance/source/buffers/vec_get_owner.aji b/tests/conformance/source/buffers/vec_get_owner.aji new file mode 100644 index 0000000..5e18c4c --- /dev/null +++ b/tests/conformance/source/buffers/vec_get_owner.aji @@ -0,0 +1,10 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.10 +module test.vec +import std.vec; +import std.option; +fn bad(value: ref>>) -> void effects [] { + let result = std.vec.get::>(value, 0); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/buffers/vec_owner.aji b/tests/conformance/source/buffers/vec_owner.aji new file mode 100644 index 0000000..1b073bb --- /dev/null +++ b/tests/conformance/source/buffers/vec_owner.aji @@ -0,0 +1,24 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.10 +module test.vec +import std.vec; +import std.option; +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.vec.new::>(1, heap) { + std.vec.NewResult::>::ok(value) => { + let owner = own.new(42u64, heap) or trap; + { + mut v = value; + match std.vec.push::>(v, move owner) { std.vec.PushResult::>::ok => {}, std.vec.PushResult::>::full(returned) => { own.free(move returned); trap; } } + } + var answer: u64 = 0; + { mut v = value; match std.vec.pop::>(v) { std.option.Option::>::some(item) => { answer = own.take(move item); }, std.option.Option::>::none => { trap; } } } + match std.vec.free::>(move value) { std.vec.FreeResult::>::ok => {}, std.vec.FreeResult::>::not_empty(returned) => { trap; } } + return answer; + } + std.vec.NewResult::>::err(e) => { trap; } + } +} diff --git a/tests/conformance/source/buffers/vec_replace_owner.aji b/tests/conformance/source/buffers/vec_replace_owner.aji new file mode 100644 index 0000000..a060948 --- /dev/null +++ b/tests/conformance/source/buffers/vec_replace_owner.aji @@ -0,0 +1,29 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +import std.vec; +import std.option; +fn drain(value: std.vec.Vec>) -> u64 effects [] { + var answer: u64 = 0; + { mut v = value; match std.vec.pop::>(v) { std.option.Option::>::some(item) => { answer = own.take(move item); }, std.option.Option::>::none => { trap; } } } + match std.vec.free::>(move value) { std.vec.FreeResult::>::ok => {}, std.vec.FreeResult::>::not_empty(returned) => { trap; } } + return answer; +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.vec.new::>(1, heap) { + std.vec.NewResult::>::ok(value) => { + let original = own.new(7u64, heap) or trap; + { mut v = value; + match std.vec.push::>(v, move original) { std.vec.PushResult::>::ok => {}, std.vec.PushResult::>::full(returned) => { trap; } } + let replacement = own.new(42u64, heap) or trap; + match std.vec.replace::>(v, 0, move replacement) { std.vec.ReplaceResult::>::ok(old) => { assert(own.take(move old) == 7u64); }, std.vec.ReplaceResult::>::out_of_bounds(returned) => { trap; } } + let outside = own.new(99u64, heap) or trap; + match std.vec.replace::>(v, 1, move outside) { std.vec.ReplaceResult::>::ok(old) => { trap; }, std.vec.ReplaceResult::>::out_of_bounds(returned) => { assert(own.take(move returned) == 99u64); } } + } + match std.vec.free::>(move value) { std.vec.FreeResult::>::ok => { trap; }, std.vec.FreeResult::>::not_empty(returned) => { return drain(move returned); } } + }, std.vec.NewResult::>::err(error) => { trap; } + } +} diff --git a/tests/conformance/source/buffers/vec_sender.aji b/tests/conformance/source/buffers/vec_sender.aji new file mode 100644 index 0000000..ca830ef --- /dev/null +++ b/tests/conformance/source/buffers/vec_sender.aji @@ -0,0 +1,26 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// schedules: 8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffer +import std.vec; +import std.option; +struct Job { number: u64 } +fn worker(value: std.vec.Vec>) -> void effects [task.wait] { + { mut v = value; match std.vec.pop::>(v) { std.option.Option::>::some(tx) => { channel.send(tx, Job { number: 42 }) or trap; channel.close_sender(move tx); }, std.option.Option::>::none => { trap; } } } + match std.vec.free::>(move value) { std.vec.FreeResult::>::ok => {}, std.vec.FreeResult::>::not_empty(returned) => { trap; } } +} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + match channel.make(1, heap) { + ok(tx, rx) => { + match std.vec.new::>(1, heap) { + std.vec.NewResult::>::ok(value) => { + { mut v = value; match std.vec.push::>(v, move tx) { std.vec.PushResult::>::ok => {}, std.vec.PushResult::>::full(returned) => { channel.close_sender(move returned); trap; } } } + scope s { let task = task.spawn(s, worker, move value); let job = channel.recv(rx) or trap; task.join(move task); channel.close_receiver(move rx) or trap; return job.number; } + }, std.vec.NewResult::>::err(error) => { trap; } + } + }, err(error) => { trap; } + } +} diff --git a/tests/conformance/source/buffers/view.aji b/tests/conformance/source/buffers/view.aji new file mode 100644 index 0000000..3a76737 --- /dev/null +++ b/tests/conformance/source/buffers/view.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new(2, heap) or trap; + { + mut b = data; + buffer.push(b, 41u64) or trap; + { mut values = buffer.view(b); assert(values.len == 1usize); values[0] = values[0] + 1; } + { ref values = buffer.view(b); assert(values[0] == 42); } + } + var answer: u64 = 0; + { mut b = data; answer = buffer.pop(b) or trap; } + buffer.free(move data) or trap; + return answer; +} diff --git a/tests/conformance/source/buffers/zero.aji b/tests/conformance/source/buffers/zero.aji new file mode 100644 index 0000000..26c51a8 --- /dev/null +++ b/tests/conformance/source/buffers/zero.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:0 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/15-source-language.md §17 +module test.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new(0, heap) or trap; + { + mut b = data; + match buffer.pop(b) { ok(v) => { trap; } err() => {} } + match buffer.push(b, 42u64) { ok() => { trap; } err(v) => { assert(v == 42); } } + assert(buffer.len(b) == 0); + } + buffer.free(move data) or trap; + return 42; +} diff --git a/tests/conformance/source/deque/alias.aji b/tests/conformance/source/deque/alias.aji new file mode 100644 index 0000000..fe89ca5 --- /dev/null +++ b/tests/conformance/source/deque/alias.aji @@ -0,0 +1,41 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn bad(q: mut>) -> void effects [] { + ref observed = q; + pushed::(std.deque.push_back::(q, 42u64)); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/allocation_tag.aji b/tests/conformance/source/deque/allocation_tag.aji new file mode 100644 index 0000000..11f8310 --- /dev/null +++ b/tests/conformance/source/deque/allocation_tag.aji @@ -0,0 +1,45 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + // An own slot charges 9 bytes, including Option's tag, rather than 8. + match std.deque.new::>(1, heap) { + std.deque.NewResult::>::ok(value) => { released::>(move value); trap; } + std.deque.NewResult::>::err(error) => { return 42; } + } +} diff --git a/tests/conformance/source/deque/copy.aji b/tests/conformance/source/deque/copy.aji new file mode 100644 index 0000000..9934b37 --- /dev/null +++ b/tests/conformance/source/deque/copy.aji @@ -0,0 +1,57 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:1024 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(3, heap); + { mut q = value; + pushed::(std.deque.push_back::(q, 2u64)); + pushed::(std.deque.push_front::(q, 1u64)); + pushed::(std.deque.push_back::(q, 3u64)); + assert(front::(q) == 1u64); + assert(back::(q) == 3u64); + match std.deque.replace::(q, 0, 42u64) { std.deque.ReplaceResult::::ok(old) => { assert(old == 2u64); }, std.deque.ReplaceResult::::out_of_bounds(item) => { trap; } } + } + { ref q = value; + assert(std.deque.len::(q) == 1usize); assert(std.deque.capacity::(q) == 3usize); + match std.deque.get::(q, 0) { std.option.Option::::some(item) => { assert(item == 42u64); }, std.option.Option::::none => { trap; } } + match std.deque.get::(q, 1) { std.option.Option::::some(item) => { trap; }, std.option.Option::::none => {} } + } + var answer: u64 = 0; + { mut q = value; answer = front::(q); } + released::(move value); return answer; +} diff --git a/tests/conformance/source/deque/double_move.aji b/tests/conformance/source/deque/double_move.aji new file mode 100644 index 0000000..090050e --- /dev/null +++ b/tests/conformance/source/deque/double_move.aji @@ -0,0 +1,41 @@ +// expect: reject E2002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn bad(q: mut>>, item: own) -> void effects [] { + pushed::>(std.deque.push_back::>(q, move item)); + pushed::>(std.deque.push_front::>(q, move item)); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/empty.aji b/tests/conformance/source/deque/empty.aji new file mode 100644 index 0000000..f77e7f9 --- /dev/null +++ b/tests/conformance/source/deque/empty.aji @@ -0,0 +1,46 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(0, heap); + { mut q = value; + match std.deque.reserve::(q, 0, heap) { std.deque.ReserveResult::ok => {}, std.deque.ReserveResult::err(error) => { trap; } } + match std.deque.push_back::(q, 42u64) { std.deque.PushResult::::ok => { trap; }, std.deque.PushResult::::full(item) => { assert(item == 42u64); } } + } + released::(move value); return 42; +} diff --git a/tests/conformance/source/deque/file.aji b/tests/conformance/source/deque/file.aji new file mode 100644 index 0000000..fb3e138 --- /dev/null +++ b/tests/conformance/source/deque/file.aji @@ -0,0 +1,21 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// grant: dst=fs.write:/out +// file: /out/deque.txt=42 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn main(heap: cap, dst: cap) -> u64 effects [mem.alloc, fs.write] { + match std.deque.new::>(1, heap) { + std.deque.NewResult::>::ok(value) => { + let file = fs.create(dst, b"/out/deque.txt") or trap; + { mut v = value; match std.deque.push_back::>(v, move file) { std.deque.PushResult::>::ok => {}, std.deque.PushResult::>::full(returned) => { fs.close(move returned) or trap; trap; } } } + { mut v = value; match std.deque.pop_front::>(v) { std.option.Option::>::some(item) => { fs.write_all(item, ref b"42") or trap; fs.close(move item) or trap; }, std.option.Option::>::none => { trap; } } } + match std.deque.free::>(move value) { std.deque.FreeResult::>::ok => {}, std.deque.FreeResult::>::not_empty(returned) => { trap; } } + return 42; + }, std.deque.NewResult::>::err(error) => { trap; } + } +} diff --git a/tests/conformance/source/deque/free_leak.aji b/tests/conformance/source/deque/free_leak.aji new file mode 100644 index 0000000..9d1c8bd --- /dev/null +++ b/tests/conformance/source/deque/free_leak.aji @@ -0,0 +1,40 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn bad(value: std.deque.Deque>) -> void effects [] { + match std.deque.free::>(move value) { std.deque.FreeResult::>::ok => { return; }, std.deque.FreeResult::>::not_empty(returned) => { return; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/full.aji b/tests/conformance/source/deque/full.aji new file mode 100644 index 0000000..103c81c --- /dev/null +++ b/tests/conformance/source/deque/full.aji @@ -0,0 +1,48 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:1024 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(1, heap); + let a = own.new(7u64, heap) or trap; let b = own.new(42u64, heap) or trap; + { mut q = value; + pushed::>(std.deque.push_back::>(q, move a)); + match std.deque.push_back::>(q, move b) { std.deque.PushResult::>::ok => { trap; }, std.deque.PushResult::>::full(returned) => { assert(own.take(move returned) == 42u64); } } + let a = front::>(q); assert(own.take(move a) == 7u64); + } + released::>(move value); return 42; +} diff --git a/tests/conformance/source/deque/full_leak.aji b/tests/conformance/source/deque/full_leak.aji new file mode 100644 index 0000000..ee8774b --- /dev/null +++ b/tests/conformance/source/deque/full_leak.aji @@ -0,0 +1,40 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn bad(q: mut>>, item: own) -> void effects [] { + match std.deque.push_front::>(q, move item) { std.deque.PushResult::>::ok => { return; }, std.deque.PushResult::>::full(returned) => { return; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/get_owner.aji b/tests/conformance/source/deque/get_owner.aji new file mode 100644 index 0000000..3b3bb93 --- /dev/null +++ b/tests/conformance/source/deque/get_owner.aji @@ -0,0 +1,38 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn bad(value: ref>>) -> void effects [] { let item = std.deque.get::>(value, 0); trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/growth_matrix.aji b/tests/conformance/source/deque/growth_matrix.aji new file mode 100644 index 0000000..a2584d2 --- /dev/null +++ b/tests/conformance/source/deque/growth_matrix.aji @@ -0,0 +1,71 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn scenario(heap: cap, size: usize, shift: usize, length: usize) -> void effects [mem.alloc] { + let value = opened::(size, heap); + { mut q = value; + for i in 0usize..size { pushed::(std.deque.push_back::(q, i as! u64)); } + for i in 0usize..shift { assert(front::(q) == i as! u64); } + for i in 0usize..shift { pushed::(std.deque.push_back::(q, (size + i) as! u64)); } + for i in 0usize..size - length { assert(back::(q) == (shift + size - 1 - i) as! u64); } + let original_head = q.head; + match std.deque.reserve::(q, size, heap) { std.deque.ReserveResult::ok => {}, std.deque.ReserveResult::err(error) => { trap; } } + assert(q.head == original_head); + match std.deque.reserve::(q, size * 2 + 1, heap) { std.deque.ReserveResult::ok => {}, std.deque.ReserveResult::err(error) => { trap; } } + assert(q.head == 0usize); + } + { ref q = value; + assert(std.deque.len::(q) == length); + assert(std.deque.capacity::(q) == size * 2 + 1); + for i in 0usize..length { + match std.deque.get::(q, i) { std.option.Option::::some(item) => { assert(item == (shift + i) as! u64); }, std.option.Option::::none => { trap; } } + } + } + { mut q = value; for i in 0usize..length { assert(front::(q) == (shift + i) as! u64); } } + released::(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + scenario(heap, 0, 0, 0); + for size in 1usize..6usize { + for shift in 0usize..size { + for length in 0usize..size + 1 { scenario(heap, size, shift, length); } + } + } + return 42; +} diff --git a/tests/conformance/source/deque/invalid_empty.aji b/tests/conformance/source/deque/invalid_empty.aji new file mode 100644 index 0000000..410b49e --- /dev/null +++ b/tests/conformance/source/deque/invalid_empty.aji @@ -0,0 +1,45 @@ +// expect: run +// trap: T0001 +// grant: heap=mem.alloc:17 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(1, heap); let item = own.new(42u64, heap) or trap; + { mut q = value; pushed::>(std.deque.push_back::>(q, move item)); q.length = 0; } + // A corrupt empty claim cannot cause normal destruction of a nested owner. + released::>(move value); + return 42; +} diff --git a/tests/conformance/source/deque/loan.aji b/tests/conformance/source/deque/loan.aji new file mode 100644 index 0000000..64dd439 --- /dev/null +++ b/tests/conformance/source/deque/loan.aji @@ -0,0 +1,41 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn worker(q: mut>) -> void effects [] {} +fn bad(q: mut>) -> void effects [task.spawn, task.wait] { + scope s { let worker = task.spawn(s, worker, q); pushed::(std.deque.push_front::(q, 42u64)); task.join(move worker); } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/loan_join.aji b/tests/conformance/source/deque/loan_join.aji new file mode 100644 index 0000000..5b672d7 --- /dev/null +++ b/tests/conformance/source/deque/loan_join.aji @@ -0,0 +1,47 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:17 +// schedules: 8 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn worker(q: mut>>) -> void effects [] { let item = front::>(q); assert(own.take(move item) == 42u64); } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let value = opened::>(1, heap); let item = own.new(42u64, heap) or trap; + { mut q = value; pushed::>(std.deque.push_back::>(q, move item)); + scope s { let worker = task.spawn(s, worker, q); task.join(move worker); } + } + released::>(move value); return 42; +} diff --git a/tests/conformance/source/deque/missing_move.aji b/tests/conformance/source/deque/missing_move.aji new file mode 100644 index 0000000..994a99f --- /dev/null +++ b/tests/conformance/source/deque/missing_move.aji @@ -0,0 +1,42 @@ +// expect: reject E7003 +// grant: heap=mem.alloc:1024 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(1, heap); let item = own.new(42u64, heap) or trap; + { mut q = value; pushed::>(std.deque.push_back::>(q, item)); } + trap; +} diff --git a/tests/conformance/source/deque/model.aji b/tests/conformance/source/deque/model.aji new file mode 100644 index 0000000..2e0101b --- /dev/null +++ b/tests/conformance/source/deque/model.aji @@ -0,0 +1,73 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:2048 +// fuel: 1000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn trace(heap: cap, ops: slice, values: slice, indices: slice, flags: slice, returned: slice, lengths: slice, expected: slice) -> void effects [mem.alloc] { + let value = opened::(3, heap); + for step in 0usize..ops.len { + let number = values[step] as u64; + { mut q = value; + match ops[step] { + 0 => { match std.deque.push_back::(q, number) { std.deque.PushResult::::ok => { assert(flags[step] == 0u8); }, std.deque.PushResult::::full(item) => { assert(flags[step] == 1u8 and item == number); } } } + 1 => { match std.deque.push_front::(q, number) { std.deque.PushResult::::ok => { assert(flags[step] == 0u8); }, std.deque.PushResult::::full(item) => { assert(flags[step] == 1u8 and item == number); } } } + 2 => { match std.deque.pop_front::(q) { std.option.Option::::some(item) => { assert(flags[step] == 0u8 and item == returned[step] as u64); }, std.option.Option::::none => { assert(flags[step] == 1u8); } } } + 3 => { match std.deque.pop_back::(q) { std.option.Option::::some(item) => { assert(flags[step] == 0u8 and item == returned[step] as u64); }, std.option.Option::::none => { assert(flags[step] == 1u8); } } } + 4 => { match std.deque.reserve::(q, indices[step] as! usize, heap) { std.deque.ReserveResult::ok => {}, std.deque.ReserveResult::err(error) => { trap; } } } + 5 => { match std.deque.replace::(q, indices[step] as! usize, number) { std.deque.ReplaceResult::::ok(item) => { assert(flags[step] == 0u8 and item == returned[step] as u64); }, std.deque.ReplaceResult::::out_of_bounds(item) => { assert(flags[step] == 1u8 and item == number); } } } + _ => { trap; } + } + } + { ref q = value; + let length = lengths[step] as! usize; + assert(std.deque.len::(q) == length); + for i in 0usize..length { + match std.deque.get::(q, i) { std.option.Option::::some(item) => { assert(item == expected[step * 8 + i] as u64); }, std.option.Option::::none => { trap; } } + } + match std.deque.get::(q, length) { std.option.Option::::some(item) => { trap; }, std.option.Option::::none => {} } + } + } + { mut q = value; while q.length != 0usize { let item = front::(q); } } + released::(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + trace(heap, ref b"\x01\x01\x05\x04\x02\x01\x04\x03\x01\x04\x05\x01\x02\x02\x05\x03\x01\x00\x03\x05\x03\x04\x04\x02\x02\x05\x04\x05\x05\x02\x03\x00", ref b"\x26\x18\x26\x01\x24\x2e\x36\x1a\x29\x19\x32\x31\x32\x1f\x33\x2f\x39\x03\x0e\x1c\x21\x17\x1b\x2c\x27\x38\x3a\x2a\x36\x08\x37\x17", ref b"\x08\x07\x01\x07\x03\x07\x08\x02\x02\x00\x01\x00\x00\x06\x06\x07\x05\x02\x04\x04\x06\x08\x03\x00\x02\x05\x01\x03\x04\x01\x07\x01", ref b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x00\x01\x01\x01\x00\x01\x01\x01\x01\x00", ref b"\x00\x00\x26\x00\x18\x00\x00\x26\x00\x00\x2e\x00\x31\x29\x00\x32\x00\x00\x03\x00\x39\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", ref b"\x01\x02\x02\x02\x01\x02\x02\x01\x02\x02\x02\x03\x02\x01\x01\x00\x01\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", ref b"\x26\x00\x00\x00\x00\x00\x00\x00\x18\x26\x00\x00\x00\x00\x00\x00\x18\x26\x00\x00\x00\x00\x00\x00\x18\x26\x00\x00\x00\x00\x00\x00\x26\x00\x00\x00\x00\x00\x00\x00\x2e\x26\x00\x00\x00\x00\x00\x00\x2e\x26\x00\x00\x00\x00\x00\x00\x2e\x00\x00\x00\x00\x00\x00\x00\x29\x2e\x00\x00\x00\x00\x00\x00\x29\x2e\x00\x00\x00\x00\x00\x00\x29\x32\x00\x00\x00\x00\x00\x00\x31\x29\x32\x00\x00\x00\x00\x00\x29\x32\x00\x00\x00\x00\x00\x00\x32\x00\x00\x00\x00\x00\x00\x00\x32\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x39\x00\x00\x00\x00\x00\x00\x00\x39\x03\x00\x00\x00\x00\x00\x00\x39\x00\x00\x00\x00\x00\x00\x00\x39\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00"); + trace(heap, ref b"\x05\x00\x03\x02\x04\x02\x02\x02\x00\x00\x00\x03\x00\x00\x03\x04\x01\x01\x04\x01\x01\x00\x00\x03\x04\x03\x04\x00\x00\x03\x01\x03", ref b"\x03\x21\x17\x26\x11\x1b\x36\x3a\x25\x3b\x23\x38\x1b\x26\x1d\x3b\x33\x32\x2f\x19\x09\x24\x3e\x27\x1f\x18\x38\x10\x1e\x08\x1f\x1a", ref b"\x08\x03\x08\x02\x01\x05\x01\x04\x03\x03\x07\x01\x00\x06\x04\x08\x06\x08\x01\x03\x07\x07\x07\x01\x08\x06\x02\x01\x06\x04\x04\x04", ref b"\x01\x00\x00\x01\x00\x01\x01\x01\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", ref b"\x00\x00\x21\x00\x00\x00\x00\x00\x00\x00\x00\x23\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x3e\x00\x24\x00\x00\x00\x1e\x00\x10", ref b"\x00\x01\x00\x00\x00\x00\x00\x00\x01\x02\x03\x02\x03\x03\x02\x02\x03\x04\x04\x05\x06\x07\x08\x07\x07\x06\x06\x07\x08\x07\x08\x07", ref b"\x00\x00\x00\x00\x00\x00\x00\x00\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x25\x00\x00\x00\x00\x00\x00\x00\x25\x3b\x00\x00\x00\x00\x00\x00\x25\x3b\x23\x00\x00\x00\x00\x00\x25\x3b\x00\x00\x00\x00\x00\x00\x25\x3b\x1b\x00\x00\x00\x00\x00\x25\x3b\x1b\x00\x00\x00\x00\x00\x25\x3b\x00\x00\x00\x00\x00\x00\x25\x3b\x00\x00\x00\x00\x00\x00\x33\x25\x3b\x00\x00\x00\x00\x00\x32\x33\x25\x3b\x00\x00\x00\x00\x32\x33\x25\x3b\x00\x00\x00\x00\x19\x32\x33\x25\x3b\x00\x00\x00\x09\x19\x32\x33\x25\x3b\x00\x00\x09\x19\x32\x33\x25\x3b\x24\x00\x09\x19\x32\x33\x25\x3b\x24\x3e\x09\x19\x32\x33\x25\x3b\x24\x00\x09\x19\x32\x33\x25\x3b\x24\x00\x09\x19\x32\x33\x25\x3b\x00\x00\x09\x19\x32\x33\x25\x3b\x00\x00\x09\x19\x32\x33\x25\x3b\x10\x00\x09\x19\x32\x33\x25\x3b\x10\x1e\x09\x19\x32\x33\x25\x3b\x10\x00\x1f\x09\x19\x32\x33\x25\x3b\x10\x1f\x09\x19\x32\x33\x25\x3b\x00"); + trace(heap, ref b"\x05\x05\x01\x05\x00\x00\x01\x04\x01\x03\x04\x01\x02\x01\x00\x00\x04\x05\x00\x00\x05\x04\x00\x02\x00\x03\x01\x01\x05\x04\x04\x01", ref b"\x08\x12\x09\x30\x26\x02\x0f\x02\x2e\x0f\x12\x2d\x12\x3e\x06\x17\x11\x1e\x3f\x24\x28\x0d\x2b\x06\x19\x29\x18\x2b\x3c\x29\x2f\x1e", ref b"\x00\x03\x01\x08\x06\x01\x08\x08\x08\x07\x00\x06\x02\x05\x06\x05\x00\x08\x06\x04\x05\x01\x03\x03\x04\x05\x05\x04\x01\x02\x03\x06", ref b"\x01\x01\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x00\x01", ref b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x2d\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x3e\x00\x19\x00\x00\x2e\x00\x00\x00", ref b"\x00\x00\x01\x01\x02\x03\x03\x03\x04\x03\x03\x04\x03\x04\x05\x06\x06\x06\x07\x08\x08\x08\x08\x07\x08\x07\x08\x08\x08\x08\x08\x08", ref b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x09\x26\x00\x00\x00\x00\x00\x00\x09\x26\x02\x00\x00\x00\x00\x00\x09\x26\x02\x00\x00\x00\x00\x00\x09\x26\x02\x00\x00\x00\x00\x00\x2e\x09\x26\x02\x00\x00\x00\x00\x2e\x09\x26\x00\x00\x00\x00\x00\x2e\x09\x26\x00\x00\x00\x00\x00\x2d\x2e\x09\x26\x00\x00\x00\x00\x2e\x09\x26\x00\x00\x00\x00\x00\x3e\x2e\x09\x26\x00\x00\x00\x00\x3e\x2e\x09\x26\x06\x00\x00\x00\x3e\x2e\x09\x26\x06\x17\x00\x00\x3e\x2e\x09\x26\x06\x17\x00\x00\x3e\x2e\x09\x26\x06\x17\x00\x00\x3e\x2e\x09\x26\x06\x17\x3f\x00\x3e\x2e\x09\x26\x06\x17\x3f\x24\x3e\x2e\x09\x26\x06\x28\x3f\x24\x3e\x2e\x09\x26\x06\x28\x3f\x24\x3e\x2e\x09\x26\x06\x28\x3f\x24\x2e\x09\x26\x06\x28\x3f\x24\x00\x2e\x09\x26\x06\x28\x3f\x24\x19\x2e\x09\x26\x06\x28\x3f\x24\x00\x18\x2e\x09\x26\x06\x28\x3f\x24\x18\x2e\x09\x26\x06\x28\x3f\x24\x18\x3c\x09\x26\x06\x28\x3f\x24\x18\x3c\x09\x26\x06\x28\x3f\x24\x18\x3c\x09\x26\x06\x28\x3f\x24\x18\x3c\x09\x26\x06\x28\x3f\x24"); + trace(heap, ref b"\x00\x05\x03\x05\x03\x01\x03\x03\x00\x05\x03\x03\x03\x01\x05\x01\x00\x03\x04\x04\x05\x04\x01\x05\x03\x05\x02\x01\x02\x04\x01\x03", ref b"\x26\x2c\x3d\x1d\x35\x0d\x0e\x31\x34\x23\x24\x2f\x0c\x19\x39\x3b\x22\x1c\x0d\x1c\x2f\x35\x27\x3e\x3a\x17\x04\x30\x0e\x3c\x27\x03", ref b"\x02\x02\x07\x07\x04\x05\x03\x01\x07\x04\x05\x08\x05\x05\x08\x04\x00\x02\x01\x06\x04\x05\x07\x05\x03\x07\x06\x08\x08\x08\x01\x00", ref b"\x00\x01\x00\x01\x01\x00\x00\x01\x00\x01\x00\x01\x01\x00\x01\x00\x00\x00\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00", ref b"\x00\x00\x26\x00\x00\x00\x0d\x00\x00\x00\x34\x00\x00\x00\x00\x00\x00\x22\x00\x00\x00\x00\x00\x00\x19\x00\x27\x00\x30\x00\x00\x3b", ref b"\x01\x01\x00\x00\x00\x01\x00\x00\x01\x01\x00\x00\x00\x01\x01\x02\x03\x02\x02\x02\x02\x02\x03\x03\x02\x02\x01\x02\x01\x01\x02\x01", ref b"\x26\x00\x00\x00\x00\x00\x00\x00\x26\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x00\x00\x00\x00\x00\x00\x34\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x3b\x19\x00\x00\x00\x00\x00\x00\x3b\x19\x22\x00\x00\x00\x00\x00\x3b\x19\x00\x00\x00\x00\x00\x00\x3b\x19\x00\x00\x00\x00\x00\x00\x3b\x19\x00\x00\x00\x00\x00\x00\x3b\x19\x00\x00\x00\x00\x00\x00\x3b\x19\x00\x00\x00\x00\x00\x00\x27\x3b\x19\x00\x00\x00\x00\x00\x27\x3b\x19\x00\x00\x00\x00\x00\x27\x3b\x00\x00\x00\x00\x00\x00\x27\x3b\x00\x00\x00\x00\x00\x00\x3b\x00\x00\x00\x00\x00\x00\x00\x30\x3b\x00\x00\x00\x00\x00\x00\x3b\x00\x00\x00\x00\x00\x00\x00\x3b\x00\x00\x00\x00\x00\x00\x00\x27\x3b\x00\x00\x00\x00\x00\x00\x27\x00\x00\x00\x00\x00\x00\x00"); + return 42; +} diff --git a/tests/conformance/source/deque/not_share.aji b/tests/conformance/source/deque/not_share.aji new file mode 100644 index 0000000..f2294ee --- /dev/null +++ b/tests/conformance/source/deque/not_share.aji @@ -0,0 +1,10 @@ +// expect: reject E4002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +fn worker(q: ref>>) -> void effects [] {} +fn bad(q: ref>>) -> void effects [task.spawn, task.wait] { + scope s { let worker = task.spawn(s, worker, q); task.join(move worker); } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/owner.aji b/tests/conformance/source/deque/owner.aji new file mode 100644 index 0000000..0ee505b --- /dev/null +++ b/tests/conformance/source/deque/owner.aji @@ -0,0 +1,51 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:1024 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(2, heap); + let first = own.new(7u64, heap) or trap; + let last = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { mut q = value; + pushed::>(std.deque.push_front::>(q, move first)); + pushed::>(std.deque.push_back::>(q, move last)); + let a = front::>(q); assert(own.take(move a) == 7u64); + let b = back::>(q); answer = own.take(move b); + } + released::>(move value); return answer; +} diff --git a/tests/conformance/source/deque/pop_leak.aji b/tests/conformance/source/deque/pop_leak.aji new file mode 100644 index 0000000..049696a --- /dev/null +++ b/tests/conformance/source/deque/pop_leak.aji @@ -0,0 +1,10 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +fn bad(q: mut>>) -> void effects [] { + let item = std.deque.pop_front::>(q); + return; +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/replace_owner.aji b/tests/conformance/source/deque/replace_owner.aji new file mode 100644 index 0000000..686a7dd --- /dev/null +++ b/tests/conformance/source/deque/replace_owner.aji @@ -0,0 +1,57 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:1024 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(2, heap); + let a = own.new(7u64, heap) or trap; + { mut q = value; + pushed::>(std.deque.push_front::>(q, move a)); + let b = own.new(42u64, heap) or trap; + match std.deque.replace::>(q, 0, move b) { std.deque.ReplaceResult::>::ok(old) => { assert(own.take(move old) == 7u64); }, std.deque.ReplaceResult::>::out_of_bounds(item) => { trap; } } + let c = own.new(99u64, heap) or trap; + match std.deque.replace::>(q, 1, move c) { std.deque.ReplaceResult::>::ok(old) => { trap; }, std.deque.ReplaceResult::>::out_of_bounds(item) => { assert(own.take(move item) == 99u64); } } + } + match std.deque.free::>(move value) { + std.deque.FreeResult::>::ok => { trap; } + std.deque.FreeResult::>::not_empty(returned) => { + var answer: u64 = 0; + { mut q = returned; let item = back::>(q); answer = own.take(move item); } + released::>(move returned); return answer; + } + } +} diff --git a/tests/conformance/source/deque/reserve_authority.aji b/tests/conformance/source/deque/reserve_authority.aji new file mode 100644 index 0000000..18c8c82 --- /dev/null +++ b/tests/conformance/source/deque/reserve_authority.aji @@ -0,0 +1,56 @@ +// expect: run +// result: 42 +// grant: first=mem.alloc:27 +// grant: second=mem.alloc:45 +// grant: items=mem.alloc:16 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(first: cap, second: cap, items: cap) -> u64 effects [mem.alloc] { + let value = opened::>(3, first); + let a = own.new(7u64, items) or trap; let b = own.new(42u64, items) or trap; + { mut q = value; + pushed::>(std.deque.push_front::>(q, move a)); + pushed::>(std.deque.push_back::>(q, move b)); + match std.deque.reserve::>(q, 5, second) { std.deque.ReserveResult::ok => {}, std.deque.ReserveResult::err(error) => { trap; } } + } + let reuse_first = opened::>(3, first); released::>(move reuse_first); + var answer: u64 = 0; + { mut q = value; let a = front::>(q); assert(own.take(move a) == 7u64); let b = front::>(q); answer = own.take(move b); } + released::>(move value); + let reuse_second = opened::>(5, second); released::>(move reuse_second); + let reuse_items = own.new(42u64, items) or trap; own.free(move reuse_items); + return answer; +} diff --git a/tests/conformance/source/deque/reserve_failure.aji b/tests/conformance/source/deque/reserve_failure.aji new file mode 100644 index 0000000..f7f8c62 --- /dev/null +++ b/tests/conformance/source/deque/reserve_failure.aji @@ -0,0 +1,55 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:80 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(3, heap); + let a = own.new(7u64, heap) or trap; let b = own.new(42u64, heap) or trap; + { mut q = value; + pushed::>(std.deque.push_front::>(q, move a)); + pushed::>(std.deque.push_back::>(q, move b)); + assert(q.head == 2usize); + match std.deque.reserve::>(q, 5, heap) { std.deque.ReserveResult::ok => { trap; }, std.deque.ReserveResult::err(error) => {} } + assert(q.head == 2usize); + } + { ref q = value; assert(std.deque.len::>(q) == 2usize); assert(std.deque.capacity::>(q) == 3usize); } + var answer: u64 = 0; + { mut q = value; let a = front::>(q); assert(own.take(move a) == 7u64); let b = front::>(q); answer = own.take(move b); } + released::>(move value); + let same_budget = opened::>(8, heap); released::>(move same_budget); + return answer; +} diff --git a/tests/conformance/source/deque/reuse.aji b/tests/conformance/source/deque/reuse.aji new file mode 100644 index 0000000..ce06e58 --- /dev/null +++ b/tests/conformance/source/deque/reuse.aji @@ -0,0 +1,49 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:26 +// fuel: 400000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(2, heap); + for index in 0usize..300usize { + let item = own.new(42u64, heap) or trap; + { mut q = value; pushed::>(std.deque.push_front::>(q, move item)); let old = back::>(q); assert(own.take(move old) == 42u64); } + } + released::>(move value); + let again = opened::>(2, heap); released::>(move again); + return 42; +} diff --git a/tests/conformance/source/deque/sender.aji b/tests/conformance/source/deque/sender.aji new file mode 100644 index 0000000..b97fcf3 --- /dev/null +++ b/tests/conformance/source/deque/sender.aji @@ -0,0 +1,26 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:256 +// schedules: 8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §26; docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +struct Job { number: u64 } +fn worker(value: std.deque.Deque>) -> void effects [task.wait] { + { mut v = value; match std.deque.pop_front::>(v) { std.option.Option::>::some(tx) => { channel.send(tx, Job { number: 42 }) or trap; channel.close_sender(move tx); }, std.option.Option::>::none => { trap; } } } + match std.deque.free::>(move value) { std.deque.FreeResult::>::ok => {}, std.deque.FreeResult::>::not_empty(returned) => { trap; } } +} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + match channel.make(1, heap) { + ok(tx, rx) => { + match std.deque.new::>(1, heap) { + std.deque.NewResult::>::ok(value) => { + { mut v = value; match std.deque.push_back::>(v, move tx) { std.deque.PushResult::>::ok => {}, std.deque.PushResult::>::full(returned) => { channel.close_sender(move returned); trap; } } } + scope s { let task = task.spawn(s, worker, move value); let job = channel.recv(rx) or trap; task.join(move task); channel.close_receiver(move rx) or trap; return job.number; } + }, std.deque.NewResult::>::err(error) => { trap; } + } + }, err(error) => { trap; } + } +} diff --git a/tests/conformance/source/deque/shared.aji b/tests/conformance/source/deque/shared.aji new file mode 100644 index 0000000..cfea2b4 --- /dev/null +++ b/tests/conformance/source/deque/shared.aji @@ -0,0 +1,56 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:9 +// schedules: 8 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn worker(q: ref>) -> u64 effects [] { + match std.deque.get::(q, 0) { std.option.Option::::some(item) => { return item; }, std.option.Option::::none => { trap; } } +} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let value = opened::(1, heap); + { mut q = value; pushed::(std.deque.push_back::(q, 42u64)); } + var answer: u64 = 0; + { ref q = value; + scope s { + let first = task.spawn(s, worker, q); let second = task.spawn(s, worker, q); + assert(std.deque.len::(q) == 1usize); + let a = task.join(move first); let b = task.join(move second); assert(a == b); answer = a; + } + } + { mut q = value; let item = front::(q); assert(item == answer); } + released::(move value); return answer; +} diff --git a/tests/conformance/source/deque/slot_view.aji b/tests/conformance/source/deque/slot_view.aji new file mode 100644 index 0000000..ff7fd49 --- /dev/null +++ b/tests/conformance/source/deque/slot_view.aji @@ -0,0 +1,42 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn bad(q: mut>) -> void effects [] { + mut storage = q.storage; + ref slots = buffer.view(storage); + pushed::(std.deque.push_back::(q, 42u64)); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/deque/wrap_reserve.aji b/tests/conformance/source/deque/wrap_reserve.aji new file mode 100644 index 0000000..fb0f2de --- /dev/null +++ b/tests/conformance/source/deque/wrap_reserve.aji @@ -0,0 +1,61 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:128 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(3, heap); + let a = own.new(1u64, heap) or trap; + let b = own.new(2u64, heap) or trap; + let c = own.new(42u64, heap) or trap; + { mut q = value; + pushed::>(std.deque.push_back::>(q, move a)); + pushed::>(std.deque.push_back::>(q, move b)); + let first = front::>(q); assert(own.take(move first) == 1u64); + pushed::>(std.deque.push_back::>(q, move c)); + let second = front::>(q); assert(own.take(move second) == 2u64); + let d = own.new(7u64, heap) or trap; + pushed::>(std.deque.push_back::>(q, move d)); + assert(q.head == 2usize); + match std.deque.reserve::>(q, 5, heap) { std.deque.ReserveResult::ok => {}, std.deque.ReserveResult::err(error) => { trap; } } + assert(q.head == 0usize); + let last = back::>(q); assert(own.take(move last) == 7u64); + } + var answer: u64 = 0; + { mut q = value; let last = front::>(q); answer = own.take(move last); } + released::>(move value); + return answer; +} diff --git a/tests/conformance/source/deque/zero.aji b/tests/conformance/source/deque/zero.aji new file mode 100644 index 0000000..8513d47 --- /dev/null +++ b/tests/conformance/source/deque/zero.aji @@ -0,0 +1,49 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.11 +module test.deque +import std.deque; +import std.option; +fn opened(capacity: usize, heap: cap) -> std.deque.Deque effects [mem.alloc] { + match std.deque.new::(capacity, heap) { + std.deque.NewResult::::ok(value) => { return move value; } + std.deque.NewResult::::err(error) => { trap; } + } +} +fn pushed(result: std.deque.PushResult) -> void effects [] { + match move result { + std.deque.PushResult::::ok => {} + std.deque.PushResult::::full(item) => { trap; } + } +} +fn front(value: mut>) -> T effects [] { + match std.deque.pop_front::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn back(value: mut>) -> T effects [] { + match std.deque.pop_back::(value) { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn released(value: std.deque.Deque) -> void effects [] { + match std.deque.free::(move value) { + std.deque.FreeResult::::ok => {} + std.deque.FreeResult::::not_empty(returned) => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::>(0, heap); + let item = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { mut q = value; + match std.deque.pop_front::>(q) { std.option.Option::>::some(item) => { trap; }, std.option.Option::>::none => {} } + match std.deque.pop_back::>(q) { std.option.Option::>::some(item) => { trap; }, std.option.Option::>::none => {} } + match std.deque.push_front::>(q, move item) { std.deque.PushResult::>::ok => { trap; }, std.deque.PushResult::>::full(returned) => { answer = own.take(move returned); } } + } + released::>(move value); return answer; +} diff --git a/tests/conformance/source/error_values/alloc_error.aji b/tests/conformance/source/error_values/alloc_error.aji new file mode 100644 index 0000000..79e9cbd --- /dev/null +++ b/tests/conformance/source/error_values/alloc_error.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn v0() -> alloc_error effects [] { return alloc_error::budget_exceeded; } +fn v1() -> alloc_error effects [] { return alloc_error::out_of_memory; } +fn main() -> u64 effects [] { + let e0 = v0(); + match e0 { + alloc_error::budget_exceeded => {} + alloc_error::out_of_memory => { trap; } + } + let e1 = v1(); + match e1 { + alloc_error::budget_exceeded => { trap; } + alloc_error::out_of_memory => {} + } + return 42u64; +} diff --git a/tests/conformance/source/error_values/cap_error.aji b/tests/conformance/source/error_values/cap_error.aji new file mode 100644 index 0000000..98abdc8 --- /dev/null +++ b/tests/conformance/source/error_values/cap_error.aji @@ -0,0 +1,29 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn v0() -> cap_error effects [] { return cap_error::invalid_restriction; } +fn v1() -> cap_error effects [] { return cap_error::not_subset; } +fn v2() -> cap_error effects [] { return cap_error::unsupported_restriction; } +fn main() -> u64 effects [] { + let e0 = v0(); + match e0 { + cap_error::invalid_restriction => {} + cap_error::not_subset => { trap; } + cap_error::unsupported_restriction => { trap; } + } + let e1 = v1(); + match e1 { + cap_error::invalid_restriction => { trap; } + cap_error::not_subset => {} + cap_error::unsupported_restriction => { trap; } + } + let e2 = v2(); + match e2 { + cap_error::invalid_restriction => { trap; } + cap_error::not_subset => { trap; } + cap_error::unsupported_restriction => {} + } + return 42u64; +} diff --git a/tests/conformance/source/error_values/io_error.aji b/tests/conformance/source/error_values/io_error.aji new file mode 100644 index 0000000..89b2ad6 --- /dev/null +++ b/tests/conformance/source/error_values/io_error.aji @@ -0,0 +1,200 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn v0() -> io_error effects [] { return io_error::not_found; } +fn v1() -> io_error effects [] { return io_error::permission_denied; } +fn v2() -> io_error effects [] { return io_error::already_exists; } +fn v3() -> io_error effects [] { return io_error::invalid_input; } +fn v4() -> io_error effects [] { return io_error::no_space; } +fn v5() -> io_error effects [] { return io_error::broken_pipe; } +fn v6() -> io_error effects [] { return io_error::connection_refused; } +fn v7() -> io_error effects [] { return io_error::connection_reset; } +fn v8() -> io_error effects [] { return io_error::address_in_use; } +fn v9() -> io_error effects [] { return io_error::address_unavailable; } +fn v10() -> io_error effects [] { return io_error::timed_out; } +fn v11() -> io_error effects [] { return io_error::other; } +fn main() -> u64 effects [] { + let e0 = v0(); + match e0 { + io_error::not_found => {} + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e1 = v1(); + match e1 { + io_error::not_found => { trap; } + io_error::permission_denied => {} + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e2 = v2(); + match e2 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => {} + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e3 = v3(); + match e3 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => {} + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e4 = v4(); + match e4 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => {} + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e5 = v5(); + match e5 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => {} + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e6 = v6(); + match e6 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => {} + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e7 = v7(); + match e7 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => {} + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e8 = v8(); + match e8 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => {} + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e9 = v9(); + match e9 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => {} + io_error::timed_out => { trap; } + io_error::other => { trap; } + } + let e10 = v10(); + match e10 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => {} + io_error::other => { trap; } + } + let e11 = v11(); + match e11 { + io_error::not_found => { trap; } + io_error::permission_denied => { trap; } + io_error::already_exists => { trap; } + io_error::invalid_input => { trap; } + io_error::no_space => { trap; } + io_error::broken_pipe => { trap; } + io_error::connection_refused => { trap; } + io_error::connection_reset => { trap; } + io_error::address_in_use => { trap; } + io_error::address_unavailable => { trap; } + io_error::timed_out => { trap; } + io_error::other => {} + } + return 42u64; +} diff --git a/tests/conformance/source/error_values/no_authority.aji b/tests/conformance/source/error_values/no_authority.aji new file mode 100644 index 0000000..eb4cc69 --- /dev/null +++ b/tests/conformance/source/error_values/no_authority.aji @@ -0,0 +1,5 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn main() -> cap effects [] { return alloc_error::budget_exceeded; } diff --git a/tests/conformance/source/error_values/payload.aji b/tests/conformance/source/error_values/payload.aji new file mode 100644 index 0000000..43cf15f --- /dev/null +++ b/tests/conformance/source/error_values/payload.aji @@ -0,0 +1,5 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn main() -> alloc_error effects [] { return alloc_error::budget_exceeded(1u64); } diff --git a/tests/conformance/source/error_values/unknown_variant.aji b/tests/conformance/source/error_values/unknown_variant.aji new file mode 100644 index 0000000..0b527f4 --- /dev/null +++ b/tests/conformance/source/error_values/unknown_variant.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn main() -> alloc_error effects [] { return alloc_error::invalid; } diff --git a/tests/conformance/source/error_values/wrong_family.aji b/tests/conformance/source/error_values/wrong_family.aji new file mode 100644 index 0000000..33f2b3e --- /dev/null +++ b/tests/conformance/source/error_values/wrong_family.aji @@ -0,0 +1,5 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/05-effects-and-capabilities.md §14 +module test.errors +fn main() -> io_error effects [] { return alloc_error::budget_exceeded; } diff --git a/tests/conformance/source/generics/arity.aji b/tests/conformance/source/generics/arity.aji new file mode 100644 index 0000000..b988d84 --- /dev/null +++ b/tests/conformance/source/generics/arity.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::(); } diff --git a/tests/conformance/source/generics/array_generic_argument.aji b/tests/conformance/source/generics/array_generic_argument.aji new file mode 100644 index 0000000..33111ce --- /dev/null +++ b/tests/conformance/source/generics/array_generic_argument.aji @@ -0,0 +1,7 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn id(value: T) -> T effects [] { return value; } +fn main() -> u64 effects [] { let v = id::<[u64; 2]>([21u64; 2]); return v[0] + v[1]; } diff --git a/tests/conformance/source/generics/array_layout.aji b/tests/conformance/source/generics/array_layout.aji new file mode 100644 index 0000000..51facc2 --- /dev/null +++ b/tests/conformance/source/generics/array_layout.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// equivalent: generics/array_layout.air +module demo.generic +struct Leaf { value: T } +struct Node { child: [Leaf; 1] } +fn unused(node: Node) -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/atomic_argument.aji b/tests/conformance/source/generics/atomic_argument.aji new file mode 100644 index 0000000..22ceb7e --- /dev/null +++ b/tests/conformance/source/generics/atomic_argument.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>(); } diff --git a/tests/conformance/source/generics/bare_angle_call.aji b/tests/conformance/source/generics/bare_angle_call.aji new file mode 100644 index 0000000..b8c5c5b --- /dev/null +++ b/tests/conformance/source/generics/bare_angle_call.aji @@ -0,0 +1,6 @@ +// expect: reject E7001 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn id(value: T) -> T effects [] { return value; } +fn main() -> u64 effects [] { return id(42); } diff --git a/tests/conformance/source/generics/basic.aji b/tests/conformance/source/generics/basic.aji new file mode 100644 index 0000000..6e0482a --- /dev/null +++ b/tests/conformance/source/generics/basic.aji @@ -0,0 +1,16 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generics +struct Pair { left: T, right: T } +enum Maybe { some(T), none } +fn identity(value: T) -> T effects [] { return value; } +fn main() -> u64 effects [] { + let p: Pair = Pair:: { left: identity::(20), right: identity::(22) }; + let m = Maybe::>::some(p); + match m { + Maybe::>::some(pair) => { return pair.left + pair.right; } + Maybe::>::none => { return 0; } + } +} diff --git a/tests/conformance/source/generics/borrow.aji b/tests/conformance/source/generics/borrow.aji new file mode 100644 index 0000000..2bb40e7 --- /dev/null +++ b/tests/conformance/source/generics/borrow.aji @@ -0,0 +1,11 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn swap(left: mut, right: mut) -> void effects [] { + let saved = *left; + *left = *right; + *right = saved; +} +fn main() -> u64 effects [] { var a: u64 = 20; var b: u64 = 22; swap::(mut a, mut b); return a + b; } diff --git a/tests/conformance/source/generics/borrow_alias.aji b/tests/conformance/source/generics/borrow_alias.aji new file mode 100644 index 0000000..0b470ff --- /dev/null +++ b/tests/conformance/source/generics/borrow_alias.aji @@ -0,0 +1,6 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn swap(a: mut, b: mut) -> void effects [] { let v = *a; *a = *b; *b = v; } +fn main() -> u64 effects [] { var a: u64 = 42; swap::(mut a, mut a); return a; } diff --git a/tests/conformance/source/generics/borrow_read.aji b/tests/conformance/source/generics/borrow_read.aji new file mode 100644 index 0000000..2c6dda5 --- /dev/null +++ b/tests/conformance/source/generics/borrow_read.aji @@ -0,0 +1,7 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn read(value: ref) -> T effects [] { return *value; } +fn main() -> u64 effects [] { var value: u64 = 42; return read::(ref value); } diff --git a/tests/conformance/source/generics/constraints.aji b/tests/conformance/source/generics/constraints.aji new file mode 100644 index 0000000..e003537 --- /dev/null +++ b/tests/conformance/source/generics/constraints.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.constraints +struct Pair { a: u64, b: u64 } +fn plain() -> u64 effects [] { return 40; } +fn context() -> u64 effects [] { return 2; } +fn main() -> u64 effects [] { return plain::() + context::>(); } diff --git a/tests/conformance/source/generics/constraints_positive.aji b/tests/conformance/source/generics/constraints_positive.aji new file mode 100644 index 0000000..3aab30a --- /dev/null +++ b/tests/conformance/source/generics/constraints_positive.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +enum Kind { value } +fn copy() -> u64 effects [] { return 10; } +fn send() -> u64 effects [] { return 10; } +fn share() -> u64 effects [] { return 10; } +fn freeze() -> u64 effects [] { return 10; } +fn local() -> u64 effects [] { return 2; } +fn main() -> u64 effects [] { return copy::>() + send::>() + share::>() + freeze::<[Kind; 2]>() + local::>(); } diff --git a/tests/conformance/source/generics/copy_borrow_reject.aji b/tests/conformance/source/generics/copy_borrow_reject.aji new file mode 100644 index 0000000..f663054 --- /dev/null +++ b/tests/conformance/source/generics/copy_borrow_reject.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>(); } diff --git a/tests/conformance/source/generics/copy_reject.aji b/tests/conformance/source/generics/copy_reject.aji new file mode 100644 index 0000000..a27a4a0 --- /dev/null +++ b/tests/conformance/source/generics/copy_reject.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.constraint +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>(); } diff --git a/tests/conformance/source/generics/duplicate_constraint.aji b/tests/conformance/source/generics/duplicate_constraint.aji new file mode 100644 index 0000000..1674714 --- /dev/null +++ b/tests/conformance/source/generics/duplicate_constraint.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/duplicate_field_unused.aji b/tests/conformance/source/generics/duplicate_field_unused.aji new file mode 100644 index 0000000..969a317 --- /dev/null +++ b/tests/conformance/source/generics/duplicate_field_unused.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct Pair { value: T, value: T } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/duplicate_parameter.aji b/tests/conformance/source/generics/duplicate_parameter.aji new file mode 100644 index 0000000..0625b01 --- /dev/null +++ b/tests/conformance/source/generics/duplicate_parameter.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/effect.aji b/tests/conformance/source/generics/effect.aji new file mode 100644 index 0000000..d2e352f --- /dev/null +++ b/tests/conformance/source/generics/effect.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// grant: out=io.write +// stdout: generic +module demo.generic +fn emit(out: cap) -> u64 effects [io.write] { io.stdout_write(out, b"generic") or trap; return 42; } +fn main(out: cap) -> u64 effects [io.write] { return emit::(out); } diff --git a/tests/conformance/source/generics/effect_missing.aji b/tests/conformance/source/generics/effect_missing.aji new file mode 100644 index 0000000..7d957a1 --- /dev/null +++ b/tests/conformance/source/generics/effect_missing.aji @@ -0,0 +1,6 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn emit(out: cap) -> u64 effects [io.write] { io.stdout_write(out, b"generic") or trap; return 42; } +fn main(out: cap) -> u64 effects [] { return emit::(out); } diff --git a/tests/conformance/source/generics/expanding_recursion.aji b/tests/conformance/source/generics/expanding_recursion.aji new file mode 100644 index 0000000..f9bc61a --- /dev/null +++ b/tests/conformance/source/generics/expanding_recursion.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn grow() -> u64 effects [] { return grow::<[T; 2]>(); } +fn main() -> u64 effects [] { return grow::(); } diff --git a/tests/conformance/source/generics/freeze_reject.aji b/tests/conformance/source/generics/freeze_reject.aji new file mode 100644 index 0000000..8997802 --- /dev/null +++ b/tests/conformance/source/generics/freeze_reject.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>(); } diff --git a/tests/conformance/source/generics/generic_entry.aji b/tests/conformance/source/generics/generic_entry.aji new file mode 100644 index 0000000..1ddc4d7 --- /dev/null +++ b/tests/conformance/source/generics/generic_entry.aji @@ -0,0 +1,5 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/layout_cycle.aji b/tests/conformance/source/generics/layout_cycle.aji new file mode 100644 index 0000000..17ee893 --- /dev/null +++ b/tests/conformance/source/generics/layout_cycle.aji @@ -0,0 +1,6 @@ +// expect: reject E1003 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct Node { child: [Node; 1] } +fn main() -> u64 effects [] { var node: Node = zero; return 42; } diff --git a/tests/conformance/source/generics/lib.aji.inc b/tests/conformance/source/generics/lib.aji.inc new file mode 100644 index 0000000..0e5efeb --- /dev/null +++ b/tests/conformance/source/generics/lib.aji.inc @@ -0,0 +1,6 @@ +module app.lib +struct Pair { value: T } +enum Maybe { some(Pair), none } +fn wrap(value: T) -> Maybe effects [] { return Maybe::::some(Pair:: { value: value }); } +fn unwrap(value: Maybe) -> T effects [] { match value { Maybe::::some(pair) => { return pair.value; } Maybe::::none => { trap; } } } +fn identity(value: T) -> T effects [] { return value; } diff --git a/tests/conformance/source/generics/linear_aggregate.aji b/tests/conformance/source/generics/linear_aggregate.aji new file mode 100644 index 0000000..fb420f1 --- /dev/null +++ b/tests/conformance/source/generics/linear_aggregate.aji @@ -0,0 +1,7 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct Cell { value: T } +fn unused(value: Cell>) -> u64 effects [] { return 0; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/local_reject.aji b/tests/conformance/source/generics/local_reject.aji new file mode 100644 index 0000000..87feae3 --- /dev/null +++ b/tests/conformance/source/generics/local_reject.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::(); } diff --git a/tests/conformance/source/generics/lowercase_parameter.aji b/tests/conformance/source/generics/lowercase_parameter.aji new file mode 100644 index 0000000..137afa2 --- /dev/null +++ b/tests/conformance/source/generics/lowercase_parameter.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/missing_arguments.aji b/tests/conformance/source/generics/missing_arguments.aji new file mode 100644 index 0000000..cb55ef3 --- /dev/null +++ b/tests/conformance/source/generics/missing_arguments.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker(); } diff --git a/tests/conformance/source/generics/missing_import.aji b/tests/conformance/source/generics/missing_import.aji new file mode 100644 index 0000000..cfb3b64 --- /dev/null +++ b/tests/conformance/source/generics/missing_import.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// module: app.lib=source/generics/lib.aji.inc +module demo.generic +fn main() -> u64 effects [] { return app.lib.identity::(42); } diff --git a/tests/conformance/source/generics/modules.aji b/tests/conformance/source/generics/modules.aji new file mode 100644 index 0000000..1ff2abb --- /dev/null +++ b/tests/conformance/source/generics/modules.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// module: app.lib=source/generics/lib.aji.inc +module demo.generic +import app.lib; +struct Local { value: u64 } +fn main() -> u64 effects [] { let app = 7u8; assert(app == 7); let own = Local { value: 42 }; let wrapped = app.lib.wrap::(own); return app.lib.unwrap::(wrapped).value; } diff --git a/tests/conformance/source/generics/monomorphic_arguments.aji b/tests/conformance/source/generics/monomorphic_arguments.aji new file mode 100644 index 0000000..14b7fe7 --- /dev/null +++ b/tests/conformance/source/generics/monomorphic_arguments.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::(); } diff --git a/tests/conformance/source/generics/monomorphic_layout_cycle.aji b/tests/conformance/source/generics/monomorphic_layout_cycle.aji new file mode 100644 index 0000000..61ee9ee --- /dev/null +++ b/tests/conformance/source/generics/monomorphic_layout_cycle.aji @@ -0,0 +1,6 @@ +// expect: reject E1003 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct Node { child: [Node; 1] } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/nested_borrow_argument.aji b/tests/conformance/source/generics/nested_borrow_argument.aji new file mode 100644 index 0000000..601f7cc --- /dev/null +++ b/tests/conformance/source/generics/nested_borrow_argument.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>>(); } diff --git a/tests/conformance/source/generics/nested_owner_argument.aji b/tests/conformance/source/generics/nested_owner_argument.aji new file mode 100644 index 0000000..6517fcf --- /dev/null +++ b/tests/conformance/source/generics/nested_owner_argument.aji @@ -0,0 +1,7 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>>(); } diff --git a/tests/conformance/source/generics/nominal_instantiations.aji b/tests/conformance/source/generics/nominal_instantiations.aji new file mode 100644 index 0000000..69c2e23 --- /dev/null +++ b/tests/conformance/source/generics/nominal_instantiations.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct Cell { value: T } +fn read(value: Cell) -> u64 effects [] { return value.value; } +fn main() -> u64 effects [] { return read(Cell:: { value: 42 }); } diff --git a/tests/conformance/source/generics/option_air_twin.aji b/tests/conformance/source/generics/option_air_twin.aji new file mode 100644 index 0000000..676b8cc --- /dev/null +++ b/tests/conformance/source/generics/option_air_twin.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// equivalent: generics/option.air +module demo.generic +import std.option; +fn identity(value: T) -> T effects [] { return value; } +fn main() -> u64 effects [] { let v = std.option.Option::::some(identity::(42)); match v { std.option.Option::::some(n) => { return n; } std.option.Option::::none => { return 0; } } } diff --git a/tests/conformance/source/generics/owner.aji b/tests/conformance/source/generics/owner.aji new file mode 100644 index 0000000..7c4d5be --- /dev/null +++ b/tests/conformance/source/generics/owner.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// grant: heap=mem.alloc:64 +module demo.generic +fn identity(value: T) -> T effects [] { return move value; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = own.new(42u64, heap) or trap; + let returned = identity::>(move value); + return own.take(move returned); +} diff --git a/tests/conformance/source/generics/owner_missing_move.aji b/tests/conformance/source/generics/owner_missing_move.aji new file mode 100644 index 0000000..fd8e833 --- /dev/null +++ b/tests/conformance/source/generics/owner_missing_move.aji @@ -0,0 +1,6 @@ +// expect: reject E7003 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn identity(value: T) -> T effects [] { return move value; } +fn main(heap: cap) -> u64 effects [mem.alloc] { let value = own.new(42u64, heap) or trap; let v = identity::>(value); return own.take(move v); } diff --git a/tests/conformance/source/generics/recursive_function.aji b/tests/conformance/source/generics/recursive_function.aji new file mode 100644 index 0000000..54166a9 --- /dev/null +++ b/tests/conformance/source/generics/recursive_function.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn repeat(value: T, n: u64) -> T effects [] { + if n == 0 { return value; } + return repeat::(value, n - 1); +} +fn main() -> u64 effects [] { return repeat::(42, 10); } diff --git a/tests/conformance/source/generics/send_reject.aji b/tests/conformance/source/generics/send_reject.aji new file mode 100644 index 0000000..0cd4b1e --- /dev/null +++ b/tests/conformance/source/generics/send_reject.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::>(); } diff --git a/tests/conformance/source/generics/shadow_type_parameter.aji b/tests/conformance/source/generics/shadow_type_parameter.aji new file mode 100644 index 0000000..74c84d6 --- /dev/null +++ b/tests/conformance/source/generics/shadow_type_parameter.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct T { x: u64 } +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/share_reject.aji b/tests/conformance/source/generics/share_reject.aji new file mode 100644 index 0000000..1b255f2 --- /dev/null +++ b/tests/conformance/source/generics/share_reject.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::(); } diff --git a/tests/conformance/source/generics/specialized_bad_body.aji b/tests/conformance/source/generics/specialized_bad_body.aji new file mode 100644 index 0000000..08a83cd --- /dev/null +++ b/tests/conformance/source/generics/specialized_bad_body.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn bad(value: T) -> T effects [] { return does_not_exist(value); } +fn main() -> u64 effects [] { return bad::(42); } diff --git a/tests/conformance/source/generics/std_option_exhaustive.aji b/tests/conformance/source/generics/std_option_exhaustive.aji new file mode 100644 index 0000000..2fd7c1b --- /dev/null +++ b/tests/conformance/source/generics/std_option_exhaustive.aji @@ -0,0 +1,6 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +import std.option; +fn main() -> u64 effects [] { let v = std.option.Option::::some(42); match v { std.option.Option::::some(n) => { return n; } } } diff --git a/tests/conformance/source/generics/std_option_owner.aji b/tests/conformance/source/generics/std_option_owner.aji new file mode 100644 index 0000000..1b9b3e4 --- /dev/null +++ b/tests/conformance/source/generics/std_option_owner.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +import std.option; +fn unused(value: std.option.Option>) -> u64 effects [] { return std.option.is_some::>(move value); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/std_option_result.aji b/tests/conformance/source/generics/std_option_result.aji new file mode 100644 index 0000000..d52fa87 --- /dev/null +++ b/tests/conformance/source/generics/std_option_result.aji @@ -0,0 +1,23 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +import std.option; +import std.result; +fn main() -> u64 effects [] { + let absent = std.option.Option::::none; + assert(not std.option.is_some::(absent)); + let present: std.option.Option = std.option.Option::::some(42); + assert(std.option.is_some::(present)); + let failure = std.result.Result::::err(7); + assert(not std.result.is_ok::(failure)); + match present { + std.option.Option::::some(value) => { + let success = std.result.Result::::ok(value); + assert(std.result.is_ok::(success)); + match success { std.result.Result::::ok(n) => { return n; } std.result.Result::::err(e) => { return e as u64; } } + } + std.option.Option::::none => { return 0; } + } +} diff --git a/tests/conformance/source/generics/std_result_borrow.aji b/tests/conformance/source/generics/std_result_borrow.aji new file mode 100644 index 0000000..18784bf --- /dev/null +++ b/tests/conformance/source/generics/std_result_borrow.aji @@ -0,0 +1,7 @@ +// expect: reject E1001 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +import std.result; +fn unused(value: std.result.Result>) -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/task.aji b/tests/conformance/source/generics/task.aji new file mode 100644 index 0000000..ebe7938 --- /dev/null +++ b/tests/conformance/source/generics/task.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// schedules: 8 +module demo.generic +fn worker(value: T) -> T effects [] { return value; } +fn main() -> u64 effects [task.spawn, task.wait] { var result: u64 = 0; scope s { let t = task.spawn(s, worker::, 42); result = task.join(move t); } return result; } diff --git a/tests/conformance/source/generics/task_lend.aji b/tests/conformance/source/generics/task_lend.aji new file mode 100644 index 0000000..b2996d6 --- /dev/null +++ b/tests/conformance/source/generics/task_lend.aji @@ -0,0 +1,12 @@ +// expect: run +// result: [20,20,22,22] +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +// schedules: 8 +module demo.generic +fn fill(data: slice_mut, value: T) -> void effects [] { for i in 0..data.len { data[i] = value; } } +fn main() -> [u64; 4] effects [task.spawn] { + var data: [u64; 4] = zero; + { mut all = data; let (l, r) = all.split_at(2); scope s { let a = task.spawn(s, fill::, l, 20); let b = task.spawn(s, fill::, r, 22); task.join(move a); task.join(move b); } } + return data; +} diff --git a/tests/conformance/source/generics/task_lend_twice.aji b/tests/conformance/source/generics/task_lend_twice.aji new file mode 100644 index 0000000..42b7009 --- /dev/null +++ b/tests/conformance/source/generics/task_lend_twice.aji @@ -0,0 +1,6 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn fill(data: slice_mut, value: T) -> void effects [] { data[0] = value; } +fn main() -> u64 effects [task.spawn] { var data: [u64; 2] = zero; { mut all = data; scope s { let a = task.spawn(s, fill::, all, 20); let b = task.spawn(s, fill::, all, 22); task.join(move a); task.join(move b); } } return data[0]; } diff --git a/tests/conformance/source/generics/type_constraint.aji b/tests/conformance/source/generics/type_constraint.aji new file mode 100644 index 0000000..97fd1fd --- /dev/null +++ b/tests/conformance/source/generics/type_constraint.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +enum Value { some(T) } +fn main() -> u64 effects [] { let v = Value::>::some(0); return 42; } diff --git a/tests/conformance/source/generics/type_missing_arguments.aji b/tests/conformance/source/generics/type_missing_arguments.aji new file mode 100644 index 0000000..9c723a0 --- /dev/null +++ b/tests/conformance/source/generics/type_missing_arguments.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +struct Pair { value: T } +fn main() -> u64 effects [] { let p: Pair = Pair { value: 42 }; return p.value; } diff --git a/tests/conformance/source/generics/unknown_constraint.aji b/tests/conformance/source/generics/unknown_constraint.aji new file mode 100644 index 0000000..0d9f9cd --- /dev/null +++ b/tests/conformance/source/generics/unknown_constraint.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/unused_body.aji b/tests/conformance/source/generics/unused_body.aji new file mode 100644 index 0000000..0551638 --- /dev/null +++ b/tests/conformance/source/generics/unused_body.aji @@ -0,0 +1,7 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn unused(value: T) -> T effects [] { return does_not_exist(value); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/unused_trusted.aji b/tests/conformance/source/generics/unused_trusted.aji new file mode 100644 index 0000000..72ba9c8 --- /dev/null +++ b/tests/conformance/source/generics/unused_trusted.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> T effects [] trusted "proof" { trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/unused_unknown_effect.aji b/tests/conformance/source/generics/unused_unknown_effect.aji new file mode 100644 index 0000000..1a02744 --- /dev/null +++ b/tests/conformance/source/generics/unused_unknown_effect.aji @@ -0,0 +1,6 @@ +// expect: reject E0006 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> T effects [unknown] { trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/unused_unknown_type.aji b/tests/conformance/source/generics/unused_unknown_type.aji new file mode 100644 index 0000000..b4214df --- /dev/null +++ b/tests/conformance/source/generics/unused_unknown_type.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker(value: Typo) -> T effects [] { trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/generics/void_argument.aji b/tests/conformance/source/generics/void_argument.aji new file mode 100644 index 0000000..19d766d --- /dev/null +++ b/tests/conformance/source/generics/void_argument.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::(); } diff --git a/tests/conformance/source/generics/zero_array_argument.aji b/tests/conformance/source/generics/zero_array_argument.aji new file mode 100644 index 0000000..4b4787d --- /dev/null +++ b/tests/conformance/source/generics/zero_array_argument.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +fn marker() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return marker::<[u64; 0]>(); } diff --git a/tests/conformance/source/hash/alias.aji b/tests/conformance/source/hash/alias.aji new file mode 100644 index 0000000..2a289f4 --- /dev/null +++ b/tests/conformance/source/hash/alias.aji @@ -0,0 +1,12 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; +fn bad(data: slice_mut) -> u64 effects [] { + mut byte = data[0]; + let result = std.hash.fnv1a64(ref data); + *byte = 1; + return result; +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hash/borrow.aji b/tests/conformance/source/hash/borrow.aji new file mode 100644 index 0000000..7ef69ad --- /dev/null +++ b/tests/conformance/source/hash/borrow.aji @@ -0,0 +1,22 @@ +// expect: run +// result: 42 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; +import std.bytes; +fn main() -> u64 effects [] { + var data: [u8; 12] = zero; + std.bytes.fill(mut data, 0xff); + let first = std.hash.crc32c(ref data[2..10]); + assert(first == std.hash.crc32c(b"\xff\xff\xff\xff\xff\xff\xff\xff")); + data[0] = 0; + data[11] = 0; + assert(std.hash.crc32c(ref data[2..10]) == first); + data[2] = 1; + assert(std.hash.crc32c(ref data[2..10]) != first); + assert(std.hash.fnv1a64(ref data[3..3]) == 0xcbf29ce484222325u64); + assert(data[1] == 255u8 and data[10] == 255u8); + return 42; +} diff --git a/tests/conformance/source/hash/generic.aji b/tests/conformance/source/hash/generic.aji new file mode 100644 index 0000000..d4f459e --- /dev/null +++ b/tests/conformance/source/hash/generic.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; +fn main() -> u64 effects [] { return std.hash.fnv1a64::(b"a"); } diff --git a/tests/conformance/source/hash/known.aji b/tests/conformance/source/hash/known.aji new file mode 100644 index 0000000..2ef1097 --- /dev/null +++ b/tests/conformance/source/hash/known.aji @@ -0,0 +1,28 @@ +// expect: run +// result: 42 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; + +fn fixture(data: slice, fnv: u64, crc: u32, extended_fnv: u64, extended_crc: u32) -> void effects [] { + assert(std.hash.fnv1a64(data) == fnv); + assert(std.hash.crc32c(data) == crc); + assert(std.hash.fnv1a64_extend(0xffffffffffffffffu64, data) == extended_fnv); + assert(std.hash.crc32c_extend(0x12345678u32, data) == extended_crc); +} +fn main() -> u64 effects [] { + var empty: [u8; 1] = zero; + fixture(ref empty[0..0], 0xcbf29ce484222325u64, 0x00000000u32, 0xffffffffffffffffu64, 0x12345678u32); + fixture(ref b"\x61", 0xaf63dc4c8601ec8cu64, 0xc1d04330u32, 0xffff9dffffff597au64, 0x3a837ba4u32); + fixture(ref b"\x66\x6f\x6f\x62\x61\x72", 0x85944171f73967e8u64, 0x0d5f5c7fu32, 0x84b5fbfdea9d3fc6u64, 0x741fe86fu32); + fixture(ref b"\x48\x65\x6c\x6c\x6f\x21\x01\xff\xed", 0xbd51ea7094ee6fa1u64, 0x49651a38u32, 0x7b119b056ee0c82fu64, 0x8dbbf3d1u32); + fixture(ref b"\x31\x32\x33\x34\x35\x36\x37\x38\x39", 0x06d5573923c6cdfcu64, 0xe3069283u32, 0x7d1c37bcffcdcb42u64, 0x27d87b6au32); + fixture(ref b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0c8210784d8af5a5u64, 0x8a9136aau32, 0xfaa74d195d09bf7fu64, 0x90c2769du32); + fixture(ref b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 0x9ac5e12119fd3f85u64, 0x62a8ab43u32, 0x62c2a7593aa53b5fu64, 0x78fbeb74u32); + fixture(ref b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 0xe6cb594c1a148ac5u64, 0x46dd794eu32, 0xc3af98b6b870ba7fu64, 0x5c8e3979u32); + fixture(ref b"\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00", 0x1996adfc65ca0fe5u64, 0x113fdb5cu32, 0xa4c71b3c7cc556dfu64, 0x0b6c9b6bu32); + fixture(ref b"\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x14\x00\x00\x00\x18\x28\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 0x604415443fea059au64, 0xd9963a56u32, 0x137db44d06632ba8u64, 0xa3572cccu32); + return 42; +} diff --git a/tests/conformance/source/hash/map_storage.aji b/tests/conformance/source/hash/map_storage.aji new file mode 100644 index 0000000..4f99115 --- /dev/null +++ b/tests/conformance/source/hash/map_storage.aji @@ -0,0 +1,48 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:26 +// phase: 6 +// spec: docs/spec/15-source-language.md §16–§17; docs/spec/03-memory-model.md §25–§26 +// Map storage prerequisite only; no std.map API is registered. +module test.map_storage +import std.option; + +enum SlotState { empty, deleted, occupied } +struct Slot { key: u64, state: SlotState, value: std.option.Option } + +fn drain(storage: mut>>>) -> u64 effects [] { + let slot = buffer.pop(storage) or trap; + let (key, state, value) = struct.unpack(move slot); + assert(key == 0xffffffffffffffffu64); + match state { + SlotState::occupied => {} + SlotState::empty => { trap; } + SlotState::deleted => { trap; } + } + match move value { + std.option.Option::>::some(owner) => { return own.take(move owner); } + std.option.Option::>::none => { trap; } + } +} + +fn main(heap: cap) -> u64 effects [mem.alloc] { + let storage = buffer.new>>(1, heap) or trap; + let owner = own.new(42u64, heap) or trap; + let slot = Slot::> { key: 0xffffffffffffffffu64, state: SlotState::occupied, value: std.option.Option::>::some(move owner) }; + { mut slots = storage; buffer.push(slots, move slot) or trap; } + { + ref values = storage; + ref slots = buffer.view(values); + ref current = slots[0]; + assert(current.key == 0xffffffffffffffffu64); + match current.state { + SlotState::occupied => {} + SlotState::empty => { trap; } + SlotState::deleted => { trap; } + } + } + var answer: u64 = 0; + { mut values = storage; answer = drain(values); } + buffer.free(move storage) or trap; + return answer; +} diff --git a/tests/conformance/source/hash/missing_import.aji b/tests/conformance/source/hash/missing_import.aji new file mode 100644 index 0000000..2962ef6 --- /dev/null +++ b/tests/conformance/source/hash/missing_import.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +fn main() -> u64 effects [] { return std.hash.fnv1a64(b"a"); } diff --git a/tests/conformance/source/hash/patterns.aji b/tests/conformance/source/hash/patterns.aji new file mode 100644 index 0000000..b6a7ff4 --- /dev/null +++ b/tests/conformance/source/hash/patterns.aji @@ -0,0 +1,37 @@ +// expect: run +// result: 42 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; + +fn fixture(data: slice, fnv: u64, crc: u32, extended_fnv: u64, extended_crc: u32) -> void effects [] { + assert(std.hash.fnv1a64(data) == fnv); + assert(std.hash.crc32c(data) == crc); + assert(std.hash.fnv1a64_extend(0xffffffffffffffffu64, data) == extended_fnv); + assert(std.hash.crc32c_extend(0x12345678u32, data) == extended_crc); +} +fn main() -> u64 effects [] { + fixture(ref b"\x13\x5c", 0x086c2a07b51c487au64, 0xe6253bc9u32, 0xffbc5bffffc6cf88u64, 0xb3ec03f9u32); + fixture(ref b"\x13\x5c\xa5", 0x6c144a18bf0fd2edu64, 0x7e1e2ad8u32, 0x53df80ff9ed20977u64, 0x4ea8aa51u32); + fixture(ref b"\x13\x5c\xa5\xee", 0xb64beb0ca7e1db19u64, 0x4441e322u32, 0x56d1cb5adee64efbu64, 0xbe35b516u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9", 0x0a56e73fbb474e15u64, 0x970d06f8u32, 0x1b3776e7aea8b01fu64, 0x872a8123u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12", 0xd8f8f84b3a2995e5u64, 0xda38de75u32, 0xe7ef18adc8a32617u64, 0x9072b362u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b", 0xd8a3a5d3d4a971dau64, 0xde625a76u32, 0xbe6d3b4bed3a1324u64, 0x1abcb39fu32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11", 0xd4cc78e5b3e42d0du64, 0x81cf75ffu32, 0x99317233964ef62fu64, 0xd6d39720u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a", 0x7b9ec550acb90ad5u64, 0xc5463d9eu32, 0x9dfb82a8682cc8cfu64, 0x48d1fcf3u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3", 0xc7d3be157e6cc682u64, 0xdd73100eu32, 0x9f27702904188f84u64, 0x0310587eu32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1", 0xa4730c0d1834560du64, 0x472610ffu32, 0x81b1f0d0a970664fu64, 0x6e1a1285u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea", 0xa3d4614020efaa85u64, 0x7795a632u32, 0xd1c2d78fe9fe6a5fu64, 0x6dc6e605u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33", 0x518bf5f7f73f1342u64, 0xa06145f4u32, 0x6c7eb58a9b4ed584u64, 0x44523beeu32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1", 0x8e60a69459d6840du64, 0xb593e760u32, 0x191d98f83277624fu64, 0x2ef582c5u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a", 0xc4bf1514a78257e5u64, 0x58ec7becu32, 0x24ad32bdc0dbfb3fu64, 0xcfcdbc33u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a\x53", 0xd3088818a27b0a42u64, 0xbe23f1c7u32, 0x2e48a46eb5cc3884u64, 0x33740d8fu32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a\x53\x9c\xe5\x2e\x77\xc0\x09\x52\x9b\xe4\x2d\x76\xbf\x08\x51\x9a\xe3\x2c\x75\xbe\x07\x50\x99\xe2\x2b\x74\xbd\x06\x4f\x98\xe1\x2a\x73\xbc\x05\x4e\x97\xe0\x29\x72\xbb\x04\x4d\x96\xdf\x28\x71\xba\x03\x4c\x95\xde\x27\x70\xb9\x02\x4b\x94\xdd\x26\x6f\xb8\x01", 0x41a1c0b5a1f2b90du64, 0x521667dau32, 0x4b5aa1022b08034fu64, 0xd65fb5cbu32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a\x53\x9c\xe5\x2e\x77\xc0\x09\x52\x9b\xe4\x2d\x76\xbf\x08\x51\x9a\xe3\x2c\x75\xbe\x07\x50\x99\xe2\x2b\x74\xbd\x06\x4f\x98\xe1\x2a\x73\xbc\x05\x4e\x97\xe0\x29\x72\xbb\x04\x4d\x96\xdf\x28\x71\xba\x03\x4c\x95\xde\x27\x70\xb9\x02\x4b\x94\xdd\x26\x6f\xb8\x01\x4a", 0x7893bba22f70d3a5u64, 0xc087b921u32, 0x13029baf1e9d217fu64, 0x2236b49fu32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a\x53\x9c\xe5\x2e\x77\xc0\x09\x52\x9b\xe4\x2d\x76\xbf\x08\x51\x9a\xe3\x2c\x75\xbe\x07\x50\x99\xe2\x2b\x74\xbd\x06\x4f\x98\xe1\x2a\x73\xbc\x05\x4e\x97\xe0\x29\x72\xbb\x04\x4d\x96\xdf\x28\x71\xba\x03\x4c\x95\xde\x27\x70\xb9\x02\x4b\x94\xdd\x26\x6f\xb8\x01\x4a\x93", 0x53db0a969cb6e4c2u64, 0x0193d6d6u32, 0xea9076910500a404u64, 0x1f1caa35u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a\x53\x9c\xe5\x2e\x77\xc0\x09\x52\x9b\xe4\x2d\x76\xbf\x08\x51\x9a\xe3\x2c\x75\xbe\x07\x50\x99\xe2\x2b\x74\xbd\x06\x4f\x98\xe1\x2a\x73\xbc\x05\x4e\x97\xe0\x29\x72\xbb\x04\x4d\x96\xdf\x28\x71\xba\x03\x4c\x95\xde\x27\x70\xb9\x02\x4b\x94\xdd\x26\x6f\xb8\x01\x4a\x93\xdc\x25\x6e\xb7\x00\x49\x92\xdb\x24\x6d\xb6\xff\x48\x91\xda\x23\x6c\xb5\xfe\x47\x90\xd9\x22\x6b\xb4\xfd\x46\x8f\xd8\x21\x6a\xb3\xfc\x45\x8e\xd7\x20\x69\xb2\xfb\x44\x8d\xd6\x1f\x68\xb1\xfa\x43\x8c\xd5\x1e\x67\xb0\xf9\x42\x8b\xd4\x1d\x66\xaf\xf8\x41\x8a\xd3\x1c\x65\xae\xf7\x40\x89\xd2\x1b\x64\xad\xf6\x3f\x88\xd1\x1a\x63\xac\xf5\x3e\x87\xd0\x19\x62\xab\xf4\x3d\x86\xcf\x18\x61\xaa\xf3\x3c\x85\xce\x17\x60\xa9\xf2\x3b\x84\xcd\x16\x5f\xa8\xf1\x3a\x83\xcc\x15\x5e\xa7\xf0\x39\x82\xcb\x14\x5d\xa6\xef\x38\x81", 0xf6a9671c820d770du64, 0xc66153dau32, 0x336c2332e699084fu64, 0x08f91272u32); + fixture(ref b"\x13\x5c\xa5\xee\x37\x80\xc9\x12\x5b\xa4\xed\x36\x7f\xc8\x11\x5a\xa3\xec\x35\x7e\xc7\x10\x59\xa2\xeb\x34\x7d\xc6\x0f\x58\xa1\xea\x33\x7c\xc5\x0e\x57\xa0\xe9\x32\x7b\xc4\x0d\x56\x9f\xe8\x31\x7a\xc3\x0c\x55\x9e\xe7\x30\x79\xc2\x0b\x54\x9d\xe6\x2f\x78\xc1\x0a\x53\x9c\xe5\x2e\x77\xc0\x09\x52\x9b\xe4\x2d\x76\xbf\x08\x51\x9a\xe3\x2c\x75\xbe\x07\x50\x99\xe2\x2b\x74\xbd\x06\x4f\x98\xe1\x2a\x73\xbc\x05\x4e\x97\xe0\x29\x72\xbb\x04\x4d\x96\xdf\x28\x71\xba\x03\x4c\x95\xde\x27\x70\xb9\x02\x4b\x94\xdd\x26\x6f\xb8\x01\x4a\x93\xdc\x25\x6e\xb7\x00\x49\x92\xdb\x24\x6d\xb6\xff\x48\x91\xda\x23\x6c\xb5\xfe\x47\x90\xd9\x22\x6b\xb4\xfd\x46\x8f\xd8\x21\x6a\xb3\xfc\x45\x8e\xd7\x20\x69\xb2\xfb\x44\x8d\xd6\x1f\x68\xb1\xfa\x43\x8c\xd5\x1e\x67\xb0\xf9\x42\x8b\xd4\x1d\x66\xaf\xf8\x41\x8a\xd3\x1c\x65\xae\xf7\x40\x89\xd2\x1b\x64\xad\xf6\x3f\x88\xd1\x1a\x63\xac\xf5\x3e\x87\xd0\x19\x62\xab\xf4\x3d\x86\xcf\x18\x61\xaa\xf3\x3c\x85\xce\x17\x60\xa9\xf2\x3b\x84\xcd\x16\x5f\xa8\xf1\x3a\x83\xcc\x15\x5e\xa7\xf0\x39\x82\xcb\x14\x5d\xa6\xef\x38\x81\xca", 0x2f51fc70fce28725u64, 0x42e5f56du32, 0xf9c8547dd60979ffu64, 0x6ab98045u32); + return 42; +} diff --git a/tests/conformance/source/hash/shared.aji b/tests/conformance/source/hash/shared.aji new file mode 100644 index 0000000..0b51885 --- /dev/null +++ b/tests/conformance/source/hash/shared.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// schedules: 8 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; + +fn worker(data: slice) -> u32 effects [] { return std.hash.crc32c(data); } +fn main() -> u64 effects [task.spawn, task.wait] { + var data: [u8; 9] = zero; + { mut dst = data; for index in 0usize..9usize { dst[index] = (index as! u8) + 49u8; } } + { ref bytes = data; ref input = bytes[0..9]; + scope s { + let first = task.spawn(s, worker, input); + let second = task.spawn(s, worker, input); + assert(std.hash.fnv1a64(ref bytes[0..9]) == std.hash.fnv1a64(b"123456789")); + let a = task.join(move first); let b = task.join(move second); + assert(a == 0xe3069283u32 and a == b); + } + } + data[0] = 0; + return 42; +} diff --git a/tests/conformance/source/hash/single_bytes.aji b/tests/conformance/source/hash/single_bytes.aji new file mode 100644 index 0000000..de1b8b0 --- /dev/null +++ b/tests/conformance/source/hash/single_bytes.aji @@ -0,0 +1,273 @@ +// expect: run +// result: 42 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; + +fn fixture(data: slice, fnv: u64, crc: u32, extended_fnv: u64, extended_crc: u32) -> void effects [] { + assert(std.hash.fnv1a64(data) == fnv); + assert(std.hash.crc32c(data) == crc); + assert(std.hash.fnv1a64_extend(0xffffffffffffffffu64, data) == extended_fnv); + assert(std.hash.crc32c_extend(0x12345678u32, data) == extended_crc); +} +fn main() -> u64 effects [] { + fixture(ref b"\x00", 0xaf63bd4c8601b7dfu64, 0x527d5351u32, 0xfffffefffffffe4du64, 0xa92e6bc5u32); + fixture(ref b"\x01", 0xaf63bc4c8601b62cu64, 0xa016d052u32, 0xfffffdfffffffc9au64, 0x5b45e8c6u32); + fixture(ref b"\x02", 0xaf63bf4c8601bb45u64, 0xb34623a6u32, 0xfffffcfffffffae7u64, 0x48151b32u32); + fixture(ref b"\x03", 0xaf63be4c8601b992u64, 0x412da0a5u32, 0xfffffbfffffff934u64, 0xba7e9831u32); + fixture(ref b"\x04", 0xaf63b94c8601b113u64, 0x95e7c44eu32, 0xfffffafffffff781u64, 0x6eb4fcdau32); + fixture(ref b"\x05", 0xaf63b84c8601af60u64, 0x678c474du32, 0xfffff9fffffff5ceu64, 0x9cdf7fd9u32); + fixture(ref b"\x06", 0xaf63bb4c8601b479u64, 0x74dcb4b9u32, 0xfffff8fffffff41bu64, 0x8f8f8c2du32); + fixture(ref b"\x07", 0xaf63ba4c8601b2c6u64, 0x86b737bau32, 0xfffff7fffffff268u64, 0x7de40f2eu32); + fixture(ref b"\x08", 0xaf63c54c8601c577u64, 0xd8a40b9eu32, 0xfffff6fffffff0b5u64, 0x23f7330au32); + fixture(ref b"\x09", 0xaf63c44c8601c3c4u64, 0x2acf889du32, 0xfffff5ffffffef02u64, 0xd19cb009u32); + fixture(ref b"\x0a", 0xaf63c74c8601c8ddu64, 0x399f7b69u32, 0xfffff4ffffffed4fu64, 0xc2cc43fdu32); + fixture(ref b"\x0b", 0xaf63c64c8601c72au64, 0xcbf4f86au32, 0xfffff3ffffffeb9cu64, 0x30a7c0feu32); + fixture(ref b"\x0c", 0xaf63c14c8601beabu64, 0x1f3e9c81u32, 0xfffff2ffffffe9e9u64, 0xe46da415u32); + fixture(ref b"\x0d", 0xaf63c04c8601bcf8u64, 0xed551f82u32, 0xfffff1ffffffe836u64, 0x16062716u32); + fixture(ref b"\x0e", 0xaf63c34c8601c211u64, 0xfe05ec76u32, 0xfffff0ffffffe683u64, 0x0556d4e2u32); + fixture(ref b"\x0f", 0xaf63c24c8601c05eu64, 0x0c6e6f75u32, 0xffffefffffffe4d0u64, 0xf73d57e1u32); + fixture(ref b"\x10", 0xaf63cd4c8601d30fu64, 0x4223943eu32, 0xffffeeffffffe31du64, 0xb970acaau32); + fixture(ref b"\x11", 0xaf63cc4c8601d15cu64, 0xb048173du32, 0xffffedffffffe16au64, 0x4b1b2fa9u32); + fixture(ref b"\x12", 0xaf63cf4c8601d675u64, 0xa318e4c9u32, 0xffffecffffffdfb7u64, 0x584bdc5du32); + fixture(ref b"\x13", 0xaf63ce4c8601d4c2u64, 0x517367cau32, 0xffffebffffffde04u64, 0xaa205f5eu32); + fixture(ref b"\x14", 0xaf63c94c8601cc43u64, 0x85b90321u32, 0xffffeaffffffdc51u64, 0x7eea3bb5u32); + fixture(ref b"\x15", 0xaf63c84c8601ca90u64, 0x77d28022u32, 0xffffe9ffffffda9eu64, 0x8c81b8b6u32); + fixture(ref b"\x16", 0xaf63cb4c8601cfa9u64, 0x648273d6u32, 0xffffe8ffffffd8ebu64, 0x9fd14b42u32); + fixture(ref b"\x17", 0xaf63ca4c8601cdf6u64, 0x96e9f0d5u32, 0xffffe7ffffffd738u64, 0x6dbac841u32); + fixture(ref b"\x18", 0xaf63d54c8601e0a7u64, 0xc8faccf1u32, 0xffffe6ffffffd585u64, 0x33a9f465u32); + fixture(ref b"\x19", 0xaf63d44c8601def4u64, 0x3a914ff2u32, 0xffffe5ffffffd3d2u64, 0xc1c27766u32); + fixture(ref b"\x1a", 0xaf63d74c8601e40du64, 0x29c1bc06u32, 0xffffe4ffffffd21fu64, 0xd2928492u32); + fixture(ref b"\x1b", 0xaf63d64c8601e25au64, 0xdbaa3f05u32, 0xffffe3ffffffd06cu64, 0x20f90791u32); + fixture(ref b"\x1c", 0xaf63d14c8601d9dbu64, 0x0f605beeu32, 0xffffe2ffffffceb9u64, 0xf433637au32); + fixture(ref b"\x1d", 0xaf63d04c8601d828u64, 0xfd0bd8edu32, 0xffffe1ffffffcd06u64, 0x0658e079u32); + fixture(ref b"\x1e", 0xaf63d34c8601dd41u64, 0xee5b2b19u32, 0xffffe0ffffffcb53u64, 0x1508138du32); + fixture(ref b"\x1f", 0xaf63d24c8601db8eu64, 0x1c30a81au32, 0xffffdfffffffc9a0u64, 0xe763908eu32); + fixture(ref b"\x20", 0xaf639d4c8601817fu64, 0x72c0dd8fu32, 0xffffdeffffffc7edu64, 0x8993e51bu32); + fixture(ref b"\x21", 0xaf639c4c86017fccu64, 0x80ab5e8cu32, 0xffffddffffffc63au64, 0x7bf86618u32); + fixture(ref b"\x22", 0xaf639f4c860184e5u64, 0x93fbad78u32, 0xffffdcffffffc487u64, 0x68a895ecu32); + fixture(ref b"\x23", 0xaf639e4c86018332u64, 0x61902e7bu32, 0xffffdbffffffc2d4u64, 0x9ac316efu32); + fixture(ref b"\x24", 0xaf63994c86017ab3u64, 0xb55a4a90u32, 0xffffdaffffffc121u64, 0x4e097204u32); + fixture(ref b"\x25", 0xaf63984c86017900u64, 0x4731c993u32, 0xffffd9ffffffbf6eu64, 0xbc62f107u32); + fixture(ref b"\x26", 0xaf639b4c86017e19u64, 0x54613a67u32, 0xffffd8ffffffbdbbu64, 0xaf3202f3u32); + fixture(ref b"\x27", 0xaf639a4c86017c66u64, 0xa60ab964u32, 0xffffd7ffffffbc08u64, 0x5d5981f0u32); + fixture(ref b"\x28", 0xaf63a54c86018f17u64, 0xf8198540u32, 0xffffd6ffffffba55u64, 0x034abdd4u32); + fixture(ref b"\x29", 0xaf63a44c86018d64u64, 0x0a720643u32, 0xffffd5ffffffb8a2u64, 0xf1213ed7u32); + fixture(ref b"\x2a", 0xaf63a74c8601927du64, 0x1922f5b7u32, 0xffffd4ffffffb6efu64, 0xe271cd23u32); + fixture(ref b"\x2b", 0xaf63a64c860190cau64, 0xeb4976b4u32, 0xffffd3ffffffb53cu64, 0x101a4e20u32); + fixture(ref b"\x2c", 0xaf63a14c8601884bu64, 0x3f83125fu32, 0xffffd2ffffffb389u64, 0xc4d02acbu32); + fixture(ref b"\x2d", 0xaf63a04c86018698u64, 0xcde8915cu32, 0xffffd1ffffffb1d6u64, 0x36bba9c8u32); + fixture(ref b"\x2e", 0xaf63a34c86018bb1u64, 0xdeb862a8u32, 0xffffd0ffffffb023u64, 0x25eb5a3cu32); + fixture(ref b"\x2f", 0xaf63a24c860189feu64, 0x2cd3e1abu32, 0xffffcfffffffae70u64, 0xd780d93fu32); + fixture(ref b"\x30", 0xaf63ad4c86019cafu64, 0x629e1ae0u32, 0xffffceffffffacbdu64, 0x99cd2274u32); + fixture(ref b"\x31", 0xaf63ac4c86019afcu64, 0x90f599e3u32, 0xffffcdffffffab0au64, 0x6ba6a177u32); + fixture(ref b"\x32", 0xaf63af4c8601a015u64, 0x83a56a17u32, 0xffffccffffffa957u64, 0x78f65283u32); + fixture(ref b"\x33", 0xaf63ae4c86019e62u64, 0x71cee914u32, 0xffffcbffffffa7a4u64, 0x8a9dd180u32); + fixture(ref b"\x34", 0xaf63a94c860195e3u64, 0xa5048dffu32, 0xffffcaffffffa5f1u64, 0x5e57b56bu32); + fixture(ref b"\x35", 0xaf63a84c86019430u64, 0x576f0efcu32, 0xffffc9ffffffa43eu64, 0xac3c3668u32); + fixture(ref b"\x36", 0xaf63ab4c86019949u64, 0x443ffd08u32, 0xffffc8ffffffa28bu64, 0xbf6cc59cu32); + fixture(ref b"\x37", 0xaf63aa4c86019796u64, 0xb6547e0bu32, 0xffffc7ffffffa0d8u64, 0x4d07469fu32); + fixture(ref b"\x38", 0xaf63b54c8601aa47u64, 0xe847422fu32, 0xffffc6ffffff9f25u64, 0x13147abbu32); + fixture(ref b"\x39", 0xaf63b44c8601a894u64, 0x1a2cc12cu32, 0xffffc5ffffff9d72u64, 0xe17ff9b8u32); + fixture(ref b"\x3a", 0xaf63b74c8601adadu64, 0x097c32d8u32, 0xffffc4ffffff9bbfu64, 0xf22f0a4cu32); + fixture(ref b"\x3b", 0xaf63b64c8601abfau64, 0xfb17b1dbu32, 0xffffc3ffffff9a0cu64, 0x0044894fu32); + fixture(ref b"\x3c", 0xaf63b14c8601a37bu64, 0x2fddd530u32, 0xffffc2ffffff9859u64, 0xd48eeda4u32); + fixture(ref b"\x3d", 0xaf63b04c8601a1c8u64, 0xddb65633u32, 0xffffc1ffffff96a6u64, 0x26e56ea7u32); + fixture(ref b"\x3e", 0xaf63b34c8601a6e1u64, 0xcee6a5c7u32, 0xffffc0ffffff94f3u64, 0x35b59d53u32); + fixture(ref b"\x3f", 0xaf63b24c8601a52eu64, 0x3c8d26c4u32, 0xffffbfffffff9340u64, 0xc7de1e50u32); + fixture(ref b"\x40", 0xaf63fd4c8602249fu64, 0x13064eedu32, 0xffffbeffffff918du64, 0xe8557679u32); + fixture(ref b"\x41", 0xaf63fc4c860222ecu64, 0xe16dcdeeu32, 0xffffbdffffff8fdau64, 0x1a3ef57au32); + fixture(ref b"\x42", 0xaf63ff4c86022805u64, 0xf23d3e1au32, 0xffffbcffffff8e27u64, 0x096e068eu32); + fixture(ref b"\x43", 0xaf63fe4c86022652u64, 0x0056bd19u32, 0xffffbbffffff8c74u64, 0xfb05858du32); + fixture(ref b"\x44", 0xaf63f94c86021dd3u64, 0xd49cd9f2u32, 0xffffbaffffff8ac1u64, 0x2fcfe166u32); + fixture(ref b"\x45", 0xaf63f84c86021c20u64, 0x26f75af1u32, 0xffffb9ffffff890eu64, 0xdda46265u32); + fixture(ref b"\x46", 0xaf63fb4c86022139u64, 0x35a7a905u32, 0xffffb8ffffff875bu64, 0xcef49191u32); + fixture(ref b"\x47", 0xaf63fa4c86021f86u64, 0xc7cc2a06u32, 0xffffb7ffffff85a8u64, 0x3c9f1292u32); + fixture(ref b"\x48", 0xaf64054c86023237u64, 0x99df1622u32, 0xffffb6ffffff83f5u64, 0x628c2eb6u32); + fixture(ref b"\x49", 0xaf64044c86023084u64, 0x6bb49521u32, 0xffffb5ffffff8242u64, 0x90e7adb5u32); + fixture(ref b"\x4a", 0xaf64074c8602359du64, 0x78e466d5u32, 0xffffb4ffffff808fu64, 0x83b75e41u32); + fixture(ref b"\x4b", 0xaf64064c860233eau64, 0x8a8fe5d6u32, 0xffffb3ffffff7edcu64, 0x71dcdd42u32); + fixture(ref b"\x4c", 0xaf64014c86022b6bu64, 0x5e45813du32, 0xffffb2ffffff7d29u64, 0xa516b9a9u32); + fixture(ref b"\x4d", 0xaf64004c860229b8u64, 0xac2e023eu32, 0xffffb1ffffff7b76u64, 0x577d3aaau32); + fixture(ref b"\x4e", 0xaf64034c86022ed1u64, 0xbf7ef1cau32, 0xffffb0ffffff79c3u64, 0x442dc95eu32); + fixture(ref b"\x4f", 0xaf64024c86022d1eu64, 0x4d1572c9u32, 0xffffafffffff7810u64, 0xb6464a5du32); + fixture(ref b"\x50", 0xaf640d4c86023fcfu64, 0x03588982u32, 0xffffaeffffff765du64, 0xf80bb116u32); + fixture(ref b"\x51", 0xaf640c4c86023e1cu64, 0xf1330a81u32, 0xffffadffffff74aau64, 0x0a603215u32); + fixture(ref b"\x52", 0xaf640f4c86024335u64, 0xe263f975u32, 0xffffacffffff72f7u64, 0x1930c1e1u32); + fixture(ref b"\x53", 0xaf640e4c86024182u64, 0x10087a76u32, 0xffffabffffff7144u64, 0xeb5b42e2u32); + fixture(ref b"\x54", 0xaf64094c86023903u64, 0xc4c21e9du32, 0xffffaaffffff6f91u64, 0x3f912609u32); + fixture(ref b"\x55", 0xaf64084c86023750u64, 0x36a99d9eu32, 0xffffa9ffffff6ddeu64, 0xcdfaa50au32); + fixture(ref b"\x56", 0xaf640b4c86023c69u64, 0x25f96e6au32, 0xffffa8ffffff6c2bu64, 0xdeaa56feu32); + fixture(ref b"\x57", 0xaf640a4c86023ab6u64, 0xd792ed69u32, 0xffffa7ffffff6a78u64, 0x2cc1d5fdu32); + fixture(ref b"\x58", 0xaf64154c86024d67u64, 0x8981d14du32, 0xffffa6ffffff68c5u64, 0x72d2e9d9u32); + fixture(ref b"\x59", 0xaf64144c86024bb4u64, 0x7bea524eu32, 0xffffa5ffffff6712u64, 0x80b96adau32); + fixture(ref b"\x5a", 0xaf64174c860250cdu64, 0x68baa1bau32, 0xffffa4ffffff655fu64, 0x93e9992eu32); + fixture(ref b"\x5b", 0xaf64164c86024f1au64, 0x9ad122b9u32, 0xffffa3ffffff63acu64, 0x61821a2du32); + fixture(ref b"\x5c", 0xaf64114c8602469bu64, 0x4e1b4652u32, 0xffffa2ffffff61f9u64, 0xb5487ec6u32); + fixture(ref b"\x5d", 0xaf64104c860244e8u64, 0xbc70c551u32, 0xffffa1ffffff6046u64, 0x4723fdc5u32); + fixture(ref b"\x5e", 0xaf64134c86024a01u64, 0xaf2036a5u32, 0xffffa0ffffff5e93u64, 0x54730e31u32); + fixture(ref b"\x5f", 0xaf64124c8602484eu64, 0x5d4bb5a6u32, 0xffff9fffffff5ce0u64, 0xa6188d32u32); + fixture(ref b"\x60", 0xaf63dd4c8601ee3fu64, 0x33bbc033u32, 0xffff9effffff5b2du64, 0xc8e8f8a7u32); + fixture(ref b"\x61", 0xaf63dc4c8601ec8cu64, 0xc1d04330u32, 0xffff9dffffff597au64, 0x3a837ba4u32); + fixture(ref b"\x62", 0xaf63df4c8601f1a5u64, 0xd280b0c4u32, 0xffff9cffffff57c7u64, 0x29d38850u32); + fixture(ref b"\x63", 0xaf63de4c8601eff2u64, 0x20eb33c7u32, 0xffff9bffffff5614u64, 0xdbb80b53u32); + fixture(ref b"\x64", 0xaf63d94c8601e773u64, 0xf421572cu32, 0xffff9affffff5461u64, 0x0f726fb8u32); + fixture(ref b"\x65", 0xaf63d84c8601e5c0u64, 0x064ad42fu32, 0xffff99ffffff52aeu64, 0xfd19ecbbu32); + fixture(ref b"\x66", 0xaf63db4c8601ead9u64, 0x151a27dbu32, 0xffff98ffffff50fbu64, 0xee491f4fu32); + fixture(ref b"\x67", 0xaf63da4c8601e926u64, 0xe771a4d8u32, 0xffff97ffffff4f48u64, 0x1c229c4cu32); + fixture(ref b"\x68", 0xaf63e54c8601fbd7u64, 0xb96298fcu32, 0xffff96ffffff4d95u64, 0x4231a068u32); + fixture(ref b"\x69", 0xaf63e44c8601fa24u64, 0x4b091bffu32, 0xffff95ffffff4be2u64, 0xb05a236bu32); + fixture(ref b"\x6a", 0xaf63e74c8601ff3du64, 0x5859e80bu32, 0xffff94ffffff4a2fu64, 0xa30ad09fu32); + fixture(ref b"\x6b", 0xaf63e64c8601fd8au64, 0xaa326b08u32, 0xffff93ffffff487cu64, 0x5161539cu32); + fixture(ref b"\x6c", 0xaf63e14c8601f50bu64, 0x7ef80fe3u32, 0xffff92ffffff46c9u64, 0x85ab3777u32); + fixture(ref b"\x6d", 0xaf63e04c8601f358u64, 0x8c938ce0u32, 0xffff91ffffff4516u64, 0x77c0b474u32); + fixture(ref b"\x6e", 0xaf63e34c8601f871u64, 0x9fc37f14u32, 0xffff90ffffff4363u64, 0x64904780u32); + fixture(ref b"\x6f", 0xaf63e24c8601f6beu64, 0x6da8fc17u32, 0xffff8fffffff41b0u64, 0x96fbc483u32); + fixture(ref b"\x70", 0xaf63ed4c8602096fu64, 0x23e5075cu32, 0xffff8effffff3ffdu64, 0xd8b63fc8u32); + fixture(ref b"\x71", 0xaf63ec4c860207bcu64, 0xd18e845fu32, 0xffff8dffffff3e4au64, 0x2addbccbu32); + fixture(ref b"\x72", 0xaf63ef4c86020cd5u64, 0xc2de77abu32, 0xffff8cffffff3c97u64, 0x398d4f3fu32); + fixture(ref b"\x73", 0xaf63ee4c86020b22u64, 0x30b5f4a8u32, 0xffff8bffffff3ae4u64, 0xcbe6cc3cu32); + fixture(ref b"\x74", 0xaf63e94c860202a3u64, 0xe47f9043u32, 0xffff8affffff3931u64, 0x1f2ca8d7u32); + fixture(ref b"\x75", 0xaf63e84c860200f0u64, 0x16141340u32, 0xffff89ffffff377eu64, 0xed472bd4u32); + fixture(ref b"\x76", 0xaf63eb4c86020609u64, 0x0544e0b4u32, 0xffff88ffffff35cbu64, 0xfe17d820u32); + fixture(ref b"\x77", 0xaf63ea4c86020456u64, 0xf72f63b7u32, 0xffff87ffffff3418u64, 0x0c7c5b23u32); + fixture(ref b"\x78", 0xaf63f54c86021707u64, 0xa93c5f93u32, 0xffff86ffffff3265u64, 0x526f6707u32); + fixture(ref b"\x79", 0xaf63f44c86021554u64, 0x5b57dc90u32, 0xffff85ffffff30b2u64, 0xa004e404u32); + fixture(ref b"\x7a", 0xaf63f74c86021a6du64, 0x48072f64u32, 0xffff84ffffff2effu64, 0xb35417f0u32); + fixture(ref b"\x7b", 0xaf63f64c860218bau64, 0xba6cac67u32, 0xffff83ffffff2d4cu64, 0x413f94f3u32); + fixture(ref b"\x7c", 0xaf63f14c8602103bu64, 0x6ea6c88cu32, 0xffff82ffffff2b99u64, 0x95f5f018u32); + fixture(ref b"\x7d", 0xaf63f04c86020e88u64, 0x9ccd4b8fu32, 0xffff81ffffff29e6u64, 0x679e731bu32); + fixture(ref b"\x7e", 0xaf63f34c860213a1u64, 0x8f9db87bu32, 0xffff80ffffff2833u64, 0x74ce80efu32); + fixture(ref b"\x7f", 0xaf63f24c860211eeu64, 0x7df63b78u32, 0xffff7fffffff2680u64, 0x86a503ecu32); + fixture(ref b"\x80", 0xaf643d4c8602915fu64, 0xd08b6829u32, 0xffff7effffff24cdu64, 0x2bd850bdu32); + fixture(ref b"\x81", 0xaf643c4c86028facu64, 0x22e0eb2au32, 0xffff7dffffff231au64, 0xd9b3d3beu32); + fixture(ref b"\x82", 0xaf643f4c860294c5u64, 0x31b018deu32, 0xffff7cffffff2167u64, 0xcae3204au32); + fixture(ref b"\x83", 0xaf643e4c86029312u64, 0xc3db9bddu32, 0xffff7bffffff1fb4u64, 0x3888a349u32); + fixture(ref b"\x84", 0xaf64394c86028a93u64, 0x1711ff36u32, 0xffff7affffff1e01u64, 0xec42c7a2u32); + fixture(ref b"\x85", 0xaf64384c860288e0u64, 0xe57a7c35u32, 0xffff79ffffff1c4eu64, 0x1e2944a1u32); + fixture(ref b"\x86", 0xaf643b4c86028df9u64, 0xf62a8fc1u32, 0xffff78ffffff1a9bu64, 0x0d79b755u32); + fixture(ref b"\x87", 0xaf643a4c86028c46u64, 0x04410cc2u32, 0xffff77ffffff18e8u64, 0xff123456u32); + fixture(ref b"\x88", 0xaf64454c86029ef7u64, 0x5a5230e6u32, 0xffff76ffffff1735u64, 0xa1010872u32); + fixture(ref b"\x89", 0xaf64444c86029d44u64, 0xa839b3e5u32, 0xffff75ffffff1582u64, 0x536a8b71u32); + fixture(ref b"\x8a", 0xaf64474c8602a25du64, 0xbb694011u32, 0xffff74ffffff13cfu64, 0x403a7885u32); + fixture(ref b"\x8b", 0xaf64464c8602a0aau64, 0x4902c312u32, 0xffff73ffffff121cu64, 0xb251fb86u32); + fixture(ref b"\x8c", 0xaf64414c8602982bu64, 0x9dc8a7f9u32, 0xffff72ffffff1069u64, 0x669b9f6du32); + fixture(ref b"\x8d", 0xaf64404c86029678u64, 0x6fa324fau32, 0xffff71ffffff0eb6u64, 0x94f01c6eu32); + fixture(ref b"\x8e", 0xaf64434c86029b91u64, 0x7cf3d70eu32, 0xffff70ffffff0d03u64, 0x87a0ef9au32); + fixture(ref b"\x8f", 0xaf64424c860299deu64, 0x8e98540du32, 0xffff6fffffff0b50u64, 0x75cb6c99u32); + fixture(ref b"\x90", 0xaf644d4c8602ac8fu64, 0xc0d5af46u32, 0xffff6effffff099du64, 0x3b8697d2u32); + fixture(ref b"\x91", 0xaf644c4c8602aadcu64, 0x32be2c45u32, 0xffff6dffffff07eau64, 0xc9ed14d1u32); + fixture(ref b"\x92", 0xaf644f4c8602aff5u64, 0x21eedfb1u32, 0xffff6cffffff0637u64, 0xdabde725u32); + fixture(ref b"\x93", 0xaf644e4c8602ae42u64, 0xd3855cb2u32, 0xffff6bffffff0484u64, 0x28d66426u32); + fixture(ref b"\x94", 0xaf64494c8602a5c3u64, 0x074f3859u32, 0xffff6affffff02d1u64, 0xfc1c00cdu32); + fixture(ref b"\x95", 0xaf64484c8602a410u64, 0xf524bb5au32, 0xffff69ffffff011eu64, 0x0e7783ceu32); + fixture(ref b"\x96", 0xaf644b4c8602a929u64, 0xe67448aeu32, 0xffff68fffffeff6bu64, 0x1d27703au32); + fixture(ref b"\x97", 0xaf644a4c8602a776u64, 0x141fcbadu32, 0xffff67fffffefdb8u64, 0xef4cf339u32); + fixture(ref b"\x98", 0xaf64554c8602ba27u64, 0x4a0cf789u32, 0xffff66fffffefc05u64, 0xb15fcf1du32); + fixture(ref b"\x99", 0xaf64544c8602b874u64, 0xb867748au32, 0xffff65fffffefa52u64, 0x43344c1eu32); + fixture(ref b"\x9a", 0xaf64574c8602bd8du64, 0xab37877eu32, 0xffff64fffffef89fu64, 0x5064bfeau32); + fixture(ref b"\x9b", 0xaf64564c8602bbdau64, 0x595c047du32, 0xffff63fffffef6ecu64, 0xa20f3ce9u32); + fixture(ref b"\x9c", 0xaf64514c8602b35bu64, 0x8d966096u32, 0xffff62fffffef539u64, 0x76c55802u32); + fixture(ref b"\x9d", 0xaf64504c8602b1a8u64, 0x7ffde395u32, 0xffff61fffffef386u64, 0x84aedb01u32); + fixture(ref b"\x9e", 0xaf64534c8602b6c1u64, 0x6cad1061u32, 0xffff60fffffef1d3u64, 0x97fe28f5u32); + fixture(ref b"\x9f", 0xaf64524c8602b50eu64, 0x9ec69362u32, 0xffff5ffffffef020u64, 0x6595abf6u32); + fixture(ref b"\xa0", 0xaf641d4c86025affu64, 0xf036e6f7u32, 0xffff5efffffeee6du64, 0x0b65de63u32); + fixture(ref b"\xa1", 0xaf641c4c8602594cu64, 0x025d65f4u32, 0xffff5dfffffeecbau64, 0xf90e5d60u32); + fixture(ref b"\xa2", 0xaf641f4c86025e65u64, 0x110d9600u32, 0xffff5cfffffeeb07u64, 0xea5eae94u32); + fixture(ref b"\xa3", 0xaf641e4c86025cb2u64, 0xe3661503u32, 0xffff5bfffffee954u64, 0x18352d97u32); + fixture(ref b"\xa4", 0xaf64194c86025433u64, 0x37ac71e8u32, 0xffff5afffffee7a1u64, 0xccff497cu32); + fixture(ref b"\xa5", 0xaf64184c86025280u64, 0xc5c7f2ebu32, 0xffff59fffffee5eeu64, 0x3e94ca7fu32); + fixture(ref b"\xa6", 0xaf641b4c86025799u64, 0xd697011fu32, 0xffff58fffffee43bu64, 0x2dc4398bu32); + fixture(ref b"\xa7", 0xaf641a4c860255e6u64, 0x24fc821cu32, 0xffff57fffffee288u64, 0xdfafba88u32); + fixture(ref b"\xa8", 0xaf64254c86026897u64, 0x7aefbe38u32, 0xffff56fffffee0d5u64, 0x81bc86acu32); + fixture(ref b"\xa9", 0xaf64244c860266e4u64, 0x88843d3bu32, 0xffff55fffffedf22u64, 0x73d705afu32); + fixture(ref b"\xaa", 0xaf64274c86026bfdu64, 0x9bd4cecfu32, 0xffff54fffffedd6fu64, 0x6087f65bu32); + fixture(ref b"\xab", 0xaf64264c86026a4au64, 0x69bf4dccu32, 0xffff53fffffedbbcu64, 0x92ec7558u32); + fixture(ref b"\xac", 0xaf64214c860261cbu64, 0xbd752927u32, 0xffff52fffffeda09u64, 0x462611b3u32); + fixture(ref b"\xad", 0xaf64204c86026018u64, 0x4f1eaa24u32, 0xffff51fffffed856u64, 0xb44d92b0u32); + fixture(ref b"\xae", 0xaf64234c86026531u64, 0x5c4e59d0u32, 0xffff50fffffed6a3u64, 0xa71d6144u32); + fixture(ref b"\xaf", 0xaf64224c8602637eu64, 0xae25dad3u32, 0xffff4ffffffed4f0u64, 0x5576e247u32); + fixture(ref b"\xb0", 0xaf642d4c8602762fu64, 0xe0682198u32, 0xffff4efffffed33du64, 0x1b3b190cu32); + fixture(ref b"\xb1", 0xaf642c4c8602747cu64, 0x1203a29bu32, 0xffff4dfffffed18au64, 0xe9509a0fu32); + fixture(ref b"\xb2", 0xaf642f4c86027995u64, 0x0153516fu32, 0xffff4cfffffecfd7u64, 0xfa0069fbu32); + fixture(ref b"\xb3", 0xaf642e4c860277e2u64, 0xf338d26cu32, 0xffff4bfffffece24u64, 0x086beaf8u32); + fixture(ref b"\xb4", 0xaf64294c86026f63u64, 0x27f2b687u32, 0xffff4afffffecc71u64, 0xdca18e13u32); + fixture(ref b"\xb5", 0xaf64284c86026db0u64, 0xd5993584u32, 0xffff49fffffecabeu64, 0x2eca0d10u32); + fixture(ref b"\xb6", 0xaf642b4c860272c9u64, 0xc6c9c670u32, 0xffff48fffffec90bu64, 0x3d9afee4u32); + fixture(ref b"\xb7", 0xaf642a4c86027116u64, 0x34a24573u32, 0xffff47fffffec758u64, 0xcff17de7u32); + fixture(ref b"\xb8", 0xaf64354c860283c7u64, 0x6ab17957u32, 0xffff46fffffec5a5u64, 0x91e241c3u32); + fixture(ref b"\xb9", 0xaf64344c86028214u64, 0x98dafa54u32, 0xffff45fffffec3f2u64, 0x6389c2c0u32); + fixture(ref b"\xba", 0xaf64374c8602872du64, 0x8b8a09a0u32, 0xffff44fffffec23fu64, 0x70d93134u32); + fixture(ref b"\xbb", 0xaf64364c8602857au64, 0x79e18aa3u32, 0xffff43fffffec08cu64, 0x82b2b237u32); + fixture(ref b"\xbc", 0xaf64314c86027cfbu64, 0xad2bee48u32, 0xffff42fffffebed9u64, 0x5678d6dcu32); + fixture(ref b"\xbd", 0xaf64304c86027b48u64, 0x5f406d4bu32, 0xffff41fffffebd26u64, 0xa41355dfu32); + fixture(ref b"\xbe", 0xaf64334c86028061u64, 0x4c109ebfu32, 0xffff40fffffebb73u64, 0xb743a62bu32); + fixture(ref b"\xbf", 0xaf64324c86027eaeu64, 0xbe7b1dbcu32, 0xffff3ffffffeb9c0u64, 0x45282528u32); + fixture(ref b"\xc0", 0xaf647d4c8602fe1fu64, 0x91f07595u32, 0xffff3efffffeb80du64, 0x6aa34d01u32); + fixture(ref b"\xc1", 0xaf647c4c8602fc6cu64, 0x639bf696u32, 0xffff3dfffffeb65au64, 0x98c8ce02u32); + fixture(ref b"\xc2", 0xaf647f4c86030185u64, 0x70cb0562u32, 0xffff3cfffffeb4a7u64, 0x8b983df6u32); + fixture(ref b"\xc3", 0xaf647e4c8602ffd2u64, 0x82a08661u32, 0xffff3bfffffeb2f4u64, 0x79f3bef5u32); + fixture(ref b"\xc4", 0xaf64794c8602f753u64, 0x566ae28au32, 0xffff3afffffeb141u64, 0xad39da1eu32); + fixture(ref b"\xc5", 0xaf64784c8602f5a0u64, 0xa4016189u32, 0xffff39fffffeaf8eu64, 0x5f52591du32); + fixture(ref b"\xc6", 0xaf647b4c8602fab9u64, 0xb751927du32, 0xffff38fffffeaddbu64, 0x4c02aae9u32); + fixture(ref b"\xc7", 0xaf647a4c8602f906u64, 0x453a117eu32, 0xffff37fffffeac28u64, 0xbe6929eau32); + fixture(ref b"\xc8", 0xaf64854c86030bb7u64, 0x1b292d5au32, 0xffff36fffffeaa75u64, 0xe07a15ceu32); + fixture(ref b"\xc9", 0xaf64844c86030a04u64, 0xe942ae59u32, 0xffff35fffffea8c2u64, 0x121196cdu32); + fixture(ref b"\xca", 0xaf64874c86030f1du64, 0xfa125dadu32, 0xffff34fffffea70fu64, 0x01416539u32); + fixture(ref b"\xcb", 0xaf64864c86030d6au64, 0x0879deaeu32, 0xffff33fffffea55cu64, 0xf32ae63au32); + fixture(ref b"\xcc", 0xaf64814c860304ebu64, 0xdcb3ba45u32, 0xffff32fffffea3a9u64, 0x27e082d1u32); + fixture(ref b"\xcd", 0xaf64804c86030338u64, 0x2ed83946u32, 0xffff31fffffea1f6u64, 0xd58b01d2u32); + fixture(ref b"\xce", 0xaf64834c86030851u64, 0x3d88cab2u32, 0xffff30fffffea043u64, 0xc6dbf226u32); + fixture(ref b"\xcf", 0xaf64824c8603069eu64, 0xcfe349b1u32, 0xffff2ffffffe9e90u64, 0x34b07125u32); + fixture(ref b"\xd0", 0xaf648d4c8603194fu64, 0x81aeb2fau32, 0xffff2efffffe9cddu64, 0x7afd8a6eu32); + fixture(ref b"\xd1", 0xaf648c4c8603179cu64, 0x73c531f9u32, 0xffff2dfffffe9b2au64, 0x8896096du32); + fixture(ref b"\xd2", 0xaf648f4c86031cb5u64, 0x6095c20du32, 0xffff2cfffffe9977u64, 0x9bc6fa99u32); + fixture(ref b"\xd3", 0xaf648e4c86031b02u64, 0x92fe410eu32, 0xffff2bfffffe97c4u64, 0x69ad799au32); + fixture(ref b"\xd4", 0xaf64894c86031283u64, 0x463425e5u32, 0xffff2afffffe9611u64, 0xbd671d71u32); + fixture(ref b"\xd5", 0xaf64884c860310d0u64, 0xb45fa6e6u32, 0xffff29fffffe945eu64, 0x4f0c9e72u32); + fixture(ref b"\xd6", 0xaf648b4c860315e9u64, 0xa70f5512u32, 0xffff28fffffe92abu64, 0x5c5c6d86u32); + fixture(ref b"\xd7", 0xaf648a4c86031436u64, 0x5564d611u32, 0xffff27fffffe90f8u64, 0xae37ee85u32); + fixture(ref b"\xd8", 0xaf64954c860326e7u64, 0x0b77ea35u32, 0xffff26fffffe8f45u64, 0xf024d2a1u32); + fixture(ref b"\xd9", 0xaf64944c86032534u64, 0xf91c6936u32, 0xffff25fffffe8d92u64, 0x024f51a2u32); + fixture(ref b"\xda", 0xaf64974c86032a4du64, 0xea4c9ac2u32, 0xffff24fffffe8bdfu64, 0x111fa256u32); + fixture(ref b"\xdb", 0xaf64964c8603289au64, 0x182719c1u32, 0xffff23fffffe8a2cu64, 0xe3742155u32); + fixture(ref b"\xdc", 0xaf64914c8603201bu64, 0xcced7d2au32, 0xffff22fffffe8879u64, 0x37be45beu32); + fixture(ref b"\xdd", 0xaf64904c86031e68u64, 0x3e86fe29u32, 0xffff21fffffe86c6u64, 0xc5d5c6bdu32); + fixture(ref b"\xde", 0xaf64934c86032381u64, 0x2dd60dddu32, 0xffff20fffffe8513u64, 0xd6853549u32); + fixture(ref b"\xdf", 0xaf64924c860321ceu64, 0xdfbd8edeu32, 0xffff1ffffffe8360u64, 0x24eeb64au32); + fixture(ref b"\xe0", 0xaf645d4c8602c7bfu64, 0xb14dfb4bu32, 0xffff1efffffe81adu64, 0x4a1ec3dfu32); + fixture(ref b"\xe1", 0xaf645c4c8602c60cu64, 0x43267848u32, 0xffff1dfffffe7ffau64, 0xb87540dcu32); + fixture(ref b"\xe2", 0xaf645f4c8602cb25u64, 0x50768bbcu32, 0xffff1cfffffe7e47u64, 0xab25b328u32); + fixture(ref b"\xe3", 0xaf645e4c8602c972u64, 0xa21d08bfu32, 0xffff1bfffffe7c94u64, 0x594e302bu32); + fixture(ref b"\xe4", 0xaf64594c8602c0f3u64, 0x76d76c54u32, 0xffff1afffffe7ae1u64, 0x8d8454c0u32); + fixture(ref b"\xe5", 0xaf64584c8602bf40u64, 0x84bcef57u32, 0xffff19fffffe792eu64, 0x7fefd7c3u32); + fixture(ref b"\xe6", 0xaf645b4c8602c459u64, 0x97ec1ca3u32, 0xffff18fffffe777bu64, 0x6cbf2437u32); + fixture(ref b"\xe7", 0xaf645a4c8602c2a6u64, 0x65879fa0u32, 0xffff17fffffe75c8u64, 0x9ed4a734u32); + fixture(ref b"\xe8", 0xaf64654c8602d557u64, 0x3b94a384u32, 0xffff16fffffe7415u64, 0xc0c79b10u32); + fixture(ref b"\xe9", 0xaf64644c8602d3a4u64, 0xc9ff2087u32, 0xffff15fffffe7262u64, 0x32ac1813u32); + fixture(ref b"\xea", 0xaf64674c8602d8bdu64, 0xdaafd373u32, 0xffff14fffffe70afu64, 0x21fcebe7u32); + fixture(ref b"\xeb", 0xaf64664c8602d70au64, 0x28c45070u32, 0xffff13fffffe6efcu64, 0xd39768e4u32); + fixture(ref b"\xec", 0xaf64614c8602ce8bu64, 0xfc0e349bu32, 0xffff12fffffe6d49u64, 0x075d0c0fu32); + fixture(ref b"\xed", 0xaf64604c8602ccd8u64, 0x0e65b798u32, 0xffff11fffffe6b96u64, 0xf5368f0cu32); + fixture(ref b"\xee", 0xaf64634c8602d1f1u64, 0x1d35446cu32, 0xffff10fffffe69e3u64, 0xe6667cf8u32); + fixture(ref b"\xef", 0xaf64624c8602d03eu64, 0xef5ec76fu32, 0xffff0ffffffe6830u64, 0x140dfffbu32); + fixture(ref b"\xf0", 0xaf646d4c8602e2efu64, 0xa1133c24u32, 0xffff0efffffe667du64, 0x5a4004b0u32); + fixture(ref b"\xf1", 0xaf646c4c8602e13cu64, 0x5378bf27u32, 0xffff0dfffffe64cau64, 0xa82b87b3u32); + fixture(ref b"\xf2", 0xaf646f4c8602e655u64, 0x40284cd3u32, 0xffff0cfffffe6317u64, 0xbb7b7447u32); + fixture(ref b"\xf3", 0xaf646e4c8602e4a2u64, 0xb243cfd0u32, 0xffff0bfffffe6164u64, 0x4910f744u32); + fixture(ref b"\xf4", 0xaf64694c8602dc23u64, 0x6689ab3bu32, 0xffff0afffffe5fb1u64, 0x9dda93afu32); + fixture(ref b"\xf5", 0xaf64684c8602da70u64, 0x94e22838u32, 0xffff09fffffe5dfeu64, 0x6fb110acu32); + fixture(ref b"\xf6", 0xaf646b4c8602df89u64, 0x87b2dbccu32, 0xffff08fffffe5c4bu64, 0x7ce1e358u32); + fixture(ref b"\xf7", 0xaf646a4c8602ddd6u64, 0x75d958cfu32, 0xffff07fffffe5a98u64, 0x8e8a605bu32); + fixture(ref b"\xf8", 0xaf64754c8602f087u64, 0x2bca64ebu32, 0xffff06fffffe58e5u64, 0xd0995c7fu32); + fixture(ref b"\xf9", 0xaf64744c8602eed4u64, 0xd9a1e7e8u32, 0xffff05fffffe5732u64, 0x22f2df7cu32); + fixture(ref b"\xfa", 0xaf64774c8602f3edu64, 0xcaf1141cu32, 0xffff04fffffe557fu64, 0x31a22c88u32); + fixture(ref b"\xfb", 0xaf64764c8602f23au64, 0x389a971fu32, 0xffff03fffffe53ccu64, 0xc3c9af8bu32); + fixture(ref b"\xfc", 0xaf64714c8602e9bbu64, 0xec50f3f4u32, 0xffff02fffffe5219u64, 0x1703cb60u32); + fixture(ref b"\xfd", 0xaf64704c8602e808u64, 0x1e3b70f7u32, 0xffff01fffffe5066u64, 0xe5684863u32); + fixture(ref b"\xfe", 0xaf64734c8602ed21u64, 0x0d6b8303u32, 0xffff00fffffe4eb3u64, 0xf638bb97u32); + fixture(ref b"\xff", 0xaf64724c8602eb6eu64, 0xff000000u32, 0xfffefffffffe4d00u64, 0x04533894u32); + return 42; +} diff --git a/tests/conformance/source/hash/streaming.aji b/tests/conformance/source/hash/streaming.aji new file mode 100644 index 0000000..0366d9c --- /dev/null +++ b/tests/conformance/source/hash/streaming.aji @@ -0,0 +1,41 @@ +// expect: run +// result: 42 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; + +fn check(data: slice) -> void effects [] { + let fnv = std.hash.fnv1a64(data); + let crc = std.hash.crc32c(data); + for split in 0usize..data.len + 1usize { + let first = std.hash.fnv1a64(ref data[0..split]); + assert(std.hash.fnv1a64_extend(first, ref data[split..data.len]) == fnv); + let prefix = std.hash.crc32c(ref data[0..split]); + assert(std.hash.crc32c_extend(prefix, ref data[split..data.len]) == crc); + let custom_fnv = std.hash.fnv1a64_extend(0u64, ref data[0..split]); + assert(std.hash.fnv1a64_extend(custom_fnv, ref data[split..data.len]) == std.hash.fnv1a64_extend(0u64, data)); + let custom_crc = std.hash.crc32c_extend(0xffffffffu32, ref data[0..split]); + assert(std.hash.crc32c_extend(custom_crc, ref data[split..data.len]) == std.hash.crc32c_extend(0xffffffffu32, data)); + } + var incremental_fnv: u64 = std.hash.fnv1a64(ref data[0..0]); + var incremental_crc: u32 = 0; + for index in 0usize..data.len { + incremental_fnv = std.hash.fnv1a64_extend(incremental_fnv, ref data[index..index + 1usize]); + incremental_crc = std.hash.crc32c_extend(incremental_crc, ref data[index..index + 1usize]); + } + assert(incremental_fnv == fnv); + assert(incremental_crc == crc); +} +fn main() -> u64 effects [] { + var empty: [u8; 1] = zero; + check(ref empty[0..0]); + check(b"a"); + check(b"123456789"); + check(b"\x00\xff\x80\x01\x00"); + check(b"abcdefghijklmnopqrstuvwxyz012345"); + assert(std.hash.fnv1a64_extend(0u64, ref empty[0..0]) == 0u64); + assert(std.hash.crc32c_extend(0xffffffffu32, ref empty[0..0]) == 0xffffffffu32); + return 42; +} diff --git a/tests/conformance/source/hash/wrong_slice.aji b/tests/conformance/source/hash/wrong_slice.aji new file mode 100644 index 0000000..7b58841 --- /dev/null +++ b/tests/conformance/source/hash/wrong_slice.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; +fn main() -> u64 effects [] { var data: [u64; 1] = zero; return std.hash.fnv1a64(ref data); } diff --git a/tests/conformance/source/hash/wrong_state.aji b/tests/conformance/source/hash/wrong_state.aji new file mode 100644 index 0000000..26454cc --- /dev/null +++ b/tests/conformance/source/hash/wrong_state.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.12 +module test.hash +import std.hash; +fn main() -> u64 effects [] { return std.hash.crc32c_extend(0u64, b"a"); } diff --git a/tests/conformance/source/hashmap/alias.aji b/tests/conformance/source/hashmap/alias.aji new file mode 100644 index 0000000..94ba7c6 --- /dev/null +++ b/tests/conformance/source/hashmap/alias.aji @@ -0,0 +1,30 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(map: mut>) -> void effects [] { + ref entries = map.entries; ref view = buffer.view(entries); + inserted::(std.hashmap.insert::(map, Key { id: 1 }, 42)); + assert(view.len == 0usize); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/byte_keys.aji b/tests/conformance/source/hashmap/byte_keys.aji new file mode 100644 index 0000000..380888f --- /dev/null +++ b/tests/conformance/source/hashmap/byte_keys.aji @@ -0,0 +1,50 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:256 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +fn hash(key: ref>) -> u64 effects [] { return 3; } +fn equal(a: ref>, b: ref>) -> bool effects [] { + ref left = buffer.view(a); ref right = buffer.view(b); + if left.len != right.len { return false; } + for i in 0usize..left.len { if left[i] != right[i] { return false; } } + return true; +} +fn bytes(value: u8, heap: cap) -> buffer effects [mem.alloc] { + let result = buffer.new(2usize, heap) or trap; + { mut q = result; buffer.push(q, value) or trap; buffer.push(q, 0u8) or trap; } + return move result; +} +fn key_freed(key: buffer) -> void effects [] { + { mut q = key; while buffer.len(q) != 0usize { let unused = buffer.pop(q) or trap; } } buffer.free(move key) or trap; +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::, u64, fn hash, fn equal>(2, heap); + { mut q = map; + let first = bytes(7u8, heap); inserted::,u64>(std.hashmap.insert::, u64, fn hash, fn equal>(q, move first, 42)); + let second = bytes(8u8, heap); inserted::,u64>(std.hashmap.insert::, u64, fn hash, fn equal>(q, move second, 8)); + let query = bytes(7u8, heap); + assert(extracted::(std.hashmap.get::, u64, fn hash, fn equal>(ref q, ref query)) == 42u64); + let entry = extracted::,u64>>(std.hashmap.remove::, u64, fn hash, fn equal>(q, ref query)); + let (key,value) = struct.unpack(move entry); assert(value == 42u64); key_freed(move key); key_freed(move query); + let last = extracted::,u64>>(std.hashmap.pop::, u64, fn hash, fn equal>(q)); let (last_key,last_value) = struct.unpack(move last); assert(last_value == 8u64); key_freed(move last_key); + } released::, u64, fn hash, fn equal>(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/copy.aji b/tests/conformance/source/hashmap/copy.aji new file mode 100644 index 0000000..1b78379 --- /dev/null +++ b/tests/conformance/source/hashmap/copy.aji @@ -0,0 +1,53 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:1024 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { mut q = map; + inserted::(std.hashmap.insert::(q, Key { id: 1 }, 11)); + inserted::(std.hashmap.insert::(q, Key { id: 2 }, 22)); + match std.hashmap.insert::(q, Key { id: 3 }, 33) { + std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 3u64); assert(entry.value == 33u64); }, + std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(old) => { trap; } + } + match std.hashmap.insert::(q, Key { id: 2 }, 42) { + std.hashmap.InsertResult::::replaced(old) => { assert(old.key.id == 2u64); assert(old.value == 22u64); }, + std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } + } + let key = Key { id: 1 }; + let removed = extracted::>(std.hashmap.remove::(q, ref key)); + assert(removed.key.id == 1u64); assert(removed.value == 11u64); + inserted::(std.hashmap.insert::(q, Key { id: 3 }, 33)); + match std.hashmap.reserve::(q, 4, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } + } + { ref q = map; let key = Key { id: 2 }; assert(std.hashmap.contains::(q, ref key)); + assert(extracted::(std.hashmap.get::(q, ref key)) == 42u64); + assert(std.hashmap.len::(q) == 2usize); assert(std.hashmap.capacity::(q) == 4usize); + } + { mut q = map; let last = extracted::>(std.hashmap.pop::(q)); assert(last.key.id == 3u64); + let first = extracted::>(std.hashmap.pop::(q)); assert(first.value == 42u64); } + released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/file.aji b/tests/conformance/source/hashmap/file.aji new file mode 100644 index 0000000..bc64e20 --- /dev/null +++ b/tests/conformance/source/hashmap/file.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:58 +// grant: dst=fs.write:/out +// file: /out/hashmap.txt=42 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap, dst: cap) -> u64 effects [mem.alloc, fs.write] { + let map = opened::, fn hash, fn equal>(1, heap); let file = fs.create(dst, b"/out/hashmap.txt") or trap; + { mut q = map; inserted::>(std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 7 }, move file)); + let key = Key { id: 7 }; let entry = extracted::>>(std.hashmap.remove::, fn hash, fn equal>(q, ref key)); + let (stored_key,item) = struct.unpack(move entry); fs.write_all(item, b"42") or trap; fs.close(move item) or trap; } + released::, fn hash, fn equal>(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/free_leak.aji b/tests/conformance/source/hashmap/free_leak.aji new file mode 100644 index 0000000..83255bc --- /dev/null +++ b/tests/conformance/source/hashmap/free_leak.aji @@ -0,0 +1,28 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(map: std.hashmap.HashMap, fn hash, fn equal>) -> void effects [] { + match std.hashmap.free::, fn hash, fn equal>(move map) { std.hashmap.FreeResult::, fn hash, fn equal>::not_empty(returned) => { return; }, std.hashmap.FreeResult::, fn hash, fn equal>::ok => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/full_leak.aji b/tests/conformance/source/hashmap/full_leak.aji new file mode 100644 index 0000000..5bc8889 --- /dev/null +++ b/tests/conformance/source/hashmap/full_leak.aji @@ -0,0 +1,32 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(map: mut,fn hash,fn equal>>, value: own) -> void effects [] { + match std.hashmap.insert::,fn hash,fn equal>(map, Key { id: 1 }, move value) { + std.hashmap.InsertResult::>::inserted => {}, + std.hashmap.InsertResult::>::replaced(entry) => { trap; }, + std.hashmap.InsertResult::>::full(entry) => { return; } + } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/get_owner.aji b/tests/conformance/source/hashmap/get_owner.aji new file mode 100644 index 0000000..582813c --- /dev/null +++ b/tests/conformance/source/hashmap/get_owner.aji @@ -0,0 +1,28 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(map: ref,fn hash,fn equal>>, key: ref) -> void effects [] { + std.hashmap.get::,fn hash,fn equal>(map, key); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/invalid_empty.aji b/tests/conformance/source/hashmap/invalid_empty.aji new file mode 100644 index 0000000..e00589c --- /dev/null +++ b/tests/conformance/source/hashmap/invalid_empty.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:58 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(1, heap); + { mut q = map; inserted::(std.hashmap.insert::(q, Key { id: 1 }, 42)); + mut index = q.buckets; mut buckets = buffer.view(index); buckets[1].state = std.hashmap.BucketState::empty; } + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::not_empty(returned) => { + let (entries,buckets) = struct.unpack(move returned); { mut q = entries; let entry = buffer.pop(q) or trap; assert(entry.value == 42u64); } buffer.free(move entries) or trap; + { mut q = buckets; while buffer.len(q) != 0usize { let unused = buffer.pop(q) or trap; } } buffer.free(move buckets) or trap; + }, std.hashmap.FreeResult::::ok => { trap; } } return 42; +} diff --git a/tests/conformance/source/hashmap/key_copy_lookup.aji b/tests/conformance/source/hashmap/key_copy_lookup.aji new file mode 100644 index 0000000..c4a8d79 --- /dev/null +++ b/tests/conformance/source/hashmap/key_copy_lookup.aji @@ -0,0 +1,40 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:82 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(entry: std.hashmap.Entry>, expected_key: u64, expected_value: u64) -> void effects [] { + let (key,value) = struct.unpack(move entry); let (id,owner) = struct.unpack(move key); + assert(own.take(move owner) == expected_key); assert(own.take(move value) == expected_value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(1, heap); + let key = Key { id: 7, owner: own.new(7u64,heap) or trap }; + { mut q = map; inserted::(std.hashmap.insert::(q, move key, 42)); } + let query = Key { id: 7, owner: own.new(7u64,heap) or trap }; + { ref q = map; assert(extracted::(std.hashmap.get::(q,ref query)) == 42u64); } + let (query_id,query_owner) = struct.unpack(move query); own.take(move query_owner); + { mut q = map; let entry = extracted::>(std.hashmap.pop::(q)); let (stored_key,value) = struct.unpack(move entry); let (id,owner) = struct.unpack(move stored_key); assert(own.take(move owner) == 7u64); assert(value == 42u64); } + released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/key_missing_move.aji b/tests/conformance/source/hashmap/key_missing_move.aji new file mode 100644 index 0000000..8172595 --- /dev/null +++ b/tests/conformance/source/hashmap/key_missing_move.aji @@ -0,0 +1,30 @@ +// expect: reject E7003 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(entry: std.hashmap.Entry>, expected_key: u64, expected_value: u64) -> void effects [] { + let (key,value) = struct.unpack(move entry); let (id,owner) = struct.unpack(move key); + assert(own.take(move owner) == expected_key); assert(own.take(move value) == expected_value); +} +fn bad(q: mut, fn hash, fn equal>>, key: Key, value: own) -> void effects [] { std.hashmap.insert::, fn hash, fn equal>(q, key, move value); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/loan.aji b/tests/conformance/source/hashmap/loan.aji new file mode 100644 index 0000000..98e9587 --- /dev/null +++ b/tests/conformance/source/hashmap/loan.aji @@ -0,0 +1,27 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: mut>) -> void effects [] {} +fn bad(q: mut>) -> void effects [task.spawn, task.wait] { scope s { let t = task.spawn(s, worker, q); inserted::(std.hashmap.insert::(q, Key { id: 1 }, 42)); task.join(move t); } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/loan_join.aji b/tests/conformance/source/hashmap/loan_join.aji new file mode 100644 index 0000000..cd56663 --- /dev/null +++ b/tests/conformance/source/hashmap/loan_join.aji @@ -0,0 +1,34 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:58 +// schedules: 12 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: mut>) -> void effects [] { inserted::(std.hashmap.insert::(q, Key { id: 1 }, 42)); } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let map = opened::(1, heap); + { mut q = map; scope s { let t = task.spawn(s, worker, q); task.join(move t); + let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.value == 42u64); } } + released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/missing_effect.aji b/tests/conformance/source/hashmap/missing_effect.aji new file mode 100644 index 0000000..4464b58 --- /dev/null +++ b/tests/conformance/source/hashmap/missing_effect.aji @@ -0,0 +1,28 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(map: mut>, heap: cap) -> void effects [] { + match std.hashmap.reserve::(map, 0, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/model.aji b/tests/conformance/source/hashmap/model.aji new file mode 100644 index 0000000..0ec0dd9 --- /dev/null +++ b/tests/conformance/source/hashmap/model.aji @@ -0,0 +1,3455 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:1120 +// fuel: 4000000 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64, salt: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id % 4u64; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { mut q = map; +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 1 }, 278u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 1usize); assert(std.hashmap.capacity::(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 278u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 1u64); assert(view[0usize].value == 278u64); } +} +{ +match std.hashmap.reserve::(q, 3usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 1usize); assert(std.hashmap.capacity::(ref q) == 3usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 278u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 1u64); assert(view[0usize].value == 278u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 7, salt: 3 }, 59u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 2usize); assert(std.hashmap.capacity::(ref q) == 3usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 278u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 1u64); assert(view[0usize].value == 278u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +} +{ +let query = Key { id: 3, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 2usize); assert(std.hashmap.capacity::(ref q) == 3usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 278u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 1u64); assert(view[0usize].value == 278u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +} +{ +match std.hashmap.reserve::(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 2usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 278u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 1u64); assert(view[0usize].value == 278u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 6 }, 281u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 1u64); assert(entry.value == 278u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 2usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 3, salt: 7 }, 420u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 6, salt: 8 }, 118u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 8u64); assert(view[3usize].value == 118u64); } +} +{ +match std.hashmap.reserve::(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 8u64); assert(view[3usize].value == 118u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 6, salt: 10 }, 453u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 6u64); assert(entry.key.salt == 8u64); assert(entry.value == 118u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 453u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 10u64); assert(view[3usize].value == 453u64); } +} +{ +let query = Key { id: 18446744073709551615, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 453u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 10u64); assert(view[3usize].value == 453u64); } +} +{ +let query = Key { id: 4, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 453u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 10u64); assert(view[3usize].value == 453u64); } +} +{ +let query = Key { id: 0, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 453u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 10u64); assert(view[3usize].value == 453u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 6u64); assert(entry.key.salt == 10u64); assert(entry.value == 453u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +} +{ +match std.hashmap.reserve::(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +} +{ +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 281u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 6u64); assert(view[0usize].value == 281u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 17 }, 324u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 6u64); assert(entry.value == 281u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +} +{ +let query = Key { id: 6, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 18446744073709551615, salt: 19 }, 442u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +} +{ +let query = Key { id: 0, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 4, salt: 21 }, 386u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 1, salt: 22 }, 490u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +let query = Key { id: 2, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 59u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 3u64); assert(view[1usize].value == 59u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 7, salt: 24 }, 3u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 7u64); assert(entry.key.salt == 3u64); assert(entry.value == 59u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 324u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 17u64); assert(view[0usize].value == 324u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 26 }, 447u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 17u64); assert(entry.value == 324u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 6, salt: 27 }, 27u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 6u64); assert(entry.key.salt == 27u64); assert(entry.value == 27u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 442u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 19u64); assert(view[3usize].value == 442u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 18446744073709551615, salt: 28 }, 195u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 18446744073709551615u64); assert(entry.key.salt == 19u64); assert(entry.value == 442u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 490u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 1u64); assert(view[5usize].key.salt == 22u64); assert(view[5usize].value == 490u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 1u64); assert(entry.key.salt == 22u64); assert(entry.value == 490u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 7u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 3, salt: 30 }, 420u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 3u64); assert(entry.key.salt == 7u64); assert(entry.value == 420u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 386u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 21u64); assert(view[4usize].value == 386u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 4, salt: 31 }, 427u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 4u64); assert(entry.key.salt == 21u64); assert(entry.value == 386u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +} +{ +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +} +{ +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 6, salt: 34 }, 229u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.reserve::(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +let query = Key { id: 0, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 420u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 30u64); assert(view[2usize].value == 420u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 3, salt: 37 }, 421u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 3u64); assert(entry.key.salt == 30u64); assert(entry.value == 420u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.reserve::(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.reserve::(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 3u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 24u64); assert(view[1usize].value == 3u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 7, salt: 41 }, 343u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 7u64); assert(entry.key.salt == 24u64); assert(entry.value == 3u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 427u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 343u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 41u64); assert(view[1usize].value == 343u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 31u64); assert(view[4usize].value == 427u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 4, salt: 42 }, 6u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 4u64); assert(entry.key.salt == 31u64); assert(entry.value == 427u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 343u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 195u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 41u64); assert(view[1usize].value == 343u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 28u64); assert(view[3usize].value == 195u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 18446744073709551615, salt: 43 }, 9u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 18446744073709551615u64); assert(entry.key.salt == 28u64); assert(entry.value == 195u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 343u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 41u64); assert(view[1usize].value == 343u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 0, salt: 44 }, 461u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 0u64); assert(entry.key.salt == 44u64); assert(entry.value == 461u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 343u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 41u64); assert(view[1usize].value == 343u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 7, salt: 45 }, 311u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 7u64); assert(entry.key.salt == 41u64); assert(entry.value == 343u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 1, salt: 46 }, 142u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 1u64); assert(entry.key.salt == 46u64); assert(entry.value == 142u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 447u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 26u64); assert(view[0usize].value == 447u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 47 }, 203u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 26u64); assert(entry.value == 447u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +let query = Key { id: 2, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 2, salt: 49 }, 385u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 2u64); assert(entry.key.salt == 49u64); assert(entry.value == 385u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 2, salt: 50 }, 57u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 2u64); assert(entry.key.salt == 50u64); assert(entry.value == 57u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 0, salt: 51 }, 429u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 0u64); assert(entry.key.salt == 51u64); assert(entry.value == 429u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 6u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 42u64); assert(view[4usize].value == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 4, salt: 53 }, 485u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 4u64); assert(entry.key.salt == 42u64); assert(entry.value == 6u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 485u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 311u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 45u64); assert(view[1usize].value == 311u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 53u64); assert(view[4usize].value == 485u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 7, salt: 54 }, 145u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 7u64); assert(entry.key.salt == 45u64); assert(entry.value == 311u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 485u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 229u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 145u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 54u64); assert(view[1usize].value == 145u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 53u64); assert(view[4usize].value == 485u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 6u64); assert(view[5usize].key.salt == 34u64); assert(view[5usize].value == 229u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 6u64); assert(entry.key.salt == 34u64); assert(entry.value == 229u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 485u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 145u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 54u64); assert(view[1usize].value == 145u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 53u64); assert(view[4usize].value == 485u64); } +} +{ +let query = Key { id: 6, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 485u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 145u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 54u64); assert(view[1usize].value == 145u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 53u64); assert(view[4usize].value == 485u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 4u64); assert(entry.key.salt == 53u64); assert(entry.value == 485u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 145u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 7u64); assert(view[1usize].key.salt == 54u64); assert(view[1usize].value == 145u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 18446744073709551615u64); assert(view[3usize].key.salt == 43u64); assert(view[3usize].value == 9u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { assert(entry.key.id == 7u64); assert(entry.key.salt == 54u64); assert(entry.value == 145u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +} +{ +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +} +{ +match std.hashmap.reserve::(q, 2usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 2, salt: 61 }, 118u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 4, salt: 62 }, 254u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 421u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 37u64); assert(view[2usize].value == 421u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 3, salt: 63 }, 176u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 3u64); assert(entry.key.salt == 37u64); assert(entry.value == 421u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 7, salt: 66 }, 10u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 6, salt: 67 }, 294u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 6u64); assert(entry.key.salt == 67u64); assert(entry.value == 294u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 203u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 47u64); assert(view[0usize].value == 203u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 68 }, 85u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 47u64); assert(entry.value == 203u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 254u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 62u64); assert(view[4usize].value == 254u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 4, salt: 69 }, 361u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 4u64); assert(entry.key.salt == 62u64); assert(entry.value == 254u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 1, salt: 70 }, 206u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 1u64); assert(entry.key.salt == 70u64); assert(entry.value == 206u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 0, salt: 73 }, 74u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { assert(entry.key.id == 0u64); assert(entry.key.salt == 73u64); assert(entry.value == 74u64); } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +match std.hashmap.reserve::(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 176u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 63u64); assert(view[2usize].value == 176u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 66u64); assert(view[5usize].value == 10u64); } +} +{ +let query = Key { id: 3, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { assert(entry.key.id == 3u64); assert(entry.key.salt == 63u64); assert(entry.value == 176u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 0, salt: 77 }, 73u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 6usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 85u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 68u64); assert(view[0usize].value == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 77u64); assert(view[5usize].value == 73u64); } +} +{ +let query = Key { id: 5, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 68u64); assert(entry.value == 85u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +} +{ +let query = Key { id: 1, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { trap; }, std.option.Option::>::none => { } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 9u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 43u64); assert(view[1usize].value == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 18446744073709551615, salt: 80 }, 185u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 18446744073709551615u64); assert(entry.key.salt == 43u64); assert(entry.value == 9u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 361u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 4u64); assert(view[4usize].key.salt == 69u64); assert(view[4usize].value == 361u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 4u64); assert(entry.key.salt == 69u64); assert(entry.value == 361u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +} +{ +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 5, salt: 83 }, 378u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 10u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 66u64); assert(view[2usize].value == 10u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 5u64); assert(view[4usize].key.salt == 83u64); assert(view[4usize].value == 378u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { assert(entry.key.id == 7u64); assert(entry.key.salt == 66u64); assert(entry.value == 10u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 118u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 5u64); assert(view[2usize].key.salt == 83u64); assert(view[2usize].value == 378u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 61u64); assert(view[3usize].value == 118u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 2u64); assert(entry.key.salt == 61u64); assert(entry.value == 118u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 5u64); assert(view[2usize].key.salt == 83u64); assert(view[2usize].value == 378u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 2, salt: 86 }, 482u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 482u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 5u64); assert(view[2usize].key.salt == 83u64); assert(view[2usize].value == 378u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 86u64); assert(view[3usize].value == 482u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 3, salt: 87 }, 109u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 5usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 482u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 109u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 5u64); assert(view[2usize].key.salt == 83u64); assert(view[2usize].value == 378u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 86u64); assert(view[3usize].value == 482u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 87u64); assert(view[4usize].value == 109u64); } +} +{ +let query = Key { id: 2, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { assert(entry.key.id == 2u64); assert(entry.key.salt == 86u64); assert(entry.value == 482u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 73u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 109u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 77u64); assert(view[0usize].value == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 5u64); assert(view[2usize].key.salt == 83u64); assert(view[2usize].value == 378u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 3u64); assert(view[3usize].key.salt == 87u64); assert(view[3usize].value == 109u64); } +} +{ +match std.hashmap.insert::(q, Key { id: 0, salt: 89 }, 481u64) { std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(entry) => { assert(entry.key.id == 0u64); assert(entry.key.salt == 77u64); assert(entry.value == 73u64); }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 4usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 481u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 109u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 378u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 89u64); assert(view[0usize].value == 481u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 5u64); assert(view[2usize].key.salt == 83u64); assert(view[2usize].value == 378u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 3u64); assert(view[3usize].key.salt == 87u64); assert(view[3usize].value == 109u64); } +} +{ +let query = Key { id: 5, salt: 0 }; +match std.hashmap.remove::(q, ref query) { std.option.Option::>::some(entry) => { assert(entry.key.id == 5u64); assert(entry.key.salt == 83u64); assert(entry.value == 378u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 481u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 109u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 89u64); assert(view[0usize].value == 481u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 87u64); assert(view[2usize].value == 109u64); } +} +{ +match std.hashmap.reserve::(q, 4usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 3usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 481u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 109u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 89u64); assert(view[0usize].value == 481u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 3u64); assert(view[2usize].key.salt == 87u64); assert(view[2usize].value == 109u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 3u64); assert(entry.key.salt == 87u64); assert(entry.value == 109u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 2usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 481u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 185u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 89u64); assert(view[0usize].value == 481u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 18446744073709551615u64); assert(view[1usize].key.salt == 80u64); assert(view[1usize].value == 185u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 18446744073709551615u64); assert(entry.key.salt == 80u64); assert(entry.value == 185u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 1usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 481u64); }, std.option.Option::::none => { trap; } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 0u64); assert(view[0usize].key.salt == 89u64); assert(view[0usize].value == 481u64); } +} +{ +match std.hashmap.pop::(q) { std.option.Option::>::some(entry) => { assert(entry.key.id == 0u64); assert(entry.key.salt == 89u64); assert(entry.value == 481u64); }, std.option.Option::>::none => { trap; } } +assert(std.hashmap.len::(ref q) == 0usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +} +{ +match std.hashmap.reserve::(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::(ref q) == 0usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +} +{ +match std.hashmap.insert::(q, Key { id: 18446744073709551615, salt: 96 }, 489u64) { std.hashmap.InsertResult::::inserted => { }, std.hashmap.InsertResult::::replaced(entry) => { trap; }, std.hashmap.InsertResult::::full(entry) => { trap; } } +assert(std.hashmap.len::(ref q) == 1usize); assert(std.hashmap.capacity::(ref q) == 6usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == false); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { trap; }, std.option.Option::::none => { } } +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::(ref q, ref query) == true); +match std.hashmap.get::(ref q, ref query) { std.option.Option::::some(value) => { assert(value == 489u64); }, std.option.Option::::none => { trap; } } +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 18446744073709551615u64); assert(view[0usize].key.salt == 96u64); assert(view[0usize].value == 489u64); } +} +{ let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.key.id == 18446744073709551615u64); assert(entry.key.salt == 96u64); assert(entry.value == 489u64); } + } released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/model_owner.aji b/tests/conformance/source/hashmap/model_owner.aji new file mode 100644 index 0000000..4c8114f --- /dev/null +++ b/tests/conformance/source/hashmap/model_owner.aji @@ -0,0 +1,2556 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:1120 +// fuel: 4000000 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64, salt: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id % 4u64; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::, fn hash, fn equal>(2, heap); + { mut q = map; +{ +let item = own.new(204u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 6, salt: 1 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 1usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 6u64); assert(view[0usize].key.salt == 1u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 1usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 6u64); assert(view[0usize].key.salt == 1u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 6u64); assert(key.salt == 1u64); assert(number == 204u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 0usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +} +{ +let item = own.new(193u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 5, salt: 4 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 1usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 4u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 1usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 4u64); } +} +{ +let item = own.new(10u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 3, salt: 6 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 2usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 4u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 4usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 4u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +} +{ +let item = own.new(492u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 5, salt: 8 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 5u64); assert(key.salt == 4u64); assert(number == 193u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +} +{ +let item = own.new(487u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 18446744073709551615, salt: 9 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let query = Key { id: 1, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let query = Key { id: 6, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let item = own.new(476u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 2, salt: 13 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 13u64); } +} +{ +let item = own.new(207u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 7, salt: 14 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 7u64); assert(key.salt == 14u64); assert(number == 207u64); } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 5u64); assert(view[0usize].key.salt == 8u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 2u64); assert(view[3usize].key.salt == 13u64); } +} +{ +let query = Key { id: 5, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 5u64); assert(key.salt == 8u64); assert(number == 492u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 6u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let item = own.new(3u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 3, salt: 17 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 3u64); assert(key.salt == 6u64); assert(number == 10u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 17u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 17u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +} +{ +let item = own.new(40u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 19 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 17u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 9u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +let item = own.new(449u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 18446744073709551615, salt: 20 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 18446744073709551615u64); assert(key.salt == 9u64); assert(number == 487u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 17u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 20u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +let item = own.new(358u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 3, salt: 21 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 3u64); assert(key.salt == 17u64); assert(number == 3u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 20u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 20u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +let item = own.new(282u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 5, salt: 23 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 5u64); assert(key.salt == 23u64); assert(number == 282u64); } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 20u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +let item = own.new(96u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 18446744073709551615, salt: 24 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 18446744073709551615u64); assert(key.salt == 20u64); assert(number == 449u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 3usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +let query = Key { id: 5, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 19u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 19u64); assert(number == 40u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +} +{ +let item = own.new(417u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 1, salt: 28 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 1u64); assert(view[3usize].key.salt == 28u64); } +} +{ +let item = own.new(75u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 4, salt: 29 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 4u64); assert(key.salt == 29u64); assert(number == 75u64); } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 1u64); assert(view[3usize].key.salt == 28u64); } +} +{ +let item = own.new(246u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 30 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 30u64); assert(number == 246u64); } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 24u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 1u64); assert(view[3usize].key.salt == 28u64); } +} +{ +let item = own.new(74u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 18446744073709551615, salt: 31 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 18446744073709551615u64); assert(key.salt == 24u64); assert(number == 96u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 31u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 1u64); assert(view[3usize].key.salt == 28u64); } +} +{ +let item = own.new(181u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 7, salt: 32 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 7u64); assert(key.salt == 32u64); assert(number == 181u64); } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 31u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 1u64); assert(view[3usize].key.salt == 28u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 2u64); assert(view[0usize].key.salt == 13u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 31u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 1u64); assert(view[3usize].key.salt == 28u64); } +} +{ +let query = Key { id: 2, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 2u64); assert(key.salt == 13u64); assert(number == 476u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 18446744073709551615u64); assert(view[2usize].key.salt == 31u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 18446744073709551615u64); assert(key.salt == 31u64); assert(number == 74u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +} +{ +let query = Key { id: 7, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 2usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 3u64); assert(view[1usize].key.salt == 21u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 3u64); assert(key.salt == 21u64); assert(number == 358u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 1usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 1usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +} +{ +let item = own.new(289u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 2, salt: 42 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +} +{ +let query = Key { id: 3, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 4usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 8usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 28u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +} +{ +let item = own.new(246u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 1, salt: 46 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 1u64); assert(key.salt == 28u64); assert(number == 417u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +} +{ +let query = Key { id: 4, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 2usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +} +{ +let item = own.new(458u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 48 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +} +{ +let item = own.new(176u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 6, salt: 49 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 49u64); } +} +{ +let item = own.new(260u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 3, salt: 50 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 49u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let item = own.new(154u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 6, salt: 51 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 6u64); assert(key.salt == 49u64); assert(number == 176u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 46u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let item = own.new(351u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 1, salt: 53 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 1u64); assert(key.salt == 46u64); assert(number == 246u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 53u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let item = own.new(301u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 1, salt: 54 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 1u64); assert(key.salt == 53u64); assert(number == 351u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 42u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let item = own.new(491u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 2, salt: 55 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 2u64); assert(key.salt == 42u64); assert(number == 289u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 55u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let query = Key { id: 18446744073709551615, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 55u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 55u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let item = own.new(16u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 2, salt: 58 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 2u64); assert(key.salt == 55u64); assert(number == 491u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 48u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let item = own.new(219u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 60 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 48u64); assert(number == 458u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 60u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 6u64); assert(view[3usize].key.salt == 51u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 3u64); assert(view[4usize].key.salt == 50u64); } +} +{ +let query = Key { id: 6, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 6u64); assert(key.salt == 51u64); assert(number == 154u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 60u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 3u64); assert(view[3usize].key.salt == 50u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 0usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 60u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 3u64); assert(view[3usize].key.salt == 50u64); } +} +{ +let item = own.new(419u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 63 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 60u64); assert(number == 219u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 3u64); assert(view[3usize].key.salt == 50u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 3u64); assert(key.salt == 50u64); assert(number == 260u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 8usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +} +{ +let item = own.new(277u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 5, salt: 66 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +} +{ +let query = Key { id: 3, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { trap; }, std.option.Option::>>::none => { } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +} +{ +let item = own.new(381u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 18446744073709551615, salt: 68 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 18446744073709551615u64); assert(view[4usize].key.salt == 68u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 18446744073709551615u64); assert(view[4usize].key.salt == 68u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 18446744073709551615u64); assert(key.salt == 68u64); assert(number == 381u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +} +{ +let item = own.new(343u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 6, salt: 72 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 58u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +let item = own.new(63u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 2, salt: 73 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 2u64); assert(key.salt == 58u64); assert(number == 16u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 66u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +let item = own.new(28u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 5, salt: 74 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 5u64); assert(key.salt == 66u64); assert(number == 277u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +let item = own.new(414u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 7, salt: 75 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 75u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 75u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 0u64); assert(view[2usize].key.salt == 63u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 7u64); assert(view[5usize].key.salt == 75u64); } +} +{ +let query = Key { id: 0, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 63u64); assert(number == 419u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 75u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 4usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 75u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +let item = own.new(195u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 7, salt: 80 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 7u64); assert(key.salt == 75u64); assert(number == 414u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 2usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 4usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +} +{ +let item = own.new(369u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 83 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 83u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 54u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 83u64); } +} +{ +let item = own.new(201u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 1, salt: 85 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 1u64); assert(key.salt == 54u64); assert(number == 301u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 83u64); } +} +{ +let item = own.new(402u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 3, salt: 86 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 7usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 72u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 83u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[6usize].key.id == 3u64); assert(view[6usize].key.salt == 86u64); } +} +{ +let item = own.new(447u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 6, salt: 87 }, move item) { std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 6u64); assert(key.salt == 72u64); assert(number == 343u64); }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 7usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 87u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 83u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[6usize].key.id == 3u64); assert(view[6usize].key.salt == 86u64); } +} +{ +let query = Key { id: 3, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 3u64); assert(key.salt == 86u64); assert(number == 402u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 6usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 87u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[5usize].key.id == 0u64); assert(view[5usize].key.salt == 83u64); } +} +{ +match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 83u64); assert(number == 369u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 5usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 2u64); assert(view[1usize].key.salt == 73u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[4usize].key.id == 6u64); assert(view[4usize].key.salt == 87u64); } +} +{ +let query = Key { id: 2, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 2u64); assert(key.salt == 73u64); assert(number == 63u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 6u64); assert(view[1usize].key.salt == 87u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 4usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 6u64); assert(view[1usize].key.salt == 87u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +} +{ +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 6u64); assert(view[1usize].key.salt == 87u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 5u64); assert(view[3usize].key.salt == 74u64); } +} +{ +let query = Key { id: 6, salt: 0 }; +match std.hashmap.remove::, fn hash, fn equal>(q, ref query) { std.option.Option::>>::some(entry) => { let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 6u64); assert(key.salt == 87u64); assert(number == 447u64); }, std.option.Option::>>::none => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 5u64); assert(view[1usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 4usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 5u64); assert(view[1usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +} +{ +match std.hashmap.reserve::, fn hash, fn equal>(q, 6usize, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 3usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 5u64); assert(view[1usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +} +{ +let item = own.new(86u64, heap) or trap; +match std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 0, salt: 96 }, move item) { std.hashmap.InsertResult::>::inserted => { }, std.hashmap.InsertResult::>::replaced(entry) => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } +assert(std.hashmap.len::, fn hash, fn equal>(ref q) == 4usize); assert(std.hashmap.capacity::, fn hash, fn equal>(ref q) == 8usize); +{ let query = Key { id: 0, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 1, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 2, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 3, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 4, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 5, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 6, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ let query = Key { id: 7, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == true); +} +{ let query = Key { id: 18446744073709551615, salt: 0 }; assert(std.hashmap.contains::, fn hash, fn equal>(ref q, ref query) == false); +} +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[0usize].key.id == 1u64); assert(view[0usize].key.salt == 85u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[1usize].key.id == 5u64); assert(view[1usize].key.salt == 74u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[2usize].key.id == 7u64); assert(view[2usize].key.salt == 80u64); } +{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[3usize].key.id == 0u64); assert(view[3usize].key.salt == 96u64); } +} +{ let entry = extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q)); let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 0u64); assert(key.salt == 96u64); assert(number == 86u64); } +{ let entry = extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q)); let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 7u64); assert(key.salt == 80u64); assert(number == 195u64); } +{ let entry = extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q)); let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 5u64); assert(key.salt == 74u64); assert(number == 28u64); } +{ let entry = extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q)); let (key,value) = struct.unpack(move entry); let number = own.take(move value); assert(key.id == 1u64); assert(key.salt == 85u64); assert(number == 201u64); } + } released::, fn hash, fn equal>(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/no_empty.aji b/tests/conformance/source/hashmap/no_empty.aji new file mode 100644 index 0000000..54e4d17 --- /dev/null +++ b/tests/conformance/source/hashmap/no_empty.aji @@ -0,0 +1,38 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:116 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { mut q = map; + for number in 0usize..4usize { + inserted::(std.hashmap.insert::(q, Key { id: number as! u64 }, 42)); + let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.value == 42u64); + } + let absent = Key { id: 100 }; assert(not std.hashmap.contains::(ref q, ref absent)); + inserted::(std.hashmap.insert::(q, absent, 42)); + let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.value == 42u64); + } released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/not_share.aji b/tests/conformance/source/hashmap/not_share.aji new file mode 100644 index 0000000..4eaafa9 --- /dev/null +++ b/tests/conformance/source/hashmap/not_share.aji @@ -0,0 +1,27 @@ +// expect: reject E4002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: ref, fn hash, fn equal>>) -> void effects [] {} +fn bad(q: ref, fn hash, fn equal>>) -> 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; } diff --git a/tests/conformance/source/hashmap/overflow.aji b/tests/conformance/source/hashmap/overflow.aji new file mode 100644 index 0000000..acb2967 --- /dev/null +++ b/tests/conformance/source/hashmap/overflow.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:8 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.hashmap.new::((0usize -% 1usize) / 2usize + 1usize, heap) { std.hashmap.NewResult::::err(error) => {}, std.hashmap.NewResult::::ok(map) => { trap; } } + match std.hashmap.new::((0usize -% 1usize) / 24usize + 1usize, heap) { std.hashmap.NewResult::::err(error) => {}, std.hashmap.NewResult::::ok(map) => { trap; } } + let map = opened::(0, heap); + { mut q = map; match std.hashmap.reserve::(q, (0usize -% 1usize) / 2usize + 1usize, heap) { std.hashmap.ReserveResult::err(error) => {}, std.hashmap.ReserveResult::ok => { trap; } } } + released::(move map); let owner = own.new(42u64, heap) or trap; return own.take(move owner); +} diff --git a/tests/conformance/source/hashmap/owner.aji b/tests/conformance/source/hashmap/owner.aji new file mode 100644 index 0000000..790238c --- /dev/null +++ b/tests/conformance/source/hashmap/owner.aji @@ -0,0 +1,45 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:1024 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(entry: std.hashmap.Entry>) -> u64 effects [] { + let (key, value) = struct.unpack(move entry); let (id, owner) = struct.unpack(move key); + assert(own.take(move owner) == id); return own.take(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::, fn hash, fn equal>(2, heap); + { mut q = map; + let k1 = Key { id: 1, owner: own.new(1u64, heap) or trap }; let v1 = own.new(11u64, heap) or trap; + inserted::>(std.hashmap.insert::, fn hash, fn equal>(q, move k1, move v1)); + let k2 = Key { id: 2, owner: own.new(2u64, heap) or trap }; let v2 = own.new(22u64, heap) or trap; + inserted::>(std.hashmap.insert::, fn hash, fn equal>(q, move k2, move v2)); + let query = Key { id: 1, owner: own.new(1u64, heap) or trap }; + assert(consumed(extracted::>>(std.hashmap.remove::, fn hash, fn equal>(q, ref query))) == 11u64); + let (id, owner) = struct.unpack(move query); own.take(move owner); + match std.hashmap.reserve::, fn hash, fn equal>(q, 3, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } + assert(consumed(extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q))) == 22u64); + } + released::, fn hash, fn equal>(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/owner_returned.aji b/tests/conformance/source/hashmap/owner_returned.aji new file mode 100644 index 0000000..f729911 --- /dev/null +++ b/tests/conformance/source/hashmap/owner_returned.aji @@ -0,0 +1,47 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:98 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(entry: std.hashmap.Entry>, expected_key: u64, expected_value: u64) -> void effects [] { + let (key,value) = struct.unpack(move entry); let (id,owner) = struct.unpack(move key); + assert(own.take(move owner) == expected_key); assert(own.take(move value) == expected_value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::, fn hash, fn equal>(1, heap); + { mut q = map; + let key = Key { id: 7, owner: own.new(101u64, heap) or trap }; let value = own.new(11u64, heap) or trap; + inserted::>(std.hashmap.insert::, fn hash, fn equal>(q, move key, move value)); + let replacement = Key { id: 7, owner: own.new(202u64, heap) or trap }; let replacement_value = own.new(42u64, heap) or trap; + match std.hashmap.insert::, fn hash, fn equal>(q, move replacement, move replacement_value) { + std.hashmap.InsertResult::>::replaced(entry) => { consumed(move entry, 101, 11); }, std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::full(entry) => { trap; } } + let full_key = Key { id: 8, owner: own.new(303u64, heap) or trap }; let full_value = own.new(99u64, heap) or trap; + match std.hashmap.insert::, fn hash, fn equal>(q, move full_key, move full_value) { + std.hashmap.InsertResult::>::full(entry) => { consumed(move entry, 303, 99); }, std.hashmap.InsertResult::>::inserted => { trap; }, std.hashmap.InsertResult::>::replaced(entry) => { trap; } } + } + match std.hashmap.free::, fn hash, fn equal>(move map) { + std.hashmap.FreeResult::, fn hash, fn equal>::not_empty(returned) => { { mut q = returned; consumed(extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q)), 202, 42); } released::, fn hash, fn equal>(move returned); }, + std.hashmap.FreeResult::, fn hash, fn equal>::ok => { trap; } } + return 42; +} diff --git a/tests/conformance/source/hashmap/policy_effect.aji b/tests/conformance/source/hashmap/policy_effect.aji new file mode 100644 index 0000000..78a5a3c --- /dev/null +++ b/tests/conformance/source/hashmap/policy_effect.aji @@ -0,0 +1,27 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn effectful(key: ref) -> u64 effects [mem.alloc] { return 3; } +fn bad(q: ref,fn effectful,fn equal>>) -> void effects [] {} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/policy_mismatch.aji b/tests/conformance/source/hashmap/policy_mismatch.aji new file mode 100644 index 0000000..b4e3feb --- /dev/null +++ b/tests/conformance/source/hashmap/policy_mismatch.aji @@ -0,0 +1,27 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn other(key: ref) -> u64 effects [] { return 3; } +fn bad(map: ref>) -> void effects [] { std.hashmap.len::(map); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/pop_leak.aji b/tests/conformance/source/hashmap/pop_leak.aji new file mode 100644 index 0000000..40417d6 --- /dev/null +++ b/tests/conformance/source/hashmap/pop_leak.aji @@ -0,0 +1,28 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut, fn hash, fn equal>>) -> void effects [] { + match std.hashmap.pop::, fn hash, fn equal>(q) { std.option.Option::>>::some(item) => { return; }, std.option.Option::>>::none => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/remove_leak.aji b/tests/conformance/source/hashmap/remove_leak.aji new file mode 100644 index 0000000..acbba1a --- /dev/null +++ b/tests/conformance/source/hashmap/remove_leak.aji @@ -0,0 +1,28 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut, fn hash, fn equal>>, key: ref) -> void effects [] { + match std.hashmap.remove::, fn hash, fn equal>(q,key) { std.option.Option::>>::some(item) => { return; }, std.option.Option::>>::none => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/replace_leak.aji b/tests/conformance/source/hashmap/replace_leak.aji new file mode 100644 index 0000000..fad7220 --- /dev/null +++ b/tests/conformance/source/hashmap/replace_leak.aji @@ -0,0 +1,28 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut, fn hash, fn equal>>, value: own) -> void effects [] { + match std.hashmap.insert::, fn hash, fn equal>(q,Key { id: 1 },move value) { std.hashmap.InsertResult::>::replaced(item) => { return; }, std.hashmap.InsertResult::>::inserted => {}, std.hashmap.InsertResult::>::full(item) => { trap; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashmap/reserve_authority.aji b/tests/conformance/source/hashmap/reserve_authority.aji new file mode 100644 index 0000000..6379e81 --- /dev/null +++ b/tests/conformance/source/hashmap/reserve_authority.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: first=mem.alloc:58 +// grant: second=mem.alloc:116 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(first: cap, second: cap) -> u64 effects [mem.alloc] { + let map = opened::(1, first); + { mut q = map; inserted::(std.hashmap.insert::(q, Key { id: 1 }, 42)); + match std.hashmap.reserve::(q, 2, second) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } } + let old = opened::(1, first); released::(move old); + { mut q = map; let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.value == 42u64); } + released::(move map); let next = opened::(2, second); released::(move next); return 42; +} diff --git a/tests/conformance/source/hashmap/reserve_failure.aji b/tests/conformance/source/hashmap/reserve_failure.aji new file mode 100644 index 0000000..34916a6 --- /dev/null +++ b/tests/conformance/source/hashmap/reserve_failure.aji @@ -0,0 +1,48 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:251 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn check(heap: cap) -> void effects [mem.alloc] { + let map = opened::(1, heap); + { mut q = map; inserted::(std.hashmap.insert::(q, Key { id: 1 }, 42)); } + let empty = std.hashmap.Bucket { hash: 0, index: 0, state: std.hashmap.BucketState::empty }; + var before: [std.hashmap.Bucket; 2] = [empty; 2]; + { ref q = map; ref index = q.buckets; ref buckets = buffer.view(index); before[0] = buckets[0]; before[1] = buckets[1]; } + { mut q = map; + match std.hashmap.reserve::(q, 2, heap) { std.hashmap.ReserveResult::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }, std.hashmap.ReserveResult::ok => { trap; } } + assert(std.hashmap.capacity::(ref q) == 1usize); + } + { ref q = map; ref index = q.buckets; ref buckets = buffer.view(index); + for i in 0usize..2usize { assert(buckets[i].hash == before[i].hash); assert(buckets[i].index == before[i].index); + match before[i].state { std.hashmap.BucketState::empty => { match buckets[i].state { std.hashmap.BucketState::empty => {}, std.hashmap.BucketState::deleted => { trap; }, std.hashmap.BucketState::occupied => { trap; } } }, std.hashmap.BucketState::deleted => { trap; }, std.hashmap.BucketState::occupied => { match buckets[i].state { std.hashmap.BucketState::occupied => {}, std.hashmap.BucketState::empty => { trap; }, std.hashmap.BucketState::deleted => { trap; } } } } + } } + { mut q = map; let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.value == 42u64); } + released::(move map); + let reused = own.new([0u8; 125], heap) or trap; own.free(move reused); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let early = cap.narrow.budget(heap, 125usize) or trap; check(early); + let late = cap.narrow.budget(heap, 126usize) or trap; check(late); return 42; +} diff --git a/tests/conformance/source/hashmap/reserve_peak.aji b/tests/conformance/source/hashmap/reserve_peak.aji new file mode 100644 index 0000000..f310ecb --- /dev/null +++ b/tests/conformance/source/hashmap/reserve_peak.aji @@ -0,0 +1,34 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:174 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(1, heap); + { mut q = map; inserted::(std.hashmap.insert::(q, Key { id: 1 }, 42)); + match std.hashmap.reserve::(q, 2, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } + let owner = own.new([0u8; 58], heap) or trap; own.free(move owner); + let entry = extracted::>(std.hashmap.pop::(q)); assert(entry.value == 42u64); + } released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/rollback.aji b/tests/conformance/source/hashmap/rollback.aji new file mode 100644 index 0000000..b369972 --- /dev/null +++ b/tests/conformance/source/hashmap/rollback.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:40 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.hashmap.new::(1, heap) { + std.hashmap.NewResult::::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }, + std.hashmap.NewResult::::ok(map) => { trap; } + } + let owner = own.new([0u8; 40], heap) or trap; own.free(move owner); return 42; +} diff --git a/tests/conformance/source/hashmap/sender.aji b/tests/conformance/source/hashmap/sender.aji new file mode 100644 index 0000000..fb1b711 --- /dev/null +++ b/tests/conformance/source/hashmap/sender.aji @@ -0,0 +1,39 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:256 +// schedules: 12 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +struct Job { number: u64 } +fn worker(map: std.hashmap.HashMap, fn hash, fn equal>) -> void effects [task.wait] { + { mut q = map; let entry = extracted::>>(std.hashmap.pop::, fn hash, fn equal>(q)); + let (key,tx) = struct.unpack(move entry); channel.send(tx, Job { number: 42 }) or trap; channel.close_sender(move tx); } + released::, fn hash, fn equal>(move map); +} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + match channel.make(1, heap) { ok(tx,rx) => { + let map = opened::, fn hash, fn equal>(1, heap); { mut q = map; inserted::>(std.hashmap.insert::, fn hash, fn equal>(q, Key { id: 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; +} diff --git a/tests/conformance/source/hashmap/shared.aji b/tests/conformance/source/hashmap/shared.aji new file mode 100644 index 0000000..cea82d8 --- /dev/null +++ b/tests/conformance/source/hashmap/shared.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:58 +// schedules: 12 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: ref>) -> u64 effects [] { let key = Key { id: 7 }; return extracted::(std.hashmap.get::(q, ref key)); } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let map = opened::(1, heap); { mut q = map; inserted::(std.hashmap.insert::(q, Key { id: 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; let entry = extracted::>(std.hashmap.pop::(q)); } released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/tombstones.aji b/tests/conformance/source/hashmap/tombstones.aji new file mode 100644 index 0000000..532f700 --- /dev/null +++ b/tests/conformance/source/hashmap/tombstones.aji @@ -0,0 +1,38 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:116 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { mut q = map; + for cycle in 0usize..12usize { + inserted::(std.hashmap.insert::(q, Key { id: 1 }, 1)); + inserted::(std.hashmap.insert::(q, Key { id: 2 }, 2)); + let key = Key { id: 1 }; let removed = extracted::>(std.hashmap.remove::(q, ref key)); + assert(removed.value == 1u64); + match std.hashmap.insert::(q, Key { id: 2 }, 42) { std.hashmap.InsertResult::::replaced(old) => { assert(old.value == 2u64); }, std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::full(old) => { trap; } } + let item = extracted::>(std.hashmap.pop::(q)); assert(item.key.id == 2u64); assert(item.value == 42u64); + } } released::(move map); return 42; +} diff --git a/tests/conformance/source/hashmap/zero.aji b/tests/conformance/source/hashmap/zero.aji new file mode 100644 index 0000000..b0573e1 --- /dev/null +++ b/tests/conformance/source/hashmap/zero.aji @@ -0,0 +1,36 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.14 +// grant: heap=mem.alloc:0 +module test.hashmap +import std.hashmap; +import std.option; +fn opened) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(capacity: usize, heap: cap) -> std.hashmap.HashMap effects [mem.alloc] { + match std.hashmap.new::(capacity, heap) { + std.hashmap.NewResult::::ok(map) => { return move map; } + std.hashmap.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.hashmap.InsertResult) -> void effects [] { + match move result { std.hashmap.InsertResult::::inserted => {}, std.hashmap.InsertResult::::full(value) => { trap; }, std.hashmap.InsertResult::::replaced(value) => { trap; } } +} +fn extracted(value: std.option.Option) -> T effects [] { + match move value { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } +} +fn released) -> u64 effects [], E: fn(ref, ref) -> bool effects []>(map: std.hashmap.HashMap) -> void effects [] { + match std.hashmap.free::(move map) { std.hashmap.FreeResult::::ok => {}, std.hashmap.FreeResult::::not_empty(value) => { trap; } } +} +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(0, heap); + { mut q = map; let key = Key { id: 1 }; + match std.hashmap.insert::(q, key, 42) { std.hashmap.InsertResult::::full(entry) => { assert(entry.value == 42u64); }, std.hashmap.InsertResult::::inserted => { trap; }, std.hashmap.InsertResult::::replaced(old) => { trap; } } + assert(not std.hashmap.contains::(ref q, ref key)); + match std.hashmap.remove::(q, ref key) { std.option.Option::>::none => {}, std.option.Option::>::some(entry) => { trap; } } + match std.hashmap.pop::(q) { std.option.Option::>::none => {}, std.option.Option::>::some(entry) => { trap; } } + match std.hashmap.reserve::(q, 0, heap) { std.hashmap.ReserveResult::ok => {}, std.hashmap.ReserveResult::err(error) => { trap; } } + } released::(move map); return 42; +} diff --git a/tests/conformance/source/hashset/alias.aji b/tests/conformance/source/hashset/alias.aji new file mode 100644 index 0000000..e80fd1e --- /dev/null +++ b/tests/conformance/source/hashset/alias.aji @@ -0,0 +1,24 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut>) -> void effects [] { + ref data = q.map.entries; ref view = buffer.view(data); + inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); assert(view.len == 0usize); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/byte_keys.aji b/tests/conformance/source/hashset/byte_keys.aji new file mode 100644 index 0000000..93de934 --- /dev/null +++ b/tests/conformance/source/hashset/byte_keys.aji @@ -0,0 +1,50 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:256 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +fn hash(key: ref>) -> u64 effects [] { return 3; } +fn equal(a: ref>, b: ref>) -> bool effects [] { + ref left = buffer.view(a); ref right = buffer.view(b); + if left.len != right.len { return false; } + for i in 0usize..left.len { if left[i] != right[i] { return false; } } return true; +} +fn bytes(value: u8, heap: cap) -> buffer effects [mem.alloc] { + let result = buffer.new(2usize,heap) or trap; + { mut q = result; buffer.push(q,value) or trap; buffer.push(q,0u8) or trap; } return move result; +} +fn consumed(key: buffer, value: u8) -> void effects [] { + { ref q = key; ref view = buffer.view(q); assert(view.len == 2usize); assert(view[0] == value); } + { mut q = key; while buffer.len(q) != 0usize { let unused = buffer.pop(q) or trap; } } buffer.free(move key) or trap; +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::,fn hash,fn equal>(1,heap); + { mut q = set; + let key = bytes(7u8,heap); inserted::>(std.hashset.insert::,fn hash,fn equal>(q,move key)); + let duplicate = bytes(7u8,heap); + match std.hashset.insert::,fn hash,fn equal>(q,move duplicate) { + std.hashset.InsertResult::>::present(key) => { consumed(move key,7u8); }, + std.hashset.InsertResult::>::inserted => { trap; }, std.hashset.InsertResult::>::full(key) => { trap; } + } + let full = bytes(8u8,heap); + match std.hashset.insert::,fn hash,fn equal>(q,move full) { + std.hashset.InsertResult::>::full(key) => { consumed(move key,8u8); }, + std.hashset.InsertResult::>::inserted => { trap; }, std.hashset.InsertResult::>::present(key) => { trap; } + } + let query = bytes(7u8,heap); assert(std.hashset.contains::,fn hash,fn equal>(ref q,ref query)); + consumed(extracted::>(std.hashset.remove::,fn hash,fn equal>(q,ref query)),7u8); consumed(move query,7u8); + } released::,fn hash,fn equal>(move set); return 42; +} diff --git a/tests/conformance/source/hashset/copy.aji b/tests/conformance/source/hashset/copy.aji new file mode 100644 index 0000000..036da3a --- /dev/null +++ b/tests/conformance/source/hashset/copy.aji @@ -0,0 +1,32 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:512 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(2,heap); + { mut q = set; + inserted::(std.hashset.insert::(q,Key { id: 1,marker: 11 })); inserted::(std.hashset.insert::(q,Key { id: 2,marker: 22 })); + match std.hashset.insert::(q,Key { id: 2,marker: 99 }) { std.hashset.InsertResult::::present(key) => { assert(key.marker == 99u64); }, std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } + match std.hashset.insert::(q,Key { id: 3,marker: 33 }) { std.hashset.InsertResult::::full(key) => { assert(key.marker == 33u64); }, std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; } } + let key = Key { id: 1,marker: 0 }; let old = extracted::(std.hashset.remove::(q,ref key)); assert(old.marker == 11u64); + match std.hashset.reserve::(q,3,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } + let old = extracted::(std.hashset.pop::(q)); assert(old.marker == 22u64); assert(std.hashset.len::(ref q) == 0usize); + } released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/duplicate_state.aji b/tests/conformance/source/hashset/duplicate_state.aji new file mode 100644 index 0000000..f9691bb --- /dev/null +++ b/tests/conformance/source/hashset/duplicate_state.aji @@ -0,0 +1,44 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:59 +module test.hashset +import std.hashset; +import std.option; +import std.hashmap; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bucket(q: ref>,index: usize) -> std.hashmap.Bucket effects [] { + ref storage = q.map.buckets; ref buckets = buffer.view(storage); return buckets[index]; +} +fn state(value: std.hashmap.BucketState) -> u64 effects [] { + match value { std.hashmap.BucketState::empty => { return 0; }, std.hashmap.BucketState::deleted => { return 1; }, std.hashmap.BucketState::occupied => { return 2; } } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(1,heap); + { mut q = set; inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); } + let first = bucket(ref set,0usize); + let second = bucket(ref set,1usize); + { mut q = set; + match std.hashset.insert::(q,Key { id: 1,marker: 99 }) { + std.hashset.InsertResult::::present(key) => { assert(key.marker == 99u64); }, + std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } + } } + { ref q = set; ref storage = q.map.buckets; ref buckets = buffer.view(storage); + assert(buckets[0].hash == first.hash); assert(buckets[0].index == first.index); assert(state(buckets[0].state) == state(first.state)); + assert(buckets[1].hash == second.hash); assert(buckets[1].index == second.index); assert(state(buckets[1].state) == state(second.state)); } + { mut q = set; let key = extracted::(std.hashset.pop::(q)); assert(key.marker == 42u64); } + released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/file.aji b/tests/conformance/source/hashset/file.aji new file mode 100644 index 0000000..cff82a1 --- /dev/null +++ b/tests/conformance/source/hashset/file.aji @@ -0,0 +1,31 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:59 +// grant: dst=fs.write:/out +// file: /out/hashset.txt=42 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, file: file } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap,dst: cap) -> u64 effects [mem.alloc,fs.write] { + let set = opened::(1,heap); + let key = Key { id: 1,file: fs.create(dst,b"/out/hashset.txt") or trap }; + { mut q = set; inserted::(std.hashset.insert::(q,move key)); + let key = extracted::(std.hashset.pop::(q)); let (id,file) = struct.unpack(move key); + fs.write_all(file,b"42") or trap; fs.close(move file) or trap; } + released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/free_leak.aji b/tests/conformance/source/hashset/free_leak.aji new file mode 100644 index 0000000..a02c62b --- /dev/null +++ b/tests/conformance/source/hashset/free_leak.aji @@ -0,0 +1,23 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::not_empty(set) => { return; }, std.hashset.FreeResult::::ok => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/free_returns.aji b/tests/conformance/source/hashset/free_returns.aji new file mode 100644 index 0000000..e26f12d --- /dev/null +++ b/tests/conformance/source/hashset/free_returns.aji @@ -0,0 +1,26 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:59 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(1,heap); { mut q = set; inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); } + match std.hashset.free::(move set) { std.hashset.FreeResult::::not_empty(returned) => { + { mut q = returned; let key = extracted::(std.hashset.pop::(q)); assert(key.marker == 42u64); } released::(move returned); }, std.hashset.FreeResult::::ok => { trap; } } return 42; +} diff --git a/tests/conformance/source/hashset/full_leak.aji b/tests/conformance/source/hashset/full_leak.aji new file mode 100644 index 0000000..a7aac52 --- /dev/null +++ b/tests/conformance/source/hashset/full_leak.aji @@ -0,0 +1,23 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut>,key: Key) -> void effects [] { + match std.hashset.insert::(q,move key) { std.hashset.InsertResult::::full(key) => { return; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::inserted => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/loan.aji b/tests/conformance/source/hashset/loan.aji new file mode 100644 index 0000000..038bf06 --- /dev/null +++ b/tests/conformance/source/hashset/loan.aji @@ -0,0 +1,22 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: mut>) -> void effects [] {} +fn bad(q: mut>) -> void effects [task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,q); inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); task.join(move t); } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/missing_effect.aji b/tests/conformance/source/hashset/missing_effect.aji new file mode 100644 index 0000000..2037f50 --- /dev/null +++ b/tests/conformance/source/hashset/missing_effect.aji @@ -0,0 +1,23 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut>,heap: cap) -> void effects [] { + match std.hashset.reserve::(q,0,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/missing_move.aji b/tests/conformance/source/hashset/missing_move.aji new file mode 100644 index 0000000..31fb2ea --- /dev/null +++ b/tests/conformance/source/hashset/missing_move.aji @@ -0,0 +1,22 @@ +// expect: reject E7003 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(key: Key,expected: u64) -> void effects [] { let (id,owner) = struct.unpack(move key); assert(own.take(move owner) == expected); } +fn bad(q: mut>,key: Key) -> void effects [] { std.hashset.insert::(q,key); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/model.aji b/tests/conformance/source/hashset/model.aji new file mode 100644 index 0000000..ef53c0d --- /dev/null +++ b/tests/conformance/source/hashset/model.aji @@ -0,0 +1,674 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:512 +// fuel: 2000000 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id % 3u64; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(2,heap); + { mut q = set; +{ +match std.hashset.insert::(q,Key { id: 1,marker: 1 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 2,marker: 2 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 2u64); assert(key.marker == 2u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +let query = Key { id: 2,marker: 0 }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 5 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 1u64); assert(key.marker == 5u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.reserve::(q,3usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 7 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 1u64); assert(key.marker == 7u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 0,marker: 8 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.reserve::(q,0usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +let query = Key { id: 7,marker: 0 }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +let query = Key { id: 0,marker: 0 }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { assert(key.id == 0u64); assert(key.marker == 8u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 3,marker: 12 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 2,marker: 13 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 14 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 1u64); assert(key.marker == 14u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 7,marker: 15 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { assert(key.id == 7u64); assert(key.marker == 15u64); } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 2u64); assert(key.marker == 13u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 3,marker: 17 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 3u64); assert(key.marker == 17u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +let query = Key { id: 3,marker: 0 }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { assert(key.id == 3u64); assert(key.marker == 12u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 7,marker: 19 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 7,marker: 20 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 7u64); assert(key.marker == 20u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 7u64); assert(key.marker == 19u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 3,marker: 22 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 3u64); assert(key.marker == 22u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 2,marker: 24 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 25 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 1u64); assert(key.marker == 25u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 18446744073709551615,marker: 26 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +} +{ +match std.hashset.reserve::(q,2usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +} +{ +match std.hashset.insert::(q,Key { id: 3,marker: 28 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { assert(key.id == 3u64); assert(key.marker == 28u64); } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 18446744073709551615u64); assert(key.marker == 26u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 2u64); assert(key.marker == 24u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.reserve::(q,4usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +let query = Key { id: 2,marker: 0 }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 1u64); assert(key.marker == 1u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 0usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 34 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 1u64); assert(key.marker == 34u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 0usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 7,marker: 36 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 37 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 1,marker: 38 }) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { assert(key.id == 1u64); assert(key.marker == 38u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ +match std.hashset.insert::(q,Key { id: 18446744073709551615,marker: 39 }) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { assert(key.id == 18446744073709551615u64); assert(key.marker == 39u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 1,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 2,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 3,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +{ let query = Key { id: 7,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == true); +} +{ let query = Key { id: 18446744073709551615,marker: 0 }; assert(std.hashset.contains::(ref q,ref query) == false); +} +} +{ let key = extracted::(std.hashset.pop::(q)); assert(key.id == 1u64); assert(key.marker == 37u64); } +{ let key = extracted::(std.hashset.pop::(q)); assert(key.id == 7u64); assert(key.marker == 36u64); } + } released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/model_owner.aji b/tests/conformance/source/hashset/model_owner.aji new file mode 100644 index 0000000..0d56b79 --- /dev/null +++ b/tests/conformance/source/hashset/model_owner.aji @@ -0,0 +1,946 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:512 +// fuel: 2000000 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return key.id % 3u64; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(2,heap); + { mut q = set; +{ +let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 0usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +assert(std.hashset.len::(ref q) == 0usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 2,owner: own.new(3u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 2u64); assert(own.take(move owner) == 3u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 0usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 2,owner: own.new(5u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 2u64); assert(own.take(move owner) == 5u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 0usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 3,owner: own.new(7u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 2,owner: own.new(9u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 1,owner: own.new(10u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 1u64); assert(own.take(move owner) == 10u64); } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 3,owner: own.new(11u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { let (id,owner) = struct.unpack(move key); assert(id == 3u64); assert(own.take(move owner) == 11u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 0,owner: own.new(12u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 0u64); assert(own.take(move owner) == 12u64); } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 2u64); assert(own.take(move owner) == 9u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 18446744073709551615,owner: own.new(14u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 1,owner: own.new(16u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 1u64); assert(own.take(move owner) == 16u64); } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 0,owner: own.new(17u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 0u64); assert(own.take(move owner) == 17u64); } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 2,owner: own.new(18u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 2u64); assert(own.take(move owner) == 18u64); } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 3,owner: own.new(19u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { let (id,owner) = struct.unpack(move key); assert(id == 3u64); assert(own.take(move owner) == 19u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 2usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.reserve::(q,3usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 18446744073709551615,owner: own.new(21u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { let (id,owner) = struct.unpack(move key); assert(id == 18446744073709551615u64); assert(own.take(move owner) == 21u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 0,owner: own.new(22u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 18446744073709551615u64); assert(own.take(move owner) == 14u64); }, std.option.Option::::none => { trap; } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 0u64); assert(own.take(move owner) == 22u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 18446744073709551615,owner: own.new(26u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.reserve::(q,3usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 18446744073709551615u64); assert(own.take(move owner) == 26u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 1usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 2,owner: own.new(29u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 1,owner: own.new(30u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 18446744073709551615,owner: own.new(31u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 18446744073709551615u64); assert(own.take(move owner) == 31u64); } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 1,owner: own.new(33u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { let (id,owner) = struct.unpack(move key); assert(id == 1u64); assert(own.take(move owner) == 33u64); }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 7,owner: own.new(34u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { let (id,owner) = struct.unpack(move key); assert(id == 7u64); assert(own.take(move owner) == 34u64); } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.reserve::(q,2usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.pop::(q) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 1u64); assert(own.take(move owner) == 30u64); }, std.option.Option::::none => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 3usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +match std.hashset.reserve::(q,4usize,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let incoming = Key { id: 1,owner: own.new(38u64,heap) or trap }; +match std.hashset.insert::(q,move incoming) { std.hashset.InsertResult::::inserted => { }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +assert(std.hashset.len::(ref q) == 3usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { let (id,owner) = struct.unpack(move key); assert(id == 3u64); assert(own.take(move owner) == 7u64); }, std.option.Option::::none => { trap; } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ +let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; +match std.hashset.remove::(q,ref query) { std.option.Option::::some(key) => { trap; }, std.option.Option::::none => { } } +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +assert(std.hashset.len::(ref q) == 2usize); assert(std.hashset.capacity::(ref q) == 4usize); +{ let query = Key { id: 0,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 1,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 2,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == true); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 3,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 7,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +{ let query = Key { id: 18446744073709551615,owner: own.new(0u64,heap) or trap }; assert(std.hashset.contains::(ref q,ref query) == false); +let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64); +} +} +{ let key = extracted::(std.hashset.pop::(q)); let (id,owner) = struct.unpack(move key); assert(id == 2u64); assert(own.take(move owner) == 29u64); } +{ let key = extracted::(std.hashset.pop::(q)); let (id,owner) = struct.unpack(move key); assert(id == 1u64); assert(own.take(move owner) == 38u64); } + } released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/not_share.aji b/tests/conformance/source/hashset/not_share.aji new file mode 100644 index 0000000..7ef1727 --- /dev/null +++ b/tests/conformance/source/hashset/not_share.aji @@ -0,0 +1,24 @@ +// expect: reject E4002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, file: file } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: ref>) -> void effects [] {} +fn bad(q: ref>) -> void effects [task.spawn,task.wait] { + scope s { let task = task.spawn(s,worker,q); task.join(move task); } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/overflow.aji b/tests/conformance/source/hashset/overflow.aji new file mode 100644 index 0000000..f3f26b7 --- /dev/null +++ b/tests/conformance/source/hashset/overflow.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:8 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.hashset.new::((0usize -% 1usize) / 2usize + 1usize,heap) { std.hashset.NewResult::::err(error) => {}, std.hashset.NewResult::::ok(set) => { trap; } } + let allocation = own.new(42u64,heap) or trap; return own.take(move allocation); +} diff --git a/tests/conformance/source/hashset/owner.aji b/tests/conformance/source/hashset/owner.aji new file mode 100644 index 0000000..d6f135b --- /dev/null +++ b/tests/conformance/source/hashset/owner.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:75 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(key: Key,expected: u64) -> void effects [] { let (id,owner) = struct.unpack(move key); assert(own.take(move owner) == expected); } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(1,heap); + { mut q = set; + let first = Key { id: 1,owner: own.new(11u64,heap) or trap }; inserted::(std.hashset.insert::(q,move first)); + let duplicate = Key { id: 1,owner: own.new(99u64,heap) or trap }; + match std.hashset.insert::(q,move duplicate) { std.hashset.InsertResult::::present(key) => { consumed(move key,99); }, std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } + let full = Key { id: 2,owner: own.new(22u64,heap) or trap }; + match std.hashset.insert::(q,move full) { std.hashset.InsertResult::::full(key) => { consumed(move key,22); }, std.hashset.InsertResult::::inserted => { trap; }, std.hashset.InsertResult::::present(key) => { trap; } } + consumed(extracted::(std.hashset.pop::(q)),11); + } released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/policy_mismatch.aji b/tests/conformance/source/hashset/policy_mismatch.aji new file mode 100644 index 0000000..3a4d4f7 --- /dev/null +++ b/tests/conformance/source/hashset/policy_mismatch.aji @@ -0,0 +1,22 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn other(key: ref) -> u64 effects [] { return 3; } +fn bad(q: ref>) -> void effects [] { std.hashset.len::(q); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/pop_leak.aji b/tests/conformance/source/hashset/pop_leak.aji new file mode 100644 index 0000000..39d90a8 --- /dev/null +++ b/tests/conformance/source/hashset/pop_leak.aji @@ -0,0 +1,23 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut>) -> void effects [] { + match std.hashset.pop::(q) { std.option.Option::::some(key) => { return; }, std.option.Option::::none => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/present_leak.aji b/tests/conformance/source/hashset/present_leak.aji new file mode 100644 index 0000000..404a4ec --- /dev/null +++ b/tests/conformance/source/hashset/present_leak.aji @@ -0,0 +1,24 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn consumed(key: Key,expected: u64) -> void effects [] { let (id,owner) = struct.unpack(move key); assert(own.take(move owner) == expected); } +fn bad(q: mut>,key: Key) -> void effects [] { + match std.hashset.insert::(q,move key) { std.hashset.InsertResult::::present(item) => { return; }, std.hashset.InsertResult::::full(item) => { trap; }, std.hashset.InsertResult::::inserted => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/remove_leak.aji b/tests/conformance/source/hashset/remove_leak.aji new file mode 100644 index 0000000..b09a308 --- /dev/null +++ b/tests/conformance/source/hashset/remove_leak.aji @@ -0,0 +1,23 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn bad(q: mut>,key: ref) -> void effects [] { + match std.hashset.remove::(q,key) { std.option.Option::::some(key) => { return; }, std.option.Option::::none => {} } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/hashset/reserve_authority.aji b/tests/conformance/source/hashset/reserve_authority.aji new file mode 100644 index 0000000..aa02f88 --- /dev/null +++ b/tests/conformance/source/hashset/reserve_authority.aji @@ -0,0 +1,30 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: first=mem.alloc:59 +// grant: second=mem.alloc:118 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(first: cap,second: cap) -> u64 effects [mem.alloc] { + let set = opened::(1,first); + { mut q = set; inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); + match std.hashset.reserve::(q,2,second) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } } + let old = opened::(1,first); released::(move old); + { mut q = set; let key = extracted::(std.hashset.pop::(q)); assert(key.marker == 42u64); } released::(move set); + let next = opened::(2,second); released::(move next); return 42; +} diff --git a/tests/conformance/source/hashset/reserve_failure.aji b/tests/conformance/source/hashset/reserve_failure.aji new file mode 100644 index 0000000..326f375 --- /dev/null +++ b/tests/conformance/source/hashset/reserve_failure.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:253 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn check(heap: cap) -> void effects [mem.alloc] { + let set = opened::(1,heap); + { mut q = set; inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); + match std.hashset.reserve::(q,2,heap) { std.hashset.ReserveResult::err(error) => {}, std.hashset.ReserveResult::ok => { trap; } } + assert(std.hashset.capacity::(ref q) == 1usize); + let key = extracted::(std.hashset.pop::(q)); assert(key.marker == 42u64); } released::(move set); + let allocation = own.new([0u8;126],heap) or trap; own.free(move allocation); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let first = cap.narrow.budget(heap,126usize) or trap; check(first); + let second = cap.narrow.budget(heap,127usize) or trap; check(second); return 42; +} diff --git a/tests/conformance/source/hashset/reserve_peak.aji b/tests/conformance/source/hashset/reserve_peak.aji new file mode 100644 index 0000000..1361946 --- /dev/null +++ b/tests/conformance/source/hashset/reserve_peak.aji @@ -0,0 +1,28 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:177 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(1,heap); + { mut q = set; inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); + match std.hashset.reserve::(q,2,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } + let allocation = own.new([0u8;59],heap) or trap; own.free(move allocation); + let key = extracted::(std.hashset.pop::(q)); assert(key.marker == 42u64); } released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/rollback.aji b/tests/conformance/source/hashset/rollback.aji new file mode 100644 index 0000000..80d4fb8 --- /dev/null +++ b/tests/conformance/source/hashset/rollback.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:40 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.hashset.new::(1,heap) { std.hashset.NewResult::::err(error) => {}, std.hashset.NewResult::::ok(set) => { trap; } } + let allocation = own.new([0u8;40],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/hashset/shared.aji b/tests/conformance/source/hashset/shared.aji new file mode 100644 index 0000000..c1ef653 --- /dev/null +++ b/tests/conformance/source/hashset/shared.aji @@ -0,0 +1,28 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:59 +// schedules: 12 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn worker(q: ref>) -> bool effects [] { let key = Key { id: 1,marker: 0 }; return std.hashset.contains::(q,ref key); } +fn main(heap: cap) -> u64 effects [mem.alloc,task.spawn,task.wait] { + let set = opened::(1,heap); { mut q = set; inserted::(std.hashset.insert::(q,Key { id: 1,marker: 42 })); } + { ref q = set; scope s { let a = task.spawn(s,worker,q); let b = task.spawn(s,worker,q); assert(task.join(move a)); assert(task.join(move b)); } } + { mut q = set; let key = extracted::(std.hashset.pop::(q)); } released::(move set); return 42; +} diff --git a/tests/conformance/source/hashset/zero.aji b/tests/conformance/source/hashset/zero.aji new file mode 100644 index 0000000..ca5d4e7 --- /dev/null +++ b/tests/conformance/source/hashset/zero.aji @@ -0,0 +1,31 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.15 +// grant: heap=mem.alloc:0 +module test.hashset +import std.hashset; +import std.option; +fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { + match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } +} +fn inserted(result: std.hashset.InsertResult) -> void effects [] { + match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } +} +fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } +fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { + match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } +} +struct Key { id: u64, marker: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let set = opened::(0,heap); + { mut q = set; let key = Key { id: 1,marker: 42 }; + match std.hashset.insert::(q,key) { std.hashset.InsertResult::::full(key) => { assert(key.marker == 42u64); }, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::inserted => { trap; } } + assert(not std.hashset.contains::(ref q,ref key)); + match std.hashset.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(key) => { trap; } } + match std.hashset.remove::(q,ref key) { std.option.Option::::none => {}, std.option.Option::::some(key) => { trap; } } + match std.hashset.reserve::(q,0,heap) { std.hashset.ReserveResult::ok => {}, std.hashset.ReserveResult::err(error) => { trap; } } + } released::(move set); return 42; +} diff --git a/tests/conformance/source/heap/alias.aji b/tests/conformance/source/heap/alias.aji new file mode 100644 index 0000000..a206877 --- /dev/null +++ b/tests/conformance/source/heap/alias.aji @@ -0,0 +1,17 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn bad(q: mut>) -> void effects [] { + ref index = q.indices; ref indices = buffer.view(index); std.heap.pop::(q); assert(indices.len == 0usize); +} fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/byte_values.aji b/tests/conformance/source/heap/byte_values.aji new file mode 100644 index 0000000..b1137f2 --- /dev/null +++ b/tests/conformance/source/heap/byte_values.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:256 +module test.heap +import std.heap; +import std.option; +import std.bytes; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref>,b: ref>) -> bool effects [] { + ref left = buffer.view(a); ref right = buffer.view(b); return std.bytes.compare(left,right) < 0i8; +} +fn bytes(value: u8,heap: cap) -> buffer effects [mem.alloc] { + let result = buffer.new(2,heap) or trap; + { mut q = result; buffer.push(q,value) or trap; buffer.push(q,0u8) or trap; } return move result; +} +fn consumed(item: buffer,expected: u8) -> void effects [] { + { ref q = item; ref view = buffer.view(q); assert(view[0] == expected); } + { mut q = item; while buffer.len(q) != 0usize { let unused = buffer.pop(q) or trap; } } buffer.free(move item) or trap; +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::,fn before>(3,heap); + { mut q = value; let first = bytes(9u8,heap); let second = bytes(1u8,heap); let third = bytes(5u8,heap); + pushed::>(std.heap.push::,fn before>(q,move first)); pushed::>(std.heap.push::,fn before>(q,move second)); pushed::>(std.heap.push::,fn before>(q,move third)); + consumed(extracted::>(std.heap.pop::,fn before>(q)),1u8); consumed(extracted::>(std.heap.pop::,fn before>(q)),5u8); consumed(extracted::>(std.heap.pop::,fn before>(q)),9u8); + } released::,fn before>(move value); return 42; +} diff --git a/tests/conformance/source/heap/copy.aji b/tests/conformance/source/heap/copy.aji new file mode 100644 index 0000000..a983915 --- /dev/null +++ b/tests/conformance/source/heap/copy.aji @@ -0,0 +1,38 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:192 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(3,heap); + { mut q = value; + match std.heap.peek::(ref q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } + pushed::(std.heap.push::(q,9)); pushed::(std.heap.push::(q,1)); pushed::(std.heap.push::(q,5)); + assert(extracted::(std.heap.peek::(ref q)) == 1u64); + match std.heap.push::(q,42) { std.heap.PushResult::::full(item) => { assert(item == 42u64); }, std.heap.PushResult::::ok => { trap; } } + match std.heap.reserve::(q,5,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } + pushed::(std.heap.push::(q,3)); pushed::(std.heap.push::(q,3)); + assert(extracted::(std.heap.pop::(q)) == 1u64); + assert(extracted::(std.heap.pop::(q)) == 3u64); + assert(extracted::(std.heap.pop::(q)) == 3u64); + assert(extracted::(std.heap.pop::(q)) == 5u64); + assert(extracted::(std.heap.pop::(q)) == 9u64); + match std.heap.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } + assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 5usize); + } released::(move value); + let maximum = opened::(4,heap); + { mut q = maximum; for i in 0usize..4usize { pushed::(std.heap.push::(q,i as! u64)); } + for i in 0usize..4usize { assert(extracted::(std.heap.pop::(q)) == (3usize-i) as! u64); } + } released::(move maximum); return 42; +} diff --git a/tests/conformance/source/heap/direct_owner.aji b/tests/conformance/source/heap/direct_owner.aji new file mode 100644 index 0000000..d0e9194 --- /dev/null +++ b/tests/conformance/source/heap/direct_owner.aji @@ -0,0 +1,23 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:64 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref>,b: ref>) -> bool effects [] { return false; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::,fn before>(2,heap); + { mut q = value; let first = own.new(9u64,heap) or trap; let second = own.new(1u64,heap) or trap; + pushed::>(std.heap.push::,fn before>(q,move first)); pushed::>(std.heap.push::,fn before>(q,move second)); + assert(own.take(extracted::>(std.heap.pop::,fn before>(q))) == 9u64); + assert(own.take(extracted::>(std.heap.pop::,fn before>(q))) == 1u64); + } released::,fn before>(move value); return 42; +} diff --git a/tests/conformance/source/heap/file.aji b/tests/conformance/source/heap/file.aji new file mode 100644 index 0000000..b9429c1 --- /dev/null +++ b/tests/conformance/source/heap/file.aji @@ -0,0 +1,28 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:64 +// grant: dst=fs.write:/out +// file: /out/first.txt=first +// file: /out/last.txt=last +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, file: file } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn main(heap: cap,dst: cap) -> u64 effects [mem.alloc,fs.write] { + let value = opened::(2,heap); + let first = Item { priority: 9,file: fs.create(dst,b"/out/last.txt") or trap }; + let second = Item { priority: 1,file: fs.create(dst,b"/out/first.txt") or trap }; + { mut q = value; pushed::(std.heap.push::(q,move first)); pushed::(std.heap.push::(q,move second)); + let item = extracted::(std.heap.pop::(q)); let (priority,file) = struct.unpack(move item); assert(priority == 1u64); fs.write_all(file,b"first") or trap; fs.close(move file) or trap; + let item = extracted::(std.heap.pop::(q)); let (priority,file) = struct.unpack(move item); assert(priority == 9u64); fs.write_all(file,b"last") or trap; fs.close(move file) or trap; + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/free_leak.aji b/tests/conformance/source/heap/free_leak.aji new file mode 100644 index 0000000..376a729 --- /dev/null +++ b/tests/conformance/source/heap/free_leak.aji @@ -0,0 +1,18 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn bad(value: std.heap.BinaryHeap) -> void effects [] { + match std.heap.free::(move value) { std.heap.FreeResult::::not_empty(value) => { return; }, std.heap.FreeResult::::ok => {} } +} fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/free_returns.aji b/tests/conformance/source/heap/free_returns.aji new file mode 100644 index 0000000..a11c1e3 --- /dev/null +++ b/tests/conformance/source/heap/free_returns.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:40 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(1,heap); let item = Item { priority: 42,owner: own.new(42u64,heap) or trap }; + { mut q = value; pushed::(std.heap.push::(q,move item)); } + match std.heap.free::(move value) { + std.heap.FreeResult::::ok => { trap; }, std.heap.FreeResult::::not_empty(value) => { + { mut q = value; consumed(extracted::(std.heap.pop::(q)),42); } released::(move value); + } } return 42; +} diff --git a/tests/conformance/source/heap/full_leak.aji b/tests/conformance/source/heap/full_leak.aji new file mode 100644 index 0000000..690fd0a --- /dev/null +++ b/tests/conformance/source/heap/full_leak.aji @@ -0,0 +1,19 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn bad(q: mut>,item: Item) -> void effects [] { + match std.heap.push::(q,move item) { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { return; } } +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/full_no_callback.aji b/tests/conformance/source/heap/full_no_callback.aji new file mode 100644 index 0000000..4340fa3 --- /dev/null +++ b/tests/conformance/source/heap/full_no_callback.aji @@ -0,0 +1,22 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:24 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { trap; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(1,heap); + { mut q = value; pushed::(std.heap.push::(q,42)); + match std.heap.push::(q,1) { std.heap.PushResult::::full(item) => { assert(item == 1u64); }, std.heap.PushResult::::ok => { trap; } } + assert(extracted::(std.heap.peek::(ref q)) == 42u64); assert(extracted::(std.heap.pop::(q)) == 42u64); + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/invalid_indices.aji b/tests/conformance/source/heap/invalid_indices.aji new file mode 100644 index 0000000..30ed9a6 --- /dev/null +++ b/tests/conformance/source/heap/invalid_indices.aji @@ -0,0 +1,24 @@ +// expect: run +// trap: T0008 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:24 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(1,heap); + { mut q = value; pushed::(std.heap.push::(q,42)); } + { mut q = value; mut index = q.indices; mut indices = buffer.view(index); indices[0] = 7usize; } + { ref q = value; std.heap.peek::(q); } + { mut q = value; let item = extracted::(std.heap.pop::(q)); } + released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/layout_failure.aji b/tests/conformance/source/heap/layout_failure.aji new file mode 100644 index 0000000..ec42f0b --- /dev/null +++ b/tests/conformance/source/heap/layout_failure.aji @@ -0,0 +1,31 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:207 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn check(heap: cap) -> void effects [mem.alloc] { + let value = opened::(3,heap); + { mut q = value; pushed::(std.heap.push::(q,9)); pushed::(std.heap.push::(q,1)); pushed::(std.heap.push::(q,5)); } + var positions: [usize;3] = [0usize;3]; var values: [u64;3] = [0u64;3]; var indices: [usize;3] = [0usize;3]; + { ref q = value; ref storage = q.entries; ref entries = buffer.view(storage); ref index = q.indices; ref current = buffer.view(index); + for i in 0usize..3usize { positions[i] = entries[i].position; values[i] = entries[i].value; indices[i] = current[i]; } } + { mut q = value; match std.heap.reserve::(q,4,heap) { std.heap.ReserveResult::err(error) => {}, std.heap.ReserveResult::ok => { trap; } } } + { ref q = value; assert(std.heap.capacity::(q) == 3usize); ref storage = q.entries; ref entries = buffer.view(storage); ref index = q.indices; ref current = buffer.view(index); + for i in 0usize..3usize { assert(positions[i] == entries[i].position); assert(values[i] == entries[i].value); assert(indices[i] == current[i]); } } + { mut q = value; assert(extracted::(std.heap.pop::(q)) == 1u64); assert(extracted::(std.heap.pop::(q)) == 5u64); assert(extracted::(std.heap.pop::(q)) == 9u64); } + released::(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let first = cap.narrow.budget(heap,103usize) or trap; check(first); let second = cap.narrow.budget(heap,104usize) or trap; check(second); return 42; +} diff --git a/tests/conformance/source/heap/loan.aji b/tests/conformance/source/heap/loan.aji new file mode 100644 index 0000000..0973650 --- /dev/null +++ b/tests/conformance/source/heap/loan.aji @@ -0,0 +1,18 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn worker(q: mut>) -> void effects [] {} +fn bad(q: mut>) -> void effects [task.spawn,task.wait] { + scope s { let task = task.spawn(s,worker,q); std.heap.pop::(q); task.join(move task); } +} fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/loan_join.aji b/tests/conformance/source/heap/loan_join.aji new file mode 100644 index 0000000..fddebec --- /dev/null +++ b/tests/conformance/source/heap/loan_join.aji @@ -0,0 +1,23 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:24 +// schedules: 12 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn worker(q: mut>) -> void effects [] { pushed::(std.heap.push::(q,42)); } +fn main(heap: cap) -> u64 effects [mem.alloc,task.spawn,task.wait] { + let value = opened::(1,heap); + { mut q = value; scope s { let task = task.spawn(s,worker,q); task.join(move task); assert(extracted::(std.heap.pop::(q)) == 42u64); } } + released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/missing_effect.aji b/tests/conformance/source/heap/missing_effect.aji new file mode 100644 index 0000000..9beecc4 --- /dev/null +++ b/tests/conformance/source/heap/missing_effect.aji @@ -0,0 +1,16 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn bad(q: mut>,heap: cap) -> void effects [] { std.heap.reserve::(q,0,heap); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/missing_move.aji b/tests/conformance/source/heap/missing_move.aji new file mode 100644 index 0000000..d2385c8 --- /dev/null +++ b/tests/conformance/source/heap/missing_move.aji @@ -0,0 +1,17 @@ +// expect: reject E7003 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn bad(q: mut>,item: Item) -> void effects [] { std.heap.push::(q,item); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/model.aji b/tests/conformance/source/heap/model.aji new file mode 100644 index 0000000..4ef4342 --- /dev/null +++ b/tests/conformance/source/heap/model.aji @@ -0,0 +1,430 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:2048 +// fuel: 2000000 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, id: u64, marker: u64 } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority or (a.priority == b.priority and a.id < b.id); } +fn checked(item: Item,priority: u64,id: u64) -> void effects [] { +assert(item.priority == priority); assert(item.id == id); assert(item.marker == id); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(2,heap); + { mut q = value; +{ +match std.heap.push::(q,Item { priority: 2,id: 1,marker: 1 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,1u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 2,marker: 2 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +match std.heap.reserve::(q,0usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +match std.heap.push::(q,Item { priority: 2,id: 4,marker: 4 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,2u64,4u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 5,marker: 5 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,3u64,5u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 7,marker: 7 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,3u64,7u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 8,marker: 8 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,1u64,8u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,2u64); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,2u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,1u64); +} +{ +checked(extracted::(std.heap.pop::(q)),2u64,1u64); +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +match std.heap.peek::(ref q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } +} +{ +match std.heap.push::(q,Item { priority: 18446744073709551615,id: 11,marker: 11 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +checked(extracted::(std.heap.peek::(ref q)),18446744073709551615u64,11u64); +} +{ +match std.heap.reserve::(q,8usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),18446744073709551615u64,11u64); +} +{ +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,11u64); +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 8usize); +match std.heap.peek::(ref q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } +} +{ +match std.heap.push::(q,Item { priority: 7,id: 14,marker: 14 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),7u64,14u64); +} +{ +match std.heap.push::(q,Item { priority: 18446744073709551615,id: 15,marker: 15 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),7u64,14u64); +} +{ +checked(extracted::(std.heap.pop::(q)),7u64,14u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),18446744073709551615u64,15u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 17,marker: 17 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 18,marker: 18 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 19,marker: 19 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,19u64); +} +{ +checked(extracted::(std.heap.pop::(q)),0u64,19u64); +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 21,marker: 21 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,21u64); +} +{ +match std.heap.push::(q,Item { priority: 7,id: 22,marker: 22 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,21u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 23,marker: 23 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,23u64); +} +{ +match std.heap.reserve::(q,4usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,23u64); +} +{ +checked(extracted::(std.heap.pop::(q)),0u64,23u64); +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,21u64); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,21u64); +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +match std.heap.reserve::(q,4usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +match std.heap.reserve::(q,4usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,17u64); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,17u64); +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,18u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 31,marker: 31 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,18u64); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,18u64); +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,31u64); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,31u64); +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),7u64,22u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 34,marker: 34 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,34u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 35,marker: 35 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,34u64); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,34u64); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,34u64); +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,35u64); +} +{ +match std.heap.push::(q,Item { priority: 2,id: 38,marker: 38 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,38u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 39,marker: 39 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,39u64); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,39u64); +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,38u64); +} +{ +match std.heap.push::(q,Item { priority: 2,id: 41,marker: 41 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,38u64); +} +{ +checked(extracted::(std.heap.pop::(q)),2u64,38u64); +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,41u64); +} +{ +match std.heap.reserve::(q,0usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,41u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 44,marker: 44 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,41u64); +} +{ +checked(extracted::(std.heap.pop::(q)),2u64,41u64); +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,35u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 46,marker: 46 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 47,marker: 47 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 48,marker: 48 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 18446744073709551615,id: 49,marker: 49 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 50,marker: 50 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,0u64,50u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 51,marker: 51 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,0u64,51u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 52,marker: 52 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,1u64,52u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 53,marker: 53 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,0u64,53u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,46u64); +} +{ +checked(extracted::(std.heap.pop::(q)),0u64,46u64); +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,48u64); +} +{ +checked(extracted::(std.heap.pop::(q)),0u64,48u64); +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,47u64); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,47u64); +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,35u64); +} +{ +match std.heap.push::(q,Item { priority: 2,id: 57,marker: 57 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 58,marker: 58 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,58u64); +} +{ +match std.heap.reserve::(q,0usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,58u64); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),0u64,58u64); +} +{ +checked(extracted::(std.heap.pop::(q)),0u64,58u64); +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 7,id: 62,marker: 62 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 18446744073709551615,id: 63,marker: 63 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 18446744073709551615,id: 65,marker: 65 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,18446744073709551615u64,65u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 66,marker: 66 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,0u64,66u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 67,marker: 67 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,1u64,67u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 68,marker: 68 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,1u64,68u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 0,id: 69,marker: 69 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,0u64,69u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 70,marker: 70 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,3u64,70u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),2u64,57u64); +} +{ +checked(extracted::(std.heap.pop::(q)),2u64,57u64); +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,35u64); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,35u64); +} +{ +match std.heap.push::(q,Item { priority: 1,id: 73,marker: 73 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,73u64); +} +{ +match std.heap.push::(q,Item { priority: 2,id: 74,marker: 74 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,2u64,74u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,73u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 75,marker: 75 }) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(item,3u64,75u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),1u64,73u64); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,73u64); +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,35u64); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,35u64); +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,44u64); +} +{ +match std.heap.push::(q,Item { priority: 3,id: 78,marker: 78 }) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,44u64); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,44u64); +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),3u64,78u64); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,78u64); +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +checked(extracted::(std.heap.peek::(ref q)),7u64,22u64); +} +checked(extracted::(std.heap.pop::(q)),7u64,22u64); +checked(extracted::(std.heap.pop::(q)),7u64,62u64); +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,15u64); +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,49u64); +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,63u64); + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/model_owner.aji b/tests/conformance/source/heap/model_owner.aji new file mode 100644 index 0000000..f4ad1ff --- /dev/null +++ b/tests/conformance/source/heap/model_owner.aji @@ -0,0 +1,398 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:2048 +// fuel: 2000000 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, id: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority > b.priority or (a.priority == b.priority and a.id < b.id); } +fn checked(item: Item,priority: u64,id: u64) -> void effects [] { +let (actual_priority,actual_id,owner) = struct.unpack(move item); assert(actual_priority == priority); assert(actual_id == id); assert(own.take(move owner) == id); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(2,heap); + { mut q = value; +{ +match std.heap.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 2,id: 4,owner: own.new(4u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 5,owner: own.new(5u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 7,owner: own.new(7u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,18446744073709551615u64,7u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,5u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),2u64,4u64); +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 7,id: 10,owner: own.new(10u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 2,id: 11,owner: own.new(11u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 3,id: 12,owner: own.new(12u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,3u64,12u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 13,owner: own.new(13u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,1u64,13u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 2,id: 14,owner: own.new(14u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,2u64,14u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 2,id: 15,owner: own.new(15u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,2u64,15u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),7u64,10u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 18,owner: own.new(18u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 19,owner: own.new(19u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,1u64,19u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),2u64,11u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,18u64); +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 22,owner: own.new(22u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 23,owner: own.new(23u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 24,owner: own.new(24u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,1u64,24u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 0,id: 25,owner: own.new(25u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,0u64,25u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 2,id: 26,owner: own.new(26u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,2u64,26u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,23u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,22u64); +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } +assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 0,id: 30,owner: own.new(30u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 7,id: 31,owner: own.new(31u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.reserve::(q,0usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),7u64,31u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 34,owner: own.new(34u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,34u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 36,owner: own.new(36u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 7,id: 37,owner: own.new(37u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,7u64,37u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,36u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 39,owner: own.new(39u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 40,owner: own.new(40u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,1u64,40u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 41,owner: own.new(41u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,18446744073709551615u64,41u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 3,id: 42,owner: own.new(42u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,3u64,42u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,39u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.reserve::(q,2usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 3,id: 45,owner: own.new(45u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,45u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 47,owner: own.new(47u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),1u64,47u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 49,owner: own.new(49u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 1,id: 50,owner: own.new(50u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,1u64,50u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 2,id: 51,owner: own.new(51u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,2u64,51u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,49u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 7,id: 53,owner: own.new(53u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +let incoming = Item { priority: 3,id: 54,owner: own.new(54u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,3u64,54u64); } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 2usize); +} +{ +match std.heap.reserve::(q,8usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),7u64,53u64); +assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 3,id: 57,owner: own.new(57u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +match std.heap.reserve::(q,4usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 2usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 7,id: 59,owner: own.new(59u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 3usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 3,id: 60,owner: own.new(60u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 0,id: 61,owner: own.new(61u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +match std.heap.reserve::(q,0usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),7u64,59u64); +assert(std.heap.len::(ref q) == 4usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 3,id: 64,owner: own.new(64u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 3,id: 65,owner: own.new(65u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +match std.heap.reserve::(q,8usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,57u64); +assert(std.heap.len::(ref q) == 5usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 7,id: 68,owner: own.new(68u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 1,id: 69,owner: own.new(69u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 70,owner: own.new(70u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 71,owner: own.new(71u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,18446744073709551615u64,71u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 18446744073709551615,id: 72,owner: own.new(72u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { trap; }, std.heap.PushResult::::full(item) => { checked(move item,18446744073709551615u64,72u64); } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),18446744073709551615u64,70u64); +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),7u64,68u64); +assert(std.heap.len::(ref q) == 6usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 0,id: 75,owner: own.new(75u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 1,id: 76,owner: own.new(76u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +match std.heap.reserve::(q,8usize,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,60u64); +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +let incoming = Item { priority: 3,id: 79,owner: own.new(79u64,heap) or trap }; +match std.heap.push::(q,move incoming) { std.heap.PushResult::::ok => { }, std.heap.PushResult::::full(item) => { trap; } } +assert(std.heap.len::(ref q) == 8usize); assert(std.heap.capacity::(ref q) == 8usize); +} +{ +checked(extracted::(std.heap.pop::(q)),3u64,64u64); +assert(std.heap.len::(ref q) == 7usize); assert(std.heap.capacity::(ref q) == 8usize); +} +checked(extracted::(std.heap.pop::(q)),3u64,65u64); +checked(extracted::(std.heap.pop::(q)),3u64,79u64); +checked(extracted::(std.heap.pop::(q)),1u64,69u64); +checked(extracted::(std.heap.pop::(q)),1u64,76u64); +checked(extracted::(std.heap.pop::(q)),0u64,30u64); +checked(extracted::(std.heap.pop::(q)),0u64,61u64); +checked(extracted::(std.heap.pop::(q)),0u64,75u64); + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/not_share.aji b/tests/conformance/source/heap/not_share.aji new file mode 100644 index 0000000..d7ba512 --- /dev/null +++ b/tests/conformance/source/heap/not_share.aji @@ -0,0 +1,17 @@ +// expect: reject E4002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, file: file } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn worker(q: ref>) -> void effects [] {} +fn bad(q: ref>) -> 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; } diff --git a/tests/conformance/source/heap/overflow.aji b/tests/conformance/source/heap/overflow.aji new file mode 100644 index 0000000..e910342 --- /dev/null +++ b/tests/conformance/source/heap/overflow.aji @@ -0,0 +1,23 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:0 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let maximum = 0usize -% 1usize; + match std.heap.new::(maximum / 16usize + 1usize,heap) { std.heap.NewResult::::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }, std.heap.NewResult::::ok(value) => { trap; } } + let value = opened::(0,heap); + { mut q = value; match std.heap.reserve::(q,maximum / 8usize + 1usize,heap) { std.heap.ReserveResult::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }, std.heap.ReserveResult::ok => { trap; } } } + released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/owner.aji b/tests/conformance/source/heap/owner.aji new file mode 100644 index 0000000..4eb5618 --- /dev/null +++ b/tests/conformance/source/heap/owner.aji @@ -0,0 +1,27 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:88 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(2,heap); + { mut q = value; + let first = Item { priority: 9,owner: own.new(9u64,heap) or trap }; pushed::(std.heap.push::(q,move first)); + let second = Item { priority: 1,owner: own.new(1u64,heap) or trap }; pushed::(std.heap.push::(q,move second)); + let full = Item { priority: 42,owner: own.new(42u64,heap) or trap }; + match std.heap.push::(q,move full) { std.heap.PushResult::::full(item) => { consumed(move item,42); }, std.heap.PushResult::::ok => { trap; } } + consumed(extracted::(std.heap.pop::(q)),1); consumed(extracted::(std.heap.pop::(q)),9); + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/owner_failure.aji b/tests/conformance/source/heap/owner_failure.aji new file mode 100644 index 0000000..07bf497 --- /dev/null +++ b/tests/conformance/source/heap/owner_failure.aji @@ -0,0 +1,29 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:111 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn check(heap: cap) -> void effects [mem.alloc] { + let value = opened::(1,heap); + { mut q = value; let item = Item { priority: 42,owner: own.new(42u64,heap) or trap }; pushed::(std.heap.push::(q,move item)); + match std.heap.reserve::(q,2,heap) { std.heap.ReserveResult::err(error) => {}, std.heap.ReserveResult::ok => { trap; } } + assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 1usize); + consumed(extracted::(std.heap.pop::(q)),42); + } released::(move value); + let allocation = own.new([0u8;55],heap) or trap; own.free(move allocation); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let first = cap.narrow.budget(heap,55usize) or trap; check(first); let second = cap.narrow.budget(heap,56usize) or trap; check(second); return 42; +} diff --git a/tests/conformance/source/heap/owner_growth.aji b/tests/conformance/source/heap/owner_growth.aji new file mode 100644 index 0000000..eaae75c --- /dev/null +++ b/tests/conformance/source/heap/owner_growth.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:104 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(1,heap); + { mut q = value; let item = Item { priority: 42,owner: own.new(42u64,heap) or trap }; pushed::(std.heap.push::(q,move item)); + match std.heap.reserve::(q,2,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } + let allocation = own.new([0u8;32],heap) or trap; own.free(move allocation); + consumed(extracted::(std.heap.pop::(q)),42); + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/peek_owner.aji b/tests/conformance/source/heap/peek_owner.aji new file mode 100644 index 0000000..8382f73 --- /dev/null +++ b/tests/conformance/source/heap/peek_owner.aji @@ -0,0 +1,17 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn bad(q: ref>) -> void effects [] { std.heap.peek::(q); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/permutations.aji b/tests/conformance/source/heap/permutations.aji new file mode 100644 index 0000000..bb28976 --- /dev/null +++ b/tests/conformance/source/heap/permutations.aji @@ -0,0 +1,146 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:120 +// fuel: 2000000 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn check(values: slice,heap: cap) -> void effects [mem.alloc] { + let value = opened::(5,heap); + { mut q = value; + for i in 0usize..5usize { pushed::(std.heap.push::(q,values[i])); } + for i in 0usize..5usize { assert(extracted::(std.heap.peek::(ref q)) == i as! u64); assert(extracted::(std.heap.pop::(q)) == i as! u64); } + } released::(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { +{ let values: [u64;5] = [0u64,1u64,2u64,3u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,1u64,2u64,4u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,1u64,3u64,2u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,1u64,3u64,4u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,1u64,4u64,2u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,1u64,4u64,3u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,2u64,1u64,3u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,2u64,1u64,4u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,2u64,3u64,1u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,2u64,3u64,4u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,2u64,4u64,1u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,2u64,4u64,3u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,3u64,1u64,2u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,3u64,1u64,4u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,3u64,2u64,1u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,3u64,2u64,4u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,3u64,4u64,1u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,3u64,4u64,2u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,4u64,1u64,2u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,4u64,1u64,3u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,4u64,2u64,1u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,4u64,2u64,3u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,4u64,3u64,1u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [0u64,4u64,3u64,2u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,0u64,2u64,3u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,0u64,2u64,4u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,0u64,3u64,2u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,0u64,3u64,4u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,0u64,4u64,2u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,0u64,4u64,3u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,2u64,0u64,3u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,2u64,0u64,4u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,2u64,3u64,0u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,2u64,3u64,4u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,2u64,4u64,0u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,2u64,4u64,3u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,3u64,0u64,2u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,3u64,0u64,4u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,3u64,2u64,0u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,3u64,2u64,4u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,3u64,4u64,0u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,3u64,4u64,2u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,4u64,0u64,2u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,4u64,0u64,3u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,4u64,2u64,0u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,4u64,2u64,3u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,4u64,3u64,0u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [1u64,4u64,3u64,2u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,0u64,1u64,3u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,0u64,1u64,4u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,0u64,3u64,1u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,0u64,3u64,4u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,0u64,4u64,1u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,0u64,4u64,3u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,1u64,0u64,3u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,1u64,0u64,4u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,1u64,3u64,0u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,1u64,3u64,4u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,1u64,4u64,0u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,1u64,4u64,3u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,3u64,0u64,1u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,3u64,0u64,4u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,3u64,1u64,0u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,3u64,1u64,4u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,3u64,4u64,0u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,3u64,4u64,1u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,4u64,0u64,1u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,4u64,0u64,3u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,4u64,1u64,0u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,4u64,1u64,3u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,4u64,3u64,0u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [2u64,4u64,3u64,1u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,0u64,1u64,2u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,0u64,1u64,4u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,0u64,2u64,1u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,0u64,2u64,4u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,0u64,4u64,1u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,0u64,4u64,2u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,1u64,0u64,2u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,1u64,0u64,4u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,1u64,2u64,0u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,1u64,2u64,4u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,1u64,4u64,0u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,1u64,4u64,2u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,2u64,0u64,1u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,2u64,0u64,4u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,2u64,1u64,0u64,4u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,2u64,1u64,4u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,2u64,4u64,0u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,2u64,4u64,1u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,4u64,0u64,1u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,4u64,0u64,2u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,4u64,1u64,0u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,4u64,1u64,2u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,4u64,2u64,0u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [3u64,4u64,2u64,1u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,0u64,1u64,2u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,0u64,1u64,3u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,0u64,2u64,1u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,0u64,2u64,3u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,0u64,3u64,1u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,0u64,3u64,2u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,1u64,0u64,2u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,1u64,0u64,3u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,1u64,2u64,0u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,1u64,2u64,3u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,1u64,3u64,0u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,1u64,3u64,2u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,2u64,0u64,1u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,2u64,0u64,3u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,2u64,1u64,0u64,3u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,2u64,1u64,3u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,2u64,3u64,0u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,2u64,3u64,1u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,3u64,0u64,1u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,3u64,0u64,2u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,3u64,1u64,0u64,2u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,3u64,1u64,2u64,0u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,3u64,2u64,0u64,1u64]; check(ref values,heap); } +{ let values: [u64;5] = [4u64,3u64,2u64,1u64,0u64]; check(ref values,heap); } +return 42; +} diff --git a/tests/conformance/source/heap/policy_effect.aji b/tests/conformance/source/heap/policy_effect.aji new file mode 100644 index 0000000..fa0b34a --- /dev/null +++ b/tests/conformance/source/heap/policy_effect.aji @@ -0,0 +1,15 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [io.stdout] { return *a < *b; } +fn bad(heap: cap) -> void effects [mem.alloc] { let value = opened::(0,heap); released::(move value); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/policy_mismatch.aji b/tests/conformance/source/heap/policy_mismatch.aji new file mode 100644 index 0000000..f059e73 --- /dev/null +++ b/tests/conformance/source/heap/policy_mismatch.aji @@ -0,0 +1,16 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn bad(q: ref>) -> usize effects [] { return std.heap.len::(q); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/pop_leak.aji b/tests/conformance/source/heap/pop_leak.aji new file mode 100644 index 0000000..50660bc --- /dev/null +++ b/tests/conformance/source/heap/pop_leak.aji @@ -0,0 +1,17 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Item { priority: u64, owner: own } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn consumed(item: Item,expected: u64) -> void effects [] { let (priority,owner) = struct.unpack(move item); assert(priority == expected); assert(own.take(move owner) == expected); } +fn bad(q: mut>) -> void effects [] { match std.heap.pop::(q) { std.option.Option::::some(item) => { return; }, std.option.Option::::none => {} } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/heap/reserve_authority.aji b/tests/conformance/source/heap/reserve_authority.aji new file mode 100644 index 0000000..c0ce545 --- /dev/null +++ b/tests/conformance/source/heap/reserve_authority.aji @@ -0,0 +1,26 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:72 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let first = cap.narrow.budget(heap,24usize) or trap; let second = cap.narrow.budget(heap,48usize) or trap; + let value = opened::(1,first); + { mut q = value; pushed::(std.heap.push::(q,42)); + match std.heap.reserve::(q,2,second) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } + let allocation = own.new([0u8;24],first) or trap; own.free(move allocation); + assert(extracted::(std.heap.pop::(q)) == 42u64); + } released::(move value); + let allocation = own.new([0u8;48],second) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/heap/reserve_failure.aji b/tests/conformance/source/heap/reserve_failure.aji new file mode 100644 index 0000000..3fda521 --- /dev/null +++ b/tests/conformance/source/heap/reserve_failure.aji @@ -0,0 +1,29 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:79 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn check(heap: cap) -> void effects [mem.alloc] { + let value = opened::(1,heap); + { mut q = value; pushed::(std.heap.push::(q,42)); + match std.heap.reserve::(q,2,heap) { std.heap.ReserveResult::err(error) => {}, std.heap.ReserveResult::ok => { trap; } } + assert(std.heap.len::(ref q) == 1usize); assert(std.heap.capacity::(ref q) == 1usize); + assert(extracted::(std.heap.peek::(ref q)) == 42u64); assert(extracted::(std.heap.pop::(q)) == 42u64); + } released::(move value); + let allocation = own.new([0u8;39],heap) or trap; own.free(move allocation); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let first = cap.narrow.budget(heap,39usize) or trap; check(first); + let second = cap.narrow.budget(heap,40usize) or trap; check(second); return 42; +} diff --git a/tests/conformance/source/heap/reserve_peak.aji b/tests/conformance/source/heap/reserve_peak.aji new file mode 100644 index 0000000..50bf323 --- /dev/null +++ b/tests/conformance/source/heap/reserve_peak.aji @@ -0,0 +1,24 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:72 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(1,heap); + { mut q = value; pushed::(std.heap.push::(q,42)); + match std.heap.reserve::(q,2,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } + let allocation = own.new([0u8;24],heap) or trap; own.free(move allocation); + assert(extracted::(std.heap.pop::(q)) == 42u64); + } released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/rollback.aji b/tests/conformance/source/heap/rollback.aji new file mode 100644 index 0000000..bf99869 --- /dev/null +++ b/tests/conformance/source/heap/rollback.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:16 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.heap.new::(1,heap) { std.heap.NewResult::::err(error) => { match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } }, std.heap.NewResult::::ok(value) => { trap; } } + let allocation = own.new([0u8;16],heap) or trap; own.free(move allocation); return 42; +} diff --git a/tests/conformance/source/heap/sender.aji b/tests/conformance/source/heap/sender.aji new file mode 100644 index 0000000..98e8d83 --- /dev/null +++ b/tests/conformance/source/heap/sender.aji @@ -0,0 +1,36 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:256 +// schedules: 12 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +struct Job { number: u64 } +struct Item { priority: u64, tx: sender } +fn before(a: ref,b: ref) -> bool effects [] { return a.priority < b.priority; } +fn worker(value: std.heap.BinaryHeap) -> void effects [task.wait] { + { mut q = value; + let item = extracted::(std.heap.pop::(q)); let (priority,tx) = struct.unpack(move item); assert(priority == 1u64); + channel.send(tx,Job { number: 41 }) or trap; channel.close_sender(move tx); + let item = extracted::(std.heap.pop::(q)); let (priority,tx) = struct.unpack(move item); assert(priority == 9u64); + channel.send(tx,Job { number: 42 }) or trap; channel.close_sender(move tx); + } released::(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc,task.spawn,task.wait] { + match channel.make(2,heap) { ok(tx,rx) => { + let second = channel.dup(tx); + let value = opened::(2,heap); + { mut q = value; let first = Item { priority: 9,tx: move tx }; pushed::(std.heap.push::(q,move first)); + let next = Item { priority: 1,tx: move second }; pushed::(std.heap.push::(q,move next)); } + scope s { let task = task.spawn(s,worker,move value); let first = channel.recv(rx) or trap; let next = channel.recv(rx) or trap; task.join(move task); + assert(first.number == 41u64); assert(next.number == 42u64); channel.close_receiver(move rx) or trap; } + }, err(error) => { trap; } } return 42; +} diff --git a/tests/conformance/source/heap/shared.aji b/tests/conformance/source/heap/shared.aji new file mode 100644 index 0000000..d43f6a6 --- /dev/null +++ b/tests/conformance/source/heap/shared.aji @@ -0,0 +1,24 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:48 +// schedules: 12 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn worker(q: ref>) -> u64 effects [] { return extracted::(std.heap.peek::(q)); } +fn main(heap: cap) -> u64 effects [mem.alloc,task.spawn,task.wait] { + let value = opened::(2,heap); { mut q = value; pushed::(std.heap.push::(q,43)); pushed::(std.heap.push::(q,42)); } + { ref q = value; 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 = value; assert(extracted::(std.heap.pop::(q)) == 42u64); assert(extracted::(std.heap.pop::(q)) == 43u64); } + released::(move value); return 42; +} diff --git a/tests/conformance/source/heap/zero.aji b/tests/conformance/source/heap/zero.aji new file mode 100644 index 0000000..722f6b0 --- /dev/null +++ b/tests/conformance/source/heap/zero.aji @@ -0,0 +1,26 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.16 +// grant: heap=mem.alloc:0 +module test.heap +import std.heap; +import std.option; +fn opened,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.heap.BinaryHeap effects [mem.alloc] { + match std.heap.new::(capacity,heap) { std.heap.NewResult::::ok(value) => { return move value; }, std.heap.NewResult::::err(error) => { trap; } } +} +fn pushed(result: std.heap.PushResult) -> void effects [] { match move result { std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } } } +fn extracted(result: std.option.Option) -> T effects [] { match move result { std.option.Option::::some(item) => { return move item; }, std.option.Option::::none => { trap; } } } +fn released,ref) -> bool effects []>(value: std.heap.BinaryHeap) -> void effects [] { match std.heap.free::(move value) { std.heap.FreeResult::::ok => {}, std.heap.FreeResult::::not_empty(value) => { trap; } } } +fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn after(a: ref,b: ref) -> bool effects [] { return *a > *b; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let value = opened::(0,heap); + { mut q = value; + assert(std.heap.len::(ref q) == 0usize); assert(std.heap.capacity::(ref q) == 0usize); + match std.heap.push::(q,42) { std.heap.PushResult::::full(item) => { assert(item == 42u64); }, std.heap.PushResult::::ok => { trap; } } + match std.heap.peek::(ref q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } + match std.heap.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } } + match std.heap.reserve::(q,0,heap) { std.heap.ReserveResult::ok => {}, std.heap.ReserveResult::err(error) => { trap; } } + } released::(move value); return 42; +} diff --git a/tests/conformance/source/integers/switch_duplicate_spelling.aji b/tests/conformance/source/integers/switch_duplicate_spelling.aji new file mode 100644 index 0000000..da93faf --- /dev/null +++ b/tests/conformance/source/integers/switch_duplicate_spelling.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §6 +module test.integer_patterns +fn main() -> u64 effects [] { + return match 42u64 { 42u64 => { 42u64 }, 0x2_au64 => { 0u64 }, _ => { 99u64 } }; +} diff --git a/tests/conformance/source/integers/switch_literal_range.aji b/tests/conformance/source/integers/switch_literal_range.aji new file mode 100644 index 0000000..7ddf6fd --- /dev/null +++ b/tests/conformance/source/integers/switch_literal_range.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/07a-air-instructions.md switch.I; docs/spec/15-source-language.md §6 +module test.integer_patterns +fn main() -> u64 effects [] { + return match 0u8 { 256 => { 42u64 }, _ => { 0u64 } }; +} diff --git a/tests/conformance/source/integers/switch_literals.aji b/tests/conformance/source/integers/switch_literals.aji new file mode 100644 index 0000000..6f78c63 --- /dev/null +++ b/tests/conformance/source/integers/switch_literals.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §6; docs/spec/07-air.md §8.5 +module test.integer_patterns +fn unsigned(value: u64) -> u64 effects [] { + return match value { 0x2_au64 => { 42u64 }, 0u64 => { 0u64 }, _ => { 99u64 } }; +} +fn signed(value: i64) -> u64 effects [] { + return match value { -0x2ai64 => { 42u64 }, -0i64 => { 0u64 }, _ => { 99u64 } }; +} +fn main() -> u64 effects [] { + assert(unsigned(42u64) == 42u64); assert(unsigned(0u64) == 0u64); + assert(signed(-42i64) == 42u64); assert(signed(0i64) == 0u64); + let maximum = 340282366920938463463374607431768211455u128; + match maximum { 0xffffffffffffffffffffffffffffffffu128 => {}, _ => { trap; } } + let minimum = -170141183460469231731687303715884105728i128; + match minimum { -170141183460469231731687303715884105728i128 => {}, _ => { trap; } } + return 42; +} diff --git a/tests/conformance/source/integers/switch_negative_unsigned.aji b/tests/conformance/source/integers/switch_negative_unsigned.aji new file mode 100644 index 0000000..c09df82 --- /dev/null +++ b/tests/conformance/source/integers/switch_negative_unsigned.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §6 +module test.integer_patterns +fn main() -> u64 effects [] { + return match 0u8 { -1 => { 42u64 }, _ => { 0u64 } }; +} diff --git a/tests/conformance/source/io/alias.aji b/tests/conformance/source/io/alias.aji new file mode 100644 index 0000000..fa3876a --- /dev/null +++ b/tests/conformance/source/io/alias.aji @@ -0,0 +1,10 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: cap,destination: slice_mut) -> void effects [io.read] { ref view = destination[0usize..0usize]; std.io.read_exact_stdin(input,destination); assert(view.len == 0usize); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/append.aji b/tests/conformance/source/io/append.aji new file mode 100644 index 0000000..dc1ad8d --- /dev/null +++ b/tests/conformance/source/io/append.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// grant: dst=fs.write:/out +// vfs: /in/data=abcd +// file: /out/data=old:abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; let initial = fs.create(dst,b"/out/data") or trap; fs.write_all(initial,b"old:") or trap; fs.close(move initial) or trap; + let output = fs.open_append(dst,b"/out/data") or trap; var bytes: [u8;1] = [0u8;1]; + match std.io.copy_file_append(mut input,mut output,mut bytes,8usize) { std.io.CopyResult::eof(count) => { assert(count == 4usize); }, std.io.CopyResult::limit(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } } + fs.close(move input) or trap; fs.close(move output) or trap; return 42; +} diff --git a/tests/conformance/source/io/close_borrowed.aji b/tests/conformance/source/io/close_borrowed.aji new file mode 100644 index 0000000..11385b1 --- /dev/null +++ b/tests/conformance/source/io/close_borrowed.aji @@ -0,0 +1,10 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: file,destination: slice_mut) -> void effects [fs.read] { mut q = input; fs.close(move input) or trap; std.io.read_exact_file(q,destination); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/copy.aji b/tests/conformance/source/io/copy.aji new file mode 100644 index 0000000..8d77788 --- /dev/null +++ b/tests/conformance/source/io/copy.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// grant: dst=fs.write:/out +// vfs: /in/data=abcd +// file: /out/data=abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; + var bytes: [u8;4] = [99u8;4]; + match std.io.copy_file(mut input,mut output,mut bytes[1usize..3usize],10usize) { std.io.CopyResult::eof(count) => { assert(count == 4usize); }, std.io.CopyResult::limit(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } } + assert(bytes[0] == 99u8); assert(bytes[3] == 99u8); fs.close(move input) or trap; fs.close(move output) or trap; return 42; +} diff --git a/tests/conformance/source/io/copy_exact_limit.aji b/tests/conformance/source/io/copy_exact_limit.aji new file mode 100644 index 0000000..204148d --- /dev/null +++ b/tests/conformance/source/io/copy_exact_limit.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// grant: dst=fs.write:/out +// vfs: /in/data=abcd +// file: /out/data=abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; var bytes: [u8;2] = [0u8;2]; + match std.io.copy_file(mut input,mut output,mut bytes,4usize) { std.io.CopyResult::limit(count) => { assert(count == 4usize); }, std.io.CopyResult::eof(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } } + match std.io.read_exact_file(mut input,mut bytes) { std.io.ReadExactResult::eof(count) => { assert(count == 0usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } + fs.close(move input) or trap; fs.close(move output) or trap; return 42; +} diff --git a/tests/conformance/source/io/copy_limit.aji b/tests/conformance/source/io/copy_limit.aji new file mode 100644 index 0000000..329a2d9 --- /dev/null +++ b/tests/conformance/source/io/copy_limit.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// grant: dst=fs.write:/out +// vfs: /in/data=abcd +// file: /out/data=abc +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; var bytes: [u8;4] = [99u8;4]; + match std.io.copy_file(mut input,mut output,mut bytes[1usize..3usize],3usize) { std.io.CopyResult::limit(count) => { assert(count == 3usize); }, std.io.CopyResult::eof(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } } + assert(bytes[0] == 99u8); assert(bytes[3] == 99u8); + var tail: [u8;1] = [0u8;1]; exact(std.io.read_exact_file(mut input,mut tail)); assert(tail[0] == 100u8); + fs.close(move input) or trap; fs.close(move output) or trap; return 42; +} diff --git a/tests/conformance/source/io/copy_missing_write.aji b/tests/conformance/source/io/copy_missing_write.aji new file mode 100644 index 0000000..9dc596c --- /dev/null +++ b/tests/conformance/source/io/copy_missing_write.aji @@ -0,0 +1,10 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: mut>,output: mut>,scratch: slice_mut) -> void effects [fs.read] { std.io.copy_file(input,output,scratch,0usize); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/copy_mode.aji b/tests/conformance/source/io/copy_mode.aji new file mode 100644 index 0000000..ae2721f --- /dev/null +++ b/tests/conformance/source/io/copy_mode.aji @@ -0,0 +1,10 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: mut>,output: mut>,scratch: slice_mut) -> void effects [fs.read,fs.write] { std.io.copy_file(input,output,scratch,0usize); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/file.aji b/tests/conformance/source/io/file.aji new file mode 100644 index 0000000..1c49feb --- /dev/null +++ b/tests/conformance/source/io/file.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// vfs: /in/data=abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap) -> u64 effects [fs.read] { + let file = fs.open_read(src,b"/in/data") or trap; + var bytes: [u8;6] = [99u8;6]; + exact(std.io.read_exact_file(mut file,mut bytes[1usize..4usize])); + assert(bytes[0] == 99u8); assert(bytes[1] == 97u8); assert(bytes[2] == 98u8); assert(bytes[3] == 99u8); assert(bytes[4] == 99u8); assert(bytes[5] == 99u8); + match std.io.read_exact_file(mut file,mut bytes[4usize..6usize]) { std.io.ReadExactResult::eof(count) => { assert(count == 1usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } + assert(bytes[4] == 100u8); assert(bytes[5] == 99u8); + exact(std.io.read_exact_file(mut file,mut bytes[0usize..0usize])); fs.close(move file) or trap; return 42; +} diff --git a/tests/conformance/source/io/loan.aji b/tests/conformance/source/io/loan.aji new file mode 100644 index 0000000..26dad29 --- /dev/null +++ b/tests/conformance/source/io/loan.aji @@ -0,0 +1,12 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn worker(input: cap,destination: slice_mut) -> void effects [io.read] { exact(std.io.read_exact_stdin(input,destination)); } +fn bad(input: cap,destination: slice_mut) -> void effects [io.read,task.spawn,task.wait] { + scope s { let task = task.spawn(s,worker,input,destination); std.io.read_exact_stdin(input,destination); task.join(move task); } +} fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/loan_join.aji b/tests/conformance/source/io/loan_join.aji new file mode 100644 index 0000000..1ccc35c --- /dev/null +++ b/tests/conformance/source/io/loan_join.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: input=io.read +// stdin: abcd +// schedules: 12 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn worker(input: cap,destination: slice_mut) -> void effects [io.read] { exact(std.io.read_exact_stdin(input,destination)); } +fn main(input: cap) -> u64 effects [io.read,task.spawn,task.wait] { + var bytes: [u8;2] = [0u8;2]; { mut q = bytes; scope s { let task = task.spawn(s,worker,input,q); task.join(move task); exact(std.io.read_exact_stdin(input,q)); } } + assert(bytes[0] == 99u8); assert(bytes[1] == 100u8); return 42; +} diff --git a/tests/conformance/source/io/maximum_limit.aji b/tests/conformance/source/io/maximum_limit.aji new file mode 100644 index 0000000..a13afcd --- /dev/null +++ b/tests/conformance/source/io/maximum_limit.aji @@ -0,0 +1,18 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// grant: dst=fs.write:/out +// vfs: /in/data=abcd +// file: /out/data=abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; var bytes: [u8;2] = [0u8;2]; + match std.io.copy_file(mut input,mut output,mut bytes,0usize -% 1usize) { std.io.CopyResult::eof(count) => { assert(count == 4usize); }, std.io.CopyResult::limit(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } } + fs.close(move input) or trap; fs.close(move output) or trap; return 42; +} diff --git a/tests/conformance/source/io/missing_effect.aji b/tests/conformance/source/io/missing_effect.aji new file mode 100644 index 0000000..aabe500 --- /dev/null +++ b/tests/conformance/source/io/missing_effect.aji @@ -0,0 +1,10 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: cap,destination: slice_mut) -> void effects [] { std.io.read_exact_stdin(input,destination); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/model.aji b/tests/conformance/source/io/model.aji new file mode 100644 index 0000000..3e45edc --- /dev/null +++ b/tests/conformance/source/io/model.aji @@ -0,0 +1,392 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/case +// grant: dst=fs.write:/case +// file: /case/input=abcdefg +// file: /case/output=old:abcdefg +// fuel: 2000000 +module test.io +import std.io; +import std.bytes; +fn prepare(contents: slice,dst: cap) -> void effects [fs.write] { + let file = fs.create(dst,b"/case/input") or trap; fs.write_all(file,contents) or trap; fs.close(move file) or trap; +} +fn reads(contents: slice,capacity: usize,prefix: usize,filled: bool,src: cap,dst: cap) -> void effects [fs.read,fs.write] { + prepare(contents,dst); + for mode in 0usize..2usize { + let file = fs.open_read(src,b"/case/input") or trap; var bytes: [u8;12] = [255u8;12]; + if mode == 0usize { + match std.io.read_exact_file(mut file,mut bytes[1usize..capacity+1usize]) { + std.io.ReadExactResult::ok => { assert(filled); }, std.io.ReadExactResult::eof(count) => { assert(not filled); assert(count == prefix); }, std.io.ReadExactResult::err(error) => { trap; } + } + } else { + match std.io.read_to_end_file(mut file,mut bytes[1usize..capacity+1usize]) { + std.io.ReadToEndResult::full(count) => { assert(filled); assert(count == capacity); }, std.io.ReadToEndResult::eof(count) => { assert(not filled); assert(count == prefix); }, std.io.ReadToEndResult::err(error) => { trap; } + } + } + assert(std.bytes.equal(ref bytes[1usize..prefix+1usize],ref contents[0usize..prefix])); + assert(bytes[0] == 255u8); for i in prefix+1usize..12usize { assert(bytes[i] == 255u8); } + fs.close(move file) or trap; + } +} +fn copies(contents: slice,capacity: usize,limit: usize,append: bool,tag: u64,count: usize,expected: slice,tail: slice,src: cap,dst: cap) -> void effects [fs.read,fs.write] { + prepare(contents,dst); let input = fs.open_read(src,b"/case/input") or trap; + var bytes: [u8;8] = [255u8;8]; var result: std.io.CopyResult = std.io.CopyResult::limit(0usize); + if append { + let base = fs.create(dst,b"/case/output") or trap; fs.write_all(base,b"old:") or trap; fs.close(move base) or trap; + let output = fs.open_append(dst,b"/case/output") or trap; + result = std.io.copy_file_append(mut input,mut output,mut bytes[1usize..capacity+1usize],limit); fs.close(move output) or trap; + } else { + let output = fs.create(dst,b"/case/output") or trap; + result = std.io.copy_file(mut input,mut output,mut bytes[1usize..capacity+1usize],limit); fs.close(move output) or trap; + } + match result { + std.io.CopyResult::eof(actual) => { assert(tag == 0u64); assert(actual == count); }, + std.io.CopyResult::limit(actual) => { assert(tag == 1u64); assert(actual == count); }, + std.io.CopyResult::err(error) => { assert(tag == 2u64); assert(error.read == 0usize); assert(error.confirmed_written == 0usize); } + } + assert(bytes[0] == 255u8); for i in capacity+1usize..8usize { assert(bytes[i] == 255u8); } + var remaining: [u8;12] = [0u8;12]; + match std.io.read_to_end_file(mut input,mut remaining) { std.io.ReadToEndResult::eof(actual) => { assert(actual == tail.len); assert(std.bytes.equal(ref remaining[0usize..actual],tail)); }, std.io.ReadToEndResult::full(actual) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + fs.close(move input) or trap; + let output = fs.open_read(src,b"/case/output") or trap; var actual: [u8;12] = [0u8;12]; + match std.io.read_to_end_file(mut output,mut actual) { std.io.ReadToEndResult::eof(count) => { assert(count == expected.len); assert(std.bytes.equal(ref actual[0usize..count],expected)); }, std.io.ReadToEndResult::full(count) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + fs.close(move output) or trap; +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { +let blank: [u8;1] = [0u8;1]; +reads(ref blank[0usize..0usize],0usize,0usize,true,src,dst); +reads(ref blank[0usize..0usize],1usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],2usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],3usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],4usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],5usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],6usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],7usize,0usize,false,src,dst); +reads(ref blank[0usize..0usize],8usize,0usize,false,src,dst); +reads(b"a",0usize,0usize,true,src,dst); +reads(b"a",1usize,1usize,true,src,dst); +reads(b"a",2usize,1usize,false,src,dst); +reads(b"a",3usize,1usize,false,src,dst); +reads(b"a",4usize,1usize,false,src,dst); +reads(b"a",5usize,1usize,false,src,dst); +reads(b"a",6usize,1usize,false,src,dst); +reads(b"a",7usize,1usize,false,src,dst); +reads(b"a",8usize,1usize,false,src,dst); +reads(b"ab",0usize,0usize,true,src,dst); +reads(b"ab",1usize,1usize,true,src,dst); +reads(b"ab",2usize,2usize,true,src,dst); +reads(b"ab",3usize,2usize,false,src,dst); +reads(b"ab",4usize,2usize,false,src,dst); +reads(b"ab",5usize,2usize,false,src,dst); +reads(b"ab",6usize,2usize,false,src,dst); +reads(b"ab",7usize,2usize,false,src,dst); +reads(b"ab",8usize,2usize,false,src,dst); +reads(b"abc",0usize,0usize,true,src,dst); +reads(b"abc",1usize,1usize,true,src,dst); +reads(b"abc",2usize,2usize,true,src,dst); +reads(b"abc",3usize,3usize,true,src,dst); +reads(b"abc",4usize,3usize,false,src,dst); +reads(b"abc",5usize,3usize,false,src,dst); +reads(b"abc",6usize,3usize,false,src,dst); +reads(b"abc",7usize,3usize,false,src,dst); +reads(b"abc",8usize,3usize,false,src,dst); +reads(b"abcd",0usize,0usize,true,src,dst); +reads(b"abcd",1usize,1usize,true,src,dst); +reads(b"abcd",2usize,2usize,true,src,dst); +reads(b"abcd",3usize,3usize,true,src,dst); +reads(b"abcd",4usize,4usize,true,src,dst); +reads(b"abcd",5usize,4usize,false,src,dst); +reads(b"abcd",6usize,4usize,false,src,dst); +reads(b"abcd",7usize,4usize,false,src,dst); +reads(b"abcd",8usize,4usize,false,src,dst); +reads(b"abcde",0usize,0usize,true,src,dst); +reads(b"abcde",1usize,1usize,true,src,dst); +reads(b"abcde",2usize,2usize,true,src,dst); +reads(b"abcde",3usize,3usize,true,src,dst); +reads(b"abcde",4usize,4usize,true,src,dst); +reads(b"abcde",5usize,5usize,true,src,dst); +reads(b"abcde",6usize,5usize,false,src,dst); +reads(b"abcde",7usize,5usize,false,src,dst); +reads(b"abcde",8usize,5usize,false,src,dst); +reads(b"abcdef",0usize,0usize,true,src,dst); +reads(b"abcdef",1usize,1usize,true,src,dst); +reads(b"abcdef",2usize,2usize,true,src,dst); +reads(b"abcdef",3usize,3usize,true,src,dst); +reads(b"abcdef",4usize,4usize,true,src,dst); +reads(b"abcdef",5usize,5usize,true,src,dst); +reads(b"abcdef",6usize,6usize,true,src,dst); +reads(b"abcdef",7usize,6usize,false,src,dst); +reads(b"abcdef",8usize,6usize,false,src,dst); +reads(b"abcdefg",0usize,0usize,true,src,dst); +reads(b"abcdefg",1usize,1usize,true,src,dst); +reads(b"abcdefg",2usize,2usize,true,src,dst); +reads(b"abcdefg",3usize,3usize,true,src,dst); +reads(b"abcdefg",4usize,4usize,true,src,dst); +reads(b"abcdefg",5usize,5usize,true,src,dst); +reads(b"abcdefg",6usize,6usize,true,src,dst); +reads(b"abcdefg",7usize,7usize,true,src,dst); +reads(b"abcdefg",8usize,7usize,false,src,dst); +reads(b"abcdefgh",0usize,0usize,true,src,dst); +reads(b"abcdefgh",1usize,1usize,true,src,dst); +reads(b"abcdefgh",2usize,2usize,true,src,dst); +reads(b"abcdefgh",3usize,3usize,true,src,dst); +reads(b"abcdefgh",4usize,4usize,true,src,dst); +reads(b"abcdefgh",5usize,5usize,true,src,dst); +reads(b"abcdefgh",6usize,6usize,true,src,dst); +reads(b"abcdefgh",7usize,7usize,true,src,dst); +reads(b"abcdefgh",8usize,8usize,true,src,dst); +copies(ref blank[0usize..0usize],0usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,1usize,false,2u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,2usize,false,2u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,4usize,false,2u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,8usize,false,2u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,1usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,2usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,4usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,8usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,1usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,2usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,4usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,8usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,1usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,2usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,4usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,8usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,1usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,2usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,4usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,8usize,false,0u64,0usize,ref blank[0usize..0usize],ref blank[0usize..0usize],src,dst); +copies(b"a",0usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",0usize,1usize,false,2u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",0usize,2usize,false,2u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",0usize,4usize,false,2u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",0usize,8usize,false,2u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",1usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",1usize,1usize,false,1u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",1usize,2usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",1usize,4usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",1usize,8usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",2usize,1usize,false,1u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,2usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,4usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,8usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",3usize,1usize,false,1u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,2usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,4usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,8usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"a",src,dst); +copies(b"a",5usize,1usize,false,1u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,2usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,4usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,8usize,false,0u64,1usize,b"a",ref blank[0usize..0usize],src,dst); +copies(b"ab",0usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",0usize,1usize,false,2u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",0usize,2usize,false,2u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",0usize,4usize,false,2u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",0usize,8usize,false,2u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",1usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",1usize,1usize,false,1u64,1usize,b"a",b"b",src,dst); +copies(b"ab",1usize,2usize,false,1u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",1usize,4usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",1usize,8usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",2usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",2usize,1usize,false,1u64,1usize,b"a",b"b",src,dst); +copies(b"ab",2usize,2usize,false,1u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",2usize,4usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",2usize,8usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",3usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",3usize,1usize,false,1u64,1usize,b"a",b"b",src,dst); +copies(b"ab",3usize,2usize,false,1u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",3usize,4usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",3usize,8usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",5usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"ab",src,dst); +copies(b"ab",5usize,1usize,false,1u64,1usize,b"a",b"b",src,dst); +copies(b"ab",5usize,2usize,false,1u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",5usize,4usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",5usize,8usize,false,0u64,2usize,b"ab",ref blank[0usize..0usize],src,dst); +copies(b"abcd",0usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",0usize,1usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",0usize,2usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",0usize,4usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",0usize,8usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",1usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",1usize,1usize,false,1u64,1usize,b"a",b"bcd",src,dst); +copies(b"abcd",1usize,2usize,false,1u64,2usize,b"ab",b"cd",src,dst); +copies(b"abcd",1usize,4usize,false,1u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",1usize,8usize,false,0u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",2usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",2usize,1usize,false,1u64,1usize,b"a",b"bcd",src,dst); +copies(b"abcd",2usize,2usize,false,1u64,2usize,b"ab",b"cd",src,dst); +copies(b"abcd",2usize,4usize,false,1u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",2usize,8usize,false,0u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",3usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",3usize,1usize,false,1u64,1usize,b"a",b"bcd",src,dst); +copies(b"abcd",3usize,2usize,false,1u64,2usize,b"ab",b"cd",src,dst); +copies(b"abcd",3usize,4usize,false,1u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",3usize,8usize,false,0u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",5usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcd",src,dst); +copies(b"abcd",5usize,1usize,false,1u64,1usize,b"a",b"bcd",src,dst); +copies(b"abcd",5usize,2usize,false,1u64,2usize,b"ab",b"cd",src,dst); +copies(b"abcd",5usize,4usize,false,1u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",5usize,8usize,false,0u64,4usize,b"abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",0usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",0usize,1usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",0usize,2usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",0usize,4usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",0usize,8usize,false,2u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",1usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",1usize,1usize,false,1u64,1usize,b"a",b"bcdefg",src,dst); +copies(b"abcdefg",1usize,2usize,false,1u64,2usize,b"ab",b"cdefg",src,dst); +copies(b"abcdefg",1usize,4usize,false,1u64,4usize,b"abcd",b"efg",src,dst); +copies(b"abcdefg",1usize,8usize,false,0u64,7usize,b"abcdefg",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",2usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",2usize,1usize,false,1u64,1usize,b"a",b"bcdefg",src,dst); +copies(b"abcdefg",2usize,2usize,false,1u64,2usize,b"ab",b"cdefg",src,dst); +copies(b"abcdefg",2usize,4usize,false,1u64,4usize,b"abcd",b"efg",src,dst); +copies(b"abcdefg",2usize,8usize,false,0u64,7usize,b"abcdefg",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",3usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",3usize,1usize,false,1u64,1usize,b"a",b"bcdefg",src,dst); +copies(b"abcdefg",3usize,2usize,false,1u64,2usize,b"ab",b"cdefg",src,dst); +copies(b"abcdefg",3usize,4usize,false,1u64,4usize,b"abcd",b"efg",src,dst); +copies(b"abcdefg",3usize,8usize,false,0u64,7usize,b"abcdefg",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",5usize,0usize,false,1u64,0usize,ref blank[0usize..0usize],b"abcdefg",src,dst); +copies(b"abcdefg",5usize,1usize,false,1u64,1usize,b"a",b"bcdefg",src,dst); +copies(b"abcdefg",5usize,2usize,false,1u64,2usize,b"ab",b"cdefg",src,dst); +copies(b"abcdefg",5usize,4usize,false,1u64,4usize,b"abcd",b"efg",src,dst); +copies(b"abcdefg",5usize,8usize,false,0u64,7usize,b"abcdefg",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,0usize,true,1u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,1usize,true,2u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,2usize,true,2u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,4usize,true,2u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],0usize,8usize,true,2u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,0usize,true,1u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,1usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,2usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,4usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],1usize,8usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,0usize,true,1u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,1usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,2usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,4usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],2usize,8usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,0usize,true,1u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,1usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,2usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,4usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],3usize,8usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,0usize,true,1u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,1usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,2usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,4usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(ref blank[0usize..0usize],5usize,8usize,true,0u64,0usize,b"old:",ref blank[0usize..0usize],src,dst); +copies(b"a",0usize,0usize,true,1u64,0usize,b"old:",b"a",src,dst); +copies(b"a",0usize,1usize,true,2u64,0usize,b"old:",b"a",src,dst); +copies(b"a",0usize,2usize,true,2u64,0usize,b"old:",b"a",src,dst); +copies(b"a",0usize,4usize,true,2u64,0usize,b"old:",b"a",src,dst); +copies(b"a",0usize,8usize,true,2u64,0usize,b"old:",b"a",src,dst); +copies(b"a",1usize,0usize,true,1u64,0usize,b"old:",b"a",src,dst); +copies(b"a",1usize,1usize,true,1u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",1usize,2usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",1usize,4usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",1usize,8usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,0usize,true,1u64,0usize,b"old:",b"a",src,dst); +copies(b"a",2usize,1usize,true,1u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,2usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,4usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",2usize,8usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,0usize,true,1u64,0usize,b"old:",b"a",src,dst); +copies(b"a",3usize,1usize,true,1u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,2usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,4usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",3usize,8usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,0usize,true,1u64,0usize,b"old:",b"a",src,dst); +copies(b"a",5usize,1usize,true,1u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,2usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,4usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"a",5usize,8usize,true,0u64,1usize,b"old:a",ref blank[0usize..0usize],src,dst); +copies(b"ab",0usize,0usize,true,1u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",0usize,1usize,true,2u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",0usize,2usize,true,2u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",0usize,4usize,true,2u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",0usize,8usize,true,2u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",1usize,0usize,true,1u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",1usize,1usize,true,1u64,1usize,b"old:a",b"b",src,dst); +copies(b"ab",1usize,2usize,true,1u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",1usize,4usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",1usize,8usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",2usize,0usize,true,1u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",2usize,1usize,true,1u64,1usize,b"old:a",b"b",src,dst); +copies(b"ab",2usize,2usize,true,1u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",2usize,4usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",2usize,8usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",3usize,0usize,true,1u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",3usize,1usize,true,1u64,1usize,b"old:a",b"b",src,dst); +copies(b"ab",3usize,2usize,true,1u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",3usize,4usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",3usize,8usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",5usize,0usize,true,1u64,0usize,b"old:",b"ab",src,dst); +copies(b"ab",5usize,1usize,true,1u64,1usize,b"old:a",b"b",src,dst); +copies(b"ab",5usize,2usize,true,1u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",5usize,4usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"ab",5usize,8usize,true,0u64,2usize,b"old:ab",ref blank[0usize..0usize],src,dst); +copies(b"abcd",0usize,0usize,true,1u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",0usize,1usize,true,2u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",0usize,2usize,true,2u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",0usize,4usize,true,2u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",0usize,8usize,true,2u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",1usize,0usize,true,1u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",1usize,1usize,true,1u64,1usize,b"old:a",b"bcd",src,dst); +copies(b"abcd",1usize,2usize,true,1u64,2usize,b"old:ab",b"cd",src,dst); +copies(b"abcd",1usize,4usize,true,1u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",1usize,8usize,true,0u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",2usize,0usize,true,1u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",2usize,1usize,true,1u64,1usize,b"old:a",b"bcd",src,dst); +copies(b"abcd",2usize,2usize,true,1u64,2usize,b"old:ab",b"cd",src,dst); +copies(b"abcd",2usize,4usize,true,1u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",2usize,8usize,true,0u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",3usize,0usize,true,1u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",3usize,1usize,true,1u64,1usize,b"old:a",b"bcd",src,dst); +copies(b"abcd",3usize,2usize,true,1u64,2usize,b"old:ab",b"cd",src,dst); +copies(b"abcd",3usize,4usize,true,1u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",3usize,8usize,true,0u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",5usize,0usize,true,1u64,0usize,b"old:",b"abcd",src,dst); +copies(b"abcd",5usize,1usize,true,1u64,1usize,b"old:a",b"bcd",src,dst); +copies(b"abcd",5usize,2usize,true,1u64,2usize,b"old:ab",b"cd",src,dst); +copies(b"abcd",5usize,4usize,true,1u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcd",5usize,8usize,true,0u64,4usize,b"old:abcd",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",0usize,0usize,true,1u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",0usize,1usize,true,2u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",0usize,2usize,true,2u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",0usize,4usize,true,2u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",0usize,8usize,true,2u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",1usize,0usize,true,1u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",1usize,1usize,true,1u64,1usize,b"old:a",b"bcdefg",src,dst); +copies(b"abcdefg",1usize,2usize,true,1u64,2usize,b"old:ab",b"cdefg",src,dst); +copies(b"abcdefg",1usize,4usize,true,1u64,4usize,b"old:abcd",b"efg",src,dst); +copies(b"abcdefg",1usize,8usize,true,0u64,7usize,b"old:abcdefg",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",2usize,0usize,true,1u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",2usize,1usize,true,1u64,1usize,b"old:a",b"bcdefg",src,dst); +copies(b"abcdefg",2usize,2usize,true,1u64,2usize,b"old:ab",b"cdefg",src,dst); +copies(b"abcdefg",2usize,4usize,true,1u64,4usize,b"old:abcd",b"efg",src,dst); +copies(b"abcdefg",2usize,8usize,true,0u64,7usize,b"old:abcdefg",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",3usize,0usize,true,1u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",3usize,1usize,true,1u64,1usize,b"old:a",b"bcdefg",src,dst); +copies(b"abcdefg",3usize,2usize,true,1u64,2usize,b"old:ab",b"cdefg",src,dst); +copies(b"abcdefg",3usize,4usize,true,1u64,4usize,b"old:abcd",b"efg",src,dst); +copies(b"abcdefg",3usize,8usize,true,0u64,7usize,b"old:abcdefg",ref blank[0usize..0usize],src,dst); +copies(b"abcdefg",5usize,0usize,true,1u64,0usize,b"old:",b"abcdefg",src,dst); +copies(b"abcdefg",5usize,1usize,true,1u64,1usize,b"old:a",b"bcdefg",src,dst); +copies(b"abcdefg",5usize,2usize,true,1u64,2usize,b"old:ab",b"cdefg",src,dst); +copies(b"abcdefg",5usize,4usize,true,1u64,4usize,b"old:abcd",b"efg",src,dst); +copies(b"abcdefg",5usize,8usize,true,0u64,7usize,b"old:abcdefg",ref blank[0usize..0usize],src,dst); +return 42; +} diff --git a/tests/conformance/source/io/stdin.aji b/tests/conformance/source/io/stdin.aji new file mode 100644 index 0000000..1363b00 --- /dev/null +++ b/tests/conformance/source/io/stdin.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: input=io.read +// stdin: abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(input: cap) -> u64 effects [io.read] { + var bytes: [u8;6] = [99u8;6]; + exact(std.io.read_exact_stdin(input,mut bytes[1usize..4usize])); + assert(bytes[0] == 99u8); assert(bytes[1] == 97u8); assert(bytes[2] == 98u8); assert(bytes[3] == 99u8); assert(bytes[4] == 99u8); assert(bytes[5] == 99u8); + match std.io.read_exact_stdin(input,mut bytes[4usize..6usize]) { std.io.ReadExactResult::eof(count) => { assert(count == 1usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } + assert(bytes[4] == 100u8); assert(bytes[5] == 99u8); + exact(std.io.read_exact_stdin(input,mut bytes[0usize..0usize])); return 42; +} diff --git a/tests/conformance/source/io/tcp.aji b/tests/conformance/source/io/tcp.aji new file mode 100644 index 0000000..e2b107e --- /dev/null +++ b/tests/conformance/source/io/tcp.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: listen=net.listen +// grant: connect=net.connect +// schedules: 12 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn send(connect: cap) -> void effects [net.connect,net.write] { + let stream = net.connect(connect,b"127.0.0.1:7333") or trap; + for i in 0usize..4usize { let one: [u8;1] = [(97usize+i) as! u8;1]; net.send_all(stream,ref one) or trap; } + net.close_stream(move stream) or trap; +} +fn main(listen: cap,connect: cap) -> u64 effects [net.listen,net.connect,net.read,net.write,task.spawn,task.wait] { + let listener = net.listen(listen,b"127.0.0.1:7333") or trap; + scope s { let task = task.spawn(s,send,connect); let stream = net.accept(listener) or trap; var bytes: [u8;6] = [99u8;6]; + exact(std.io.read_exact_stream(mut stream,mut bytes[1usize..4usize])); assert(bytes[0] == 99u8); assert(bytes[1] == 97u8); assert(bytes[2] == 98u8); assert(bytes[3] == 99u8); assert(bytes[4] == 99u8); assert(bytes[5] == 99u8); + match std.io.read_exact_stream(mut stream,mut bytes[4usize..6usize]) { std.io.ReadExactResult::eof(count) => { assert(count == 1usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } + assert(bytes[4] == 100u8); assert(bytes[5] == 99u8); exact(std.io.read_exact_stream(mut stream,mut bytes[0usize..0usize])); net.close_stream(move stream) or trap; task.join(move task); + } net.close_listener(move listener) or trap; return 42; +} diff --git a/tests/conformance/source/io/to_end.aji b/tests/conformance/source/io/to_end.aji new file mode 100644 index 0000000..1fc5cff --- /dev/null +++ b/tests/conformance/source/io/to_end.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// vfs: /in/data=abcd +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap) -> u64 effects [fs.read] { + let file = fs.open_read(src,b"/in/data") or trap; var bytes: [u8;6] = [99u8;6]; + match std.io.read_to_end_file(mut file,mut bytes[0usize..2usize]) { std.io.ReadToEndResult::full(count) => { assert(count == 2usize); }, std.io.ReadToEndResult::eof(count) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + assert(bytes[0] == 97u8); assert(bytes[1] == 98u8); + match std.io.read_to_end_file(mut file,mut bytes[2usize..6usize]) { std.io.ReadToEndResult::eof(count) => { assert(count == 2usize); }, std.io.ReadToEndResult::full(count) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + assert(bytes[2] == 99u8); assert(bytes[3] == 100u8); assert(bytes[4] == 99u8); assert(bytes[5] == 99u8); + match std.io.read_to_end_file(mut file,mut bytes[0usize..0usize]) { std.io.ReadToEndResult::full(count) => { assert(count == 0usize); }, std.io.ReadToEndResult::eof(count) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + fs.close(move file) or trap; return 42; +} diff --git a/tests/conformance/source/io/wrong_kind.aji b/tests/conformance/source/io/wrong_kind.aji new file mode 100644 index 0000000..b1b0b63 --- /dev/null +++ b/tests/conformance/source/io/wrong_kind.aji @@ -0,0 +1,10 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: cap,destination: slice_mut) -> void effects [io.read] { std.io.read_exact_stdin(input,destination); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/wrong_mode.aji b/tests/conformance/source/io/wrong_mode.aji new file mode 100644 index 0000000..134f45a --- /dev/null +++ b/tests/conformance/source/io/wrong_mode.aji @@ -0,0 +1,10 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn bad(input: mut>,destination: slice_mut) -> void effects [fs.read] { std.io.read_exact_file(input,destination); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/io/zero_scratch.aji b/tests/conformance/source/io/zero_scratch.aji new file mode 100644 index 0000000..9fbd4e2 --- /dev/null +++ b/tests/conformance/source/io/zero_scratch.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/in +// grant: dst=fs.write:/out +// vfs: /in/data=abcd +// file: /out/data= +module test.io +import std.io; +fn exact(result: std.io.ReadExactResult) -> void effects [] { + match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } +} +fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] { + let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap; var bytes: [u8;2] = [99u8;2]; + match std.io.copy_file(mut input,mut output,mut bytes[1usize..1usize],1usize) { std.io.CopyResult::err(error) => { assert(error.read == 0usize); assert(error.confirmed_written == 0usize); match error.error { io_error::not_found => { trap; }, io_error::permission_denied => { trap; }, io_error::already_exists => { trap; }, io_error::invalid_input => { }, io_error::no_space => { trap; }, io_error::broken_pipe => { trap; }, io_error::connection_refused => { trap; }, io_error::connection_reset => { trap; }, io_error::address_in_use => { trap; }, io_error::address_unavailable => { trap; }, io_error::timed_out => { trap; }, io_error::other => { trap; } } }, std.io.CopyResult::limit(count) => { trap; }, std.io.CopyResult::eof(count) => { trap; } } + match std.io.copy_file(mut input,mut output,mut bytes[1usize..1usize],0usize) { std.io.CopyResult::limit(count) => { assert(count == 0usize); }, std.io.CopyResult::eof(count) => { trap; }, std.io.CopyResult::err(error) => { trap; } } + assert(bytes[0] == 99u8); assert(bytes[1] == 99u8); exact(std.io.read_exact_file(mut input,mut bytes)); assert(bytes[0] == 97u8); assert(bytes[1] == 98u8); + fs.close(move input) or trap; fs.close(move output) or trap; return 42; +} diff --git a/tests/conformance/source/linear/array.aji b/tests/conformance/source/linear/array.aji new file mode 100644 index 0000000..9d894f0 --- /dev/null +++ b/tests/conformance/source/linear/array.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let a = own.new(20u64, heap) or trap; + let b = own.new(22u64, heap) or trap; + let data = [move a, move b]; + let (left, right) = array.unpack(move data); + return own.take(move left) + own.take(move right); +} diff --git a/tests/conformance/source/linear/array_duplicate.aji b/tests/conformance/source/linear/array_duplicate.aji new file mode 100644 index 0000000..7e1ec90 --- /dev/null +++ b/tests/conformance/source/linear/array_duplicate.aji @@ -0,0 +1,13 @@ +// expect: reject E2002 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let a = own.new(20u64, heap) or trap; + let b = own.new(22u64, heap) or trap; + own.free(move b); + let data = [move a, move a]; + let (left, right) = array.unpack(move data); + return own.take(move left) + own.take(move right); +} diff --git a/tests/conformance/source/linear/atomic.aji b/tests/conformance/source/linear/atomic.aji new file mode 100644 index 0000000..2ce441d --- /dev/null +++ b/tests/conformance/source/linear/atomic.aji @@ -0,0 +1,11 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Cell { cell: atomic } +fn main() -> u64 effects [] { + let cell = atomic.new(42u64); + let value = Cell { cell: move cell }; + let (part) = struct.unpack(move value); return atomic.take(move part); +} diff --git a/tests/conformance/source/linear/borrow_conflict.aji b/tests/conformance/source/linear/borrow_conflict.aji new file mode 100644 index 0000000..394bbeb --- /dev/null +++ b/tests/conformance/source/linear/borrow_conflict.aji @@ -0,0 +1,14 @@ +// expect: reject E2101 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: move owner, tag: 1u64 }; + ref borrowed = record; + let (part, tag) = struct.unpack(move record); + assert(tag == 1); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/borrowed_atomic_swap.aji b/tests/conformance/source/linear/borrowed_atomic_swap.aji new file mode 100644 index 0000000..5b3de00 --- /dev/null +++ b/tests/conformance/source/linear/borrowed_atomic_swap.aji @@ -0,0 +1,7 @@ +// expect: reject E4202 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +struct Cell { cell: atomic } +fn change(value: mut, replacement: atomic) -> atomic effects [] { return value.swap(mut value.cell, move replacement); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/linear/channel.aji b/tests/conformance/source/linear/channel.aji new file mode 100644 index 0000000..946ffd8 --- /dev/null +++ b/tests/conformance/source/linear/channel.aji @@ -0,0 +1,22 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:128 +// schedules: 8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +struct Item { owner: own } +fn main(heap: cap) -> u64 effects [mem.alloc, task.wait] { + match channel.make(1, heap) { + ok(tx, rx) => { + let owner = own.new(42u64, heap) or trap; + channel.send(tx, Item { owner: move owner }) or trap; + let value = channel.recv(rx) or trap; + channel.close_sender(move tx); + channel.close_receiver(move rx) or trap; + let (part) = struct.unpack(move value); + return own.take(move part); + } + err(error) => { return 42; } + } +} diff --git a/tests/conformance/source/linear/copy_borrowed.aji b/tests/conformance/source/linear/copy_borrowed.aji new file mode 100644 index 0000000..7219046 --- /dev/null +++ b/tests/conformance/source/linear/copy_borrowed.aji @@ -0,0 +1,7 @@ +// expect: reject E1001 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Item { owner: own } +fn peek(value: ref) -> Item effects [] { return *value; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/layer5/reject/linear_field.aji b/tests/conformance/source/linear/declared_owner.aji similarity index 54% rename from tests/conformance/source/layer5/reject/linear_field.aji rename to tests/conformance/source/linear/declared_owner.aji index 3daa9c9..b7cd1e1 100644 --- a/tests/conformance/source/layer5/reject/linear_field.aji +++ b/tests/conformance/source/linear/declared_owner.aji @@ -1,5 +1,6 @@ -// A struct with a linear field needs the unpublished linear_aggregates feature: AIR rejects it. -// expect: reject E0006 +// A declared owner field is accepted under the frontend-declared linear_aggregates feature. +// expect: run +// result: 0 // phase: 6 // spec: docs/spec/15-source-language.md module demo.linearfield diff --git a/tests/conformance/source/linear/enum.aji b/tests/conformance/source/linear/enum.aji new file mode 100644 index 0000000..1d1ccf9 --- /dev/null +++ b/tests/conformance/source/linear/enum.aji @@ -0,0 +1,15 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +enum Maybe { some(T), none } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let value = Maybe::>::some(move owner); + match move value { + Maybe::>::some(part) => { return own.take(move part); } + Maybe::>::none => { return 0; } + } +} diff --git a/tests/conformance/source/linear/enum_ignored_payload.aji b/tests/conformance/source/linear/enum_ignored_payload.aji new file mode 100644 index 0000000..fb85c26 --- /dev/null +++ b/tests/conformance/source/linear/enum_ignored_payload.aji @@ -0,0 +1,16 @@ +// expect: reject E3002 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +enum Maybe { some(T), none } +fn replace(value: mut>>) -> Maybe> effects [] { + return value.swap(mut value, Maybe::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + var value: Maybe> = Maybe::>::some(move owner); + let old = replace(mut value); + match move value { Maybe::>::none => {}, Maybe::>::some(extra) => { own.free(move extra); } } + match move old { Maybe::>::some(_) => { return 42; } Maybe::>::none => { return 0; } } +} diff --git a/tests/conformance/source/linear/file.aji b/tests/conformance/source/linear/file.aji new file mode 100644 index 0000000..9bcef6b --- /dev/null +++ b/tests/conformance/source/linear/file.aji @@ -0,0 +1,23 @@ +// expect: run +// result: 42 +// grant: fs=fs.read:/in +// vfs: /in/data=x +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +struct Input { file: file } +fn main(fs: cap) -> u64 effects [fs.read] { + let file = fs.open_read(fs, b"/in/data") or trap; + let value = Input { file: move file }; + var bytes: [u8; 1] = zero; + { + mut input = value; + mut file = input.file; + let count = fs.read(file, mut bytes) or trap; + assert(count == 1); + assert(bytes[0] == 120); + } + let (file) = struct.unpack(move value); + fs.close(move file) or trap; + return 42; +} diff --git a/tests/conformance/source/linear/fixed_heap_array.aji b/tests/conformance/source/linear/fixed_heap_array.aji new file mode 100644 index 0000000..c76a0e1 --- /dev/null +++ b/tests/conformance/source/linear/fixed_heap_array.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let a = own.new(20u64, heap) or trap; + let b = own.new(22u64, heap) or trap; + let storage = own.pack([move a, move b], heap) or trap; + let data = own.take(move storage); + let (left, right) = array.unpack(move data); + return own.take(move left) + own.take(move right); +} diff --git a/tests/conformance/source/linear/free_linear_content.aji b/tests/conformance/source/linear/free_linear_content.aji new file mode 100644 index 0000000..5608698 --- /dev/null +++ b/tests/conformance/source/linear/free_linear_content.aji @@ -0,0 +1,6 @@ +// expect: reject E1001 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { let owner = own.new(42u64, heap) or trap; let outer = own.pack(move owner, heap) or trap; own.free(move outer); return 42; } diff --git a/tests/conformance/source/linear/graph.aji b/tests/conformance/source/linear/graph.aji new file mode 100644 index 0000000..8bcc65f --- /dev/null +++ b/tests/conformance/source/linear/graph.aji @@ -0,0 +1,27 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +struct Shared { graph: arc } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let graph = arc.new(42u64, heap) or trap; + let value = Shared { graph: move graph }; + { + ref shared = value; + ref graph = shared.graph; + let cloned = arc.clone(graph); + arc.release(move cloned); + } + let (graph) = struct.unpack(move value); + var result: u64 = 0; + { + ref shared = graph; + let root = arc.root(shared); + ref number = arc.at(shared, root); + result = *number; + } + arc.release(move graph); + return result; +} diff --git a/tests/conformance/source/linear/guard_member.aji b/tests/conformance/source/linear/guard_member.aji new file mode 100644 index 0000000..b47c42f --- /dev/null +++ b/tests/conformance/source/linear/guard_member.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Item { guard: guard } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/linear/heap_array_borrow.aji b/tests/conformance/source/linear/heap_array_borrow.aji new file mode 100644 index 0000000..032785e --- /dev/null +++ b/tests/conformance/source/linear/heap_array_borrow.aji @@ -0,0 +1,16 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let a = own.new(20u64, heap) or trap; let b = own.new(22u64, heap) or trap; + let c = own.new(99u64, heap) or trap; + let storage = own.pack([move a, move b], heap) or trap; + let previous = value.swap(mut storage[0], move c); + let data = own.take(move storage); + let (replacement, second) = array.unpack(move data); + own.free(move replacement); + return own.take(move previous) + own.take(move second); +} diff --git a/tests/conformance/source/linear/ignored_field.aji b/tests/conformance/source/linear/ignored_field.aji new file mode 100644 index 0000000..cf377c4 --- /dev/null +++ b/tests/conformance/source/linear/ignored_field.aji @@ -0,0 +1,13 @@ +// expect: reject E3002 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: move owner, tag: 1u64 }; + let (_, tag) = struct.unpack(move record); + assert(tag == 1); + return 42; +} diff --git a/tests/conformance/source/linear/linear_projection.aji b/tests/conformance/source/linear/linear_projection.aji new file mode 100644 index 0000000..3459b42 --- /dev/null +++ b/tests/conformance/source/linear/linear_projection.aji @@ -0,0 +1,14 @@ +// expect: reject E1001 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: move owner, tag: 1u64 }; + let bad = record.value; + let (part, tag) = struct.unpack(move record); + assert(tag == 1); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/linear_region_allocation.aji b/tests/conformance/source/linear/linear_region_allocation.aji new file mode 100644 index 0000000..0a3ff8e --- /dev/null +++ b/tests/conformance/source/linear/linear_region_allocation.aji @@ -0,0 +1,7 @@ +// expect: reject E1001 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Item { owner: own } +fn main(heap: cap) -> u64 effects [mem.alloc] { let owner = own.new(42u64, heap) or trap; let arena = region.create(heap) or trap; ref r = arena; let pointer = region.new(r, Item { owner: move owner }) or trap; return 42; } diff --git a/tests/conformance/source/linear/missing_move.aji b/tests/conformance/source/linear/missing_move.aji new file mode 100644 index 0000000..64e9cd8 --- /dev/null +++ b/tests/conformance/source/linear/missing_move.aji @@ -0,0 +1,13 @@ +// expect: reject E7003 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: owner, tag: 1u64 }; + let (part, tag) = struct.unpack(move record); + assert(tag == 1); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/mutex.aji b/tests/conformance/source/linear/mutex.aji new file mode 100644 index 0000000..7081ee0 --- /dev/null +++ b/tests/conformance/source/linear/mutex.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +struct Item { mutex: mutex } +fn main() -> u64 effects [task.wait] { + let mutex = mutex.make(20u64); + let value = Item { mutex: move mutex }; + { ref r = value; ref m = r.mutex; lock ref m as data { *data = 42; } cancelled { trap; } } + let (mutex) = struct.unpack(move value); + return mutex.take(move mutex); +} diff --git a/tests/conformance/source/linear/none_leak.aji b/tests/conformance/source/linear/none_leak.aji new file mode 100644 index 0000000..63ebeb8 --- /dev/null +++ b/tests/conformance/source/linear/none_leak.aji @@ -0,0 +1,9 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +import std.option; +fn main() -> u64 effects [] { + let value = std.option.Option::>::none; + return 42; +} diff --git a/tests/conformance/source/linear/pack.aji b/tests/conformance/source/linear/pack.aji new file mode 100644 index 0000000..50f53b2 --- /dev/null +++ b/tests/conformance/source/linear/pack.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// equivalent: linear/pack.air +// spec: docs/spec/03-memory-model.md §25 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + match own.pack(move owner, heap) { + ok(outer) => { let inner = own.take(move outer); return own.take(move inner); } + err(error, returned) => { return own.take(move returned); } + } +} diff --git a/tests/conformance/source/linear/pack_failure.aji b/tests/conformance/source/linear/pack_failure.aji new file mode 100644 index 0000000..6cca330 --- /dev/null +++ b/tests/conformance/source/linear/pack_failure.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// phase: 6 +// equivalent: linear/pack_failure.air +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + match own.pack(move owner, heap) { + ok(outer) => { let inner = own.take(move outer); return own.take(move inner); } + err(error, returned) => { return own.take(move returned); } + } +} diff --git a/tests/conformance/source/linear/pack_failure_leak.aji b/tests/conformance/source/linear/pack_failure_leak.aji new file mode 100644 index 0000000..62f2d30 --- /dev/null +++ b/tests/conformance/source/linear/pack_failure_leak.aji @@ -0,0 +1,12 @@ +// expect: reject E3002 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + match own.pack(move owner, heap) { + ok(outer) => { let inner = own.take(move outer); return own.take(move inner); } + err(error, _) => { return 0; } + } +} diff --git a/tests/conformance/source/linear/plain_enum_match.aji b/tests/conformance/source/linear/plain_enum_match.aji new file mode 100644 index 0000000..0924978 --- /dev/null +++ b/tests/conformance/source/linear/plain_enum_match.aji @@ -0,0 +1,16 @@ +// expect: reject E7003 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +enum Maybe { some(T), none } +fn replace(value: mut>>) -> Maybe> effects [] { + return value.swap(mut value, Maybe::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + var value: Maybe> = Maybe::>::some(move owner); + let old = replace(mut value); + match move value { Maybe::>::none => {}, Maybe::>::some(extra) => { own.free(move extra); } } + match old { Maybe::>::some(part) => { return own.take(move part); } Maybe::>::none => { return 0; } } +} diff --git a/tests/conformance/source/linear/recursive_ownership.aji b/tests/conformance/source/linear/recursive_ownership.aji new file mode 100644 index 0000000..dca1aad --- /dev/null +++ b/tests/conformance/source/linear/recursive_ownership.aji @@ -0,0 +1,6 @@ +// expect: reject E1003 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Node { next: own } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/linear/region.aji b/tests/conformance/source/linear/region.aji new file mode 100644 index 0000000..f12a240 --- /dev/null +++ b/tests/conformance/source/linear/region.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Arena { region: region } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let region = region.create(heap) or trap; + let value = Arena { region: move region }; + let (part) = struct.unpack(move value); + region.destroy(move part); return 42; +} diff --git a/tests/conformance/source/linear/repeat.aji b/tests/conformance/source/linear/repeat.aji new file mode 100644 index 0000000..f93796e --- /dev/null +++ b/tests/conformance/source/linear/repeat.aji @@ -0,0 +1,15 @@ +// expect: reject E2002 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: move owner, tag: 1u64 }; + let (part, tag) = struct.unpack(move record); + let (again, _) = struct.unpack(move record); + own.free(move again); + assert(tag == 1); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/repeated_array.aji b/tests/conformance/source/linear/repeated_array.aji new file mode 100644 index 0000000..f77c1a5 --- /dev/null +++ b/tests/conformance/source/linear/repeated_array.aji @@ -0,0 +1,6 @@ +// expect: reject E1001 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { let owner = own.new(42u64, heap) or trap; let data = [move owner; 2]; let (a,b) = array.unpack(move data); own.free(move a); own.free(move b); return 42; } diff --git a/tests/conformance/source/linear/single_tuple.aji b/tests/conformance/source/linear/single_tuple.aji new file mode 100644 index 0000000..2d669d6 --- /dev/null +++ b/tests/conformance/source/linear/single_tuple.aji @@ -0,0 +1,5 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §16 +module test.linear +fn main() -> u64 effects [] { let (value) = 42u64; return value; } diff --git a/tests/conformance/source/linear/std_option.aji b/tests/conformance/source/linear/std_option.aji new file mode 100644 index 0000000..1111deb --- /dev/null +++ b/tests/conformance/source/linear/std_option.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +import std.option; +fn replace(value: mut>>) -> std.option.Option> effects [] { + return value.swap(mut value, std.option.Option::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + var value: std.option.Option> = std.option.Option::>::some(move owner); + let old = replace(mut value); + match move value { std.option.Option::>::none => {}, std.option.Option::>::some(extra) => { own.free(move extra); } } + match move old { std.option.Option::>::some(part) => { return own.take(move part); } std.option.Option::>::none => { return 0; } } +} diff --git a/tests/conformance/source/linear/std_result.aji b/tests/conformance/source/linear/std_result.aji new file mode 100644 index 0000000..51f8d68 --- /dev/null +++ b/tests/conformance/source/linear/std_result.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +import std.result; +fn pass(value: std.result.Result) -> std.result.Result effects [] { return move value; } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let result = pass::>(std.result.Result::, u64>::ok(move owner)); + match move result { std.result.Result::, u64>::ok(part) => { return own.take(move part); } std.result.Result::, u64>::err(error) => { return error; } } +} diff --git a/tests/conformance/source/linear/store_linear.aji b/tests/conformance/source/linear/store_linear.aji new file mode 100644 index 0000000..27f3e13 --- /dev/null +++ b/tests/conformance/source/linear/store_linear.aji @@ -0,0 +1,6 @@ +// expect: reject E1001 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn replace(value: mut>, replacement: own) -> void effects [] { *value = move replacement; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/linear/struct.aji b/tests/conformance/source/linear/struct.aji new file mode 100644 index 0000000..82737e2 --- /dev/null +++ b/tests/conformance/source/linear/struct.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: move owner, tag: 1u64 }; + let (part, tag) = struct.unpack(move record); + assert(tag == 1); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/swap.aji b/tests/conformance/source/linear/swap.aji new file mode 100644 index 0000000..0e6d672 --- /dev/null +++ b/tests/conformance/source/linear/swap.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +enum Maybe { some(T), none } +fn replace(value: mut>>) -> Maybe> effects [] { + return value.swap(mut value, Maybe::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + var value: Maybe> = Maybe::>::some(move owner); + let old = replace(mut value); + match move value { Maybe::>::none => {}, Maybe::>::some(extra) => { own.free(move extra); } } + match move old { Maybe::>::some(part) => { return own.take(move part); } Maybe::>::none => { return 0; } } +} diff --git a/tests/conformance/source/linear/swap_array.aji b/tests/conformance/source/linear/swap_array.aji new file mode 100644 index 0000000..f27c0c6 --- /dev/null +++ b/tests/conformance/source/linear/swap_array.aji @@ -0,0 +1,15 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +fn main(heap: cap) -> u64 effects [mem.alloc] { + let a = own.new(20u64, heap) or trap; let b = own.new(22u64, heap) or trap; + let c = own.new(99u64, heap) or trap; + var data: [own; 2] = [move a, move b]; + let previous = value.swap(mut data[0], move c); + let (replacement, second) = array.unpack(move data); + own.free(move replacement); + return own.take(move previous) + own.take(move second); +} diff --git a/tests/conformance/source/linear/swap_heap.aji b/tests/conformance/source/linear/swap_heap.aji new file mode 100644 index 0000000..40f89d2 --- /dev/null +++ b/tests/conformance/source/linear/swap_heap.aji @@ -0,0 +1,18 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +enum Maybe { some(T), none } +fn replace(value: mut>>) -> Maybe> effects [] { + return value.swap(mut value, Maybe::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let storage = own.pack(Maybe::>::some(move owner), heap) or trap; + let old = replace(mut storage); + let value = own.take(move storage); + match move value { Maybe::>::none => {}, Maybe::>::some(extra) => { own.free(move extra); } } + match move old { Maybe::>::some(part) => { return own.take(move part); } Maybe::>::none => { return 0; } } +} diff --git a/tests/conformance/source/linear/swap_loop.aji b/tests/conformance/source/linear/swap_loop.aji new file mode 100644 index 0000000..23b9c79 --- /dev/null +++ b/tests/conformance/source/linear/swap_loop.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:8 +// fuel: 1000000 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module test.linear +import std.option; +fn main(heap: cap) -> u64 effects [mem.alloc] { + var slot: std.option.Option> = std.option.Option::>::none; + for i in 0usize..1000usize { + let owner = own.new(42u64, heap) or trap; + let old = value.swap(mut slot, std.option.Option::>::some(move owner)); + match move old { std.option.Option::>::some(part) => { own.free(move part); } std.option.Option::>::none => {} } + let current = value.swap(mut slot, std.option.Option::>::none); + match move current { std.option.Option::>::some(part) => { own.free(move part); } std.option.Option::>::none => {} } + } + match move slot { std.option.Option::>::some(part) => { return own.take(move part); } std.option.Option::>::none => { return 42; } } +} diff --git a/tests/conformance/source/linear/swap_twice.aji b/tests/conformance/source/linear/swap_twice.aji new file mode 100644 index 0000000..62b403d --- /dev/null +++ b/tests/conformance/source/linear/swap_twice.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +enum Maybe { some(T), none } +fn replace(value: mut>>) -> Maybe> effects [] { + return value.swap(mut value, Maybe::>::none); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + var value: Maybe> = Maybe::>::some(move owner); + let old = replace(mut value); + let empty = replace(mut value); + match move empty { Maybe::>::none => {}, Maybe::>::some(unexpected) => { own.free(move unexpected); } } + match move value { Maybe::>::none => {}, Maybe::>::some(extra) => { own.free(move extra); } } + match move old { Maybe::>::some(part) => { return own.take(move part); } Maybe::>::none => { return 0; } } +} diff --git a/tests/conformance/source/linear/task.aji b/tests/conformance/source/linear/task.aji new file mode 100644 index 0000000..ebb4ba1 --- /dev/null +++ b/tests/conformance/source/linear/task.aji @@ -0,0 +1,16 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// schedules: 8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Payload { owner: own } +fn worker(value: Payload) -> u64 effects [] { let (part) = struct.unpack(move value); return own.take(move part); } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let owner = own.new(42u64, heap) or trap; + let value = Payload { owner: move owner }; + var result: u64 = 0; + scope s { let task = task.spawn(s, worker, move value); result = task.join(move task); } + return result; +} diff --git a/tests/conformance/source/linear/task_loan.aji b/tests/conformance/source/linear/task_loan.aji new file mode 100644 index 0000000..719159c --- /dev/null +++ b/tests/conformance/source/linear/task_loan.aji @@ -0,0 +1,24 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/04-concurrency-and-atomics.md §34 +module test.linear +struct Payload { owner: own } +fn worker(value: mut) -> void effects [] {} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let owner = own.new(42u64, heap) or trap; + var value: Payload = Payload { owner: move owner }; + let replacement_owner = own.new(42u64, heap) or trap; + let replacement = Payload { owner: move replacement_owner }; + { + mut borrowed = value; + scope s { + let task = task.spawn(s, worker, borrowed); + let old = value.swap(mut borrowed, move replacement); + let (part) = struct.unpack(move old); + own.free(move part); + task.join(move task); + } + } + let (part) = struct.unpack(move value); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/task_loan_join.aji b/tests/conformance/source/linear/task_loan_join.aji new file mode 100644 index 0000000..5880f55 --- /dev/null +++ b/tests/conformance/source/linear/task_loan_join.aji @@ -0,0 +1,27 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// schedules: 8 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/04-concurrency-and-atomics.md §34 +module test.linear +struct Payload { owner: own } +fn worker(value: mut) -> void effects [] {} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let owner = own.new(42u64, heap) or trap; + var value: Payload = Payload { owner: move owner }; + let replacement_owner = own.new(42u64, heap) or trap; + let replacement = Payload { owner: move replacement_owner }; + { + mut borrowed = value; + scope s { + let task = task.spawn(s, worker, borrowed); + task.join(move task); + let old = value.swap(mut borrowed, move replacement); + let (part) = struct.unpack(move old); + own.free(move part); + } + } + let (part) = struct.unpack(move value); + return own.take(move part); +} diff --git a/tests/conformance/source/linear/task_member.aji b/tests/conformance/source/linear/task_member.aji new file mode 100644 index 0000000..65a0c5d --- /dev/null +++ b/tests/conformance/source/linear/task_member.aji @@ -0,0 +1,6 @@ +// expect: reject E0006 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Item { task: task } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/linear/wrong_unpack_count.aji b/tests/conformance/source/linear/wrong_unpack_count.aji new file mode 100644 index 0000000..813c79c --- /dev/null +++ b/tests/conformance/source/linear/wrong_unpack_count.aji @@ -0,0 +1,13 @@ +// expect: reject E7005 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25; docs/spec/15-source-language.md §16 +module test.linear +struct Pair { value: own, tag: u64 } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let record = Pair { value: move owner, tag: 1u64 }; + let (part) = struct.unpack(move record); + assert(tag == 1); + return own.take(move part); +} diff --git a/tests/conformance/source/map/alias.aji b/tests/conformance/source/map/alias.aji new file mode 100644 index 0000000..ef1c145 --- /dev/null +++ b/tests/conformance/source/map/alias.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>) -> void effects [] { ref observed = q; inserted::(std.map.insert::(q, 0, 42)); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/allocation.aji b/tests/conformance/source/map/allocation.aji new file mode 100644 index 0000000..a91df5d --- /dev/null +++ b/tests/conformance/source/map/allocation.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + match std.map.new::>(1, heap) { + std.map.NewResult::>::ok(map) => { trap; } + std.map.NewResult::>::err(error) => { + match error { alloc_error::budget_exceeded => {}, alloc_error::out_of_memory => { trap; } } + } + } + match std.map.new::((0usize -% 1usize) / 2usize + 1usize, heap) { + std.map.NewResult::::ok(map) => { trap; } + std.map.NewResult::::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); +} diff --git a/tests/conformance/source/map/collision.aji b/tests/conformance/source/map/collision.aji new file mode 100644 index 0000000..83e434a --- /dev/null +++ b/tests/conformance/source/map/collision.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(4, heap); + { mut q = map; + inserted::(std.map.insert::(q, 0, 1)); + inserted::(std.map.insert::(q, 8, 2)); + inserted::(std.map.insert::(q, 16, 3)); + inserted::(std.map.insert::(q, 24, 4)); + assert(extracted::(std.map.remove::(q, 8)) == 2u64); + match std.map.insert::(q, 16, 42) { + std.map.InsertResult::::replaced(previous) => { assert(previous == 3u64); } + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 3usize); + inserted::(std.map.insert::(q, 32, 5)); + assert(extracted::(std.map.get::(ref q, 24)) == 4u64); + assert(extracted::(std.map.get::(ref q, 16)) == 42u64); + assert(extracted::(std.map.get::(ref q, 32)) == 5u64); + assert(not std.map.contains::(ref q, 8)); + match std.map.reserve::(q, 7, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + for key in 0u64..5u64 { + if key != 1u64 { let removed = extracted::(std.map.remove::(q, key * 8u64)); } + } + assert(std.map.len::(ref q) == 0usize); + } + released::(move map); + return 42; +} + diff --git a/tests/conformance/source/map/copy.aji b/tests/conformance/source/map/copy.aji new file mode 100644 index 0000000..80da322 --- /dev/null +++ b/tests/conformance/source/map/copy.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { ref q = map; assert(std.map.len::(ref q) == 0); assert(std.map.capacity::(ref q) == 2); } + { mut q = map; + inserted::(std.map.insert::(q, 0, 7u64)); + inserted::(std.map.insert::(q, 0xffffffffffffffffu64, 42u64)); + match std.map.insert::(q, 0, 9u64) { + std.map.InsertResult::::replaced(old) => { assert(old == 7u64); } + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } + match std.map.insert::(q, 3, 99u64) { + std.map.InsertResult::::full(value) => { assert(value == 99u64); } + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(old) => { trap; } + } + } + { ref q = map; + assert(std.map.contains::(ref q, 0)); assert(not std.map.contains::(ref q, 3)); + assert(extracted::(std.map.get::(ref q, 0)) == 9u64); + assert(extracted::(std.map.get::(ref q, 0xffffffffffffffffu64)) == 42u64); + } + { mut q = map; + match std.map.remove::(q, 3) { std.option.Option::::none => {}, std.option.Option::::some(value) => { trap; } } + assert(extracted::(std.map.remove::(q, 0)) == 9u64); + match std.map.reserve::(q, 4, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + let entry = extracted::>(std.map.pop::(q)); + assert(entry.key == 0xffffffffffffffffu64 and entry.value == 42u64); + match std.map.pop::(q) { std.option.Option::>::none => {}, std.option.Option::>::some(value) => { trap; } } + } + released::(move map); + return 42; +} diff --git a/tests/conformance/source/map/double_move.aji b/tests/conformance/source/map/double_move.aji new file mode 100644 index 0000000..cd83fb5 --- /dev/null +++ b/tests/conformance/source/map/double_move.aji @@ -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) -> void effects [] { + let first = std.map.free::(move map); + let second = std.map.free::(move map); + trap; +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/file.aji b/tests/conformance/source/map/file.aji new file mode 100644 index 0000000..48e8e3b --- /dev/null +++ b/tests/conformance/source/map/file.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap, dst: cap) -> u64 effects [mem.alloc, fs.write] { + let map = opened::>(1, heap); + let file = fs.create(dst, b"/out/map.txt") or trap; + { mut q = map; inserted::>(std.map.insert::>(q, 7, move file)); + let item = extracted::>(std.map.remove::>(q, 7)); + fs.write_all(item, ref b"42") or trap; fs.close(move item) or trap; + } + released::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/free_leak.aji b/tests/conformance/source/map/free_leak.aji new file mode 100644 index 0000000..177d6a8 --- /dev/null +++ b/tests/conformance/source/map/free_leak.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(map: std.map.U64Map>) -> void effects [] { match std.map.free::>(move map) { std.map.FreeResult::>::ok => { return; }, std.map.FreeResult::>::not_empty(returned) => { return; } } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/full_leak.aji b/tests/conformance/source/map/full_leak.aji new file mode 100644 index 0000000..a7432af --- /dev/null +++ b/tests/conformance/source/map/full_leak.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>>, item: own) -> void effects [] { match std.map.insert::>(q, 0, move item) { std.map.InsertResult::>::inserted => { return; }, std.map.InsertResult::>::replaced(old) => { own.free(move old); return; }, std.map.InsertResult::>::full(returned) => { return; } } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/get_owner.aji b/tests/conformance/source/map/get_owner.aji new file mode 100644 index 0000000..67d9968 --- /dev/null +++ b/tests/conformance/source/map/get_owner.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: ref>>) -> void effects [] { let item = std.map.get::>(ref q, 0); trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/grow_missing_effect.aji b/tests/conformance/source/map/grow_missing_effect.aji new file mode 100644 index 0000000..cf2ccf2 --- /dev/null +++ b/tests/conformance/source/map/grow_missing_effect.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>, heap: cap) -> void effects [] { match std.map.reserve::(q, 8, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => {} } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/invalid_empty.aji b/tests/conformance/source/map/invalid_empty.aji new file mode 100644 index 0000000..f41a5e8 --- /dev/null +++ b/tests/conformance/source/map/invalid_empty.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::>(1, heap); let owner = own.new(42u64, heap) or trap; + { mut q = map; inserted::>(std.map.insert::>(q, 0, move owner)); q.length = 0; } + released::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/invalid_vacant_owner.aji b/tests/conformance/source/map/invalid_vacant_owner.aji new file mode 100644 index 0000000..9ac91f2 --- /dev/null +++ b/tests/conformance/source/map/invalid_vacant_owner.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::>(1, heap); let owner = own.new(42u64, heap) or trap; + { mut q = map; inserted::>(std.map.insert::>(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::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/loan.aji b/tests/conformance/source/map/loan.aji new file mode 100644 index 0000000..031efc2 --- /dev/null +++ b/tests/conformance/source/map/loan.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn worker(q: mut>) -> void effects [] {} +fn bad(q: mut>) -> void effects [task.spawn, task.wait] { scope s { let t = task.spawn(s, worker, q); inserted::(std.map.insert::(q, 0, 42)); task.join(move t); } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/loan_join.aji b/tests/conformance/source/map/loan_join.aji new file mode 100644 index 0000000..bdc3f1d --- /dev/null +++ b/tests/conformance/source/map/loan_join.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn worker(q: mut>>) -> void effects [] { let item = extracted::>(std.map.remove::>(q, 7)); assert(own.take(move item) == 42u64); } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let map = opened::>(1, heap); let owner = own.new(42u64, heap) or trap; + { mut q = map; inserted::>(std.map.insert::>(q, 7, move owner)); + scope s { let t = task.spawn(s, worker, q); task.join(move t); } + assert(std.map.len::>(ref q) == 0usize); + } + released::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/missing_move.aji b/tests/conformance/source/map/missing_move.aji new file mode 100644 index 0000000..4a5abfb --- /dev/null +++ b/tests/conformance/source/map/missing_move.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>>, item: own) -> void effects [] { inserted::>(std.map.insert::>(q, 0, item)); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/model.aji b/tests/conformance/source/map/model.aji new file mode 100644 index 0000000..f212df4 --- /dev/null +++ b/tests/conformance/source/map/model.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { mut q = map; + assert(std.map.contains::(ref q, 16) == false); + assert(std.map.len::(ref q) == 0usize); + match std.map.insert::(q, 16, 607) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 1usize); + match std.map.insert::(q, 1, 165) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.get::(ref q, 1) { std.option.Option::::some(returned) => { assert(returned == 165u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 2usize); + match std.map.remove::(q, 1) { std.option.Option::::some(returned) => { assert(returned == 165u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 1usize); + assert(std.map.contains::(ref q, 24) == false); + assert(std.map.len::(ref q) == 1usize); + match std.map.insert::(q, 1, 63) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.get::(ref q, 18446744073709551615) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 2usize); + match std.map.insert::(q, 1, 584) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 63u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.insert::(q, 24, 218) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 218u64); } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.get::(ref q, 1) { std.option.Option::::some(returned) => { assert(returned == 584u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 2usize); + match std.map.insert::(q, 32, 836) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 836u64); } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.insert::(q, 32, 996) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 996u64); } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.insert::(q, 32, 511) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 511u64); } + } + assert(std.map.len::(ref q) == 2usize); + assert(std.map.contains::(ref q, 24) == false); + assert(std.map.len::(ref q) == 2usize); + match std.map.insert::(q, 32, 733) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 733u64); } + } + assert(std.map.len::(ref q) == 2usize); + match std.map.remove::(q, 32) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 2usize); + match std.map.remove::(q, 32) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 2usize); + match std.map.reserve::(q, 4, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + match std.map.insert::(q, 8, 173) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 3usize); + assert(std.map.contains::(ref q, 18446744073709551615) == false); + assert(std.map.len::(ref q) == 3usize); + assert(std.map.contains::(ref q, 18446744073709551615) == false); + assert(std.map.len::(ref q) == 3usize); + assert(std.map.contains::(ref q, 0) == false); + assert(std.map.len::(ref q) == 3usize); + match std.map.get::(ref q, 18446744073709551615) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 3usize); + match std.map.insert::(q, 8, 495) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 173u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 3usize); + match std.map.get::(ref q, 8) { std.option.Option::::some(returned) => { assert(returned == 495u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 3usize); + assert(std.map.contains::(ref q, 16) == true); + assert(std.map.len::(ref q) == 3usize); + match std.map.insert::(q, 32, 693) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 18446744073709551615, 999) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 999u64); } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 8, 391) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 495u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.remove::(q, 32) { std.option.Option::::some(returned) => { assert(returned == 693u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 3usize); + match std.map.insert::(q, 32, 238) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 18446744073709551615, 172) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { assert(returned == 172u64); } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 16, 415) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 607u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.remove::(q, 8) { std.option.Option::::some(returned) => { assert(returned == 391u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 3usize); + match std.map.insert::(q, 32, 595) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 238u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 3usize); + match std.map.insert::(q, 18446744073709551615, 27) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.reserve::(q, 6, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + assert(std.map.contains::(ref q, 0) == false); + assert(std.map.len::(ref q) == 4usize); + match std.map.remove::(q, 18446744073709551615) { std.option.Option::::some(returned) => { assert(returned == 27u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 3usize); + match std.map.insert::(q, 8, 258) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.remove::(q, 18446744073709551615) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 32, 446) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 595u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 1, 311) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 584u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + assert(std.map.contains::(ref q, 24) == false); + assert(std.map.len::(ref q) == 4usize); + match std.map.get::(ref q, 24) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 24, 764) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.get::(ref q, 16) { std.option.Option::::some(returned) => { assert(returned == 415u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + match std.map.remove::(q, 0) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 5usize); + assert(std.map.contains::(ref q, 0) == false); + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 0, 274) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 6usize); + match std.map.remove::(q, 8) { std.option.Option::::some(returned) => { assert(returned == 258u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 0, 58) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 274u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.get::(ref q, 16) { std.option.Option::::some(returned) => { assert(returned == 415u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 8, 394) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 6usize); + match std.map.get::(ref q, 8) { std.option.Option::::some(returned) => { assert(returned == 394u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 6usize); + match std.map.remove::(q, 0) { std.option.Option::::some(returned) => { assert(returned == 58u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + match std.map.get::(ref q, 0) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 0, 476) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 6usize); + match std.map.remove::(q, 8) { std.option.Option::::some(returned) => { assert(returned == 394u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + match std.map.remove::(q, 1) { std.option.Option::::some(returned) => { assert(returned == 311u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 1, 893) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 0, 529) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 476u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 0, 385) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 529u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.get::(ref q, 8) { std.option.Option::::some(returned) => { trap; }, std.option.Option::::none => {} } + assert(std.map.len::(ref q) == 5usize); + match std.map.insert::(q, 0, 777) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 385u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + assert(std.map.contains::(ref q, 32) == true); + assert(std.map.len::(ref q) == 5usize); + match std.map.remove::(q, 1) { std.option.Option::::some(returned) => { assert(returned == 893u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 18446744073709551615, 423) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.remove::(q, 18446744073709551615) { std.option.Option::::some(returned) => { assert(returned == 423u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 16, 269) { + std.map.InsertResult::::inserted => { trap; } + std.map.InsertResult::::replaced(returned) => { assert(returned == 415u64); } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 4usize); + match std.map.insert::(q, 8, 172) { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(returned) => { trap; } + std.map.InsertResult::::full(returned) => { trap; } + } + assert(std.map.len::(ref q) == 5usize); + match std.map.get::(ref q, 0) { std.option.Option::::some(returned) => { assert(returned == 777u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + match std.map.get::(ref q, 24) { std.option.Option::::some(returned) => { assert(returned == 764u64); }, std.option.Option::::none => { trap; } } + assert(std.map.len::(ref q) == 5usize); + var seen: [bool; 5] = zero; + { let entry = extracted::>(std.map.pop::(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.pop::(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.pop::(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.pop::(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.pop::(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::(ref q) == 0usize); + match std.map.pop::(q) { std.option.Option::>::none => {}, std.option.Option::>::some(unexpected) => { trap; } } + } + released::(move map); + return 42; +} + diff --git a/tests/conformance/source/map/model_owner.aji b/tests/conformance/source/map/model_owner.aji new file mode 100644 index 0000000..3239452 --- /dev/null +++ b/tests/conformance/source/map/model_owner.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::>(2, heap); + { mut q = map; + match std.map.remove::>(q, 16) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 0usize); + let input1 = own.new(972u64, heap) or trap; + match std.map.insert::>(q, 1, move input1) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 1usize); + match std.map.remove::>(q, 0) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 1usize); + match std.map.remove::>(q, 0) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 1usize); + match std.map.remove::>(q, 8) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 1usize); + assert(std.map.contains::>(ref q, 18446744073709551615) == false); + assert(std.map.len::>(ref q) == 1usize); + let input6 = own.new(149u64, heap) or trap; + match std.map.insert::>(q, 8, move input6) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 2usize); + match std.map.remove::>(q, 24) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 2usize); + let input8 = own.new(969u64, heap) or trap; + match std.map.insert::>(q, 0, move input8) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 969u64); } + } + assert(std.map.len::>(ref q) == 2usize); + let input9 = own.new(139u64, heap) or trap; + match std.map.insert::>(q, 32, move input9) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 139u64); } + } + assert(std.map.len::>(ref q) == 2usize); + assert(std.map.contains::>(ref q, 18446744073709551615) == false); + assert(std.map.len::>(ref q) == 2usize); + let input11 = own.new(639u64, heap) or trap; + match std.map.insert::>(q, 32, move input11) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 639u64); } + } + assert(std.map.len::>(ref q) == 2usize); + let input12 = own.new(431u64, heap) or trap; + match std.map.insert::>(q, 24, move input12) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 431u64); } + } + assert(std.map.len::>(ref q) == 2usize); + assert(std.map.contains::>(ref q, 8) == true); + assert(std.map.len::>(ref q) == 2usize); + let input14 = own.new(61u64, heap) or trap; + match std.map.insert::>(q, 24, move input14) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 61u64); } + } + assert(std.map.len::>(ref q) == 2usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 2usize); + let input16 = own.new(202u64, heap) or trap; + match std.map.insert::>(q, 24, move input16) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 202u64); } + } + assert(std.map.len::>(ref q) == 2usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 2usize); + match std.map.reserve::>(q, 4, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + match std.map.remove::>(q, 24) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 2usize); + assert(std.map.contains::>(ref q, 16) == false); + assert(std.map.len::>(ref q) == 2usize); + match std.map.remove::>(q, 0) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 2usize); + assert(std.map.contains::>(ref q, 8) == true); + assert(std.map.len::>(ref q) == 2usize); + match std.map.remove::>(q, 16) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 2usize); + let input23 = own.new(44u64, heap) or trap; + match std.map.insert::>(q, 1, move input23) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { assert(own.take(move returned) == 972u64); } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 2usize); + assert(std.map.contains::>(ref q, 24) == false); + assert(std.map.len::>(ref q) == 2usize); + let input25 = own.new(235u64, heap) or trap; + match std.map.insert::>(q, 16, move input25) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 3usize); + let input26 = own.new(287u64, heap) or trap; + match std.map.insert::>(q, 32, move input26) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 4usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 287u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 3usize); + assert(std.map.contains::>(ref q, 18446744073709551615) == false); + assert(std.map.len::>(ref q) == 3usize); + let input29 = own.new(678u64, heap) or trap; + match std.map.insert::>(q, 18446744073709551615, move input29) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 4usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 4usize); + match std.map.remove::>(q, 8) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 149u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 3usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 3usize); + assert(std.map.contains::>(ref q, 24) == false); + assert(std.map.len::>(ref q) == 3usize); + let input34 = own.new(275u64, heap) or trap; + match std.map.insert::>(q, 24, move input34) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 4usize); + assert(std.map.contains::>(ref q, 8) == false); + assert(std.map.len::>(ref q) == 4usize); + match std.map.reserve::>(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::>(q, 32, move input36) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 5usize); + let input37 = own.new(207u64, heap) or trap; + match std.map.insert::>(q, 24, move input37) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { assert(own.take(move returned) == 275u64); } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 5usize); + assert(std.map.contains::>(ref q, 18446744073709551615) == true); + assert(std.map.len::>(ref q) == 5usize); + let input39 = own.new(351u64, heap) or trap; + match std.map.insert::>(q, 24, move input39) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { assert(own.take(move returned) == 207u64); } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 5usize); + assert(std.map.contains::>(ref q, 8) == false); + assert(std.map.len::>(ref q) == 5usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 369u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 4usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 4usize); + assert(std.map.contains::>(ref q, 32) == false); + assert(std.map.len::>(ref q) == 4usize); + assert(std.map.contains::>(ref q, 18446744073709551615) == true); + assert(std.map.len::>(ref q) == 4usize); + let input45 = own.new(557u64, heap) or trap; + match std.map.insert::>(q, 8, move input45) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 5usize); + match std.map.remove::>(q, 24) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 351u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 4usize); + let input47 = own.new(171u64, heap) or trap; + match std.map.insert::>(q, 18446744073709551615, move input47) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { assert(own.take(move returned) == 678u64); } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 4usize); + match std.map.remove::>(q, 8) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 557u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 3usize); + match std.map.remove::>(q, 0) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 3usize); + match std.map.remove::>(q, 24) { std.option.Option::>::some(returned) => { trap; }, std.option.Option::>::none => {} } + assert(std.map.len::>(ref q) == 3usize); + let input51 = own.new(533u64, heap) or trap; + match std.map.insert::>(q, 18446744073709551615, move input51) { + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(returned) => { assert(own.take(move returned) == 171u64); } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 3usize); + match std.map.remove::>(q, 18446744073709551615) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 533u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 2usize); + let input53 = own.new(91u64, heap) or trap; + match std.map.insert::>(q, 32, move input53) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 3usize); + match std.map.remove::>(q, 32) { std.option.Option::>::some(returned) => { assert(own.take(move returned) == 91u64); }, std.option.Option::>::none => { trap; } } + assert(std.map.len::>(ref q) == 2usize); + let input55 = own.new(610u64, heap) or trap; + match std.map.insert::>(q, 32, move input55) { + std.map.InsertResult::>::inserted => {} + std.map.InsertResult::>::replaced(returned) => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + assert(std.map.len::>(ref q) == 3usize); + var seen: [bool; 3] = zero; + { let entry = extracted::>>(std.map.pop::>(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.pop::>(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.pop::>(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::>(ref q) == 0usize); + match std.map.pop::>(q) { std.option.Option::>>::none => {}, std.option.Option::>>::some(unexpected) => { trap; } } + } + released::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/not_share.aji b/tests/conformance/source/map/not_share.aji new file mode 100644 index 0000000..66cad8c --- /dev/null +++ b/tests/conformance/source/map/not_share.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn worker(q: ref>>) -> void effects [] {} +fn bad(q: ref>>) -> 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; } diff --git a/tests/conformance/source/map/owner.aji b/tests/conformance/source/map/owner.aji new file mode 100644 index 0000000..2e8dd3d --- /dev/null +++ b/tests/conformance/source/map/owner.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::>(1, heap); + let first = own.new(7u64, heap) or trap; + { mut q = map; inserted::>(std.map.insert::>(q, 7, move first)); } + { ref q = map; assert(std.map.contains::>(ref q, 7)); } + let second = own.new(42u64, heap) or trap; + { mut q = map; + match std.map.insert::>(q, 7, move second) { + std.map.InsertResult::>::replaced(old) => { assert(own.take(move old) == 7u64); } + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::full(returned) => { trap; } + } + let third = own.new(99u64, heap) or trap; + match std.map.insert::>(q, 8, move third) { + std.map.InsertResult::>::full(returned) => { assert(own.take(move returned) == 99u64); } + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(old) => { trap; } + } + } + match std.map.free::>(move map) { + std.map.FreeResult::>::not_empty(returned) => { + { mut q = returned; + match std.map.reserve::>(q, 3, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + let entry = extracted::>>(std.map.pop::>(q)); + let (key, owner) = struct.unpack(move entry); assert(key == 7u64); assert(own.take(move owner) == 42u64); + } + released::>(move returned); + } + std.map.FreeResult::>::ok => { trap; } + } + return 42; +} diff --git a/tests/conformance/source/map/pop_leak.aji b/tests/conformance/source/map/pop_leak.aji new file mode 100644 index 0000000..e1fc2af --- /dev/null +++ b/tests/conformance/source/map/pop_leak.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>>) -> void effects [] { let item = std.map.pop::>(q); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/replace_leak.aji b/tests/conformance/source/map/replace_leak.aji new file mode 100644 index 0000000..6b88d97 --- /dev/null +++ b/tests/conformance/source/map/replace_leak.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>>, item: own) -> void effects [] { match std.map.insert::>(q, 0, move item) { std.map.InsertResult::>::inserted => {}, std.map.InsertResult::>::replaced(old) => {}, std.map.InsertResult::>::full(returned) => { own.free(move returned); } } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/reserve_authority.aji b/tests/conformance/source/map/reserve_authority.aji new file mode 100644 index 0000000..bb13df3 --- /dev/null +++ b/tests/conformance/source/map/reserve_authority.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(first: cap, second: cap, items: cap) -> u64 effects [mem.alloc] { + let map = opened::>(2, first); + let a = own.new(42u64, items) or trap; + { mut q = map; inserted::>(std.map.insert::>(q, 9, move a)); + match std.map.reserve::>(q, 3, second) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + } + let reused = opened::>(2, first); released::>(move reused); + { mut q = map; let owner = extracted::>(std.map.remove::>(q, 9)); assert(own.take(move owner) == 42u64); } + released::>(move map); + let next = opened::>(3, second); released::>(move next); + return 42; +} + diff --git a/tests/conformance/source/map/reserve_failure.aji b/tests/conformance/source/map/reserve_failure.aji new file mode 100644 index 0000000..fe5af83 --- /dev/null +++ b/tests/conformance/source/map/reserve_failure.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::>(2, heap); + let a = own.new(7u64, heap) or trap; let b = own.new(42u64, heap) or trap; + { mut q = map; + inserted::>(std.map.insert::>(q, 0, move a)); + inserted::>(std.map.insert::>(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::>(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::>(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::>(ref q) == 2usize); assert(std.map.capacity::>(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.pop::>(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::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/reserve_peak.aji b/tests/conformance/source/map/reserve_peak.aji new file mode 100644 index 0000000..12eee28 --- /dev/null +++ b/tests/conformance/source/map/reserve_peak.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let first = cap.narrow.budget(heap, 88usize) or trap; + let map = opened::>(2, first); + let a = own.new(7u64, first) or trap; let b = own.new(42u64, first) or trap; + { mut q = map; + inserted::>(std.map.insert::>(q, 0, move a)); + inserted::>(std.map.insert::>(q, 8, move b)); + match std.map.reserve::>(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::>(std.map.remove::>(q, 0)); assert(own.take(move first_owner) == 7u64); + let second_owner = extracted::>(std.map.remove::>(q, 8)); assert(own.take(move second_owner) == 42u64); + } + released::>(move map); + return 42; +} + diff --git a/tests/conformance/source/map/sender.aji b/tests/conformance/source/map/sender.aji new file mode 100644 index 0000000..9ce50d6 --- /dev/null +++ b/tests/conformance/source/map/sender.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +struct Job { number: u64 } +fn worker(map: std.map.U64Map>) -> void effects [task.wait] { + { mut q = map; let entry = extracted::>>(std.map.pop::>(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::>(move map); +} +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + match channel.make(1, heap) { ok(tx, rx) => { + let map = opened::>(1, heap); + { mut q = map; inserted::>(std.map.insert::>(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; +} + diff --git a/tests/conformance/source/map/shared.aji b/tests/conformance/source/map/shared.aji new file mode 100644 index 0000000..064d975 --- /dev/null +++ b/tests/conformance/source/map/shared.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn worker(q: ref>) -> u64 effects [] { return extracted::(std.map.get::(ref q, 7)); } +fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { + let map = opened::(1, heap); + { mut q = map; inserted::(std.map.insert::(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::(std.map.remove::(q, 7)) == 42u64); } + released::(move map); + return 42; +} + diff --git a/tests/conformance/source/map/slot_view.aji b/tests/conformance/source/map/slot_view.aji new file mode 100644 index 0000000..79ab543 --- /dev/null +++ b/tests/conformance/source/map/slot_view.aji @@ -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>) -> void effects [] { + ref storage = map.storage; + ref slots = buffer.view(storage); + let result = std.map.remove::(map, 7); +} +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/tombstones.aji b/tests/conformance/source/map/tombstones.aji new file mode 100644 index 0000000..6434ba8 --- /dev/null +++ b/tests/conformance/source/map/tombstones.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::(2, heap); + { mut q = map; + for key in 0u64..4u64 { + inserted::(std.map.insert::(q, key, 42)); + assert(extracted::(std.map.remove::(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::(ref q, 99)); + match std.map.remove::(q, 99) { std.option.Option::::none => {}, std.option.Option::::some(unexpected) => { trap; } } + inserted::(std.map.insert::(q, 42, 42)); + assert(extracted::(std.map.remove::(q, 42)) == 42u64); + } + released::(move map); + return 42; +} + diff --git a/tests/conformance/source/map/wrong_key.aji b/tests/conformance/source/map/wrong_key.aji new file mode 100644 index 0000000..93f1443 --- /dev/null +++ b/tests/conformance/source/map/wrong_key.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn bad(q: mut>) -> void effects [] { inserted::(std.map.insert::(q, 0u32, 42)); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/map/zero.aji b/tests/conformance/source/map/zero.aji new file mode 100644 index 0000000..9fdece0 --- /dev/null +++ b/tests/conformance/source/map/zero.aji @@ -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(capacity: usize, heap: cap) -> std.map.U64Map effects [mem.alloc] { + match std.map.new::(capacity, heap) { + std.map.NewResult::::ok(map) => { return move map; } + std.map.NewResult::::err(error) => { trap; } + } +} +fn inserted(result: std.map.InsertResult) -> void effects [] { + match move result { + std.map.InsertResult::::inserted => {} + std.map.InsertResult::::replaced(old) => { trap; } + std.map.InsertResult::::full(value) => { trap; } + } +} +fn released(map: std.map.U64Map) -> void effects [] { + match std.map.free::(move map) { + std.map.FreeResult::::ok => {} + std.map.FreeResult::::not_empty(returned) => { trap; } + } +} +fn extracted(value: std.option.Option) -> V effects [] { + match move value { + std.option.Option::::some(item) => { return move item; } + std.option.Option::::none => { trap; } + } +} +fn main(heap: cap) -> u64 effects [mem.alloc] { + let map = opened::>(0, heap); + { mut q = map; + match std.map.reserve::>(q, 0, heap) { std.map.ReserveResult::ok => {}, std.map.ReserveResult::err(error) => { trap; } } + match std.map.pop::>(q) { std.option.Option::>>::none => {}, std.option.Option::>>::some(entry) => { trap; } } + match std.map.remove::>(q, 0) { std.option.Option::>::none => {}, std.option.Option::>::some(value) => { trap; } } + let value = own.new(42u64, heap) or trap; + match std.map.insert::>(q, 0, move value) { + std.map.InsertResult::>::full(value) => { assert(own.take(move value) == 42u64); } + std.map.InsertResult::>::inserted => { trap; } + std.map.InsertResult::>::replaced(old) => { trap; } + } + } + { ref q = map; assert(not std.map.contains::>(ref q, 0)); } + released::>(move map); return 42; +} diff --git a/tests/conformance/source/modules/alias.aji b/tests/conformance/source/modules/alias.aji new file mode 100644 index 0000000..b05754c --- /dev/null +++ b/tests/conformance/source/modules/alias.aji @@ -0,0 +1,7 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.borrow=source/modules/borrow.aji.inc +module app.entry +import app.borrow; +fn main() -> u8 effects [] { var data: [u8; 4] = zero; ref held = data; app.borrow.fill(mut data); return held[0]; } diff --git a/tests/conformance/source/modules/bad_member.aji.inc b/tests/conformance/source/modules/bad_member.aji.inc new file mode 100644 index 0000000..c6f8ac3 --- /dev/null +++ b/tests/conformance/source/modules/bad_member.aji.inc @@ -0,0 +1,2 @@ +module app.bad +fn nope() -> u8 effects [] { return missing(); } diff --git a/tests/conformance/source/modules/bad_syntax.aji.inc b/tests/conformance/source/modules/bad_syntax.aji.inc new file mode 100644 index 0000000..ed261bf --- /dev/null +++ b/tests/conformance/source/modules/bad_syntax.aji.inc @@ -0,0 +1,2 @@ +module app.broken +fn nope( diff --git a/tests/conformance/source/modules/borrow.aji b/tests/conformance/source/modules/borrow.aji new file mode 100644 index 0000000..1de4cd3 --- /dev/null +++ b/tests/conformance/source/modules/borrow.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.borrow=source/modules/borrow.aji.inc +module app.entry +import app.borrow; +fn main() -> u8 effects [] { var data: [u8; 4] = zero; app.borrow.fill(mut data); return data[3]; } diff --git a/tests/conformance/source/modules/borrow.aji.inc b/tests/conformance/source/modules/borrow.aji.inc new file mode 100644 index 0000000..18e4ba9 --- /dev/null +++ b/tests/conformance/source/modules/borrow.aji.inc @@ -0,0 +1,2 @@ +module app.borrow +fn fill(dst: slice_mut) -> void effects [] { for i in 0..dst.len { dst[i] = 42; } } diff --git a/tests/conformance/source/modules/collision.aji b/tests/conformance/source/modules/collision.aji new file mode 100644 index 0000000..41ab30d --- /dev/null +++ b/tests/conformance/source/modules/collision.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +struct __aji_app_model_Pair { own_value: u64 } +fn __aji_app_model_total() -> u64 effects [] { return 7; } +fn main() -> u64 effects [] { + assert(__aji_app_model_total() == 7); + let pair = app.model.Pair { right: 22, left: 20 }; + return app.model.total(pair); +} diff --git a/tests/conformance/source/modules/cycle.aji b/tests/conformance/source/modules/cycle.aji new file mode 100644 index 0000000..d9e333a --- /dev/null +++ b/tests/conformance/source/modules/cycle.aji @@ -0,0 +1,8 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.a=source/modules/cycle_a.aji.inc +// module: app.b=source/modules/cycle_b.aji.inc +module app.entry +import app.a; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/cycle_a.aji.inc b/tests/conformance/source/modules/cycle_a.aji.inc new file mode 100644 index 0000000..1f678de --- /dev/null +++ b/tests/conformance/source/modules/cycle_a.aji.inc @@ -0,0 +1,3 @@ +module app.a +import app.b; +fn value() -> u8 effects [] { return 1; } diff --git a/tests/conformance/source/modules/cycle_b.aji.inc b/tests/conformance/source/modules/cycle_b.aji.inc new file mode 100644 index 0000000..cc8748a --- /dev/null +++ b/tests/conformance/source/modules/cycle_b.aji.inc @@ -0,0 +1,2 @@ +module app.b +import app.a; diff --git a/tests/conformance/source/modules/duplicate_binding.aji b/tests/conformance/source/modules/duplicate_binding.aji new file mode 100644 index 0000000..b1b9170 --- /dev/null +++ b/tests/conformance/source/modules/duplicate_binding.aji @@ -0,0 +1,8 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/duplicate_import.aji b/tests/conformance/source/modules/duplicate_import.aji new file mode 100644 index 0000000..d92dee9 --- /dev/null +++ b/tests/conformance/source/modules/duplicate_import.aji @@ -0,0 +1,8 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +import app.model; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/duplicate_member.aji b/tests/conformance/source/modules/duplicate_member.aji new file mode 100644 index 0000000..e230551 --- /dev/null +++ b/tests/conformance/source/modules/duplicate_member.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.duplicate=source/modules/duplicate_member.aji.inc +module app.entry +import app.duplicate; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/duplicate_member.aji.inc b/tests/conformance/source/modules/duplicate_member.aji.inc new file mode 100644 index 0000000..cc3908b --- /dev/null +++ b/tests/conformance/source/modules/duplicate_member.aji.inc @@ -0,0 +1,3 @@ +module app.duplicate +fn member() -> u64 effects [] { return 1; } +fn member() -> u64 effects [] { return 2; } diff --git a/tests/conformance/source/modules/effect.aji.inc b/tests/conformance/source/modules/effect.aji.inc new file mode 100644 index 0000000..36e81ec --- /dev/null +++ b/tests/conformance/source/modules/effect.aji.inc @@ -0,0 +1,2 @@ +module app.effect +fn emit(out: cap) -> void effects [io.write] { io.stdout_write(out, b"module") or trap; } diff --git a/tests/conformance/source/modules/effects.aji b/tests/conformance/source/modules/effects.aji new file mode 100644 index 0000000..b2fed9e --- /dev/null +++ b/tests/conformance/source/modules/effects.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// grant: out=io.write +// stdout: module +// module: app.effect=source/modules/effect.aji.inc +module app.entry +import app.effect; +fn main(out: cap) -> u64 effects [io.write] { app.effect.emit(out); return 42; } diff --git a/tests/conformance/source/modules/error_in_unused_member.aji b/tests/conformance/source/modules/error_in_unused_member.aji new file mode 100644 index 0000000..f604232 --- /dev/null +++ b/tests/conformance/source/modules/error_in_unused_member.aji @@ -0,0 +1,7 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.bad=source/modules/bad_member.aji.inc +module app.entry +import app.bad; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/example.aji b/tests/conformance/source/modules/example.aji new file mode 100644 index 0000000..627e817 --- /dev/null +++ b/tests/conformance/source/modules/example.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/example_model.aji.inc +module app.entry +import app.model; + +fn main() -> u64 +effects [] +{ + let pair = app.model.Pair { left: 20, right: 22 }; + return app.model.total(pair); +} diff --git a/tests/conformance/source/modules/example_model.aji.inc b/tests/conformance/source/modules/example_model.aji.inc new file mode 100644 index 0000000..b794fcd --- /dev/null +++ b/tests/conformance/source/modules/example_model.aji.inc @@ -0,0 +1,7 @@ +module app.model + +struct Pair { left: u64, right: u64 } + +fn total(pair: Pair) -> u64 +effects [] +{ return pair.left + pair.right; } diff --git a/tests/conformance/source/modules/fields.aji b/tests/conformance/source/modules/fields.aji new file mode 100644 index 0000000..e1d8907 --- /dev/null +++ b/tests/conformance/source/modules/fields.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.fields=source/modules/fields.aji.inc +module app.entry +import app.fields; +fn main() -> u64 effects [] { + var pair: app.fields.Pair = app.fields.Pair { left: 19, right: 22 }; + app.fields.increment(mut pair); + let wrapper = app.fields.Wrap { pair: pair }; + let value: app.fields.Pair = app.fields.unwrap(wrapper); + return app.fields.total(ref value); +} diff --git a/tests/conformance/source/modules/fields.aji.inc b/tests/conformance/source/modules/fields.aji.inc new file mode 100644 index 0000000..80bf8ec --- /dev/null +++ b/tests/conformance/source/modules/fields.aji.inc @@ -0,0 +1,6 @@ +module app.fields +struct Pair { left: u64, right: u64 } +struct Wrap { pair: Pair } +fn increment(pair: mut) -> void effects [] { pair.left = pair.left + 1; } +fn total(pair: ref) -> u64 effects [] { return pair.left + pair.right; } +fn unwrap(value: Wrap) -> Pair effects [] { return value.pair; } diff --git a/tests/conformance/source/modules/mismatched_module.aji b/tests/conformance/source/modules/mismatched_module.aji new file mode 100644 index 0000000..7e6b03e --- /dev/null +++ b/tests/conformance/source/modules/mismatched_module.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.other=source/modules/model.aji.inc +module app.entry +import app.other; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/missing_effect.aji b/tests/conformance/source/modules/missing_effect.aji new file mode 100644 index 0000000..e57c352 --- /dev/null +++ b/tests/conformance/source/modules/missing_effect.aji @@ -0,0 +1,7 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.effect=source/modules/effect.aji.inc +module app.entry +import app.effect; +fn main(out: cap) -> u64 effects [] { app.effect.emit(out); return 42; } diff --git a/tests/conformance/source/modules/missing_field.aji b/tests/conformance/source/modules/missing_field.aji new file mode 100644 index 0000000..8093eb6 --- /dev/null +++ b/tests/conformance/source/modules/missing_field.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +fn main() -> u64 effects [] { let pair = app.model.Pair { left: 20 }; return pair.left; } diff --git a/tests/conformance/source/modules/missing_module.aji b/tests/conformance/source/modules/missing_module.aji new file mode 100644 index 0000000..0326c41 --- /dev/null +++ b/tests/conformance/source/modules/missing_module.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +module app.entry +import app.unknown; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/missing_move.aji b/tests/conformance/source/modules/missing_move.aji new file mode 100644 index 0000000..5a8a268 --- /dev/null +++ b/tests/conformance/source/modules/missing_move.aji @@ -0,0 +1,7 @@ +// expect: reject E7003 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.owner=source/modules/owner.aji.inc +module app.entry +import app.owner; +fn main(mem: cap) -> u64 effects [mem.alloc] { let value = own.new(42u64, mem) or trap; app.owner.dispose(value); return 42; } diff --git a/tests/conformance/source/modules/model.aji.inc b/tests/conformance/source/modules/model.aji.inc new file mode 100644 index 0000000..b09f97f --- /dev/null +++ b/tests/conformance/source/modules/model.aji.inc @@ -0,0 +1,9 @@ +module app.model +struct Pair { left: u64, right: u64 } +struct Wrap { pair: Pair } +enum State { Done(Pair), Empty } +fn make() -> Pair effects [] { return Pair { left: 20, right: 22 }; } +fn total(pair: Pair) -> u64 effects [] { return pair.left + pair.right; } +fn helper() -> u64 effects [] { return 10; } +fn local() -> u64 effects [] { return helper(); } +fn main() -> u64 effects [] { return 9; } diff --git a/tests/conformance/source/modules/no_short_import.aji b/tests/conformance/source/modules/no_short_import.aji new file mode 100644 index 0000000..a9b7ecd --- /dev/null +++ b/tests/conformance/source/modules/no_short_import.aji @@ -0,0 +1,7 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +fn main() -> u64 effects [] { let pair = Pair { left: 20, right: 22 }; return pair.left; } diff --git a/tests/conformance/source/modules/nominal.aji b/tests/conformance/source/modules/nominal.aji new file mode 100644 index 0000000..a8bac59 --- /dev/null +++ b/tests/conformance/source/modules/nominal.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +// module: app.other=source/modules/other.aji.inc +module app.entry +import app.model; +import app.other; +fn main() -> u64 effects [] { let pair: app.model.Pair = app.other.make(); return pair.left; } diff --git a/tests/conformance/source/modules/other.aji.inc b/tests/conformance/source/modules/other.aji.inc new file mode 100644 index 0000000..83b6764 --- /dev/null +++ b/tests/conformance/source/modules/other.aji.inc @@ -0,0 +1,3 @@ +module app.other +struct Pair { left: u64, right: u64 } +fn make() -> Pair effects [] { return Pair { left: 20, right: 22 }; } diff --git a/tests/conformance/source/modules/owner.aji b/tests/conformance/source/modules/owner.aji new file mode 100644 index 0000000..998767f --- /dev/null +++ b/tests/conformance/source/modules/owner.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// grant: mem=mem.alloc:128 +// module: app.owner=source/modules/owner.aji.inc +module app.entry +import app.owner; +fn main(mem: cap) -> u64 effects [mem.alloc] { let value = own.new(42u64, mem) or trap; app.owner.dispose(move value); return 42; } diff --git a/tests/conformance/source/modules/owner.aji.inc b/tests/conformance/source/modules/owner.aji.inc new file mode 100644 index 0000000..a700cf2 --- /dev/null +++ b/tests/conformance/source/modules/owner.aji.inc @@ -0,0 +1,2 @@ +module app.owner +fn dispose(value: own) -> void effects [] { own.free(move value); } diff --git a/tests/conformance/source/modules/record.aji b/tests/conformance/source/modules/record.aji new file mode 100644 index 0000000..87eab19 --- /dev/null +++ b/tests/conformance/source/modules/record.aji @@ -0,0 +1,22 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// equivalent: modules/record.air +// module: app.work=source/modules/work.aji.inc +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +import app.work; +fn helper() -> u64 effects [] { return 100; } +fn main() -> u64 effects [] { + let app = 7u8; + assert(app == 7); + assert(helper() == 100); + assert(app.model.local() == 10); + assert(app.model.main() == 9); + let p: app.model.Pair = app.work.run(); + let w = app.model.Wrap { pair: p }; + let state = app.model.State::Done(w.pair); + match state { app.model.State::Done(pair) => { return app.model.total(pair); } app.model.State::Empty => { return 0; } } +} diff --git a/tests/conformance/source/modules/root_self.aji b/tests/conformance/source/modules/root_self.aji new file mode 100644 index 0000000..e6651f0 --- /dev/null +++ b/tests/conformance/source/modules/root_self.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +module app.entry +struct Pair { value: u64 } +fn total(pair: Pair) -> u64 effects [] { return pair.value; } +fn main() -> u64 effects [] { return app.entry.total(app.entry.Pair { value: 42 }); } diff --git a/tests/conformance/source/modules/self_import.aji b/tests/conformance/source/modules/self_import.aji new file mode 100644 index 0000000..30d3713 --- /dev/null +++ b/tests/conformance/source/modules/self_import.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +module app.entry +import app.entry; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/syntax_in_module.aji b/tests/conformance/source/modules/syntax_in_module.aji new file mode 100644 index 0000000..0edec80 --- /dev/null +++ b/tests/conformance/source/modules/syntax_in_module.aji @@ -0,0 +1,7 @@ +// expect: reject E7001 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.broken=source/modules/bad_syntax.aji.inc +module app.entry +import app.broken; +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/task.aji b/tests/conformance/source/modules/task.aji new file mode 100644 index 0000000..cd418cc --- /dev/null +++ b/tests/conformance/source/modules/task.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 10 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// schedules: 8 +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +fn main() -> u64 effects [task.spawn, task.wait] { var result: u64 = 0; scope s { let t = task.spawn(s, app.model.local); result = task.join(move t); } return result; } diff --git a/tests/conformance/source/modules/task_lend.aji b/tests/conformance/source/modules/task_lend.aji new file mode 100644 index 0000000..29af0f4 --- /dev/null +++ b/tests/conformance/source/modules/task_lend.aji @@ -0,0 +1,31 @@ +// Two tasks square the two halves of one buffer; the halves are lent until the joins. +// expect: run +// result: [1,4,9,16] +// equivalent: phase3/run/tasks_parallel_square.air +// schedules: 8 +// module: app.workers=source/modules/workers.aji.inc +// phase: 6 +// spec: docs/spec/15-source-language.md +module app.entry +import app.workers; + +fn main() -> [u64; 4] +effects [task.spawn] +{ + var buf: [u64; 4] = zero; + buf[0] = 1; + buf[1] = 2; + buf[2] = 3; + buf[3] = 4; + { + mut s = buf; + let (l, r) = s.split_at(2); + scope sc { + let t1 = task.spawn(sc, app.workers.square, l); + let t2 = task.spawn(sc, app.workers.square, r); + task.join(move t1); + task.join(move t2); + } + } + buf +} diff --git a/tests/conformance/source/modules/task_lend_twice.aji b/tests/conformance/source/modules/task_lend_twice.aji new file mode 100644 index 0000000..05defe3 --- /dev/null +++ b/tests/conformance/source/modules/task_lend_twice.aji @@ -0,0 +1,23 @@ +// The same exclusive borrow lent to two live tasks: a possible data race (E4101). +// expect: reject E4101 +// module: app.workers=source/modules/workers.aji.inc +// phase: 6 +// spec: docs/spec/15-source-language.md +module app.entry +import app.workers; + +fn main() -> u64 +effects [task.spawn] +{ + var buf: [u64; 2] = zero; + { + mut s = buf; + scope sc { + let a = task.spawn(sc, app.workers.bump, s); + let b = task.spawn(sc, app.workers.bump, s); + task.join(move a); + task.join(move b); + } + } + buf[0] +} diff --git a/tests/conformance/source/modules/task_missing_import.aji b/tests/conformance/source/modules/task_missing_import.aji new file mode 100644 index 0000000..f9d4f8b --- /dev/null +++ b/tests/conformance/source/modules/task_missing_import.aji @@ -0,0 +1,13 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +// module: app.work=source/modules/work.aji.inc +module app.entry +import app.work; +fn main() -> u64 effects [task.spawn, task.wait] { + scope s { + let t = task.spawn(s, app.model.local); + return task.join(move t); + } +} diff --git a/tests/conformance/source/modules/transitive_call.aji b/tests/conformance/source/modules/transitive_call.aji new file mode 100644 index 0000000..0468615 --- /dev/null +++ b/tests/conformance/source/modules/transitive_call.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.work=source/modules/work.aji.inc +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.work; +fn main() -> u64 effects [] { return app.model.local(); } diff --git a/tests/conformance/source/modules/transitive_enum.aji b/tests/conformance/source/modules/transitive_enum.aji new file mode 100644 index 0000000..90ee563 --- /dev/null +++ b/tests/conformance/source/modules/transitive_enum.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.work=source/modules/work.aji.inc +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.work; +fn main() -> u64 effects [] { let value = app.model.State::Empty; return 42; } diff --git a/tests/conformance/source/modules/transitive_type.aji b/tests/conformance/source/modules/transitive_type.aji new file mode 100644 index 0000000..e64616e --- /dev/null +++ b/tests/conformance/source/modules/transitive_type.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.work=source/modules/work.aji.inc +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.work; +fn main() -> u64 effects [] { let pair: app.model.Pair = app.work.run(); return pair.left; } diff --git a/tests/conformance/source/modules/unknown_member.aji b/tests/conformance/source/modules/unknown_member.aji new file mode 100644 index 0000000..5853b27 --- /dev/null +++ b/tests/conformance/source/modules/unknown_member.aji @@ -0,0 +1,7 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/model.aji.inc +module app.entry +import app.model; +fn main() -> u64 effects [] { return app.model.nope(); } diff --git a/tests/conformance/source/modules/unreachable.aji b/tests/conformance/source/modules/unreachable.aji new file mode 100644 index 0000000..7eb4322 --- /dev/null +++ b/tests/conformance/source/modules/unreachable.aji @@ -0,0 +1,7 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.broken=source/modules/bad_syntax.aji.inc +module app.entry +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/modules/work.aji.inc b/tests/conformance/source/modules/work.aji.inc new file mode 100644 index 0000000..6e84223 --- /dev/null +++ b/tests/conformance/source/modules/work.aji.inc @@ -0,0 +1,5 @@ +module app.work +import app.model; +import std.math; +fn run() -> app.model.Pair effects [] { return app.model.make(); } +fn bounded(value: u64) -> u64 effects [] { return std.math.min_u64(value, 42); } diff --git a/tests/conformance/source/modules/workers.aji.inc b/tests/conformance/source/modules/workers.aji.inc new file mode 100644 index 0000000..d2b9153 --- /dev/null +++ b/tests/conformance/source/modules/workers.aji.inc @@ -0,0 +1,3 @@ +module app.workers +fn square(s: slice_mut) -> void effects [] { for i in 0..s.len { s[i] = s[i] * s[i]; } } +fn bump(s: slice_mut) -> void effects [] { s[0] = s[0] + 1; } diff --git a/tests/conformance/source/path/alias.aji b/tests/conformance/source/path/alias.aji new file mode 100644 index 0000000..15e2caa --- /dev/null +++ b/tests/conformance/source/path/alias.aji @@ -0,0 +1,8 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path_alias +import std.path; +fn main() -> u64 effects [] { + var bytes: [u8;4] = [47u8;4]; std.path.normalize(mut bytes,ref bytes); return 42; +} diff --git a/tests/conformance/source/path/all_bytes.aji b/tests/conformance/source/path/all_bytes.aji new file mode 100644 index 0000000..4e20823 --- /dev/null +++ b/tests/conformance/source/path/all_bytes.aji @@ -0,0 +1,21 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path_bytes +import std.path; +fn main() -> u64 effects [] { + for value in 1u16..256u16 { + var path: [u8;1] = [0u8;1]; path[0] = value as! u8; var output: [u8;3] = [255u8;3]; + match std.path.normalize(mut output[1usize..2usize],ref path) { + std.path.WriteResult::ok(n) => { assert(n == 1usize); assert(output[1] == path[0]); }, + std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } + } + assert(output[0] == 255u8); assert(output[2] == 255u8); + let base = std.path.basename(ref path); assert(base.start == 0usize); + if path[0] == 47u8 { assert(base.end == 0usize); } else { assert(base.end == 1usize); } + assert(std.path.is_absolute(ref path) == (path[0] == 47u8)); + let ext = std.path.extension(ref path); assert(ext.start == base.end); assert(ext.end == base.end); + } + return 42; +} diff --git a/tests/conformance/source/path/authority.aji b/tests/conformance/source/path/authority.aji new file mode 100644 index 0000000..edf1573 --- /dev/null +++ b/tests/conformance/source/path/authority.aji @@ -0,0 +1,18 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +// grant: src=fs.read:/allowed +// vfs: /denied/file=secret +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn main(src: cap) -> u64 effects [fs.read] { + var bytes: [u8;16] = [255u8;16]; let n = written(std.path.join(mut bytes,b"/allowed",b"../denied/file")); assert(std.bytes.equal(ref bytes[0usize..n],b"/denied/file")); + match fs.open_read(src,ref bytes[0usize..n]) { ok(file) => { trap; }, err(error) => { match error { io_error::permission_denied => {}, io_error::not_found => { trap; }, io_error::already_exists => { trap; }, io_error::invalid_input => { trap; }, io_error::no_space => { trap; }, io_error::broken_pipe => { trap; }, io_error::connection_refused => { trap; }, io_error::connection_reset => { trap; }, io_error::address_in_use => { trap; }, io_error::address_unavailable => { trap; }, io_error::timed_out => { trap; }, io_error::other => { trap; } } } } + let count = written(std.path.normalize(mut bytes,b"x/../file")); match fs.open_read(src,ref bytes[0usize..count]) { ok(file) => { trap; }, err(error) => { match error { io_error::invalid_input => {}, io_error::permission_denied => { trap; }, io_error::not_found => { trap; }, io_error::already_exists => { trap; }, io_error::no_space => { trap; }, io_error::broken_pipe => { trap; }, io_error::connection_refused => { trap; }, io_error::connection_reset => { trap; }, io_error::address_in_use => { trap; }, io_error::address_unavailable => { trap; }, io_error::timed_out => { trap; }, io_error::other => { trap; } } } } + return 42; +} diff --git a/tests/conformance/source/path/basic.aji b/tests/conformance/source/path/basic.aji new file mode 100644 index 0000000..d16c391 --- /dev/null +++ b/tests/conformance/source/path/basic.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn main() -> u64 effects [] { + var bytes: [u8;12] = [255u8;12]; + match std.path.normalize(mut bytes[1usize..5usize],b"a//b/../c/") { std.path.WriteResult::ok(n) => { assert(n == 3usize); }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } + assert(std.bytes.equal(ref bytes[1usize..4usize],b"a/c")); assert(bytes[0] == 255u8); assert(bytes[4] == 255u8); + match std.path.join(mut bytes,b"/data/a",b"../b") { std.path.WriteResult::ok(n) => { assert(n == 7usize); assert(std.bytes.equal(ref bytes[0usize..n],b"/data/b")); }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } + let base = std.path.basename(b"a//b///"); assert(base.start == 3usize); assert(base.end == 4usize); + let parent = std.path.parent(b"a//b///"); assert(parent.start == 0usize); assert(parent.end == 1usize); + let extension = std.path.extension(b".profile.json"); assert(extension.start == 9usize); assert(extension.end == 13usize); + assert(std.path.is_absolute(b"/")); assert(not std.path.is_absolute(b"a")); return 42; +} diff --git a/tests/conformance/source/path/canceled_capacity.aji b/tests/conformance/source/path/canceled_capacity.aji new file mode 100644 index 0000000..1a79526 --- /dev/null +++ b/tests/conformance/source/path/canceled_capacity.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn main() -> u64 effects [] { + var bytes: [u8;3] = [255u8;3]; let n = written(std.path.normalize(mut bytes[1usize..2usize],b"very-long-component/..")); assert(n == 1usize); assert(bytes[1] == 46u8); assert(bytes[0] == 255u8); assert(bytes[2] == 255u8); + let count = written(std.path.join(mut bytes[1usize..2usize],b"very-long-component",b"../x")); assert(count == 1usize); assert(bytes[1] == 120u8); return 42; +} diff --git a/tests/conformance/source/path/disjoint.aji b/tests/conformance/source/path/disjoint.aji new file mode 100644 index 0000000..270f5ab --- /dev/null +++ b/tests/conformance/source/path/disjoint.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn main() -> u64 effects [] { + var bytes: [u8;16] = [255u8;16]; bytes[0] = 97u8; bytes[1] = 47u8; bytes[2] = 46u8; bytes[3] = 46u8; + { mut all = bytes; let (src,dst) = all.split_at(4usize); let n = written(std.path.normalize(mut dst,ref src)); assert(n == 1usize); } + assert(bytes[4] == 46u8); assert(bytes[5] == 255u8); assert(bytes[0] == 97u8); assert(bytes[3] == 46u8); + { mut all = bytes; let (src,dst) = all.split_at(4usize); let n = written(std.path.join(mut dst,ref src,b"b")); assert(n == 1usize); } + assert(bytes[4] == 98u8); for i in 5usize..16usize { assert(bytes[i] == 255u8); } return 42; +} diff --git a/tests/conformance/source/path/join_alias.aji b/tests/conformance/source/path/join_alias.aji new file mode 100644 index 0000000..0d4e935 --- /dev/null +++ b/tests/conformance/source/path/join_alias.aji @@ -0,0 +1,11 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn bad(bytes: slice_mut) -> void effects [] { std.path.join(mut bytes,b"a",ref bytes); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/path/loan.aji b/tests/conformance/source/path/loan.aji new file mode 100644 index 0000000..dc90761 --- /dev/null +++ b/tests/conformance/source/path/loan.aji @@ -0,0 +1,12 @@ +// expect: reject E4101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn worker(dst: slice_mut) -> void effects [] { std.path.normalize(dst,b"a"); } +fn bad(dst: slice_mut) -> void effects [task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,dst); std.path.normalize(dst,b"b"); task.join(move t); } } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/path/loan_join.aji b/tests/conformance/source/path/loan_join.aji new file mode 100644 index 0000000..18676b3 --- /dev/null +++ b/tests/conformance/source/path/loan_join.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +// schedules: 12 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn worker(destination: slice_mut) -> usize effects [] { return written(std.path.join(destination,b"/data/a",b"../b")); } +fn main() -> u64 effects [task.spawn,task.wait] { + var bytes: [u8;12] = [255u8;12]; + { mut destination = bytes; scope s { let t = task.spawn(s,worker,destination); assert(task.join(move t) == 7usize); assert(written(std.path.normalize(destination,b"/x/..")) == 1usize); } } + assert(bytes[0] == 47u8); assert(std.bytes.equal(ref bytes[1usize..7usize],b"data/b")); return 42; +} diff --git a/tests/conformance/source/path/malformed_unchanged.aji b/tests/conformance/source/path/malformed_unchanged.aji new file mode 100644 index 0000000..c6d53aa --- /dev/null +++ b/tests/conformance/source/path/malformed_unchanged.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn main() -> u64 effects [] { + var bytes: [u8;4] = [255u8;4]; + match std.path.normalize(mut bytes[0usize..0usize],b"very-long/late/\0") { std.path.WriteResult::invalid_input => {}, std.path.WriteResult::ok(n) => { trap; }, std.path.WriteResult::short_output => { trap; }, std.path.WriteResult::size_overflow => { trap; } } + match std.path.join(mut bytes,b"late/\0",b"/ok") { std.path.WriteResult::invalid_input => {}, std.path.WriteResult::ok(n) => { trap; }, std.path.WriteResult::short_output => { trap; }, std.path.WriteResult::size_overflow => { trap; } } + for i in 0usize..4usize { assert(bytes[i] == 255u8); } + let p = std.path.basename(b"a/\0.bin/"); assert(p.start == 2usize); assert(p.end == 7usize); let ext = std.path.extension(b"a/\0.bin/"); assert(ext.start == 4usize); assert(ext.end == 7usize); return 42; +} diff --git a/tests/conformance/source/path/missing_import.aji b/tests/conformance/source/path/missing_import.aji new file mode 100644 index 0000000..77b66b9 --- /dev/null +++ b/tests/conformance/source/path/missing_import.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path_import +fn main() -> u64 effects [] { if std.path.is_absolute(b"a") { trap; } return 42; } diff --git a/tests/conformance/source/path/model.aji b/tests/conformance/source/path/model.aji new file mode 100644 index 0000000..6bfa730 --- /dev/null +++ b/tests/conformance/source/path/model.aji @@ -0,0 +1,465 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +// fuel: 2000000 +module test.path_model +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn query(path: slice,absolute: bool,bs: usize,be: usize,pe: usize,es: usize,ee: usize) -> void effects [] { + assert(std.path.is_absolute(path) == absolute); + let base = std.path.basename(path); let parent = std.path.parent(path); let extension = std.path.extension(path); + assert(base.start == bs); assert(base.end == be); assert(parent.start == 0usize); assert(parent.end == pe); assert(extension.start == es); assert(extension.end == ee); + assert(base.start <= base.end); assert(base.end <= path.len); assert(parent.end <= path.len); assert(extension.start <= extension.end); assert(extension.end <= path.len); +} +fn normalized(path: slice,expected: slice) -> void effects [] { + for capacity in 0usize..expected.len+2usize { + var bytes: [u8;64] = [255u8;64]; + match std.path.normalize(mut bytes[1usize..capacity+1usize],path) { + std.path.WriteResult::ok(n) => { assert(capacity >= expected.len); assert(n == expected.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],expected)); for i in n+1usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::short_output => { assert(capacity < expected.len); for i in 0usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; } + } + assert(bytes[0] == 255u8); + } + var twice: [u8;64] = [255u8;64]; let n = written(std.path.normalize(mut twice,expected)); assert(std.bytes.equal(ref twice[0usize..n],expected)); +} +fn joined(base: slice,child: slice,expected: slice) -> void effects [] { + for capacity in 0usize..expected.len+2usize { + var bytes: [u8;64] = [255u8;64]; + match std.path.join(mut bytes[1usize..capacity+1usize],base,child) { + std.path.WriteResult::ok(n) => { assert(capacity >= expected.len); assert(n == expected.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],expected)); for i in n+1usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::short_output => { assert(capacity < expected.len); for i in 0usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; } + } + assert(bytes[0] == 255u8); + } +} +fn invalid(base: slice,child: slice) -> void effects [] { + for capacity in 0usize..3usize { var bytes: [u8;4] = [255u8;4]; + match std.path.join(mut bytes[0usize..capacity],base,child) { std.path.WriteResult::invalid_input => {}, std.path.WriteResult::ok(n) => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } + for i in 0usize..4usize { assert(bytes[i] == 255u8); } + } +} +fn batch_0() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(ref blank[0usize..0usize],false,0usize,0usize,0usize,0usize,0usize); +normalized(ref blank[0usize..0usize],b"."); +query(b".",false,0usize,1usize,0usize,1usize,1usize); +normalized(b".",b"."); +query(b"..",false,0usize,2usize,0usize,2usize,2usize); +normalized(b"..",b".."); +query(b"../.",false,3usize,4usize,2usize,4usize,4usize); +normalized(b"../.",b".."); +query(b"../..",false,3usize,5usize,2usize,5usize,5usize); +normalized(b"../..",b"../.."); +query(b"../../.",false,6usize,7usize,5usize,7usize,7usize); +normalized(b"../../.",b"../.."); +query(b"../../..",false,6usize,8usize,5usize,8usize,8usize); +normalized(b"../../..",b"../../.."); +query(b"../../..//",false,6usize,8usize,5usize,8usize,8usize); +normalized(b"../../..//",b"../../.."); +} + +fn batch_1() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"../.././/",false,6usize,7usize,5usize,7usize,7usize); +normalized(b"../.././/",b"../.."); +query(b"../..//",false,3usize,5usize,2usize,5usize,5usize); +normalized(b"../..//",b"../.."); +query(b"../../a",false,6usize,7usize,5usize,7usize,7usize); +normalized(b"../../a",b"../../a"); +query(b"../../a//",false,6usize,7usize,5usize,7usize,7usize); +normalized(b"../../a//",b"../../a"); +query(b".././.",false,5usize,6usize,4usize,6usize,6usize); +normalized(b".././.",b".."); +query(b".././..",false,5usize,7usize,4usize,7usize,7usize); +normalized(b".././..",b"../.."); +query(b".././..//",false,5usize,7usize,4usize,7usize,7usize); +normalized(b".././..//",b"../.."); +query(b"../././/",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"../././/",b".."); +} + +fn batch_2() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b".././/",false,3usize,4usize,2usize,4usize,4usize); +normalized(b".././/",b".."); +query(b".././a",false,5usize,6usize,4usize,6usize,6usize); +normalized(b".././a",b"../a"); +query(b".././a//",false,5usize,6usize,4usize,6usize,6usize); +normalized(b".././a//",b"../a"); +query(b"..//",false,0usize,2usize,0usize,2usize,2usize); +normalized(b"..//",b".."); +query(b"../a",false,3usize,4usize,2usize,4usize,4usize); +normalized(b"../a",b"../a"); +query(b"../a/.",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"../a/.",b"../a"); +query(b"../a/..",false,5usize,7usize,4usize,7usize,7usize); +normalized(b"../a/..",b".."); +query(b"../a/..//",false,5usize,7usize,4usize,7usize,7usize); +normalized(b"../a/..//",b".."); +} + +fn batch_3() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"../a/.//",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"../a/.//",b"../a"); +query(b"../a//",false,3usize,4usize,2usize,4usize,4usize); +normalized(b"../a//",b"../a"); +query(b"../a/a",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"../a/a",b"../a/a"); +query(b"../a/a//",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"../a/a//",b"../a/a"); +query(b"./.",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"./.",b"."); +query(b"./..",false,2usize,4usize,1usize,4usize,4usize); +normalized(b"./..",b".."); +query(b"./../.",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"./../.",b".."); +query(b"./../..",false,5usize,7usize,4usize,7usize,7usize); +normalized(b"./../..",b"../.."); +} + +fn batch_4() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"./../..//",false,5usize,7usize,4usize,7usize,7usize); +normalized(b"./../..//",b"../.."); +query(b"./.././/",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"./.././/",b".."); +query(b"./..//",false,2usize,4usize,1usize,4usize,4usize); +normalized(b"./..//",b".."); +query(b"./../a",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"./../a",b"../a"); +query(b"./../a//",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"./../a//",b"../a"); +query(b"././.",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"././.",b"."); +query(b"././..",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"././..",b".."); +query(b"././..//",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"././..//",b".."); +} + +fn batch_5() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"./././/",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"./././/",b"."); +query(b"././/",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"././/",b"."); +query(b"././a",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"././a",b"a"); +query(b"././a//",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"././a//",b"a"); +query(b".//",false,0usize,1usize,0usize,1usize,1usize); +normalized(b".//",b"."); +query(b"./a",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"./a",b"a"); +query(b"./a/.",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"./a/.",b"a"); +query(b"./a/..",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"./a/..",b"."); +} + +fn batch_6() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"./a/..//",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"./a/..//",b"."); +query(b"./a/.//",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"./a/.//",b"a"); +query(b"./a//",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"./a//",b"a"); +query(b"./a/a",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"./a/a",b"a/a"); +query(b"./a/a//",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"./a/a//",b"a/a"); +query(b".profile",false,0usize,8usize,0usize,8usize,8usize); +normalized(b".profile",b".profile"); +query(b".profile.json",false,0usize,13usize,0usize,9usize,13usize); +normalized(b".profile.json",b".profile.json"); +query(b"/",true,0usize,0usize,1usize,0usize,0usize); +normalized(b"/",b"/"); +} + +fn batch_7() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"/.",true,1usize,2usize,1usize,2usize,2usize); +normalized(b"/.",b"/"); +query(b"/..",true,1usize,3usize,1usize,3usize,3usize); +normalized(b"/..",b"/"); +query(b"/../.",true,4usize,5usize,3usize,5usize,5usize); +normalized(b"/../.",b"/"); +query(b"/../..",true,4usize,6usize,3usize,6usize,6usize); +normalized(b"/../..",b"/"); +query(b"/../../.",true,7usize,8usize,6usize,8usize,8usize); +normalized(b"/../../.",b"/"); +query(b"/../../..",true,7usize,9usize,6usize,9usize,9usize); +normalized(b"/../../..",b"/"); +query(b"/../../a",true,7usize,8usize,6usize,8usize,8usize); +normalized(b"/../../a",b"/a"); +query(b"/.././.",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/.././.",b"/"); +} + +fn batch_8() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"/.././..",true,6usize,8usize,5usize,8usize,8usize); +normalized(b"/.././..",b"/"); +query(b"/.././a",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/.././a",b"/a"); +query(b"/../a",true,4usize,5usize,3usize,5usize,5usize); +normalized(b"/../a",b"/a"); +query(b"/../a/.",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/../a/.",b"/a"); +query(b"/../a/..",true,6usize,8usize,5usize,8usize,8usize); +normalized(b"/../a/..",b"/"); +query(b"/../a/a",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/../a/a",b"/a/a"); +query(b"/./.",true,3usize,4usize,2usize,4usize,4usize); +normalized(b"/./.",b"/"); +query(b"/./..",true,3usize,5usize,2usize,5usize,5usize); +normalized(b"/./..",b"/"); +} + +fn batch_9() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"/./../.",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/./../.",b"/"); +query(b"/./../..",true,6usize,8usize,5usize,8usize,8usize); +normalized(b"/./../..",b"/"); +query(b"/./../a",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/./../a",b"/a"); +query(b"/././.",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/././.",b"/"); +query(b"/././..",true,5usize,7usize,4usize,7usize,7usize); +normalized(b"/././..",b"/"); +query(b"/././a",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/././a",b"/a"); +query(b"/./a",true,3usize,4usize,2usize,4usize,4usize); +normalized(b"/./a",b"/a"); +query(b"/./a/.",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/./a/.",b"/a"); +} + +fn batch_10() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"/./a/..",true,5usize,7usize,4usize,7usize,7usize); +normalized(b"/./a/..",b"/"); +query(b"/./a/a",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/./a/a",b"/a/a"); +query(b"///",true,0usize,0usize,1usize,0usize,0usize); +normalized(b"///",b"/"); +query(b"//a//b///",true,5usize,6usize,3usize,6usize,6usize); +normalized(b"//a//b///",b"/a/b"); +query(b"/a",true,1usize,2usize,1usize,2usize,2usize); +normalized(b"/a",b"/a"); +query(b"/a/.",true,3usize,4usize,2usize,4usize,4usize); +normalized(b"/a/.",b"/a"); +query(b"/a/..",true,3usize,5usize,2usize,5usize,5usize); +normalized(b"/a/..",b"/"); +query(b"/a/../.",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/a/../.",b"/"); +} + +fn batch_11() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"/a/../..",true,6usize,8usize,5usize,8usize,8usize); +normalized(b"/a/../..",b"/"); +query(b"/a/../a",true,6usize,7usize,5usize,7usize,7usize); +normalized(b"/a/../a",b"/a"); +query(b"/a/./.",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/a/./.",b"/a"); +query(b"/a/./..",true,5usize,7usize,4usize,7usize,7usize); +normalized(b"/a/./..",b"/"); +query(b"/a/./a",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/a/./a",b"/a/a"); +query(b"/a/a",true,3usize,4usize,2usize,4usize,4usize); +normalized(b"/a/a",b"/a/a"); +query(b"/a/a/.",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/a/a/.",b"/a/a"); +query(b"/a/a/..",true,5usize,7usize,4usize,7usize,7usize); +normalized(b"/a/a/..",b"/a"); +} + +fn batch_12() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"/a/a/a",true,5usize,6usize,4usize,6usize,6usize); +normalized(b"/a/a/a",b"/a/a/a"); +query(b"/a/\xff/..",true,5usize,7usize,4usize,7usize,7usize); +normalized(b"/a/\xff/..",b"/a"); +query(b"C:\x5cfile.txt",false,0usize,11usize,0usize,8usize,11usize); +normalized(b"C:\x5cfile.txt",b"C:\x5cfile.txt"); +query(b"a",false,0usize,1usize,0usize,1usize,1usize); +normalized(b"a",b"a"); +query(b"a.",false,0usize,2usize,0usize,2usize,2usize); +normalized(b"a.",b"a."); +query(b"a..b",false,0usize,4usize,0usize,3usize,4usize); +normalized(b"a..b",b"a..b"); +query(b"a/.",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"a/.",b"a"); +query(b"a/..",false,2usize,4usize,1usize,4usize,4usize); +normalized(b"a/..",b"."); +} + +fn batch_13() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"a/../.",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"a/../.",b"."); +query(b"a/../..",false,5usize,7usize,4usize,7usize,7usize); +normalized(b"a/../..",b".."); +query(b"a/../..//",false,5usize,7usize,4usize,7usize,7usize); +normalized(b"a/../..//",b".."); +query(b"a/../../b",false,8usize,9usize,7usize,9usize,9usize); +normalized(b"a/../../b",b"../b"); +query(b"a/.././/",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"a/.././/",b"."); +query(b"a/..//",false,2usize,4usize,1usize,4usize,4usize); +normalized(b"a/..//",b"."); +query(b"a/../a",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"a/../a",b"a"); +query(b"a/../a//",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"a/../a//",b"a"); +} + +fn batch_14() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"a/../b",false,5usize,6usize,4usize,6usize,6usize); +normalized(b"a/../b",b"b"); +query(b"a/./.",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/./.",b"a"); +query(b"a/./..",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"a/./..",b"."); +query(b"a/./..//",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"a/./..//",b"."); +query(b"a/././/",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/././/",b"a"); +query(b"a/.//",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"a/.//",b"a"); +query(b"a/./a",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/./a",b"a/a"); +query(b"a/./a//",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/./a//",b"a/a"); +} + +fn batch_15() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"a//",false,0usize,1usize,0usize,1usize,1usize); +normalized(b"a//",b"a"); +query(b"a/a",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"a/a",b"a/a"); +query(b"a/a/.",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/a/.",b"a/a"); +query(b"a/a/..",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"a/a/..",b"a"); +query(b"a/a/..//",false,4usize,6usize,3usize,6usize,6usize); +normalized(b"a/a/..//",b"a"); +query(b"a/a/.//",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/a/.//",b"a/a"); +query(b"a/a//",false,2usize,3usize,1usize,3usize,3usize); +normalized(b"a/a//",b"a/a"); +query(b"a/a/a",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/a/a",b"a/a/a"); +} + +fn batch_16() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +query(b"a/a/a//",false,4usize,5usize,3usize,5usize,5usize); +normalized(b"a/a/a//",b"a/a/a"); +query(b"a/\xff.bin",false,2usize,7usize,1usize,4usize,7usize); +normalized(b"a/\xff.bin",b"a/\xff.bin"); +query(b"x\x5cy/../z",false,7usize,8usize,6usize,8usize,8usize); +normalized(b"x\x5cy/../z",b"z"); +query(b"\x80\xfe",false,0usize,2usize,0usize,2usize,2usize); +normalized(b"\x80\xfe",b"\x80\xfe"); +joined(ref blank[0usize..0usize],ref blank[0usize..0usize],b"."); +joined(ref blank[0usize..0usize],b"b",b"b"); +joined(ref blank[0usize..0usize],b"..",b".."); +joined(ref blank[0usize..0usize],b"../b",b"../b"); +joined(ref blank[0usize..0usize],b"../../b",b"../../b"); +joined(ref blank[0usize..0usize],b"/b",b"/b"); +joined(ref blank[0usize..0usize],b"//../b/",b"/b"); +joined(b"a",ref blank[0usize..0usize],b"a"); +} + +fn batch_17() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +joined(b"a",b"b",b"a/b"); +joined(b"a",b"..",b"."); +joined(b"a",b"../b",b"b"); +joined(b"a",b"../../b",b"../b"); +joined(b"a",b"/b",b"/b"); +joined(b"a",b"//../b/",b"/b"); +joined(b"/a",ref blank[0usize..0usize],b"/a"); +joined(b"/a",b"b",b"/a/b"); +joined(b"/a",b"..",b"/"); +joined(b"/a",b"../b",b"/b"); +joined(b"/a",b"../../b",b"/b"); +joined(b"/a",b"/b",b"/b"); +joined(b"/a",b"//../b/",b"/b"); +joined(b"a/b/",ref blank[0usize..0usize],b"a/b"); +joined(b"a/b/",b"b",b"a/b/b"); +joined(b"a/b/",b"..",b"a"); +} + +fn batch_18() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +joined(b"a/b/",b"../b",b"a/b"); +joined(b"a/b/",b"../../b",b"b"); +joined(b"a/b/",b"/b",b"/b"); +joined(b"a/b/",b"//../b/",b"/b"); +joined(b"../a",ref blank[0usize..0usize],b"../a"); +joined(b"../a",b"b",b"../a/b"); +joined(b"../a",b"..",b".."); +joined(b"../a",b"../b",b"../b"); +joined(b"../a",b"../../b",b"../../b"); +joined(b"../a",b"/b",b"/b"); +joined(b"../a",b"//../b/",b"/b"); +joined(b"/",ref blank[0usize..0usize],b"/"); +joined(b"/",b"b",b"/b"); +joined(b"/",b"..",b"/"); +joined(b"/",b"../b",b"/b"); +joined(b"/",b"../../b",b"/b"); +} + +fn batch_19() -> void effects [] { +let blank: [u8;1] = [0u8;1]; +joined(b"/",b"/b",b"/b"); +joined(b"/",b"//../b/",b"/b"); +joined(b"a/..",ref blank[0usize..0usize],b"."); +joined(b"a/..",b"b",b"b"); +joined(b"a/..",b"..",b".."); +joined(b"a/..",b"../b",b"../b"); +joined(b"a/..",b"../../b",b"../../b"); +joined(b"a/..",b"/b",b"/b"); +joined(b"a/..",b"//../b/",b"/b"); +invalid(b"late/name/\x00",b"/b"); +invalid(b"a",b"b/\x00"); +invalid(b"\x00",ref blank[0usize..0usize]); +invalid(ref blank[0usize..0usize],b"\x00"); +} +fn main() -> u64 effects [] { +batch_0(); +batch_1(); +batch_2(); +batch_3(); +batch_4(); +batch_5(); +batch_6(); +batch_7(); +batch_8(); +batch_9(); +batch_10(); +batch_11(); +batch_12(); +batch_13(); +batch_14(); +batch_15(); +batch_16(); +batch_17(); +batch_18(); +batch_19(); +return 42; +} diff --git a/tests/conformance/source/path/overlap.aji b/tests/conformance/source/path/overlap.aji new file mode 100644 index 0000000..e9b8bd9 --- /dev/null +++ b/tests/conformance/source/path/overlap.aji @@ -0,0 +1,10 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn main() -> u64 effects [] { var bytes: [u8;8] = [47u8;8]; std.path.normalize(mut bytes[0usize..4usize],ref bytes[2usize..6usize]); return 42; } diff --git a/tests/conformance/source/path/range_bounds.aji b/tests/conformance/source/path/range_bounds.aji new file mode 100644 index 0000000..d8019f5 --- /dev/null +++ b/tests/conformance/source/path/range_bounds.aji @@ -0,0 +1,10 @@ +// expect: run +// trap: T0008 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path_bounds +import std.path; +fn main() -> u64 effects [] { + let range = std.path.basename(b"long/name.txt"); let short: [u8;1] = [0u8;1]; + ref bytes = short[range.start..range.end]; return bytes.len as! u64; +} diff --git a/tests/conformance/source/path/shared.aji b/tests/conformance/source/path/shared.aji new file mode 100644 index 0000000..4f5bf85 --- /dev/null +++ b/tests/conformance/source/path/shared.aji @@ -0,0 +1,17 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +// schedules: 12 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn worker(path: slice) -> usize effects [] { let result = std.path.basename(path); return result.end - result.start; } +fn main() -> u64 effects [task.spawn,task.wait] { + let path = b"/data/file.txt"; + { ref input = path; scope s { let a = task.spawn(s,worker,input); let b = task.spawn(s,worker,input); assert(task.join(move a) == 8usize); assert(task.join(move b) == 8usize); } } + return 42; +} diff --git a/tests/conformance/source/path/wrong_input.aji b/tests/conformance/source/path/wrong_input.aji new file mode 100644 index 0000000..47def35 --- /dev/null +++ b/tests/conformance/source/path/wrong_input.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn bad(path: slice) -> std.path.Range effects [] { return std.path.basename(path); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/path/wrong_range.aji b/tests/conformance/source/path/wrong_range.aji new file mode 100644 index 0000000..d3fed22 --- /dev/null +++ b/tests/conformance/source/path/wrong_range.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path +import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn bad(path: slice) -> usize effects [] { return std.path.basename(path); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/path/wrong_slice.aji b/tests/conformance/source/path/wrong_slice.aji new file mode 100644 index 0000000..e8d1580 --- /dev/null +++ b/tests/conformance/source/path/wrong_slice.aji @@ -0,0 +1,8 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +module test.path_type +import std.path; +fn main() -> u64 effects [] { + var bytes: [u16;4] = [0u16;4]; std.path.normalize(mut bytes,b"a"); return 42; +} diff --git a/tests/conformance/source/quickref/buffers.aji b/tests/conformance/source/quickref/buffers.aji new file mode 100644 index 0000000..c8356d2 --- /dev/null +++ b/tests/conformance/source/quickref/buffers.aji @@ -0,0 +1,18 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:16 +// phase: 6 +// spec: docs/agent/quick-reference.md §14 +module quickref.buffers +fn main(heap: cap) -> u64 effects [mem.alloc] { + let data = buffer.new>(1, heap) or trap; + let item = own.new(42u64, heap) or trap; + var answer: u64 = 0; + { mut b = data; + buffer.push(b, move item) or trap; + let last = buffer.pop(b) or trap; + answer = own.take(move last); + } + buffer.free(move data) or trap; + return answer; +} diff --git a/tests/conformance/source/quickref/generics.aji b/tests/conformance/source/quickref/generics.aji new file mode 100644 index 0000000..0c3ea33 --- /dev/null +++ b/tests/conformance/source/quickref/generics.aji @@ -0,0 +1,16 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §15 +module demo.generic +import std.option; + +fn identity(value: T) -> T effects [] { return value; } + +fn main() -> u64 effects [] { + let value = std.option.Option::::some(identity::(42)); + match value { + std.option.Option::::some(n) => { return n; } + std.option.Option::::none => { return 0; } + } +} diff --git a/tests/conformance/source/quickref/linear.aji b/tests/conformance/source/quickref/linear.aji new file mode 100644 index 0000000..3be2c71 --- /dev/null +++ b/tests/conformance/source/quickref/linear.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/03-memory-model.md §25 +module demo.linear +struct Item { owner: own } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let owner = own.new(42u64, heap) or trap; + let value = Item { owner: move owner }; + let (part) = struct.unpack(move value); + return own.take(move part); +} diff --git a/tests/conformance/source/quickref/modules.aji b/tests/conformance/source/quickref/modules.aji new file mode 100644 index 0000000..627e817 --- /dev/null +++ b/tests/conformance/source/quickref/modules.aji @@ -0,0 +1,14 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §14 +// module: app.model=source/modules/example_model.aji.inc +module app.entry +import app.model; + +fn main() -> u64 +effects [] +{ + let pair = app.model.Pair { left: 20, right: 22 }; + return app.model.total(pair); +} diff --git a/tests/conformance/source/quickref/static_functions.aji b/tests/conformance/source/quickref/static_functions.aji new file mode 100644 index 0000000..7fde659 --- /dev/null +++ b/tests/conformance/source/quickref/static_functions.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module demo.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { + return F(move value); +} +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/quickref/std.aji b/tests/conformance/source/quickref/std.aji new file mode 100644 index 0000000..56b7517 --- /dev/null +++ b/tests/conformance/source/quickref/std.aji @@ -0,0 +1,18 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md +module demo.standard +import std.bytes; +import std.math; + +fn main() -> u64 +effects [] +{ + var data: [u8; 4] = zero; + std.bytes.fill(mut data, 65); + assert(std.bytes.equal(ref data, b"AAAA")); + let index = std.bytes.find(ref data, 65); + if index < data.len { assert(data[index] == 65); } + return std.math.clamp_u64(42, 0, 100); +} diff --git a/tests/conformance/source/quickref/std_endian.aji b/tests/conformance/source/quickref/std_endian.aji new file mode 100644 index 0000000..e8605b8 --- /dev/null +++ b/tests/conformance/source/quickref/std_endian.aji @@ -0,0 +1,20 @@ +// expect: run +// result: 305419896 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3 +module demo.endian +import std.bytes; + +fn main() -> u32 +effects [] +{ + var wire: [u8; 6] = zero; + match std.bytes.write_u32_be(mut wire[1..5], 0x12345678) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + match std.bytes.read_u32_be(ref wire[1..5]) { + std.bytes.ReadU32::ok(value) => { return value; } + std.bytes.ReadU32::short_input => { return 0; } + } +} diff --git a/tests/conformance/source/static_functions/algorithm.aji.inc b/tests/conformance/source/static_functions/algorithm.aji.inc new file mode 100644 index 0000000..9e027eb --- /dev/null +++ b/tests/conformance/source/static_functions/algorithm.aji.inc @@ -0,0 +1,3 @@ +module app.algorithm +import app.policy; +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } diff --git a/tests/conformance/source/static_functions/bad_effect_header.aji b/tests/conformance/source/static_functions/bad_effect_header.aji new file mode 100644 index 0000000..1137504 --- /dev/null +++ b/tests/conformance/source/static_functions/bad_effect_header.aji @@ -0,0 +1,6 @@ +// expect: reject E0006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn unused u64 effects [nonexistent]>() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/borrow.aji b/tests/conformance/source/static_functions/borrow.aji new file mode 100644 index 0000000..fcb1bfb --- /dev/null +++ b/tests/conformance/source/static_functions/borrow.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn observe) -> u64 effects []>(key: ref) -> u64 effects [] { return H(key); } +fn main() -> u64 effects [] { let key = Key { id: 42 }; return observe::(ref key); } diff --git a/tests/conformance/source/static_functions/borrow_return_header.aji b/tests/conformance/source/static_functions/borrow_return_header.aji new file mode 100644 index 0000000..2c04896 --- /dev/null +++ b/tests/conformance/source/static_functions/borrow_return_header.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn unused) -> ref effects []>() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/builtin_function.aji b/tests/conformance/source/static_functions/builtin_function.aji new file mode 100644 index 0000000..3029026 --- /dev/null +++ b/tests/conformance/source/static_functions/builtin_function.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn run u64 effects []>(x: u64) -> u64 effects [] { return F(x); } +fn main() -> u64 effects [] { return run::(42); } diff --git a/tests/conformance/source/static_functions/callable_as_type.aji b/tests/conformance/source/static_functions/callable_as_type.aji new file mode 100644 index 0000000..99878f4 --- /dev/null +++ b/tests/conformance/source/static_functions/callable_as_type.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +struct Bad u64 effects []> { stored: F } +fn main() -> u64 effects [] { let bad = Bad:: { stored: 42 }; return 42; } diff --git a/tests/conformance/source/static_functions/copy.aji b/tests/conformance/source/static_functions/copy.aji new file mode 100644 index 0000000..5c4adc0 --- /dev/null +++ b/tests/conformance/source/static_functions/copy.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// equivalent: static_functions/copy.air +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/static_functions/cyclic_contract.aji b/tests/conformance/source/static_functions/cyclic_contract.aji new file mode 100644 index 0000000..74e180c --- /dev/null +++ b/tests/conformance/source/static_functions/cyclic_contract.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +struct Policy) -> u64 effects []> { value: T } +fn selected(value: Policy>) -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { let value = Policy::> { value: 42 }; return selected::(value); } diff --git a/tests/conformance/source/static_functions/duplicate_effect_header.aji b/tests/conformance/source/static_functions/duplicate_effect_header.aji new file mode 100644 index 0000000..e54fe2c --- /dev/null +++ b/tests/conformance/source/static_functions/duplicate_effect_header.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn unused u64 effects [io.write, io.write]>() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/effect_narrowing.aji b/tests/conformance/source/static_functions/effect_narrowing.aji new file mode 100644 index 0000000..3503cfa --- /dev/null +++ b/tests/conformance/source/static_functions/effect_narrowing.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn run u64 effects [mem.alloc]>() -> u64 effects [mem.alloc] { return F(42u64); } +fn main() -> u64 effects [mem.alloc] { return run::(); } diff --git a/tests/conformance/source/static_functions/effect_order.aji b/tests/conformance/source/static_functions/effect_order.aji new file mode 100644 index 0000000..8b1670e --- /dev/null +++ b/tests/conformance/source/static_functions/effect_order.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected() -> u64 effects [task.wait, task.spawn] { return 42; } +fn run u64 effects [task.spawn, task.wait]>() -> u64 effects [task.spawn, task.wait] { return F(); } +fn main() -> u64 effects [task.spawn, task.wait] { return run::(); } diff --git a/tests/conformance/source/static_functions/effects.aji b/tests/conformance/source/static_functions/effects.aji new file mode 100644 index 0000000..ee679cc --- /dev/null +++ b/tests/conformance/source/static_functions/effects.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// grant: out=io.write +// stdout: 42 +module test.static_functions +fn write(out: cap, data: slice) -> void effects [io.write] { io.stdout_write(out, data) or trap; } +fn run, slice) -> void effects [io.write]>(out: cap) -> u64 effects [io.write] { F(out, b"42"); return 42; } +fn main(out: cap) -> u64 effects [io.write] { return run::(out); } diff --git a/tests/conformance/source/static_functions/effects_mismatch.aji b/tests/conformance/source/static_functions/effects_mismatch.aji new file mode 100644 index 0000000..474b0a4 --- /dev/null +++ b/tests/conformance/source/static_functions/effects_mismatch.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected(value: u64) -> u64 effects [io.write] { return value; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/static_functions/escape.aji b/tests/conformance/source/static_functions/escape.aji new file mode 100644 index 0000000..89383e7 --- /dev/null +++ b/tests/conformance/source/static_functions/escape.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn bad u64 effects []>() -> u64 effects [] { let value = F; return 42; } +fn main() -> u64 effects [] { return bad::(); } diff --git a/tests/conformance/source/static_functions/fn_shadow.aji b/tests/conformance/source/static_functions/fn_shadow.aji new file mode 100644 index 0000000..de345f7 --- /dev/null +++ b/tests/conformance/source/static_functions/fn_shadow.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn F(value: u64) -> u64 effects [] { return value; } +fn unused u64 effects []>() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/forward.aji b/tests/conformance/source/static_functions/forward.aji new file mode 100644 index 0000000..27544a9 --- /dev/null +++ b/tests/conformance/source/static_functions/forward.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn forward T effects []>(value: T) -> T effects [] { return apply::(move value); } +fn main() -> u64 effects [] { return forward::(42u64); } diff --git a/tests/conformance/source/static_functions/forward_respecialize.aji b/tests/conformance/source/static_functions/forward_respecialize.aji new file mode 100644 index 0000000..9ac68dd --- /dev/null +++ b/tests/conformance/source/static_functions/forward_respecialize.aji @@ -0,0 +1,8 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply u64 effects []>() -> u64 effects [] { return 42; } +fn run u64 effects []>() -> u64 effects [] { return apply::>(); } +fn main() -> u64 effects [] { return run::(); } diff --git a/tests/conformance/source/static_functions/function_as_type.aji b/tests/conformance/source/static_functions/function_as_type.aji new file mode 100644 index 0000000..0018ef4 --- /dev/null +++ b/tests/conformance/source/static_functions/function_as_type.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn id(value: T) -> T effects [] { return move value; } +fn main() -> u64 effects [] { return id::(42u64); } diff --git a/tests/conformance/source/static_functions/generic_argument.aji b/tests/conformance/source/static_functions/generic_argument.aji new file mode 100644 index 0000000..6dacccb --- /dev/null +++ b/tests/conformance/source/static_functions/generic_argument.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn identity(value: T) -> T effects [] { return move value; } +fn main() -> u64 effects [] { return apply::>(42u64); } diff --git a/tests/conformance/source/static_functions/imported.aji b/tests/conformance/source/static_functions/imported.aji new file mode 100644 index 0000000..99a383d --- /dev/null +++ b/tests/conformance/source/static_functions/imported.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// module: app.policy=source/static_functions/policy.aji.inc +// module: app.algorithm=source/static_functions/algorithm.aji.inc +module test.static_functions +import app.policy; +import app.algorithm; +fn main() -> u64 effects [] { return app.algorithm.apply::(42u64); } diff --git a/tests/conformance/source/static_functions/limit_header.aji b/tests/conformance/source/static_functions/limit_header.aji new file mode 100644 index 0000000..b446522 --- /dev/null +++ b/tests/conformance/source/static_functions/limit_header.aji @@ -0,0 +1,6 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn unused u64 effects []>() -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/loan_conflict.aji b/tests/conformance/source/static_functions/loan_conflict.aji new file mode 100644 index 0000000..c256e52 --- /dev/null +++ b/tests/conformance/source/static_functions/loan_conflict.aji @@ -0,0 +1,7 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn set(value: mut) -> void effects [] { *value = 42; } +fn apply) -> void effects []>(value: mut) -> void effects [] { F(value); } +fn main() -> u64 effects [] { var value: u64 = 0; ref loan = value; apply::(mut value); return *loan; } diff --git a/tests/conformance/source/static_functions/local_shadow.aji b/tests/conformance/source/static_functions/local_shadow.aji new file mode 100644 index 0000000..4f6b5cb --- /dev/null +++ b/tests/conformance/source/static_functions/local_shadow.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn bad u64 effects []>() -> u64 effects [] { let F = 42u64; return F; } +fn main() -> u64 effects [] { return bad::(); } diff --git a/tests/conformance/source/static_functions/missing_effect.aji b/tests/conformance/source/static_functions/missing_effect.aji new file mode 100644 index 0000000..5c13aaf --- /dev/null +++ b/tests/conformance/source/static_functions/missing_effect.aji @@ -0,0 +1,7 @@ +// expect: reject E3101 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected(out: cap) -> u64 effects [io.write] { return 42; } +fn run) -> u64 effects [io.write]>(out: cap) -> u64 effects [] { return F(out); } +fn main(out: cap) -> u64 effects [] { return run::(out); } diff --git a/tests/conformance/source/static_functions/mutating.aji b/tests/conformance/source/static_functions/mutating.aji new file mode 100644 index 0000000..474e7aa --- /dev/null +++ b/tests/conformance/source/static_functions/mutating.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn set(value: mut) -> void effects [] { *value = 42; } +fn apply) -> void effects []>(value: mut) -> void effects [] { F(value); } +fn main() -> u64 effects [] { var value: u64 = 0; apply::(mut value); return value; } diff --git a/tests/conformance/source/static_functions/nested_argument.aji b/tests/conformance/source/static_functions/nested_argument.aji new file mode 100644 index 0000000..5a1280c --- /dev/null +++ b/tests/conformance/source/static_functions/nested_argument.aji @@ -0,0 +1,10 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +struct Policy T effects []> { value: T } +fn read(value: Policy>) -> T effects [] { return value.value; } +fn main() -> u64 effects [] { let p = Policy::> { value: 42 }; return read::(p); } diff --git a/tests/conformance/source/static_functions/owner.aji b/tests/conformance/source/static_functions/owner.aji new file mode 100644 index 0000000..0bd017b --- /dev/null +++ b/tests/conformance/source/static_functions/owner.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// grant: heap=mem.alloc:8 +module test.static_functions +fn identity(value: own) -> own effects [] { return move value; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main(heap: cap) -> u64 effects [mem.alloc] { + let input = own.new(42u64, heap) or trap; + let output = apply::, fn identity>(move input); return own.take(move output); +} diff --git a/tests/conformance/source/static_functions/owner_leak.aji b/tests/conformance/source/static_functions/owner_leak.aji new file mode 100644 index 0000000..bac796f --- /dev/null +++ b/tests/conformance/source/static_functions/owner_leak.aji @@ -0,0 +1,7 @@ +// expect: reject E3002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected(value: own) -> u64 effects [] { return 42; } +fn run) -> u64 effects []>(value: own) -> u64 effects [] { return F(move value); } +fn main(heap: cap) -> u64 effects [mem.alloc] { let value = own.new(42u64, heap) or trap; return run::(move value); } diff --git a/tests/conformance/source/static_functions/owner_reuse.aji b/tests/conformance/source/static_functions/owner_reuse.aji new file mode 100644 index 0000000..a578244 --- /dev/null +++ b/tests/conformance/source/static_functions/owner_reuse.aji @@ -0,0 +1,9 @@ +// expect: reject E2002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: own) -> own effects [] { return move value; } +fn apply) -> own effects []>(value: own) -> u64 effects [] { + let output = F(move value); own.take(move value); return own.take(move output); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { let value = own.new(42u64, heap) or trap; return apply::(move value); } diff --git a/tests/conformance/source/static_functions/policy.aji.inc b/tests/conformance/source/static_functions/policy.aji.inc new file mode 100644 index 0000000..e6ff766 --- /dev/null +++ b/tests/conformance/source/static_functions/policy.aji.inc @@ -0,0 +1,2 @@ +module app.policy +fn identity(value: u64) -> u64 effects [] { return value; } diff --git a/tests/conformance/source/static_functions/policy_mismatch.aji b/tests/conformance/source/static_functions/policy_mismatch.aji new file mode 100644 index 0000000..3308f2d --- /dev/null +++ b/tests/conformance/source/static_functions/policy_mismatch.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn other(value: u64) -> u64 effects [] { return value; } +struct Policy T effects []> { value: T } +fn read(value: Policy) -> u64 effects [] { return value.value; } +fn main() -> u64 effects [] { let value = Policy:: { value: 42 }; return read(value); } diff --git a/tests/conformance/source/static_functions/recursive.aji b/tests/conformance/source/static_functions/recursive.aji new file mode 100644 index 0000000..40c5b08 --- /dev/null +++ b/tests/conformance/source/static_functions/recursive.aji @@ -0,0 +1,11 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply T effects []>(value: T, n: usize) -> T effects [] { + if n == 0usize { return F(move value); } + return apply::(move value, n - 1usize); +} +fn main() -> u64 effects [] { return apply::(42u64, 4usize); } diff --git a/tests/conformance/source/static_functions/recursive_contract.aji b/tests/conformance/source/static_functions/recursive_contract.aji new file mode 100644 index 0000000..ca6efc5 --- /dev/null +++ b/tests/conformance/source/static_functions/recursive_contract.aji @@ -0,0 +1,9 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +struct Policy) -> u64 effects []> { value: u64 } +fn selected(value: Policy) -> u64 effects [] { return value.value; } +fn apply) -> u64 effects []>(value: Policy) -> u64 effects [] { return F(value); } +fn main() -> u64 effects [] { let value = Policy:: { value: 42 }; return apply::(value); } diff --git a/tests/conformance/source/static_functions/respecialize.aji b/tests/conformance/source/static_functions/respecialize.aji new file mode 100644 index 0000000..9db0114 --- /dev/null +++ b/tests/conformance/source/static_functions/respecialize.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn apply u64 effects []>() -> u64 effects [] { return F::(42u64); } +fn main() -> u64 effects [] { return apply::(); } diff --git a/tests/conformance/source/static_functions/shadow.aji b/tests/conformance/source/static_functions/shadow.aji new file mode 100644 index 0000000..b022365 --- /dev/null +++ b/tests/conformance/source/static_functions/shadow.aji @@ -0,0 +1,7 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn bad u64 effects []>(F: u64) -> u64 effects [] { return 42; } +fn main() -> u64 effects [] { return bad::(0u64); } diff --git a/tests/conformance/source/static_functions/type_as_function.aji b/tests/conformance/source/static_functions/type_as_function.aji new file mode 100644 index 0000000..2733e66 --- /dev/null +++ b/tests/conformance/source/static_functions/type_as_function.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/static_functions/type_identity.aji b/tests/conformance/source/static_functions/type_identity.aji new file mode 100644 index 0000000..7746d47 --- /dev/null +++ b/tests/conformance/source/static_functions/type_identity.aji @@ -0,0 +1,16 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +struct Policy T effects []> { value: T } +enum Result T effects []> { ok(Policy), none } +fn identity(value: u64) -> u64 effects [] { return value; } +fn read T effects []>(value: Policy) -> T effects [] { + let (item) = struct.unpack(move value); return F(move item); +} +fn main() -> u64 effects [] { + let value = Policy:: { value: 42 }; + let result = Result::::ok(value); + match result { Result::::ok(item) => { return read::(item); }, Result::::none => { trap; } } +} diff --git a/tests/conformance/source/static_functions/unimported.aji b/tests/conformance/source/static_functions/unimported.aji new file mode 100644 index 0000000..8dd5b91 --- /dev/null +++ b/tests/conformance/source/static_functions/unimported.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// module: app.policy=source/static_functions/policy.aji.inc +// module: app.algorithm=source/static_functions/algorithm.aji.inc +module test.static_functions +import app.algorithm; +fn main() -> u64 effects [] { return app.algorithm.apply::(42u64); } diff --git a/tests/conformance/source/static_functions/unknown_function.aji b/tests/conformance/source/static_functions/unknown_function.aji new file mode 100644 index 0000000..6b9f177 --- /dev/null +++ b/tests/conformance/source/static_functions/unknown_function.aji @@ -0,0 +1,6 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/static_functions/unused_header.aji b/tests/conformance/source/static_functions/unused_header.aji new file mode 100644 index 0000000..f0792e9 --- /dev/null +++ b/tests/conformance/source/static_functions/unused_header.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +struct Policy T effects []> { value: T } +fn unused(value: Policy) -> void effects [] { trap; } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/worker.aji b/tests/conformance/source/static_functions/worker.aji new file mode 100644 index 0000000..7226d0a --- /dev/null +++ b/tests/conformance/source/static_functions/worker.aji @@ -0,0 +1,11 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// schedules: 12 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn run u64 effects []>() -> u64 effects [task.spawn, task.wait] { + scope s { let t = task.spawn(s, F, 42u64); return task.join(move t); } +} +fn main() -> u64 effects [task.spawn, task.wait] { return run::(); } diff --git a/tests/conformance/source/static_functions/worker_generic.aji b/tests/conformance/source/static_functions/worker_generic.aji new file mode 100644 index 0000000..df214df --- /dev/null +++ b/tests/conformance/source/static_functions/worker_generic.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// schedules: 12 +module test.static_functions +fn identity(value: u64) -> u64 effects [] { return value; } +fn worker(value: T) -> T effects [] { return value; } +fn run u64 effects []>() -> u64 effects [task.spawn, task.wait] { + scope s { let t = task.spawn(s, F, 42u64); return task.join(move t); } +} +fn main() -> u64 effects [task.spawn, task.wait] { return run::>(); } diff --git a/tests/conformance/source/static_functions/worker_live_loan.aji b/tests/conformance/source/static_functions/worker_live_loan.aji new file mode 100644 index 0000000..fd3f95a --- /dev/null +++ b/tests/conformance/source/static_functions/worker_live_loan.aji @@ -0,0 +1,9 @@ +// expect: reject E2101 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn read(value: ref) -> u64 effects [] { return *value; } +fn run) -> u64 effects []>() -> u64 effects [task.spawn, task.wait] { + var value: u64 = 42; scope s { ref loan = value; let t = task.spawn(s, F, loan); value = 0; return task.join(move t); } +} +fn main() -> u64 effects [task.spawn, task.wait] { return run::(); } diff --git a/tests/conformance/source/static_functions/worker_loan.aji b/tests/conformance/source/static_functions/worker_loan.aji new file mode 100644 index 0000000..5e60d06 --- /dev/null +++ b/tests/conformance/source/static_functions/worker_loan.aji @@ -0,0 +1,11 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +// schedules: 12 +module test.static_functions +fn read(value: ref) -> u64 effects [] { return *value; } +fn run) -> u64 effects []>() -> u64 effects [task.spawn, task.wait] { + var value: u64 = 42; var result: u64 = 0; { ref loan = value; scope s { let t = task.spawn(s, F, loan); result = task.join(move t); } } value = 0; return result; +} +fn main() -> u64 effects [task.spawn, task.wait] { return run::(); } diff --git a/tests/conformance/source/static_functions/worker_not_share.aji b/tests/conformance/source/static_functions/worker_not_share.aji new file mode 100644 index 0000000..163eb27 --- /dev/null +++ b/tests/conformance/source/static_functions/worker_not_share.aji @@ -0,0 +1,10 @@ +// expect: reject E4002 +// phase: 6 +// spec: docs/spec/15-source-language.md §18; docs/spec/04-concurrency.md §35 +module test.static_functions +fn worker(value: ref>) -> u64 effects [] { return 42; } +fn run>) -> u64 effects []>(value: ref>) -> u64 effects [task.spawn, task.wait] { + scope s { let t = task.spawn(s, F, value); return task.join(move t); } +} +fn bad(value: ref>) -> u64 effects [task.spawn, task.wait] { return run::(value); } +fn main() -> u64 effects [] { return 42; } diff --git a/tests/conformance/source/static_functions/wrong_arity.aji b/tests/conformance/source/static_functions/wrong_arity.aji new file mode 100644 index 0000000..0657b59 --- /dev/null +++ b/tests/conformance/source/static_functions/wrong_arity.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected() -> u64 effects [] { return 42; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/static_functions/wrong_borrow.aji b/tests/conformance/source/static_functions/wrong_borrow.aji new file mode 100644 index 0000000..87a6631 --- /dev/null +++ b/tests/conformance/source/static_functions/wrong_borrow.aji @@ -0,0 +1,8 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +struct Key { id: u64 } +fn selected(key: mut) -> u64 effects [] { return key.id; } +fn run) -> u64 effects []>(key: ref) -> u64 effects [] { return F(key); } +fn main() -> u64 effects [] { let key = Key { id: 42 }; return run::(ref key); } diff --git a/tests/conformance/source/static_functions/wrong_param.aji b/tests/conformance/source/static_functions/wrong_param.aji new file mode 100644 index 0000000..7093f01 --- /dev/null +++ b/tests/conformance/source/static_functions/wrong_param.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected(value: u32) -> u64 effects [] { return value as u64; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/static_functions/wrong_return.aji b/tests/conformance/source/static_functions/wrong_return.aji new file mode 100644 index 0000000..b6f0fb2 --- /dev/null +++ b/tests/conformance/source/static_functions/wrong_return.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §18 +module test.static_functions +fn selected(value: u64) -> u32 effects [] { return 42; } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn main() -> u64 effects [] { return apply::(42u64); } diff --git a/tests/conformance/source/std/air_equivalence.aji b/tests/conformance/source/std/air_equivalence.aji new file mode 100644 index 0000000..4c73288 --- /dev/null +++ b/tests/conformance/source/std/air_equivalence.aji @@ -0,0 +1,11 @@ +// expect: run +// result: 7 +// equivalent: std/minimum.air +// phase: 6 +// spec: docs/spec/16-standard-library.md +module test.minimum +import std.math; + +fn main() -> u64 +effects [] +{ return std.math.min_u64(7, 11); } diff --git a/tests/conformance/source/std/borrow_conflict.aji b/tests/conformance/source/std/borrow_conflict.aji new file mode 100644 index 0000000..429d69a --- /dev/null +++ b/tests/conformance/source/std/borrow_conflict.aji @@ -0,0 +1,9 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ var b: [u8; 2] = zero; ref saved = b; std.bytes.fill(mut b, 1); return 0; } diff --git a/tests/conformance/source/std/bounded_arithmetic_equivalence.aji b/tests/conformance/source/std/bounded_arithmetic_equivalence.aji new file mode 100644 index 0000000..618704c --- /dev/null +++ b/tests/conformance/source/std/bounded_arithmetic_equivalence.aji @@ -0,0 +1,11 @@ +// expect: run +// result: {"variant":"overflow","payload":[]} +// equivalent: std/bounded_arithmetic.air +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1 +module test.bounded_arithmetic +import std.math; + +fn main() -> std.math.U64Result +effects [] +{ return std.math.checked_add_u64(18446744073709551615, 1); } diff --git a/tests/conformance/source/std/bounded_copy.aji b/tests/conformance/source/std/bounded_copy.aji new file mode 100644 index 0000000..22f2131 --- /dev/null +++ b/tests/conformance/source/std/bounded_copy.aji @@ -0,0 +1,44 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn expect_copy(result: std.bytes.WriteResult, success: bool) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => { assert(success); } + std.bytes.WriteResult::short_output => { assert(not success); } + } +} +fn main() -> u8 +effects [] +{ + // Every source/output length through eight, including all empty combinations. + var src: [u8; 8] = zero; + for i in 0..src.len { src[i] = (i * 31 + 7) as! u8; } + for count in 0usize..9usize { + for capacity in 0usize..9usize { + var dst: [u8; 10] = [165; 10]; + expect_copy(std.bytes.copy(mut dst[1..1 + capacity], ref src[0..count]), capacity >= count); + for i in 0..dst.len { + if capacity >= count and i >= 1 and i < 1 + count { + assert(dst[i] == src[i - 1]); + } else { assert(dst[i] == 165); } + } + for i in 0..src.len { assert(src[i] == (i * 31 + 7) as! u8); } + } + } + // Same allocation is allowed through proven disjoint split borrows. + var buf: [u8; 8] = zero; + for i in 0..4usize { buf[i] = i as! u8 + 1; } + { + mut all = buf; + let (left, right) = all.split_at(4); + expect_copy(std.bytes.copy(mut right, ref left), true); + } + assert(std.bytes.equal(ref buf, b"\x01\x02\x03\x04\x01\x02\x03\x04")); + return 0; +} diff --git a/tests/conformance/source/std/bounded_copy_alias.aji b/tests/conformance/source/std/bounded_copy_alias.aji new file mode 100644 index 0000000..0c44e3f --- /dev/null +++ b/tests/conformance/source/std/bounded_copy_alias.aji @@ -0,0 +1,9 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn main() -> u8 +effects [] +{ var buf: [u8; 4] = zero; let result = std.bytes.copy(mut buf, ref buf); return 0; } diff --git a/tests/conformance/source/std/bounded_copy_alias_short.aji b/tests/conformance/source/std/bounded_copy_alias_short.aji new file mode 100644 index 0000000..79bf552 --- /dev/null +++ b/tests/conformance/source/std/bounded_copy_alias_short.aji @@ -0,0 +1,9 @@ +// expect: reject E2101 E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn main() -> u8 +effects [] +{ var buf: [u8; 4] = zero; ref saved = buf; let result = std.bytes.copy(mut buf[0..0], ref saved); return 0; } diff --git a/tests/conformance/source/std/bounded_copy_equivalence.aji b/tests/conformance/source/std/bounded_copy_equivalence.aji new file mode 100644 index 0000000..fded9b9 --- /dev/null +++ b/tests/conformance/source/std/bounded_copy_equivalence.aji @@ -0,0 +1,23 @@ +// expect: run +// result: [5,5,5,165] +// equivalent: std/bounded_copy.air +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded_copy +import std.bytes; + +fn main() -> [u8; 4] +effects [] +{ + let src: [u8; 3] = [5; 3]; + var dst: [u8; 4] = [165; 4]; + match std.bytes.copy(mut dst[0..2], ref src) { + std.bytes.WriteResult::ok => { trap; } + std.bytes.WriteResult::short_output => { assert(dst[0] == 165); } + } + match std.bytes.copy(mut dst, ref src) { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { trap; } + } + return dst; +} diff --git a/tests/conformance/source/std/bounded_copy_immutable.aji b/tests/conformance/source/std/bounded_copy_immutable.aji new file mode 100644 index 0000000..6d9b890 --- /dev/null +++ b/tests/conformance/source/std/bounded_copy_immutable.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn main() -> u8 +effects [] +{ var buf: [u8; 4] = zero; let result = std.bytes.copy(ref buf, b"x"); return 0; } diff --git a/tests/conformance/source/std/bounded_example.aji b/tests/conformance/source/std/bounded_example.aji new file mode 100644 index 0000000..edf157b --- /dev/null +++ b/tests/conformance/source/std/bounded_example.aji @@ -0,0 +1,39 @@ +// expect: run +// result: 10 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1, §2.4 +module demo.bounded +import std.bytes; +import std.math; + +fn encode(dst: slice_mut, data: slice) -> usize +effects [] +{ + match std.math.checked_add_usize(data.len, 1) { + std.math.UsizeResult::ok(total) => { + if total > dst.len { return 0; } + match std.bytes.copy(mut dst, ref data) { + std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; } + std.bytes.WriteResult::short_output => { return 0; } + } + } + std.math.UsizeResult::overflow => { return 0; } + } +} + +fn main() -> usize +effects [] +{ + var buf: [u8; 16] = [165; 16]; + let size = encode(mut buf, b"key=value"); + assert(size == 10); + assert(buf[9] == 0 and buf[10] == 165); + match std.bytes.find_slice(ref buf[0..size - 1], b"=") { + std.bytes.FindResult::found(index) => { + assert(std.bytes.equal(ref buf[0..index], b"key")); + assert(std.bytes.equal(ref buf[index + 1..size - 1], b"value")); + } + std.bytes.FindResult::not_found => { trap; } + } + return size; +} diff --git a/tests/conformance/source/std/bounded_math.aji b/tests/conformance/source/std/bounded_math.aji new file mode 100644 index 0000000..13cbec9 --- /dev/null +++ b/tests/conformance/source/std/bounded_math.aji @@ -0,0 +1,360 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/09-runtime-and-abi.md §9 +// Numeric vectors use the interpreter's default air64 target. +module test.bounded_math +import std.math; + +fn check_u64(result: std.math.U64Result, success: bool, expected: u64) -> void +effects [] +{ + match result { + std.math.U64Result::ok(value) => { assert(success); assert(value == expected); } + std.math.U64Result::overflow => { assert(not success); } + } +} +fn check_usize(result: std.math.UsizeResult, success: bool, expected: usize) -> void +effects [] +{ + match result { + std.math.UsizeResult::ok(value) => { assert(success); assert(value == expected); } + std.math.UsizeResult::overflow => { assert(not success); } + } +} +fn fixture(a: u64, b: u64, add_ok: bool, add: u64, sub_ok: bool, sub: u64, mul_ok: bool, mul: u64) -> void +effects [] +{ + check_u64(std.math.checked_add_u64(a, b), add_ok, add); + check_u64(std.math.checked_sub_u64(a, b), sub_ok, sub); + check_u64(std.math.checked_mul_u64(a, b), mul_ok, mul); + check_usize(std.math.checked_add_usize(a as! usize, b as! usize), add_ok, add as! usize); + check_usize(std.math.checked_sub_usize(a as! usize, b as! usize), sub_ok, sub as! usize); + check_usize(std.math.checked_mul_usize(a as! usize, b as! usize), mul_ok, mul as! usize); +} +fn main() -> u8 +effects [] +{ + // Python arbitrary-precision arithmetic determines representability and values. + fixture(0, 0, true, 0, true, 0, true, 0); + fixture(0, 1, true, 1, false, 0, true, 0); + fixture(0, 2, true, 2, false, 0, true, 0); + fixture(0, 3, true, 3, false, 0, true, 0); + fixture(0, 255, true, 255, false, 0, true, 0); + fixture(0, 256, true, 256, false, 0, true, 0); + fixture(0, 65535, true, 65535, false, 0, true, 0); + fixture(0, 65536, true, 65536, false, 0, true, 0); + fixture(0, 4294967295, true, 4294967295, false, 0, true, 0); + fixture(0, 4294967296, true, 4294967296, false, 0, true, 0); + fixture(0, 4294967297, true, 4294967297, false, 0, true, 0); + fixture(0, 9223372036854775807, true, 9223372036854775807, false, 0, true, 0); + fixture(0, 9223372036854775808, true, 9223372036854775808, false, 0, true, 0); + fixture(0, 9223372036854775809, true, 9223372036854775809, false, 0, true, 0); + fixture(0, 18446744073709551614, true, 18446744073709551614, false, 0, true, 0); + fixture(0, 18446744073709551615, true, 18446744073709551615, false, 0, true, 0); + fixture(1, 0, true, 1, true, 1, true, 0); + fixture(1, 1, true, 2, true, 0, true, 1); + fixture(1, 2, true, 3, false, 0, true, 2); + fixture(1, 3, true, 4, false, 0, true, 3); + fixture(1, 255, true, 256, false, 0, true, 255); + fixture(1, 256, true, 257, false, 0, true, 256); + fixture(1, 65535, true, 65536, false, 0, true, 65535); + fixture(1, 65536, true, 65537, false, 0, true, 65536); + fixture(1, 4294967295, true, 4294967296, false, 0, true, 4294967295); + fixture(1, 4294967296, true, 4294967297, false, 0, true, 4294967296); + fixture(1, 4294967297, true, 4294967298, false, 0, true, 4294967297); + fixture(1, 9223372036854775807, true, 9223372036854775808, false, 0, true, 9223372036854775807); + fixture(1, 9223372036854775808, true, 9223372036854775809, false, 0, true, 9223372036854775808); + fixture(1, 9223372036854775809, true, 9223372036854775810, false, 0, true, 9223372036854775809); + fixture(1, 18446744073709551614, true, 18446744073709551615, false, 0, true, 18446744073709551614); + fixture(1, 18446744073709551615, false, 0, false, 0, true, 18446744073709551615); + fixture(2, 0, true, 2, true, 2, true, 0); + fixture(2, 1, true, 3, true, 1, true, 2); + fixture(2, 2, true, 4, true, 0, true, 4); + fixture(2, 3, true, 5, false, 0, true, 6); + fixture(2, 255, true, 257, false, 0, true, 510); + fixture(2, 256, true, 258, false, 0, true, 512); + fixture(2, 65535, true, 65537, false, 0, true, 131070); + fixture(2, 65536, true, 65538, false, 0, true, 131072); + fixture(2, 4294967295, true, 4294967297, false, 0, true, 8589934590); + fixture(2, 4294967296, true, 4294967298, false, 0, true, 8589934592); + fixture(2, 4294967297, true, 4294967299, false, 0, true, 8589934594); + fixture(2, 9223372036854775807, true, 9223372036854775809, false, 0, true, 18446744073709551614); + fixture(2, 9223372036854775808, true, 9223372036854775810, false, 0, false, 0); + fixture(2, 9223372036854775809, true, 9223372036854775811, false, 0, false, 0); + fixture(2, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(2, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(3, 0, true, 3, true, 3, true, 0); + fixture(3, 1, true, 4, true, 2, true, 3); + fixture(3, 2, true, 5, true, 1, true, 6); + fixture(3, 3, true, 6, true, 0, true, 9); + fixture(3, 255, true, 258, false, 0, true, 765); + fixture(3, 256, true, 259, false, 0, true, 768); + fixture(3, 65535, true, 65538, false, 0, true, 196605); + fixture(3, 65536, true, 65539, false, 0, true, 196608); + fixture(3, 4294967295, true, 4294967298, false, 0, true, 12884901885); + fixture(3, 4294967296, true, 4294967299, false, 0, true, 12884901888); + fixture(3, 4294967297, true, 4294967300, false, 0, true, 12884901891); + fixture(3, 9223372036854775807, true, 9223372036854775810, false, 0, false, 0); + fixture(3, 9223372036854775808, true, 9223372036854775811, false, 0, false, 0); + fixture(3, 9223372036854775809, true, 9223372036854775812, false, 0, false, 0); + fixture(3, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(3, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(255, 0, true, 255, true, 255, true, 0); + fixture(255, 1, true, 256, true, 254, true, 255); + fixture(255, 2, true, 257, true, 253, true, 510); + fixture(255, 3, true, 258, true, 252, true, 765); + fixture(255, 255, true, 510, true, 0, true, 65025); + fixture(255, 256, true, 511, false, 0, true, 65280); + fixture(255, 65535, true, 65790, false, 0, true, 16711425); + fixture(255, 65536, true, 65791, false, 0, true, 16711680); + fixture(255, 4294967295, true, 4294967550, false, 0, true, 1095216660225); + fixture(255, 4294967296, true, 4294967551, false, 0, true, 1095216660480); + fixture(255, 4294967297, true, 4294967552, false, 0, true, 1095216660735); + fixture(255, 9223372036854775807, true, 9223372036854776062, false, 0, false, 0); + fixture(255, 9223372036854775808, true, 9223372036854776063, false, 0, false, 0); + fixture(255, 9223372036854775809, true, 9223372036854776064, false, 0, false, 0); + fixture(255, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(255, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(256, 0, true, 256, true, 256, true, 0); + fixture(256, 1, true, 257, true, 255, true, 256); + fixture(256, 2, true, 258, true, 254, true, 512); + fixture(256, 3, true, 259, true, 253, true, 768); + fixture(256, 255, true, 511, true, 1, true, 65280); + fixture(256, 256, true, 512, true, 0, true, 65536); + fixture(256, 65535, true, 65791, false, 0, true, 16776960); + fixture(256, 65536, true, 65792, false, 0, true, 16777216); + fixture(256, 4294967295, true, 4294967551, false, 0, true, 1099511627520); + fixture(256, 4294967296, true, 4294967552, false, 0, true, 1099511627776); + fixture(256, 4294967297, true, 4294967553, false, 0, true, 1099511628032); + fixture(256, 9223372036854775807, true, 9223372036854776063, false, 0, false, 0); + fixture(256, 9223372036854775808, true, 9223372036854776064, false, 0, false, 0); + fixture(256, 9223372036854775809, true, 9223372036854776065, false, 0, false, 0); + fixture(256, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(256, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(65535, 0, true, 65535, true, 65535, true, 0); + fixture(65535, 1, true, 65536, true, 65534, true, 65535); + fixture(65535, 2, true, 65537, true, 65533, true, 131070); + fixture(65535, 3, true, 65538, true, 65532, true, 196605); + fixture(65535, 255, true, 65790, true, 65280, true, 16711425); + fixture(65535, 256, true, 65791, true, 65279, true, 16776960); + fixture(65535, 65535, true, 131070, true, 0, true, 4294836225); + fixture(65535, 65536, true, 131071, false, 0, true, 4294901760); + fixture(65535, 4294967295, true, 4295032830, false, 0, true, 281470681677825); + fixture(65535, 4294967296, true, 4295032831, false, 0, true, 281470681743360); + fixture(65535, 4294967297, true, 4295032832, false, 0, true, 281470681808895); + fixture(65535, 9223372036854775807, true, 9223372036854841342, false, 0, false, 0); + fixture(65535, 9223372036854775808, true, 9223372036854841343, false, 0, false, 0); + fixture(65535, 9223372036854775809, true, 9223372036854841344, false, 0, false, 0); + fixture(65535, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(65535, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(65536, 0, true, 65536, true, 65536, true, 0); + fixture(65536, 1, true, 65537, true, 65535, true, 65536); + fixture(65536, 2, true, 65538, true, 65534, true, 131072); + fixture(65536, 3, true, 65539, true, 65533, true, 196608); + fixture(65536, 255, true, 65791, true, 65281, true, 16711680); + fixture(65536, 256, true, 65792, true, 65280, true, 16777216); + fixture(65536, 65535, true, 131071, true, 1, true, 4294901760); + fixture(65536, 65536, true, 131072, true, 0, true, 4294967296); + fixture(65536, 4294967295, true, 4295032831, false, 0, true, 281474976645120); + fixture(65536, 4294967296, true, 4295032832, false, 0, true, 281474976710656); + fixture(65536, 4294967297, true, 4295032833, false, 0, true, 281474976776192); + fixture(65536, 9223372036854775807, true, 9223372036854841343, false, 0, false, 0); + fixture(65536, 9223372036854775808, true, 9223372036854841344, false, 0, false, 0); + fixture(65536, 9223372036854775809, true, 9223372036854841345, false, 0, false, 0); + fixture(65536, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(65536, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(4294967295, 0, true, 4294967295, true, 4294967295, true, 0); + fixture(4294967295, 1, true, 4294967296, true, 4294967294, true, 4294967295); + fixture(4294967295, 2, true, 4294967297, true, 4294967293, true, 8589934590); + fixture(4294967295, 3, true, 4294967298, true, 4294967292, true, 12884901885); + fixture(4294967295, 255, true, 4294967550, true, 4294967040, true, 1095216660225); + fixture(4294967295, 256, true, 4294967551, true, 4294967039, true, 1099511627520); + fixture(4294967295, 65535, true, 4295032830, true, 4294901760, true, 281470681677825); + fixture(4294967295, 65536, true, 4295032831, true, 4294901759, true, 281474976645120); + fixture(4294967295, 4294967295, true, 8589934590, true, 0, true, 18446744065119617025); + fixture(4294967295, 4294967296, true, 8589934591, false, 0, true, 18446744069414584320); + fixture(4294967295, 4294967297, true, 8589934592, false, 0, true, 18446744073709551615); + fixture(4294967295, 9223372036854775807, true, 9223372041149743102, false, 0, false, 0); + fixture(4294967295, 9223372036854775808, true, 9223372041149743103, false, 0, false, 0); + fixture(4294967295, 9223372036854775809, true, 9223372041149743104, false, 0, false, 0); + fixture(4294967295, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(4294967295, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(4294967296, 0, true, 4294967296, true, 4294967296, true, 0); + fixture(4294967296, 1, true, 4294967297, true, 4294967295, true, 4294967296); + fixture(4294967296, 2, true, 4294967298, true, 4294967294, true, 8589934592); + fixture(4294967296, 3, true, 4294967299, true, 4294967293, true, 12884901888); + fixture(4294967296, 255, true, 4294967551, true, 4294967041, true, 1095216660480); + fixture(4294967296, 256, true, 4294967552, true, 4294967040, true, 1099511627776); + fixture(4294967296, 65535, true, 4295032831, true, 4294901761, true, 281470681743360); + fixture(4294967296, 65536, true, 4295032832, true, 4294901760, true, 281474976710656); + fixture(4294967296, 4294967295, true, 8589934591, true, 1, true, 18446744069414584320); + fixture(4294967296, 4294967296, true, 8589934592, true, 0, false, 0); + fixture(4294967296, 4294967297, true, 8589934593, false, 0, false, 0); + fixture(4294967296, 9223372036854775807, true, 9223372041149743103, false, 0, false, 0); + fixture(4294967296, 9223372036854775808, true, 9223372041149743104, false, 0, false, 0); + fixture(4294967296, 9223372036854775809, true, 9223372041149743105, false, 0, false, 0); + fixture(4294967296, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(4294967296, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(4294967297, 0, true, 4294967297, true, 4294967297, true, 0); + fixture(4294967297, 1, true, 4294967298, true, 4294967296, true, 4294967297); + fixture(4294967297, 2, true, 4294967299, true, 4294967295, true, 8589934594); + fixture(4294967297, 3, true, 4294967300, true, 4294967294, true, 12884901891); + fixture(4294967297, 255, true, 4294967552, true, 4294967042, true, 1095216660735); + fixture(4294967297, 256, true, 4294967553, true, 4294967041, true, 1099511628032); + fixture(4294967297, 65535, true, 4295032832, true, 4294901762, true, 281470681808895); + fixture(4294967297, 65536, true, 4295032833, true, 4294901761, true, 281474976776192); + fixture(4294967297, 4294967295, true, 8589934592, true, 2, true, 18446744073709551615); + fixture(4294967297, 4294967296, true, 8589934593, true, 1, false, 0); + fixture(4294967297, 4294967297, true, 8589934594, true, 0, false, 0); + fixture(4294967297, 9223372036854775807, true, 9223372041149743104, false, 0, false, 0); + fixture(4294967297, 9223372036854775808, true, 9223372041149743105, false, 0, false, 0); + fixture(4294967297, 9223372036854775809, true, 9223372041149743106, false, 0, false, 0); + fixture(4294967297, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(4294967297, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(9223372036854775807, 0, true, 9223372036854775807, true, 9223372036854775807, true, 0); + fixture(9223372036854775807, 1, true, 9223372036854775808, true, 9223372036854775806, true, 9223372036854775807); + fixture(9223372036854775807, 2, true, 9223372036854775809, true, 9223372036854775805, true, 18446744073709551614); + fixture(9223372036854775807, 3, true, 9223372036854775810, true, 9223372036854775804, false, 0); + fixture(9223372036854775807, 255, true, 9223372036854776062, true, 9223372036854775552, false, 0); + fixture(9223372036854775807, 256, true, 9223372036854776063, true, 9223372036854775551, false, 0); + fixture(9223372036854775807, 65535, true, 9223372036854841342, true, 9223372036854710272, false, 0); + fixture(9223372036854775807, 65536, true, 9223372036854841343, true, 9223372036854710271, false, 0); + fixture(9223372036854775807, 4294967295, true, 9223372041149743102, true, 9223372032559808512, false, 0); + fixture(9223372036854775807, 4294967296, true, 9223372041149743103, true, 9223372032559808511, false, 0); + fixture(9223372036854775807, 4294967297, true, 9223372041149743104, true, 9223372032559808510, false, 0); + fixture(9223372036854775807, 9223372036854775807, true, 18446744073709551614, true, 0, false, 0); + fixture(9223372036854775807, 9223372036854775808, true, 18446744073709551615, false, 0, false, 0); + fixture(9223372036854775807, 9223372036854775809, false, 0, false, 0, false, 0); + fixture(9223372036854775807, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(9223372036854775807, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(9223372036854775808, 0, true, 9223372036854775808, true, 9223372036854775808, true, 0); + fixture(9223372036854775808, 1, true, 9223372036854775809, true, 9223372036854775807, true, 9223372036854775808); + fixture(9223372036854775808, 2, true, 9223372036854775810, true, 9223372036854775806, false, 0); + fixture(9223372036854775808, 3, true, 9223372036854775811, true, 9223372036854775805, false, 0); + fixture(9223372036854775808, 255, true, 9223372036854776063, true, 9223372036854775553, false, 0); + fixture(9223372036854775808, 256, true, 9223372036854776064, true, 9223372036854775552, false, 0); + fixture(9223372036854775808, 65535, true, 9223372036854841343, true, 9223372036854710273, false, 0); + fixture(9223372036854775808, 65536, true, 9223372036854841344, true, 9223372036854710272, false, 0); + fixture(9223372036854775808, 4294967295, true, 9223372041149743103, true, 9223372032559808513, false, 0); + fixture(9223372036854775808, 4294967296, true, 9223372041149743104, true, 9223372032559808512, false, 0); + fixture(9223372036854775808, 4294967297, true, 9223372041149743105, true, 9223372032559808511, false, 0); + fixture(9223372036854775808, 9223372036854775807, true, 18446744073709551615, true, 1, false, 0); + fixture(9223372036854775808, 9223372036854775808, false, 0, true, 0, false, 0); + fixture(9223372036854775808, 9223372036854775809, false, 0, false, 0, false, 0); + fixture(9223372036854775808, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(9223372036854775808, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(9223372036854775809, 0, true, 9223372036854775809, true, 9223372036854775809, true, 0); + fixture(9223372036854775809, 1, true, 9223372036854775810, true, 9223372036854775808, true, 9223372036854775809); + fixture(9223372036854775809, 2, true, 9223372036854775811, true, 9223372036854775807, false, 0); + fixture(9223372036854775809, 3, true, 9223372036854775812, true, 9223372036854775806, false, 0); + fixture(9223372036854775809, 255, true, 9223372036854776064, true, 9223372036854775554, false, 0); + fixture(9223372036854775809, 256, true, 9223372036854776065, true, 9223372036854775553, false, 0); + fixture(9223372036854775809, 65535, true, 9223372036854841344, true, 9223372036854710274, false, 0); + fixture(9223372036854775809, 65536, true, 9223372036854841345, true, 9223372036854710273, false, 0); + fixture(9223372036854775809, 4294967295, true, 9223372041149743104, true, 9223372032559808514, false, 0); + fixture(9223372036854775809, 4294967296, true, 9223372041149743105, true, 9223372032559808513, false, 0); + fixture(9223372036854775809, 4294967297, true, 9223372041149743106, true, 9223372032559808512, false, 0); + fixture(9223372036854775809, 9223372036854775807, false, 0, true, 2, false, 0); + fixture(9223372036854775809, 9223372036854775808, false, 0, true, 1, false, 0); + fixture(9223372036854775809, 9223372036854775809, false, 0, true, 0, false, 0); + fixture(9223372036854775809, 18446744073709551614, false, 0, false, 0, false, 0); + fixture(9223372036854775809, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(18446744073709551614, 0, true, 18446744073709551614, true, 18446744073709551614, true, 0); + fixture(18446744073709551614, 1, true, 18446744073709551615, true, 18446744073709551613, true, 18446744073709551614); + fixture(18446744073709551614, 2, false, 0, true, 18446744073709551612, false, 0); + fixture(18446744073709551614, 3, false, 0, true, 18446744073709551611, false, 0); + fixture(18446744073709551614, 255, false, 0, true, 18446744073709551359, false, 0); + fixture(18446744073709551614, 256, false, 0, true, 18446744073709551358, false, 0); + fixture(18446744073709551614, 65535, false, 0, true, 18446744073709486079, false, 0); + fixture(18446744073709551614, 65536, false, 0, true, 18446744073709486078, false, 0); + fixture(18446744073709551614, 4294967295, false, 0, true, 18446744069414584319, false, 0); + fixture(18446744073709551614, 4294967296, false, 0, true, 18446744069414584318, false, 0); + fixture(18446744073709551614, 4294967297, false, 0, true, 18446744069414584317, false, 0); + fixture(18446744073709551614, 9223372036854775807, false, 0, true, 9223372036854775807, false, 0); + fixture(18446744073709551614, 9223372036854775808, false, 0, true, 9223372036854775806, false, 0); + fixture(18446744073709551614, 9223372036854775809, false, 0, true, 9223372036854775805, false, 0); + fixture(18446744073709551614, 18446744073709551614, false, 0, true, 0, false, 0); + fixture(18446744073709551614, 18446744073709551615, false, 0, false, 0, false, 0); + fixture(18446744073709551615, 0, true, 18446744073709551615, true, 18446744073709551615, true, 0); + fixture(18446744073709551615, 1, false, 0, true, 18446744073709551614, true, 18446744073709551615); + fixture(18446744073709551615, 2, false, 0, true, 18446744073709551613, false, 0); + fixture(18446744073709551615, 3, false, 0, true, 18446744073709551612, false, 0); + fixture(18446744073709551615, 255, false, 0, true, 18446744073709551360, false, 0); + fixture(18446744073709551615, 256, false, 0, true, 18446744073709551359, false, 0); + fixture(18446744073709551615, 65535, false, 0, true, 18446744073709486080, false, 0); + fixture(18446744073709551615, 65536, false, 0, true, 18446744073709486079, false, 0); + fixture(18446744073709551615, 4294967295, false, 0, true, 18446744069414584320, false, 0); + fixture(18446744073709551615, 4294967296, false, 0, true, 18446744069414584319, false, 0); + fixture(18446744073709551615, 4294967297, false, 0, true, 18446744069414584318, false, 0); + fixture(18446744073709551615, 9223372036854775807, false, 0, true, 9223372036854775808, false, 0); + fixture(18446744073709551615, 9223372036854775808, false, 0, true, 9223372036854775807, false, 0); + fixture(18446744073709551615, 9223372036854775809, false, 0, true, 9223372036854775806, false, 0); + fixture(18446744073709551615, 18446744073709551614, false, 0, true, 1, false, 0); + fixture(18446744073709551615, 18446744073709551615, false, 0, true, 0, false, 0); + fixture(22826, 8367811077280, true, 8367811100106, false, 0, true, 191003655649993280); + fixture(51593471070231, 53279520, true, 51593524349751, true, 51593417790711, false, 0); + fixture(44221820468, 9167, true, 44221829635, true, 44221811301, true, 405381428230156); + fixture(7738, 681, true, 8419, true, 7057, true, 5269578); + fixture(1665, 5665, true, 7330, false, 0, true, 9432225); + fixture(535130129349569381, 74173, true, 535130129349643554, true, 535130129349495208, false, 0); + fixture(39484571, 14368932415, true, 14408416986, false, 0, true, 567351132134268965); + fixture(655837162, 0, true, 655837162, true, 655837162, true, 0); + fixture(24263945274549, 5922203636850238, true, 5946467582124787, false, 0, false, 0); + fixture(1358311, 1589, true, 1359900, true, 1356722, true, 2158356179); + fixture(576800471, 70102195884118449, true, 70102196460918920, false, 0, false, 0); + fixture(205, 59442931, true, 59443136, false, 0, true, 12185800855); + fixture(6713838, 10288843303, true, 10295557141, false, 0, true, 69077627143726914); + fixture(113309654, 56964999, true, 170274653, true, 56344655, true, 6454684326800346); + fixture(2710646336777, 1327432, true, 2710647664209, true, 2710645009345, true, 3598198688120566664); + fixture(102398190504438869, 33455376019343141, true, 135853566523782010, true, 68942814485095728, false, 0); + fixture(15110500053195, 1846226806251251761, true, 1846241916751304956, false, 0, false, 0); + fixture(92259697, 110072463, true, 202332160, false, 0, true, 10155252084423711); + fixture(9189325, 15633344, true, 24822669, false, 0, true, 143659878852800); + fixture(229887117848438, 4209657228195905, true, 4439544346044343, false, 0, false, 0); + fixture(707, 35394681, true, 35395388, false, 0, true, 25024039467); + fixture(366886542353037072, 521603756, true, 366886542874640828, true, 366886541831433316, false, 0); + fixture(3149543, 940, true, 3150483, true, 3148603, true, 2960570420); + fixture(22251316823, 9960569387575863, true, 9960591638892686, false, 0, false, 0); + fixture(44605, 1078529957565922052, true, 1078529957565966657, false, 0, false, 0); + fixture(63959489124825692, 1173018, true, 63959489125998710, true, 63959489123652674, false, 0); + fixture(22216483, 72615, true, 22289098, true, 22143868, true, 1613249913045); + fixture(4809, 377746108198, true, 377746113007, false, 0, true, 1816581034324182); + fixture(114572438714163, 1873997096453140, true, 1988569535167303, false, 0, false, 0); + fixture(767029847, 324, true, 767030171, true, 767029523, true, 248517670428); + fixture(4250932681200, 279793451149599326, true, 279797702082280526, false, 0, false, 0); + fixture(198016577350, 770073984820857066, true, 770074182837434416, false, 0, false, 0); + fixture(29908, 121, true, 30029, true, 29787, true, 3618868); + fixture(339685630, 27, true, 339685657, true, 339685603, true, 9171512010); + fixture(435343, 152150, true, 587493, true, 283193, true, 66237437450); + fixture(214819840135, 0, true, 214819840135, true, 214819840135, true, 0); + fixture(47387502183386252, 494501857556655, true, 47882004040942907, true, 46893000325829597, false, 0); + fixture(442452015457818960, 1031972, true, 442452015458850932, true, 442452015456786988, false, 0); + fixture(31118767, 7, true, 31118774, true, 31118760, true, 217831369); + fixture(664, 49681316821, true, 49681317485, false, 0, true, 32988394369144); + fixture(336104835056, 424, true, 336104835480, true, 336104834632, true, 142508450063744); + fixture(15647158001728818016, 538507692697, true, 15647158540236510713, true, 15647157463221125319, false, 0); + fixture(11501959764, 5636, true, 11501965400, true, 11501954128, true, 64825045229904); + fixture(247638850912878, 2552731, true, 247638853465609, true, 247638848360147, false, 0); + fixture(217, 24, true, 241, true, 193, true, 5208); + fixture(991798435, 57491197064698733, true, 57491198056497168, false, 0, false, 0); + fixture(13667425, 96, true, 13667521, true, 13667329, true, 1312072800); + fixture(1141625698, 1842638482103948, true, 1842639623729646, false, 0, false, 0); + fixture(675441552758543024, 1701504, true, 675441552760244528, true, 675441552756841520, false, 0); + fixture(4043227632, 3572158, true, 4046799790, true, 4039655474, true, 14443047931469856); + fixture(181, 21747, true, 21928, false, 0, true, 3936207); + fixture(347, 51961183391702751, true, 51961183391703098, false, 0, true, 18030530636920854597); + fixture(15897801183, 820998858494053947, true, 820998874391855130, false, 0, false, 0); + fixture(11102207627936, 3956352, true, 11102211584288, true, 11102203671584, false, 0); + fixture(7716, 34, true, 7750, true, 7682, true, 262344); + fixture(2525470172558571, 47635234075287, true, 2573105406633858, true, 2477834938483284, false, 0); + fixture(1041112819, 29, true, 1041112848, true, 1041112790, true, 30192271751); + fixture(43, 18445734596328899, true, 18445734596328942, false, 0, true, 793166587642142657); + fixture(4416413916661094, 3, true, 4416413916661097, true, 4416413916661091, true, 13249241749983282); + fixture(194105530, 6249, true, 194111779, true, 194099281, true, 1212965456970); + fixture(242378907314190932, 4527967589446891778, true, 4770346496761082710, false, 0, false, 0); + fixture(307260339, 674682, true, 307935021, true, 306585657, true, 207303020037198); + fixture(116240498161, 0, true, 116240498161, true, 116240498161, true, 0); + fixture(1292039328228149846, 131256129543, true, 1292039459484279389, true, 1292039196972020303, false, 0); + return 0; +} diff --git a/tests/conformance/source/std/bounded_math_incomplete.aji b/tests/conformance/source/std/bounded_math_incomplete.aji new file mode 100644 index 0000000..0370d0f --- /dev/null +++ b/tests/conformance/source/std/bounded_math_incomplete.aji @@ -0,0 +1,8 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1 +module test.bounded_math +import std.math; +fn main() -> std.math.U64Result +effects [] +{ match std.math.checked_add_u64(1, 2) { std.math.U64Result::ok(value) => { return std.math.U64Result::ok(value); } } } diff --git a/tests/conformance/source/std/bounded_math_missing_import.aji b/tests/conformance/source/std/bounded_math_missing_import.aji new file mode 100644 index 0000000..7cfdd18 --- /dev/null +++ b/tests/conformance/source/std/bounded_math_missing_import.aji @@ -0,0 +1,7 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1 +module test.bounded_math +fn main() -> u64 +effects [] +{ return std.math.checked_add_u64(1, 2); } diff --git a/tests/conformance/source/std/bounded_math_payload.aji b/tests/conformance/source/std/bounded_math_payload.aji new file mode 100644 index 0000000..260de02 --- /dev/null +++ b/tests/conformance/source/std/bounded_math_payload.aji @@ -0,0 +1,8 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1 +module test.bounded_math +import std.math; +fn main() -> std.math.U64Result +effects [] +{ return std.math.U64Result::ok(true); } diff --git a/tests/conformance/source/std/bounded_math_type.aji b/tests/conformance/source/std/bounded_math_type.aji new file mode 100644 index 0000000..5ad2606 --- /dev/null +++ b/tests/conformance/source/std/bounded_math_type.aji @@ -0,0 +1,8 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1 +module test.bounded_math +import std.math; +fn main() -> std.math.U64Result +effects [] +{ let a: u32 = 1; let result = std.math.checked_add_u64(a, 2); return std.math.U64Result::overflow; } diff --git a/tests/conformance/source/std/bounded_math_wrong_enum.aji b/tests/conformance/source/std/bounded_math_wrong_enum.aji new file mode 100644 index 0000000..c9348cc --- /dev/null +++ b/tests/conformance/source/std/bounded_math_wrong_enum.aji @@ -0,0 +1,8 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.1.1 +module test.bounded_math +import std.math; +fn main() -> std.math.U64Result +effects [] +{ return std.math.UsizeResult::ok(1); } diff --git a/tests/conformance/source/std/bounded_search.aji b/tests/conformance/source/std/bounded_search.aji new file mode 100644 index 0000000..0210bf2 --- /dev/null +++ b/tests/conformance/source/std/bounded_search.aji @@ -0,0 +1,449 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn check(data: slice, needle: slice, found: bool, index: usize) -> void +effects [] +{ + match std.bytes.find_slice(ref data, ref needle) { + std.bytes.FindResult::found(value) => { assert(found); assert(value == index); } + std.bytes.FindResult::not_found => { assert(not found); } + } +} +fn main() -> u8 +effects [] +{ + var empty: [u8; 1] = zero; + check(ref empty[0..0], ref empty[0..0], true, 0); + check(ref empty[0..0], b"x", false, 0); + check(b"abc", ref empty[0..0], true, 0); + check(b"\x00", b"\x00", true, 0); + check(b"\x00", b"\x01", false, 0); + check(b"\x00", b"\x00\x00", false, 0); + check(b"\x00", b"\x01\x00", false, 0); + check(b"\x00", b"\x00\x01", false, 0); + check(b"\x00", b"\x01\x01", false, 0); + check(b"\x00", b"\x00\x00\x00", false, 0); + check(b"\x00", b"\x01\x00\x00", false, 0); + check(b"\x00", b"\x00\x01\x00", false, 0); + check(b"\x00", b"\x01\x01\x00", false, 0); + check(b"\x00", b"\x00\x00\x01", false, 0); + check(b"\x00", b"\x01\x00\x01", false, 0); + check(b"\x00", b"\x00\x01\x01", false, 0); + check(b"\x00", b"\x01\x01\x01", false, 0); + check(b"\x01", b"\x00", false, 0); + check(b"\x01", b"\x01", true, 0); + check(b"\x01", b"\x00\x00", false, 0); + check(b"\x01", b"\x01\x00", false, 0); + check(b"\x01", b"\x00\x01", false, 0); + check(b"\x01", b"\x01\x01", false, 0); + check(b"\x01", b"\x00\x00\x00", false, 0); + check(b"\x01", b"\x01\x00\x00", false, 0); + check(b"\x01", b"\x00\x01\x00", false, 0); + check(b"\x01", b"\x01\x01\x00", false, 0); + check(b"\x01", b"\x00\x00\x01", false, 0); + check(b"\x01", b"\x01\x00\x01", false, 0); + check(b"\x01", b"\x00\x01\x01", false, 0); + check(b"\x01", b"\x01\x01\x01", false, 0); + check(b"\x00\x00", b"\x00", true, 0); + check(b"\x00\x00", b"\x01", false, 0); + check(b"\x00\x00", b"\x00\x00", true, 0); + check(b"\x00\x00", b"\x01\x00", false, 0); + check(b"\x00\x00", b"\x00\x01", false, 0); + check(b"\x00\x00", b"\x01\x01", false, 0); + check(b"\x00\x00", b"\x00\x00\x00", false, 0); + check(b"\x00\x00", b"\x01\x00\x00", false, 0); + check(b"\x00\x00", b"\x00\x01\x00", false, 0); + check(b"\x00\x00", b"\x01\x01\x00", false, 0); + check(b"\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x00", b"\x00", true, 1); + check(b"\x01\x00", b"\x01", true, 0); + check(b"\x01\x00", b"\x00\x00", false, 0); + check(b"\x01\x00", b"\x01\x00", true, 0); + check(b"\x01\x00", b"\x00\x01", false, 0); + check(b"\x01\x00", b"\x01\x01", false, 0); + check(b"\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x01\x00", b"\x00\x01\x00", false, 0); + check(b"\x01\x00", b"\x01\x01\x00", false, 0); + check(b"\x01\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x00", b"\x01\x00\x01", false, 0); + check(b"\x01\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x00", b"\x01\x01\x01", false, 0); + check(b"\x00\x01", b"\x00", true, 0); + check(b"\x00\x01", b"\x01", true, 1); + check(b"\x00\x01", b"\x00\x00", false, 0); + check(b"\x00\x01", b"\x01\x00", false, 0); + check(b"\x00\x01", b"\x00\x01", true, 0); + check(b"\x00\x01", b"\x01\x01", false, 0); + check(b"\x00\x01", b"\x00\x00\x00", false, 0); + check(b"\x00\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x01", b"\x00\x01\x00", false, 0); + check(b"\x00\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x01", b"\x00\x00\x01", false, 0); + check(b"\x00\x01", b"\x01\x00\x01", false, 0); + check(b"\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x01\x01", b"\x00", false, 0); + check(b"\x01\x01", b"\x01", true, 0); + check(b"\x01\x01", b"\x00\x00", false, 0); + check(b"\x01\x01", b"\x01\x00", false, 0); + check(b"\x01\x01", b"\x00\x01", false, 0); + check(b"\x01\x01", b"\x01\x01", true, 0); + check(b"\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x01\x01", b"\x00\x00\x01", false, 0); + check(b"\x01\x01", b"\x01\x00\x01", false, 0); + check(b"\x01\x01", b"\x00\x01\x01", false, 0); + check(b"\x01\x01", b"\x01\x01\x01", false, 0); + check(b"\x00\x00\x00", b"\x00", true, 0); + check(b"\x00\x00\x00", b"\x01", false, 0); + check(b"\x00\x00\x00", b"\x00\x00", true, 0); + check(b"\x00\x00\x00", b"\x01\x00", false, 0); + check(b"\x00\x00\x00", b"\x00\x01", false, 0); + check(b"\x00\x00\x00", b"\x01\x01", false, 0); + check(b"\x00\x00\x00", b"\x00\x00\x00", true, 0); + check(b"\x00\x00\x00", b"\x01\x00\x00", false, 0); + check(b"\x00\x00\x00", b"\x00\x01\x00", false, 0); + check(b"\x00\x00\x00", b"\x01\x01\x00", false, 0); + check(b"\x00\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x00\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x00\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x00\x00", b"\x00", true, 1); + check(b"\x01\x00\x00", b"\x01", true, 0); + check(b"\x01\x00\x00", b"\x00\x00", true, 1); + check(b"\x01\x00\x00", b"\x01\x00", true, 0); + check(b"\x01\x00\x00", b"\x00\x01", false, 0); + check(b"\x01\x00\x00", b"\x01\x01", false, 0); + check(b"\x01\x00\x00", b"\x00\x00\x00", false, 0); + check(b"\x01\x00\x00", b"\x01\x00\x00", true, 0); + check(b"\x01\x00\x00", b"\x00\x01\x00", false, 0); + check(b"\x01\x00\x00", b"\x01\x01\x00", false, 0); + check(b"\x01\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x01\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x00\x01\x00", b"\x00", true, 0); + check(b"\x00\x01\x00", b"\x01", true, 1); + check(b"\x00\x01\x00", b"\x00\x00", false, 0); + check(b"\x00\x01\x00", b"\x01\x00", true, 1); + check(b"\x00\x01\x00", b"\x00\x01", true, 0); + check(b"\x00\x01\x00", b"\x01\x01", false, 0); + check(b"\x00\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x00\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x00\x01\x00", b"\x00\x01\x00", true, 0); + check(b"\x00\x01\x00", b"\x01\x01\x00", false, 0); + check(b"\x00\x01\x00", b"\x00\x00\x01", false, 0); + check(b"\x00\x01\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x01\x00", b"\x00\x01\x01", false, 0); + check(b"\x00\x01\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x01\x00", b"\x00", true, 2); + check(b"\x01\x01\x00", b"\x01", true, 0); + check(b"\x01\x01\x00", b"\x00\x00", false, 0); + check(b"\x01\x01\x00", b"\x01\x00", true, 1); + check(b"\x01\x01\x00", b"\x00\x01", false, 0); + check(b"\x01\x01\x00", b"\x01\x01", true, 0); + check(b"\x01\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x01\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x01\x01\x00", b"\x00\x01\x00", false, 0); + check(b"\x01\x01\x00", b"\x01\x01\x00", true, 0); + check(b"\x01\x01\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x01\x00", b"\x01\x00\x01", false, 0); + check(b"\x01\x01\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x01\x00", b"\x01\x01\x01", false, 0); + check(b"\x00\x00\x01", b"\x00", true, 0); + check(b"\x00\x00\x01", b"\x01", true, 2); + check(b"\x00\x00\x01", b"\x00\x00", true, 0); + check(b"\x00\x00\x01", b"\x01\x00", false, 0); + check(b"\x00\x00\x01", b"\x00\x01", true, 1); + check(b"\x00\x00\x01", b"\x01\x01", false, 0); + check(b"\x00\x00\x01", b"\x00\x00\x00", false, 0); + check(b"\x00\x00\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x00\x01", b"\x00\x01\x00", false, 0); + check(b"\x00\x00\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x00\x01", b"\x00\x00\x01", true, 0); + check(b"\x00\x00\x01", b"\x01\x00\x01", false, 0); + check(b"\x00\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x00\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x01\x00\x01", b"\x00", true, 1); + check(b"\x01\x00\x01", b"\x01", true, 0); + check(b"\x01\x00\x01", b"\x00\x00", false, 0); + check(b"\x01\x00\x01", b"\x01\x00", true, 0); + check(b"\x01\x00\x01", b"\x00\x01", true, 1); + check(b"\x01\x00\x01", b"\x01\x01", false, 0); + check(b"\x01\x00\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x00\x01", b"\x01\x00\x00", false, 0); + check(b"\x01\x00\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x00\x01", b"\x01\x01\x00", false, 0); + check(b"\x01\x00\x01", b"\x00\x00\x01", false, 0); + check(b"\x01\x00\x01", b"\x01\x00\x01", true, 0); + check(b"\x01\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x01\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x00\x01\x01", b"\x00", true, 0); + check(b"\x00\x01\x01", b"\x01", true, 1); + check(b"\x00\x01\x01", b"\x00\x00", false, 0); + check(b"\x00\x01\x01", b"\x01\x00", false, 0); + check(b"\x00\x01\x01", b"\x00\x01", true, 0); + check(b"\x00\x01\x01", b"\x01\x01", true, 1); + check(b"\x00\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x00\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x00\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x01\x01", b"\x00\x00\x01", false, 0); + check(b"\x00\x01\x01", b"\x01\x00\x01", false, 0); + check(b"\x00\x01\x01", b"\x00\x01\x01", true, 0); + check(b"\x00\x01\x01", b"\x01\x01\x01", false, 0); + check(b"\x01\x01\x01", b"\x00", false, 0); + check(b"\x01\x01\x01", b"\x01", true, 0); + check(b"\x01\x01\x01", b"\x00\x00", false, 0); + check(b"\x01\x01\x01", b"\x01\x00", false, 0); + check(b"\x01\x01\x01", b"\x00\x01", false, 0); + check(b"\x01\x01\x01", b"\x01\x01", true, 0); + check(b"\x01\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x01\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x01\x01\x01", b"\x00\x00\x01", false, 0); + check(b"\x01\x01\x01", b"\x01\x00\x01", false, 0); + check(b"\x01\x01\x01", b"\x00\x01\x01", false, 0); + check(b"\x01\x01\x01", b"\x01\x01\x01", true, 0); + check(b"\x00\x00\x00\x00", b"\x00", true, 0); + check(b"\x00\x00\x00\x00", b"\x01", false, 0); + check(b"\x00\x00\x00\x00", b"\x00\x00", true, 0); + check(b"\x00\x00\x00\x00", b"\x01\x00", false, 0); + check(b"\x00\x00\x00\x00", b"\x00\x01", false, 0); + check(b"\x00\x00\x00\x00", b"\x01\x01", false, 0); + check(b"\x00\x00\x00\x00", b"\x00\x00\x00", true, 0); + check(b"\x00\x00\x00\x00", b"\x01\x00\x00", false, 0); + check(b"\x00\x00\x00\x00", b"\x00\x01\x00", false, 0); + check(b"\x00\x00\x00\x00", b"\x01\x01\x00", false, 0); + check(b"\x00\x00\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x00\x00\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x00\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x00\x00\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x00\x00\x00", b"\x00", true, 1); + check(b"\x01\x00\x00\x00", b"\x01", true, 0); + check(b"\x01\x00\x00\x00", b"\x00\x00", true, 1); + check(b"\x01\x00\x00\x00", b"\x01\x00", true, 0); + check(b"\x01\x00\x00\x00", b"\x00\x01", false, 0); + check(b"\x01\x00\x00\x00", b"\x01\x01", false, 0); + check(b"\x01\x00\x00\x00", b"\x00\x00\x00", true, 1); + check(b"\x01\x00\x00\x00", b"\x01\x00\x00", true, 0); + check(b"\x01\x00\x00\x00", b"\x00\x01\x00", false, 0); + check(b"\x01\x00\x00\x00", b"\x01\x01\x00", false, 0); + check(b"\x01\x00\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x00\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x01\x00\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x00\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x00\x01\x00\x00", b"\x00", true, 0); + check(b"\x00\x01\x00\x00", b"\x01", true, 1); + check(b"\x00\x01\x00\x00", b"\x00\x00", true, 2); + check(b"\x00\x01\x00\x00", b"\x01\x00", true, 1); + check(b"\x00\x01\x00\x00", b"\x00\x01", true, 0); + check(b"\x00\x01\x00\x00", b"\x01\x01", false, 0); + check(b"\x00\x01\x00\x00", b"\x00\x00\x00", false, 0); + check(b"\x00\x01\x00\x00", b"\x01\x00\x00", true, 1); + check(b"\x00\x01\x00\x00", b"\x00\x01\x00", true, 0); + check(b"\x00\x01\x00\x00", b"\x01\x01\x00", false, 0); + check(b"\x00\x01\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x00\x01\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x01\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x00\x01\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x01\x00\x00", b"\x00", true, 2); + check(b"\x01\x01\x00\x00", b"\x01", true, 0); + check(b"\x01\x01\x00\x00", b"\x00\x00", true, 2); + check(b"\x01\x01\x00\x00", b"\x01\x00", true, 1); + check(b"\x01\x01\x00\x00", b"\x00\x01", false, 0); + check(b"\x01\x01\x00\x00", b"\x01\x01", true, 0); + check(b"\x01\x01\x00\x00", b"\x00\x00\x00", false, 0); + check(b"\x01\x01\x00\x00", b"\x01\x00\x00", true, 1); + check(b"\x01\x01\x00\x00", b"\x00\x01\x00", false, 0); + check(b"\x01\x01\x00\x00", b"\x01\x01\x00", true, 0); + check(b"\x01\x01\x00\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x01\x00\x00", b"\x01\x00\x01", false, 0); + check(b"\x01\x01\x00\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x01\x00\x00", b"\x01\x01\x01", false, 0); + check(b"\x00\x00\x01\x00", b"\x00", true, 0); + check(b"\x00\x00\x01\x00", b"\x01", true, 2); + check(b"\x00\x00\x01\x00", b"\x00\x00", true, 0); + check(b"\x00\x00\x01\x00", b"\x01\x00", true, 2); + check(b"\x00\x00\x01\x00", b"\x00\x01", true, 1); + check(b"\x00\x00\x01\x00", b"\x01\x01", false, 0); + check(b"\x00\x00\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x00\x00\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x00\x00\x01\x00", b"\x00\x01\x00", true, 1); + check(b"\x00\x00\x01\x00", b"\x01\x01\x00", false, 0); + check(b"\x00\x00\x01\x00", b"\x00\x00\x01", true, 0); + check(b"\x00\x00\x01\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x00\x01\x00", b"\x00\x01\x01", false, 0); + check(b"\x00\x00\x01\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x00\x01\x00", b"\x00", true, 1); + check(b"\x01\x00\x01\x00", b"\x01", true, 0); + check(b"\x01\x00\x01\x00", b"\x00\x00", false, 0); + check(b"\x01\x00\x01\x00", b"\x01\x00", true, 0); + check(b"\x01\x00\x01\x00", b"\x00\x01", true, 1); + check(b"\x01\x00\x01\x00", b"\x01\x01", false, 0); + check(b"\x01\x00\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x01\x00\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x01\x00\x01\x00", b"\x00\x01\x00", true, 1); + check(b"\x01\x00\x01\x00", b"\x01\x01\x00", false, 0); + check(b"\x01\x00\x01\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x00\x01\x00", b"\x01\x00\x01", true, 0); + check(b"\x01\x00\x01\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x00\x01\x00", b"\x01\x01\x01", false, 0); + check(b"\x00\x01\x01\x00", b"\x00", true, 0); + check(b"\x00\x01\x01\x00", b"\x01", true, 1); + check(b"\x00\x01\x01\x00", b"\x00\x00", false, 0); + check(b"\x00\x01\x01\x00", b"\x01\x00", true, 2); + check(b"\x00\x01\x01\x00", b"\x00\x01", true, 0); + check(b"\x00\x01\x01\x00", b"\x01\x01", true, 1); + check(b"\x00\x01\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x00\x01\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x00\x01\x01\x00", b"\x00\x01\x00", false, 0); + check(b"\x00\x01\x01\x00", b"\x01\x01\x00", true, 1); + check(b"\x00\x01\x01\x00", b"\x00\x00\x01", false, 0); + check(b"\x00\x01\x01\x00", b"\x01\x00\x01", false, 0); + check(b"\x00\x01\x01\x00", b"\x00\x01\x01", true, 0); + check(b"\x00\x01\x01\x00", b"\x01\x01\x01", false, 0); + check(b"\x01\x01\x01\x00", b"\x00", true, 3); + check(b"\x01\x01\x01\x00", b"\x01", true, 0); + check(b"\x01\x01\x01\x00", b"\x00\x00", false, 0); + check(b"\x01\x01\x01\x00", b"\x01\x00", true, 2); + check(b"\x01\x01\x01\x00", b"\x00\x01", false, 0); + check(b"\x01\x01\x01\x00", b"\x01\x01", true, 0); + check(b"\x01\x01\x01\x00", b"\x00\x00\x00", false, 0); + check(b"\x01\x01\x01\x00", b"\x01\x00\x00", false, 0); + check(b"\x01\x01\x01\x00", b"\x00\x01\x00", false, 0); + check(b"\x01\x01\x01\x00", b"\x01\x01\x00", true, 1); + check(b"\x01\x01\x01\x00", b"\x00\x00\x01", false, 0); + check(b"\x01\x01\x01\x00", b"\x01\x00\x01", false, 0); + check(b"\x01\x01\x01\x00", b"\x00\x01\x01", false, 0); + check(b"\x01\x01\x01\x00", b"\x01\x01\x01", true, 0); + check(b"\x00\x00\x00\x01", b"\x00", true, 0); + check(b"\x00\x00\x00\x01", b"\x01", true, 3); + check(b"\x00\x00\x00\x01", b"\x00\x00", true, 0); + check(b"\x00\x00\x00\x01", b"\x01\x00", false, 0); + check(b"\x00\x00\x00\x01", b"\x00\x01", true, 2); + check(b"\x00\x00\x00\x01", b"\x01\x01", false, 0); + check(b"\x00\x00\x00\x01", b"\x00\x00\x00", true, 0); + check(b"\x00\x00\x00\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x00\x00\x01", b"\x00\x01\x00", false, 0); + check(b"\x00\x00\x00\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x00\x00\x01", b"\x00\x00\x01", true, 1); + check(b"\x00\x00\x00\x01", b"\x01\x00\x01", false, 0); + check(b"\x00\x00\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x00\x00\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x01\x00\x00\x01", b"\x00", true, 1); + check(b"\x01\x00\x00\x01", b"\x01", true, 0); + check(b"\x01\x00\x00\x01", b"\x00\x00", true, 1); + check(b"\x01\x00\x00\x01", b"\x01\x00", true, 0); + check(b"\x01\x00\x00\x01", b"\x00\x01", true, 2); + check(b"\x01\x00\x00\x01", b"\x01\x01", false, 0); + check(b"\x01\x00\x00\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x00\x00\x01", b"\x01\x00\x00", true, 0); + check(b"\x01\x00\x00\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x00\x00\x01", b"\x01\x01\x00", false, 0); + check(b"\x01\x00\x00\x01", b"\x00\x00\x01", true, 1); + check(b"\x01\x00\x00\x01", b"\x01\x00\x01", false, 0); + check(b"\x01\x00\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x01\x00\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x00\x01\x00\x01", b"\x00", true, 0); + check(b"\x00\x01\x00\x01", b"\x01", true, 1); + check(b"\x00\x01\x00\x01", b"\x00\x00", false, 0); + check(b"\x00\x01\x00\x01", b"\x01\x00", true, 1); + check(b"\x00\x01\x00\x01", b"\x00\x01", true, 0); + check(b"\x00\x01\x00\x01", b"\x01\x01", false, 0); + check(b"\x00\x01\x00\x01", b"\x00\x00\x00", false, 0); + check(b"\x00\x01\x00\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x01\x00\x01", b"\x00\x01\x00", true, 0); + check(b"\x00\x01\x00\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x01\x00\x01", b"\x00\x00\x01", false, 0); + check(b"\x00\x01\x00\x01", b"\x01\x00\x01", true, 1); + check(b"\x00\x01\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x00\x01\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x01\x01\x00\x01", b"\x00", true, 2); + check(b"\x01\x01\x00\x01", b"\x01", true, 0); + check(b"\x01\x01\x00\x01", b"\x00\x00", false, 0); + check(b"\x01\x01\x00\x01", b"\x01\x00", true, 1); + check(b"\x01\x01\x00\x01", b"\x00\x01", true, 2); + check(b"\x01\x01\x00\x01", b"\x01\x01", true, 0); + check(b"\x01\x01\x00\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x01\x00\x01", b"\x01\x00\x00", false, 0); + check(b"\x01\x01\x00\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x01\x00\x01", b"\x01\x01\x00", true, 0); + check(b"\x01\x01\x00\x01", b"\x00\x00\x01", false, 0); + check(b"\x01\x01\x00\x01", b"\x01\x00\x01", true, 1); + check(b"\x01\x01\x00\x01", b"\x00\x01\x01", false, 0); + check(b"\x01\x01\x00\x01", b"\x01\x01\x01", false, 0); + check(b"\x00\x00\x01\x01", b"\x00", true, 0); + check(b"\x00\x00\x01\x01", b"\x01", true, 2); + check(b"\x00\x00\x01\x01", b"\x00\x00", true, 0); + check(b"\x00\x00\x01\x01", b"\x01\x00", false, 0); + check(b"\x00\x00\x01\x01", b"\x00\x01", true, 1); + check(b"\x00\x00\x01\x01", b"\x01\x01", true, 2); + check(b"\x00\x00\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x00\x00\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x00\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x00\x00\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x00\x01\x01", b"\x00\x00\x01", true, 0); + check(b"\x00\x00\x01\x01", b"\x01\x00\x01", false, 0); + check(b"\x00\x00\x01\x01", b"\x00\x01\x01", true, 1); + check(b"\x00\x00\x01\x01", b"\x01\x01\x01", false, 0); + check(b"\x01\x00\x01\x01", b"\x00", true, 1); + check(b"\x01\x00\x01\x01", b"\x01", true, 0); + check(b"\x01\x00\x01\x01", b"\x00\x00", false, 0); + check(b"\x01\x00\x01\x01", b"\x01\x00", true, 0); + check(b"\x01\x00\x01\x01", b"\x00\x01", true, 1); + check(b"\x01\x00\x01\x01", b"\x01\x01", true, 2); + check(b"\x01\x00\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x00\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x01\x00\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x00\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x01\x00\x01\x01", b"\x00\x00\x01", false, 0); + check(b"\x01\x00\x01\x01", b"\x01\x00\x01", true, 0); + check(b"\x01\x00\x01\x01", b"\x00\x01\x01", true, 1); + check(b"\x01\x00\x01\x01", b"\x01\x01\x01", false, 0); + check(b"\x00\x01\x01\x01", b"\x00", true, 0); + check(b"\x00\x01\x01\x01", b"\x01", true, 1); + check(b"\x00\x01\x01\x01", b"\x00\x00", false, 0); + check(b"\x00\x01\x01\x01", b"\x01\x00", false, 0); + check(b"\x00\x01\x01\x01", b"\x00\x01", true, 0); + check(b"\x00\x01\x01\x01", b"\x01\x01", true, 1); + check(b"\x00\x01\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x00\x01\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x00\x01\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x00\x01\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x00\x01\x01\x01", b"\x00\x00\x01", false, 0); + check(b"\x00\x01\x01\x01", b"\x01\x00\x01", false, 0); + check(b"\x00\x01\x01\x01", b"\x00\x01\x01", true, 0); + check(b"\x00\x01\x01\x01", b"\x01\x01\x01", true, 1); + check(b"\x01\x01\x01\x01", b"\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x01", true, 0); + check(b"\x01\x01\x01\x01", b"\x00\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x01\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x00\x01", false, 0); + check(b"\x01\x01\x01\x01", b"\x01\x01", true, 0); + check(b"\x01\x01\x01\x01", b"\x00\x00\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x01\x00\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x00\x01\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x01\x01\x00", false, 0); + check(b"\x01\x01\x01\x01", b"\x00\x00\x01", false, 0); + check(b"\x01\x01\x01\x01", b"\x01\x00\x01", false, 0); + check(b"\x01\x01\x01\x01", b"\x00\x01\x01", false, 0); + check(b"\x01\x01\x01\x01", b"\x01\x01\x01", true, 0); + check(b"\x78\x78\x61\x62\x63\x61\x62\x63", b"\x61\x62\x63", true, 2); + check(b"\x61\x61\x61\x61\x61\x62", b"\x61\x61\x61\x62", true, 2); + check(b"\x61\x62\x63", b"\x61\x62\x63\x64", false, 0); + check(b"\xff\x00\x80\xff", b"\x80\xff", true, 2); + check(b"\x61\x62\x63", b"\x63", true, 2); + return 0; +} diff --git a/tests/conformance/source/std/bounded_search_incomplete.aji b/tests/conformance/source/std/bounded_search_incomplete.aji new file mode 100644 index 0000000..46fdd78 --- /dev/null +++ b/tests/conformance/source/std/bounded_search_incomplete.aji @@ -0,0 +1,9 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn main() -> usize +effects [] +{ match std.bytes.find_slice(b"abc", b"b") { std.bytes.FindResult::found(index) => { return index; } } } diff --git a/tests/conformance/source/std/bounded_search_missing_import.aji b/tests/conformance/source/std/bounded_search_missing_import.aji new file mode 100644 index 0000000..bf51f7a --- /dev/null +++ b/tests/conformance/source/std/bounded_search_missing_import.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded + +fn main() -> u8 +effects [] +{ let result = std.bytes.find_slice(b"a", b"a"); return 0; } diff --git a/tests/conformance/source/std/bounded_search_offset.aji b/tests/conformance/source/std/bounded_search_offset.aji new file mode 100644 index 0000000..b07706f --- /dev/null +++ b/tests/conformance/source/std/bounded_search_offset.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 2 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded_offset +import std.bytes; + +fn locate(data: slice) -> usize +effects [] +{ + match std.bytes.find_slice(ref data[2..data.len], b"ab") { + std.bytes.FindResult::found(index) => { return index; } + std.bytes.FindResult::not_found => { trap; } + } +} + +fn main() -> usize +effects [] +{ return locate(b"xxzzab"); } diff --git a/tests/conformance/source/std/bounded_search_payload.aji b/tests/conformance/source/std/bounded_search_payload.aji new file mode 100644 index 0000000..6da1ea6 --- /dev/null +++ b/tests/conformance/source/std/bounded_search_payload.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn main() -> std.bytes.FindResult +effects [] +{ return std.bytes.FindResult::found(true); } diff --git a/tests/conformance/source/std/bounded_search_wrong_type.aji b/tests/conformance/source/std/bounded_search_wrong_type.aji new file mode 100644 index 0000000..40df628 --- /dev/null +++ b/tests/conformance/source/std/bounded_search_wrong_type.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4 +module test.bounded +import std.bytes; + +fn main() -> u8 +effects [] +{ var words: [u16; 2] = zero; let result = std.bytes.find_slice(ref words, b"x"); return 0; } diff --git a/tests/conformance/source/std/bounded_split.aji b/tests/conformance/source/std/bounded_split.aji new file mode 100644 index 0000000..0812de5 --- /dev/null +++ b/tests/conformance/source/std/bounded_split.aji @@ -0,0 +1,34 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.4; docs/spec/15-source-language.md §6 +module test.bounded_split +import std.bytes; + +fn check(data: slice, separator: slice, expected_left: slice, expected_right: slice) -> void +effects [] +{ + match std.bytes.find_slice(ref data, ref separator) { + std.bytes.FindResult::found(index) => { + let (left, tail) = data.split_at(index); + ref right = tail[separator.len..tail.len]; + assert(std.bytes.equal(ref left, ref expected_left)); + assert(std.bytes.equal(ref right, ref expected_right)); + } + std.bytes.FindResult::not_found => { trap; } + } +} + +fn main() -> u8 +effects [] +{ + var storage: [u8; 1] = zero; + check(b"key=value", b"=", b"key", b"value"); + check(b"=value", b"=", ref storage[0..0], b"value"); + check(b"key=", b"=", b"key", ref storage[0..0]); + check(b"==", b"=", ref storage[0..0], b"="); + check(b"key::value::tail", b"::", b"key", b"value::tail"); + check(b"abc", ref storage[0..0], ref storage[0..0], b"abc"); + check(ref storage[0..0], ref storage[0..0], ref storage[0..0], ref storage[0..0]); + return 0; +} diff --git a/tests/conformance/source/std/bytes.aji b/tests/conformance/source/std/bytes.aji new file mode 100644 index 0000000..b155683 --- /dev/null +++ b/tests/conformance/source/std/bytes.aji @@ -0,0 +1,45 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ + var storage: [u8; 1] = zero; + ref empty = storage[0..0]; + assert(std.bytes.equal(ref empty, ref empty)); + assert(std.bytes.equal(b"a\0\xff", b"a\0\xff")); + assert(not std.bytes.equal(b"a", b"ab")); + assert(not std.bytes.equal(b"ab", b"ax")); + assert(std.bytes.compare(ref empty, ref empty) == 0); + assert(std.bytes.compare(ref empty, b"a") == -1); + assert(std.bytes.compare(b"a", ref empty) == 1); + assert(std.bytes.compare(b"ab", b"ab") == 0); + assert(std.bytes.compare(b"a", b"ab") == -1); + assert(std.bytes.compare(b"ab", b"a") == 1); + assert(std.bytes.compare(b"abc", b"abd") == -1); + assert(std.bytes.compare(b"abd", b"abc") == 1); + assert(std.bytes.compare(b"\x80", b"\x7f") == 1); + assert(std.bytes.compare(b"\0", b"\xff") == -1); + assert(std.bytes.find(ref empty, 0) == 0usize); + assert(std.bytes.find(b"aba", 97) == 0usize); + assert(std.bytes.find(b"abc", 99) == 2usize); + assert(std.bytes.find(b"abc", 100) == 3usize); + assert(std.bytes.find(b"a\0\xff", 0) == 1usize); + assert(std.bytes.starts_with(ref empty, ref empty)); + assert(std.bytes.ends_with(ref empty, ref empty)); + assert(std.bytes.starts_with(b"abc", ref empty)); + assert(std.bytes.ends_with(b"abc", ref empty)); + assert(std.bytes.starts_with(b"abc", b"abc")); + assert(std.bytes.ends_with(b"abc", b"abc")); + assert(std.bytes.starts_with(b"abc", b"ab")); + assert(std.bytes.ends_with(b"abc", b"bc")); + assert(not std.bytes.starts_with(b"a", b"ab")); + assert(not std.bytes.ends_with(b"a", b"ab")); + assert(not std.bytes.starts_with(b"abc", b"x")); + assert(not std.bytes.ends_with(b"abc", b"x")); + return 0; +} diff --git a/tests/conformance/source/std/clamp_invalid.aji b/tests/conformance/source/std/clamp_invalid.aji new file mode 100644 index 0000000..186f459 --- /dev/null +++ b/tests/conformance/source/std/clamp_invalid.aji @@ -0,0 +1,10 @@ +// expect: run +// trap: T0002 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.math; + +fn main() -> u64 +effects [] +{ return std.math.clamp_u64(5, 9, 4); } diff --git a/tests/conformance/source/std/duplicate_import.aji b/tests/conformance/source/std/duplicate_import.aji new file mode 100644 index 0000000..f351216 --- /dev/null +++ b/tests/conformance/source/std/duplicate_import.aji @@ -0,0 +1,10 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; +import std.bytes; + +fn main() -> u8 +effects [] +{ return 0; } diff --git a/tests/conformance/source/std/endian_air_equivalence.aji b/tests/conformance/source/std/endian_air_equivalence.aji new file mode 100644 index 0000000..308cd79 --- /dev/null +++ b/tests/conformance/source/std/endian_air_equivalence.aji @@ -0,0 +1,11 @@ +// expect: run +// result: {"variant":"ok","payload":[4660]} +// equivalent: std/endian_read.air +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> std.bytes.ReadU16 +effects [] +{ return std.bytes.read_u16_le(b"\x34\x12"); } diff --git a/tests/conformance/source/std/endian_alias.aji b/tests/conformance/source/std/endian_alias.aji new file mode 100644 index 0000000..e51ce3e --- /dev/null +++ b/tests/conformance/source/std/endian_alias.aji @@ -0,0 +1,9 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ var b: [u8; 2] = zero; ref saved = b; let r = std.bytes.write_u16_le(mut b, 1); return 0; } diff --git a/tests/conformance/source/std/endian_bare_outcome.aji b/tests/conformance/source/std/endian_bare_outcome.aji new file mode 100644 index 0000000..b5e5874 --- /dev/null +++ b/tests/conformance/source/std/endian_bare_outcome.aji @@ -0,0 +1,9 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ match std.bytes.read_u16_le(b"xx") { ok(v) => { return 0; } short_input => { return 1; } } } diff --git a/tests/conformance/source/std/endian_compound_type.aji b/tests/conformance/source/std/endian_compound_type.aji new file mode 100644 index 0000000..d679b4e --- /dev/null +++ b/tests/conformance/source/std/endian_compound_type.aji @@ -0,0 +1,25 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §13; docs/spec/16-standard-library.md §2.3 +module test.endian +import std.bytes; + +struct Packet { word: std.bytes.ReadU32 } + +fn read_first(words: slice) -> u32 +effects [] +{ + match words[0] { + std.bytes.ReadU32::ok(value) => { return value; } + std.bytes.ReadU32::short_input => { return 0; } + } +} + +fn main() -> u32 +effects [] +{ + let packet = Packet { word: std.bytes.ReadU32::ok(42) }; + let words: [std.bytes.ReadU32; 2] = [packet.word; 2]; + return read_first(ref words); +} diff --git a/tests/conformance/source/std/endian_match_duplicate.aji b/tests/conformance/source/std/endian_match_duplicate.aji new file mode 100644 index 0000000..a4729c2 --- /dev/null +++ b/tests/conformance/source/std/endian_match_duplicate.aji @@ -0,0 +1,9 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ match std.bytes.read_u16_le(b"xx") { std.bytes.ReadU16::ok(v) => { return 0; } std.bytes.ReadU16::ok(w) => { return 1; } std.bytes.ReadU16::short_input => { return 2; } } } diff --git a/tests/conformance/source/std/endian_match_incomplete.aji b/tests/conformance/source/std/endian_match_incomplete.aji new file mode 100644 index 0000000..b159ebd --- /dev/null +++ b/tests/conformance/source/std/endian_match_incomplete.aji @@ -0,0 +1,9 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ match std.bytes.read_u16_le(b"xx") { std.bytes.ReadU16::ok(v) => { return 0; } } } diff --git a/tests/conformance/source/std/endian_match_wildcard.aji b/tests/conformance/source/std/endian_match_wildcard.aji new file mode 100644 index 0000000..689c3a0 --- /dev/null +++ b/tests/conformance/source/std/endian_match_wildcard.aji @@ -0,0 +1,9 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ match std.bytes.read_u16_le(b"xx") { std.bytes.ReadU16::ok(v) => { return 0; } _ => { return 1; } } } diff --git a/tests/conformance/source/std/endian_missing_constructor_import.aji b/tests/conformance/source/std/endian_missing_constructor_import.aji new file mode 100644 index 0000000..baa43dc --- /dev/null +++ b/tests/conformance/source/std/endian_missing_constructor_import.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian + + +fn main() -> u8 +effects [] +{ let r = std.bytes.ReadU16::short_input; return 0; } diff --git a/tests/conformance/source/std/endian_missing_payload.aji b/tests/conformance/source/std/endian_missing_payload.aji new file mode 100644 index 0000000..cf9b29b --- /dev/null +++ b/tests/conformance/source/std/endian_missing_payload.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ let r = std.bytes.ReadU16::ok; return 0; } diff --git a/tests/conformance/source/std/endian_missing_type_import.aji b/tests/conformance/source/std/endian_missing_type_import.aji new file mode 100644 index 0000000..d2e74aa --- /dev/null +++ b/tests/conformance/source/std/endian_missing_type_import.aji @@ -0,0 +1,12 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian + + +fn take(r: std.bytes.ReadU16) -> void +effects [] +{} +fn main() -> u8 +effects [] +{ return 0; } diff --git a/tests/conformance/source/std/endian_payload_type.aji b/tests/conformance/source/std/endian_payload_type.aji new file mode 100644 index 0000000..9f025df --- /dev/null +++ b/tests/conformance/source/std/endian_payload_type.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ let r = std.bytes.ReadU16::ok(true); return 0; } diff --git a/tests/conformance/source/std/endian_result_is_not_integer.aji b/tests/conformance/source/std/endian_result_is_not_integer.aji new file mode 100644 index 0000000..8615e37 --- /dev/null +++ b/tests/conformance/source/std/endian_result_is_not_integer.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ let r: u16 = std.bytes.read_u16_le(b"xx"); return 0; } diff --git a/tests/conformance/source/std/endian_type_namespace.aji b/tests/conformance/source/std/endian_type_namespace.aji new file mode 100644 index 0000000..e612fac --- /dev/null +++ b/tests/conformance/source/std/endian_type_namespace.aji @@ -0,0 +1,30 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +enum ReadU16 { Local(u8) } +struct __aji_std_bytes_ReadU16 { marker: u8 } +fn __aji_std_bytes_ReadU16_1() -> u8 +effects [] +{ return 7; } + +fn relay(r: std.bytes.ReadU16) -> std.bytes.ReadU16 +effects [] +{ return r; } + +fn main() -> u8 +effects [] +{ + let std: u8 = 1; + let result: std.bytes.ReadU16 = relay(std.bytes.ReadU16::ok(0x1234)); + match result { + std.bytes.ReadU16::ok(value) => { assert(value == 0x1234); } + std.bytes.ReadU16::short_input => { trap; } + } + let local = ReadU16::Local(std); + match local { ReadU16::Local(value) => { assert(value == 1); } } + return __aji_std_bytes_ReadU16_1() - 7; +} diff --git a/tests/conformance/source/std/endian_u16.aji b/tests/conformance/source/std/endian_u16.aji new file mode 100644 index 0000000..fa2de22 --- /dev/null +++ b/tests/conformance/source/std/endian_u16.aji @@ -0,0 +1,114 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn expect_read(result: std.bytes.ReadU16, expected: u16) -> void +effects [] +{ + match result { + std.bytes.ReadU16::ok(value) => { assert(value == expected); } + std.bytes.ReadU16::short_input => { trap; } + } +} + +fn expect_short_read(result: std.bytes.ReadU16) -> void +effects [] +{ + match result { + std.bytes.ReadU16::ok(value) => { trap; } + std.bytes.ReadU16::short_input => {} + } +} + +fn expect_write(result: std.bytes.WriteResult) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { trap; } + } +} + +fn expect_short_write(result: std.bytes.WriteResult) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => { trap; } + std.bytes.WriteResult::short_output => {} + } +} + +fn fixture(value: u16, le: slice, be: slice) -> void +effects [] +{ + expect_read(std.bytes.read_u16_le(ref le), value); + expect_read(std.bytes.read_u16_be(ref be), value); + var buf: [u8; 10] = [165; 10]; + expect_write(std.bytes.write_u16_le(mut buf[1..3], value)); + assert(std.bytes.equal(ref buf[1..3], ref le)); + assert(buf[0] == 165); + for i in 3usize..buf.len { assert(buf[i] == 165); } + expect_read(std.bytes.read_u16_le(ref buf[1..10]), value); + expect_write(std.bytes.write_u16_be(mut buf[1..10], value)); + assert(std.bytes.equal(ref buf[1..3], ref be)); + assert(buf[0] == 165); + for i in 3usize..buf.len { assert(buf[i] == 165); } + expect_read(std.bytes.read_u16_be(ref buf[1..10]), value); +} + +fn main() -> u8 +effects [] +{ + // Every short length, including zero; error writes preserve the whole array. + var buf: [u8; 10] = [165; 10]; + for size in 0usize..2usize { + expect_short_read(std.bytes.read_u16_le(ref buf[1..1 + size])); + expect_short_read(std.bytes.read_u16_be(ref buf[1..1 + size])); + expect_short_write(std.bytes.write_u16_le(mut buf[1..1 + size], 65535)); + expect_short_write(std.bytes.write_u16_be(mut buf[1..1 + size], 65535)); + for i in 0..buf.len { assert(buf[i] == 165); } + } + // Expected bytes are fixed by Python int.to_bytes, independently of std's algorithm. + fixture(0, b"\x00\x00", b"\x00\x00"); + fixture(1, b"\x01\x00", b"\x00\x01"); + fixture(65535, b"\xff\xff", b"\xff\xff"); + fixture(32768, b"\x00\x80", b"\x80\x00"); + fixture(21845, b"\x55\x55", b"\x55\x55"); + fixture(258, b"\x02\x01", b"\x01\x02"); + fixture(65197, b"\xad\xfe", b"\xfe\xad"); + fixture(30078, b"\x7e\x75", b"\x75\x7e"); + fixture(3740, b"\x9c\x0e", b"\x0e\x9c"); + fixture(31293, b"\x3d\x7a", b"\x7a\x3d"); + fixture(58065, b"\xd1\xe2", b"\xe2\xd1"); + fixture(26864, b"\xf0\x68", b"\x68\xf0"); + fixture(39631, b"\xcf\x9a", b"\x9a\xcf"); + fixture(22646, b"\x76\x58", b"\x58\x76"); + fixture(34206, b"\x9e\x85", b"\x85\x9e"); + fixture(47885, b"\x0d\xbb", b"\xbb\x0d"); + fixture(47204, b"\x64\xb8", b"\xb8\x64"); + fixture(58243, b"\x83\xe3", b"\xe3\x83"); + fixture(55416, b"\x78\xd8", b"\xd8\x78"); + fixture(4283, b"\xbb\x10", b"\x10\xbb"); + fixture(13816, b"\xf8\x35", b"\x35\xf8"); + fixture(43928, b"\x98\xab", b"\xab\x98"); + fixture(5670, b"\x26\x16", b"\x16\x26"); + fixture(50429, b"\xfd\xc4", b"\xc4\xfd"); + fixture(6951, b"\x27\x1b", b"\x1b\x27"); + fixture(1626, b"\x5a\x06", b"\x06\x5a"); + fixture(42424, b"\xb8\xa5", b"\xa5\xb8"); + fixture(62732, b"\x0c\xf5", b"\xf5\x0c"); + fixture(19262, b"\x3e\x4b", b"\x4b\x3e"); + fixture(12581, b"\x25\x31", b"\x31\x25"); + // Exercise every bit position as well as the fixed encoding fixtures. + for bit in 0u16..16u16 { + let value = 1u16 << bit; + expect_write(std.bytes.write_u16_le(mut buf, value)); + expect_read(std.bytes.read_u16_le(ref buf), value); + expect_write(std.bytes.write_u16_be(mut buf, value)); + expect_read(std.bytes.read_u16_be(ref buf), value); + } + return 0; +} diff --git a/tests/conformance/source/std/endian_u32.aji b/tests/conformance/source/std/endian_u32.aji new file mode 100644 index 0000000..b834916 --- /dev/null +++ b/tests/conformance/source/std/endian_u32.aji @@ -0,0 +1,114 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn expect_read(result: std.bytes.ReadU32, expected: u32) -> void +effects [] +{ + match result { + std.bytes.ReadU32::ok(value) => { assert(value == expected); } + std.bytes.ReadU32::short_input => { trap; } + } +} + +fn expect_short_read(result: std.bytes.ReadU32) -> void +effects [] +{ + match result { + std.bytes.ReadU32::ok(value) => { trap; } + std.bytes.ReadU32::short_input => {} + } +} + +fn expect_write(result: std.bytes.WriteResult) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { trap; } + } +} + +fn expect_short_write(result: std.bytes.WriteResult) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => { trap; } + std.bytes.WriteResult::short_output => {} + } +} + +fn fixture(value: u32, le: slice, be: slice) -> void +effects [] +{ + expect_read(std.bytes.read_u32_le(ref le), value); + expect_read(std.bytes.read_u32_be(ref be), value); + var buf: [u8; 10] = [165; 10]; + expect_write(std.bytes.write_u32_le(mut buf[1..5], value)); + assert(std.bytes.equal(ref buf[1..5], ref le)); + assert(buf[0] == 165); + for i in 5usize..buf.len { assert(buf[i] == 165); } + expect_read(std.bytes.read_u32_le(ref buf[1..10]), value); + expect_write(std.bytes.write_u32_be(mut buf[1..10], value)); + assert(std.bytes.equal(ref buf[1..5], ref be)); + assert(buf[0] == 165); + for i in 5usize..buf.len { assert(buf[i] == 165); } + expect_read(std.bytes.read_u32_be(ref buf[1..10]), value); +} + +fn main() -> u8 +effects [] +{ + // Every short length, including zero; error writes preserve the whole array. + var buf: [u8; 10] = [165; 10]; + for size in 0usize..4usize { + expect_short_read(std.bytes.read_u32_le(ref buf[1..1 + size])); + expect_short_read(std.bytes.read_u32_be(ref buf[1..1 + size])); + expect_short_write(std.bytes.write_u32_le(mut buf[1..1 + size], 4294967295)); + expect_short_write(std.bytes.write_u32_be(mut buf[1..1 + size], 4294967295)); + for i in 0..buf.len { assert(buf[i] == 165); } + } + // Expected bytes are fixed by Python int.to_bytes, independently of std's algorithm. + fixture(0, b"\x00\x00\x00\x00", b"\x00\x00\x00\x00"); + fixture(1, b"\x01\x00\x00\x00", b"\x00\x00\x00\x01"); + fixture(4294967295, b"\xff\xff\xff\xff", b"\xff\xff\xff\xff"); + fixture(2147483648, b"\x00\x00\x00\x80", b"\x80\x00\x00\x00"); + fixture(1431655765, b"\x55\x55\x55\x55", b"\x55\x55\x55\x55"); + fixture(16909060, b"\x04\x03\x02\x01", b"\x01\x02\x03\x04"); + fixture(185903060, b"\xd4\xa7\x14\x0b", b"\x0b\x14\xa7\xd4"); + fixture(2037551487, b"\x7f\x91\x72\x79", b"\x79\x72\x91\x7f"); + fixture(2312196622, b"\x0e\x52\xd1\x89", b"\x89\xd1\x52\x0e"); + fixture(3350121379, b"\xa3\xcb\xae\xc7", b"\xc7\xae\xcb\xa3"); + fixture(1919861753, b"\xf9\xc3\x6e\x72", b"\x72\x6e\xc3\xf9"); + fixture(2075794910, b"\xde\x1d\xba\x7b", b"\x7b\xba\x1d\xde"); + fixture(2934997640, b"\x88\x82\xf0\xae", b"\xae\xf0\x82\x88"); + fixture(3004148163, b"\xc3\xa9\x0f\xb3", b"\xb3\x0f\xa9\xc3"); + fixture(2571791918, b"\x2e\x6e\x4a\x99", b"\x99\x4a\x6e\x2e"); + fixture(3086068765, b"\x1d\xac\xf1\xb7", b"\xb7\xf1\xac\x1d"); + fixture(3288209780, b"\x74\x19\xfe\xc3", b"\xc3\xfe\x19\x74"); + fixture(595502178, b"\x62\xa4\x7e\x23", b"\x23\x7e\xa4\x62"); + fixture(246423927, b"\x77\x21\xb0\x0e", b"\x0e\xb0\x21\x77"); + fixture(4061270332, b"\x3c\x11\x12\xf2", b"\xf2\x12\x11\x3c"); + fixture(2716554228, b"\xf4\x53\xeb\xa1", b"\xa1\xeb\x53\xf4"); + fixture(19619250, b"\xb2\x5d\x2b\x01", b"\x01\x2b\x5d\xb2"); + fixture(908296138, b"\xca\x7f\x23\x36", b"\x36\x23\x7f\xca"); + fixture(1856085160, b"\xa8\x9c\xa1\x6e", b"\x6e\xa1\x9c\xa8"); + fixture(2157080593, b"\x11\x70\x92\x80", b"\x80\x92\x70\x11"); + fixture(3019974009, b"\x79\x25\x01\xb4", b"\xb4\x01\x25\x79"); + fixture(877787239, b"\x67\xf8\x51\x34", b"\x34\x51\xf8\x67"); + fixture(4107084175, b"\x8f\x21\xcd\xf4", b"\xf4\xcd\x21\x8f"); + fixture(2223566135, b"\x37\xed\x88\x84", b"\x84\x88\xed\x37"); + fixture(1062036093, b"\x7d\x62\x4d\x3f", b"\x3f\x4d\x62\x7d"); + // Exercise every bit position as well as the fixed encoding fixtures. + for bit in 0u32..32u32 { + let value = 1u32 << bit; + expect_write(std.bytes.write_u32_le(mut buf, value)); + expect_read(std.bytes.read_u32_le(ref buf), value); + expect_write(std.bytes.write_u32_be(mut buf, value)); + expect_read(std.bytes.read_u32_be(ref buf), value); + } + return 0; +} diff --git a/tests/conformance/source/std/endian_u64.aji b/tests/conformance/source/std/endian_u64.aji new file mode 100644 index 0000000..0859cc9 --- /dev/null +++ b/tests/conformance/source/std/endian_u64.aji @@ -0,0 +1,114 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn expect_read(result: std.bytes.ReadU64, expected: u64) -> void +effects [] +{ + match result { + std.bytes.ReadU64::ok(value) => { assert(value == expected); } + std.bytes.ReadU64::short_input => { trap; } + } +} + +fn expect_short_read(result: std.bytes.ReadU64) -> void +effects [] +{ + match result { + std.bytes.ReadU64::ok(value) => { trap; } + std.bytes.ReadU64::short_input => {} + } +} + +fn expect_write(result: std.bytes.WriteResult) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { trap; } + } +} + +fn expect_short_write(result: std.bytes.WriteResult) -> void +effects [] +{ + match result { + std.bytes.WriteResult::ok => { trap; } + std.bytes.WriteResult::short_output => {} + } +} + +fn fixture(value: u64, le: slice, be: slice) -> void +effects [] +{ + expect_read(std.bytes.read_u64_le(ref le), value); + expect_read(std.bytes.read_u64_be(ref be), value); + var buf: [u8; 10] = [165; 10]; + expect_write(std.bytes.write_u64_le(mut buf[1..9], value)); + assert(std.bytes.equal(ref buf[1..9], ref le)); + assert(buf[0] == 165); + for i in 9usize..buf.len { assert(buf[i] == 165); } + expect_read(std.bytes.read_u64_le(ref buf[1..10]), value); + expect_write(std.bytes.write_u64_be(mut buf[1..10], value)); + assert(std.bytes.equal(ref buf[1..9], ref be)); + assert(buf[0] == 165); + for i in 9usize..buf.len { assert(buf[i] == 165); } + expect_read(std.bytes.read_u64_be(ref buf[1..10]), value); +} + +fn main() -> u8 +effects [] +{ + // Every short length, including zero; error writes preserve the whole array. + var buf: [u8; 10] = [165; 10]; + for size in 0usize..8usize { + expect_short_read(std.bytes.read_u64_le(ref buf[1..1 + size])); + expect_short_read(std.bytes.read_u64_be(ref buf[1..1 + size])); + expect_short_write(std.bytes.write_u64_le(mut buf[1..1 + size], 18446744073709551615)); + expect_short_write(std.bytes.write_u64_be(mut buf[1..1 + size], 18446744073709551615)); + for i in 0..buf.len { assert(buf[i] == 165); } + } + // Expected bytes are fixed by Python int.to_bytes, independently of std's algorithm. + fixture(0, b"\x00\x00\x00\x00\x00\x00\x00\x00", b"\x00\x00\x00\x00\x00\x00\x00\x00"); + fixture(1, b"\x01\x00\x00\x00\x00\x00\x00\x00", b"\x00\x00\x00\x00\x00\x00\x00\x01"); + fixture(18446744073709551615, b"\xff\xff\xff\xff\xff\xff\xff\xff", b"\xff\xff\xff\xff\xff\xff\xff\xff"); + fixture(9223372036854775808, b"\x00\x00\x00\x00\x00\x00\x00\x80", b"\x80\x00\x00\x00\x00\x00\x00\x00"); + fixture(6148914691236517205, b"\x55\x55\x55\x55\x55\x55\x55\x55", b"\x55\x55\x55\x55\x55\x55\x55\x55"); + fixture(72623859790382856, b"\x08\x07\x06\x05\x04\x03\x02\x01", b"\x01\x02\x03\x04\x05\x06\x07\x08"); + fixture(15292073328584422715, b"\x3b\xf5\x7f\xe5\xab\x5b\x38\xd4", b"\xd4\x38\x5b\xab\xe5\x7f\xf5\x3b"); + fixture(16250661963492436153, b"\xb9\x28\xeb\xc2\xf4\xf2\x85\xe1", b"\xe1\x85\xf2\xf4\xc2\xeb\x28\xb9"); + fixture(10437458558198301272, b"\x58\x42\x45\x37\x42\x4d\xd9\x90", b"\x90\xd9\x4d\x42\x37\x45\x42\x58"); + fixture(17041513473160135133, b"\xdd\x41\xbe\xca\x36\x9e\x7f\xec", b"\xec\x7f\x9e\x36\xca\xbe\x41\xdd"); + fixture(228321258174005107, b"\x73\xbf\x21\x80\xf9\x28\x2b\x03", b"\x03\x2b\x28\xf9\x80\x21\xbf\x73"); + fixture(3870920093340187, b"\x1b\x12\x1e\xd1\x94\xc0\x0d\x00", b"\x00\x0d\xc0\x94\xd1\x1e\x12\x1b"); + fixture(10610674309359647252, b"\x14\xba\xbe\x0c\x11\xb0\x40\x93", b"\x93\x40\xb0\x11\x0c\xbe\xba\x14"); + fixture(10430557097931907062, b"\xf6\x1f\xa9\xc7\x6a\xc8\xc0\x90", b"\x90\xc0\xc8\x6a\xc7\xa9\x1f\xf6"); + fixture(3219893636986986552, b"\x38\x60\x26\xff\x33\x5c\xaf\x2c", b"\x2c\xaf\x5c\x33\xff\x26\x60\x38"); + fixture(8545323553216493439, b"\x7f\x77\x3f\x20\x7f\x16\x97\x76", b"\x76\x97\x16\x7f\x20\x3f\x77\x7f"); + fixture(8990680145927224152, b"\x58\x3b\x26\x43\xf5\x4f\xc5\x7c", b"\x7c\xc5\x4f\xf5\x43\x26\x3b\x58"); + fixture(12294589648129633388, b"\x6c\x2c\xf6\x3b\x25\x28\x9f\xaa", b"\xaa\x9f\x28\x25\x3b\xf6\x2c\x6c"); + fixture(7802525658554814316, b"\x6c\xcf\x07\x35\xbf\x23\x48\x6c", b"\x6c\x48\x23\xbf\x35\x07\xcf\x6c"); + fixture(3321086216808458160, b"\xb0\x67\x50\x7d\x51\xde\x16\x2e", b"\x2e\x16\xde\x51\x7d\x50\x67\xb0"); + fixture(6819651081902464023, b"\x17\x9c\xe7\xe4\x86\x44\xa4\x5e", b"\x5e\xa4\x44\x86\xe4\xe7\x9c\x17"); + fixture(2183293185793142392, b"\x78\x2e\xbb\xbb\x95\x9d\x4c\x1e", b"\x1e\x4c\x9d\x95\xbb\xbb\x2e\x78"); + fixture(5544438551056829737, b"\x29\x4d\xb9\x8a\x7c\xcd\xf1\x4c", b"\x4c\xf1\xcd\x7c\x8a\xb9\x4d\x29"); + fixture(7373447788311746792, b"\xe8\x18\x36\x80\xb2\xbf\x53\x66", b"\x66\x53\xbf\xb2\x80\x36\x18\xe8"); + fixture(4804431457320197428, b"\x34\x5d\x48\x99\xf4\xc4\xac\x42", b"\x42\xac\xc4\xf4\x99\x48\x5d\x34"); + fixture(13174703505296887866, b"\x3a\x90\x50\x16\x09\xf3\xd5\xb6", b"\xb6\xd5\xf3\x09\x16\x50\x90\x3a"); + fixture(12286828819404160673, b"\xa1\xfe\x9d\x7c\xb6\x95\x83\xaa", b"\xaa\x83\x95\xb6\x7c\x9d\xfe\xa1"); + fixture(8427543257253372388, b"\xe4\x61\xd3\x01\xf1\xa5\xf4\x74", b"\x74\xf4\xa5\xf1\x01\xd3\x61\xe4"); + fixture(6325739954515741802, b"\x6a\x0c\x68\x32\xf9\x8a\xc9\x57", b"\x57\xc9\x8a\xf9\x32\x68\x0c\x6a"); + fixture(3169332480603093103, b"\x6f\x78\x74\x69\x19\xbb\xfb\x2b", b"\x2b\xfb\xbb\x19\x69\x74\x78\x6f"); + // Exercise every bit position as well as the fixed encoding fixtures. + for bit in 0u64..64u64 { + let value = 1u64 << bit; + expect_write(std.bytes.write_u64_le(mut buf, value)); + expect_read(std.bytes.read_u64_le(ref buf), value); + expect_write(std.bytes.write_u64_be(mut buf, value)); + expect_read(std.bytes.read_u64_be(ref buf), value); + } + return 0; +} diff --git a/tests/conformance/source/std/endian_unknown_match_type.aji b/tests/conformance/source/std/endian_unknown_match_type.aji new file mode 100644 index 0000000..f1d3fcf --- /dev/null +++ b/tests/conformance/source/std/endian_unknown_match_type.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ match std.bytes.read_u16_le(b"xx") { std.bytes.Missing::ok(v) => { return 0; } std.bytes.Missing::short_input => { return 1; } } } diff --git a/tests/conformance/source/std/endian_unknown_type.aji b/tests/conformance/source/std/endian_unknown_type.aji new file mode 100644 index 0000000..47a2adf --- /dev/null +++ b/tests/conformance/source/std/endian_unknown_type.aji @@ -0,0 +1,12 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn take(r: std.bytes.Missing) -> void +effects [] +{} +fn main() -> u8 +effects [] +{ return 0; } diff --git a/tests/conformance/source/std/endian_unknown_variant.aji b/tests/conformance/source/std/endian_unknown_variant.aji new file mode 100644 index 0000000..6c104db --- /dev/null +++ b/tests/conformance/source/std/endian_unknown_variant.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ let r = std.bytes.ReadU16::missing; return 0; } diff --git a/tests/conformance/source/std/endian_unqualified_type.aji b/tests/conformance/source/std/endian_unqualified_type.aji new file mode 100644 index 0000000..945fecc --- /dev/null +++ b/tests/conformance/source/std/endian_unqualified_type.aji @@ -0,0 +1,12 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn take(r: ReadU16) -> void +effects [] +{} +fn main() -> u8 +effects [] +{ return 0; } diff --git a/tests/conformance/source/std/endian_value_width.aji b/tests/conformance/source/std/endian_value_width.aji new file mode 100644 index 0000000..9734800 --- /dev/null +++ b/tests/conformance/source/std/endian_value_width.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ var b: [u8; 2] = zero; let r = std.bytes.write_u16_le(mut b, 1u32); return 0; } diff --git a/tests/conformance/source/std/endian_variant_wrong_enum.aji b/tests/conformance/source/std/endian_variant_wrong_enum.aji new file mode 100644 index 0000000..66bb03f --- /dev/null +++ b/tests/conformance/source/std/endian_variant_wrong_enum.aji @@ -0,0 +1,15 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +enum ReadU16 { ok(u16), short_input } +fn main() -> u8 +effects [] +{ + match std.bytes.read_u16_le(b"xx") { + ReadU16::ok(value) => { return 0; } + ReadU16::short_input => { return 1; } + } +} diff --git a/tests/conformance/source/std/endian_write_needs_mut.aji b/tests/conformance/source/std/endian_write_needs_mut.aji new file mode 100644 index 0000000..d529cf1 --- /dev/null +++ b/tests/conformance/source/std/endian_write_needs_mut.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.3; docs/spec/15-source-language.md §13 +module test.endian +import std.bytes; + +fn main() -> u8 +effects [] +{ var b: [u8; 2] = zero; let r = std.bytes.write_u16_le(ref b, 1); return 0; } diff --git a/tests/conformance/source/std/fill_and_search.aji b/tests/conformance/source/std/fill_and_search.aji new file mode 100644 index 0000000..107aae0 --- /dev/null +++ b/tests/conformance/source/std/fill_and_search.aji @@ -0,0 +1,28 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ + var buf: [u8; 5] = zero; + std.bytes.fill(mut buf[1..4], 255); + assert(buf[0] == 0 and buf[4] == 0); + assert(buf[1] == 255 and buf[2] == 255 and buf[3] == 255); + std.bytes.fill(mut buf[2..2], 42); + assert(buf[2] == 255); + let index = std.bytes.find(ref buf, 255); + if index < buf.len { assert(buf[index] == 255); } + assert(index == 1usize); + for n in 0u16..256u16 { + let byte = n as% u8; + std.bytes.fill(mut buf, byte); + assert(std.bytes.compare(ref buf, ref buf) == 0); + assert(std.bytes.find(ref buf, byte) == 0usize); + for i in 0..buf.len { assert(buf[i] == byte); } + } + return 0; +} diff --git a/tests/conformance/source/std/fmt_alias.aji b/tests/conformance/source/std/fmt_alias.aji new file mode 100644 index 0000000..6f1e8c6 --- /dev/null +++ b/tests/conformance/source/std/fmt_alias.aji @@ -0,0 +1,6 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +import std.fmt; +fn main() -> u8 effects [] { var buf: [u8; 4] = zero; ref held = buf; let result = std.fmt.write_i64(mut buf[0..0], -1); assert(held[0] == 0); return 0; } diff --git a/tests/conformance/source/std/fmt_equivalence.aji b/tests/conformance/source/std/fmt_equivalence.aji new file mode 100644 index 0000000..4c101a3 --- /dev/null +++ b/tests/conformance/source/std/fmt_equivalence.aji @@ -0,0 +1,14 @@ +// expect: run +// result: {"variant":"ok","payload":[20]} +// equivalent: std/fmt_count.air +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt_count +import std.bytes; +import std.fmt; +fn main() -> std.fmt.WriteResult effects [] { + var buf: [u8; 20] = zero; + let result = std.fmt.write_u64(mut buf, 18446744073709551615u64); + assert(std.bytes.equal(ref buf, b"18446744073709551615")); + return result; +} diff --git a/tests/conformance/source/std/fmt_example.aji b/tests/conformance/source/std/fmt_example.aji new file mode 100644 index 0000000..5e0c20d --- /dev/null +++ b/tests/conformance/source/std/fmt_example.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 17 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module demo.format +import std.bytes; +import std.fmt; + +fn main() -> usize +effects [] +{ + var record: [u8; 24] = [165; 24]; + match std.bytes.copy(mut record, b"value=") { + std.bytes.WriteResult::ok => {} + std.bytes.WriteResult::short_output => { return 0; } + } + var offset: usize = 6; + match std.fmt.write_i64(mut record[offset..record.len], -42) { + std.fmt.WriteResult::ok(count) => { offset = offset + count; } + std.fmt.WriteResult::short_output => { return 0; } + } + match std.bytes.copy(mut record[offset..record.len], b" count=") { + std.bytes.WriteResult::ok => { offset = offset + 7; } + std.bytes.WriteResult::short_output => { return 0; } + } + match std.fmt.write_usize(mut record[offset..record.len], 7) { + std.fmt.WriteResult::ok(count) => { offset = offset + count; } + std.fmt.WriteResult::short_output => { return 0; } + } + assert(std.bytes.equal(ref record[0..offset], b"value=-42 count=7")); + for i in offset..record.len { assert(record[i] == 165); } + return offset; +} diff --git a/tests/conformance/source/std/fmt_i64_vectors.aji b/tests/conformance/source/std/fmt_i64_vectors.aji new file mode 100644 index 0000000..051afdb --- /dev/null +++ b/tests/conformance/source/std/fmt_i64_vectors.aji @@ -0,0 +1,1020 @@ +// expect: run +// result: 1 +// fuel: 20000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +// Decimal oracle: Python str(value); fixed seed 202010. Small values, powers +// of ten/two and their neighbors, signed limits, and 48 seeded unsigned inputs. +module test.fmt_i64 +import std.fmt; + +fn check(value: i64, expected: slice) -> void +effects [] +{ + for capacity in 0usize..23usize { + var storage: [u8; 26] = [165; 26]; + match std.fmt.write_i64(mut storage[1..1 + capacity], value as! i64) { + std.fmt.WriteResult::ok(count) => { + assert(capacity >= expected.len); + assert(count == expected.len); + for i in 0..count { assert(storage[1 + i] == expected[i]); } + for i in count + 1..storage.len { assert(storage[i] == 165); } + } + std.fmt.WriteResult::short_output => { + assert(capacity < expected.len); + for i in 0..storage.len { assert(storage[i] == 165); } + } + } + assert(storage[0] == 165); + } +} + +fn main() -> u8 +effects [] +{ + check((-9223372036854775807i64 - 1i64), b"-9223372036854775808"); + check(-9223372036854775807i64, b"-9223372036854775807"); + check(-8840889545696419459i64, b"-8840889545696419459"); + check(-8741427099435404153i64, b"-8741427099435404153"); + check(-8601570958497122972i64, b"-8601570958497122972"); + check(-8019800572464344819i64, b"-8019800572464344819"); + check(-7960147437111475408i64, b"-7960147437111475408"); + check(-7384412550790166007i64, b"-7384412550790166007"); + check(-6472241654744496554i64, b"-6472241654744496554"); + check(-6307099386378364894i64, b"-6307099386378364894"); + check(-5600760056953198506i64, b"-5600760056953198506"); + check(-5281330341569806731i64, b"-5281330341569806731"); + check(-5051844181780778935i64, b"-5051844181780778935"); + check(-4611686018427387905i64, b"-4611686018427387905"); + check(-4611686018427387904i64, b"-4611686018427387904"); + check(-4611686018427387903i64, b"-4611686018427387903"); + check(-4358181693715673361i64, b"-4358181693715673361"); + check(-3869189413169762050i64, b"-3869189413169762050"); + check(-3861594818318916497i64, b"-3861594818318916497"); + check(-3660992601043197614i64, b"-3660992601043197614"); + check(-3222271663937675830i64, b"-3222271663937675830"); + check(-2942703002681949929i64, b"-2942703002681949929"); + check(-2395990555469872943i64, b"-2395990555469872943"); + check(-2305843009213693953i64, b"-2305843009213693953"); + check(-2305843009213693952i64, b"-2305843009213693952"); + check(-2305843009213693951i64, b"-2305843009213693951"); + check(-2181996174858958743i64, b"-2181996174858958743"); + check(-1964819683467062741i64, b"-1964819683467062741"); + check(-1918875392190302266i64, b"-1918875392190302266"); + check(-1779373561758428289i64, b"-1779373561758428289"); + check(-1152921504606846977i64, b"-1152921504606846977"); + check(-1152921504606846976i64, b"-1152921504606846976"); + check(-1152921504606846975i64, b"-1152921504606846975"); + check(-1000000000000000001i64, b"-1000000000000000001"); + check(-1000000000000000000i64, b"-1000000000000000000"); + check(-999999999999999999i64, b"-999999999999999999"); + check(-576460752303423489i64, b"-576460752303423489"); + check(-576460752303423488i64, b"-576460752303423488"); + check(-576460752303423487i64, b"-576460752303423487"); + check(-288230376151711745i64, b"-288230376151711745"); + check(-288230376151711744i64, b"-288230376151711744"); + check(-288230376151711743i64, b"-288230376151711743"); + check(-253292627452887239i64, b"-253292627452887239"); + check(-144115188075855873i64, b"-144115188075855873"); + check(-144115188075855872i64, b"-144115188075855872"); + check(-144115188075855871i64, b"-144115188075855871"); + check(-100000000000000001i64, b"-100000000000000001"); + check(-100000000000000000i64, b"-100000000000000000"); + check(-99999999999999999i64, b"-99999999999999999"); + check(-72057594037927937i64, b"-72057594037927937"); + check(-72057594037927936i64, b"-72057594037927936"); + check(-72057594037927935i64, b"-72057594037927935"); + check(-36028797018963969i64, b"-36028797018963969"); + check(-36028797018963968i64, b"-36028797018963968"); + check(-36028797018963967i64, b"-36028797018963967"); + check(-18014398509481985i64, b"-18014398509481985"); + check(-18014398509481984i64, b"-18014398509481984"); + check(-18014398509481983i64, b"-18014398509481983"); + check(-10000000000000001i64, b"-10000000000000001"); + check(-10000000000000000i64, b"-10000000000000000"); + check(-9999999999999999i64, b"-9999999999999999"); + check(-9007199254740993i64, b"-9007199254740993"); + check(-9007199254740992i64, b"-9007199254740992"); + check(-9007199254740991i64, b"-9007199254740991"); + check(-4503599627370497i64, b"-4503599627370497"); + check(-4503599627370496i64, b"-4503599627370496"); + check(-4503599627370495i64, b"-4503599627370495"); + check(-2251799813685249i64, b"-2251799813685249"); + check(-2251799813685248i64, b"-2251799813685248"); + check(-2251799813685247i64, b"-2251799813685247"); + check(-1125899906842625i64, b"-1125899906842625"); + check(-1125899906842624i64, b"-1125899906842624"); + check(-1125899906842623i64, b"-1125899906842623"); + check(-1000000000000001i64, b"-1000000000000001"); + check(-1000000000000000i64, b"-1000000000000000"); + check(-999999999999999i64, b"-999999999999999"); + check(-562949953421313i64, b"-562949953421313"); + check(-562949953421312i64, b"-562949953421312"); + check(-562949953421311i64, b"-562949953421311"); + check(-281474976710657i64, b"-281474976710657"); + check(-281474976710656i64, b"-281474976710656"); + check(-281474976710655i64, b"-281474976710655"); + check(-140737488355329i64, b"-140737488355329"); + check(-140737488355328i64, b"-140737488355328"); + check(-140737488355327i64, b"-140737488355327"); + check(-100000000000001i64, b"-100000000000001"); + check(-100000000000000i64, b"-100000000000000"); + check(-99999999999999i64, b"-99999999999999"); + check(-70368744177665i64, b"-70368744177665"); + check(-70368744177664i64, b"-70368744177664"); + check(-70368744177663i64, b"-70368744177663"); + check(-35184372088833i64, b"-35184372088833"); + check(-35184372088832i64, b"-35184372088832"); + check(-35184372088831i64, b"-35184372088831"); + check(-17592186044417i64, b"-17592186044417"); + check(-17592186044416i64, b"-17592186044416"); + check(-17592186044415i64, b"-17592186044415"); + check(-10000000000001i64, b"-10000000000001"); + check(-10000000000000i64, b"-10000000000000"); + check(-9999999999999i64, b"-9999999999999"); + check(-8796093022209i64, b"-8796093022209"); + check(-8796093022208i64, b"-8796093022208"); + check(-8796093022207i64, b"-8796093022207"); + check(-4398046511105i64, b"-4398046511105"); + check(-4398046511104i64, b"-4398046511104"); + check(-4398046511103i64, b"-4398046511103"); + check(-2199023255553i64, b"-2199023255553"); + check(-2199023255552i64, b"-2199023255552"); + check(-2199023255551i64, b"-2199023255551"); + check(-1099511627777i64, b"-1099511627777"); + check(-1099511627776i64, b"-1099511627776"); + check(-1099511627775i64, b"-1099511627775"); + check(-1000000000001i64, b"-1000000000001"); + check(-1000000000000i64, b"-1000000000000"); + check(-999999999999i64, b"-999999999999"); + check(-549755813889i64, b"-549755813889"); + check(-549755813888i64, b"-549755813888"); + check(-549755813887i64, b"-549755813887"); + check(-274877906945i64, b"-274877906945"); + check(-274877906944i64, b"-274877906944"); + check(-274877906943i64, b"-274877906943"); + check(-137438953473i64, b"-137438953473"); + check(-137438953472i64, b"-137438953472"); + check(-137438953471i64, b"-137438953471"); + check(-100000000001i64, b"-100000000001"); + check(-100000000000i64, b"-100000000000"); + check(-99999999999i64, b"-99999999999"); + check(-68719476737i64, b"-68719476737"); + check(-68719476736i64, b"-68719476736"); + check(-68719476735i64, b"-68719476735"); + check(-34359738369i64, b"-34359738369"); + check(-34359738368i64, b"-34359738368"); + check(-34359738367i64, b"-34359738367"); + check(-17179869185i64, b"-17179869185"); + check(-17179869184i64, b"-17179869184"); + check(-17179869183i64, b"-17179869183"); + check(-10000000001i64, b"-10000000001"); + check(-10000000000i64, b"-10000000000"); + check(-9999999999i64, b"-9999999999"); + check(-8589934593i64, b"-8589934593"); + check(-8589934592i64, b"-8589934592"); + check(-8589934591i64, b"-8589934591"); + check(-4294967297i64, b"-4294967297"); + check(-4294967296i64, b"-4294967296"); + check(-4294967295i64, b"-4294967295"); + check(-2147483649i64, b"-2147483649"); + check(-2147483648i64, b"-2147483648"); + check(-2147483647i64, b"-2147483647"); + check(-1073741825i64, b"-1073741825"); + check(-1073741824i64, b"-1073741824"); + check(-1073741823i64, b"-1073741823"); + check(-1000000001i64, b"-1000000001"); + check(-1000000000i64, b"-1000000000"); + check(-999999999i64, b"-999999999"); + check(-536870913i64, b"-536870913"); + check(-536870912i64, b"-536870912"); + check(-536870911i64, b"-536870911"); + check(-268435457i64, b"-268435457"); + check(-268435456i64, b"-268435456"); + check(-268435455i64, b"-268435455"); + check(-134217729i64, b"-134217729"); + check(-134217728i64, b"-134217728"); + check(-134217727i64, b"-134217727"); + check(-100000001i64, b"-100000001"); + check(-100000000i64, b"-100000000"); + check(-99999999i64, b"-99999999"); + check(-67108865i64, b"-67108865"); + check(-67108864i64, b"-67108864"); + check(-67108863i64, b"-67108863"); + check(-33554433i64, b"-33554433"); + check(-33554432i64, b"-33554432"); + check(-33554431i64, b"-33554431"); + check(-16777217i64, b"-16777217"); + check(-16777216i64, b"-16777216"); + check(-16777215i64, b"-16777215"); + check(-10000001i64, b"-10000001"); + check(-10000000i64, b"-10000000"); + check(-9999999i64, b"-9999999"); + check(-8388609i64, b"-8388609"); + check(-8388608i64, b"-8388608"); + check(-8388607i64, b"-8388607"); + check(-4194305i64, b"-4194305"); + check(-4194304i64, b"-4194304"); + check(-4194303i64, b"-4194303"); + check(-2097153i64, b"-2097153"); + check(-2097152i64, b"-2097152"); + check(-2097151i64, b"-2097151"); + check(-1048577i64, b"-1048577"); + check(-1048576i64, b"-1048576"); + check(-1048575i64, b"-1048575"); + check(-1000001i64, b"-1000001"); + check(-1000000i64, b"-1000000"); + check(-999999i64, b"-999999"); + check(-524289i64, b"-524289"); + check(-524288i64, b"-524288"); + check(-524287i64, b"-524287"); + check(-262145i64, b"-262145"); + check(-262144i64, b"-262144"); + check(-262143i64, b"-262143"); + check(-131073i64, b"-131073"); + check(-131072i64, b"-131072"); + check(-131071i64, b"-131071"); + check(-100001i64, b"-100001"); + check(-100000i64, b"-100000"); + check(-99999i64, b"-99999"); + check(-65537i64, b"-65537"); + check(-65536i64, b"-65536"); + check(-65535i64, b"-65535"); + check(-32769i64, b"-32769"); + check(-32768i64, b"-32768"); + check(-32767i64, b"-32767"); + check(-16385i64, b"-16385"); + check(-16384i64, b"-16384"); + check(-16383i64, b"-16383"); + check(-10001i64, b"-10001"); + check(-10000i64, b"-10000"); + check(-9999i64, b"-9999"); + check(-8193i64, b"-8193"); + check(-8192i64, b"-8192"); + check(-8191i64, b"-8191"); + check(-4097i64, b"-4097"); + check(-4096i64, b"-4096"); + check(-4095i64, b"-4095"); + check(-2049i64, b"-2049"); + check(-2048i64, b"-2048"); + check(-2047i64, b"-2047"); + check(-1025i64, b"-1025"); + check(-1024i64, b"-1024"); + check(-1023i64, b"-1023"); + check(-1001i64, b"-1001"); + check(-1000i64, b"-1000"); + check(-999i64, b"-999"); + check(-513i64, b"-513"); + check(-512i64, b"-512"); + check(-511i64, b"-511"); + check(-257i64, b"-257"); + check(-256i64, b"-256"); + check(-255i64, b"-255"); + check(-254i64, b"-254"); + check(-253i64, b"-253"); + check(-252i64, b"-252"); + check(-251i64, b"-251"); + check(-250i64, b"-250"); + check(-249i64, b"-249"); + check(-248i64, b"-248"); + check(-247i64, b"-247"); + check(-246i64, b"-246"); + check(-245i64, b"-245"); + check(-244i64, b"-244"); + check(-243i64, b"-243"); + check(-242i64, b"-242"); + check(-241i64, b"-241"); + check(-240i64, b"-240"); + check(-239i64, b"-239"); + check(-238i64, b"-238"); + check(-237i64, b"-237"); + check(-236i64, b"-236"); + check(-235i64, b"-235"); + check(-234i64, b"-234"); + check(-233i64, b"-233"); + check(-232i64, b"-232"); + check(-231i64, b"-231"); + check(-230i64, b"-230"); + check(-229i64, b"-229"); + check(-228i64, b"-228"); + check(-227i64, b"-227"); + check(-226i64, b"-226"); + check(-225i64, b"-225"); + check(-224i64, b"-224"); + check(-223i64, b"-223"); + check(-222i64, b"-222"); + check(-221i64, b"-221"); + check(-220i64, b"-220"); + check(-219i64, b"-219"); + check(-218i64, b"-218"); + check(-217i64, b"-217"); + check(-216i64, b"-216"); + check(-215i64, b"-215"); + check(-214i64, b"-214"); + check(-213i64, b"-213"); + check(-212i64, b"-212"); + check(-211i64, b"-211"); + check(-210i64, b"-210"); + check(-209i64, b"-209"); + check(-208i64, b"-208"); + check(-207i64, b"-207"); + check(-206i64, b"-206"); + check(-205i64, b"-205"); + check(-204i64, b"-204"); + check(-203i64, b"-203"); + check(-202i64, b"-202"); + check(-201i64, b"-201"); + check(-200i64, b"-200"); + check(-199i64, b"-199"); + check(-198i64, b"-198"); + check(-197i64, b"-197"); + check(-196i64, b"-196"); + check(-195i64, b"-195"); + check(-194i64, b"-194"); + check(-193i64, b"-193"); + check(-192i64, b"-192"); + check(-191i64, b"-191"); + check(-190i64, b"-190"); + check(-189i64, b"-189"); + check(-188i64, b"-188"); + check(-187i64, b"-187"); + check(-186i64, b"-186"); + check(-185i64, b"-185"); + check(-184i64, b"-184"); + check(-183i64, b"-183"); + check(-182i64, b"-182"); + check(-181i64, b"-181"); + check(-180i64, b"-180"); + check(-179i64, b"-179"); + check(-178i64, b"-178"); + check(-177i64, b"-177"); + check(-176i64, b"-176"); + check(-175i64, b"-175"); + check(-174i64, b"-174"); + check(-173i64, b"-173"); + check(-172i64, b"-172"); + check(-171i64, b"-171"); + check(-170i64, b"-170"); + check(-169i64, b"-169"); + check(-168i64, b"-168"); + check(-167i64, b"-167"); + check(-166i64, b"-166"); + check(-165i64, b"-165"); + check(-164i64, b"-164"); + check(-163i64, b"-163"); + check(-162i64, b"-162"); + check(-161i64, b"-161"); + check(-160i64, b"-160"); + check(-159i64, b"-159"); + check(-158i64, b"-158"); + check(-157i64, b"-157"); + check(-156i64, b"-156"); + check(-155i64, b"-155"); + check(-154i64, b"-154"); + check(-153i64, b"-153"); + check(-152i64, b"-152"); + check(-151i64, b"-151"); + check(-150i64, b"-150"); + check(-149i64, b"-149"); + check(-148i64, b"-148"); + check(-147i64, b"-147"); + check(-146i64, b"-146"); + check(-145i64, b"-145"); + check(-144i64, b"-144"); + check(-143i64, b"-143"); + check(-142i64, b"-142"); + check(-141i64, b"-141"); + check(-140i64, b"-140"); + check(-139i64, b"-139"); + check(-138i64, b"-138"); + check(-137i64, b"-137"); + check(-136i64, b"-136"); + check(-135i64, b"-135"); + check(-134i64, b"-134"); + check(-133i64, b"-133"); + check(-132i64, b"-132"); + check(-131i64, b"-131"); + check(-130i64, b"-130"); + check(-129i64, b"-129"); + check(-128i64, b"-128"); + check(-127i64, b"-127"); + check(-126i64, b"-126"); + check(-125i64, b"-125"); + check(-124i64, b"-124"); + check(-123i64, b"-123"); + check(-122i64, b"-122"); + check(-121i64, b"-121"); + check(-120i64, b"-120"); + check(-119i64, b"-119"); + check(-118i64, b"-118"); + check(-117i64, b"-117"); + check(-116i64, b"-116"); + check(-115i64, b"-115"); + check(-114i64, b"-114"); + check(-113i64, b"-113"); + check(-112i64, b"-112"); + check(-111i64, b"-111"); + check(-110i64, b"-110"); + check(-109i64, b"-109"); + check(-108i64, b"-108"); + check(-107i64, b"-107"); + check(-106i64, b"-106"); + check(-105i64, b"-105"); + check(-104i64, b"-104"); + check(-103i64, b"-103"); + check(-102i64, b"-102"); + check(-101i64, b"-101"); + check(-100i64, b"-100"); + check(-99i64, b"-99"); + check(-98i64, b"-98"); + check(-97i64, b"-97"); + check(-96i64, b"-96"); + check(-95i64, b"-95"); + check(-94i64, b"-94"); + check(-93i64, b"-93"); + check(-92i64, b"-92"); + check(-91i64, b"-91"); + check(-90i64, b"-90"); + check(-89i64, b"-89"); + check(-88i64, b"-88"); + check(-87i64, b"-87"); + check(-86i64, b"-86"); + check(-85i64, b"-85"); + check(-84i64, b"-84"); + check(-83i64, b"-83"); + check(-82i64, b"-82"); + check(-81i64, b"-81"); + check(-80i64, b"-80"); + check(-79i64, b"-79"); + check(-78i64, b"-78"); + check(-77i64, b"-77"); + check(-76i64, b"-76"); + check(-75i64, b"-75"); + check(-74i64, b"-74"); + check(-73i64, b"-73"); + check(-72i64, b"-72"); + check(-71i64, b"-71"); + check(-70i64, b"-70"); + check(-69i64, b"-69"); + check(-68i64, b"-68"); + check(-67i64, b"-67"); + check(-66i64, b"-66"); + check(-65i64, b"-65"); + check(-64i64, b"-64"); + check(-63i64, b"-63"); + check(-62i64, b"-62"); + check(-61i64, b"-61"); + check(-60i64, b"-60"); + check(-59i64, b"-59"); + check(-58i64, b"-58"); + check(-57i64, b"-57"); + check(-56i64, b"-56"); + check(-55i64, b"-55"); + check(-54i64, b"-54"); + check(-53i64, b"-53"); + check(-52i64, b"-52"); + check(-51i64, b"-51"); + check(-50i64, b"-50"); + check(-49i64, b"-49"); + check(-48i64, b"-48"); + check(-47i64, b"-47"); + check(-46i64, b"-46"); + check(-45i64, b"-45"); + check(-44i64, b"-44"); + check(-43i64, b"-43"); + check(-42i64, b"-42"); + check(-41i64, b"-41"); + check(-40i64, b"-40"); + check(-39i64, b"-39"); + check(-38i64, b"-38"); + check(-37i64, b"-37"); + check(-36i64, b"-36"); + check(-35i64, b"-35"); + check(-34i64, b"-34"); + check(-33i64, b"-33"); + check(-32i64, b"-32"); + check(-31i64, b"-31"); + check(-30i64, b"-30"); + check(-29i64, b"-29"); + check(-28i64, b"-28"); + check(-27i64, b"-27"); + check(-26i64, b"-26"); + check(-25i64, b"-25"); + check(-24i64, b"-24"); + check(-23i64, b"-23"); + check(-22i64, b"-22"); + check(-21i64, b"-21"); + check(-20i64, b"-20"); + check(-19i64, b"-19"); + check(-18i64, b"-18"); + check(-17i64, b"-17"); + check(-16i64, b"-16"); + check(-15i64, b"-15"); + check(-14i64, b"-14"); + check(-13i64, b"-13"); + check(-12i64, b"-12"); + check(-11i64, b"-11"); + check(-10i64, b"-10"); + check(-9i64, b"-9"); + check(-8i64, b"-8"); + check(-7i64, b"-7"); + check(-6i64, b"-6"); + check(-5i64, b"-5"); + check(-4i64, b"-4"); + check(-3i64, b"-3"); + check(-2i64, b"-2"); + check(-1i64, b"-1"); + check(0i64, b"0"); + check(1i64, b"1"); + check(2i64, b"2"); + check(3i64, b"3"); + check(4i64, b"4"); + check(5i64, b"5"); + check(6i64, b"6"); + check(7i64, b"7"); + check(8i64, b"8"); + check(9i64, b"9"); + check(10i64, b"10"); + check(11i64, b"11"); + check(12i64, b"12"); + check(13i64, b"13"); + check(14i64, b"14"); + check(15i64, b"15"); + check(16i64, b"16"); + check(17i64, b"17"); + check(18i64, b"18"); + check(19i64, b"19"); + check(20i64, b"20"); + check(21i64, b"21"); + check(22i64, b"22"); + check(23i64, b"23"); + check(24i64, b"24"); + check(25i64, b"25"); + check(26i64, b"26"); + check(27i64, b"27"); + check(28i64, b"28"); + check(29i64, b"29"); + check(30i64, b"30"); + check(31i64, b"31"); + check(32i64, b"32"); + check(33i64, b"33"); + check(34i64, b"34"); + check(35i64, b"35"); + check(36i64, b"36"); + check(37i64, b"37"); + check(38i64, b"38"); + check(39i64, b"39"); + check(40i64, b"40"); + check(41i64, b"41"); + check(42i64, b"42"); + check(43i64, b"43"); + check(44i64, b"44"); + check(45i64, b"45"); + check(46i64, b"46"); + check(47i64, b"47"); + check(48i64, b"48"); + check(49i64, b"49"); + check(50i64, b"50"); + check(51i64, b"51"); + check(52i64, b"52"); + check(53i64, b"53"); + check(54i64, b"54"); + check(55i64, b"55"); + check(56i64, b"56"); + check(57i64, b"57"); + check(58i64, b"58"); + check(59i64, b"59"); + check(60i64, b"60"); + check(61i64, b"61"); + check(62i64, b"62"); + check(63i64, b"63"); + check(64i64, b"64"); + check(65i64, b"65"); + check(66i64, b"66"); + check(67i64, b"67"); + check(68i64, b"68"); + check(69i64, b"69"); + check(70i64, b"70"); + check(71i64, b"71"); + check(72i64, b"72"); + check(73i64, b"73"); + check(74i64, b"74"); + check(75i64, b"75"); + check(76i64, b"76"); + check(77i64, b"77"); + check(78i64, b"78"); + check(79i64, b"79"); + check(80i64, b"80"); + check(81i64, b"81"); + check(82i64, b"82"); + check(83i64, b"83"); + check(84i64, b"84"); + check(85i64, b"85"); + check(86i64, b"86"); + check(87i64, b"87"); + check(88i64, b"88"); + check(89i64, b"89"); + check(90i64, b"90"); + check(91i64, b"91"); + check(92i64, b"92"); + check(93i64, b"93"); + check(94i64, b"94"); + check(95i64, b"95"); + check(96i64, b"96"); + check(97i64, b"97"); + check(98i64, b"98"); + check(99i64, b"99"); + check(100i64, b"100"); + check(101i64, b"101"); + check(102i64, b"102"); + check(103i64, b"103"); + check(104i64, b"104"); + check(105i64, b"105"); + check(106i64, b"106"); + check(107i64, b"107"); + check(108i64, b"108"); + check(109i64, b"109"); + check(110i64, b"110"); + check(111i64, b"111"); + check(112i64, b"112"); + check(113i64, b"113"); + check(114i64, b"114"); + check(115i64, b"115"); + check(116i64, b"116"); + check(117i64, b"117"); + check(118i64, b"118"); + check(119i64, b"119"); + check(120i64, b"120"); + check(121i64, b"121"); + check(122i64, b"122"); + check(123i64, b"123"); + check(124i64, b"124"); + check(125i64, b"125"); + check(126i64, b"126"); + check(127i64, b"127"); + check(128i64, b"128"); + check(129i64, b"129"); + check(130i64, b"130"); + check(131i64, b"131"); + check(132i64, b"132"); + check(133i64, b"133"); + check(134i64, b"134"); + check(135i64, b"135"); + check(136i64, b"136"); + check(137i64, b"137"); + check(138i64, b"138"); + check(139i64, b"139"); + check(140i64, b"140"); + check(141i64, b"141"); + check(142i64, b"142"); + check(143i64, b"143"); + check(144i64, b"144"); + check(145i64, b"145"); + check(146i64, b"146"); + check(147i64, b"147"); + check(148i64, b"148"); + check(149i64, b"149"); + check(150i64, b"150"); + check(151i64, b"151"); + check(152i64, b"152"); + check(153i64, b"153"); + check(154i64, b"154"); + check(155i64, b"155"); + check(156i64, b"156"); + check(157i64, b"157"); + check(158i64, b"158"); + check(159i64, b"159"); + check(160i64, b"160"); + check(161i64, b"161"); + check(162i64, b"162"); + check(163i64, b"163"); + check(164i64, b"164"); + check(165i64, b"165"); + check(166i64, b"166"); + check(167i64, b"167"); + check(168i64, b"168"); + check(169i64, b"169"); + check(170i64, b"170"); + check(171i64, b"171"); + check(172i64, b"172"); + check(173i64, b"173"); + check(174i64, b"174"); + check(175i64, b"175"); + check(176i64, b"176"); + check(177i64, b"177"); + check(178i64, b"178"); + check(179i64, b"179"); + check(180i64, b"180"); + check(181i64, b"181"); + check(182i64, b"182"); + check(183i64, b"183"); + check(184i64, b"184"); + check(185i64, b"185"); + check(186i64, b"186"); + check(187i64, b"187"); + check(188i64, b"188"); + check(189i64, b"189"); + check(190i64, b"190"); + check(191i64, b"191"); + check(192i64, b"192"); + check(193i64, b"193"); + check(194i64, b"194"); + check(195i64, b"195"); + check(196i64, b"196"); + check(197i64, b"197"); + check(198i64, b"198"); + check(199i64, b"199"); + check(200i64, b"200"); + check(201i64, b"201"); + check(202i64, b"202"); + check(203i64, b"203"); + check(204i64, b"204"); + check(205i64, b"205"); + check(206i64, b"206"); + check(207i64, b"207"); + check(208i64, b"208"); + check(209i64, b"209"); + check(210i64, b"210"); + check(211i64, b"211"); + check(212i64, b"212"); + check(213i64, b"213"); + check(214i64, b"214"); + check(215i64, b"215"); + check(216i64, b"216"); + check(217i64, b"217"); + check(218i64, b"218"); + check(219i64, b"219"); + check(220i64, b"220"); + check(221i64, b"221"); + check(222i64, b"222"); + check(223i64, b"223"); + check(224i64, b"224"); + check(225i64, b"225"); + check(226i64, b"226"); + check(227i64, b"227"); + check(228i64, b"228"); + check(229i64, b"229"); + check(230i64, b"230"); + check(231i64, b"231"); + check(232i64, b"232"); + check(233i64, b"233"); + check(234i64, b"234"); + check(235i64, b"235"); + check(236i64, b"236"); + check(237i64, b"237"); + check(238i64, b"238"); + check(239i64, b"239"); + check(240i64, b"240"); + check(241i64, b"241"); + check(242i64, b"242"); + check(243i64, b"243"); + check(244i64, b"244"); + check(245i64, b"245"); + check(246i64, b"246"); + check(247i64, b"247"); + check(248i64, b"248"); + check(249i64, b"249"); + check(250i64, b"250"); + check(251i64, b"251"); + check(252i64, b"252"); + check(253i64, b"253"); + check(254i64, b"254"); + check(255i64, b"255"); + check(256i64, b"256"); + check(257i64, b"257"); + check(511i64, b"511"); + check(512i64, b"512"); + check(513i64, b"513"); + check(999i64, b"999"); + check(1000i64, b"1000"); + check(1001i64, b"1001"); + check(1023i64, b"1023"); + check(1024i64, b"1024"); + check(1025i64, b"1025"); + check(2047i64, b"2047"); + check(2048i64, b"2048"); + check(2049i64, b"2049"); + check(4095i64, b"4095"); + check(4096i64, b"4096"); + check(4097i64, b"4097"); + check(8191i64, b"8191"); + check(8192i64, b"8192"); + check(8193i64, b"8193"); + check(9999i64, b"9999"); + check(10000i64, b"10000"); + check(10001i64, b"10001"); + check(16383i64, b"16383"); + check(16384i64, b"16384"); + check(16385i64, b"16385"); + check(32767i64, b"32767"); + check(32768i64, b"32768"); + check(32769i64, b"32769"); + check(65535i64, b"65535"); + check(65536i64, b"65536"); + check(65537i64, b"65537"); + check(99999i64, b"99999"); + check(100000i64, b"100000"); + check(100001i64, b"100001"); + check(131071i64, b"131071"); + check(131072i64, b"131072"); + check(131073i64, b"131073"); + check(262143i64, b"262143"); + check(262144i64, b"262144"); + check(262145i64, b"262145"); + check(524287i64, b"524287"); + check(524288i64, b"524288"); + check(524289i64, b"524289"); + check(999999i64, b"999999"); + check(1000000i64, b"1000000"); + check(1000001i64, b"1000001"); + check(1048575i64, b"1048575"); + check(1048576i64, b"1048576"); + check(1048577i64, b"1048577"); + check(2097151i64, b"2097151"); + check(2097152i64, b"2097152"); + check(2097153i64, b"2097153"); + check(4194303i64, b"4194303"); + check(4194304i64, b"4194304"); + check(4194305i64, b"4194305"); + check(8388607i64, b"8388607"); + check(8388608i64, b"8388608"); + check(8388609i64, b"8388609"); + check(9999999i64, b"9999999"); + check(10000000i64, b"10000000"); + check(10000001i64, b"10000001"); + check(16777215i64, b"16777215"); + check(16777216i64, b"16777216"); + check(16777217i64, b"16777217"); + check(33554431i64, b"33554431"); + check(33554432i64, b"33554432"); + check(33554433i64, b"33554433"); + check(67108863i64, b"67108863"); + check(67108864i64, b"67108864"); + check(67108865i64, b"67108865"); + check(99999999i64, b"99999999"); + check(100000000i64, b"100000000"); + check(100000001i64, b"100000001"); + check(134217727i64, b"134217727"); + check(134217728i64, b"134217728"); + check(134217729i64, b"134217729"); + check(268435455i64, b"268435455"); + check(268435456i64, b"268435456"); + check(268435457i64, b"268435457"); + check(536870911i64, b"536870911"); + check(536870912i64, b"536870912"); + check(536870913i64, b"536870913"); + check(999999999i64, b"999999999"); + check(1000000000i64, b"1000000000"); + check(1000000001i64, b"1000000001"); + check(1073741823i64, b"1073741823"); + check(1073741824i64, b"1073741824"); + check(1073741825i64, b"1073741825"); + check(2147483647i64, b"2147483647"); + check(2147483648i64, b"2147483648"); + check(2147483649i64, b"2147483649"); + check(4294967295i64, b"4294967295"); + check(4294967296i64, b"4294967296"); + check(4294967297i64, b"4294967297"); + check(8589934591i64, b"8589934591"); + check(8589934592i64, b"8589934592"); + check(8589934593i64, b"8589934593"); + check(9999999999i64, b"9999999999"); + check(10000000000i64, b"10000000000"); + check(10000000001i64, b"10000000001"); + check(17179869183i64, b"17179869183"); + check(17179869184i64, b"17179869184"); + check(17179869185i64, b"17179869185"); + check(34359738367i64, b"34359738367"); + check(34359738368i64, b"34359738368"); + check(34359738369i64, b"34359738369"); + check(68719476735i64, b"68719476735"); + check(68719476736i64, b"68719476736"); + check(68719476737i64, b"68719476737"); + check(99999999999i64, b"99999999999"); + check(100000000000i64, b"100000000000"); + check(100000000001i64, b"100000000001"); + check(137438953471i64, b"137438953471"); + check(137438953472i64, b"137438953472"); + check(137438953473i64, b"137438953473"); + check(274877906943i64, b"274877906943"); + check(274877906944i64, b"274877906944"); + check(274877906945i64, b"274877906945"); + check(549755813887i64, b"549755813887"); + check(549755813888i64, b"549755813888"); + check(549755813889i64, b"549755813889"); + check(999999999999i64, b"999999999999"); + check(1000000000000i64, b"1000000000000"); + check(1000000000001i64, b"1000000000001"); + check(1099511627775i64, b"1099511627775"); + check(1099511627776i64, b"1099511627776"); + check(1099511627777i64, b"1099511627777"); + check(2199023255551i64, b"2199023255551"); + check(2199023255552i64, b"2199023255552"); + check(2199023255553i64, b"2199023255553"); + check(4398046511103i64, b"4398046511103"); + check(4398046511104i64, b"4398046511104"); + check(4398046511105i64, b"4398046511105"); + check(8796093022207i64, b"8796093022207"); + check(8796093022208i64, b"8796093022208"); + check(8796093022209i64, b"8796093022209"); + check(9999999999999i64, b"9999999999999"); + check(10000000000000i64, b"10000000000000"); + check(10000000000001i64, b"10000000000001"); + check(17592186044415i64, b"17592186044415"); + check(17592186044416i64, b"17592186044416"); + check(17592186044417i64, b"17592186044417"); + check(35184372088831i64, b"35184372088831"); + check(35184372088832i64, b"35184372088832"); + check(35184372088833i64, b"35184372088833"); + check(70368744177663i64, b"70368744177663"); + check(70368744177664i64, b"70368744177664"); + check(70368744177665i64, b"70368744177665"); + check(99999999999999i64, b"99999999999999"); + check(100000000000000i64, b"100000000000000"); + check(100000000000001i64, b"100000000000001"); + check(140737488355327i64, b"140737488355327"); + check(140737488355328i64, b"140737488355328"); + check(140737488355329i64, b"140737488355329"); + check(281474976710655i64, b"281474976710655"); + check(281474976710656i64, b"281474976710656"); + check(281474976710657i64, b"281474976710657"); + check(562949953421311i64, b"562949953421311"); + check(562949953421312i64, b"562949953421312"); + check(562949953421313i64, b"562949953421313"); + check(999999999999999i64, b"999999999999999"); + check(1000000000000000i64, b"1000000000000000"); + check(1000000000000001i64, b"1000000000000001"); + check(1125899906842623i64, b"1125899906842623"); + check(1125899906842624i64, b"1125899906842624"); + check(1125899906842625i64, b"1125899906842625"); + check(2251799813685247i64, b"2251799813685247"); + check(2251799813685248i64, b"2251799813685248"); + check(2251799813685249i64, b"2251799813685249"); + check(4503599627370495i64, b"4503599627370495"); + check(4503599627370496i64, b"4503599627370496"); + check(4503599627370497i64, b"4503599627370497"); + check(9007199254740991i64, b"9007199254740991"); + check(9007199254740992i64, b"9007199254740992"); + check(9007199254740993i64, b"9007199254740993"); + check(9999999999999999i64, b"9999999999999999"); + check(10000000000000000i64, b"10000000000000000"); + check(10000000000000001i64, b"10000000000000001"); + check(18014398509481983i64, b"18014398509481983"); + check(18014398509481984i64, b"18014398509481984"); + check(18014398509481985i64, b"18014398509481985"); + check(36028797018963967i64, b"36028797018963967"); + check(36028797018963968i64, b"36028797018963968"); + check(36028797018963969i64, b"36028797018963969"); + check(72057594037927935i64, b"72057594037927935"); + check(72057594037927936i64, b"72057594037927936"); + check(72057594037927937i64, b"72057594037927937"); + check(99999999999999999i64, b"99999999999999999"); + check(100000000000000000i64, b"100000000000000000"); + check(100000000000000001i64, b"100000000000000001"); + check(144115188075855871i64, b"144115188075855871"); + check(144115188075855872i64, b"144115188075855872"); + check(144115188075855873i64, b"144115188075855873"); + check(253292627452887239i64, b"253292627452887239"); + check(288230376151711743i64, b"288230376151711743"); + check(288230376151711744i64, b"288230376151711744"); + check(288230376151711745i64, b"288230376151711745"); + check(576460752303423487i64, b"576460752303423487"); + check(576460752303423488i64, b"576460752303423488"); + check(576460752303423489i64, b"576460752303423489"); + check(999999999999999999i64, b"999999999999999999"); + check(1000000000000000000i64, b"1000000000000000000"); + check(1000000000000000001i64, b"1000000000000000001"); + check(1152921504606846975i64, b"1152921504606846975"); + check(1152921504606846976i64, b"1152921504606846976"); + check(1152921504606846977i64, b"1152921504606846977"); + check(1779373561758428289i64, b"1779373561758428289"); + check(1918875392190302266i64, b"1918875392190302266"); + check(1964819683467062741i64, b"1964819683467062741"); + check(2181996174858958743i64, b"2181996174858958743"); + check(2305843009213693951i64, b"2305843009213693951"); + check(2305843009213693952i64, b"2305843009213693952"); + check(2305843009213693953i64, b"2305843009213693953"); + check(2395990555469872943i64, b"2395990555469872943"); + check(2942703002681949929i64, b"2942703002681949929"); + check(3222271663937675830i64, b"3222271663937675830"); + check(3660992601043197614i64, b"3660992601043197614"); + check(3861594818318916497i64, b"3861594818318916497"); + check(3869189413169762050i64, b"3869189413169762050"); + check(4358181693715673361i64, b"4358181693715673361"); + check(4611686018427387903i64, b"4611686018427387903"); + check(4611686018427387904i64, b"4611686018427387904"); + check(4611686018427387905i64, b"4611686018427387905"); + check(5051844181780778935i64, b"5051844181780778935"); + check(5281330341569806731i64, b"5281330341569806731"); + check(5600760056953198506i64, b"5600760056953198506"); + check(6307099386378364894i64, b"6307099386378364894"); + check(6472241654744496554i64, b"6472241654744496554"); + check(7384412550790166007i64, b"7384412550790166007"); + check(7960147437111475408i64, b"7960147437111475408"); + check(8019800572464344819i64, b"8019800572464344819"); + check(8601570958497122972i64, b"8601570958497122972"); + check(8741427099435404153i64, b"8741427099435404153"); + check(8840889545696419459i64, b"8840889545696419459"); + check(9223372036854775807i64, b"9223372036854775807"); + return 1; +} diff --git a/tests/conformance/source/std/fmt_immutable.aji b/tests/conformance/source/std/fmt_immutable.aji new file mode 100644 index 0000000..2aeed07 --- /dev/null +++ b/tests/conformance/source/std/fmt_immutable.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +import std.fmt; +fn main() -> u8 effects [] { var buf: [u8; 4] = zero; let result = std.fmt.write_u64(ref buf, 1); return 0; } diff --git a/tests/conformance/source/std/fmt_incomplete.aji b/tests/conformance/source/std/fmt_incomplete.aji new file mode 100644 index 0000000..cfc6ac2 --- /dev/null +++ b/tests/conformance/source/std/fmt_incomplete.aji @@ -0,0 +1,6 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +import std.fmt; +fn main() -> u8 effects [] { var buf: [u8; 4] = zero; match std.fmt.write_u64(mut buf, 1) { std.fmt.WriteResult::ok(count) => {} } return 0; } diff --git a/tests/conformance/source/std/fmt_isize_vectors.aji b/tests/conformance/source/std/fmt_isize_vectors.aji new file mode 100644 index 0000000..02b3dab --- /dev/null +++ b/tests/conformance/source/std/fmt_isize_vectors.aji @@ -0,0 +1,1023 @@ +// expect: run +// result: 1 +// fuel: 20000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +// Decimal oracle: Python str(value); fixed seed 202010. Small values, powers +// of ten/two and their neighbors, signed limits, and 48 seeded unsigned inputs. +module test.fmt_isize +import std.fmt; + +fn check(value: i64, expected: slice) -> void +effects [] +{ + let maximum = ((0usize -% 1usize) >> 1) as! isize; + let minimum = -maximum - 1isize; + if value < minimum as! i64 or value > maximum as! i64 { return; } + for capacity in 0usize..23usize { + var storage: [u8; 26] = [165; 26]; + match std.fmt.write_isize(mut storage[1..1 + capacity], value as! isize) { + std.fmt.WriteResult::ok(count) => { + assert(capacity >= expected.len); + assert(count == expected.len); + for i in 0..count { assert(storage[1 + i] == expected[i]); } + for i in count + 1..storage.len { assert(storage[i] == 165); } + } + std.fmt.WriteResult::short_output => { + assert(capacity < expected.len); + for i in 0..storage.len { assert(storage[i] == 165); } + } + } + assert(storage[0] == 165); + } +} + +fn main() -> u8 +effects [] +{ + check((-9223372036854775807i64 - 1i64), b"-9223372036854775808"); + check(-9223372036854775807i64, b"-9223372036854775807"); + check(-8840889545696419459i64, b"-8840889545696419459"); + check(-8741427099435404153i64, b"-8741427099435404153"); + check(-8601570958497122972i64, b"-8601570958497122972"); + check(-8019800572464344819i64, b"-8019800572464344819"); + check(-7960147437111475408i64, b"-7960147437111475408"); + check(-7384412550790166007i64, b"-7384412550790166007"); + check(-6472241654744496554i64, b"-6472241654744496554"); + check(-6307099386378364894i64, b"-6307099386378364894"); + check(-5600760056953198506i64, b"-5600760056953198506"); + check(-5281330341569806731i64, b"-5281330341569806731"); + check(-5051844181780778935i64, b"-5051844181780778935"); + check(-4611686018427387905i64, b"-4611686018427387905"); + check(-4611686018427387904i64, b"-4611686018427387904"); + check(-4611686018427387903i64, b"-4611686018427387903"); + check(-4358181693715673361i64, b"-4358181693715673361"); + check(-3869189413169762050i64, b"-3869189413169762050"); + check(-3861594818318916497i64, b"-3861594818318916497"); + check(-3660992601043197614i64, b"-3660992601043197614"); + check(-3222271663937675830i64, b"-3222271663937675830"); + check(-2942703002681949929i64, b"-2942703002681949929"); + check(-2395990555469872943i64, b"-2395990555469872943"); + check(-2305843009213693953i64, b"-2305843009213693953"); + check(-2305843009213693952i64, b"-2305843009213693952"); + check(-2305843009213693951i64, b"-2305843009213693951"); + check(-2181996174858958743i64, b"-2181996174858958743"); + check(-1964819683467062741i64, b"-1964819683467062741"); + check(-1918875392190302266i64, b"-1918875392190302266"); + check(-1779373561758428289i64, b"-1779373561758428289"); + check(-1152921504606846977i64, b"-1152921504606846977"); + check(-1152921504606846976i64, b"-1152921504606846976"); + check(-1152921504606846975i64, b"-1152921504606846975"); + check(-1000000000000000001i64, b"-1000000000000000001"); + check(-1000000000000000000i64, b"-1000000000000000000"); + check(-999999999999999999i64, b"-999999999999999999"); + check(-576460752303423489i64, b"-576460752303423489"); + check(-576460752303423488i64, b"-576460752303423488"); + check(-576460752303423487i64, b"-576460752303423487"); + check(-288230376151711745i64, b"-288230376151711745"); + check(-288230376151711744i64, b"-288230376151711744"); + check(-288230376151711743i64, b"-288230376151711743"); + check(-253292627452887239i64, b"-253292627452887239"); + check(-144115188075855873i64, b"-144115188075855873"); + check(-144115188075855872i64, b"-144115188075855872"); + check(-144115188075855871i64, b"-144115188075855871"); + check(-100000000000000001i64, b"-100000000000000001"); + check(-100000000000000000i64, b"-100000000000000000"); + check(-99999999999999999i64, b"-99999999999999999"); + check(-72057594037927937i64, b"-72057594037927937"); + check(-72057594037927936i64, b"-72057594037927936"); + check(-72057594037927935i64, b"-72057594037927935"); + check(-36028797018963969i64, b"-36028797018963969"); + check(-36028797018963968i64, b"-36028797018963968"); + check(-36028797018963967i64, b"-36028797018963967"); + check(-18014398509481985i64, b"-18014398509481985"); + check(-18014398509481984i64, b"-18014398509481984"); + check(-18014398509481983i64, b"-18014398509481983"); + check(-10000000000000001i64, b"-10000000000000001"); + check(-10000000000000000i64, b"-10000000000000000"); + check(-9999999999999999i64, b"-9999999999999999"); + check(-9007199254740993i64, b"-9007199254740993"); + check(-9007199254740992i64, b"-9007199254740992"); + check(-9007199254740991i64, b"-9007199254740991"); + check(-4503599627370497i64, b"-4503599627370497"); + check(-4503599627370496i64, b"-4503599627370496"); + check(-4503599627370495i64, b"-4503599627370495"); + check(-2251799813685249i64, b"-2251799813685249"); + check(-2251799813685248i64, b"-2251799813685248"); + check(-2251799813685247i64, b"-2251799813685247"); + check(-1125899906842625i64, b"-1125899906842625"); + check(-1125899906842624i64, b"-1125899906842624"); + check(-1125899906842623i64, b"-1125899906842623"); + check(-1000000000000001i64, b"-1000000000000001"); + check(-1000000000000000i64, b"-1000000000000000"); + check(-999999999999999i64, b"-999999999999999"); + check(-562949953421313i64, b"-562949953421313"); + check(-562949953421312i64, b"-562949953421312"); + check(-562949953421311i64, b"-562949953421311"); + check(-281474976710657i64, b"-281474976710657"); + check(-281474976710656i64, b"-281474976710656"); + check(-281474976710655i64, b"-281474976710655"); + check(-140737488355329i64, b"-140737488355329"); + check(-140737488355328i64, b"-140737488355328"); + check(-140737488355327i64, b"-140737488355327"); + check(-100000000000001i64, b"-100000000000001"); + check(-100000000000000i64, b"-100000000000000"); + check(-99999999999999i64, b"-99999999999999"); + check(-70368744177665i64, b"-70368744177665"); + check(-70368744177664i64, b"-70368744177664"); + check(-70368744177663i64, b"-70368744177663"); + check(-35184372088833i64, b"-35184372088833"); + check(-35184372088832i64, b"-35184372088832"); + check(-35184372088831i64, b"-35184372088831"); + check(-17592186044417i64, b"-17592186044417"); + check(-17592186044416i64, b"-17592186044416"); + check(-17592186044415i64, b"-17592186044415"); + check(-10000000000001i64, b"-10000000000001"); + check(-10000000000000i64, b"-10000000000000"); + check(-9999999999999i64, b"-9999999999999"); + check(-8796093022209i64, b"-8796093022209"); + check(-8796093022208i64, b"-8796093022208"); + check(-8796093022207i64, b"-8796093022207"); + check(-4398046511105i64, b"-4398046511105"); + check(-4398046511104i64, b"-4398046511104"); + check(-4398046511103i64, b"-4398046511103"); + check(-2199023255553i64, b"-2199023255553"); + check(-2199023255552i64, b"-2199023255552"); + check(-2199023255551i64, b"-2199023255551"); + check(-1099511627777i64, b"-1099511627777"); + check(-1099511627776i64, b"-1099511627776"); + check(-1099511627775i64, b"-1099511627775"); + check(-1000000000001i64, b"-1000000000001"); + check(-1000000000000i64, b"-1000000000000"); + check(-999999999999i64, b"-999999999999"); + check(-549755813889i64, b"-549755813889"); + check(-549755813888i64, b"-549755813888"); + check(-549755813887i64, b"-549755813887"); + check(-274877906945i64, b"-274877906945"); + check(-274877906944i64, b"-274877906944"); + check(-274877906943i64, b"-274877906943"); + check(-137438953473i64, b"-137438953473"); + check(-137438953472i64, b"-137438953472"); + check(-137438953471i64, b"-137438953471"); + check(-100000000001i64, b"-100000000001"); + check(-100000000000i64, b"-100000000000"); + check(-99999999999i64, b"-99999999999"); + check(-68719476737i64, b"-68719476737"); + check(-68719476736i64, b"-68719476736"); + check(-68719476735i64, b"-68719476735"); + check(-34359738369i64, b"-34359738369"); + check(-34359738368i64, b"-34359738368"); + check(-34359738367i64, b"-34359738367"); + check(-17179869185i64, b"-17179869185"); + check(-17179869184i64, b"-17179869184"); + check(-17179869183i64, b"-17179869183"); + check(-10000000001i64, b"-10000000001"); + check(-10000000000i64, b"-10000000000"); + check(-9999999999i64, b"-9999999999"); + check(-8589934593i64, b"-8589934593"); + check(-8589934592i64, b"-8589934592"); + check(-8589934591i64, b"-8589934591"); + check(-4294967297i64, b"-4294967297"); + check(-4294967296i64, b"-4294967296"); + check(-4294967295i64, b"-4294967295"); + check(-2147483649i64, b"-2147483649"); + check(-2147483648i64, b"-2147483648"); + check(-2147483647i64, b"-2147483647"); + check(-1073741825i64, b"-1073741825"); + check(-1073741824i64, b"-1073741824"); + check(-1073741823i64, b"-1073741823"); + check(-1000000001i64, b"-1000000001"); + check(-1000000000i64, b"-1000000000"); + check(-999999999i64, b"-999999999"); + check(-536870913i64, b"-536870913"); + check(-536870912i64, b"-536870912"); + check(-536870911i64, b"-536870911"); + check(-268435457i64, b"-268435457"); + check(-268435456i64, b"-268435456"); + check(-268435455i64, b"-268435455"); + check(-134217729i64, b"-134217729"); + check(-134217728i64, b"-134217728"); + check(-134217727i64, b"-134217727"); + check(-100000001i64, b"-100000001"); + check(-100000000i64, b"-100000000"); + check(-99999999i64, b"-99999999"); + check(-67108865i64, b"-67108865"); + check(-67108864i64, b"-67108864"); + check(-67108863i64, b"-67108863"); + check(-33554433i64, b"-33554433"); + check(-33554432i64, b"-33554432"); + check(-33554431i64, b"-33554431"); + check(-16777217i64, b"-16777217"); + check(-16777216i64, b"-16777216"); + check(-16777215i64, b"-16777215"); + check(-10000001i64, b"-10000001"); + check(-10000000i64, b"-10000000"); + check(-9999999i64, b"-9999999"); + check(-8388609i64, b"-8388609"); + check(-8388608i64, b"-8388608"); + check(-8388607i64, b"-8388607"); + check(-4194305i64, b"-4194305"); + check(-4194304i64, b"-4194304"); + check(-4194303i64, b"-4194303"); + check(-2097153i64, b"-2097153"); + check(-2097152i64, b"-2097152"); + check(-2097151i64, b"-2097151"); + check(-1048577i64, b"-1048577"); + check(-1048576i64, b"-1048576"); + check(-1048575i64, b"-1048575"); + check(-1000001i64, b"-1000001"); + check(-1000000i64, b"-1000000"); + check(-999999i64, b"-999999"); + check(-524289i64, b"-524289"); + check(-524288i64, b"-524288"); + check(-524287i64, b"-524287"); + check(-262145i64, b"-262145"); + check(-262144i64, b"-262144"); + check(-262143i64, b"-262143"); + check(-131073i64, b"-131073"); + check(-131072i64, b"-131072"); + check(-131071i64, b"-131071"); + check(-100001i64, b"-100001"); + check(-100000i64, b"-100000"); + check(-99999i64, b"-99999"); + check(-65537i64, b"-65537"); + check(-65536i64, b"-65536"); + check(-65535i64, b"-65535"); + check(-32769i64, b"-32769"); + check(-32768i64, b"-32768"); + check(-32767i64, b"-32767"); + check(-16385i64, b"-16385"); + check(-16384i64, b"-16384"); + check(-16383i64, b"-16383"); + check(-10001i64, b"-10001"); + check(-10000i64, b"-10000"); + check(-9999i64, b"-9999"); + check(-8193i64, b"-8193"); + check(-8192i64, b"-8192"); + check(-8191i64, b"-8191"); + check(-4097i64, b"-4097"); + check(-4096i64, b"-4096"); + check(-4095i64, b"-4095"); + check(-2049i64, b"-2049"); + check(-2048i64, b"-2048"); + check(-2047i64, b"-2047"); + check(-1025i64, b"-1025"); + check(-1024i64, b"-1024"); + check(-1023i64, b"-1023"); + check(-1001i64, b"-1001"); + check(-1000i64, b"-1000"); + check(-999i64, b"-999"); + check(-513i64, b"-513"); + check(-512i64, b"-512"); + check(-511i64, b"-511"); + check(-257i64, b"-257"); + check(-256i64, b"-256"); + check(-255i64, b"-255"); + check(-254i64, b"-254"); + check(-253i64, b"-253"); + check(-252i64, b"-252"); + check(-251i64, b"-251"); + check(-250i64, b"-250"); + check(-249i64, b"-249"); + check(-248i64, b"-248"); + check(-247i64, b"-247"); + check(-246i64, b"-246"); + check(-245i64, b"-245"); + check(-244i64, b"-244"); + check(-243i64, b"-243"); + check(-242i64, b"-242"); + check(-241i64, b"-241"); + check(-240i64, b"-240"); + check(-239i64, b"-239"); + check(-238i64, b"-238"); + check(-237i64, b"-237"); + check(-236i64, b"-236"); + check(-235i64, b"-235"); + check(-234i64, b"-234"); + check(-233i64, b"-233"); + check(-232i64, b"-232"); + check(-231i64, b"-231"); + check(-230i64, b"-230"); + check(-229i64, b"-229"); + check(-228i64, b"-228"); + check(-227i64, b"-227"); + check(-226i64, b"-226"); + check(-225i64, b"-225"); + check(-224i64, b"-224"); + check(-223i64, b"-223"); + check(-222i64, b"-222"); + check(-221i64, b"-221"); + check(-220i64, b"-220"); + check(-219i64, b"-219"); + check(-218i64, b"-218"); + check(-217i64, b"-217"); + check(-216i64, b"-216"); + check(-215i64, b"-215"); + check(-214i64, b"-214"); + check(-213i64, b"-213"); + check(-212i64, b"-212"); + check(-211i64, b"-211"); + check(-210i64, b"-210"); + check(-209i64, b"-209"); + check(-208i64, b"-208"); + check(-207i64, b"-207"); + check(-206i64, b"-206"); + check(-205i64, b"-205"); + check(-204i64, b"-204"); + check(-203i64, b"-203"); + check(-202i64, b"-202"); + check(-201i64, b"-201"); + check(-200i64, b"-200"); + check(-199i64, b"-199"); + check(-198i64, b"-198"); + check(-197i64, b"-197"); + check(-196i64, b"-196"); + check(-195i64, b"-195"); + check(-194i64, b"-194"); + check(-193i64, b"-193"); + check(-192i64, b"-192"); + check(-191i64, b"-191"); + check(-190i64, b"-190"); + check(-189i64, b"-189"); + check(-188i64, b"-188"); + check(-187i64, b"-187"); + check(-186i64, b"-186"); + check(-185i64, b"-185"); + check(-184i64, b"-184"); + check(-183i64, b"-183"); + check(-182i64, b"-182"); + check(-181i64, b"-181"); + check(-180i64, b"-180"); + check(-179i64, b"-179"); + check(-178i64, b"-178"); + check(-177i64, b"-177"); + check(-176i64, b"-176"); + check(-175i64, b"-175"); + check(-174i64, b"-174"); + check(-173i64, b"-173"); + check(-172i64, b"-172"); + check(-171i64, b"-171"); + check(-170i64, b"-170"); + check(-169i64, b"-169"); + check(-168i64, b"-168"); + check(-167i64, b"-167"); + check(-166i64, b"-166"); + check(-165i64, b"-165"); + check(-164i64, b"-164"); + check(-163i64, b"-163"); + check(-162i64, b"-162"); + check(-161i64, b"-161"); + check(-160i64, b"-160"); + check(-159i64, b"-159"); + check(-158i64, b"-158"); + check(-157i64, b"-157"); + check(-156i64, b"-156"); + check(-155i64, b"-155"); + check(-154i64, b"-154"); + check(-153i64, b"-153"); + check(-152i64, b"-152"); + check(-151i64, b"-151"); + check(-150i64, b"-150"); + check(-149i64, b"-149"); + check(-148i64, b"-148"); + check(-147i64, b"-147"); + check(-146i64, b"-146"); + check(-145i64, b"-145"); + check(-144i64, b"-144"); + check(-143i64, b"-143"); + check(-142i64, b"-142"); + check(-141i64, b"-141"); + check(-140i64, b"-140"); + check(-139i64, b"-139"); + check(-138i64, b"-138"); + check(-137i64, b"-137"); + check(-136i64, b"-136"); + check(-135i64, b"-135"); + check(-134i64, b"-134"); + check(-133i64, b"-133"); + check(-132i64, b"-132"); + check(-131i64, b"-131"); + check(-130i64, b"-130"); + check(-129i64, b"-129"); + check(-128i64, b"-128"); + check(-127i64, b"-127"); + check(-126i64, b"-126"); + check(-125i64, b"-125"); + check(-124i64, b"-124"); + check(-123i64, b"-123"); + check(-122i64, b"-122"); + check(-121i64, b"-121"); + check(-120i64, b"-120"); + check(-119i64, b"-119"); + check(-118i64, b"-118"); + check(-117i64, b"-117"); + check(-116i64, b"-116"); + check(-115i64, b"-115"); + check(-114i64, b"-114"); + check(-113i64, b"-113"); + check(-112i64, b"-112"); + check(-111i64, b"-111"); + check(-110i64, b"-110"); + check(-109i64, b"-109"); + check(-108i64, b"-108"); + check(-107i64, b"-107"); + check(-106i64, b"-106"); + check(-105i64, b"-105"); + check(-104i64, b"-104"); + check(-103i64, b"-103"); + check(-102i64, b"-102"); + check(-101i64, b"-101"); + check(-100i64, b"-100"); + check(-99i64, b"-99"); + check(-98i64, b"-98"); + check(-97i64, b"-97"); + check(-96i64, b"-96"); + check(-95i64, b"-95"); + check(-94i64, b"-94"); + check(-93i64, b"-93"); + check(-92i64, b"-92"); + check(-91i64, b"-91"); + check(-90i64, b"-90"); + check(-89i64, b"-89"); + check(-88i64, b"-88"); + check(-87i64, b"-87"); + check(-86i64, b"-86"); + check(-85i64, b"-85"); + check(-84i64, b"-84"); + check(-83i64, b"-83"); + check(-82i64, b"-82"); + check(-81i64, b"-81"); + check(-80i64, b"-80"); + check(-79i64, b"-79"); + check(-78i64, b"-78"); + check(-77i64, b"-77"); + check(-76i64, b"-76"); + check(-75i64, b"-75"); + check(-74i64, b"-74"); + check(-73i64, b"-73"); + check(-72i64, b"-72"); + check(-71i64, b"-71"); + check(-70i64, b"-70"); + check(-69i64, b"-69"); + check(-68i64, b"-68"); + check(-67i64, b"-67"); + check(-66i64, b"-66"); + check(-65i64, b"-65"); + check(-64i64, b"-64"); + check(-63i64, b"-63"); + check(-62i64, b"-62"); + check(-61i64, b"-61"); + check(-60i64, b"-60"); + check(-59i64, b"-59"); + check(-58i64, b"-58"); + check(-57i64, b"-57"); + check(-56i64, b"-56"); + check(-55i64, b"-55"); + check(-54i64, b"-54"); + check(-53i64, b"-53"); + check(-52i64, b"-52"); + check(-51i64, b"-51"); + check(-50i64, b"-50"); + check(-49i64, b"-49"); + check(-48i64, b"-48"); + check(-47i64, b"-47"); + check(-46i64, b"-46"); + check(-45i64, b"-45"); + check(-44i64, b"-44"); + check(-43i64, b"-43"); + check(-42i64, b"-42"); + check(-41i64, b"-41"); + check(-40i64, b"-40"); + check(-39i64, b"-39"); + check(-38i64, b"-38"); + check(-37i64, b"-37"); + check(-36i64, b"-36"); + check(-35i64, b"-35"); + check(-34i64, b"-34"); + check(-33i64, b"-33"); + check(-32i64, b"-32"); + check(-31i64, b"-31"); + check(-30i64, b"-30"); + check(-29i64, b"-29"); + check(-28i64, b"-28"); + check(-27i64, b"-27"); + check(-26i64, b"-26"); + check(-25i64, b"-25"); + check(-24i64, b"-24"); + check(-23i64, b"-23"); + check(-22i64, b"-22"); + check(-21i64, b"-21"); + check(-20i64, b"-20"); + check(-19i64, b"-19"); + check(-18i64, b"-18"); + check(-17i64, b"-17"); + check(-16i64, b"-16"); + check(-15i64, b"-15"); + check(-14i64, b"-14"); + check(-13i64, b"-13"); + check(-12i64, b"-12"); + check(-11i64, b"-11"); + check(-10i64, b"-10"); + check(-9i64, b"-9"); + check(-8i64, b"-8"); + check(-7i64, b"-7"); + check(-6i64, b"-6"); + check(-5i64, b"-5"); + check(-4i64, b"-4"); + check(-3i64, b"-3"); + check(-2i64, b"-2"); + check(-1i64, b"-1"); + check(0i64, b"0"); + check(1i64, b"1"); + check(2i64, b"2"); + check(3i64, b"3"); + check(4i64, b"4"); + check(5i64, b"5"); + check(6i64, b"6"); + check(7i64, b"7"); + check(8i64, b"8"); + check(9i64, b"9"); + check(10i64, b"10"); + check(11i64, b"11"); + check(12i64, b"12"); + check(13i64, b"13"); + check(14i64, b"14"); + check(15i64, b"15"); + check(16i64, b"16"); + check(17i64, b"17"); + check(18i64, b"18"); + check(19i64, b"19"); + check(20i64, b"20"); + check(21i64, b"21"); + check(22i64, b"22"); + check(23i64, b"23"); + check(24i64, b"24"); + check(25i64, b"25"); + check(26i64, b"26"); + check(27i64, b"27"); + check(28i64, b"28"); + check(29i64, b"29"); + check(30i64, b"30"); + check(31i64, b"31"); + check(32i64, b"32"); + check(33i64, b"33"); + check(34i64, b"34"); + check(35i64, b"35"); + check(36i64, b"36"); + check(37i64, b"37"); + check(38i64, b"38"); + check(39i64, b"39"); + check(40i64, b"40"); + check(41i64, b"41"); + check(42i64, b"42"); + check(43i64, b"43"); + check(44i64, b"44"); + check(45i64, b"45"); + check(46i64, b"46"); + check(47i64, b"47"); + check(48i64, b"48"); + check(49i64, b"49"); + check(50i64, b"50"); + check(51i64, b"51"); + check(52i64, b"52"); + check(53i64, b"53"); + check(54i64, b"54"); + check(55i64, b"55"); + check(56i64, b"56"); + check(57i64, b"57"); + check(58i64, b"58"); + check(59i64, b"59"); + check(60i64, b"60"); + check(61i64, b"61"); + check(62i64, b"62"); + check(63i64, b"63"); + check(64i64, b"64"); + check(65i64, b"65"); + check(66i64, b"66"); + check(67i64, b"67"); + check(68i64, b"68"); + check(69i64, b"69"); + check(70i64, b"70"); + check(71i64, b"71"); + check(72i64, b"72"); + check(73i64, b"73"); + check(74i64, b"74"); + check(75i64, b"75"); + check(76i64, b"76"); + check(77i64, b"77"); + check(78i64, b"78"); + check(79i64, b"79"); + check(80i64, b"80"); + check(81i64, b"81"); + check(82i64, b"82"); + check(83i64, b"83"); + check(84i64, b"84"); + check(85i64, b"85"); + check(86i64, b"86"); + check(87i64, b"87"); + check(88i64, b"88"); + check(89i64, b"89"); + check(90i64, b"90"); + check(91i64, b"91"); + check(92i64, b"92"); + check(93i64, b"93"); + check(94i64, b"94"); + check(95i64, b"95"); + check(96i64, b"96"); + check(97i64, b"97"); + check(98i64, b"98"); + check(99i64, b"99"); + check(100i64, b"100"); + check(101i64, b"101"); + check(102i64, b"102"); + check(103i64, b"103"); + check(104i64, b"104"); + check(105i64, b"105"); + check(106i64, b"106"); + check(107i64, b"107"); + check(108i64, b"108"); + check(109i64, b"109"); + check(110i64, b"110"); + check(111i64, b"111"); + check(112i64, b"112"); + check(113i64, b"113"); + check(114i64, b"114"); + check(115i64, b"115"); + check(116i64, b"116"); + check(117i64, b"117"); + check(118i64, b"118"); + check(119i64, b"119"); + check(120i64, b"120"); + check(121i64, b"121"); + check(122i64, b"122"); + check(123i64, b"123"); + check(124i64, b"124"); + check(125i64, b"125"); + check(126i64, b"126"); + check(127i64, b"127"); + check(128i64, b"128"); + check(129i64, b"129"); + check(130i64, b"130"); + check(131i64, b"131"); + check(132i64, b"132"); + check(133i64, b"133"); + check(134i64, b"134"); + check(135i64, b"135"); + check(136i64, b"136"); + check(137i64, b"137"); + check(138i64, b"138"); + check(139i64, b"139"); + check(140i64, b"140"); + check(141i64, b"141"); + check(142i64, b"142"); + check(143i64, b"143"); + check(144i64, b"144"); + check(145i64, b"145"); + check(146i64, b"146"); + check(147i64, b"147"); + check(148i64, b"148"); + check(149i64, b"149"); + check(150i64, b"150"); + check(151i64, b"151"); + check(152i64, b"152"); + check(153i64, b"153"); + check(154i64, b"154"); + check(155i64, b"155"); + check(156i64, b"156"); + check(157i64, b"157"); + check(158i64, b"158"); + check(159i64, b"159"); + check(160i64, b"160"); + check(161i64, b"161"); + check(162i64, b"162"); + check(163i64, b"163"); + check(164i64, b"164"); + check(165i64, b"165"); + check(166i64, b"166"); + check(167i64, b"167"); + check(168i64, b"168"); + check(169i64, b"169"); + check(170i64, b"170"); + check(171i64, b"171"); + check(172i64, b"172"); + check(173i64, b"173"); + check(174i64, b"174"); + check(175i64, b"175"); + check(176i64, b"176"); + check(177i64, b"177"); + check(178i64, b"178"); + check(179i64, b"179"); + check(180i64, b"180"); + check(181i64, b"181"); + check(182i64, b"182"); + check(183i64, b"183"); + check(184i64, b"184"); + check(185i64, b"185"); + check(186i64, b"186"); + check(187i64, b"187"); + check(188i64, b"188"); + check(189i64, b"189"); + check(190i64, b"190"); + check(191i64, b"191"); + check(192i64, b"192"); + check(193i64, b"193"); + check(194i64, b"194"); + check(195i64, b"195"); + check(196i64, b"196"); + check(197i64, b"197"); + check(198i64, b"198"); + check(199i64, b"199"); + check(200i64, b"200"); + check(201i64, b"201"); + check(202i64, b"202"); + check(203i64, b"203"); + check(204i64, b"204"); + check(205i64, b"205"); + check(206i64, b"206"); + check(207i64, b"207"); + check(208i64, b"208"); + check(209i64, b"209"); + check(210i64, b"210"); + check(211i64, b"211"); + check(212i64, b"212"); + check(213i64, b"213"); + check(214i64, b"214"); + check(215i64, b"215"); + check(216i64, b"216"); + check(217i64, b"217"); + check(218i64, b"218"); + check(219i64, b"219"); + check(220i64, b"220"); + check(221i64, b"221"); + check(222i64, b"222"); + check(223i64, b"223"); + check(224i64, b"224"); + check(225i64, b"225"); + check(226i64, b"226"); + check(227i64, b"227"); + check(228i64, b"228"); + check(229i64, b"229"); + check(230i64, b"230"); + check(231i64, b"231"); + check(232i64, b"232"); + check(233i64, b"233"); + check(234i64, b"234"); + check(235i64, b"235"); + check(236i64, b"236"); + check(237i64, b"237"); + check(238i64, b"238"); + check(239i64, b"239"); + check(240i64, b"240"); + check(241i64, b"241"); + check(242i64, b"242"); + check(243i64, b"243"); + check(244i64, b"244"); + check(245i64, b"245"); + check(246i64, b"246"); + check(247i64, b"247"); + check(248i64, b"248"); + check(249i64, b"249"); + check(250i64, b"250"); + check(251i64, b"251"); + check(252i64, b"252"); + check(253i64, b"253"); + check(254i64, b"254"); + check(255i64, b"255"); + check(256i64, b"256"); + check(257i64, b"257"); + check(511i64, b"511"); + check(512i64, b"512"); + check(513i64, b"513"); + check(999i64, b"999"); + check(1000i64, b"1000"); + check(1001i64, b"1001"); + check(1023i64, b"1023"); + check(1024i64, b"1024"); + check(1025i64, b"1025"); + check(2047i64, b"2047"); + check(2048i64, b"2048"); + check(2049i64, b"2049"); + check(4095i64, b"4095"); + check(4096i64, b"4096"); + check(4097i64, b"4097"); + check(8191i64, b"8191"); + check(8192i64, b"8192"); + check(8193i64, b"8193"); + check(9999i64, b"9999"); + check(10000i64, b"10000"); + check(10001i64, b"10001"); + check(16383i64, b"16383"); + check(16384i64, b"16384"); + check(16385i64, b"16385"); + check(32767i64, b"32767"); + check(32768i64, b"32768"); + check(32769i64, b"32769"); + check(65535i64, b"65535"); + check(65536i64, b"65536"); + check(65537i64, b"65537"); + check(99999i64, b"99999"); + check(100000i64, b"100000"); + check(100001i64, b"100001"); + check(131071i64, b"131071"); + check(131072i64, b"131072"); + check(131073i64, b"131073"); + check(262143i64, b"262143"); + check(262144i64, b"262144"); + check(262145i64, b"262145"); + check(524287i64, b"524287"); + check(524288i64, b"524288"); + check(524289i64, b"524289"); + check(999999i64, b"999999"); + check(1000000i64, b"1000000"); + check(1000001i64, b"1000001"); + check(1048575i64, b"1048575"); + check(1048576i64, b"1048576"); + check(1048577i64, b"1048577"); + check(2097151i64, b"2097151"); + check(2097152i64, b"2097152"); + check(2097153i64, b"2097153"); + check(4194303i64, b"4194303"); + check(4194304i64, b"4194304"); + check(4194305i64, b"4194305"); + check(8388607i64, b"8388607"); + check(8388608i64, b"8388608"); + check(8388609i64, b"8388609"); + check(9999999i64, b"9999999"); + check(10000000i64, b"10000000"); + check(10000001i64, b"10000001"); + check(16777215i64, b"16777215"); + check(16777216i64, b"16777216"); + check(16777217i64, b"16777217"); + check(33554431i64, b"33554431"); + check(33554432i64, b"33554432"); + check(33554433i64, b"33554433"); + check(67108863i64, b"67108863"); + check(67108864i64, b"67108864"); + check(67108865i64, b"67108865"); + check(99999999i64, b"99999999"); + check(100000000i64, b"100000000"); + check(100000001i64, b"100000001"); + check(134217727i64, b"134217727"); + check(134217728i64, b"134217728"); + check(134217729i64, b"134217729"); + check(268435455i64, b"268435455"); + check(268435456i64, b"268435456"); + check(268435457i64, b"268435457"); + check(536870911i64, b"536870911"); + check(536870912i64, b"536870912"); + check(536870913i64, b"536870913"); + check(999999999i64, b"999999999"); + check(1000000000i64, b"1000000000"); + check(1000000001i64, b"1000000001"); + check(1073741823i64, b"1073741823"); + check(1073741824i64, b"1073741824"); + check(1073741825i64, b"1073741825"); + check(2147483647i64, b"2147483647"); + check(2147483648i64, b"2147483648"); + check(2147483649i64, b"2147483649"); + check(4294967295i64, b"4294967295"); + check(4294967296i64, b"4294967296"); + check(4294967297i64, b"4294967297"); + check(8589934591i64, b"8589934591"); + check(8589934592i64, b"8589934592"); + check(8589934593i64, b"8589934593"); + check(9999999999i64, b"9999999999"); + check(10000000000i64, b"10000000000"); + check(10000000001i64, b"10000000001"); + check(17179869183i64, b"17179869183"); + check(17179869184i64, b"17179869184"); + check(17179869185i64, b"17179869185"); + check(34359738367i64, b"34359738367"); + check(34359738368i64, b"34359738368"); + check(34359738369i64, b"34359738369"); + check(68719476735i64, b"68719476735"); + check(68719476736i64, b"68719476736"); + check(68719476737i64, b"68719476737"); + check(99999999999i64, b"99999999999"); + check(100000000000i64, b"100000000000"); + check(100000000001i64, b"100000000001"); + check(137438953471i64, b"137438953471"); + check(137438953472i64, b"137438953472"); + check(137438953473i64, b"137438953473"); + check(274877906943i64, b"274877906943"); + check(274877906944i64, b"274877906944"); + check(274877906945i64, b"274877906945"); + check(549755813887i64, b"549755813887"); + check(549755813888i64, b"549755813888"); + check(549755813889i64, b"549755813889"); + check(999999999999i64, b"999999999999"); + check(1000000000000i64, b"1000000000000"); + check(1000000000001i64, b"1000000000001"); + check(1099511627775i64, b"1099511627775"); + check(1099511627776i64, b"1099511627776"); + check(1099511627777i64, b"1099511627777"); + check(2199023255551i64, b"2199023255551"); + check(2199023255552i64, b"2199023255552"); + check(2199023255553i64, b"2199023255553"); + check(4398046511103i64, b"4398046511103"); + check(4398046511104i64, b"4398046511104"); + check(4398046511105i64, b"4398046511105"); + check(8796093022207i64, b"8796093022207"); + check(8796093022208i64, b"8796093022208"); + check(8796093022209i64, b"8796093022209"); + check(9999999999999i64, b"9999999999999"); + check(10000000000000i64, b"10000000000000"); + check(10000000000001i64, b"10000000000001"); + check(17592186044415i64, b"17592186044415"); + check(17592186044416i64, b"17592186044416"); + check(17592186044417i64, b"17592186044417"); + check(35184372088831i64, b"35184372088831"); + check(35184372088832i64, b"35184372088832"); + check(35184372088833i64, b"35184372088833"); + check(70368744177663i64, b"70368744177663"); + check(70368744177664i64, b"70368744177664"); + check(70368744177665i64, b"70368744177665"); + check(99999999999999i64, b"99999999999999"); + check(100000000000000i64, b"100000000000000"); + check(100000000000001i64, b"100000000000001"); + check(140737488355327i64, b"140737488355327"); + check(140737488355328i64, b"140737488355328"); + check(140737488355329i64, b"140737488355329"); + check(281474976710655i64, b"281474976710655"); + check(281474976710656i64, b"281474976710656"); + check(281474976710657i64, b"281474976710657"); + check(562949953421311i64, b"562949953421311"); + check(562949953421312i64, b"562949953421312"); + check(562949953421313i64, b"562949953421313"); + check(999999999999999i64, b"999999999999999"); + check(1000000000000000i64, b"1000000000000000"); + check(1000000000000001i64, b"1000000000000001"); + check(1125899906842623i64, b"1125899906842623"); + check(1125899906842624i64, b"1125899906842624"); + check(1125899906842625i64, b"1125899906842625"); + check(2251799813685247i64, b"2251799813685247"); + check(2251799813685248i64, b"2251799813685248"); + check(2251799813685249i64, b"2251799813685249"); + check(4503599627370495i64, b"4503599627370495"); + check(4503599627370496i64, b"4503599627370496"); + check(4503599627370497i64, b"4503599627370497"); + check(9007199254740991i64, b"9007199254740991"); + check(9007199254740992i64, b"9007199254740992"); + check(9007199254740993i64, b"9007199254740993"); + check(9999999999999999i64, b"9999999999999999"); + check(10000000000000000i64, b"10000000000000000"); + check(10000000000000001i64, b"10000000000000001"); + check(18014398509481983i64, b"18014398509481983"); + check(18014398509481984i64, b"18014398509481984"); + check(18014398509481985i64, b"18014398509481985"); + check(36028797018963967i64, b"36028797018963967"); + check(36028797018963968i64, b"36028797018963968"); + check(36028797018963969i64, b"36028797018963969"); + check(72057594037927935i64, b"72057594037927935"); + check(72057594037927936i64, b"72057594037927936"); + check(72057594037927937i64, b"72057594037927937"); + check(99999999999999999i64, b"99999999999999999"); + check(100000000000000000i64, b"100000000000000000"); + check(100000000000000001i64, b"100000000000000001"); + check(144115188075855871i64, b"144115188075855871"); + check(144115188075855872i64, b"144115188075855872"); + check(144115188075855873i64, b"144115188075855873"); + check(253292627452887239i64, b"253292627452887239"); + check(288230376151711743i64, b"288230376151711743"); + check(288230376151711744i64, b"288230376151711744"); + check(288230376151711745i64, b"288230376151711745"); + check(576460752303423487i64, b"576460752303423487"); + check(576460752303423488i64, b"576460752303423488"); + check(576460752303423489i64, b"576460752303423489"); + check(999999999999999999i64, b"999999999999999999"); + check(1000000000000000000i64, b"1000000000000000000"); + check(1000000000000000001i64, b"1000000000000000001"); + check(1152921504606846975i64, b"1152921504606846975"); + check(1152921504606846976i64, b"1152921504606846976"); + check(1152921504606846977i64, b"1152921504606846977"); + check(1779373561758428289i64, b"1779373561758428289"); + check(1918875392190302266i64, b"1918875392190302266"); + check(1964819683467062741i64, b"1964819683467062741"); + check(2181996174858958743i64, b"2181996174858958743"); + check(2305843009213693951i64, b"2305843009213693951"); + check(2305843009213693952i64, b"2305843009213693952"); + check(2305843009213693953i64, b"2305843009213693953"); + check(2395990555469872943i64, b"2395990555469872943"); + check(2942703002681949929i64, b"2942703002681949929"); + check(3222271663937675830i64, b"3222271663937675830"); + check(3660992601043197614i64, b"3660992601043197614"); + check(3861594818318916497i64, b"3861594818318916497"); + check(3869189413169762050i64, b"3869189413169762050"); + check(4358181693715673361i64, b"4358181693715673361"); + check(4611686018427387903i64, b"4611686018427387903"); + check(4611686018427387904i64, b"4611686018427387904"); + check(4611686018427387905i64, b"4611686018427387905"); + check(5051844181780778935i64, b"5051844181780778935"); + check(5281330341569806731i64, b"5281330341569806731"); + check(5600760056953198506i64, b"5600760056953198506"); + check(6307099386378364894i64, b"6307099386378364894"); + check(6472241654744496554i64, b"6472241654744496554"); + check(7384412550790166007i64, b"7384412550790166007"); + check(7960147437111475408i64, b"7960147437111475408"); + check(8019800572464344819i64, b"8019800572464344819"); + check(8601570958497122972i64, b"8601570958497122972"); + check(8741427099435404153i64, b"8741427099435404153"); + check(8840889545696419459i64, b"8840889545696419459"); + check(9223372036854775807i64, b"9223372036854775807"); + return 1; +} diff --git a/tests/conformance/source/std/fmt_missing_import.aji b/tests/conformance/source/std/fmt_missing_import.aji new file mode 100644 index 0000000..b7773ca --- /dev/null +++ b/tests/conformance/source/std/fmt_missing_import.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +fn main() -> u8 effects [] { var buf: [u8; 4] = zero; let result = std.fmt.write_u64(mut buf, 1); return 0; } diff --git a/tests/conformance/source/std/fmt_namespace.aji b/tests/conformance/source/std/fmt_namespace.aji new file mode 100644 index 0000000..e7e7c87 --- /dev/null +++ b/tests/conformance/source/std/fmt_namespace.aji @@ -0,0 +1,30 @@ +// expect: run +// result: 1 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8; docs/spec/15-source-language.md §13 +module test.fmt_namespace +import std.fmt; +import std.bytes; +enum __aji_std_fmt_WriteResult { local } +fn __aji_std_fmt_write_u64() -> u8 effects [] { return 7; } +fn check(result: std.fmt.WriteResult) -> usize effects [] { + match result { + std.fmt.WriteResult::ok(count) => { return count; } + std.fmt.WriteResult::short_output => { return 0; } + } +} +fn main() -> u8 effects [] { + var buf: [u8; 6] = [165; 6]; + let std = 7u8; + { mut all = buf; + let (left, right) = all.split_at(3); + ref held = right; + let result: std.fmt.WriteResult = std.fmt.write_i64(mut left, -12); + assert(check(result) == 3); + assert(held[0] == 165); + } + assert(std.bytes.equal(ref buf[0..3], b"-12")); + assert(__aji_std_fmt_write_u64() == std); + assert(check(std.fmt.WriteResult::short_output) == 0); + return 1; +} diff --git a/tests/conformance/source/std/fmt_payload.aji b/tests/conformance/source/std/fmt_payload.aji new file mode 100644 index 0000000..4c1b813 --- /dev/null +++ b/tests/conformance/source/std/fmt_payload.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +import std.fmt; +fn main() -> u8 effects [] { let result: std.fmt.WriteResult = std.fmt.WriteResult::ok(true); return 0; } diff --git a/tests/conformance/source/std/fmt_u64_vectors.aji b/tests/conformance/source/std/fmt_u64_vectors.aji new file mode 100644 index 0000000..d2ccbb1 --- /dev/null +++ b/tests/conformance/source/std/fmt_u64_vectors.aji @@ -0,0 +1,559 @@ +// expect: run +// result: 1 +// fuel: 20000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +// Decimal oracle: Python str(value); fixed seed 202010. Small values, powers +// of ten/two and their neighbors, signed limits, and 48 seeded unsigned inputs. +module test.fmt_u64 +import std.fmt; + +fn check(value: u64, expected: slice) -> void +effects [] +{ + for capacity in 0usize..23usize { + var storage: [u8; 26] = [165; 26]; + match std.fmt.write_u64(mut storage[1..1 + capacity], value as! u64) { + std.fmt.WriteResult::ok(count) => { + assert(capacity >= expected.len); + assert(count == expected.len); + for i in 0..count { assert(storage[1 + i] == expected[i]); } + for i in count + 1..storage.len { assert(storage[i] == 165); } + } + std.fmt.WriteResult::short_output => { + assert(capacity < expected.len); + for i in 0..storage.len { assert(storage[i] == 165); } + } + } + assert(storage[0] == 165); + } +} + +fn main() -> u8 +effects [] +{ + check(0u64, b"0"); + check(1u64, b"1"); + check(2u64, b"2"); + check(3u64, b"3"); + check(4u64, b"4"); + check(5u64, b"5"); + check(6u64, b"6"); + check(7u64, b"7"); + check(8u64, b"8"); + check(9u64, b"9"); + check(10u64, b"10"); + check(11u64, b"11"); + check(12u64, b"12"); + check(13u64, b"13"); + check(14u64, b"14"); + check(15u64, b"15"); + check(16u64, b"16"); + check(17u64, b"17"); + check(18u64, b"18"); + check(19u64, b"19"); + check(20u64, b"20"); + check(21u64, b"21"); + check(22u64, b"22"); + check(23u64, b"23"); + check(24u64, b"24"); + check(25u64, b"25"); + check(26u64, b"26"); + check(27u64, b"27"); + check(28u64, b"28"); + check(29u64, b"29"); + check(30u64, b"30"); + check(31u64, b"31"); + check(32u64, b"32"); + check(33u64, b"33"); + check(34u64, b"34"); + check(35u64, b"35"); + check(36u64, b"36"); + check(37u64, b"37"); + check(38u64, b"38"); + check(39u64, b"39"); + check(40u64, b"40"); + check(41u64, b"41"); + check(42u64, b"42"); + check(43u64, b"43"); + check(44u64, b"44"); + check(45u64, b"45"); + check(46u64, b"46"); + check(47u64, b"47"); + check(48u64, b"48"); + check(49u64, b"49"); + check(50u64, b"50"); + check(51u64, b"51"); + check(52u64, b"52"); + check(53u64, b"53"); + check(54u64, b"54"); + check(55u64, b"55"); + check(56u64, b"56"); + check(57u64, b"57"); + check(58u64, b"58"); + check(59u64, b"59"); + check(60u64, b"60"); + check(61u64, b"61"); + check(62u64, b"62"); + check(63u64, b"63"); + check(64u64, b"64"); + check(65u64, b"65"); + check(66u64, b"66"); + check(67u64, b"67"); + check(68u64, b"68"); + check(69u64, b"69"); + check(70u64, b"70"); + check(71u64, b"71"); + check(72u64, b"72"); + check(73u64, b"73"); + check(74u64, b"74"); + check(75u64, b"75"); + check(76u64, b"76"); + check(77u64, b"77"); + check(78u64, b"78"); + check(79u64, b"79"); + check(80u64, b"80"); + check(81u64, b"81"); + check(82u64, b"82"); + check(83u64, b"83"); + check(84u64, b"84"); + check(85u64, b"85"); + check(86u64, b"86"); + check(87u64, b"87"); + check(88u64, b"88"); + check(89u64, b"89"); + check(90u64, b"90"); + check(91u64, b"91"); + check(92u64, b"92"); + check(93u64, b"93"); + check(94u64, b"94"); + check(95u64, b"95"); + check(96u64, b"96"); + check(97u64, b"97"); + check(98u64, b"98"); + check(99u64, b"99"); + check(100u64, b"100"); + check(101u64, b"101"); + check(102u64, b"102"); + check(103u64, b"103"); + check(104u64, b"104"); + check(105u64, b"105"); + check(106u64, b"106"); + check(107u64, b"107"); + check(108u64, b"108"); + check(109u64, b"109"); + check(110u64, b"110"); + check(111u64, b"111"); + check(112u64, b"112"); + check(113u64, b"113"); + check(114u64, b"114"); + check(115u64, b"115"); + check(116u64, b"116"); + check(117u64, b"117"); + check(118u64, b"118"); + check(119u64, b"119"); + check(120u64, b"120"); + check(121u64, b"121"); + check(122u64, b"122"); + check(123u64, b"123"); + check(124u64, b"124"); + check(125u64, b"125"); + check(126u64, b"126"); + check(127u64, b"127"); + check(128u64, b"128"); + check(129u64, b"129"); + check(130u64, b"130"); + check(131u64, b"131"); + check(132u64, b"132"); + check(133u64, b"133"); + check(134u64, b"134"); + check(135u64, b"135"); + check(136u64, b"136"); + check(137u64, b"137"); + check(138u64, b"138"); + check(139u64, b"139"); + check(140u64, b"140"); + check(141u64, b"141"); + check(142u64, b"142"); + check(143u64, b"143"); + check(144u64, b"144"); + check(145u64, b"145"); + check(146u64, b"146"); + check(147u64, b"147"); + check(148u64, b"148"); + check(149u64, b"149"); + check(150u64, b"150"); + check(151u64, b"151"); + check(152u64, b"152"); + check(153u64, b"153"); + check(154u64, b"154"); + check(155u64, b"155"); + check(156u64, b"156"); + check(157u64, b"157"); + check(158u64, b"158"); + check(159u64, b"159"); + check(160u64, b"160"); + check(161u64, b"161"); + check(162u64, b"162"); + check(163u64, b"163"); + check(164u64, b"164"); + check(165u64, b"165"); + check(166u64, b"166"); + check(167u64, b"167"); + check(168u64, b"168"); + check(169u64, b"169"); + check(170u64, b"170"); + check(171u64, b"171"); + check(172u64, b"172"); + check(173u64, b"173"); + check(174u64, b"174"); + check(175u64, b"175"); + check(176u64, b"176"); + check(177u64, b"177"); + check(178u64, b"178"); + check(179u64, b"179"); + check(180u64, b"180"); + check(181u64, b"181"); + check(182u64, b"182"); + check(183u64, b"183"); + check(184u64, b"184"); + check(185u64, b"185"); + check(186u64, b"186"); + check(187u64, b"187"); + check(188u64, b"188"); + check(189u64, b"189"); + check(190u64, b"190"); + check(191u64, b"191"); + check(192u64, b"192"); + check(193u64, b"193"); + check(194u64, b"194"); + check(195u64, b"195"); + check(196u64, b"196"); + check(197u64, b"197"); + check(198u64, b"198"); + check(199u64, b"199"); + check(200u64, b"200"); + check(201u64, b"201"); + check(202u64, b"202"); + check(203u64, b"203"); + check(204u64, b"204"); + check(205u64, b"205"); + check(206u64, b"206"); + check(207u64, b"207"); + check(208u64, b"208"); + check(209u64, b"209"); + check(210u64, b"210"); + check(211u64, b"211"); + check(212u64, b"212"); + check(213u64, b"213"); + check(214u64, b"214"); + check(215u64, b"215"); + check(216u64, b"216"); + check(217u64, b"217"); + check(218u64, b"218"); + check(219u64, b"219"); + check(220u64, b"220"); + check(221u64, b"221"); + check(222u64, b"222"); + check(223u64, b"223"); + check(224u64, b"224"); + check(225u64, b"225"); + check(226u64, b"226"); + check(227u64, b"227"); + check(228u64, b"228"); + check(229u64, b"229"); + check(230u64, b"230"); + check(231u64, b"231"); + check(232u64, b"232"); + check(233u64, b"233"); + check(234u64, b"234"); + check(235u64, b"235"); + check(236u64, b"236"); + check(237u64, b"237"); + check(238u64, b"238"); + check(239u64, b"239"); + check(240u64, b"240"); + check(241u64, b"241"); + check(242u64, b"242"); + check(243u64, b"243"); + check(244u64, b"244"); + check(245u64, b"245"); + check(246u64, b"246"); + check(247u64, b"247"); + check(248u64, b"248"); + check(249u64, b"249"); + check(250u64, b"250"); + check(251u64, b"251"); + check(252u64, b"252"); + check(253u64, b"253"); + check(254u64, b"254"); + check(255u64, b"255"); + check(256u64, b"256"); + check(257u64, b"257"); + check(511u64, b"511"); + check(512u64, b"512"); + check(513u64, b"513"); + check(999u64, b"999"); + check(1000u64, b"1000"); + check(1001u64, b"1001"); + check(1023u64, b"1023"); + check(1024u64, b"1024"); + check(1025u64, b"1025"); + check(2047u64, b"2047"); + check(2048u64, b"2048"); + check(2049u64, b"2049"); + check(4095u64, b"4095"); + check(4096u64, b"4096"); + check(4097u64, b"4097"); + check(8191u64, b"8191"); + check(8192u64, b"8192"); + check(8193u64, b"8193"); + check(9999u64, b"9999"); + check(10000u64, b"10000"); + check(10001u64, b"10001"); + check(16383u64, b"16383"); + check(16384u64, b"16384"); + check(16385u64, b"16385"); + check(32767u64, b"32767"); + check(32768u64, b"32768"); + check(32769u64, b"32769"); + check(65535u64, b"65535"); + check(65536u64, b"65536"); + check(65537u64, b"65537"); + check(99999u64, b"99999"); + check(100000u64, b"100000"); + check(100001u64, b"100001"); + check(131071u64, b"131071"); + check(131072u64, b"131072"); + check(131073u64, b"131073"); + check(262143u64, b"262143"); + check(262144u64, b"262144"); + check(262145u64, b"262145"); + check(524287u64, b"524287"); + check(524288u64, b"524288"); + check(524289u64, b"524289"); + check(999999u64, b"999999"); + check(1000000u64, b"1000000"); + check(1000001u64, b"1000001"); + check(1048575u64, b"1048575"); + check(1048576u64, b"1048576"); + check(1048577u64, b"1048577"); + check(2097151u64, b"2097151"); + check(2097152u64, b"2097152"); + check(2097153u64, b"2097153"); + check(4194303u64, b"4194303"); + check(4194304u64, b"4194304"); + check(4194305u64, b"4194305"); + check(8388607u64, b"8388607"); + check(8388608u64, b"8388608"); + check(8388609u64, b"8388609"); + check(9999999u64, b"9999999"); + check(10000000u64, b"10000000"); + check(10000001u64, b"10000001"); + check(16777215u64, b"16777215"); + check(16777216u64, b"16777216"); + check(16777217u64, b"16777217"); + check(33554431u64, b"33554431"); + check(33554432u64, b"33554432"); + check(33554433u64, b"33554433"); + check(67108863u64, b"67108863"); + check(67108864u64, b"67108864"); + check(67108865u64, b"67108865"); + check(99999999u64, b"99999999"); + check(100000000u64, b"100000000"); + check(100000001u64, b"100000001"); + check(134217727u64, b"134217727"); + check(134217728u64, b"134217728"); + check(134217729u64, b"134217729"); + check(268435455u64, b"268435455"); + check(268435456u64, b"268435456"); + check(268435457u64, b"268435457"); + check(536870911u64, b"536870911"); + check(536870912u64, b"536870912"); + check(536870913u64, b"536870913"); + check(999999999u64, b"999999999"); + check(1000000000u64, b"1000000000"); + check(1000000001u64, b"1000000001"); + check(1073741823u64, b"1073741823"); + check(1073741824u64, b"1073741824"); + check(1073741825u64, b"1073741825"); + check(2147483647u64, b"2147483647"); + check(2147483648u64, b"2147483648"); + check(2147483649u64, b"2147483649"); + check(4294967295u64, b"4294967295"); + check(4294967296u64, b"4294967296"); + check(4294967297u64, b"4294967297"); + check(8589934591u64, b"8589934591"); + check(8589934592u64, b"8589934592"); + check(8589934593u64, b"8589934593"); + check(9999999999u64, b"9999999999"); + check(10000000000u64, b"10000000000"); + check(10000000001u64, b"10000000001"); + check(17179869183u64, b"17179869183"); + check(17179869184u64, b"17179869184"); + check(17179869185u64, b"17179869185"); + check(34359738367u64, b"34359738367"); + check(34359738368u64, b"34359738368"); + check(34359738369u64, b"34359738369"); + check(68719476735u64, b"68719476735"); + check(68719476736u64, b"68719476736"); + check(68719476737u64, b"68719476737"); + check(99999999999u64, b"99999999999"); + check(100000000000u64, b"100000000000"); + check(100000000001u64, b"100000000001"); + check(137438953471u64, b"137438953471"); + check(137438953472u64, b"137438953472"); + check(137438953473u64, b"137438953473"); + check(274877906943u64, b"274877906943"); + check(274877906944u64, b"274877906944"); + check(274877906945u64, b"274877906945"); + check(549755813887u64, b"549755813887"); + check(549755813888u64, b"549755813888"); + check(549755813889u64, b"549755813889"); + check(999999999999u64, b"999999999999"); + check(1000000000000u64, b"1000000000000"); + check(1000000000001u64, b"1000000000001"); + check(1099511627775u64, b"1099511627775"); + check(1099511627776u64, b"1099511627776"); + check(1099511627777u64, b"1099511627777"); + check(2199023255551u64, b"2199023255551"); + check(2199023255552u64, b"2199023255552"); + check(2199023255553u64, b"2199023255553"); + check(4398046511103u64, b"4398046511103"); + check(4398046511104u64, b"4398046511104"); + check(4398046511105u64, b"4398046511105"); + check(8796093022207u64, b"8796093022207"); + check(8796093022208u64, b"8796093022208"); + check(8796093022209u64, b"8796093022209"); + check(9999999999999u64, b"9999999999999"); + check(10000000000000u64, b"10000000000000"); + check(10000000000001u64, b"10000000000001"); + check(17592186044415u64, b"17592186044415"); + check(17592186044416u64, b"17592186044416"); + check(17592186044417u64, b"17592186044417"); + check(35184372088831u64, b"35184372088831"); + check(35184372088832u64, b"35184372088832"); + check(35184372088833u64, b"35184372088833"); + check(70368744177663u64, b"70368744177663"); + check(70368744177664u64, b"70368744177664"); + check(70368744177665u64, b"70368744177665"); + check(99999999999999u64, b"99999999999999"); + check(100000000000000u64, b"100000000000000"); + check(100000000000001u64, b"100000000000001"); + check(140737488355327u64, b"140737488355327"); + check(140737488355328u64, b"140737488355328"); + check(140737488355329u64, b"140737488355329"); + check(281474976710655u64, b"281474976710655"); + check(281474976710656u64, b"281474976710656"); + check(281474976710657u64, b"281474976710657"); + check(562949953421311u64, b"562949953421311"); + check(562949953421312u64, b"562949953421312"); + check(562949953421313u64, b"562949953421313"); + check(999999999999999u64, b"999999999999999"); + check(1000000000000000u64, b"1000000000000000"); + check(1000000000000001u64, b"1000000000000001"); + check(1125899906842623u64, b"1125899906842623"); + check(1125899906842624u64, b"1125899906842624"); + check(1125899906842625u64, b"1125899906842625"); + check(2251799813685247u64, b"2251799813685247"); + check(2251799813685248u64, b"2251799813685248"); + check(2251799813685249u64, b"2251799813685249"); + check(4503599627370495u64, b"4503599627370495"); + check(4503599627370496u64, b"4503599627370496"); + check(4503599627370497u64, b"4503599627370497"); + check(9007199254740991u64, b"9007199254740991"); + check(9007199254740992u64, b"9007199254740992"); + check(9007199254740993u64, b"9007199254740993"); + check(9999999999999999u64, b"9999999999999999"); + check(10000000000000000u64, b"10000000000000000"); + check(10000000000000001u64, b"10000000000000001"); + check(18014398509481983u64, b"18014398509481983"); + check(18014398509481984u64, b"18014398509481984"); + check(18014398509481985u64, b"18014398509481985"); + check(36028797018963967u64, b"36028797018963967"); + check(36028797018963968u64, b"36028797018963968"); + check(36028797018963969u64, b"36028797018963969"); + check(72057594037927935u64, b"72057594037927935"); + check(72057594037927936u64, b"72057594037927936"); + check(72057594037927937u64, b"72057594037927937"); + check(99999999999999999u64, b"99999999999999999"); + check(100000000000000000u64, b"100000000000000000"); + check(100000000000000001u64, b"100000000000000001"); + check(144115188075855871u64, b"144115188075855871"); + check(144115188075855872u64, b"144115188075855872"); + check(144115188075855873u64, b"144115188075855873"); + check(253292627452887239u64, b"253292627452887239"); + check(288230376151711743u64, b"288230376151711743"); + check(288230376151711744u64, b"288230376151711744"); + check(288230376151711745u64, b"288230376151711745"); + check(576460752303423487u64, b"576460752303423487"); + check(576460752303423488u64, b"576460752303423488"); + check(576460752303423489u64, b"576460752303423489"); + check(999999999999999999u64, b"999999999999999999"); + check(1000000000000000000u64, b"1000000000000000000"); + check(1000000000000000001u64, b"1000000000000000001"); + check(1152921504606846975u64, b"1152921504606846975"); + check(1152921504606846976u64, b"1152921504606846976"); + check(1152921504606846977u64, b"1152921504606846977"); + check(1779373561758428289u64, b"1779373561758428289"); + check(1918875392190302266u64, b"1918875392190302266"); + check(1964819683467062741u64, b"1964819683467062741"); + check(2181996174858958743u64, b"2181996174858958743"); + check(2305843009213693951u64, b"2305843009213693951"); + check(2305843009213693952u64, b"2305843009213693952"); + check(2305843009213693953u64, b"2305843009213693953"); + check(2395990555469872943u64, b"2395990555469872943"); + check(2942703002681949929u64, b"2942703002681949929"); + check(3222271663937675830u64, b"3222271663937675830"); + check(3660992601043197614u64, b"3660992601043197614"); + check(3861594818318916497u64, b"3861594818318916497"); + check(3869189413169762050u64, b"3869189413169762050"); + check(4358181693715673361u64, b"4358181693715673361"); + check(4611686018427387903u64, b"4611686018427387903"); + check(4611686018427387904u64, b"4611686018427387904"); + check(4611686018427387905u64, b"4611686018427387905"); + check(5051844181780778935u64, b"5051844181780778935"); + check(5281330341569806731u64, b"5281330341569806731"); + check(5600760056953198506u64, b"5600760056953198506"); + check(6307099386378364894u64, b"6307099386378364894"); + check(6472241654744496554u64, b"6472241654744496554"); + check(7384412550790166007u64, b"7384412550790166007"); + check(7960147437111475408u64, b"7960147437111475408"); + check(8019800572464344819u64, b"8019800572464344819"); + check(8601570958497122972u64, b"8601570958497122972"); + check(8741427099435404153u64, b"8741427099435404153"); + check(8840889545696419459u64, b"8840889545696419459"); + check(9223372036854775807u64, b"9223372036854775807"); + check(9223372036854775808u64, b"9223372036854775808"); + check(9223372036854775809u64, b"9223372036854775809"); + check(9477922267068789827u64, b"9477922267068789827"); + check(9523164641122904587u64, b"9523164641122904587"); + check(9999999999999999999u64, b"9999999999999999999"); + check(10000000000000000000u64, b"10000000000000000000"); + check(10000000000000000001u64, b"10000000000000000001"); + check(10949610239016948546u64, b"10949610239016948546"); + check(11610360713622818187u64, b"11610360713622818187"); + check(11839042677354619057u64, b"11839042677354619057"); + check(12342332997136427924u64, b"12342332997136427924"); + check(12529046498585059976u64, b"12529046498585059976"); + check(12554036026111723040u64, b"12554036026111723040"); + check(13417776601858245942u64, b"13417776601858245942"); + check(13473308908716231875u64, b"13473308908716231875"); + check(13817797190199887798u64, b"13817797190199887798"); + check(14322322805036888198u64, b"14322322805036888198"); + check(14577304145948649203u64, b"14577304145948649203"); + check(14579249030151104812u64, b"14579249030151104812"); + check(14635337296518971126u64, b"14635337296518971126"); + check(15073383254679939260u64, b"15073383254679939260"); + check(15556210989592942816u64, b"15556210989592942816"); + check(15557706225418536871u64, b"15557706225418536871"); + check(15648597401350673906u64, b"15648597401350673906"); + check(15818471236957517009u64, b"15818471236957517009"); + check(16502049970942785740u64, b"16502049970942785740"); + check(16830612805540997508u64, b"16830612805540997508"); + check(16856184049892812909u64, b"16856184049892812909"); + check(16995872497743105300u64, b"16995872497743105300"); + check(17599502550275446939u64, b"17599502550275446939"); + check(18446744073709551615u64, b"18446744073709551615"); + return 1; +} diff --git a/tests/conformance/source/std/fmt_usize_vectors.aji b/tests/conformance/source/std/fmt_usize_vectors.aji new file mode 100644 index 0000000..f6fb378 --- /dev/null +++ b/tests/conformance/source/std/fmt_usize_vectors.aji @@ -0,0 +1,560 @@ +// expect: run +// result: 1 +// fuel: 20000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +// Decimal oracle: Python str(value); fixed seed 202010. Small values, powers +// of ten/two and their neighbors, signed limits, and 48 seeded unsigned inputs. +module test.fmt_usize +import std.fmt; + +fn check(value: u64, expected: slice) -> void +effects [] +{ + if value > (0usize -% 1usize) as! u64 { return; } + for capacity in 0usize..23usize { + var storage: [u8; 26] = [165; 26]; + match std.fmt.write_usize(mut storage[1..1 + capacity], value as! usize) { + std.fmt.WriteResult::ok(count) => { + assert(capacity >= expected.len); + assert(count == expected.len); + for i in 0..count { assert(storage[1 + i] == expected[i]); } + for i in count + 1..storage.len { assert(storage[i] == 165); } + } + std.fmt.WriteResult::short_output => { + assert(capacity < expected.len); + for i in 0..storage.len { assert(storage[i] == 165); } + } + } + assert(storage[0] == 165); + } +} + +fn main() -> u8 +effects [] +{ + check(0u64, b"0"); + check(1u64, b"1"); + check(2u64, b"2"); + check(3u64, b"3"); + check(4u64, b"4"); + check(5u64, b"5"); + check(6u64, b"6"); + check(7u64, b"7"); + check(8u64, b"8"); + check(9u64, b"9"); + check(10u64, b"10"); + check(11u64, b"11"); + check(12u64, b"12"); + check(13u64, b"13"); + check(14u64, b"14"); + check(15u64, b"15"); + check(16u64, b"16"); + check(17u64, b"17"); + check(18u64, b"18"); + check(19u64, b"19"); + check(20u64, b"20"); + check(21u64, b"21"); + check(22u64, b"22"); + check(23u64, b"23"); + check(24u64, b"24"); + check(25u64, b"25"); + check(26u64, b"26"); + check(27u64, b"27"); + check(28u64, b"28"); + check(29u64, b"29"); + check(30u64, b"30"); + check(31u64, b"31"); + check(32u64, b"32"); + check(33u64, b"33"); + check(34u64, b"34"); + check(35u64, b"35"); + check(36u64, b"36"); + check(37u64, b"37"); + check(38u64, b"38"); + check(39u64, b"39"); + check(40u64, b"40"); + check(41u64, b"41"); + check(42u64, b"42"); + check(43u64, b"43"); + check(44u64, b"44"); + check(45u64, b"45"); + check(46u64, b"46"); + check(47u64, b"47"); + check(48u64, b"48"); + check(49u64, b"49"); + check(50u64, b"50"); + check(51u64, b"51"); + check(52u64, b"52"); + check(53u64, b"53"); + check(54u64, b"54"); + check(55u64, b"55"); + check(56u64, b"56"); + check(57u64, b"57"); + check(58u64, b"58"); + check(59u64, b"59"); + check(60u64, b"60"); + check(61u64, b"61"); + check(62u64, b"62"); + check(63u64, b"63"); + check(64u64, b"64"); + check(65u64, b"65"); + check(66u64, b"66"); + check(67u64, b"67"); + check(68u64, b"68"); + check(69u64, b"69"); + check(70u64, b"70"); + check(71u64, b"71"); + check(72u64, b"72"); + check(73u64, b"73"); + check(74u64, b"74"); + check(75u64, b"75"); + check(76u64, b"76"); + check(77u64, b"77"); + check(78u64, b"78"); + check(79u64, b"79"); + check(80u64, b"80"); + check(81u64, b"81"); + check(82u64, b"82"); + check(83u64, b"83"); + check(84u64, b"84"); + check(85u64, b"85"); + check(86u64, b"86"); + check(87u64, b"87"); + check(88u64, b"88"); + check(89u64, b"89"); + check(90u64, b"90"); + check(91u64, b"91"); + check(92u64, b"92"); + check(93u64, b"93"); + check(94u64, b"94"); + check(95u64, b"95"); + check(96u64, b"96"); + check(97u64, b"97"); + check(98u64, b"98"); + check(99u64, b"99"); + check(100u64, b"100"); + check(101u64, b"101"); + check(102u64, b"102"); + check(103u64, b"103"); + check(104u64, b"104"); + check(105u64, b"105"); + check(106u64, b"106"); + check(107u64, b"107"); + check(108u64, b"108"); + check(109u64, b"109"); + check(110u64, b"110"); + check(111u64, b"111"); + check(112u64, b"112"); + check(113u64, b"113"); + check(114u64, b"114"); + check(115u64, b"115"); + check(116u64, b"116"); + check(117u64, b"117"); + check(118u64, b"118"); + check(119u64, b"119"); + check(120u64, b"120"); + check(121u64, b"121"); + check(122u64, b"122"); + check(123u64, b"123"); + check(124u64, b"124"); + check(125u64, b"125"); + check(126u64, b"126"); + check(127u64, b"127"); + check(128u64, b"128"); + check(129u64, b"129"); + check(130u64, b"130"); + check(131u64, b"131"); + check(132u64, b"132"); + check(133u64, b"133"); + check(134u64, b"134"); + check(135u64, b"135"); + check(136u64, b"136"); + check(137u64, b"137"); + check(138u64, b"138"); + check(139u64, b"139"); + check(140u64, b"140"); + check(141u64, b"141"); + check(142u64, b"142"); + check(143u64, b"143"); + check(144u64, b"144"); + check(145u64, b"145"); + check(146u64, b"146"); + check(147u64, b"147"); + check(148u64, b"148"); + check(149u64, b"149"); + check(150u64, b"150"); + check(151u64, b"151"); + check(152u64, b"152"); + check(153u64, b"153"); + check(154u64, b"154"); + check(155u64, b"155"); + check(156u64, b"156"); + check(157u64, b"157"); + check(158u64, b"158"); + check(159u64, b"159"); + check(160u64, b"160"); + check(161u64, b"161"); + check(162u64, b"162"); + check(163u64, b"163"); + check(164u64, b"164"); + check(165u64, b"165"); + check(166u64, b"166"); + check(167u64, b"167"); + check(168u64, b"168"); + check(169u64, b"169"); + check(170u64, b"170"); + check(171u64, b"171"); + check(172u64, b"172"); + check(173u64, b"173"); + check(174u64, b"174"); + check(175u64, b"175"); + check(176u64, b"176"); + check(177u64, b"177"); + check(178u64, b"178"); + check(179u64, b"179"); + check(180u64, b"180"); + check(181u64, b"181"); + check(182u64, b"182"); + check(183u64, b"183"); + check(184u64, b"184"); + check(185u64, b"185"); + check(186u64, b"186"); + check(187u64, b"187"); + check(188u64, b"188"); + check(189u64, b"189"); + check(190u64, b"190"); + check(191u64, b"191"); + check(192u64, b"192"); + check(193u64, b"193"); + check(194u64, b"194"); + check(195u64, b"195"); + check(196u64, b"196"); + check(197u64, b"197"); + check(198u64, b"198"); + check(199u64, b"199"); + check(200u64, b"200"); + check(201u64, b"201"); + check(202u64, b"202"); + check(203u64, b"203"); + check(204u64, b"204"); + check(205u64, b"205"); + check(206u64, b"206"); + check(207u64, b"207"); + check(208u64, b"208"); + check(209u64, b"209"); + check(210u64, b"210"); + check(211u64, b"211"); + check(212u64, b"212"); + check(213u64, b"213"); + check(214u64, b"214"); + check(215u64, b"215"); + check(216u64, b"216"); + check(217u64, b"217"); + check(218u64, b"218"); + check(219u64, b"219"); + check(220u64, b"220"); + check(221u64, b"221"); + check(222u64, b"222"); + check(223u64, b"223"); + check(224u64, b"224"); + check(225u64, b"225"); + check(226u64, b"226"); + check(227u64, b"227"); + check(228u64, b"228"); + check(229u64, b"229"); + check(230u64, b"230"); + check(231u64, b"231"); + check(232u64, b"232"); + check(233u64, b"233"); + check(234u64, b"234"); + check(235u64, b"235"); + check(236u64, b"236"); + check(237u64, b"237"); + check(238u64, b"238"); + check(239u64, b"239"); + check(240u64, b"240"); + check(241u64, b"241"); + check(242u64, b"242"); + check(243u64, b"243"); + check(244u64, b"244"); + check(245u64, b"245"); + check(246u64, b"246"); + check(247u64, b"247"); + check(248u64, b"248"); + check(249u64, b"249"); + check(250u64, b"250"); + check(251u64, b"251"); + check(252u64, b"252"); + check(253u64, b"253"); + check(254u64, b"254"); + check(255u64, b"255"); + check(256u64, b"256"); + check(257u64, b"257"); + check(511u64, b"511"); + check(512u64, b"512"); + check(513u64, b"513"); + check(999u64, b"999"); + check(1000u64, b"1000"); + check(1001u64, b"1001"); + check(1023u64, b"1023"); + check(1024u64, b"1024"); + check(1025u64, b"1025"); + check(2047u64, b"2047"); + check(2048u64, b"2048"); + check(2049u64, b"2049"); + check(4095u64, b"4095"); + check(4096u64, b"4096"); + check(4097u64, b"4097"); + check(8191u64, b"8191"); + check(8192u64, b"8192"); + check(8193u64, b"8193"); + check(9999u64, b"9999"); + check(10000u64, b"10000"); + check(10001u64, b"10001"); + check(16383u64, b"16383"); + check(16384u64, b"16384"); + check(16385u64, b"16385"); + check(32767u64, b"32767"); + check(32768u64, b"32768"); + check(32769u64, b"32769"); + check(65535u64, b"65535"); + check(65536u64, b"65536"); + check(65537u64, b"65537"); + check(99999u64, b"99999"); + check(100000u64, b"100000"); + check(100001u64, b"100001"); + check(131071u64, b"131071"); + check(131072u64, b"131072"); + check(131073u64, b"131073"); + check(262143u64, b"262143"); + check(262144u64, b"262144"); + check(262145u64, b"262145"); + check(524287u64, b"524287"); + check(524288u64, b"524288"); + check(524289u64, b"524289"); + check(999999u64, b"999999"); + check(1000000u64, b"1000000"); + check(1000001u64, b"1000001"); + check(1048575u64, b"1048575"); + check(1048576u64, b"1048576"); + check(1048577u64, b"1048577"); + check(2097151u64, b"2097151"); + check(2097152u64, b"2097152"); + check(2097153u64, b"2097153"); + check(4194303u64, b"4194303"); + check(4194304u64, b"4194304"); + check(4194305u64, b"4194305"); + check(8388607u64, b"8388607"); + check(8388608u64, b"8388608"); + check(8388609u64, b"8388609"); + check(9999999u64, b"9999999"); + check(10000000u64, b"10000000"); + check(10000001u64, b"10000001"); + check(16777215u64, b"16777215"); + check(16777216u64, b"16777216"); + check(16777217u64, b"16777217"); + check(33554431u64, b"33554431"); + check(33554432u64, b"33554432"); + check(33554433u64, b"33554433"); + check(67108863u64, b"67108863"); + check(67108864u64, b"67108864"); + check(67108865u64, b"67108865"); + check(99999999u64, b"99999999"); + check(100000000u64, b"100000000"); + check(100000001u64, b"100000001"); + check(134217727u64, b"134217727"); + check(134217728u64, b"134217728"); + check(134217729u64, b"134217729"); + check(268435455u64, b"268435455"); + check(268435456u64, b"268435456"); + check(268435457u64, b"268435457"); + check(536870911u64, b"536870911"); + check(536870912u64, b"536870912"); + check(536870913u64, b"536870913"); + check(999999999u64, b"999999999"); + check(1000000000u64, b"1000000000"); + check(1000000001u64, b"1000000001"); + check(1073741823u64, b"1073741823"); + check(1073741824u64, b"1073741824"); + check(1073741825u64, b"1073741825"); + check(2147483647u64, b"2147483647"); + check(2147483648u64, b"2147483648"); + check(2147483649u64, b"2147483649"); + check(4294967295u64, b"4294967295"); + check(4294967296u64, b"4294967296"); + check(4294967297u64, b"4294967297"); + check(8589934591u64, b"8589934591"); + check(8589934592u64, b"8589934592"); + check(8589934593u64, b"8589934593"); + check(9999999999u64, b"9999999999"); + check(10000000000u64, b"10000000000"); + check(10000000001u64, b"10000000001"); + check(17179869183u64, b"17179869183"); + check(17179869184u64, b"17179869184"); + check(17179869185u64, b"17179869185"); + check(34359738367u64, b"34359738367"); + check(34359738368u64, b"34359738368"); + check(34359738369u64, b"34359738369"); + check(68719476735u64, b"68719476735"); + check(68719476736u64, b"68719476736"); + check(68719476737u64, b"68719476737"); + check(99999999999u64, b"99999999999"); + check(100000000000u64, b"100000000000"); + check(100000000001u64, b"100000000001"); + check(137438953471u64, b"137438953471"); + check(137438953472u64, b"137438953472"); + check(137438953473u64, b"137438953473"); + check(274877906943u64, b"274877906943"); + check(274877906944u64, b"274877906944"); + check(274877906945u64, b"274877906945"); + check(549755813887u64, b"549755813887"); + check(549755813888u64, b"549755813888"); + check(549755813889u64, b"549755813889"); + check(999999999999u64, b"999999999999"); + check(1000000000000u64, b"1000000000000"); + check(1000000000001u64, b"1000000000001"); + check(1099511627775u64, b"1099511627775"); + check(1099511627776u64, b"1099511627776"); + check(1099511627777u64, b"1099511627777"); + check(2199023255551u64, b"2199023255551"); + check(2199023255552u64, b"2199023255552"); + check(2199023255553u64, b"2199023255553"); + check(4398046511103u64, b"4398046511103"); + check(4398046511104u64, b"4398046511104"); + check(4398046511105u64, b"4398046511105"); + check(8796093022207u64, b"8796093022207"); + check(8796093022208u64, b"8796093022208"); + check(8796093022209u64, b"8796093022209"); + check(9999999999999u64, b"9999999999999"); + check(10000000000000u64, b"10000000000000"); + check(10000000000001u64, b"10000000000001"); + check(17592186044415u64, b"17592186044415"); + check(17592186044416u64, b"17592186044416"); + check(17592186044417u64, b"17592186044417"); + check(35184372088831u64, b"35184372088831"); + check(35184372088832u64, b"35184372088832"); + check(35184372088833u64, b"35184372088833"); + check(70368744177663u64, b"70368744177663"); + check(70368744177664u64, b"70368744177664"); + check(70368744177665u64, b"70368744177665"); + check(99999999999999u64, b"99999999999999"); + check(100000000000000u64, b"100000000000000"); + check(100000000000001u64, b"100000000000001"); + check(140737488355327u64, b"140737488355327"); + check(140737488355328u64, b"140737488355328"); + check(140737488355329u64, b"140737488355329"); + check(281474976710655u64, b"281474976710655"); + check(281474976710656u64, b"281474976710656"); + check(281474976710657u64, b"281474976710657"); + check(562949953421311u64, b"562949953421311"); + check(562949953421312u64, b"562949953421312"); + check(562949953421313u64, b"562949953421313"); + check(999999999999999u64, b"999999999999999"); + check(1000000000000000u64, b"1000000000000000"); + check(1000000000000001u64, b"1000000000000001"); + check(1125899906842623u64, b"1125899906842623"); + check(1125899906842624u64, b"1125899906842624"); + check(1125899906842625u64, b"1125899906842625"); + check(2251799813685247u64, b"2251799813685247"); + check(2251799813685248u64, b"2251799813685248"); + check(2251799813685249u64, b"2251799813685249"); + check(4503599627370495u64, b"4503599627370495"); + check(4503599627370496u64, b"4503599627370496"); + check(4503599627370497u64, b"4503599627370497"); + check(9007199254740991u64, b"9007199254740991"); + check(9007199254740992u64, b"9007199254740992"); + check(9007199254740993u64, b"9007199254740993"); + check(9999999999999999u64, b"9999999999999999"); + check(10000000000000000u64, b"10000000000000000"); + check(10000000000000001u64, b"10000000000000001"); + check(18014398509481983u64, b"18014398509481983"); + check(18014398509481984u64, b"18014398509481984"); + check(18014398509481985u64, b"18014398509481985"); + check(36028797018963967u64, b"36028797018963967"); + check(36028797018963968u64, b"36028797018963968"); + check(36028797018963969u64, b"36028797018963969"); + check(72057594037927935u64, b"72057594037927935"); + check(72057594037927936u64, b"72057594037927936"); + check(72057594037927937u64, b"72057594037927937"); + check(99999999999999999u64, b"99999999999999999"); + check(100000000000000000u64, b"100000000000000000"); + check(100000000000000001u64, b"100000000000000001"); + check(144115188075855871u64, b"144115188075855871"); + check(144115188075855872u64, b"144115188075855872"); + check(144115188075855873u64, b"144115188075855873"); + check(253292627452887239u64, b"253292627452887239"); + check(288230376151711743u64, b"288230376151711743"); + check(288230376151711744u64, b"288230376151711744"); + check(288230376151711745u64, b"288230376151711745"); + check(576460752303423487u64, b"576460752303423487"); + check(576460752303423488u64, b"576460752303423488"); + check(576460752303423489u64, b"576460752303423489"); + check(999999999999999999u64, b"999999999999999999"); + check(1000000000000000000u64, b"1000000000000000000"); + check(1000000000000000001u64, b"1000000000000000001"); + check(1152921504606846975u64, b"1152921504606846975"); + check(1152921504606846976u64, b"1152921504606846976"); + check(1152921504606846977u64, b"1152921504606846977"); + check(1779373561758428289u64, b"1779373561758428289"); + check(1918875392190302266u64, b"1918875392190302266"); + check(1964819683467062741u64, b"1964819683467062741"); + check(2181996174858958743u64, b"2181996174858958743"); + check(2305843009213693951u64, b"2305843009213693951"); + check(2305843009213693952u64, b"2305843009213693952"); + check(2305843009213693953u64, b"2305843009213693953"); + check(2395990555469872943u64, b"2395990555469872943"); + check(2942703002681949929u64, b"2942703002681949929"); + check(3222271663937675830u64, b"3222271663937675830"); + check(3660992601043197614u64, b"3660992601043197614"); + check(3861594818318916497u64, b"3861594818318916497"); + check(3869189413169762050u64, b"3869189413169762050"); + check(4358181693715673361u64, b"4358181693715673361"); + check(4611686018427387903u64, b"4611686018427387903"); + check(4611686018427387904u64, b"4611686018427387904"); + check(4611686018427387905u64, b"4611686018427387905"); + check(5051844181780778935u64, b"5051844181780778935"); + check(5281330341569806731u64, b"5281330341569806731"); + check(5600760056953198506u64, b"5600760056953198506"); + check(6307099386378364894u64, b"6307099386378364894"); + check(6472241654744496554u64, b"6472241654744496554"); + check(7384412550790166007u64, b"7384412550790166007"); + check(7960147437111475408u64, b"7960147437111475408"); + check(8019800572464344819u64, b"8019800572464344819"); + check(8601570958497122972u64, b"8601570958497122972"); + check(8741427099435404153u64, b"8741427099435404153"); + check(8840889545696419459u64, b"8840889545696419459"); + check(9223372036854775807u64, b"9223372036854775807"); + check(9223372036854775808u64, b"9223372036854775808"); + check(9223372036854775809u64, b"9223372036854775809"); + check(9477922267068789827u64, b"9477922267068789827"); + check(9523164641122904587u64, b"9523164641122904587"); + check(9999999999999999999u64, b"9999999999999999999"); + check(10000000000000000000u64, b"10000000000000000000"); + check(10000000000000000001u64, b"10000000000000000001"); + check(10949610239016948546u64, b"10949610239016948546"); + check(11610360713622818187u64, b"11610360713622818187"); + check(11839042677354619057u64, b"11839042677354619057"); + check(12342332997136427924u64, b"12342332997136427924"); + check(12529046498585059976u64, b"12529046498585059976"); + check(12554036026111723040u64, b"12554036026111723040"); + check(13417776601858245942u64, b"13417776601858245942"); + check(13473308908716231875u64, b"13473308908716231875"); + check(13817797190199887798u64, b"13817797190199887798"); + check(14322322805036888198u64, b"14322322805036888198"); + check(14577304145948649203u64, b"14577304145948649203"); + check(14579249030151104812u64, b"14579249030151104812"); + check(14635337296518971126u64, b"14635337296518971126"); + check(15073383254679939260u64, b"15073383254679939260"); + check(15556210989592942816u64, b"15556210989592942816"); + check(15557706225418536871u64, b"15557706225418536871"); + check(15648597401350673906u64, b"15648597401350673906"); + check(15818471236957517009u64, b"15818471236957517009"); + check(16502049970942785740u64, b"16502049970942785740"); + check(16830612805540997508u64, b"16830612805540997508"); + check(16856184049892812909u64, b"16856184049892812909"); + check(16995872497743105300u64, b"16995872497743105300"); + check(17599502550275446939u64, b"17599502550275446939"); + check(18446744073709551615u64, b"18446744073709551615"); + return 1; +} diff --git a/tests/conformance/source/std/fmt_wide_value.aji b/tests/conformance/source/std/fmt_wide_value.aji new file mode 100644 index 0000000..dbe9830 --- /dev/null +++ b/tests/conformance/source/std/fmt_wide_value.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +import std.fmt; +fn main() -> u8 effects [] { var buf: [u8; 4] = zero; let result = std.fmt.write_u64(mut buf, 1u128); return 0; } diff --git a/tests/conformance/source/std/fmt_wrong_enum.aji b/tests/conformance/source/std/fmt_wrong_enum.aji new file mode 100644 index 0000000..8f0a8d1 --- /dev/null +++ b/tests/conformance/source/std/fmt_wrong_enum.aji @@ -0,0 +1,7 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.8 +module test.fmt +import std.fmt; +import std.bytes; +fn main() -> u8 effects [] { let result: std.fmt.WriteResult = std.bytes.WriteResult::ok; return 0; } diff --git a/tests/conformance/source/std/implicit_borrow.aji b/tests/conformance/source/std/implicit_borrow.aji new file mode 100644 index 0000000..d586982 --- /dev/null +++ b/tests/conformance/source/std/implicit_borrow.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ var b: [u8; 2] = zero; std.bytes.fill(b, 1); return 0; } diff --git a/tests/conformance/source/std/late_import.aji b/tests/conformance/source/std/late_import.aji new file mode 100644 index 0000000..9b80b94 --- /dev/null +++ b/tests/conformance/source/std/late_import.aji @@ -0,0 +1,10 @@ +// expect: reject E7001 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard + + +fn main() -> u8 +effects [] +{ return 0; } +import std.bytes; diff --git a/tests/conformance/source/std/mangling_collision.aji b/tests/conformance/source/std/mangling_collision.aji new file mode 100644 index 0000000..cc4eb25 --- /dev/null +++ b/tests/conformance/source/std/mangling_collision.aji @@ -0,0 +1,24 @@ +// expect: run +// result: 19 +// phase: 6 +// spec: docs/spec/15-source-language.md §13 +module test.collision +import std.math; + +struct __aji_std_math_max_u64 { value: u8 } + +fn __aji_std_math_min_u64(a: u64, b: u64) -> u64 +effects [] +{ return a + b; } + +fn import(value: u64) -> u64 +effects [] +{ return value; } + +fn main() -> u64 +effects [] +{ + let import = std.math.min_u64(4, 9); + assert(std.math.max_u64(4, 9) == 9); + return __aji_std_math_min_u64(import, 15); +} diff --git a/tests/conformance/source/std/math.aji b/tests/conformance/source/std/math.aji new file mode 100644 index 0000000..6784b33 --- /dev/null +++ b/tests/conformance/source/std/math.aji @@ -0,0 +1,23 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.math; + +fn main() -> u64 +effects [] +{ + assert(std.math.min_u64(0, 18446744073709551615) == 0); + assert(std.math.min_u64(7, 7) == 7); + assert(std.math.min_u64(9, 4) == 4); + assert(std.math.max_u64(0, 18446744073709551615) == 18446744073709551615); + assert(std.math.max_u64(7, 7) == 7); + assert(std.math.max_u64(9, 4) == 9); + assert(std.math.clamp_u64(0, 4, 9) == 4); + assert(std.math.clamp_u64(20, 4, 9) == 9); + assert(std.math.clamp_u64(7, 4, 9) == 7); + assert(std.math.clamp_u64(7, 4, 4) == 4); + assert(std.math.clamp_u64(18446744073709551615, 0, 18446744073709551615) == 18446744073709551615); + return 0; +} diff --git a/tests/conformance/source/std/missing_import.aji b/tests/conformance/source/std/missing_import.aji new file mode 100644 index 0000000..0038647 --- /dev/null +++ b/tests/conformance/source/std/missing_import.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard + + +fn main() -> u8 +effects [] +{ assert(std.bytes.equal(b"a", b"a")); return 0; } diff --git a/tests/conformance/source/std/missing_semicolon.aji b/tests/conformance/source/std/missing_semicolon.aji new file mode 100644 index 0000000..f6035c0 --- /dev/null +++ b/tests/conformance/source/std/missing_semicolon.aji @@ -0,0 +1,9 @@ +// expect: reject E7001 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes + +fn main() -> u8 +effects [] +{ return 0; } diff --git a/tests/conformance/source/std/namespaces.aji b/tests/conformance/source/std/namespaces.aji new file mode 100644 index 0000000..3910f75 --- /dev/null +++ b/tests/conformance/source/std/namespaces.aji @@ -0,0 +1,19 @@ +// expect: run +// result: 11 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.math; +import std.bytes; + +fn equal(a: u64, b: u64) -> u64 +effects [] +{ return a + b; } + +fn main() -> u64 +effects [] +{ + let std: u64 = 7; + assert(std.bytes.equal(b"a", b"a")); + return equal(std, std.math.min_u64(4, 9)); +} diff --git a/tests/conformance/source/std/no_type_args.aji b/tests/conformance/source/std/no_type_args.aji new file mode 100644 index 0000000..6766083 --- /dev/null +++ b/tests/conformance/source/std/no_type_args.aji @@ -0,0 +1,9 @@ +// expect: reject E7001 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.math; + +fn main() -> u8 +effects [] +{ std.math.min_u64(1, 2); return 0; } diff --git a/tests/conformance/source/std/ref_for_mut.aji b/tests/conformance/source/std/ref_for_mut.aji new file mode 100644 index 0000000..0919965 --- /dev/null +++ b/tests/conformance/source/std/ref_for_mut.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ var b: [u8; 2] = zero; std.bytes.fill(ref b, 1); return 0; } diff --git a/tests/conformance/source/std/text_base64_alias.aji b/tests/conformance/source/std/text_base64_alias.aji new file mode 100644 index 0000000..8254679 --- /dev/null +++ b/tests/conformance/source/std/text_base64_alias.aji @@ -0,0 +1,6 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.encoding.base64; +fn main() -> u8 effects [] { var b: [u8; 4] = zero; let result = std.encoding.base64.encode(mut b, ref b); return 0; } diff --git a/tests/conformance/source/std/text_base64_equivalence.aji b/tests/conformance/source/std/text_base64_equivalence.aji new file mode 100644 index 0000000..c5eef53 --- /dev/null +++ b/tests/conformance/source/std/text_base64_equivalence.aji @@ -0,0 +1,18 @@ +// expect: run +// result: [90,103,61,61] +// equivalent: std/text_base64_encode.air +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.6.2 +module test.text_encode +import std.encoding.base64; + +fn main() -> [u8; 4] +effects [] +{ + var dst: [u8; 4] = zero; + match std.encoding.base64.encode(mut dst, b"f") { + std.encoding.base64.EncodeResult::ok(count) => { assert(count == 4); } + std.encoding.base64.EncodeResult::short_output => { trap; } + } + return dst; +} diff --git a/tests/conformance/source/std/text_base64_missing_import.aji b/tests/conformance/source/std/text_base64_missing_import.aji new file mode 100644 index 0000000..2c7018d --- /dev/null +++ b/tests/conformance/source/std/text_base64_missing_import.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +fn main() -> u8 effects [] { var b: [u8; 4] = zero; let result = std.encoding.base64.decode(mut b, b"AAAA"); return 0; } diff --git a/tests/conformance/source/std/text_base64_result_payload.aji b/tests/conformance/source/std/text_base64_result_payload.aji new file mode 100644 index 0000000..994802d --- /dev/null +++ b/tests/conformance/source/std/text_base64_result_payload.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.encoding.base64; +fn main() -> std.encoding.base64.EncodeResult effects [] { return std.encoding.base64.EncodeResult::ok(true); } diff --git a/tests/conformance/source/std/text_base64_vectors.aji b/tests/conformance/source/std/text_base64_vectors.aji new file mode 100644 index 0000000..607bd65 --- /dev/null +++ b/tests/conformance/source/std/text_base64_vectors.aji @@ -0,0 +1,632 @@ +// expect: run +// result: 0 +// fuel: 20000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.6 +module test.text +import std.encoding.base64; +import std.bytes; + +fn fixture(data: slice, encoded: slice) -> void +effects [] +{ + for capacity in 0usize..encoded.len + 2 { + var dst: [u8; 132] = [165; 132]; + match std.encoding.base64.encode(mut dst[1..1 + capacity], ref data) { + std.encoding.base64.EncodeResult::ok(count) => { + assert(capacity >= encoded.len); assert(count == encoded.len); + assert(std.bytes.equal(ref dst[1..1 + count], ref encoded)); + } + std.encoding.base64.EncodeResult::short_output => { assert(capacity < encoded.len); } + } + for i in 0..dst.len { + if capacity < encoded.len or i == 0 or i > encoded.len { assert(dst[i] == 165); } + } + } + for capacity in 0usize..data.len + 2 { + var dst: [u8; 132] = [165; 132]; + match std.encoding.base64.decode(mut dst[1..1 + capacity], ref encoded) { + std.encoding.base64.DecodeResult::ok(count) => { + assert(capacity >= data.len); assert(count == data.len); + assert(std.bytes.equal(ref dst[1..1 + count], ref data)); + } + std.encoding.base64.DecodeResult::invalid_input => { trap; } + std.encoding.base64.DecodeResult::short_output => { assert(capacity < data.len); } + } + for i in 0..dst.len { + if capacity < data.len or i == 0 or i > data.len { assert(dst[i] == 165); } + } + } +} +fn invalid(encoded: slice) -> void +effects [] +{ + // Invalid input takes precedence over insufficient capacity, without writes. + for capacity in 0usize..12usize { + var dst: [u8; 16] = [165; 16]; + match std.encoding.base64.decode(mut dst[1..1 + capacity], ref encoded) { + std.encoding.base64.DecodeResult::invalid_input => {} + std.encoding.base64.DecodeResult::ok(count) => { trap; } + std.encoding.base64.DecodeResult::short_output => { trap; } + } + for i in 0..dst.len { assert(dst[i] == 165); } + } +} +fn main() -> u8 +effects [] +{ + var empty: [u8; 1] = zero; + fixture(ref empty[0..0], ref empty[0..0]); + fixture(b"\x00", b"\x41\x41\x3d\x3d"); + fixture(b"\x01", b"\x41\x51\x3d\x3d"); + fixture(b"\x02", b"\x41\x67\x3d\x3d"); + fixture(b"\x03", b"\x41\x77\x3d\x3d"); + fixture(b"\x04", b"\x42\x41\x3d\x3d"); + fixture(b"\x05", b"\x42\x51\x3d\x3d"); + fixture(b"\x06", b"\x42\x67\x3d\x3d"); + fixture(b"\x07", b"\x42\x77\x3d\x3d"); + fixture(b"\x08", b"\x43\x41\x3d\x3d"); + fixture(b"\x09", b"\x43\x51\x3d\x3d"); + fixture(b"\x0a", b"\x43\x67\x3d\x3d"); + fixture(b"\x0b", b"\x43\x77\x3d\x3d"); + fixture(b"\x0c", b"\x44\x41\x3d\x3d"); + fixture(b"\x0d", b"\x44\x51\x3d\x3d"); + fixture(b"\x0e", b"\x44\x67\x3d\x3d"); + fixture(b"\x0f", b"\x44\x77\x3d\x3d"); + fixture(b"\x10", b"\x45\x41\x3d\x3d"); + fixture(b"\x11", b"\x45\x51\x3d\x3d"); + fixture(b"\x12", b"\x45\x67\x3d\x3d"); + fixture(b"\x13", b"\x45\x77\x3d\x3d"); + fixture(b"\x14", b"\x46\x41\x3d\x3d"); + fixture(b"\x15", b"\x46\x51\x3d\x3d"); + fixture(b"\x16", b"\x46\x67\x3d\x3d"); + fixture(b"\x17", b"\x46\x77\x3d\x3d"); + fixture(b"\x18", b"\x47\x41\x3d\x3d"); + fixture(b"\x19", b"\x47\x51\x3d\x3d"); + fixture(b"\x1a", b"\x47\x67\x3d\x3d"); + fixture(b"\x1b", b"\x47\x77\x3d\x3d"); + fixture(b"\x1c", b"\x48\x41\x3d\x3d"); + fixture(b"\x1d", b"\x48\x51\x3d\x3d"); + fixture(b"\x1e", b"\x48\x67\x3d\x3d"); + fixture(b"\x1f", b"\x48\x77\x3d\x3d"); + fixture(b"\x20", b"\x49\x41\x3d\x3d"); + fixture(b"\x21", b"\x49\x51\x3d\x3d"); + fixture(b"\x22", b"\x49\x67\x3d\x3d"); + fixture(b"\x23", b"\x49\x77\x3d\x3d"); + fixture(b"\x24", b"\x4a\x41\x3d\x3d"); + fixture(b"\x25", b"\x4a\x51\x3d\x3d"); + fixture(b"\x26", b"\x4a\x67\x3d\x3d"); + fixture(b"\x27", b"\x4a\x77\x3d\x3d"); + fixture(b"\x28", b"\x4b\x41\x3d\x3d"); + fixture(b"\x29", b"\x4b\x51\x3d\x3d"); + fixture(b"\x2a", b"\x4b\x67\x3d\x3d"); + fixture(b"\x2b", b"\x4b\x77\x3d\x3d"); + fixture(b"\x2c", b"\x4c\x41\x3d\x3d"); + fixture(b"\x2d", b"\x4c\x51\x3d\x3d"); + fixture(b"\x2e", b"\x4c\x67\x3d\x3d"); + fixture(b"\x2f", b"\x4c\x77\x3d\x3d"); + fixture(b"\x30", b"\x4d\x41\x3d\x3d"); + fixture(b"\x31", b"\x4d\x51\x3d\x3d"); + fixture(b"\x32", b"\x4d\x67\x3d\x3d"); + fixture(b"\x33", b"\x4d\x77\x3d\x3d"); + fixture(b"\x34", b"\x4e\x41\x3d\x3d"); + fixture(b"\x35", b"\x4e\x51\x3d\x3d"); + fixture(b"\x36", b"\x4e\x67\x3d\x3d"); + fixture(b"\x37", b"\x4e\x77\x3d\x3d"); + fixture(b"\x38", b"\x4f\x41\x3d\x3d"); + fixture(b"\x39", b"\x4f\x51\x3d\x3d"); + fixture(b"\x3a", b"\x4f\x67\x3d\x3d"); + fixture(b"\x3b", b"\x4f\x77\x3d\x3d"); + fixture(b"\x3c", b"\x50\x41\x3d\x3d"); + fixture(b"\x3d", b"\x50\x51\x3d\x3d"); + fixture(b"\x3e", b"\x50\x67\x3d\x3d"); + fixture(b"\x3f", b"\x50\x77\x3d\x3d"); + fixture(b"\x40", b"\x51\x41\x3d\x3d"); + fixture(b"\x41", b"\x51\x51\x3d\x3d"); + fixture(b"\x42", b"\x51\x67\x3d\x3d"); + fixture(b"\x43", b"\x51\x77\x3d\x3d"); + fixture(b"\x44", b"\x52\x41\x3d\x3d"); + fixture(b"\x45", b"\x52\x51\x3d\x3d"); + fixture(b"\x46", b"\x52\x67\x3d\x3d"); + fixture(b"\x47", b"\x52\x77\x3d\x3d"); + fixture(b"\x48", b"\x53\x41\x3d\x3d"); + fixture(b"\x49", b"\x53\x51\x3d\x3d"); + fixture(b"\x4a", b"\x53\x67\x3d\x3d"); + fixture(b"\x4b", b"\x53\x77\x3d\x3d"); + fixture(b"\x4c", b"\x54\x41\x3d\x3d"); + fixture(b"\x4d", b"\x54\x51\x3d\x3d"); + fixture(b"\x4e", b"\x54\x67\x3d\x3d"); + fixture(b"\x4f", b"\x54\x77\x3d\x3d"); + fixture(b"\x50", b"\x55\x41\x3d\x3d"); + fixture(b"\x51", b"\x55\x51\x3d\x3d"); + fixture(b"\x52", b"\x55\x67\x3d\x3d"); + fixture(b"\x53", b"\x55\x77\x3d\x3d"); + fixture(b"\x54", b"\x56\x41\x3d\x3d"); + fixture(b"\x55", b"\x56\x51\x3d\x3d"); + fixture(b"\x56", b"\x56\x67\x3d\x3d"); + fixture(b"\x57", b"\x56\x77\x3d\x3d"); + fixture(b"\x58", b"\x57\x41\x3d\x3d"); + fixture(b"\x59", b"\x57\x51\x3d\x3d"); + fixture(b"\x5a", b"\x57\x67\x3d\x3d"); + fixture(b"\x5b", b"\x57\x77\x3d\x3d"); + fixture(b"\x5c", b"\x58\x41\x3d\x3d"); + fixture(b"\x5d", b"\x58\x51\x3d\x3d"); + fixture(b"\x5e", b"\x58\x67\x3d\x3d"); + fixture(b"\x5f", b"\x58\x77\x3d\x3d"); + fixture(b"\x60", b"\x59\x41\x3d\x3d"); + fixture(b"\x61", b"\x59\x51\x3d\x3d"); + fixture(b"\x62", b"\x59\x67\x3d\x3d"); + fixture(b"\x63", b"\x59\x77\x3d\x3d"); + fixture(b"\x64", b"\x5a\x41\x3d\x3d"); + fixture(b"\x65", b"\x5a\x51\x3d\x3d"); + fixture(b"\x66", b"\x5a\x67\x3d\x3d"); + fixture(b"\x67", b"\x5a\x77\x3d\x3d"); + fixture(b"\x68", b"\x61\x41\x3d\x3d"); + fixture(b"\x69", b"\x61\x51\x3d\x3d"); + fixture(b"\x6a", b"\x61\x67\x3d\x3d"); + fixture(b"\x6b", b"\x61\x77\x3d\x3d"); + fixture(b"\x6c", b"\x62\x41\x3d\x3d"); + fixture(b"\x6d", b"\x62\x51\x3d\x3d"); + fixture(b"\x6e", b"\x62\x67\x3d\x3d"); + fixture(b"\x6f", b"\x62\x77\x3d\x3d"); + fixture(b"\x70", b"\x63\x41\x3d\x3d"); + fixture(b"\x71", b"\x63\x51\x3d\x3d"); + fixture(b"\x72", b"\x63\x67\x3d\x3d"); + fixture(b"\x73", b"\x63\x77\x3d\x3d"); + fixture(b"\x74", b"\x64\x41\x3d\x3d"); + fixture(b"\x75", b"\x64\x51\x3d\x3d"); + fixture(b"\x76", b"\x64\x67\x3d\x3d"); + fixture(b"\x77", b"\x64\x77\x3d\x3d"); + fixture(b"\x78", b"\x65\x41\x3d\x3d"); + fixture(b"\x79", b"\x65\x51\x3d\x3d"); + fixture(b"\x7a", b"\x65\x67\x3d\x3d"); + fixture(b"\x7b", b"\x65\x77\x3d\x3d"); + fixture(b"\x7c", b"\x66\x41\x3d\x3d"); + fixture(b"\x7d", b"\x66\x51\x3d\x3d"); + fixture(b"\x7e", b"\x66\x67\x3d\x3d"); + fixture(b"\x7f", b"\x66\x77\x3d\x3d"); + fixture(b"\x80", b"\x67\x41\x3d\x3d"); + fixture(b"\x81", b"\x67\x51\x3d\x3d"); + fixture(b"\x82", b"\x67\x67\x3d\x3d"); + fixture(b"\x83", b"\x67\x77\x3d\x3d"); + fixture(b"\x84", b"\x68\x41\x3d\x3d"); + fixture(b"\x85", b"\x68\x51\x3d\x3d"); + fixture(b"\x86", b"\x68\x67\x3d\x3d"); + fixture(b"\x87", b"\x68\x77\x3d\x3d"); + fixture(b"\x88", b"\x69\x41\x3d\x3d"); + fixture(b"\x89", b"\x69\x51\x3d\x3d"); + fixture(b"\x8a", b"\x69\x67\x3d\x3d"); + fixture(b"\x8b", b"\x69\x77\x3d\x3d"); + fixture(b"\x8c", b"\x6a\x41\x3d\x3d"); + fixture(b"\x8d", b"\x6a\x51\x3d\x3d"); + fixture(b"\x8e", b"\x6a\x67\x3d\x3d"); + fixture(b"\x8f", b"\x6a\x77\x3d\x3d"); + fixture(b"\x90", b"\x6b\x41\x3d\x3d"); + fixture(b"\x91", b"\x6b\x51\x3d\x3d"); + fixture(b"\x92", b"\x6b\x67\x3d\x3d"); + fixture(b"\x93", b"\x6b\x77\x3d\x3d"); + fixture(b"\x94", b"\x6c\x41\x3d\x3d"); + fixture(b"\x95", b"\x6c\x51\x3d\x3d"); + fixture(b"\x96", b"\x6c\x67\x3d\x3d"); + fixture(b"\x97", b"\x6c\x77\x3d\x3d"); + fixture(b"\x98", b"\x6d\x41\x3d\x3d"); + fixture(b"\x99", b"\x6d\x51\x3d\x3d"); + fixture(b"\x9a", b"\x6d\x67\x3d\x3d"); + fixture(b"\x9b", b"\x6d\x77\x3d\x3d"); + fixture(b"\x9c", b"\x6e\x41\x3d\x3d"); + fixture(b"\x9d", b"\x6e\x51\x3d\x3d"); + fixture(b"\x9e", b"\x6e\x67\x3d\x3d"); + fixture(b"\x9f", b"\x6e\x77\x3d\x3d"); + fixture(b"\xa0", b"\x6f\x41\x3d\x3d"); + fixture(b"\xa1", b"\x6f\x51\x3d\x3d"); + fixture(b"\xa2", b"\x6f\x67\x3d\x3d"); + fixture(b"\xa3", b"\x6f\x77\x3d\x3d"); + fixture(b"\xa4", b"\x70\x41\x3d\x3d"); + fixture(b"\xa5", b"\x70\x51\x3d\x3d"); + fixture(b"\xa6", b"\x70\x67\x3d\x3d"); + fixture(b"\xa7", b"\x70\x77\x3d\x3d"); + fixture(b"\xa8", b"\x71\x41\x3d\x3d"); + fixture(b"\xa9", b"\x71\x51\x3d\x3d"); + fixture(b"\xaa", b"\x71\x67\x3d\x3d"); + fixture(b"\xab", b"\x71\x77\x3d\x3d"); + fixture(b"\xac", b"\x72\x41\x3d\x3d"); + fixture(b"\xad", b"\x72\x51\x3d\x3d"); + fixture(b"\xae", b"\x72\x67\x3d\x3d"); + fixture(b"\xaf", b"\x72\x77\x3d\x3d"); + fixture(b"\xb0", b"\x73\x41\x3d\x3d"); + fixture(b"\xb1", b"\x73\x51\x3d\x3d"); + fixture(b"\xb2", b"\x73\x67\x3d\x3d"); + fixture(b"\xb3", b"\x73\x77\x3d\x3d"); + fixture(b"\xb4", b"\x74\x41\x3d\x3d"); + fixture(b"\xb5", b"\x74\x51\x3d\x3d"); + fixture(b"\xb6", b"\x74\x67\x3d\x3d"); + fixture(b"\xb7", b"\x74\x77\x3d\x3d"); + fixture(b"\xb8", b"\x75\x41\x3d\x3d"); + fixture(b"\xb9", b"\x75\x51\x3d\x3d"); + fixture(b"\xba", b"\x75\x67\x3d\x3d"); + fixture(b"\xbb", b"\x75\x77\x3d\x3d"); + fixture(b"\xbc", b"\x76\x41\x3d\x3d"); + fixture(b"\xbd", b"\x76\x51\x3d\x3d"); + fixture(b"\xbe", b"\x76\x67\x3d\x3d"); + fixture(b"\xbf", b"\x76\x77\x3d\x3d"); + fixture(b"\xc0", b"\x77\x41\x3d\x3d"); + fixture(b"\xc1", b"\x77\x51\x3d\x3d"); + fixture(b"\xc2", b"\x77\x67\x3d\x3d"); + fixture(b"\xc3", b"\x77\x77\x3d\x3d"); + fixture(b"\xc4", b"\x78\x41\x3d\x3d"); + fixture(b"\xc5", b"\x78\x51\x3d\x3d"); + fixture(b"\xc6", b"\x78\x67\x3d\x3d"); + fixture(b"\xc7", b"\x78\x77\x3d\x3d"); + fixture(b"\xc8", b"\x79\x41\x3d\x3d"); + fixture(b"\xc9", b"\x79\x51\x3d\x3d"); + fixture(b"\xca", b"\x79\x67\x3d\x3d"); + fixture(b"\xcb", b"\x79\x77\x3d\x3d"); + fixture(b"\xcc", b"\x7a\x41\x3d\x3d"); + fixture(b"\xcd", b"\x7a\x51\x3d\x3d"); + fixture(b"\xce", b"\x7a\x67\x3d\x3d"); + fixture(b"\xcf", b"\x7a\x77\x3d\x3d"); + fixture(b"\xd0", b"\x30\x41\x3d\x3d"); + fixture(b"\xd1", b"\x30\x51\x3d\x3d"); + fixture(b"\xd2", b"\x30\x67\x3d\x3d"); + fixture(b"\xd3", b"\x30\x77\x3d\x3d"); + fixture(b"\xd4", b"\x31\x41\x3d\x3d"); + fixture(b"\xd5", b"\x31\x51\x3d\x3d"); + fixture(b"\xd6", b"\x31\x67\x3d\x3d"); + fixture(b"\xd7", b"\x31\x77\x3d\x3d"); + fixture(b"\xd8", b"\x32\x41\x3d\x3d"); + fixture(b"\xd9", b"\x32\x51\x3d\x3d"); + fixture(b"\xda", b"\x32\x67\x3d\x3d"); + fixture(b"\xdb", b"\x32\x77\x3d\x3d"); + fixture(b"\xdc", b"\x33\x41\x3d\x3d"); + fixture(b"\xdd", b"\x33\x51\x3d\x3d"); + fixture(b"\xde", b"\x33\x67\x3d\x3d"); + fixture(b"\xdf", b"\x33\x77\x3d\x3d"); + fixture(b"\xe0", b"\x34\x41\x3d\x3d"); + fixture(b"\xe1", b"\x34\x51\x3d\x3d"); + fixture(b"\xe2", b"\x34\x67\x3d\x3d"); + fixture(b"\xe3", b"\x34\x77\x3d\x3d"); + fixture(b"\xe4", b"\x35\x41\x3d\x3d"); + fixture(b"\xe5", b"\x35\x51\x3d\x3d"); + fixture(b"\xe6", b"\x35\x67\x3d\x3d"); + fixture(b"\xe7", b"\x35\x77\x3d\x3d"); + fixture(b"\xe8", b"\x36\x41\x3d\x3d"); + fixture(b"\xe9", b"\x36\x51\x3d\x3d"); + fixture(b"\xea", b"\x36\x67\x3d\x3d"); + fixture(b"\xeb", b"\x36\x77\x3d\x3d"); + fixture(b"\xec", b"\x37\x41\x3d\x3d"); + fixture(b"\xed", b"\x37\x51\x3d\x3d"); + fixture(b"\xee", b"\x37\x67\x3d\x3d"); + fixture(b"\xef", b"\x37\x77\x3d\x3d"); + fixture(b"\xf0", b"\x38\x41\x3d\x3d"); + fixture(b"\xf1", b"\x38\x51\x3d\x3d"); + fixture(b"\xf2", b"\x38\x67\x3d\x3d"); + fixture(b"\xf3", b"\x38\x77\x3d\x3d"); + fixture(b"\xf4", b"\x39\x41\x3d\x3d"); + fixture(b"\xf5", b"\x39\x51\x3d\x3d"); + fixture(b"\xf6", b"\x39\x67\x3d\x3d"); + fixture(b"\xf7", b"\x39\x77\x3d\x3d"); + fixture(b"\xf8", b"\x2b\x41\x3d\x3d"); + fixture(b"\xf9", b"\x2b\x51\x3d\x3d"); + fixture(b"\xfa", b"\x2b\x67\x3d\x3d"); + fixture(b"\xfb", b"\x2b\x77\x3d\x3d"); + fixture(b"\xfc", b"\x2f\x41\x3d\x3d"); + fixture(b"\xfd", b"\x2f\x51\x3d\x3d"); + fixture(b"\xfe", b"\x2f\x67\x3d\x3d"); + fixture(b"\xff", b"\x2f\x77\x3d\x3d"); + fixture(b"\x66", b"\x5a\x67\x3d\x3d"); + fixture(b"\x66\x6f", b"\x5a\x6d\x38\x3d"); + fixture(b"\x66\x6f\x6f", b"\x5a\x6d\x39\x76"); + fixture(b"\x66\x6f\x6f\x62", b"\x5a\x6d\x39\x76\x59\x67\x3d\x3d"); + fixture(b"\x66\x6f\x6f\x62\x61", b"\x5a\x6d\x39\x76\x59\x6d\x45\x3d"); + fixture(b"\x66\x6f\x6f\x62\x61\x72", b"\x5a\x6d\x39\x76\x59\x6d\x46\x79"); + fixture(b"\xe4\x03", b"\x35\x41\x4d\x3d"); + fixture(b"\xb6\x42\xec", b"\x74\x6b\x4c\x73"); + fixture(b"\xa6\x88\x2a\xea", b"\x70\x6f\x67\x71\x36\x67\x3d\x3d"); + fixture(b"\xd6\xe4\xb6\xe7\x93", b"\x31\x75\x53\x32\x35\x35\x4d\x3d"); + fixture(b"\x30\x3d\xf5\x4a\x67\x1a", b"\x4d\x44\x33\x31\x53\x6d\x63\x61"); + fixture(b"\xf6\x2f\xec\xaf\x53\xb5\xb8", b"\x39\x69\x2f\x73\x72\x31\x4f\x31\x75\x41\x3d\x3d"); + fixture(b"\xf3\x38\x3c\x9d\xf1\x2f\xb5\x3a", b"\x38\x7a\x67\x38\x6e\x66\x45\x76\x74\x54\x6f\x3d"); + fixture(b"\x3a\x52\x8f\x78\x05\x25\x08\x41\xc6", b"\x4f\x6c\x4b\x50\x65\x41\x55\x6c\x43\x45\x48\x47"); + fixture(b"\xec\xa2\xbb\xf8\xdf\x5a\xd8\x23\xb4\x11\x25\x8d", b"\x37\x4b\x4b\x37\x2b\x4e\x39\x61\x32\x43\x4f\x30\x45\x53\x57\x4e"); + fixture(b"\xdd\x28\x7c\x16\x18\xc3\xd7\x4e\x0a\x2a\x67\x8e\x71\xe0\x51\x01", b"\x33\x53\x68\x38\x46\x68\x6a\x44\x31\x30\x34\x4b\x4b\x6d\x65\x4f\x63\x65\x42\x52\x41\x51\x3d\x3d"); + fixture(b"\x82\x79\x9f\x1b\xd0\x11\xb8\x13\x73\xd9\x84\xee\x93\xb4\x42\x61\x73\x1d\x91\x31\x3b\x68\x39\xfe\x45\xb5\xf0\x96\x69\x88\x33", b"\x67\x6e\x6d\x66\x47\x39\x41\x52\x75\x42\x4e\x7a\x32\x59\x54\x75\x6b\x37\x52\x43\x59\x58\x4d\x64\x6b\x54\x45\x37\x61\x44\x6e\x2b\x52\x62\x58\x77\x6c\x6d\x6d\x49\x4d\x77\x3d\x3d"); + fixture(b"\x91\x82\x0f\x8a\xc9\x17\x4a\x2c\xa0\x31\xb8\x6e\x00\xee\x62\x21\xcb\xd0\x50\x08\x6f\xe2\xe9\xc2\x05\xe9\x1a\x0c\x14\x63\x1d\x46", b"\x6b\x59\x49\x50\x69\x73\x6b\x58\x53\x69\x79\x67\x4d\x62\x68\x75\x41\x4f\x35\x69\x49\x63\x76\x51\x55\x41\x68\x76\x34\x75\x6e\x43\x42\x65\x6b\x61\x44\x42\x52\x6a\x48\x55\x59\x3d"); + fixture(b"\x0f\x2a\x6c\xe9\xbd\xc9\x64\xe4\x4b\x17\x1d\x86\x7c\xc6\x75\x3a\x10\xc5\x76\x46\x4a\x3a\x37\x23\xfc\x5d\xba\x78\xc2\xde\xe4\xef\x44\xe0\x93\x7a\xea\xb1\x26\xf6\x4b\xe0\x30\xc3\xa3\x06\xf9\x1b", b"\x44\x79\x70\x73\x36\x62\x33\x4a\x5a\x4f\x52\x4c\x46\x78\x32\x47\x66\x4d\x5a\x31\x4f\x68\x44\x46\x64\x6b\x5a\x4b\x4f\x6a\x63\x6a\x2f\x46\x32\x36\x65\x4d\x4c\x65\x35\x4f\x39\x45\x34\x4a\x4e\x36\x36\x72\x45\x6d\x39\x6b\x76\x67\x4d\x4d\x4f\x6a\x42\x76\x6b\x62"); + invalid(b"\x41"); + invalid(b"\x41\x41"); + invalid(b"\x41\x41\x41"); + invalid(b"\x41\x41\x41\x41\x41"); + invalid(b"\x3d"); + invalid(b"\x3d\x3d\x3d\x3d"); + invalid(b"\x41\x3d\x3d\x3d"); + invalid(b"\x41\x41\x3d\x41"); + invalid(b"\x3d\x41\x41\x41"); + invalid(b"\x41\x41\x41\x3d\x3d"); + invalid(b"\x5a\x67"); + invalid(b"\x5a\x6d\x38"); + invalid(b"\x5a\x67\x3d\x3d\x3d"); + invalid(b"\x5a\x68\x3d\x3d"); + invalid(b"\x5a\x6d\x39\x3d"); + invalid(b"\x41\x41\x41\x41\x0a"); + invalid(b"\x41\x41\x41\x41\x20"); + invalid(b"\x41\x41\x2d\x41"); + invalid(b"\x41\x41\x5f\x41"); + invalid(b"\x5a\x67\x3d\x3d\x41\x41\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x00\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x01\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x02\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x03\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x04\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x05\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x06\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x07\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x08\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x09\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x0a\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x0b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x0c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x0d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x0e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x0f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x10\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x11\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x12\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x13\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x14\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x15\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x16\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x17\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x18\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x19\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x1a\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x1b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x1c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x1d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x1e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x1f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x20\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x21\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x22\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x23\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x24\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x25\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x26\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x27\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x28\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x29\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x2a\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x2c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x2d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x2e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x3a\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x3b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x3c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x3d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x3e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x3f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x40\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x5b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x5c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x5d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x5e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x5f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x60\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x7b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x7c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x7d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x7e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x7f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x80\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x81\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x82\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x83\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x84\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x85\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x86\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x87\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x88\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x89\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x8a\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x8b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x8c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x8d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x8e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x8f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x90\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x91\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x92\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x93\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x94\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x95\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x96\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x97\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x98\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x99\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x9a\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x9b\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x9c\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x9d\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x9e\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\x9f\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa0\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa1\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa2\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa3\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa4\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa5\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa6\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa7\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa8\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xa9\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xaa\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xab\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xac\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xad\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xae\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xaf\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb0\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb1\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb2\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb3\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb4\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb5\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb6\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb7\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb8\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xb9\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xba\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xbb\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xbc\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xbd\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xbe\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xbf\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc0\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc1\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc2\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc3\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc4\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc5\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc6\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc7\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc8\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xc9\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xca\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xcb\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xcc\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xcd\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xce\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xcf\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd0\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd1\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd2\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd3\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd4\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd5\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd6\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd7\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd8\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xd9\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xda\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xdb\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xdc\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xdd\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xde\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xdf\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe0\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe1\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe2\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe3\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe4\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe5\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe6\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe7\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe8\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xe9\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xea\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xeb\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xec\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xed\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xee\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xef\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf0\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf1\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf2\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf3\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf4\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf5\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf6\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf7\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf8\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xf9\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xfa\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xfb\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xfc\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xfd\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xfe\x41\x41"); + invalid(b"\x5a\x6d\x39\x76\x41\xff\x41\x41"); + invalid(b"\x41\x42\x3d\x3d"); + invalid(b"\x41\x43\x3d\x3d"); + invalid(b"\x41\x44\x3d\x3d"); + invalid(b"\x41\x45\x3d\x3d"); + invalid(b"\x41\x46\x3d\x3d"); + invalid(b"\x41\x47\x3d\x3d"); + invalid(b"\x41\x48\x3d\x3d"); + invalid(b"\x41\x49\x3d\x3d"); + invalid(b"\x41\x4a\x3d\x3d"); + invalid(b"\x41\x4b\x3d\x3d"); + invalid(b"\x41\x4c\x3d\x3d"); + invalid(b"\x41\x4d\x3d\x3d"); + invalid(b"\x41\x4e\x3d\x3d"); + invalid(b"\x41\x4f\x3d\x3d"); + invalid(b"\x41\x50\x3d\x3d"); + invalid(b"\x41\x52\x3d\x3d"); + invalid(b"\x41\x53\x3d\x3d"); + invalid(b"\x41\x54\x3d\x3d"); + invalid(b"\x41\x55\x3d\x3d"); + invalid(b"\x41\x56\x3d\x3d"); + invalid(b"\x41\x57\x3d\x3d"); + invalid(b"\x41\x58\x3d\x3d"); + invalid(b"\x41\x59\x3d\x3d"); + invalid(b"\x41\x5a\x3d\x3d"); + invalid(b"\x41\x61\x3d\x3d"); + invalid(b"\x41\x62\x3d\x3d"); + invalid(b"\x41\x63\x3d\x3d"); + invalid(b"\x41\x64\x3d\x3d"); + invalid(b"\x41\x65\x3d\x3d"); + invalid(b"\x41\x66\x3d\x3d"); + invalid(b"\x66\x78\x3d\x3d"); + invalid(b"\x66\x79\x3d\x3d"); + invalid(b"\x66\x7a\x3d\x3d"); + invalid(b"\x66\x30\x3d\x3d"); + invalid(b"\x66\x31\x3d\x3d"); + invalid(b"\x66\x32\x3d\x3d"); + invalid(b"\x66\x33\x3d\x3d"); + invalid(b"\x66\x34\x3d\x3d"); + invalid(b"\x66\x35\x3d\x3d"); + invalid(b"\x66\x36\x3d\x3d"); + invalid(b"\x66\x37\x3d\x3d"); + invalid(b"\x66\x38\x3d\x3d"); + invalid(b"\x66\x39\x3d\x3d"); + invalid(b"\x66\x2b\x3d\x3d"); + invalid(b"\x66\x2f\x3d\x3d"); + invalid(b"\x67\x42\x3d\x3d"); + invalid(b"\x67\x43\x3d\x3d"); + invalid(b"\x67\x44\x3d\x3d"); + invalid(b"\x67\x45\x3d\x3d"); + invalid(b"\x67\x46\x3d\x3d"); + invalid(b"\x67\x47\x3d\x3d"); + invalid(b"\x67\x48\x3d\x3d"); + invalid(b"\x67\x49\x3d\x3d"); + invalid(b"\x67\x4a\x3d\x3d"); + invalid(b"\x67\x4b\x3d\x3d"); + invalid(b"\x67\x4c\x3d\x3d"); + invalid(b"\x67\x4d\x3d\x3d"); + invalid(b"\x67\x4e\x3d\x3d"); + invalid(b"\x67\x4f\x3d\x3d"); + invalid(b"\x67\x50\x3d\x3d"); + invalid(b"\x2f\x78\x3d\x3d"); + invalid(b"\x2f\x79\x3d\x3d"); + invalid(b"\x2f\x7a\x3d\x3d"); + invalid(b"\x2f\x30\x3d\x3d"); + invalid(b"\x2f\x31\x3d\x3d"); + invalid(b"\x2f\x32\x3d\x3d"); + invalid(b"\x2f\x33\x3d\x3d"); + invalid(b"\x2f\x34\x3d\x3d"); + invalid(b"\x2f\x35\x3d\x3d"); + invalid(b"\x2f\x36\x3d\x3d"); + invalid(b"\x2f\x37\x3d\x3d"); + invalid(b"\x2f\x38\x3d\x3d"); + invalid(b"\x2f\x39\x3d\x3d"); + invalid(b"\x2f\x2b\x3d\x3d"); + invalid(b"\x2f\x2f\x3d\x3d"); + invalid(b"\x41\x41\x42\x3d"); + invalid(b"\x41\x41\x43\x3d"); + invalid(b"\x41\x41\x44\x3d"); + invalid(b"\x66\x2f\x39\x3d"); + invalid(b"\x66\x2f\x2b\x3d"); + invalid(b"\x66\x2f\x2f\x3d"); + invalid(b"\x2f\x2f\x39\x3d"); + invalid(b"\x2f\x2f\x2b\x3d"); + invalid(b"\x2f\x2f\x2f\x3d"); + return 0; +} diff --git a/tests/conformance/source/std/text_base64_wrong_type.aji b/tests/conformance/source/std/text_base64_wrong_type.aji new file mode 100644 index 0000000..e5335c8 --- /dev/null +++ b/tests/conformance/source/std/text_base64_wrong_type.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.encoding.base64; +fn main() -> u8 effects [] { var b: [u16; 4] = zero; let result = std.encoding.base64.decode(mut b, b"AAAA"); return 0; } diff --git a/tests/conformance/source/std/text_disjoint.aji b/tests/conformance/source/std/text_disjoint.aji new file mode 100644 index 0000000..e8e1e79 --- /dev/null +++ b/tests/conformance/source/std/text_disjoint.aji @@ -0,0 +1,50 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.6; docs/spec/08-verifier.md §11.2 +module test.text_disjoint +import std.encoding.hex; +import std.encoding.base64; +import std.bytes; + +fn main() -> u8 +effects [] +{ + var buf: [u8; 16] = [165; 16]; + buf[0] = 0; buf[1] = 127; buf[2] = 128; buf[3] = 255; + { + mut all = buf; + let (src, dst) = all.split_at(4); + match std.encoding.hex.encode(mut dst, ref src) { + std.encoding.hex.EncodeResult::ok(count) => { assert(count == 8); } + std.encoding.hex.EncodeResult::short_output => { trap; } + } + } + assert(std.bytes.equal(ref buf[4..12], b"007f80ff")); + { + mut all = buf; + let (dst, src) = all.split_at(4); + match std.encoding.hex.decode(mut dst, ref src[0..8]) { + std.encoding.hex.DecodeResult::ok(count) => { assert(count == 4); } + std.encoding.hex.DecodeResult::invalid_input => { trap; } + std.encoding.hex.DecodeResult::short_output => { trap; } + } + match std.encoding.base64.encode(mut src, ref dst) { + std.encoding.base64.EncodeResult::ok(count) => { assert(count == 8); } + std.encoding.base64.EncodeResult::short_output => { trap; } + } + } + assert(std.bytes.equal(ref buf[4..12], b"AH+A/w==")); + { + mut all = buf; + let (dst, src) = all.split_at(4); + match std.encoding.base64.decode(mut dst, ref src[0..8]) { + std.encoding.base64.DecodeResult::ok(count) => { assert(count == 4); } + std.encoding.base64.DecodeResult::invalid_input => { trap; } + std.encoding.base64.DecodeResult::short_output => { trap; } + } + } + assert(std.bytes.equal(ref buf[0..4], b"\x00\x7f\x80\xff")); + for i in 12usize..buf.len { assert(buf[i] == 165); } + return 0; +} diff --git a/tests/conformance/source/std/text_example.aji b/tests/conformance/source/std/text_example.aji new file mode 100644 index 0000000..03fed83 --- /dev/null +++ b/tests/conformance/source/std/text_example.aji @@ -0,0 +1,35 @@ +// expect: run +// result: 8364 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module demo.text +import std.bytes; +import std.encoding.hex; +import std.encoding.base64; +import std.utf8; + +fn main() -> u32 +effects [] +{ + var utf8: [u8; 3] = zero; + match std.encoding.hex.decode(mut utf8, b"E282AC") { + std.encoding.hex.DecodeResult::ok(count) => { assert(count == 3); } + std.encoding.hex.DecodeResult::invalid_input => { return 0; } + std.encoding.hex.DecodeResult::short_output => { return 0; } + } + match std.utf8.validate(ref utf8) { + std.utf8.ValidateResult::ok => {} + std.utf8.ValidateResult::invalid_input(offset) => { return 0; } + } + var encoded: [u8; 4] = zero; + match std.encoding.base64.encode(mut encoded, ref utf8) { + std.encoding.base64.EncodeResult::ok(count) => { assert(count == 4); } + std.encoding.base64.EncodeResult::short_output => { return 0; } + } + assert(std.bytes.equal(ref encoded, b"4oKs")); + match std.utf8.next(ref utf8) { + std.utf8.NextResult::ok(scalar, count) => { assert(count == 3); return scalar; } + std.utf8.NextResult::end => { return 0; } + std.utf8.NextResult::invalid_input => { return 0; } + } +} diff --git a/tests/conformance/source/std/text_hex_alias.aji b/tests/conformance/source/std/text_hex_alias.aji new file mode 100644 index 0000000..3d1870d --- /dev/null +++ b/tests/conformance/source/std/text_hex_alias.aji @@ -0,0 +1,6 @@ +// expect: reject E2101 E2101 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.encoding.hex; +fn main() -> u8 effects [] { var b: [u8; 4] = zero; let result = std.encoding.hex.decode(mut b, ref b); return 0; } diff --git a/tests/conformance/source/std/text_hex_immutable.aji b/tests/conformance/source/std/text_hex_immutable.aji new file mode 100644 index 0000000..7c31b08 --- /dev/null +++ b/tests/conformance/source/std/text_hex_immutable.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.encoding.hex; +fn main() -> u8 effects [] { var b: [u8; 4] = zero; let result = std.encoding.hex.encode(ref b, b"x"); return 0; } diff --git a/tests/conformance/source/std/text_hex_incomplete.aji b/tests/conformance/source/std/text_hex_incomplete.aji new file mode 100644 index 0000000..e9c0ea5 --- /dev/null +++ b/tests/conformance/source/std/text_hex_incomplete.aji @@ -0,0 +1,6 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.encoding.hex; +fn main() -> usize effects [] { var b: [u8; 4] = zero; match std.encoding.hex.decode(mut b, b"00") { std.encoding.hex.DecodeResult::ok(count) => { return count; } } } diff --git a/tests/conformance/source/std/text_hex_missing_import.aji b/tests/conformance/source/std/text_hex_missing_import.aji new file mode 100644 index 0000000..ac0ccf9 --- /dev/null +++ b/tests/conformance/source/std/text_hex_missing_import.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +fn main() -> u8 effects [] { var b: [u8; 4] = zero; let result = std.encoding.hex.encode(mut b, b"x"); return 0; } diff --git a/tests/conformance/source/std/text_hex_vectors.aji b/tests/conformance/source/std/text_hex_vectors.aji new file mode 100644 index 0000000..e0629f1 --- /dev/null +++ b/tests/conformance/source/std/text_hex_vectors.aji @@ -0,0 +1,584 @@ +// expect: run +// result: 0 +// fuel: 20000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.6 +module test.text +import std.encoding.hex; +import std.bytes; + +fn fixture(data: slice, encoded: slice) -> void +effects [] +{ + for capacity in 0usize..encoded.len + 2 { + var dst: [u8; 132] = [165; 132]; + match std.encoding.hex.encode(mut dst[1..1 + capacity], ref data) { + std.encoding.hex.EncodeResult::ok(count) => { + assert(capacity >= encoded.len); assert(count == encoded.len); + assert(std.bytes.equal(ref dst[1..1 + count], ref encoded)); + } + std.encoding.hex.EncodeResult::short_output => { assert(capacity < encoded.len); } + } + for i in 0..dst.len { + if capacity < encoded.len or i == 0 or i > encoded.len { assert(dst[i] == 165); } + } + } + for capacity in 0usize..data.len + 2 { + var dst: [u8; 132] = [165; 132]; + match std.encoding.hex.decode(mut dst[1..1 + capacity], ref encoded) { + std.encoding.hex.DecodeResult::ok(count) => { + assert(capacity >= data.len); assert(count == data.len); + assert(std.bytes.equal(ref dst[1..1 + count], ref data)); + } + std.encoding.hex.DecodeResult::invalid_input => { trap; } + std.encoding.hex.DecodeResult::short_output => { assert(capacity < data.len); } + } + for i in 0..dst.len { + if capacity < data.len or i == 0 or i > data.len { assert(dst[i] == 165); } + } + } +} +fn invalid(encoded: slice) -> void +effects [] +{ + // Invalid input takes precedence over insufficient capacity, without writes. + for capacity in 0usize..12usize { + var dst: [u8; 16] = [165; 16]; + match std.encoding.hex.decode(mut dst[1..1 + capacity], ref encoded) { + std.encoding.hex.DecodeResult::invalid_input => {} + std.encoding.hex.DecodeResult::ok(count) => { trap; } + std.encoding.hex.DecodeResult::short_output => { trap; } + } + for i in 0..dst.len { assert(dst[i] == 165); } + } +} +fn main() -> u8 +effects [] +{ + var empty: [u8; 1] = zero; + fixture(ref empty[0..0], ref empty[0..0]); + fixture(b"\x00", b"\x30\x30"); + fixture(b"\x01", b"\x30\x31"); + fixture(b"\x02", b"\x30\x32"); + fixture(b"\x03", b"\x30\x33"); + fixture(b"\x04", b"\x30\x34"); + fixture(b"\x05", b"\x30\x35"); + fixture(b"\x06", b"\x30\x36"); + fixture(b"\x07", b"\x30\x37"); + fixture(b"\x08", b"\x30\x38"); + fixture(b"\x09", b"\x30\x39"); + fixture(b"\x0a", b"\x30\x61"); + fixture(b"\x0b", b"\x30\x62"); + fixture(b"\x0c", b"\x30\x63"); + fixture(b"\x0d", b"\x30\x64"); + fixture(b"\x0e", b"\x30\x65"); + fixture(b"\x0f", b"\x30\x66"); + fixture(b"\x10", b"\x31\x30"); + fixture(b"\x11", b"\x31\x31"); + fixture(b"\x12", b"\x31\x32"); + fixture(b"\x13", b"\x31\x33"); + fixture(b"\x14", b"\x31\x34"); + fixture(b"\x15", b"\x31\x35"); + fixture(b"\x16", b"\x31\x36"); + fixture(b"\x17", b"\x31\x37"); + fixture(b"\x18", b"\x31\x38"); + fixture(b"\x19", b"\x31\x39"); + fixture(b"\x1a", b"\x31\x61"); + fixture(b"\x1b", b"\x31\x62"); + fixture(b"\x1c", b"\x31\x63"); + fixture(b"\x1d", b"\x31\x64"); + fixture(b"\x1e", b"\x31\x65"); + fixture(b"\x1f", b"\x31\x66"); + fixture(b"\x20", b"\x32\x30"); + fixture(b"\x21", b"\x32\x31"); + fixture(b"\x22", b"\x32\x32"); + fixture(b"\x23", b"\x32\x33"); + fixture(b"\x24", b"\x32\x34"); + fixture(b"\x25", b"\x32\x35"); + fixture(b"\x26", b"\x32\x36"); + fixture(b"\x27", b"\x32\x37"); + fixture(b"\x28", b"\x32\x38"); + fixture(b"\x29", b"\x32\x39"); + fixture(b"\x2a", b"\x32\x61"); + fixture(b"\x2b", b"\x32\x62"); + fixture(b"\x2c", b"\x32\x63"); + fixture(b"\x2d", b"\x32\x64"); + fixture(b"\x2e", b"\x32\x65"); + fixture(b"\x2f", b"\x32\x66"); + fixture(b"\x30", b"\x33\x30"); + fixture(b"\x31", b"\x33\x31"); + fixture(b"\x32", b"\x33\x32"); + fixture(b"\x33", b"\x33\x33"); + fixture(b"\x34", b"\x33\x34"); + fixture(b"\x35", b"\x33\x35"); + fixture(b"\x36", b"\x33\x36"); + fixture(b"\x37", b"\x33\x37"); + fixture(b"\x38", b"\x33\x38"); + fixture(b"\x39", b"\x33\x39"); + fixture(b"\x3a", b"\x33\x61"); + fixture(b"\x3b", b"\x33\x62"); + fixture(b"\x3c", b"\x33\x63"); + fixture(b"\x3d", b"\x33\x64"); + fixture(b"\x3e", b"\x33\x65"); + fixture(b"\x3f", b"\x33\x66"); + fixture(b"\x40", b"\x34\x30"); + fixture(b"\x41", b"\x34\x31"); + fixture(b"\x42", b"\x34\x32"); + fixture(b"\x43", b"\x34\x33"); + fixture(b"\x44", b"\x34\x34"); + fixture(b"\x45", b"\x34\x35"); + fixture(b"\x46", b"\x34\x36"); + fixture(b"\x47", b"\x34\x37"); + fixture(b"\x48", b"\x34\x38"); + fixture(b"\x49", b"\x34\x39"); + fixture(b"\x4a", b"\x34\x61"); + fixture(b"\x4b", b"\x34\x62"); + fixture(b"\x4c", b"\x34\x63"); + fixture(b"\x4d", b"\x34\x64"); + fixture(b"\x4e", b"\x34\x65"); + fixture(b"\x4f", b"\x34\x66"); + fixture(b"\x50", b"\x35\x30"); + fixture(b"\x51", b"\x35\x31"); + fixture(b"\x52", b"\x35\x32"); + fixture(b"\x53", b"\x35\x33"); + fixture(b"\x54", b"\x35\x34"); + fixture(b"\x55", b"\x35\x35"); + fixture(b"\x56", b"\x35\x36"); + fixture(b"\x57", b"\x35\x37"); + fixture(b"\x58", b"\x35\x38"); + fixture(b"\x59", b"\x35\x39"); + fixture(b"\x5a", b"\x35\x61"); + fixture(b"\x5b", b"\x35\x62"); + fixture(b"\x5c", b"\x35\x63"); + fixture(b"\x5d", b"\x35\x64"); + fixture(b"\x5e", b"\x35\x65"); + fixture(b"\x5f", b"\x35\x66"); + fixture(b"\x60", b"\x36\x30"); + fixture(b"\x61", b"\x36\x31"); + fixture(b"\x62", b"\x36\x32"); + fixture(b"\x63", b"\x36\x33"); + fixture(b"\x64", b"\x36\x34"); + fixture(b"\x65", b"\x36\x35"); + fixture(b"\x66", b"\x36\x36"); + fixture(b"\x67", b"\x36\x37"); + fixture(b"\x68", b"\x36\x38"); + fixture(b"\x69", b"\x36\x39"); + fixture(b"\x6a", b"\x36\x61"); + fixture(b"\x6b", b"\x36\x62"); + fixture(b"\x6c", b"\x36\x63"); + fixture(b"\x6d", b"\x36\x64"); + fixture(b"\x6e", b"\x36\x65"); + fixture(b"\x6f", b"\x36\x66"); + fixture(b"\x70", b"\x37\x30"); + fixture(b"\x71", b"\x37\x31"); + fixture(b"\x72", b"\x37\x32"); + fixture(b"\x73", b"\x37\x33"); + fixture(b"\x74", b"\x37\x34"); + fixture(b"\x75", b"\x37\x35"); + fixture(b"\x76", b"\x37\x36"); + fixture(b"\x77", b"\x37\x37"); + fixture(b"\x78", b"\x37\x38"); + fixture(b"\x79", b"\x37\x39"); + fixture(b"\x7a", b"\x37\x61"); + fixture(b"\x7b", b"\x37\x62"); + fixture(b"\x7c", b"\x37\x63"); + fixture(b"\x7d", b"\x37\x64"); + fixture(b"\x7e", b"\x37\x65"); + fixture(b"\x7f", b"\x37\x66"); + fixture(b"\x80", b"\x38\x30"); + fixture(b"\x81", b"\x38\x31"); + fixture(b"\x82", b"\x38\x32"); + fixture(b"\x83", b"\x38\x33"); + fixture(b"\x84", b"\x38\x34"); + fixture(b"\x85", b"\x38\x35"); + fixture(b"\x86", b"\x38\x36"); + fixture(b"\x87", b"\x38\x37"); + fixture(b"\x88", b"\x38\x38"); + fixture(b"\x89", b"\x38\x39"); + fixture(b"\x8a", b"\x38\x61"); + fixture(b"\x8b", b"\x38\x62"); + fixture(b"\x8c", b"\x38\x63"); + fixture(b"\x8d", b"\x38\x64"); + fixture(b"\x8e", b"\x38\x65"); + fixture(b"\x8f", b"\x38\x66"); + fixture(b"\x90", b"\x39\x30"); + fixture(b"\x91", b"\x39\x31"); + fixture(b"\x92", b"\x39\x32"); + fixture(b"\x93", b"\x39\x33"); + fixture(b"\x94", b"\x39\x34"); + fixture(b"\x95", b"\x39\x35"); + fixture(b"\x96", b"\x39\x36"); + fixture(b"\x97", b"\x39\x37"); + fixture(b"\x98", b"\x39\x38"); + fixture(b"\x99", b"\x39\x39"); + fixture(b"\x9a", b"\x39\x61"); + fixture(b"\x9b", b"\x39\x62"); + fixture(b"\x9c", b"\x39\x63"); + fixture(b"\x9d", b"\x39\x64"); + fixture(b"\x9e", b"\x39\x65"); + fixture(b"\x9f", b"\x39\x66"); + fixture(b"\xa0", b"\x61\x30"); + fixture(b"\xa1", b"\x61\x31"); + fixture(b"\xa2", b"\x61\x32"); + fixture(b"\xa3", b"\x61\x33"); + fixture(b"\xa4", b"\x61\x34"); + fixture(b"\xa5", b"\x61\x35"); + fixture(b"\xa6", b"\x61\x36"); + fixture(b"\xa7", b"\x61\x37"); + fixture(b"\xa8", b"\x61\x38"); + fixture(b"\xa9", b"\x61\x39"); + fixture(b"\xaa", b"\x61\x61"); + fixture(b"\xab", b"\x61\x62"); + fixture(b"\xac", b"\x61\x63"); + fixture(b"\xad", b"\x61\x64"); + fixture(b"\xae", b"\x61\x65"); + fixture(b"\xaf", b"\x61\x66"); + fixture(b"\xb0", b"\x62\x30"); + fixture(b"\xb1", b"\x62\x31"); + fixture(b"\xb2", b"\x62\x32"); + fixture(b"\xb3", b"\x62\x33"); + fixture(b"\xb4", b"\x62\x34"); + fixture(b"\xb5", b"\x62\x35"); + fixture(b"\xb6", b"\x62\x36"); + fixture(b"\xb7", b"\x62\x37"); + fixture(b"\xb8", b"\x62\x38"); + fixture(b"\xb9", b"\x62\x39"); + fixture(b"\xba", b"\x62\x61"); + fixture(b"\xbb", b"\x62\x62"); + fixture(b"\xbc", b"\x62\x63"); + fixture(b"\xbd", b"\x62\x64"); + fixture(b"\xbe", b"\x62\x65"); + fixture(b"\xbf", b"\x62\x66"); + fixture(b"\xc0", b"\x63\x30"); + fixture(b"\xc1", b"\x63\x31"); + fixture(b"\xc2", b"\x63\x32"); + fixture(b"\xc3", b"\x63\x33"); + fixture(b"\xc4", b"\x63\x34"); + fixture(b"\xc5", b"\x63\x35"); + fixture(b"\xc6", b"\x63\x36"); + fixture(b"\xc7", b"\x63\x37"); + fixture(b"\xc8", b"\x63\x38"); + fixture(b"\xc9", b"\x63\x39"); + fixture(b"\xca", b"\x63\x61"); + fixture(b"\xcb", b"\x63\x62"); + fixture(b"\xcc", b"\x63\x63"); + fixture(b"\xcd", b"\x63\x64"); + fixture(b"\xce", b"\x63\x65"); + fixture(b"\xcf", b"\x63\x66"); + fixture(b"\xd0", b"\x64\x30"); + fixture(b"\xd1", b"\x64\x31"); + fixture(b"\xd2", b"\x64\x32"); + fixture(b"\xd3", b"\x64\x33"); + fixture(b"\xd4", b"\x64\x34"); + fixture(b"\xd5", b"\x64\x35"); + fixture(b"\xd6", b"\x64\x36"); + fixture(b"\xd7", b"\x64\x37"); + fixture(b"\xd8", b"\x64\x38"); + fixture(b"\xd9", b"\x64\x39"); + fixture(b"\xda", b"\x64\x61"); + fixture(b"\xdb", b"\x64\x62"); + fixture(b"\xdc", b"\x64\x63"); + fixture(b"\xdd", b"\x64\x64"); + fixture(b"\xde", b"\x64\x65"); + fixture(b"\xdf", b"\x64\x66"); + fixture(b"\xe0", b"\x65\x30"); + fixture(b"\xe1", b"\x65\x31"); + fixture(b"\xe2", b"\x65\x32"); + fixture(b"\xe3", b"\x65\x33"); + fixture(b"\xe4", b"\x65\x34"); + fixture(b"\xe5", b"\x65\x35"); + fixture(b"\xe6", b"\x65\x36"); + fixture(b"\xe7", b"\x65\x37"); + fixture(b"\xe8", b"\x65\x38"); + fixture(b"\xe9", b"\x65\x39"); + fixture(b"\xea", b"\x65\x61"); + fixture(b"\xeb", b"\x65\x62"); + fixture(b"\xec", b"\x65\x63"); + fixture(b"\xed", b"\x65\x64"); + fixture(b"\xee", b"\x65\x65"); + fixture(b"\xef", b"\x65\x66"); + fixture(b"\xf0", b"\x66\x30"); + fixture(b"\xf1", b"\x66\x31"); + fixture(b"\xf2", b"\x66\x32"); + fixture(b"\xf3", b"\x66\x33"); + fixture(b"\xf4", b"\x66\x34"); + fixture(b"\xf5", b"\x66\x35"); + fixture(b"\xf6", b"\x66\x36"); + fixture(b"\xf7", b"\x66\x37"); + fixture(b"\xf8", b"\x66\x38"); + fixture(b"\xf9", b"\x66\x39"); + fixture(b"\xfa", b"\x66\x61"); + fixture(b"\xfb", b"\x66\x62"); + fixture(b"\xfc", b"\x66\x63"); + fixture(b"\xfd", b"\x66\x64"); + fixture(b"\xfe", b"\x66\x65"); + fixture(b"\xff", b"\x66\x66"); + fixture(b"\x66", b"\x36\x36"); + fixture(b"\x66\x6f", b"\x36\x36\x36\x66"); + fixture(b"\x66\x6f\x6f", b"\x36\x36\x36\x66\x36\x66"); + fixture(b"\x66\x6f\x6f\x62", b"\x36\x36\x36\x66\x36\x66\x36\x32"); + fixture(b"\x66\x6f\x6f\x62\x61", b"\x36\x36\x36\x66\x36\x66\x36\x32\x36\x31"); + fixture(b"\x66\x6f\x6f\x62\x61\x72", b"\x36\x36\x36\x66\x36\x66\x36\x32\x36\x31\x37\x32"); + fixture(b"\x31\xdb", b"\x33\x31\x64\x62"); + fixture(b"\xc4\x72\x64", b"\x63\x34\x37\x32\x36\x34"); + fixture(b"\x06\x35\x20\x96", b"\x30\x36\x33\x35\x32\x30\x39\x36"); + fixture(b"\xbe\x60\xae\xc7\x5b", b"\x62\x65\x36\x30\x61\x65\x63\x37\x35\x62"); + fixture(b"\x89\x77\x63\x34\x7f\x69", b"\x38\x39\x37\x37\x36\x33\x33\x34\x37\x66\x36\x39"); + fixture(b"\x0e\xc4\x71\x5e\xcd\xf0\x84", b"\x30\x65\x63\x34\x37\x31\x35\x65\x63\x64\x66\x30\x38\x34"); + fixture(b"\x9c\xcd\x09\x7b\x2c\xdd\x1a\xd1", b"\x39\x63\x63\x64\x30\x39\x37\x62\x32\x63\x64\x64\x31\x61\x64\x31"); + fixture(b"\x00\x98\x62\x7c\xbe\x37\x66\xb7\xae", b"\x30\x30\x39\x38\x36\x32\x37\x63\x62\x65\x33\x37\x36\x36\x62\x37\x61\x65"); + fixture(b"\xa8\xc6\x47\x46\xa4\xc8\xea\x6a\x30\x53\xff\xcd", b"\x61\x38\x63\x36\x34\x37\x34\x36\x61\x34\x63\x38\x65\x61\x36\x61\x33\x30\x35\x33\x66\x66\x63\x64"); + fixture(b"\xfb\x8d\xf8\x65\x91\x2c\xea\xa1\xc6\xc1\x42\xe6\x19\x84\xf9\x13", b"\x66\x62\x38\x64\x66\x38\x36\x35\x39\x31\x32\x63\x65\x61\x61\x31\x63\x36\x63\x31\x34\x32\x65\x36\x31\x39\x38\x34\x66\x39\x31\x33"); + fixture(b"\xce\xb4\xae\xf6\x30\xa4\xa2\xc9\xcd\xe8\xa7\x0c\x81\x45\xb1\x73\xc1\x14\x78\xc0\xc5\x29\x85\xdf\x32\xb8\x33\x38\x70\x95\xea", b"\x63\x65\x62\x34\x61\x65\x66\x36\x33\x30\x61\x34\x61\x32\x63\x39\x63\x64\x65\x38\x61\x37\x30\x63\x38\x31\x34\x35\x62\x31\x37\x33\x63\x31\x31\x34\x37\x38\x63\x30\x63\x35\x32\x39\x38\x35\x64\x66\x33\x32\x62\x38\x33\x33\x33\x38\x37\x30\x39\x35\x65\x61"); + fixture(b"\xb1\x91\xd2\x54\xa0\x0e\x69\xc1\x5b\xa4\xf3\x1a\xe7\xef\xc4\xf8\xc3\x23\x84\x89\x42\x95\xb3\x94\x5d\x37\x47\x4d\xd5\x69\xbe\xdd", b"\x62\x31\x39\x31\x64\x32\x35\x34\x61\x30\x30\x65\x36\x39\x63\x31\x35\x62\x61\x34\x66\x33\x31\x61\x65\x37\x65\x66\x63\x34\x66\x38\x63\x33\x32\x33\x38\x34\x38\x39\x34\x32\x39\x35\x62\x33\x39\x34\x35\x64\x33\x37\x34\x37\x34\x64\x64\x35\x36\x39\x62\x65\x64\x64"); + fixture(b"\x85\xf9\xb6\x6b\x5a\x7f\xab\x13\xc1\x11\xcc\xb4\xda\xc8\x81\xeb\x22\xf7\xee\x7e\x23\xa2\x95\xd6\x16\x04\x32\x45\x38\x18\x21\x2f\xbd\xab\x52\xcb\xba\x9e\x5d\x85\x9d\x54\x43\x18\xe4\xb5\xfa\xe8", b"\x38\x35\x66\x39\x62\x36\x36\x62\x35\x61\x37\x66\x61\x62\x31\x33\x63\x31\x31\x31\x63\x63\x62\x34\x64\x61\x63\x38\x38\x31\x65\x62\x32\x32\x66\x37\x65\x65\x37\x65\x32\x33\x61\x32\x39\x35\x64\x36\x31\x36\x30\x34\x33\x32\x34\x35\x33\x38\x31\x38\x32\x31\x32\x66\x62\x64\x61\x62\x35\x32\x63\x62\x62\x61\x39\x65\x35\x64\x38\x35\x39\x64\x35\x34\x34\x33\x31\x38\x65\x34\x62\x35\x66\x61\x65\x38"); + invalid(b"\x30"); + invalid(b"\x61\x62\x63"); + invalid(b"\x30\x30\x67\x67"); + invalid(b"\x30\x30\x20\x31"); + invalid(b"\x30\x30\x00"); + invalid(b"\x30\x78\x31\x32"); + invalid(b"\x30\x31\x0a\x32"); + invalid(b"\x30\x30\x66\x66\x7a\x30"); + invalid(b"\x30\x00"); + invalid(b"\x30\x01"); + invalid(b"\x30\x02"); + invalid(b"\x30\x03"); + invalid(b"\x30\x04"); + invalid(b"\x30\x05"); + invalid(b"\x30\x06"); + invalid(b"\x30\x07"); + invalid(b"\x30\x08"); + invalid(b"\x30\x09"); + invalid(b"\x30\x0a"); + invalid(b"\x30\x0b"); + invalid(b"\x30\x0c"); + invalid(b"\x30\x0d"); + invalid(b"\x30\x0e"); + invalid(b"\x30\x0f"); + invalid(b"\x30\x10"); + invalid(b"\x30\x11"); + invalid(b"\x30\x12"); + invalid(b"\x30\x13"); + invalid(b"\x30\x14"); + invalid(b"\x30\x15"); + invalid(b"\x30\x16"); + invalid(b"\x30\x17"); + invalid(b"\x30\x18"); + invalid(b"\x30\x19"); + invalid(b"\x30\x1a"); + invalid(b"\x30\x1b"); + invalid(b"\x30\x1c"); + invalid(b"\x30\x1d"); + invalid(b"\x30\x1e"); + invalid(b"\x30\x1f"); + invalid(b"\x30\x20"); + invalid(b"\x30\x21"); + invalid(b"\x30\x22"); + invalid(b"\x30\x23"); + invalid(b"\x30\x24"); + invalid(b"\x30\x25"); + invalid(b"\x30\x26"); + invalid(b"\x30\x27"); + invalid(b"\x30\x28"); + invalid(b"\x30\x29"); + invalid(b"\x30\x2a"); + invalid(b"\x30\x2b"); + invalid(b"\x30\x2c"); + invalid(b"\x30\x2d"); + invalid(b"\x30\x2e"); + invalid(b"\x30\x2f"); + invalid(b"\x30\x3a"); + invalid(b"\x30\x3b"); + invalid(b"\x30\x3c"); + invalid(b"\x30\x3d"); + invalid(b"\x30\x3e"); + invalid(b"\x30\x3f"); + invalid(b"\x30\x40"); + invalid(b"\x30\x47"); + invalid(b"\x30\x48"); + invalid(b"\x30\x49"); + invalid(b"\x30\x4a"); + invalid(b"\x30\x4b"); + invalid(b"\x30\x4c"); + invalid(b"\x30\x4d"); + invalid(b"\x30\x4e"); + invalid(b"\x30\x4f"); + invalid(b"\x30\x50"); + invalid(b"\x30\x51"); + invalid(b"\x30\x52"); + invalid(b"\x30\x53"); + invalid(b"\x30\x54"); + invalid(b"\x30\x55"); + invalid(b"\x30\x56"); + invalid(b"\x30\x57"); + invalid(b"\x30\x58"); + invalid(b"\x30\x59"); + invalid(b"\x30\x5a"); + invalid(b"\x30\x5b"); + invalid(b"\x30\x5c"); + invalid(b"\x30\x5d"); + invalid(b"\x30\x5e"); + invalid(b"\x30\x5f"); + invalid(b"\x30\x60"); + invalid(b"\x30\x67"); + invalid(b"\x30\x68"); + invalid(b"\x30\x69"); + invalid(b"\x30\x6a"); + invalid(b"\x30\x6b"); + invalid(b"\x30\x6c"); + invalid(b"\x30\x6d"); + invalid(b"\x30\x6e"); + invalid(b"\x30\x6f"); + invalid(b"\x30\x70"); + invalid(b"\x30\x71"); + invalid(b"\x30\x72"); + invalid(b"\x30\x73"); + invalid(b"\x30\x74"); + invalid(b"\x30\x75"); + invalid(b"\x30\x76"); + invalid(b"\x30\x77"); + invalid(b"\x30\x78"); + invalid(b"\x30\x79"); + invalid(b"\x30\x7a"); + invalid(b"\x30\x7b"); + invalid(b"\x30\x7c"); + invalid(b"\x30\x7d"); + invalid(b"\x30\x7e"); + invalid(b"\x30\x7f"); + invalid(b"\x30\x80"); + invalid(b"\x30\x81"); + invalid(b"\x30\x82"); + invalid(b"\x30\x83"); + invalid(b"\x30\x84"); + invalid(b"\x30\x85"); + invalid(b"\x30\x86"); + invalid(b"\x30\x87"); + invalid(b"\x30\x88"); + invalid(b"\x30\x89"); + invalid(b"\x30\x8a"); + invalid(b"\x30\x8b"); + invalid(b"\x30\x8c"); + invalid(b"\x30\x8d"); + invalid(b"\x30\x8e"); + invalid(b"\x30\x8f"); + invalid(b"\x30\x90"); + invalid(b"\x30\x91"); + invalid(b"\x30\x92"); + invalid(b"\x30\x93"); + invalid(b"\x30\x94"); + invalid(b"\x30\x95"); + invalid(b"\x30\x96"); + invalid(b"\x30\x97"); + invalid(b"\x30\x98"); + invalid(b"\x30\x99"); + invalid(b"\x30\x9a"); + invalid(b"\x30\x9b"); + invalid(b"\x30\x9c"); + invalid(b"\x30\x9d"); + invalid(b"\x30\x9e"); + invalid(b"\x30\x9f"); + invalid(b"\x30\xa0"); + invalid(b"\x30\xa1"); + invalid(b"\x30\xa2"); + invalid(b"\x30\xa3"); + invalid(b"\x30\xa4"); + invalid(b"\x30\xa5"); + invalid(b"\x30\xa6"); + invalid(b"\x30\xa7"); + invalid(b"\x30\xa8"); + invalid(b"\x30\xa9"); + invalid(b"\x30\xaa"); + invalid(b"\x30\xab"); + invalid(b"\x30\xac"); + invalid(b"\x30\xad"); + invalid(b"\x30\xae"); + invalid(b"\x30\xaf"); + invalid(b"\x30\xb0"); + invalid(b"\x30\xb1"); + invalid(b"\x30\xb2"); + invalid(b"\x30\xb3"); + invalid(b"\x30\xb4"); + invalid(b"\x30\xb5"); + invalid(b"\x30\xb6"); + invalid(b"\x30\xb7"); + invalid(b"\x30\xb8"); + invalid(b"\x30\xb9"); + invalid(b"\x30\xba"); + invalid(b"\x30\xbb"); + invalid(b"\x30\xbc"); + invalid(b"\x30\xbd"); + invalid(b"\x30\xbe"); + invalid(b"\x30\xbf"); + invalid(b"\x30\xc0"); + invalid(b"\x30\xc1"); + invalid(b"\x30\xc2"); + invalid(b"\x30\xc3"); + invalid(b"\x30\xc4"); + invalid(b"\x30\xc5"); + invalid(b"\x30\xc6"); + invalid(b"\x30\xc7"); + invalid(b"\x30\xc8"); + invalid(b"\x30\xc9"); + invalid(b"\x30\xca"); + invalid(b"\x30\xcb"); + invalid(b"\x30\xcc"); + invalid(b"\x30\xcd"); + invalid(b"\x30\xce"); + invalid(b"\x30\xcf"); + invalid(b"\x30\xd0"); + invalid(b"\x30\xd1"); + invalid(b"\x30\xd2"); + invalid(b"\x30\xd3"); + invalid(b"\x30\xd4"); + invalid(b"\x30\xd5"); + invalid(b"\x30\xd6"); + invalid(b"\x30\xd7"); + invalid(b"\x30\xd8"); + invalid(b"\x30\xd9"); + invalid(b"\x30\xda"); + invalid(b"\x30\xdb"); + invalid(b"\x30\xdc"); + invalid(b"\x30\xdd"); + invalid(b"\x30\xde"); + invalid(b"\x30\xdf"); + invalid(b"\x30\xe0"); + invalid(b"\x30\xe1"); + invalid(b"\x30\xe2"); + invalid(b"\x30\xe3"); + invalid(b"\x30\xe4"); + invalid(b"\x30\xe5"); + invalid(b"\x30\xe6"); + invalid(b"\x30\xe7"); + invalid(b"\x30\xe8"); + invalid(b"\x30\xe9"); + invalid(b"\x30\xea"); + invalid(b"\x30\xeb"); + invalid(b"\x30\xec"); + invalid(b"\x30\xed"); + invalid(b"\x30\xee"); + invalid(b"\x30\xef"); + invalid(b"\x30\xf0"); + invalid(b"\x30\xf1"); + invalid(b"\x30\xf2"); + invalid(b"\x30\xf3"); + invalid(b"\x30\xf4"); + invalid(b"\x30\xf5"); + invalid(b"\x30\xf6"); + invalid(b"\x30\xf7"); + invalid(b"\x30\xf8"); + invalid(b"\x30\xf9"); + invalid(b"\x30\xfa"); + invalid(b"\x30\xfb"); + invalid(b"\x30\xfc"); + invalid(b"\x30\xfd"); + invalid(b"\x30\xfe"); + invalid(b"\x30\xff"); + var dst: [u8; 4] = zero; + match std.encoding.hex.decode(mut dst, b"aBcD01fF") { + std.encoding.hex.DecodeResult::ok(count) => { assert(count == 4); assert(std.bytes.equal(ref dst, b"\xab\xcd\x01\xff")); } + std.encoding.hex.DecodeResult::invalid_input => { trap; } + std.encoding.hex.DecodeResult::short_output => { trap; } + } + return 0; +} diff --git a/tests/conformance/source/std/text_namespace.aji b/tests/conformance/source/std/text_namespace.aji new file mode 100644 index 0000000..c84536e --- /dev/null +++ b/tests/conformance/source/std/text_namespace.aji @@ -0,0 +1,33 @@ +// expect: run +// result: 4 +// phase: 6 +// spec: docs/spec/15-source-language.md §13; docs/spec/16-standard-library.md §2.6 +module test.text_namespace +import std.encoding.hex; +import std.encoding.base64; +import std.utf8; + +enum EncodeResult { Local } +struct __aji_std_encoding_base64_EncodeResult { marker: u8 } +fn __aji_std_encoding_base64_EncodeResult_1() -> u8 +effects [] +{ return 0; } + +fn main() -> usize +effects [] +{ + let std: u8 = __aji_std_encoding_base64_EncodeResult_1(); + assert(std == 0); + let local = EncodeResult::Local; + match local { EncodeResult::Local => {} } + let hex: std.encoding.hex.EncodeResult = std.encoding.hex.EncodeResult::ok(2); + match hex { + std.encoding.hex.EncodeResult::ok(count) => { assert(count == 2); } + std.encoding.hex.EncodeResult::short_output => { trap; } + } + let b64: std.encoding.base64.EncodeResult = std.encoding.base64.EncodeResult::ok(4); + match b64 { + std.encoding.base64.EncodeResult::ok(count) => { return count; } + std.encoding.base64.EncodeResult::short_output => { trap; } + } +} diff --git a/tests/conformance/source/std/text_utf8_equivalence.aji b/tests/conformance/source/std/text_utf8_equivalence.aji new file mode 100644 index 0000000..c873763 --- /dev/null +++ b/tests/conformance/source/std/text_utf8_equivalence.aji @@ -0,0 +1,11 @@ +// expect: run +// result: {"variant":"ok","payload":[8364,3]} +// equivalent: std/text_utf8_scalar.air +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5 +module test.text_scalar +import std.utf8; + +fn main() -> std.utf8.NextResult +effects [] +{ return std.utf8.next(b"\xe2\x82\xac"); } diff --git a/tests/conformance/source/std/text_utf8_incomplete.aji b/tests/conformance/source/std/text_utf8_incomplete.aji new file mode 100644 index 0000000..1f7cf4a --- /dev/null +++ b/tests/conformance/source/std/text_utf8_incomplete.aji @@ -0,0 +1,6 @@ +// expect: reject E7004 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.utf8; +fn main() -> u32 effects [] { match std.utf8.next(b"x") { std.utf8.NextResult::ok(value, count) => { return value; } std.utf8.NextResult::end => { return 0; } } } diff --git a/tests/conformance/source/std/text_utf8_iteration.aji b/tests/conformance/source/std/text_utf8_iteration.aji new file mode 100644 index 0000000..0008971 --- /dev/null +++ b/tests/conformance/source/std/text_utf8_iteration.aji @@ -0,0 +1,39 @@ +// expect: run +// result: 0 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5 +module test.text +import std.utf8; + +fn check(data: slice) -> void +effects [] +{ + var values: [u32; 4] = zero; + values[0] = 65; values[1] = 162; values[2] = 8364; values[3] = 66376; + var offset: usize = 0; + for i in 0..values.len { + match std.utf8.next(ref data[offset..data.len]) { + std.utf8.NextResult::ok(value, count) => { assert(value == values[i]); offset = offset + count; } + std.utf8.NextResult::end => { trap; } + std.utf8.NextResult::invalid_input => { trap; } + } + } + assert(offset == data.len); + match std.utf8.next(ref data[offset..data.len]) { + std.utf8.NextResult::end => {} + std.utf8.NextResult::ok(value, count) => { trap; } + std.utf8.NextResult::invalid_input => { trap; } + } +} +fn main() -> u8 +effects [] +{ + check(b"A\xc2\xa2\xe2\x82\xac\xf0\x90\x8d\x88"); + // `next` consumes only the first sequence, even if the rest is invalid. + match std.utf8.next(b"A\xff") { + std.utf8.NextResult::ok(value, count) => { assert(value == 65 and count == 1); } + std.utf8.NextResult::end => { trap; } + std.utf8.NextResult::invalid_input => { trap; } + } + return 0; +} diff --git a/tests/conformance/source/std/text_utf8_missing_import.aji b/tests/conformance/source/std/text_utf8_missing_import.aji new file mode 100644 index 0000000..4ecd84b --- /dev/null +++ b/tests/conformance/source/std/text_utf8_missing_import.aji @@ -0,0 +1,5 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +fn main() -> u8 effects [] { let result = std.utf8.next(b"x"); return 0; } diff --git a/tests/conformance/source/std/text_utf8_payload.aji b/tests/conformance/source/std/text_utf8_payload.aji new file mode 100644 index 0000000..6409290 --- /dev/null +++ b/tests/conformance/source/std/text_utf8_payload.aji @@ -0,0 +1,6 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5–§2.7 +module test.text +import std.utf8; +fn main() -> std.utf8.NextResult effects [] { return std.utf8.NextResult::ok(true, 1); } diff --git a/tests/conformance/source/std/text_utf8_vectors.aji b/tests/conformance/source/std/text_utf8_vectors.aji new file mode 100644 index 0000000..31cfc47 --- /dev/null +++ b/tests/conformance/source/std/text_utf8_vectors.aji @@ -0,0 +1,801 @@ +// expect: run +// result: 0 +// fuel: 2000000 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.5 +module test.text +import std.utf8; + +fn valid(data: slice, expected: u32, size: usize) -> void +effects [] +{ + match std.utf8.validate(ref data) { + std.utf8.ValidateResult::ok => {} + std.utf8.ValidateResult::invalid_input(offset) => { trap; } + } + match std.utf8.next(ref data) { + std.utf8.NextResult::ok(value, count) => { assert(value == expected); assert(count == size); } + std.utf8.NextResult::end => { trap; } + std.utf8.NextResult::invalid_input => { trap; } + } +} +fn invalid(data: slice, expected: usize) -> void +effects [] +{ + match std.utf8.validate(ref data) { + std.utf8.ValidateResult::ok => { trap; } + std.utf8.ValidateResult::invalid_input(offset) => { assert(offset == expected); } + } + match std.utf8.next(ref data[expected..data.len]) { + std.utf8.NextResult::ok(value, count) => { trap; } + std.utf8.NextResult::end => { trap; } + std.utf8.NextResult::invalid_input => {} + } +} +fn main() -> u8 +effects [] +{ + var single: [u8; 1] = zero; + match std.utf8.next(ref single[0..0]) { + std.utf8.NextResult::end => {} + std.utf8.NextResult::ok(value, count) => { trap; } + std.utf8.NextResult::invalid_input => { trap; } + } + match std.utf8.validate(ref single[0..0]) { + std.utf8.ValidateResult::ok => {} + std.utf8.ValidateResult::invalid_input(offset) => { trap; } + } + for byte in 0u16..256u16 { + single[0] = byte as! u8; + if byte < 128 { valid(ref single, byte as u32, 1); } + else { invalid(ref single, 0); } + } + valid(b"\x00", 0, 1); + valid(b"\x01", 1, 1); + valid(b"\x7f", 127, 1); + valid(b"\xc2\x80", 128, 2); + valid(b"\xdf\xbf", 2047, 2); + valid(b"\xe0\xa0\x80", 2048, 3); + valid(b"\xed\x9f\xbf", 55295, 3); + valid(b"\xee\x80\x80", 57344, 3); + valid(b"\xef\xbb\xbf", 65279, 3); + valid(b"\xef\xbf\xbf", 65535, 3); + valid(b"\xf0\x90\x80\x80", 65536, 4); + valid(b"\xf4\x8f\xbf\xbf", 1114111, 4); + valid(b"\xef\xb7\x90", 64976, 3); + valid(b"\xf0\xaf\xb3\x8f", 195791, 4); + valid(b"\xf0\xb3\x86\x86", 209286, 4); + valid(b"\xf1\xbb\x87\xaf", 504303, 4); + valid(b"\xf2\x8c\x92\xb6", 574646, 4); + valid(b"\xf0\xa1\xa6\x87", 137607, 4); + valid(b"\xf3\xb9\x84\x8a", 1020170, 4); + valid(b"\xf1\xb6\x92\xa7", 484519, 4); + valid(b"\xf3\xb5\x81\xbc", 1003644, 4); + valid(b"\xf1\xb5\xbd\x90", 483152, 4); + valid(b"\xf0\x96\xa9\xa9", 92777, 4); + valid(b"\xf1\x91\x9c\x83", 333571, 4); + valid(b"\xf0\x92\x87\xa2", 74210, 4); + valid(b"\xf3\x8f\xa4\x8a", 850186, 4); + valid(b"\xf0\xa7\x8c\x94", 160532, 4); + valid(b"\xf2\xac\x8c\x91", 705297, 4); + valid(b"\xf3\x91\x88\x8f", 856591, 4); + valid(b"\xf3\xb2\xa5\xb6", 993654, 4); + valid(b"\xf3\xa5\x85\xb4", 938356, 4); + valid(b"\xf1\x96\x83\xb4", 352500, 4); + valid(b"\xf1\x9f\x81\xa1", 389217, 4); + valid(b"\xf3\xaf\xa6\x8a", 981386, 4); + valid(b"\xf3\x9c\xb1\xb0", 904304, 4); + valid(b"\xf1\x95\x86\x9f", 348575, 4); + valid(b"\xf2\x85\x93\x95", 546005, 4); + valid(b"\xf3\xa8\xa4\xa3", 952611, 4); + valid(b"\xf3\xaa\x97\xa1", 959969, 4); + valid(b"\xf1\xa7\xa7\x89", 424393, 4); + valid(b"\xf2\x80\xb8\xb5", 527925, 4); + valid(b"\xf0\x99\xa8\xa6", 104998, 4); + valid(b"\xf4\x89\x86\xbd", 1085885, 4); + valid(b"\xf0\x96\xaf\xa1", 93153, 4); + valid(b"\xf0\xbb\xa5\x85", 244037, 4); + valid(b"\xf2\x9c\xa1\x86", 641094, 4); + valid(b"\xf3\xa1\xbf\x8e", 925646, 4); + valid(b"\xf3\xa9\x93\xbe", 955646, 4); + valid(b"\xf1\x83\xa7\xba", 276986, 4); + valid(b"\xf2\xad\x83\x8d", 708813, 4); + valid(b"\xf2\x9a\x83\x88", 630984, 4); + valid(b"\xf3\xb3\x85\xb2", 995698, 4); + valid(b"\xf1\x8a\x91\xb3", 304243, 4); + valid(b"\xf2\x83\x93\xb5", 537845, 4); + valid(b"\xf2\x8e\x90\x8c", 582668, 4); + valid(b"\xf1\x86\xad\x82", 289602, 4); + valid(b"\xf4\x8e\xad\xa5", 1108837, 4); + valid(b"\xf1\x95\xb2\x8e", 351374, 4); + valid(b"\xf3\xbb\x8e\x8f", 1029007, 4); + valid(b"\xf1\xb8\x9c\xa1", 493345, 4); + valid(b"\xf1\x82\x8b\x94", 271060, 4); + valid(b"\xf3\xa6\x99\xaa", 943722, 4); + valid(b"\xf2\x95\x9e\x93", 612243, 4); + valid(b"\xf2\x9f\xae\xb7", 654263, 4); + valid(b"\xf1\xa3\xba\xaa", 409258, 4); + valid(b"\xf2\x99\x9d\xaf", 628591, 4); + valid(b"\xf0\xa1\xb9\xb0", 138864, 4); + valid(b"\xf2\xbb\x82\xb6", 766134, 4); + valid(b"\xf2\x8a\xb4\xad", 568621, 4); + valid(b"\xf2\x83\xa0\x9a", 538650, 4); + valid(b"\xf2\xa1\xb5\x80", 662848, 4); + valid(b"\xf1\xb2\x91\xa8", 468072, 4); + valid(b"\xe8\x90\x87", 33799, 3); + valid(b"\xf2\x87\xa0\x83", 555011, 4); + valid(b"\xf3\xa6\xb4\x8b", 945419, 4); + valid(b"\xe9\x92\xb2", 38066, 3); + valid(b"\xf0\xb1\xaa\x98", 203416, 4); + valid(b"\xf3\xa4\x95\x92", 935250, 4); + valid(b"\xe6\xaa\xaf", 27311, 3); + valid(b"\xf3\xab\xa3\x97", 964823, 4); + valid(b"\xf1\x88\xb6\x8a", 298378, 4); + valid(b"\xf2\xb3\xb2\x86", 736390, 4); + valid(b"\xf4\x89\x99\x97", 1087063, 4); + valid(b"\xf0\x94\xb4\x89", 85257, 4); + valid(b"\xf3\xac\xbe\x8f", 970639, 4); + valid(b"\xf1\xb6\xb4\xa0", 486688, 4); + valid(b"\xf0\xa0\xa5\x9c", 133468, 4); + valid(b"\xf3\x99\x9a\x94", 890516, 4); + valid(b"\xf1\x92\xae\x8e", 338830, 4); + valid(b"\xf4\x81\xbc\xb9", 1056569, 4); + valid(b"\xf0\x94\x8e\xac", 82860, 4); + valid(b"\xf2\xb1\x9c\xb2", 726834, 4); + valid(b"\xf1\xa3\xb0\x8b", 408587, 4); + valid(b"\xf1\x91\xbd\xaf", 335727, 4); + valid(b"\xf0\xad\xb8\xb8", 187960, 4); + valid(b"\xf2\xae\x9a\x91", 714385, 4); + valid(b"\xf2\xaa\xac\xb0", 699184, 4); + valid(b"\xf2\x9f\x84\xae", 651566, 4); + valid(b"\xe9\xbb\x86", 40646, 3); + valid(b"\xf3\xa2\x91\x81", 926785, 4); + valid(b"\xf0\x99\xa2\x98", 104600, 4); + valid(b"\xf0\xb8\xba\x99", 233113, 4); + valid(b"\xf3\x92\x92\xab", 861355, 4); + valid(b"\xf3\x8d\x9d\xb9", 841593, 4); + valid(b"\xf0\xbe\xa4\xb1", 256305, 4); + valid(b"\xf3\xb5\xb8\x8a", 1007114, 4); + valid(b"\xf1\x80\xbd\x99", 266073, 4); + valid(b"\xf2\x80\xb2\x84", 527492, 4); + valid(b"\xf4\x8e\x8d\xb6", 1106806, 4); + invalid(b"\xc0\x00", 0); + invalid(b"\x41\xc2\xa2\xc0\x00", 3); + invalid(b"\xc0\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x00\x80", 3); + invalid(b"\xc0\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x00\x80\x80", 3); + invalid(b"\xc0\x7f", 0); + invalid(b"\x41\xc2\xa2\xc0\x7f", 3); + invalid(b"\xc0\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x7f\x80", 3); + invalid(b"\xc0\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x7f\x80\x80", 3); + invalid(b"\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x80", 3); + invalid(b"\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x80\x80", 3); + invalid(b"\xc0\x80\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x80\x80\x80", 3); + invalid(b"\xc0\x8f", 0); + invalid(b"\x41\xc2\xa2\xc0\x8f", 3); + invalid(b"\xc0\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x8f\x80", 3); + invalid(b"\xc0\x8f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x8f\x80\x80", 3); + invalid(b"\xc0\x90", 0); + invalid(b"\x41\xc2\xa2\xc0\x90", 3); + invalid(b"\xc0\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x90\x80", 3); + invalid(b"\xc0\x90\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x90\x80\x80", 3); + invalid(b"\xc0\x9f", 0); + invalid(b"\x41\xc2\xa2\xc0\x9f", 3); + invalid(b"\xc0\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x9f\x80", 3); + invalid(b"\xc0\x9f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\x9f\x80\x80", 3); + invalid(b"\xc0\xa0", 0); + invalid(b"\x41\xc2\xa2\xc0\xa0", 3); + invalid(b"\xc0\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xa0\x80", 3); + invalid(b"\xc0\xa0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xa0\x80\x80", 3); + invalid(b"\xc0\xbf", 0); + invalid(b"\x41\xc2\xa2\xc0\xbf", 3); + invalid(b"\xc0\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xbf\x80", 3); + invalid(b"\xc0\xbf\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xbf\x80\x80", 3); + invalid(b"\xc0\xc0", 0); + invalid(b"\x41\xc2\xa2\xc0\xc0", 3); + invalid(b"\xc0\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xc0\x80", 3); + invalid(b"\xc0\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xc0\x80\x80", 3); + invalid(b"\xc0\xff", 0); + invalid(b"\x41\xc2\xa2\xc0\xff", 3); + invalid(b"\xc0\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xff\x80", 3); + invalid(b"\xc0\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc0\xff\x80\x80", 3); + invalid(b"\xc1\x00", 0); + invalid(b"\x41\xc2\xa2\xc1\x00", 3); + invalid(b"\xc1\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x00\x80", 3); + invalid(b"\xc1\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x00\x80\x80", 3); + invalid(b"\xc1\x7f", 0); + invalid(b"\x41\xc2\xa2\xc1\x7f", 3); + invalid(b"\xc1\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x7f\x80", 3); + invalid(b"\xc1\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x7f\x80\x80", 3); + invalid(b"\xc1\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x80", 3); + invalid(b"\xc1\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x80\x80", 3); + invalid(b"\xc1\x80\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x80\x80\x80", 3); + invalid(b"\xc1\x8f", 0); + invalid(b"\x41\xc2\xa2\xc1\x8f", 3); + invalid(b"\xc1\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x8f\x80", 3); + invalid(b"\xc1\x8f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x8f\x80\x80", 3); + invalid(b"\xc1\x90", 0); + invalid(b"\x41\xc2\xa2\xc1\x90", 3); + invalid(b"\xc1\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x90\x80", 3); + invalid(b"\xc1\x90\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x90\x80\x80", 3); + invalid(b"\xc1\x9f", 0); + invalid(b"\x41\xc2\xa2\xc1\x9f", 3); + invalid(b"\xc1\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x9f\x80", 3); + invalid(b"\xc1\x9f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\x9f\x80\x80", 3); + invalid(b"\xc1\xa0", 0); + invalid(b"\x41\xc2\xa2\xc1\xa0", 3); + invalid(b"\xc1\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xa0\x80", 3); + invalid(b"\xc1\xa0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xa0\x80\x80", 3); + invalid(b"\xc1\xbf", 0); + invalid(b"\x41\xc2\xa2\xc1\xbf", 3); + invalid(b"\xc1\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xbf\x80", 3); + invalid(b"\xc1\xbf\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xbf\x80\x80", 3); + invalid(b"\xc1\xc0", 0); + invalid(b"\x41\xc2\xa2\xc1\xc0", 3); + invalid(b"\xc1\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xc0\x80", 3); + invalid(b"\xc1\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xc0\x80\x80", 3); + invalid(b"\xc1\xff", 0); + invalid(b"\x41\xc2\xa2\xc1\xff", 3); + invalid(b"\xc1\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xff\x80", 3); + invalid(b"\xc1\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc1\xff\x80\x80", 3); + invalid(b"\xc2\x00", 0); + invalid(b"\x41\xc2\xa2\xc2\x00", 3); + invalid(b"\xc2\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\x00\x80", 3); + invalid(b"\xc2\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\x00\x80\x80", 3); + invalid(b"\xc2\x7f", 0); + invalid(b"\x41\xc2\xa2\xc2\x7f", 3); + invalid(b"\xc2\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\x7f\x80", 3); + invalid(b"\xc2\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\x7f\x80\x80", 3); + valid(b"\xc2\x80", 128, 2); + invalid(b"\xc2\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x80\x80", 5); + invalid(b"\xc2\x80\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x80\x80\x80", 5); + valid(b"\xc2\x8f", 143, 2); + invalid(b"\xc2\x8f\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x8f\x80", 5); + invalid(b"\xc2\x8f\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x8f\x80\x80", 5); + valid(b"\xc2\x90", 144, 2); + invalid(b"\xc2\x90\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x90\x80", 5); + invalid(b"\xc2\x90\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x90\x80\x80", 5); + valid(b"\xc2\x9f", 159, 2); + invalid(b"\xc2\x9f\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x9f\x80", 5); + invalid(b"\xc2\x9f\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\x9f\x80\x80", 5); + valid(b"\xc2\xa0", 160, 2); + invalid(b"\xc2\xa0\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\xa0\x80", 5); + invalid(b"\xc2\xa0\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\xa0\x80\x80", 5); + valid(b"\xc2\xbf", 191, 2); + invalid(b"\xc2\xbf\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\xbf\x80", 5); + invalid(b"\xc2\xbf\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xc2\xbf\x80\x80", 5); + invalid(b"\xc2\xc0", 0); + invalid(b"\x41\xc2\xa2\xc2\xc0", 3); + invalid(b"\xc2\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\xc0\x80", 3); + invalid(b"\xc2\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\xc0\x80\x80", 3); + invalid(b"\xc2\xff", 0); + invalid(b"\x41\xc2\xa2\xc2\xff", 3); + invalid(b"\xc2\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\xff\x80", 3); + invalid(b"\xc2\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xc2\xff\x80\x80", 3); + invalid(b"\xdf\x00", 0); + invalid(b"\x41\xc2\xa2\xdf\x00", 3); + invalid(b"\xdf\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\x00\x80", 3); + invalid(b"\xdf\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\x00\x80\x80", 3); + invalid(b"\xdf\x7f", 0); + invalid(b"\x41\xc2\xa2\xdf\x7f", 3); + invalid(b"\xdf\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\x7f\x80", 3); + invalid(b"\xdf\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\x7f\x80\x80", 3); + valid(b"\xdf\x80", 1984, 2); + invalid(b"\xdf\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x80\x80", 5); + invalid(b"\xdf\x80\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x80\x80\x80", 5); + valid(b"\xdf\x8f", 1999, 2); + invalid(b"\xdf\x8f\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x8f\x80", 5); + invalid(b"\xdf\x8f\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x8f\x80\x80", 5); + valid(b"\xdf\x90", 2000, 2); + invalid(b"\xdf\x90\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x90\x80", 5); + invalid(b"\xdf\x90\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x90\x80\x80", 5); + valid(b"\xdf\x9f", 2015, 2); + invalid(b"\xdf\x9f\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x9f\x80", 5); + invalid(b"\xdf\x9f\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\x9f\x80\x80", 5); + valid(b"\xdf\xa0", 2016, 2); + invalid(b"\xdf\xa0\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\xa0\x80", 5); + invalid(b"\xdf\xa0\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\xa0\x80\x80", 5); + valid(b"\xdf\xbf", 2047, 2); + invalid(b"\xdf\xbf\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\xbf\x80", 5); + invalid(b"\xdf\xbf\x80\x80", 2); + invalid(b"\x41\xc2\xa2\xdf\xbf\x80\x80", 5); + invalid(b"\xdf\xc0", 0); + invalid(b"\x41\xc2\xa2\xdf\xc0", 3); + invalid(b"\xdf\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\xc0\x80", 3); + invalid(b"\xdf\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\xc0\x80\x80", 3); + invalid(b"\xdf\xff", 0); + invalid(b"\x41\xc2\xa2\xdf\xff", 3); + invalid(b"\xdf\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\xff\x80", 3); + invalid(b"\xdf\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xdf\xff\x80\x80", 3); + invalid(b"\xe0\x00", 0); + invalid(b"\x41\xc2\xa2\xe0\x00", 3); + invalid(b"\xe0\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x00\x80", 3); + invalid(b"\xe0\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x00\x80\x80", 3); + invalid(b"\xe0\x7f", 0); + invalid(b"\x41\xc2\xa2\xe0\x7f", 3); + invalid(b"\xe0\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x7f\x80", 3); + invalid(b"\xe0\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x7f\x80\x80", 3); + invalid(b"\xe0\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x80", 3); + invalid(b"\xe0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x80\x80", 3); + invalid(b"\xe0\x80\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x80\x80\x80", 3); + invalid(b"\xe0\x8f", 0); + invalid(b"\x41\xc2\xa2\xe0\x8f", 3); + invalid(b"\xe0\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x8f\x80", 3); + invalid(b"\xe0\x8f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x8f\x80\x80", 3); + invalid(b"\xe0\x90", 0); + invalid(b"\x41\xc2\xa2\xe0\x90", 3); + invalid(b"\xe0\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x90\x80", 3); + invalid(b"\xe0\x90\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x90\x80\x80", 3); + invalid(b"\xe0\x9f", 0); + invalid(b"\x41\xc2\xa2\xe0\x9f", 3); + invalid(b"\xe0\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x9f\x80", 3); + invalid(b"\xe0\x9f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\x9f\x80\x80", 3); + invalid(b"\xe0\xa0", 0); + invalid(b"\x41\xc2\xa2\xe0\xa0", 3); + valid(b"\xe0\xa0\x80", 2048, 3); + invalid(b"\xe0\xa0\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xe0\xa0\x80\x80", 6); + invalid(b"\xe0\xbf", 0); + invalid(b"\x41\xc2\xa2\xe0\xbf", 3); + valid(b"\xe0\xbf\x80", 4032, 3); + invalid(b"\xe0\xbf\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xe0\xbf\x80\x80", 6); + invalid(b"\xe0\xc0", 0); + invalid(b"\x41\xc2\xa2\xe0\xc0", 3); + invalid(b"\xe0\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\xc0\x80", 3); + invalid(b"\xe0\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\xc0\x80\x80", 3); + invalid(b"\xe0\xff", 0); + invalid(b"\x41\xc2\xa2\xe0\xff", 3); + invalid(b"\xe0\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\xff\x80", 3); + invalid(b"\xe0\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xe0\xff\x80\x80", 3); + invalid(b"\xe2", 0); + invalid(b"\x41\xc2\xa2\xe2", 3); + invalid(b"\xe2\x82", 0); + invalid(b"\x41\xc2\xa2\xe2\x82", 3); + invalid(b"\xe2\x82\x41", 0); + invalid(b"\x41\xc2\xa2\xe2\x82\x41", 3); + invalid(b"\xed\x00", 0); + invalid(b"\x41\xc2\xa2\xed\x00", 3); + invalid(b"\xed\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xed\x00\x80", 3); + invalid(b"\xed\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xed\x00\x80\x80", 3); + invalid(b"\xed\x7f", 0); + invalid(b"\x41\xc2\xa2\xed\x7f", 3); + invalid(b"\xed\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xed\x7f\x80", 3); + invalid(b"\xed\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xed\x7f\x80\x80", 3); + invalid(b"\xed\x80", 0); + invalid(b"\x41\xc2\xa2\xed\x80", 3); + valid(b"\xed\x80\x80", 53248, 3); + invalid(b"\xed\x80\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xed\x80\x80\x80", 6); + invalid(b"\xed\x8f", 0); + invalid(b"\x41\xc2\xa2\xed\x8f", 3); + valid(b"\xed\x8f\x80", 54208, 3); + invalid(b"\xed\x8f\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xed\x8f\x80\x80", 6); + invalid(b"\xed\x90", 0); + invalid(b"\x41\xc2\xa2\xed\x90", 3); + valid(b"\xed\x90\x80", 54272, 3); + invalid(b"\xed\x90\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xed\x90\x80\x80", 6); + invalid(b"\xed\x9f", 0); + invalid(b"\x41\xc2\xa2\xed\x9f", 3); + valid(b"\xed\x9f\x80", 55232, 3); + invalid(b"\xed\x9f\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xed\x9f\x80\x80", 6); + invalid(b"\xed\xa0", 0); + invalid(b"\x41\xc2\xa2\xed\xa0", 3); + invalid(b"\xed\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xa0\x80", 3); + invalid(b"\xed\xa0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xa0\x80\x80", 3); + invalid(b"\xed\xbf", 0); + invalid(b"\x41\xc2\xa2\xed\xbf", 3); + invalid(b"\xed\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xbf\x80", 3); + invalid(b"\xed\xbf\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xbf\x80\x80", 3); + invalid(b"\xed\xc0", 0); + invalid(b"\x41\xc2\xa2\xed\xc0", 3); + invalid(b"\xed\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xc0\x80", 3); + invalid(b"\xed\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xc0\x80\x80", 3); + invalid(b"\xed\xff", 0); + invalid(b"\x41\xc2\xa2\xed\xff", 3); + invalid(b"\xed\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xff\x80", 3); + invalid(b"\xed\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xed\xff\x80\x80", 3); + invalid(b"\xef\x00", 0); + invalid(b"\x41\xc2\xa2\xef\x00", 3); + invalid(b"\xef\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xef\x00\x80", 3); + invalid(b"\xef\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xef\x00\x80\x80", 3); + invalid(b"\xef\x7f", 0); + invalid(b"\x41\xc2\xa2\xef\x7f", 3); + invalid(b"\xef\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xef\x7f\x80", 3); + invalid(b"\xef\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xef\x7f\x80\x80", 3); + invalid(b"\xef\x80", 0); + invalid(b"\x41\xc2\xa2\xef\x80", 3); + valid(b"\xef\x80\x80", 61440, 3); + invalid(b"\xef\x80\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xef\x80\x80\x80", 6); + invalid(b"\xef\x8f", 0); + invalid(b"\x41\xc2\xa2\xef\x8f", 3); + valid(b"\xef\x8f\x80", 62400, 3); + invalid(b"\xef\x8f\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xef\x8f\x80\x80", 6); + invalid(b"\xef\x90", 0); + invalid(b"\x41\xc2\xa2\xef\x90", 3); + valid(b"\xef\x90\x80", 62464, 3); + invalid(b"\xef\x90\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xef\x90\x80\x80", 6); + invalid(b"\xef\x9f", 0); + invalid(b"\x41\xc2\xa2\xef\x9f", 3); + valid(b"\xef\x9f\x80", 63424, 3); + invalid(b"\xef\x9f\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xef\x9f\x80\x80", 6); + invalid(b"\xef\xa0", 0); + invalid(b"\x41\xc2\xa2\xef\xa0", 3); + valid(b"\xef\xa0\x80", 63488, 3); + invalid(b"\xef\xa0\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xef\xa0\x80\x80", 6); + invalid(b"\xef\xbf", 0); + invalid(b"\x41\xc2\xa2\xef\xbf", 3); + valid(b"\xef\xbf\x80", 65472, 3); + invalid(b"\xef\xbf\x80\x80", 3); + invalid(b"\x41\xc2\xa2\xef\xbf\x80\x80", 6); + invalid(b"\xef\xc0", 0); + invalid(b"\x41\xc2\xa2\xef\xc0", 3); + invalid(b"\xef\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xef\xc0\x80", 3); + invalid(b"\xef\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xef\xc0\x80\x80", 3); + invalid(b"\xef\xff", 0); + invalid(b"\x41\xc2\xa2\xef\xff", 3); + invalid(b"\xef\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xef\xff\x80", 3); + invalid(b"\xef\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xef\xff\x80\x80", 3); + invalid(b"\xf0\x00", 0); + invalid(b"\x41\xc2\xa2\xf0\x00", 3); + invalid(b"\xf0\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x00\x80", 3); + invalid(b"\xf0\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x00\x80\x80", 3); + invalid(b"\xf0\x7f", 0); + invalid(b"\x41\xc2\xa2\xf0\x7f", 3); + invalid(b"\xf0\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x7f\x80", 3); + invalid(b"\xf0\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x7f\x80\x80", 3); + invalid(b"\xf0\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x80", 3); + invalid(b"\xf0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x80\x80", 3); + invalid(b"\xf0\x80\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x80\x80\x80", 3); + invalid(b"\xf0\x8f", 0); + invalid(b"\x41\xc2\xa2\xf0\x8f", 3); + invalid(b"\xf0\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x8f\x80", 3); + invalid(b"\xf0\x8f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x8f\x80\x80", 3); + invalid(b"\xf0\x90", 0); + invalid(b"\x41\xc2\xa2\xf0\x90", 3); + invalid(b"\xf0\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x90\x80", 3); + invalid(b"\xf0\x90\x80\x41", 0); + invalid(b"\x41\xc2\xa2\xf0\x90\x80\x41", 3); + valid(b"\xf0\x90\x80\x80", 65536, 4); + invalid(b"\xf0\x9f", 0); + invalid(b"\x41\xc2\xa2\xf0\x9f", 3); + invalid(b"\xf0\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\x9f\x80", 3); + valid(b"\xf0\x9f\x80\x80", 126976, 4); + invalid(b"\xf0\xa0", 0); + invalid(b"\x41\xc2\xa2\xf0\xa0", 3); + invalid(b"\xf0\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\xa0\x80", 3); + valid(b"\xf0\xa0\x80\x80", 131072, 4); + invalid(b"\xf0\xbf", 0); + invalid(b"\x41\xc2\xa2\xf0\xbf", 3); + invalid(b"\xf0\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\xbf\x80", 3); + valid(b"\xf0\xbf\x80\x80", 258048, 4); + invalid(b"\xf0\xc0", 0); + invalid(b"\x41\xc2\xa2\xf0\xc0", 3); + invalid(b"\xf0\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\xc0\x80", 3); + invalid(b"\xf0\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\xc0\x80\x80", 3); + invalid(b"\xf0\xff", 0); + invalid(b"\x41\xc2\xa2\xf0\xff", 3); + invalid(b"\xf0\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\xff\x80", 3); + invalid(b"\xf0\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf0\xff\x80\x80", 3); + invalid(b"\xf4\x00", 0); + invalid(b"\x41\xc2\xa2\xf4\x00", 3); + invalid(b"\xf4\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x00\x80", 3); + invalid(b"\xf4\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x00\x80\x80", 3); + invalid(b"\xf4\x7f", 0); + invalid(b"\x41\xc2\xa2\xf4\x7f", 3); + invalid(b"\xf4\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x7f\x80", 3); + invalid(b"\xf4\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x7f\x80\x80", 3); + invalid(b"\xf4\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x80", 3); + invalid(b"\xf4\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x80\x80", 3); + valid(b"\xf4\x80\x80\x80", 1048576, 4); + invalid(b"\xf4\x8f", 0); + invalid(b"\x41\xc2\xa2\xf4\x8f", 3); + invalid(b"\xf4\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x8f\x80", 3); + valid(b"\xf4\x8f\x80\x80", 1110016, 4); + invalid(b"\xf4\x90", 0); + invalid(b"\x41\xc2\xa2\xf4\x90", 3); + invalid(b"\xf4\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x90\x80", 3); + invalid(b"\xf4\x90\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x90\x80\x80", 3); + invalid(b"\xf4\x9f", 0); + invalid(b"\x41\xc2\xa2\xf4\x9f", 3); + invalid(b"\xf4\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x9f\x80", 3); + invalid(b"\xf4\x9f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\x9f\x80\x80", 3); + invalid(b"\xf4\xa0", 0); + invalid(b"\x41\xc2\xa2\xf4\xa0", 3); + invalid(b"\xf4\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xa0\x80", 3); + invalid(b"\xf4\xa0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xa0\x80\x80", 3); + invalid(b"\xf4\xbf", 0); + invalid(b"\x41\xc2\xa2\xf4\xbf", 3); + invalid(b"\xf4\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xbf\x80", 3); + invalid(b"\xf4\xbf\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xbf\x80\x80", 3); + invalid(b"\xf4\xc0", 0); + invalid(b"\x41\xc2\xa2\xf4\xc0", 3); + invalid(b"\xf4\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xc0\x80", 3); + invalid(b"\xf4\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xc0\x80\x80", 3); + invalid(b"\xf4\xff", 0); + invalid(b"\x41\xc2\xa2\xf4\xff", 3); + invalid(b"\xf4\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xff\x80", 3); + invalid(b"\xf4\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf4\xff\x80\x80", 3); + invalid(b"\xf5\x00", 0); + invalid(b"\x41\xc2\xa2\xf5\x00", 3); + invalid(b"\xf5\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x00\x80", 3); + invalid(b"\xf5\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x00\x80\x80", 3); + invalid(b"\xf5\x7f", 0); + invalid(b"\x41\xc2\xa2\xf5\x7f", 3); + invalid(b"\xf5\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x7f\x80", 3); + invalid(b"\xf5\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x7f\x80\x80", 3); + invalid(b"\xf5\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x80", 3); + invalid(b"\xf5\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x80\x80", 3); + invalid(b"\xf5\x80\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x80\x80\x80", 3); + invalid(b"\xf5\x8f", 0); + invalid(b"\x41\xc2\xa2\xf5\x8f", 3); + invalid(b"\xf5\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x8f\x80", 3); + invalid(b"\xf5\x8f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x8f\x80\x80", 3); + invalid(b"\xf5\x90", 0); + invalid(b"\x41\xc2\xa2\xf5\x90", 3); + invalid(b"\xf5\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x90\x80", 3); + invalid(b"\xf5\x90\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x90\x80\x80", 3); + invalid(b"\xf5\x9f", 0); + invalid(b"\x41\xc2\xa2\xf5\x9f", 3); + invalid(b"\xf5\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x9f\x80", 3); + invalid(b"\xf5\x9f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\x9f\x80\x80", 3); + invalid(b"\xf5\xa0", 0); + invalid(b"\x41\xc2\xa2\xf5\xa0", 3); + invalid(b"\xf5\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xa0\x80", 3); + invalid(b"\xf5\xa0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xa0\x80\x80", 3); + invalid(b"\xf5\xbf", 0); + invalid(b"\x41\xc2\xa2\xf5\xbf", 3); + invalid(b"\xf5\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xbf\x80", 3); + invalid(b"\xf5\xbf\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xbf\x80\x80", 3); + invalid(b"\xf5\xc0", 0); + invalid(b"\x41\xc2\xa2\xf5\xc0", 3); + invalid(b"\xf5\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xc0\x80", 3); + invalid(b"\xf5\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xc0\x80\x80", 3); + invalid(b"\xf5\xff", 0); + invalid(b"\x41\xc2\xa2\xf5\xff", 3); + invalid(b"\xf5\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xff\x80", 3); + invalid(b"\xf5\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xf5\xff\x80\x80", 3); + invalid(b"\xff\x00", 0); + invalid(b"\x41\xc2\xa2\xff\x00", 3); + invalid(b"\xff\x00\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x00\x80", 3); + invalid(b"\xff\x00\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x00\x80\x80", 3); + invalid(b"\xff\x7f", 0); + invalid(b"\x41\xc2\xa2\xff\x7f", 3); + invalid(b"\xff\x7f\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x7f\x80", 3); + invalid(b"\xff\x7f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x7f\x80\x80", 3); + invalid(b"\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x80", 3); + invalid(b"\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x80\x80", 3); + invalid(b"\xff\x80\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x80\x80\x80", 3); + invalid(b"\xff\x8f", 0); + invalid(b"\x41\xc2\xa2\xff\x8f", 3); + invalid(b"\xff\x8f\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x8f\x80", 3); + invalid(b"\xff\x8f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x8f\x80\x80", 3); + invalid(b"\xff\x90", 0); + invalid(b"\x41\xc2\xa2\xff\x90", 3); + invalid(b"\xff\x90\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x90\x80", 3); + invalid(b"\xff\x90\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x90\x80\x80", 3); + invalid(b"\xff\x9f", 0); + invalid(b"\x41\xc2\xa2\xff\x9f", 3); + invalid(b"\xff\x9f\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x9f\x80", 3); + invalid(b"\xff\x9f\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\x9f\x80\x80", 3); + invalid(b"\xff\xa0", 0); + invalid(b"\x41\xc2\xa2\xff\xa0", 3); + invalid(b"\xff\xa0\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xa0\x80", 3); + invalid(b"\xff\xa0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xa0\x80\x80", 3); + invalid(b"\xff\xbf", 0); + invalid(b"\x41\xc2\xa2\xff\xbf", 3); + invalid(b"\xff\xbf\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xbf\x80", 3); + invalid(b"\xff\xbf\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xbf\x80\x80", 3); + invalid(b"\xff\xc0", 0); + invalid(b"\x41\xc2\xa2\xff\xc0", 3); + invalid(b"\xff\xc0\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xc0\x80", 3); + invalid(b"\xff\xc0\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xc0\x80\x80", 3); + invalid(b"\xff\xff", 0); + invalid(b"\x41\xc2\xa2\xff\xff", 3); + invalid(b"\xff\xff\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xff\x80", 3); + invalid(b"\xff\xff\x80\x80", 0); + invalid(b"\x41\xc2\xa2\xff\xff\x80\x80", 3); + return 0; +} diff --git a/tests/conformance/source/std/text_wrong_module_result.aji b/tests/conformance/source/std/text_wrong_module_result.aji new file mode 100644 index 0000000..98577e2 --- /dev/null +++ b/tests/conformance/source/std/text_wrong_module_result.aji @@ -0,0 +1,10 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §13; docs/spec/16-standard-library.md §2.6 +module test.text_wrong_result +import std.encoding.hex; +import std.encoding.base64; + +fn main() -> std.encoding.hex.EncodeResult +effects [] +{ return std.encoding.base64.EncodeResult::ok(4); } diff --git a/tests/conformance/source/std/unknown_long_member.aji b/tests/conformance/source/std/unknown_long_member.aji new file mode 100644 index 0000000..6c87342 --- /dev/null +++ b/tests/conformance/source/std/unknown_long_member.aji @@ -0,0 +1,8 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/15-source-language.md §13 +module test.long_name +import std.bytes; +fn main() -> u8 +effects [] +{ std.bytes.missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_(); return 0; } diff --git a/tests/conformance/source/std/unknown_member.aji b/tests/conformance/source/std/unknown_member.aji new file mode 100644 index 0000000..e7280e0 --- /dev/null +++ b/tests/conformance/source/std/unknown_member.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ std.bytes.missing(); return 0; } diff --git a/tests/conformance/source/std/unknown_module.aji b/tests/conformance/source/std/unknown_module.aji new file mode 100644 index 0000000..d9b86cd --- /dev/null +++ b/tests/conformance/source/std/unknown_module.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.missing; + +fn main() -> u8 +effects [] +{ return 0; } diff --git a/tests/conformance/source/std/unqualified.aji b/tests/conformance/source/std/unqualified.aji new file mode 100644 index 0000000..864d468 --- /dev/null +++ b/tests/conformance/source/std/unqualified.aji @@ -0,0 +1,9 @@ +// expect: reject E7002 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ fill(0); return 0; } diff --git a/tests/conformance/source/std/wrong_arity.aji b/tests/conformance/source/std/wrong_arity.aji new file mode 100644 index 0000000..c48a59d --- /dev/null +++ b/tests/conformance/source/std/wrong_arity.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.math; + +fn main() -> u8 +effects [] +{ std.math.min_u64(1); return 0; } diff --git a/tests/conformance/source/std/wrong_type.aji b/tests/conformance/source/std/wrong_type.aji new file mode 100644 index 0000000..8610cb0 --- /dev/null +++ b/tests/conformance/source/std/wrong_type.aji @@ -0,0 +1,9 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13 +module test.standard +import std.bytes; + +fn main() -> u8 +effects [] +{ std.bytes.find(b"x", 0u64); return 0; } diff --git a/tests/conformance/static_functions/copy.air b/tests/conformance/static_functions/copy.air new file mode 100644 index 0000000..29c16bb --- /dev/null +++ b/tests/conformance/static_functions/copy.air @@ -0,0 +1,23 @@ +; expect: run +; result: 42 +; phase: 6 +; spec: docs/spec/15-source-language.md §18; docs/spec/07a-air-instructions.md call +module test.static_functions +air 0 +lang 0.1 +features [effects] +fn @identity(%value: u64) -> u64 +effects [] +entry: + ret %value +fn @apply(%value: u64) -> u64 +effects [] +entry: + %result = call @identity(%value) + ret %result +fn @main() -> u64 +effects [] +entry: + %value = const.u64 42 + %result = call @apply(%value) + ret %result diff --git a/tests/conformance/static_functions/missing_effect.air b/tests/conformance/static_functions/missing_effect.air new file mode 100644 index 0000000..edf9a9c --- /dev/null +++ b/tests/conformance/static_functions/missing_effect.air @@ -0,0 +1,17 @@ +; expect: reject E3101 +; phase: 6 +; spec: docs/spec/15-source-language.md §18; docs/spec/05-effects-and-capabilities.md +module test.static_functions +air 0 +lang 0.1 +features [effects] +fn @selected() -> u64 +effects [io.write] +entry: + %result = const.u64 42 + ret %result +fn @apply() -> u64 +effects [] +entry: + %result = call @selected() + ret %result diff --git a/tests/conformance/static_functions/owner_leak.air b/tests/conformance/static_functions/owner_leak.air new file mode 100644 index 0000000..278b40c --- /dev/null +++ b/tests/conformance/static_functions/owner_leak.air @@ -0,0 +1,17 @@ +; expect: reject E3002 +; phase: 6 +; spec: docs/spec/15-source-language.md §18; docs/spec/03-memory-model.md +module test.static_functions +air 0 +lang 0.1 +features [capabilities, effects, heap, ownership, resources] +fn @selected(%value: own) -> u64 +effects [] +entry: + %result = const.u64 42 + ret %result +fn @apply(%value: own) -> u64 +effects [] +entry: + %result = call @selected(%value) + ret %result diff --git a/tests/conformance/std/bounded_arithmetic.air b/tests/conformance/std/bounded_arithmetic.air new file mode 100644 index 0000000..ae767ac --- /dev/null +++ b/tests/conformance/std/bounded_arithmetic.air @@ -0,0 +1,33 @@ +; expect: run +; result: {"variant":"overflow","payload":[]} +; phase: 0 +; spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/07a-air-instructions.md +module test.bounded_arithmetic +air 0 +lang 0.1 +features [effects] + +type @U64Result = enum { ok(u64), overflow } + +fn @main() -> @U64Result +effects [] +entry: + %a = const.u64 18446744073709551615 + %b = const.u64 1 + %result = call @checked_add(%a, %b) + ret %result + +fn @checked_add(%a: u64, %b: u64) -> @U64Result +effects [] +entry: + %maximum = const.u64 18446744073709551615 + %remaining = sub.checked.u64 %maximum, %a + %overflows = gt.u64 %b, %remaining + cbr %overflows, @failure(), @success() +failure: + %error = enum.make @U64Result.overflow() + ret %error +success: + %sum = add.checked.u64 %a, %b + %ok = enum.make @U64Result.ok(%sum) + ret %ok diff --git a/tests/conformance/std/bounded_arithmetic_payload.air b/tests/conformance/std/bounded_arithmetic_payload.air new file mode 100644 index 0000000..54d4c23 --- /dev/null +++ b/tests/conformance/std/bounded_arithmetic_payload.air @@ -0,0 +1,16 @@ +; expect: reject E1001 +; phase: 0 +; spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/07a-air-instructions.md +module test.bounded_payload +air 0 +lang 0.1 +features [] + +type @U64Result = enum { ok(u64), overflow } + +fn @main() -> @U64Result +effects [] +entry: + %wrong = const.bool true + %result = enum.make @U64Result.ok(%wrong) + ret %result diff --git a/tests/conformance/std/bounded_copy.air b/tests/conformance/std/bounded_copy.air new file mode 100644 index 0000000..253adee --- /dev/null +++ b/tests/conformance/std/bounded_copy.air @@ -0,0 +1,64 @@ +; expect: run +; result: [5,5,5,165] +; phase: 1 +; spec: docs/spec/16-standard-library.md §2.4; docs/spec/07a-air-instructions.md +module test.bounded_copy +air 0 +lang 0.1 +features [arrays, effects, ownership] + +type @WriteResult = enum { ok, short_output } + +fn @main() -> array +effects [] +entry: + %src_storage = local.alloc array + %dst_storage = local.alloc array + %five = const.u8 5 + %marker = const.u8 165 + %src_value = array.splat array %five + %dst_value = array.splat array %marker + local.store %src_storage, %src_value + local.store %dst_storage, %dst_value + %r = borrow.ref %src_storage + %src = slice.make %r + %m = borrow.mut %dst_storage + %dst = slice.make %m + %zero = const.usize 0 + %two = const.usize 2 + %short_dst = slice.sub %dst, %zero, %two + %short = call @copy(%short_dst, %src) + borrow.end %short_dst + %first = borrow.index %dst, %zero + %untouched = load %first + borrow.end %first + %same = eq.u8 %untouched, %marker + assert %same + enum.switch @WriteResult %short, ok -> @bad, short_output -> @copy_all +bad: + trap +copy_all: + %full = call @copy(%dst, %src) + enum.switch @WriteResult %full, ok -> @done, short_output -> @bad +done: + borrow.end %dst + borrow.end %m + borrow.end %src + borrow.end %r + %result = local.load %dst_storage + ret %result + +fn @copy(%dst: slice_mut, %src: slice) -> @WriteResult +effects [] +entry: + %capacity = slice.len %dst + %count = slice.len %src + %short = lt.usize %capacity, %count + cbr %short, @failure(), @success() +failure: + %error = enum.make @WriteResult.short_output() + ret %error +success: + slice.copy %dst, %src + %ok = enum.make @WriteResult.ok() + ret %ok diff --git a/tests/conformance/std/endian_payload_type.air b/tests/conformance/std/endian_payload_type.air new file mode 100644 index 0000000..96044af --- /dev/null +++ b/tests/conformance/std/endian_payload_type.air @@ -0,0 +1,16 @@ +; expect: reject E1001 +; phase: 0 +; spec: docs/spec/07a-air-instructions.md; docs/spec/16-standard-library.md §2.3 +module test.endian_payload_type +air 0 +lang 0.1 +features [] + +type @ReadU16 = enum { ok(u16), short_input } + +fn @main() -> @ReadU16 +effects [] +entry: + %wrong = const.u32 4660 + %result = enum.make @ReadU16.ok(%wrong) + ret %result diff --git a/tests/conformance/std/endian_read.air b/tests/conformance/std/endian_read.air new file mode 100644 index 0000000..118c88b --- /dev/null +++ b/tests/conformance/std/endian_read.air @@ -0,0 +1,63 @@ +; expect: run +; result: {"variant":"ok","payload":[4660]} +; phase: 1 +; spec: docs/spec/16-standard-library.md §2.3; docs/spec/07a-air-instructions.md +module test.endian_read +air 0 +lang 0.1 +features [arrays, ownership] + +type @ReadU16 = enum { ok(u16), short_input } + +fn @main() -> @ReadU16 +effects [] +entry: + %storage = local.alloc array + local.zero %storage + %m = borrow.mut %storage + %dst = slice.make %m + %zero = const.usize 0 + %one = const.usize 1 + %lo = const.u8 52 + %hi = const.u8 18 + %d0 = borrow.index %dst, %zero + store %d0, %lo + borrow.end %d0 + %d1 = borrow.index %dst, %one + store %d1, %hi + borrow.end %d1 + borrow.end %dst + borrow.end %m + %r = borrow.ref %storage + %src = slice.make %r + %result = call @read_u16_le(%src) + borrow.end %src + borrow.end %r + ret %result + +fn @read_u16_le(%src: slice) -> @ReadU16 +effects [] +entry: + %n = slice.len %src + %two = const.usize 2 + %short = lt.usize %n, %two + cbr %short, @short_input(), @decode() +short_input: + %failure = enum.make @ReadU16.short_input() + ret %failure +decode: + %zero = const.usize 0 + %one = const.usize 1 + %e0 = borrow.index %src, %zero + %b0 = load %e0 + borrow.end %e0 + %e1 = borrow.index %src, %one + %b1 = load %e1 + borrow.end %e1 + %lo = cast.checked.u16 %b0 + %hi = cast.checked.u16 %b1 + %eight = const.u16 8 + %shifted = shl.u16 %hi, %eight + %value = or.u16 %lo, %shifted + %success = enum.make @ReadU16.ok(%value) + ret %success diff --git a/tests/conformance/std/fmt_count.air b/tests/conformance/std/fmt_count.air new file mode 100644 index 0000000..dcf57eb --- /dev/null +++ b/tests/conformance/std/fmt_count.air @@ -0,0 +1,17 @@ +; expect: run +; result: {"variant":"ok","payload":[20]} +; phase: 0 +; spec: docs/spec/16-standard-library.md §2.8; docs/spec/07a-air-instructions.md +module test.fmt_count +air 0 +lang 0.1 +features [] + +type @WriteResult = enum { ok(usize), short_output } + +fn @main() -> @WriteResult +effects [] +entry: + %count = const.usize 20 + %result = enum.make @WriteResult.ok(%count) + ret %result diff --git a/tests/conformance/std/minimum.air b/tests/conformance/std/minimum.air new file mode 100644 index 0000000..923b248 --- /dev/null +++ b/tests/conformance/std/minimum.air @@ -0,0 +1,26 @@ +; expect: run +; result: 7 +; phase: 0 +; spec: docs/spec/07a-air-instructions.md; docs/spec/16-standard-library.md +module test.minimum +air 0 +lang 0.1 +features [effects] + +fn @main() -> u64 +effects [] +entry: + %a = const.u64 7 + %b = const.u64 11 + %v = call @min(%a, %b) + ret %v + +fn @min(%a: u64, %b: u64) -> u64 +effects [] +entry: + %less = lt.u64 %a, %b + cbr %less, @left(), @right() +left: + ret %a +right: + ret %b diff --git a/tests/conformance/std/text_base64_encode.air b/tests/conformance/std/text_base64_encode.air new file mode 100644 index 0000000..c68521c --- /dev/null +++ b/tests/conformance/std/text_base64_encode.air @@ -0,0 +1,31 @@ +; expect: run +; result: [90,103,61,61] +; phase: 1 +; spec: docs/spec/16-standard-library.md §2.6.2; docs/spec/07a-air-instructions.md +; Independent RFC 4648 vector: encoding byte 102 produces ASCII Zg==. +module test.text_encode +air 0 +lang 0.1 +features [arrays, ownership] + +fn @main() -> array +effects [] +entry: + %storage = local.alloc array + %pad = const.u8 61 + %initial = array.splat array %pad + local.store %storage, %initial + %m = borrow.mut %storage + %zero = const.usize 0 + %one = const.usize 1 + %a = const.u8 90 + %b = const.u8 103 + %e0 = borrow.index %m, %zero + store %e0, %a + borrow.end %e0 + %e1 = borrow.index %m, %one + store %e1, %b + borrow.end %e1 + borrow.end %m + %result = local.load %storage + ret %result diff --git a/tests/conformance/std/text_utf8_payload.air b/tests/conformance/std/text_utf8_payload.air new file mode 100644 index 0000000..4b0c433 --- /dev/null +++ b/tests/conformance/std/text_utf8_payload.air @@ -0,0 +1,17 @@ +; expect: reject E1001 +; phase: 0 +; spec: docs/spec/16-standard-library.md §2.5; docs/spec/07a-air-instructions.md +module test.text_payload +air 0 +lang 0.1 +features [] + +type @NextResult = enum { ok(u32, usize), end, invalid_input } + +fn @main() -> @NextResult +effects [] +entry: + %scalar = const.bool true + %count = const.usize 3 + %result = enum.make @NextResult.ok(%scalar, %count) + ret %result diff --git a/tests/conformance/std/text_utf8_scalar.air b/tests/conformance/std/text_utf8_scalar.air new file mode 100644 index 0000000..cedeb8c --- /dev/null +++ b/tests/conformance/std/text_utf8_scalar.air @@ -0,0 +1,18 @@ +; expect: run +; result: {"variant":"ok","payload":[8364,3]} +; phase: 0 +; spec: docs/spec/16-standard-library.md §2.5; docs/spec/07a-air-instructions.md +module test.text_scalar +air 0 +lang 0.1 +features [] + +type @NextResult = enum { ok(u32, usize), end, invalid_input } + +fn @main() -> @NextResult +effects [] +entry: + %scalar = const.u32 8364 + %count = const.usize 3 + %result = enum.make @NextResult.ok(%scalar, %count) + ret %result diff --git a/tests/hosted/source_buffered_io.py b/tests/hosted/source_buffered_io.py new file mode 100644 index 0000000..38d7a93 --- /dev/null +++ b/tests/hosted/source_buffered_io.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python3 +"""Owning buffered adapters: CLI/AIR/packages, hosted failure and no retry.""" +import base64 +import json +from pathlib import Path +import resource +import signal +import subprocess +import sys +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +CASES = REPO / "tests/conformance/source/buffered_io" +checks = 0 + + +def cli(*args, code=0, **kwargs): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True, **kwargs) + detail = None + if run.returncode != code and "--result-file" in args: + result = Path(args[args.index("--result-file") + 1]) + if result.exists(): + detail = result.read_text() + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr, detail) + checks += 1 + return run.stdout + + +def returned(path, *grants, extra=()): + args = [item for grant in grants for item in ("--grant", grant)] + record = json.loads(cli("run", "--fuel", "2000000", *args, *extra, path)) + assert record["status"] == "returned", record + return record + + +example = REPO / "examples/std/buffered_io.aji" +grants = ("src=fs.read:/in", "dst=fs.write:/out", "heap=mem.alloc:6") +record = returned(example, *grants, extra=("--vfs", "/in/data=abcdefgh")) +assert record["value"] == 8 and base64.b64decode(record["files"]["/out/data"]["data"]) == b"abcdefgh", record +cli("check", example) +report = json.loads(cli("report", example)) +assert report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report +canonical = cli("lower", example) +assert canonical == cli("lower", example) +for path in sorted(CASES.glob("*.aji")): + if "// expect: run\n" not in path.read_text(): + continue + args = [] + for line in path.read_text().splitlines(): + if line.startswith("// grant: "): + args.extend(("--grant", line.removeprefix("// grant: "))) + if line.startswith("// vfs: "): + args.extend(("--vfs", line.removeprefix("// vfs: "))) + assert returned(path, extra=args)["value"] == 42 +for name, expected in (("missing_read_effect", "E3101"), ("missing_write_effect", "E3101"), + ("missing_alloc_effect", "E3101"), ("wrong_kind", "E7005"), ("wrong_mode", "E7005"), + ("missing_move", "E7003"), ("discard_leak", "E3002"), ("finish_error_leak", "E3002"), + ("reader_alias", "E2101"), ("writer_alias", "E2101"), ("loan", "E4101"), ("not_share", "E4002")): + commands = ("check", "lower", "report", "run", "explore") if expected in ("E7003", "E7005") else ("check", "report", "run", "explore") + for command in commands: + path = CASES / (name + ".aji") + errors = [json.loads(line) for line in cli(command, path, code=1).splitlines()] + assert errors and {error["code"] for error in errors} == {expected}, errors + assert all(Path(error["file"]).resolve() == path.resolve() for error in errors), errors + +CHECK_ERROR = '''fn error_is_other(error: io_error) -> void effects [] { + match error { io_error::other => {}, _ => { trap; } } +} +fn flush_failed(result: std.io.writer.FlushResult) -> void effects [] { + match result { std.io.writer.FlushResult::err(error) => { error_is_other(error); }, std.io.writer.FlushResult::ok => { trap; } } +} +fn write_failed(result: std.io.writer.WriteResult,accepted: usize) -> void effects [] { + match result { std.io.writer.WriteResult::err(error) => { assert(error.accepted == accepted); error_is_other(error.error); }, std.io.writer.WriteResult::ok => { trap; } } +} +fn pending(value: ref,expected: usize) -> void effects [] { + assert(value.used == expected); + if expected != 0usize { ref storage = value.storage; ref bytes = buffer.view(storage); assert(bytes[0] == 99u8); assert(bytes[1] == 100u8); } +} +''' +# Enum matches are exhaustive (no enum wildcard); construct the remaining arms. +TAGS = ("not_found", "permission_denied", "already_exists", "invalid_input", "no_space", "broken_pipe", + "connection_refused", "connection_reset", "address_in_use", "address_unavailable", "timed_out") +CHECK_ERROR = CHECK_ERROR.replace('_ => { trap; }', ', '.join(f'io_error::{tag} => {{ trap; }}' for tag in TAGS)) +with tempfile.TemporaryDirectory(prefix="aji-buffered-io-") as directory: + root = Path(directory) + air = root / "lowered.air" + air.write_text(canonical) + cli("check", air) + assert returned(air, *grants, extra=("--vfs", "/in/data=abcdefgh")) == record + entry, manifest = root / "main.aji", root / "aji.toml" + entry.write_text(example.read_text()) + manifest.write_text('[package]\nname = "buffered"\nversion = "1"\nentry = "main.aji"\n[capabilities]\nsrc = "fs.read:/in"\ndst = "fs.write:/out"\nheap = "mem.alloc:6"\n') + package = json.loads(cli("run", "--fuel", "2000000", "--vfs", "/in/data=abcdefgh", "--manifest", manifest)) + assert package == record, package + assert cli("lower", "--manifest", manifest) == canonical + entry.write_text(example.read_text().replace('import std.io.reader;\nimport std.io.writer;', 'import std.io.writer;\nimport std.io.reader;')) + assert cli("lower", "--manifest", manifest) == canonical + source, target, result = root / "input", root / "output", root / "result.json" + source.write_text("abcdefgh") + entry.write_text(example.read_text().replace('b"/in/data"', f'b"{source}"').replace('b"/out/data"', f'b"{target}"')) + stdout = cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", f"src=fs.read:{root}", "--grant", f"dst=fs.write:{root}", "--grant", "heap=mem.alloc:6", "--result-file", result, entry) + assert stdout == "" and json.loads(result.read_text())["value"] == 8 and target.read_bytes() == b"abcdefgh" + # Linux /proc/self/mem opens normally but offset zero cannot be read. + # No memory contents are read; the hosted primitive returns EIO / other. + if sys.platform.startswith("linux"): + entry.write_text('''module app.read_error +import std.io; +import std.io.reader; +''' + CHECK_ERROR.split("fn flush_failed")[0] + '''fn main(src: cap,heap: cap) -> u64 effects [fs.read,mem.alloc] { + let file = fs.open_read(src,b"/proc/self/mem") or trap; + match std.io.reader.new(move file,3usize,heap) { + std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => { + var bytes: [u8;6] = [99u8;6]; + { mut q = value; match std.io.reader.read_exact(q,mut bytes[1usize..5usize]) { + std.io.ReadExactResult::err(error) => { assert(error.completed == 0usize); error_is_other(error.error); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::eof(n) => { trap; } + } + assert(q.begin == 0usize); assert(q.end == 0usize); + match std.io.reader.read(q,mut bytes[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } + match std.io.reader.read(q,mut bytes[1usize..5usize]) { std.io.reader.ReadResult::err(error) => { error_is_other(error); }, std.io.reader.ReadResult::ok(n) => { trap; } } + } + assert(bytes[0] == 99u8); assert(bytes[5] == 99u8); + let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 0usize); fs.close(move file) or trap; + } + } + let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42; +} +''') + cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", "src=fs.read:/proc/self", "--grant", "heap=mem.alloc:3", "--result-file", result, entry) + assert json.loads(result.read_text())["value"] == 42 + + def partial_write_limit(): + signal.signal(signal.SIGXFSZ, signal.SIG_IGN) + resource.setrlimit(resource.RLIMIT_FSIZE, (3, 1048576)) + + for mode in ("room", "prior", "flush", "direct"): + capacity = 0 if mode == "direct" else 2 + initial = { + "direct": 'write_failed(std.io.writer.write(q,b"abcdef"),0usize);', + "room": 'write_failed(std.io.writer.write(q,b"abcdef"),4usize);', + "prior": 'match std.io.writer.write(q,b"ab") { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } write_failed(std.io.writer.write(q,b"cdefgh"),2usize);', + "flush": 'match std.io.writer.write(q,b"abcd") { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } flush_failed(std.io.writer.flush(q));', + }[mode] + entry.write_text('''module app.partial_write +import std.io; +import std.io.writer; +import std.option; +''' + CHECK_ERROR + f'''fn main(dst: cap,heap: cap,input: cap,print: cap) -> u64 effects [fs.write,mem.alloc,io.read,io.write] {{ + let file = fs.create(dst,b"{target}") or trap; + match std.io.writer.new(move file,{capacity}usize,heap) {{ + std.io.writer.NewResult::err(error) => {{ trap; }}, std.io.writer.NewResult::ok(value) => {{ + {{ mut q = value; {initial} pending(ref q,{capacity}usize); + match q.failed {{ std.option.Option::::some(error) => {{ error_is_other(error); }}, std.option.Option::::none => {{ trap; }} }} + }} + io.stdout_write(print,b"E") or trap; + var ack: [u8;1] = [0u8;1]; match std.io.read_exact_stdin(input,mut ack) {{ std.io.ReadExactResult::ok => {{}}, std.io.ReadExactResult::eof(n) => {{ trap; }}, std.io.ReadExactResult::err(error) => {{ trap; }} }} assert(ack[0] == 89u8); + {{ mut q = value; flush_failed(std.io.writer.flush(q)); write_failed(std.io.writer.write(q,b"z"),0usize); write_failed(std.io.writer.write(q,ref ack[0usize..0usize]),0usize); pending(ref q,{capacity}usize); }} + match std.io.writer.finish(move value) {{ + std.io.writer.FinishResult::ok(file) => {{ trap; }}, std.io.writer.FinishResult::err(error) => {{ + let (writer,error) = struct.unpack(move error); error_is_other(error); + let (file,pending,failed) = struct.unpack(std.io.writer.discard(move writer)); assert(pending == {capacity}usize); + match failed {{ std.option.Option::::some(error) => {{ error_is_other(error); }}, std.option.Option::::none => {{ trap; }} }} fs.close(move file) or trap; + }} + }} + }} + }} + let allocation = own.new([0u8;2],heap) or trap; own.free(move allocation); io.stdout_write(print,b"42") or trap; return 42; +}} +''') + cli("check", entry) + command = [str(AJI), "run", "--profile", "hosted", "--fuel", "2000000", "--grant", f"dst=fs.write:{root}", "--grant", "heap=mem.alloc:2", "--grant", "input=io.read", "--grant", "print=io.write", str(entry)] + with subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=partial_write_limit) as process: + marker = process.stdout.read(1) + if marker != b"E": + output, error = process.communicate() + raise AssertionError((mode, marker, process.returncode, output, error)) + assert target.read_bytes() == b"abc", (mode, target.read_bytes()) + # On Linux raise the child's quota before subsequent calls. A retry + # would now succeed and append duplicated buffered bytes to the file. + if hasattr(resource, "prlimit"): + resource.prlimit(process.pid, resource.RLIMIT_FSIZE, (1048576, 1048576)) + output, error = process.communicate(b"Y") + assert process.returncode == 0 and output == b"42", (mode, process.returncode, output, error) + assert target.read_bytes() == b"abc", (mode, target.read_bytes()) + checks += 1 + +print(f"buffered I/O integration passed ({checks} checks, partial room/flush/direct writes; Linux read error and raised-quota no retry)") diff --git a/tests/hosted/source_buffers.py b/tests/hosted/source_buffers.py new file mode 100644 index 0000000..28461b7 --- /dev/null +++ b/tests/hosted/source_buffers.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +"""Initialized storage, resource vectors, canonical AIR and CLI contracts.""" +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/buffers" +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", "200000", *arguments, path)) + assert record["status"] == "returned" and record["value"] == 42, record + return record + + +assert "linear_buffers" in json.loads(cli("features"))["features"] +example = REPO / "examples/std/vector.aji" +returned(example, "heap=mem.alloc:256") +report = json.loads(cli("report", FIXTURES / "owner.aji")) +assert sum(function["allocations"] for function in report["functions"]) == 3, report +with tempfile.TemporaryDirectory(prefix="aji-buffers-") as directory: + root = Path(directory) + air = root / "result.air" + for fixture, grants in ( + ("owner", ("heap=mem.alloc:128",)), + ("push_failure", ("heap=mem.alloc:8",)), + ("free_failure", ("heap=mem.alloc:128",)), + ("reserve_failure", ("heap=mem.alloc:24",)), + ("reserve_authority", ("first=mem.alloc:8", "second=mem.alloc:16")), + ("long_reuse", ("heap=mem.alloc:16",)), + ("nested", ("heap=mem.alloc:128",)), + ("view", ("heap=mem.alloc:16",)), + ("vec_copy", ("heap=mem.alloc:128",)), + ("vec_replace_owner", ("heap=mem.alloc:128",)), + ("vec_file", ("heap=mem.alloc:128", "dst=fs.write:/out")), + ("vec_sender", ("heap=mem.alloc:128",)), + ): + source = FIXTURES / f"{fixture}.aji" + cli("check", source) + canonical = cli("lower", source) + assert cli("lower", source) == canonical + assert "linear_buffers" in canonical + air.write_text(canonical) + cli("check", air) + direct = returned(source, *grants) + round_trip = returned(air, *grants) + assert direct == round_trip, (direct, round_trip) + # Compiler-pinned vectors retain nominal ownership across package modules. + (root / "lib.aji").write_text( + "module app.lib\nimport std.vec;\n" + "fn identity(value: std.vec.Vec) -> std.vec.Vec effects [] { return move value; }\n" + ) + source = example.read_text().replace("module example.vector", "module app.main") + source = source.replace("import std.vec;", "import std.vec;\nimport app.lib;") + source = source.replace("::ok(value) => {", "::ok(value) => {\n let value = app.lib.identity::>(move value);") + (root / "main.aji").write_text(source) + manifest = root / "aji.toml" + manifest.write_text('[package]\nname = "buffers"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.lib = "lib.aji"\n') + cli("check", "--manifest", manifest) + cli("report", "--manifest", manifest) + assert json.loads(cli("run", "--fuel", "200000", "--manifest", manifest, "--grant", "heap=mem.alloc:128"))["value"] == 42 + cli("explore", "--max-runs", "8", "--manifest", manifest, "--grant", "heap=mem.alloc:128") + # Same buffer/Vec runtime in hosted mode; the run record is explicitly directed to a file. + result_path = root / "hosted.json" + cli("run", "--profile", "hosted", "--result-file", result_path, "--fuel", "200000", "--grant", "heap=mem.alloc:128", example) + record = json.loads(result_path.read_text()) + assert record["status"] == "returned" and record["value"] == 42, record + +for fixture, expected in ( + ("borrow_conflict", "E2101"), + ("task_loan", "E4101"), + ("push_failure_leak", "E3002"), + ("free_failure_leak", "E3002"), + ("missing_move", "E7003"), + ("duplicate_owner", "E2002"), + ("recursive", "E1003"), + ("vec_get_owner", "E7005"), + ("generic_borrow_move", "E7006"), +): + for command in ("check", "report", "run", "explore"): + diagnostics = [json.loads(line) for line in cli(command, FIXTURES / f"{fixture}.aji", code=1).splitlines()] + assert diagnostics[0]["code"] == expected, diagnostics +for fixture in ("task_loan_join", "vec_sender"): + cli("explore", "--max-runs", "16", "--grant", "heap=mem.alloc:128", FIXTURES / f"{fixture}.aji") +print(f"source buffers CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_deque.py b/tests/hosted/source_deque.py new file mode 100644 index 0000000..27ec671 --- /dev/null +++ b/tests/hosted/source_deque.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +"""Safe owning ring order, explicit allocation, canonical AIR and CLI contracts.""" +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/deque" +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/deque.aji" +returned(example, "heap=mem.alloc:1024") +report = json.loads(cli("report", FIXTURES / "wrap_reserve.aji")) +assert sum(function["allocations"] for function in report["functions"]) == 6, report +with tempfile.TemporaryDirectory(prefix="aji-deque-") as directory: + root = Path(directory) + air = root / "result.air" + for fixture, grants in ( + ("copy", ("heap=mem.alloc:1024",)), + ("owner", ("heap=mem.alloc:34",)), + ("wrap_reserve", ("heap=mem.alloc:128",)), + ("reserve_failure", ("heap=mem.alloc:80",)), + ("reserve_authority", ("first=mem.alloc:27", "second=mem.alloc:45", "items=mem.alloc:16")), + ("replace_owner", ("heap=mem.alloc:128",)), + ("zero", ("heap=mem.alloc:8",)), + ("full", ("heap=mem.alloc:25",)), + ("allocation_tag", ("heap=mem.alloc:8",)), + ("reuse", ("heap=mem.alloc:26",)), + ("model", ("heap=mem.alloc:2048",)), + ("growth_matrix", ("heap=mem.alloc:256",)), + ("file", ("heap=mem.alloc:256", "dst=fs.write:/out")), + ("sender", ("heap=mem.alloc:256",)), + ): + source = FIXTURES / f"{fixture}.aji" + cli("check", source) + canonical = cli("lower", source) + assert cli("lower", source) == canonical + assert "linear_buffers" in canonical + air.write_text(canonical) + cli("check", air) + assert returned(source, *grants) == returned(air, *grants) + # Import order cannot change canonical specializations or linked declarations. + canonical = cli("lower", example) + reordered = root / "reordered.aji" + reordered.write_text(example.read_text().replace("import std.deque;\nimport std.option;", "import std.option;\nimport std.deque;")) + assert cli("lower", reordered) == canonical + # Ownership survives nominal imported contracts and manifest loading. + (root / "lib.aji").write_text( + "module app.lib\nimport std.deque;\n" + "fn identity(value: std.deque.Deque) -> std.deque.Deque effects [] { return move value; }\n" + ) + source = example.read_text().replace("module example.deque", "module app.main") + source = source.replace("import std.deque;", "import std.deque;\nimport app.lib;") + source = source.replace("let value = opened::>(2, heap);", "let original = opened::>(2, heap);\n let value = app.lib.identity::>(move original);") + (root / "main.aji").write_text(source) + manifest = root / "aji.toml" + manifest.write_text('[package]\nname = "deque"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.lib = "lib.aji"\n') + cli("check", "--manifest", manifest) + cli("report", "--manifest", manifest) + assert json.loads(cli("run", "--manifest", manifest, "--grant", "heap=mem.alloc:128"))["value"] == 42 + cli("explore", "--max-runs", "8", "--manifest", manifest, "--grant", "heap=mem.alloc:128") + result_path = root / "hosted.json" + cli("run", "--profile", "hosted", "--result-file", result_path, "--fuel", "200000", "--grant", "heap=mem.alloc:128", example) + record = json.loads(result_path.read_text()) + assert record["status"] == "returned" and record["value"] == 42, record + +for fixture, expected in ( + ("alias", "E2101"), + ("slot_view", "E2101"), + ("loan", "E4101"), + ("not_share", "E4002"), + ("missing_move", "E7003"), + ("double_move", "E2002"), + ("get_owner", "E7005"), + ("free_leak", "E3002"), + ("full_leak", "E3002"), + ("pop_leak", "E3002"), +): + for command in ("check", "report", "run", "explore"): + diagnostics = [json.loads(line) for line in cli(command, FIXTURES / f"{fixture}.aji", code=1).splitlines()] + assert diagnostics[0]["code"] == expected, diagnostics +for fixture in ("loan_join", "sender", "shared"): + cli("explore", "--max-runs", "12", "--grant", "heap=mem.alloc:256", FIXTURES / f"{fixture}.aji") +print(f"source deque CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_errors.py b/tests/hosted/source_errors.py new file mode 100644 index 0000000..3982f14 --- /dev/null +++ b/tests/hosted/source_errors.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +"""Explicit error values: canonical AIR, pure audit and hosted execution.""" +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/error_values" +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 + + +features = json.loads(cli("features")) +assert "error_values" in features["features"], features +with tempfile.TemporaryDirectory(prefix="aji-errors-") as directory: + root = Path(directory) + air = root / "result.air" + for family in ("alloc_error", "cap_error", "io_error"): + source = FIXTURES / f"{family}.aji" + canonical = cli("lower", source) + assert cli("lower", source) == canonical + assert "error_values" in canonical and f"error.const {family}." in canonical + air.write_text(canonical) + cli("check", air) + assert cli("run", source) == cli("run", air) + report = json.loads(cli("report", source)) + assert report["entry"]["capabilities"] == [], report + assert all(function["allocations"] == 0 for function in report["functions"]), report + result_file = root / "hosted.json" + assert cli("run", "--profile", "hosted", "--result-file", result_file, source) == "" + record = json.loads(result_file.read_text()) + assert record["status"] == "returned" and record["value"] == 42, record + for name, code in (("no_authority", "E7005"), ("payload", "E7005"), + ("unknown_variant", "E7002"), ("wrong_family", "E7005")): + diagnostics = cli("check", FIXTURES / f"{name}.aji", code=1) + assert [json.loads(line)["code"] for line in diagnostics.splitlines()] == [code] +print(f"source errors: {checks} checks passed") diff --git a/tests/hosted/source_generics.py b/tests/hosted/source_generics.py new file mode 100644 index 0000000..6ddf027 --- /dev/null +++ b/tests/hosted/source_generics.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +"""Source generic CLI integration; finite programs use interpreter fuel.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +checks = 0 + + +def cli(*args, code=0): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +example = REPO / "examples/std/generics.aji" +assert json.loads(cli("run", "--fuel", "1000000", example))["value"] == 42 +cli("check", example) +cli("report", example) +cli("explore", "--max-runs", "8", example) +canonical = cli("lower", example) +assert cli("lower", example) == canonical +with tempfile.TemporaryDirectory(prefix="aji-generics-") as directory: + root = Path(directory) + air = root / "result.air" + air.write_text(canonical) + cli("check", air) + assert json.loads(cli("run", "--fuel", "1000000", air))["value"] == 42 + entry = root / "main.aji" + lib = root / "lib.aji" + manifest = root / "aji.toml" + manifest.write_text('[package]\nname = "fixture"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.lib = "lib.aji"\n') + lib.write_text("module app.lib\nfn id(value: T) -> T effects [] { return value; }\n") + entry.write_text("module app.entry\nimport app.lib;\nstruct Pair { value: u64 }\nfn main() -> u64 effects [] { return app.lib.id::(Pair { value: 42 }).value; }\n") + assert json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest))["value"] == 42 + cli("report", "--manifest", manifest) + cli("explore", "--max-runs", "8", "--manifest", manifest) + assert "__aji_g_" in cli("lower", "--manifest", manifest) + lib.write_text("module app.lib\nfn id(value: T) -> T effects [] { assert(false); return value; }\n") + record = json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest, code=4)) + assert record["source_location"]["file"] == "lib.aji" + lib.write_text("module app.lib\nfn id(value: T) -> T effects [] { return missing(value); }\n") + error = json.loads(cli("check", "--manifest", manifest, code=1)) + assert error["code"] == "E7002" and error["file"] == "lib.aji" + lib.write_text("module app.lib\nfn id(value: T) -> T effects [] { return value; }\n") + entry.write_text("module app.entry\nimport app.lib;\nfn main() -> u64 effects [] { return app.lib.id::>(0); }\n") + for command in ("check", "lower", "report", "run", "explore"): + error = json.loads(cli(command, "--manifest", manifest, code=1)) + assert error["code"] == "E7005" and error["constraint"] == "Copy" and error["parameter"] == "T" + entry.write_text("module app.entry\nimport app.lib;\nfn main() -> u64 effects [] { return app.lib.id::(); }\n") + error = json.loads(cli("check", "--manifest", manifest, code=1)) + assert error["function"] == "app.lib.id" +print(f"source generic CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_hash.py b/tests/hosted/source_hash.py new file mode 100644 index 0000000..d841e87 --- /dev/null +++ b/tests/hosted/source_hash.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""Pure hashes, canonical source/AIR, package/hosted CLI and borrow contracts.""" +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/hash" +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/hash.aji" +returned(example) +with tempfile.TemporaryDirectory(prefix="aji-hash-") as directory: + root = Path(directory) + air = root / "result.air" + for name in ("known", "single_bytes", "patterns", "streaming", "borrow", "shared"): + source = FIXTURES / f"{name}.aji" + cli("check", source) + canonical = cli("lower", source) + assert cli("lower", source) == canonical + assert "effects []" in canonical and "unsafe" not in canonical + air.write_text(canonical) + cli("check", air) + assert returned(source) == returned(air) + report = json.loads(cli("report", source)) + assert all(function["allocations"] == 0 for function in report["functions"]), report + assert report["entry"]["capabilities"] == [], report + # Proposed map storage can observe Copy metadata without consuming V. + source = FIXTURES / "map_storage.aji" + cli("check", source) + canonical = cli("lower", source) + assert cli("lower", source) == canonical + air.write_text(canonical) + cli("check", air) + assert returned(source, "heap=mem.alloc:26") == returned(air, "heap=mem.alloc:26") + report = json.loads(cli("report", source)) + assert sum(function["allocations"] for function in report["functions"]) == 2, report + canonical = cli("lower", example) + reordered = root / "reordered.aji" + reordered.write_text(example.read_text().replace("import std.hash;\nimport std.bytes;", "import std.bytes;\nimport std.hash;")) + assert cli("lower", reordered) == canonical + # A user's local name does not intercept a qualified std call. + collision = root / "collision.aji" + collision.write_text(example.read_text().replace("fn main()", "fn __aji_std_hash_fnv1a64(data: slice) -> u64 effects [] { return 0; }\nfn main()")) + returned(collision) + assert "@__aji_std_hash_fnv1a64_1" in cli("lower", collision) + (root / "lib.aji").write_text("module app.lib\nimport std.hash;\nfn checksum(data: slice) -> u32 effects [] { return std.hash.crc32c(data); }\n") + (root / "main.aji").write_text('module app.main\nimport app.lib;\nfn main() -> u64 effects [] { assert(app.lib.checksum(b"123456789") == 0xe3069283u32); return 42; }\n') + manifest = root / "aji.toml" + manifest.write_text('[package]\nname = "hash"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.lib = "lib.aji"\n') + cli("check", "--manifest", manifest) + cli("report", "--manifest", manifest) + assert json.loads(cli("run", "--manifest", manifest))["value"] == 42 + cli("explore", "--max-runs", "8", "--manifest", manifest) + result_path = root / "hosted.json" + assert cli("run", "--profile", "hosted", "--result-file", result_path, example) == "" + assert json.loads(result_path.read_text())["value"] == 42 + # No installed compiler needs std files from its working directory. + isolated = subprocess.run([str(AJI), "run", str(example)], cwd=root, capture_output=True, text=True) + assert isolated.returncode == 0 and json.loads(isolated.stdout)["value"] == 42, isolated + checks += 1 + for name, code in (("missing_import", "E7002"), ("wrong_slice", "E7005"), ("wrong_state", "E7005"), ("generic", "E7006"), ("alias", "E2101")): + source = FIXTURES / f"{name}.aji" + for command in ("check", "report", "run", "explore"): + records = [json.loads(line) for line in cli(command, source, code=1).splitlines()] + assert [record["code"] for record in records] == ([code, code] if name == "alias" else [code]), records + assert records[0]["file"].endswith(source.name), records + for seed in (0, 7, 19): + assert json.loads(cli("run", "--seed", seed, example))["value"] == 42 + cli("explore", "--max-runs", "12", FIXTURES / "shared.aji") +print(f"source hash CLI checks passed ({checks})") diff --git a/tests/hosted/source_hashmap.py b/tests/hosted/source_hashmap.py new file mode 100644 index 0000000..caab1c6 --- /dev/null +++ b/tests/hosted/source_hashmap.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +"""General owning maps through explicit policies, source/AIR, packages and profiles.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +CASES = REPO / "tests/conformance/source/hashmap" +checks = 0 + + +def cli(*args, code=0): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +def returned(path, *grants): + args = [item for grant in grants for item in ("--grant", grant)] + record = json.loads(cli("run", "--fuel", "4000000", *args, path)) + assert record["status"] == "returned" and record["value"] == 42, record + return record + + +example = REPO / "examples/std/hashmap.aji" +returned(example, "heap=mem.alloc:66") +cli("check", example) +report = json.loads(cli("report", example)) +assert report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report +canonical = cli("lower", example) +assert canonical == cli("lower", example) +assert "trusted" not in canonical and "unsafe" not in canonical +for name, budget in [("copy", 1024), ("owner", 1024), ("owner_returned", 98), ("byte_keys", 256), + ("key_copy_lookup", 82), ("reserve_failure", 251), ("reserve_peak", 174), + ("no_empty", 116), ("zero", 0), ("rollback", 40), ("model", 1120), ("model_owner", 1120)]: + returned(CASES / (name + ".aji"), f"heap=mem.alloc:{budget}") +for name, expected in [("full_leak", "E3002"), ("key_missing_move", "E7003"), + ("get_owner", "E7005"), ("policy_mismatch", "E7005"), + ("policy_effect", "E7005"), ("free_leak", "E3002")]: + commands = ("check", "report", "run", "explore") if expected == "E3002" else ("check", "lower", "report", "run", "explore") + for command in commands: + records = [json.loads(line) for line in cli(command, CASES / (name + ".aji"), code=1).splitlines()] + assert records and {error["code"] for error in records} == {expected}, records + +with tempfile.TemporaryDirectory(prefix="aji-hashmap-") as directory: + root = Path(directory) + air = root / "lowered.air" + air.write_text(canonical) + cli("check", air) + assert returned(air, "heap=mem.alloc:66") == returned(example, "heap=mem.alloc:66") + # Hosted results use the same pinned library and explicit heap accounting. + result = root / "hosted.json" + stdout = cli("run", "--profile", "hosted", "--fuel", "4000000", "--grant", "heap=mem.alloc:66", "--result-file", result, example) + assert stdout == "" and json.loads(result.read_text())["value"] == 42 + # Package policy selection is explicit and preserves nominal identities. + policy = root / "policy.aji" + policy.write_text('''module app.policy +struct Key { id: u64 } +fn hash(key: ref) -> u64 effects [] { return 3; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +''') + entry, manifest = root / "main.aji", root / "aji.toml" + manifest.write_text('[package]\nname = "hashmap"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.policy = "policy.aji"\n[capabilities]\nheap = "mem.alloc:66"\n') + program = example.read_text().replace("module demo.hashmap", "module app.entry") + start, end = program.index("struct Key"), program.index("fn main(") + program = program[:start].replace("import std.option;", "import std.option;\nimport app.policy;") + program[end:] + program = program.replace(") -> u64 effects [mem.alloc] { + let map = opened::(1,heap); + { mut q = map; inserted::(std.hashmap.insert::(q, Key { id: 1 },42)); + mut storage = q.buckets; mut buckets = buffer.view(storage); buckets[1].index = 7usize; } + { ref q = map; let key = Key { id: 1 }; std.hashmap.contains::(q,ref key); } + { mut q = map; let entry = extracted::>(std.hashmap.pop::(q)); } + released::(move map); return 42; +} +''' + entry.write_text(invalid) + record = json.loads(cli("run", "--fuel", "4000000", "--grant", "heap=mem.alloc:1024", entry, code=4)) + assert record["code"] == "T0008" and record["source_location"]["file"] == "std/hashmap.aji", record + +print(f"general hash-map CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_hashset.py b/tests/hosted/source_hashset.py new file mode 100644 index 0000000..ad15b1e --- /dev/null +++ b/tests/hosted/source_hashset.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""General owning sets: duplicate ownership, source/AIR, packages and profiles.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +CASES = REPO / "tests/conformance/source/hashset" +checks = 0 + + +def cli(*args, code=0): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +def returned(path, *grants): + args = [item for grant in grants for item in ("--grant", grant)] + record = json.loads(cli("run", "--fuel", "2000000", *args, path)) + assert record["status"] == "returned" and record["value"] == 42, record + return record + + +example = REPO / "examples/std/hashset.aji" +returned(example, "heap=mem.alloc:67") +cli("check", example) +report = json.loads(cli("report", example)) +assert report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report +canonical = cli("lower", example) +assert canonical == cli("lower", example) +assert "trusted" not in canonical and "unsafe" not in canonical +for name in ("copy", "owner", "byte_keys", "duplicate_state", "reserve_failure", "reserve_peak", + "reserve_authority", "zero", "rollback", "model", "model_owner", "free_returns", "shared"): + path = CASES / (name + ".aji") + grants = [line.removeprefix("// grant: ") for line in path.read_text().splitlines() if line.startswith("// grant: ")] + returned(path, *grants) +for name, expected in (("present_leak", "E3002"), ("full_leak", "E3002"), ("free_leak", "E3002"), + ("missing_move", "E7003"), ("policy_mismatch", "E7005"), ("not_share", "E4002")): + commands = ("check", "report", "run", "explore") if expected in ("E3002", "E4002") else ("check", "lower", "report", "run", "explore") + for command in commands: + records = [json.loads(line) for line in cli(command, CASES / (name + ".aji"), code=1).splitlines()] + assert records and {error["code"] for error in records} == {expected}, records + +with tempfile.TemporaryDirectory(prefix="aji-hashset-") as directory: + root = Path(directory) + air = root / "lowered.air" + air.write_text(canonical) + cli("check", air) + assert returned(air, "heap=mem.alloc:67") == returned(example, "heap=mem.alloc:67") + result = root / "hosted.json" + stdout = cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", "heap=mem.alloc:67", "--result-file", result, example) + assert stdout == "" and json.loads(result.read_text())["value"] == 42 + policy = root / "policy.aji" + policy.write_text('''module app.policy +struct Key { id: u64, owner: own } +fn hash(key: ref) -> u64 effects [] { return key.id; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +''') + entry, manifest = root / "main.aji", root / "aji.toml" + manifest.write_text('[package]\nname = "hashset"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.policy = "policy.aji"\n[capabilities]\nheap = "mem.alloc:67"\n') + program = example.read_text().replace("module demo.hashset", "module app.entry") + start, end = program.index("struct Key"), program.index("fn main(") + program = program[:start].replace("import std.option;", "import std.option;\nimport app.policy;") + program[end:] + program = program.replace("", "").replace("fn hash", "fn app.policy.hash").replace("fn equal", "fn app.policy.equal").replace("Key {", "app.policy.Key {") + entry.write_text(program) + record = json.loads(cli("run", "--fuel", "2000000", "--manifest", manifest)) + assert record["status"] == "returned" and record["value"] == 42, record + package_air = cli("lower", "--manifest", manifest) + cli("report", "--manifest", manifest) + imports = "import std.hashset;\nimport std.option;\nimport app.policy;" + entry.write_text(program.replace(imports, "import app.policy;\nimport std.option;\nimport std.hashset;")) + assert cli("lower", "--manifest", manifest) == package_air + entry.write_text(program) + policy.write_text(policy.read_text().replace("return key.id;", "assert(false); return key.id;")) + record = json.loads(cli("run", "--fuel", "2000000", "--manifest", manifest, code=4)) + assert Path(record["source_location"]["file"]).name == "policy.aji", record + +print(f"general hash-set CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_heap.py b/tests/hosted/source_heap.py new file mode 100644 index 0000000..9642d75 --- /dev/null +++ b/tests/hosted/source_heap.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +"""Owning binary heap through source/AIR, explicit policies and profiles.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +CASES = REPO / "tests/conformance/source/heap" +checks = 0 + + +def cli(*args, code=0): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +def returned(path, *grants): + args = [item for grant in grants for item in ("--grant", grant)] + record = json.loads(cli("run", "--fuel", "2000000", *args, path)) + assert record["status"] == "returned" and record["value"] == 42, record + return record + + +example = REPO / "examples/std/heap.aji" +returned(example, "heap=mem.alloc:40") +cli("check", example) +report = json.loads(cli("report", example)) +assert report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report +canonical = cli("lower", example) +assert canonical == cli("lower", example) +assert "trusted" not in canonical and "unsafe" not in canonical +for name in ("copy", "owner", "direct_owner", "byte_values", "owner_growth", "owner_failure", "reserve_failure", "reserve_peak", + "reserve_authority", "layout_failure", "zero", "rollback", "model", "model_owner", "permutations", + "free_returns", "shared", "full_no_callback"): + path = CASES / (name + ".aji") + grants = [line.removeprefix("// grant: ") for line in path.read_text().splitlines() if line.startswith("// grant: ")] + returned(path, *grants) +for name, expected in (("full_leak", "E3002"), ("free_leak", "E3002"), ("pop_leak", "E3002"), + ("missing_move", "E7003"), ("peek_owner", "E7005"), ("policy_effect", "E7005"), + ("policy_mismatch", "E7005"), ("not_share", "E4002")): + commands = ("check", "report", "run", "explore") if expected in ("E3002", "E4002") else ("check", "lower", "report", "run", "explore") + for command in commands: + records = [json.loads(line) for line in cli(command, CASES / (name + ".aji"), code=1).splitlines()] + assert records and {error["code"] for error in records} == {expected}, records + +with tempfile.TemporaryDirectory(prefix="aji-heap-") as directory: + root = Path(directory) + air = root / "lowered.air" + air.write_text(canonical) + cli("check", air) + assert returned(air, "heap=mem.alloc:40") == returned(example, "heap=mem.alloc:40") + result = root / "hosted.json" + stdout = cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", "heap=mem.alloc:40", "--result-file", result, example) + assert stdout == "" and json.loads(result.read_text())["value"] == 42 + policy = root / "policy.aji" + policy.write_text('''module app.policy +struct Item { priority: u64, owner: own } +fn before(a: ref, b: ref) -> bool effects [] { return a.priority < b.priority; } +''') + entry, manifest = root / "main.aji", root / "aji.toml" + manifest.write_text('[package]\nname = "heap"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.policy = "policy.aji"\n[capabilities]\nheap = "mem.alloc:40"\n') + program = example.read_text().replace("module demo.heap", "module app.entry") + start, end = program.index("struct Item"), program.index("fn main(") + program = program[:start].replace("import std.option;", "import std.option;\nimport app.policy;") + program[end:] + program = program.replace("", "").replace("fn before", "fn app.policy.before").replace("Item {", "app.policy.Item {") + entry.write_text(program) + record = json.loads(cli("run", "--fuel", "2000000", "--manifest", manifest)) + assert record["status"] == "returned" and record["value"] == 42, record + package_air = cli("lower", "--manifest", manifest) + cli("report", "--manifest", manifest) + imports = "import std.heap;\nimport std.option;\nimport app.policy;" + entry.write_text(program.replace(imports, "import app.policy;\nimport std.option;\nimport std.heap;")) + assert cli("lower", "--manifest", manifest) == package_air + # A second item makes the selected comparator run inside heap sifting. + extra = '''let second = app.policy.Item { priority: 0,owner: own.new(99u64,heap) or trap }; + match std.heap.push::(q,move second) { + std.heap.PushResult::::ok => {}, std.heap.PushResult::::full(item) => { trap; } + } + match std.heap.pop::(q) { + std.option.Option::::some(item) => { let (priority,owner) = struct.unpack(move item); assert(own.take(move owner) == 99u64); }, + std.option.Option::::none => { trap; } + } + ''' + trapped = program.replace("(1,heap)", "(2,heap)").replace(" match std.heap.pop", " " + extra + "match std.heap.pop", 1) + entry.write_text(trapped) + manifest.write_text(manifest.read_text().replace("mem.alloc:40", "mem.alloc:80")) + record = json.loads(cli("run", "--fuel", "2000000", "--manifest", manifest)) + assert record["value"] == 42, record + policy.write_text(policy.read_text().replace("return a.priority", "assert(false); return a.priority")) + record = json.loads(cli("run", "--fuel", "2000000", "--manifest", manifest, code=4)) + assert Path(record["source_location"]["file"]).name == "policy.aji", record + record = json.loads(cli("run", "--fuel", "2000000", "--grant", "heap=mem.alloc:24", CASES / "invalid_indices.aji", code=4)) + assert record["code"] == "T0008" and record["source_location"]["file"] == "std/heap.aji", record + +print(f"binary-heap CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_io.py b/tests/hosted/source_io.py new file mode 100644 index 0000000..b36f73b --- /dev/null +++ b/tests/hosted/source_io.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +"""Bounded I/O composition: CLI/AIR/packages, hosted errors and resources.""" +import base64 +import json +import os +from pathlib import Path +import resource +import signal +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +CASES = REPO / "tests/conformance/source/io" +checks = 0 + + +def cli(*args, code=0, **kwargs): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True, **kwargs) + detail = None + if run.returncode != code and "--result-file" in args: + result = Path(args[args.index("--result-file") + 1]) + if result.exists(): + detail = result.read_text() + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr, detail) + checks += 1 + return run.stdout + + +def returned(path, *grants, extra=()): + args = [item for grant in grants for item in ("--grant", grant)] + record = json.loads(cli("run", "--fuel", "2000000", *args, *extra, path)) + assert record["status"] == "returned", record + return record + + +example = REPO / "examples/std/io.aji" +grants = ("src=fs.read:/in", "dst=fs.write:/out") +record = returned(example, *grants, extra=("--vfs", "/in/data=abcd")) +assert record["value"] == 4 and base64.b64decode(record["files"]["/out/data"]["data"]) == b"abcd", record +cli("check", example) +report = json.loads(cli("report", example)) +assert report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report +canonical = cli("lower", example) +assert canonical == cli("lower", example) +for name in ("file", "copy", "copy_limit", "copy_exact_limit", "append", "zero_scratch", "maximum_limit", "to_end", "model"): + path = CASES / (name + ".aji") + args = [] + for line in path.read_text().splitlines(): + if line.startswith("// grant: "): + args.extend(("--grant", line.removeprefix("// grant: "))) + if line.startswith("// vfs: "): + args.extend(("--vfs", line.removeprefix("// vfs: "))) + assert returned(path, extra=args)["value"] == 42 +assert returned(CASES / "stdin.aji", "input=io.read", extra=("--stdin", "abcd"))["value"] == 42 +for name, expected in (("missing_effect", "E3101"), ("wrong_kind", "E7005"), ("wrong_mode", "E7005"), + ("copy_mode", "E7005"), ("alias", "E2101"), ("close_borrowed", "E2101"), ("loan", "E4101")): + commands = ("check", "lower", "report", "run", "explore") if expected == "E7005" else ("check", "report", "run", "explore") + for command in commands: + errors = [json.loads(line) for line in cli(command, CASES / (name + ".aji"), code=1).splitlines()] + assert errors and {error["code"] for error in errors} == {expected}, errors + assert all(Path(error["file"]).resolve() == (CASES / (name + ".aji")).resolve() for error in errors), errors + +tags = ("not_found", "permission_denied", "already_exists", "invalid_input", "no_space", "broken_pipe", + "connection_refused", "connection_reset", "address_in_use", "address_unavailable", "timed_out", "other") +kind = "fn kind(error: io_error) -> u64 effects [] { match error { " + ",".join(f"io_error::{tag} => {{ return {i}; }}" for i, tag in enumerate(tags)) + " } }\n" +with tempfile.TemporaryDirectory(prefix="aji-io-") as directory: + root = Path(directory) + air = root / "lowered.air" + air.write_text(canonical) + cli("check", air) + assert returned(air, *grants, extra=("--vfs", "/in/data=abcd")) == record + entry = root / "main.aji" + manifest = root / "aji.toml" + entry.write_text(example.read_text()) + manifest.write_text('[package]\nname = "io"\nversion = "1"\nentry = "main.aji"\n[capabilities]\nsrc = "fs.read:/in"\ndst = "fs.write:/out"\n') + package = json.loads(cli("run", "--fuel", "2000000", "--vfs", "/in/data=abcd", "--manifest", manifest)) + assert package == record, package + assert cli("lower", "--manifest", manifest) == canonical + imports = example.read_text().replace("import std.io;", "import std.io;\nimport std.bytes;") + entry.write_text(imports) + ordered = cli("lower", "--manifest", manifest) + entry.write_text(imports.replace("import std.io;\nimport std.bytes;", "import std.bytes;\nimport std.io;")) + assert cli("lower", "--manifest", manifest) == ordered + source, target, result = root / "input", root / "output", root / "result.json" + source.write_text("abcdef") + hosted = example.read_text().replace('b"/in/data"', f'b"{source}"').replace('b"/out/data"', f'b"{target}"') + entry.write_text(hosted) + stdout = cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", f"src=fs.read:{root}", "--grant", f"dst=fs.write:{root}", "--result-file", result, entry) + assert stdout == "" and json.loads(result.read_text())["value"] == 6 and target.read_text() == "abcdef" + # A directory used as stdin gives a real hosted read error, with zero progress. + entry.write_text('''module app.read_error +import std.io; +''' + kind + '''fn main(input: cap) -> u64 effects [io.read] { + var bytes: [u8;4] = [99u8;4]; + match std.io.read_exact_stdin(input,mut bytes[1usize..3usize]) { + std.io.ReadExactResult::err(error) => { assert(error.completed == 0usize); assert(kind(error.error) == 3u64); }, + std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::eof(count) => { trap; } + } + assert(bytes[0] == 99u8); assert(bytes[3] == 99u8); return 42; +} +''') + descriptor = os.open(root, os.O_RDONLY) + try: + cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", "input=io.read", "--result-file", result, entry, stdin=descriptor) + assert json.loads(result.read_text())["value"] == 42 + finally: + os.close(descriptor) + # Child-only file-size quota forces a partial second write: no wall timeout. + # The program's stdout is a pipe; no result file is written under this quota. + entry.write_text('''module app.partial_write +import std.io; +''' + kind + f'''fn main(src: cap,dst: cap,print: cap) -> u64 effects [fs.read,fs.write,io.write] {{ + let input = fs.open_read(src,b"{source}") or trap; let output = fs.create(dst,b"{target}") or trap; var scratch: [u8;2] = [0u8;2]; + match std.io.copy_file(mut input,mut output,mut scratch,8usize) {{ + std.io.CopyResult::err(error) => {{ assert(error.read == 4usize); assert(error.confirmed_written == 2usize); assert(kind(error.error) == 11u64); }}, + std.io.CopyResult::eof(count) => {{ trap; }}, std.io.CopyResult::limit(count) => {{ trap; }} + }} + match std.io.read_exact_file(mut input,mut scratch) {{ std.io.ReadExactResult::ok => {{}}, std.io.ReadExactResult::eof(count) => {{ trap; }}, std.io.ReadExactResult::err(error) => {{ trap; }} }} + assert(scratch[0] == 101u8); assert(scratch[1] == 102u8); fs.close(move input) or trap; fs.close(move output) or trap; + io.stdout_write(print,b"42") or trap; return 42; +}} +''') + + def partial_write_limit(): + signal.signal(signal.SIGXFSZ, signal.SIG_IGN) + resource.setrlimit(resource.RLIMIT_FSIZE, (3, 3)) + + stdout = cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", f"src=fs.read:{root}", "--grant", f"dst=fs.write:{root}", "--grant", "print=io.write", entry, preexec_fn=partial_write_limit) + assert stdout == "42" and target.read_bytes() == b"abc" + +print(f"bounded I/O CLI integration passed ({checks} checks, hosted read error and partial external write)") diff --git a/tests/hosted/source_linear.py b/tests/hosted/source_linear.py new file mode 100644 index 0000000..909381b --- /dev/null +++ b/tests/hosted/source_linear.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +"""Whole-value ownership through source, canonical AIR, and CLI entry points.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +checks = 0 + + +def cli(*args, code=0): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +def returned(path, *args): + record = json.loads(cli("run", "--fuel", "1000000", *args, path)) + assert record["status"] == "returned" and record["value"] == 42, record + + +features = json.loads(cli("features")) +assert "linear_aggregates" in features["features"] +source = REPO / "examples/std/owning-option.aji" +returned(source, "--grant", "heap=mem.alloc:64") +cli("check", source) +canonical = cli("lower", source) +assert cli("lower", source) == canonical +assert "enum.take" in canonical and "value.swap" in canonical +with tempfile.TemporaryDirectory(prefix="aji-linear-") as directory: + root = Path(directory) + air = root / "result.air" + air.write_text(canonical) + cli("check", air) + returned(air, "--grant", "heap=mem.alloc:64") + for fixture, grant in (("pack", 64), ("pack_failure", 8), ("swap_loop", 8), ("heap_array_borrow", 64)): + path = REPO / f"tests/conformance/source/linear/{fixture}.aji" + lowered = cli("lower", path) + assert cli("lower", path) == lowered + air.write_text(lowered) + cli("check", air) + returned(air, "--grant", f"heap=mem.alloc:{grant}") + # Resource-bearing nominal types imported across a package boundary. + (root / "lib.aji").write_text("module app.lib\nstruct Box { value: T }\nfn extract(box: Box) -> T effects [] { let (value) = struct.unpack(move box); return move value; }\n") + (root / "main.aji").write_text("module app.main\nimport app.lib;\nfn main(heap: cap) -> u64 effects [mem.alloc] { let owner = own.new(42u64, heap) or trap; let box = app.lib.Box::> { value: move owner }; let value = app.lib.extract::>(move box); return own.take(move value); }\n") + manifest = root / "aji.toml" + manifest.write_text('[package]\nname = "fixture"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.lib = "lib.aji"\n') + assert json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest, "--grant", "heap=mem.alloc:64"))["value"] == 42 + cli("check", "--manifest", manifest) + cli("report", "--manifest", manifest) + cli("lower", "--manifest", manifest) + cli("explore", "--max-runs", "8", "--manifest", manifest, "--grant", "heap=mem.alloc:64") + +for fixture, expected in (("missing_move", "E7003"), ("ignored_field", "E3002"), ("borrow_conflict", "E2101"), ("recursive_ownership", "E1003")): + path = REPO / f"tests/conformance/source/linear/{fixture}.aji" + commands = ("check", "lower", "report", "run", "explore") if fixture in ("missing_move", "recursive_ownership") else ("check", "report", "run", "explore") + for command in commands: + diagnostics = [json.loads(line) for line in cli(command, path, code=1).splitlines()] + assert diagnostics[0]["code"] == expected, diagnostics + +pack = REPO / "tests/conformance/source/linear/pack.aji" +report = json.loads(cli("report", pack)) +assert sum(function["allocations"] for function in report["functions"]) == 2, report +for fixture in ("task", "channel"): + path = REPO / f"tests/conformance/source/linear/{fixture}.aji" + cli("explore", "--max-runs", "8", "--grant", "heap=mem.alloc:64", path) +print(f"source linear CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_map.py b/tests/hosted/source_map.py new file mode 100644 index 0000000..8109846 --- /dev/null +++ b/tests/hosted/source_map.py @@ -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") diff --git a/tests/hosted/source_modules.py b/tests/hosted/source_modules.py new file mode 100644 index 0000000..ec5741a --- /dev/null +++ b/tests/hosted/source_modules.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 +"""Explicit package inputs through the CLI; runs use fuel, never timeouts.""" +import json +import os +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +checks = 0 + + +def cli(*args, code=0, cwd=None): + global checks + result = subprocess.run([str(AJI), *map(str, args)], cwd=cwd, capture_output=True, text=True) + assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr) + checks += 1 + return result + + +def write_manifest(root, mapping='app.model = "src/model.aji"', grants=""): + path = root / "aji.toml" + path.write_text('[package]\nname = "fixture"\nversion = "1"\nentry = "src/main.aji"\n[modules]\n' + mapping + '\n' + grants) + return path + + +with tempfile.TemporaryDirectory(prefix="aji-source-modules-") as directory: + root = Path(directory) + (root / "src").mkdir() + main = root / "src/main.aji" + model = root / "src/model.aji" + main.write_text((REPO / "examples/modules/main.aji").read_text()) + model.write_text((REPO / "examples/modules/model.aji").read_text()) + manifest = write_manifest(root) + cli("check", "--manifest", manifest) + record = cli("run", "--fuel", "1000000", "--manifest", manifest) + assert json.loads(record.stdout) == {"status": "returned", "value": 42} + canonical = cli("lower", "--manifest", manifest).stdout + assert cli("lower", "--manifest", manifest, cwd="/").stdout == canonical + annotation = cli("lower", "--annotate", "--manifest", manifest).stdout + assert "; src/model.aji:" in annotation + cli("lower", "--stats", "--manifest", manifest) + cli("report", "--manifest", manifest) + cli("check", "--report", "unsafe", "--manifest", manifest) + cli("explore", "--max-runs", "8", "--manifest", manifest) + # No ambient lookup, even with an aji.toml next to the entry. + diagnostic = json.loads(cli("check", main, code=1).stdout) + assert diagnostic["code"] == "E7002" + cli("run", "--manifest", manifest, main, code=2) + cli("lower", "--manifest", manifest, main, code=2) + cli("check", "--manifest", manifest, main, code=2) + # Mapping/import order cannot change canonical output. + other = root / "src/other.aji" + other.write_text("module app.other\nstruct Pair { value: u64 }\n") + original = main.read_text() + main.write_text(original.replace("import app.model;", "import app.model;\nimport app.other;")) + write_manifest(root, 'app.other = "src/other.aji"\napp.model = "src/model.aji"') + ordered = cli("lower", "--manifest", manifest).stdout + write_manifest(root, 'app.model = "src/model.aji"\napp.other = "src/other.aji"') + main.write_text(main.read_text().replace("import app.model;\nimport app.other;", "import app.other;\nimport app.model;")) + assert cli("lower", "--manifest", manifest).stdout == ordered + main.write_text(original) + write_manifest(root) + # Errors and traps name the actual imported source. + saved_model = model.read_text() + model.write_text("module app.model\nfn broken(\n") + diagnostic = json.loads(cli("check", "--manifest", manifest, code=1).stdout) + assert diagnostic["code"] == "E7001" and diagnostic["file"] == "src/model.aji" + assert "expected" in diagnostic and "found" in diagnostic + model.write_text("module app.model\nfn total(value: u64) -> u64 effects [] { assert(false); return value; }\n") + main.write_text("module app.entry\nimport app.model;\nfn main() -> u64 effects [] { return app.model.total(42); }\n") + trapped = json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest, code=4).stdout) + assert trapped["source_location"]["file"] == "src/model.aji" + main.write_text(original) + model.write_text(saved_model) + # Imported authority is explicit; checking never instantiates grants. + model.write_text('module app.model\nfn emit(out: cap) -> void effects [io.write] { io.stdout_write(out, b"module") or trap; }\n') + main.write_text("module app.entry\nimport app.model;\nfn main(out: cap) -> u64 effects [io.write] { app.model.emit(out); return 42; }\n") + cli("check", "--manifest", manifest) + missing = cli("run", "--fuel", "1000000", "--manifest", manifest, code=6) + assert json.loads(missing.stdout)["status"] == "not_instantiated" + write_manifest(root, grants='[capabilities]\nout = "io.write"\n') + granted = json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest).stdout) + assert granted["stdout"] == "module" + overridden = cli("run", "--fuel", "1000000", "--manifest", manifest, "--grant", "out=io.read", code=6) + assert json.loads(overridden.stdout)["status"] == "not_instantiated" + cli("explore", "--max-runs", "8", "--manifest", manifest) + result_file = root / "result.json" + hosted = cli("run", "--profile", "hosted", "--fuel", "1000000", "--result-file", result_file, "--manifest", manifest) + assert hosted.stdout == "module" and json.loads(result_file.read_text())["value"] == 42 + main.write_text(original) + model.write_text(saved_model) + write_manifest(root) + # Invalid paths/reserved names reject as manifest errors, without source execution. + for mapping in ('app.model = "../outside.aji"', 'app.model = "/outside.aji"', + 'app.model = "src/./model.aji"', 'std.bytes = "src/model.aji"', + 'app.model = "src/model.aji"\napp.model = "src/other.aji"'): + write_manifest(root, mapping) + assert cli("check", "--manifest", manifest, code=2).stdout == "" + write_manifest(root, 'app.model = "src/missing.aji"') + cli("check", "--manifest", manifest, code=2) + # Reject source symlinks and directory symlinks, including entry links. + outside = root / "outside.aji" + outside.write_text(saved_model) + link = root / "src/link.aji" + link.symlink_to(outside) + write_manifest(root, 'app.model = "src/link.aji"') + cli("check", "--manifest", manifest, code=2) + alias = root / "alias" + alias.symlink_to(root / "src", target_is_directory=True) + write_manifest(root, 'app.model = "alias/model.aji"') + cli("check", "--manifest", manifest, code=2) + entry_link = root / "src/entry-link.aji" + entry_link.symlink_to(main) + write_manifest(root) + manifest.write_text(manifest.read_text().replace('entry = "src/main.aji"', 'entry = "src/entry-link.aji"')) + cli("check", "--manifest", manifest, code=2) + # Static pipes/directories are rejected without a blocking read. + pipe = root / "src/pipe.aji" + os.mkfifo(pipe) + write_manifest(root, 'app.model = "src/pipe.aji"') + cli("check", "--manifest", manifest, code=2) + (root / "src/directory.aji").mkdir() + write_manifest(root, 'app.model = "src/directory.aji"') + cli("check", "--manifest", manifest, code=2) + large = root / "src/large.aji" + with large.open("wb") as stream: + stream.truncate((64 << 20) + 1) + write_manifest(root, 'app.model = "src/large.aji"') + cli("check", "--manifest", manifest, code=2) + # Aggregate budget is enforced before parsing even if each input fits alone. + with main.open("wb") as stream: + stream.truncate(63 << 20) + with large.open("wb") as stream: + stream.truncate(2 << 20) + cli("check", "--manifest", manifest, code=2) + +print(f"source module CLI integration passed ({checks} checks)") diff --git a/tests/hosted/source_path.py b/tests/hosted/source_path.py new file mode 100644 index 0000000..b3f6262 --- /dev/null +++ b/tests/hosted/source_path.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Pure lexical paths: byte oracles, CLI/AIR/package parity and authority.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +CASES = REPO / "tests/conformance/source/path" +checks = 0 + + +def cli(*args, code=0, **kwargs): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True, **kwargs) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +def returned(path, *extra): + record = json.loads(cli("run", "--fuel", "2000000", *extra, path)) + assert record["status"] == "returned" and record["value"] == 42, record + return record + + +example = REPO / "examples/std/path.aji" +record = returned(example) +canonical = cli("lower", example) +assert cli("lower", example) == canonical +report = json.loads(cli("report", example)) +assert report["entry"]["capabilities"] == [] and report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report +assert all(function["allocations"] == 0 for function in report["functions"]), report +for name in ("basic", "all_bytes", "canceled_capacity", "disjoint", "malformed_unchanged", "model", "shared", "loan_join"): + returned(CASES / (name + ".aji")) +for name, expected in (("alias", ["E2101", "E2101"]), ("join_alias", ["E2101", "E2101"]), + ("overlap", ["E2101", "E2101"]), ("loan", ["E4101"]), ("wrong_slice", ["E7005"]), + ("wrong_input", ["E7005"]), ("wrong_range", ["E7005"]), ("missing_import", ["E7002"])): + commands = ("check", "lower", "report", "run", "explore") if expected[0] in ("E7002", "E7005") else ("check", "report", "run", "explore") + for command in commands: + path = CASES / (name + ".aji") + errors = [json.loads(line) for line in cli(command, path, code=1).splitlines()] + assert [error["code"] for error in errors] == expected, errors + assert all(Path(error["file"]).resolve() == path.resolve() for error in errors), errors +returned(CASES / "authority.aji", "--grant", "src=fs.read:/allowed", "--vfs", "/denied/file=secret") +trap = json.loads(cli("run", CASES / "range_bounds.aji", code=4)) +assert trap["code"] == "T0008" and trap["source_location"]["file"].endswith("range_bounds.aji"), trap +with tempfile.TemporaryDirectory(prefix="aji-path-") as directory: + root = Path(directory) + air = root / "result.air" + air.write_text(canonical) + cli("check", air) + assert returned(air) == record + entry, manifest, result = root / "main.aji", root / "aji.toml", root / "hosted.json" + entry.write_text(example.read_text()) + manifest.write_text('[package]\nname = "path"\nversion = "1"\nentry = "main.aji"\n') + assert json.loads(cli("run", "--manifest", manifest)) == record + assert cli("lower", "--manifest", manifest) == canonical + entry.write_text(example.read_text().replace('import std.path;\nimport std.bytes;', 'import std.bytes;\nimport std.path;')) + assert cli("lower", "--manifest", manifest) == canonical + entry.write_text(example.read_text().replace('fn main()', 'fn __aji_std_path_join() -> u64 effects [] { return 0; }\nfn main()')) + returned(entry) + assert "@__aji_std_path_join_1" in cli("lower", entry) + # Pinned std sources do not depend on the process working directory. + assert json.loads(cli("run", example, cwd=root)) == record + cli("run", "--profile", "hosted", "--result-file", result, example) + assert json.loads(result.read_text()) == {"status": "returned", "value": 42} + # Lexical output is still checked against the entry grant by hosted fs. + # The denied file really exists, but no open/read is authorized. + denied, allowed = root / "denied", root / "allowed" + denied.mkdir(); allowed.mkdir(); (denied / "file").write_text("secret") + source = (CASES / "authority.aji").read_text().replace('b"/allowed"', f'b"{allowed}"').replace('b"/denied/file"', f'b"{denied}/file"').replace('[u8;16]', '[u8;128]').replace('[255u8;16]', '[255u8;128]') + entry.write_text(source) + cli("run", "--profile", "hosted", "--grant", f"src=fs.read:{allowed}", "--result-file", result, entry) + assert json.loads(result.read_text())["value"] == 42 + # Pure path transforms agree across profiles, including all non-NUL bytes. + for name in ("all_bytes", "canceled_capacity", "disjoint", "malformed_unchanged"): + cli("run", "--profile", "hosted", "--fuel", "2000000", "--result-file", result, CASES / (name + ".aji")) + assert json.loads(result.read_text())["value"] == 42 +for seed in (0, 7, 19): + assert returned(example, "--seed", str(seed)) == record +cli("explore", "--max-runs", "12", CASES / "shared.aji") +print(f"source path integration passed ({checks} checks; pure profiles, byte ranges and independent authority)") diff --git a/tests/hosted/source_static_functions.py b/tests/hosted/source_static_functions.py new file mode 100644 index 0000000..5fb4dd7 --- /dev/null +++ b/tests/hosted/source_static_functions.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +"""Static operations through source, AIR, packages and hosted execution; fuel bounds runs.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / "zig-out/bin/aji" +checks = 0 + + +def cli(*args, code=0): + global checks + run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr) + checks += 1 + return run.stdout + + +example = REPO / "examples/std/static_functions.aji" +cli("check", example) +assert json.loads(cli("run", "--fuel", "1000000", example))["value"] == 42 +cli("report", example) +cli("explore", "--max-runs", "8", example) +canonical = cli("lower", example) +assert canonical == cli("lower", example) +assert "call @identity" in canonical and "fn_ref" not in canonical + +with tempfile.TemporaryDirectory(prefix="aji-static-functions-") as directory: + root = Path(directory) + air = root / "result.air" + air.write_text(canonical) + cli("check", air) + assert json.loads(cli("run", "--fuel", "1000000", air))["value"] == 42 + result = root / "hosted.json" + assert cli("run", "--profile", "hosted", "--fuel", "1000000", "--result-file", result, example) == "" + assert json.loads(result.read_text())["value"] == 42 + entry, algo, policy, manifest = (root / name for name in ("main.aji", "algorithm.aji", "policy.aji", "aji.toml")) + manifest.write_text('[package]\nname = "static"\nversion = "1"\nentry = "main.aji"\n[modules]\napp.algorithm = "algorithm.aji"\napp.policy = "policy.aji"\n') + algo.write_text('''module app.algorithm +struct Policy T effects []> { value: T } +fn apply T effects []>(value: T) -> T effects [] { return F(move value); } +fn read T effects []>(value: Policy) -> T effects [] { + let (item) = struct.unpack(move value); return apply::(move item); +} +''') + policy_text = '''module app.policy +fn identity(value: T) -> T effects [] { return value; } +fn other(value: T) -> T effects [] { return value; } +''' + policy.write_text(policy_text) + imports = "import app.algorithm;\nimport app.policy;\n" + body = '''fn main() -> u64 effects [] { + let value = app.algorithm.Policy::> { value: 42 }; + return app.algorithm.read::>(value); +} +''' + entry.write_text("module app.entry\n" + imports + body) + assert json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest))["value"] == 42 + cli("report", "--manifest", manifest) + cli("explore", "--max-runs", "8", "--manifest", manifest) + package_air = cli("lower", "--manifest", manifest) + entry.write_text("module app.entry\nimport app.policy;\nimport app.algorithm;\n" + body) + assert cli("lower", "--manifest", manifest) == package_air + # Equal layouts and signatures do not erase operation identity. + entry.write_text("module app.entry\n" + imports + body.replace("read::(value: T) -> bool effects [] { return true; }\n") + for command in ("check", "lower", "report", "run", "explore"): + error = json.loads(cli(command, "--manifest", manifest, code=1)) + assert error["code"] == "E7005" and Path(error["file"]).name == "main.aji", error + assert error["parameter"] == "F" and error["expected"] == "fn(u64) -> u64 effects []" + assert error["found"] == "fn(u64) -> bool effects []" + # Recursive function-argument resolution is bounded before body expansion. + params = "T, F: fn(T) -> T effects []" + declaration = f"fn apply<{params}>(value: T) -> T effects [] {{ return F(move value); }}\n" + entry.write_text("module app.entry\nfn identity(value: u64) -> u64 effects [] { return value; }\n" + declaration + + "fn main() -> u64 effects [] { return apply::(42u64); }\n") + assert json.loads(cli("run", "--fuel", "1000000", entry))["value"] == 42 + argument = "fn identity" + for _ in range(70): + argument = f"fn apply::" + entry.write_text("module app.entry\nfn identity(value: u64) -> u64 effects [] { return value; }\n" + declaration + + f"fn main() -> u64 effects [] {{ return apply::(42u64); }}\n") + error = json.loads(cli("check", entry, code=1)) + assert error["code"] == "E7006", error + +print(f"static function CLI integration passed ({checks} checks)") diff --git a/tools/buffered_io_vectors.py b/tools/buffered_io_vectors.py new file mode 100644 index 0000000..db60dd8 --- /dev/null +++ b/tools/buffered_io_vectors.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +"""Independent byte oracle for bounded adapters; --write regenerates fixture.""" +from pathlib import Path +import sys + +ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/buffered_io" +HELPERS = '''import std.io; +import std.io.reader; +import std.io.writer; +import std.bytes; +fn prepare(contents: slice,dst: cap) -> void effects [fs.write] { + let file = fs.create(dst,b"/case/input") or trap; fs.write_all(file,contents) or trap; fs.close(move file) or trap; +} +fn reads(contents: slice,capacity: usize,chunk: usize,src: cap,dst: cap,heap: cap) -> void effects [fs.read,fs.write,mem.alloc] { + prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap; + match std.io.reader.new(move file,capacity,heap) { + std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => { + var bytes: [u8;9] = [255u8;9]; var offset: usize = 0; + { mut q = value; loop { + match std.io.reader.read(q,mut bytes[1usize..chunk+1usize]) { + std.io.reader.ReadResult::err(error) => { trap; }, std.io.reader.ReadResult::ok(count) => { + assert(count <= chunk); assert(offset + count <= contents.len); + assert(std.bytes.equal(ref bytes[1usize..count+1usize],ref contents[offset..offset+count])); + assert(bytes[0] == 255u8); for i in chunk+1usize..9usize { assert(bytes[i] == 255u8); } + offset = offset + count; if count == 0usize { break; } + } + } + } } + assert(offset == contents.len); + match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.reader.FinishResult::unread(value) => { trap; } } + } + } +} +fn exact(contents: slice,capacity: usize,requested: usize,prefix: usize,full: bool,src: cap,dst: cap,heap: cap) -> void effects [fs.read,fs.write,mem.alloc] { + prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap; + match std.io.reader.new(move file,capacity,heap) { + std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => { + var bytes: [u8;12] = [255u8;12]; + { mut q = value; match std.io.reader.read_exact(q,mut bytes[1usize..requested+1usize]) { + std.io.ReadExactResult::ok => { assert(full); }, std.io.ReadExactResult::eof(n) => { assert(not full); assert(n == prefix); }, std.io.ReadExactResult::err(error) => { trap; } + } } + assert(std.bytes.equal(ref bytes[1usize..prefix+1usize],ref contents[0usize..prefix])); + assert(bytes[0] == 255u8); for i in prefix+1usize..12usize { assert(bytes[i] == 255u8); } + let (file,unread) = struct.unpack(std.io.reader.discard(move value)); fs.close(move file) or trap; + } + } +} +fn writes(contents: slice,capacity: usize,chunk: usize,flush: bool,src: cap,dst: cap,heap: cap) -> void effects [fs.read,fs.write,mem.alloc] { + let file = fs.create(dst,b"/case/output") or trap; + match std.io.writer.new(move file,capacity,heap) { + std.io.writer.NewResult::err(error) => { trap; }, std.io.writer.NewResult::ok(value) => { + var offset: usize = 0; + { mut q = value; match std.io.writer.write(q,ref contents[0usize..0usize]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } + while offset < contents.len { + let left = contents.len - offset; let count = if left < chunk { left } else { chunk }; + match std.io.writer.write(q,ref contents[offset..offset+count]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } + offset = offset + count; + if flush { match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } } + } + } + match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.writer.FinishResult::err(error) => { trap; } } + } + } + let file = fs.open_read(src,b"/case/output") or trap; var bytes: [u8;12] = [255u8;12]; + match std.io.read_to_end_file(mut file,mut bytes[1usize..11usize]) { std.io.ReadToEndResult::eof(n) => { assert(n == contents.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],contents)); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + assert(bytes[0] == 255u8); assert(bytes[11] == 255u8); fs.close(move file) or trap; +} +''' + + +def literal(text): + return 'b"' + text + '"' if text else "ref blank[0usize..0usize]" + + +calls = [] +for length in (0, 1, 3, 8): + text = "abcdefgh"[:length] + for capacity in (0, 1, 2, 5): + for chunk in (1, 3, 7): + calls.append(f"reads({literal(text)},{capacity}usize,{chunk}usize,src,dst,heap);") + for flush in (False, True): + calls.append(f"writes({literal(text)},{capacity}usize,{chunk}usize,{str(flush).lower()},src,dst,heap);") + for requested in (0, 1, 4, 9): + calls.append(f"exact({literal(text)},{capacity}usize,{requested}usize,{min(length,requested)}usize,{str(requested <= length).lower()},src,dst,heap);") +expected = '''// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.18 +// grant: src=fs.read:/case +// grant: dst=fs.write:/case +// grant: heap=mem.alloc:5 +// file: /case/input=abcdefgh +// file: /case/output=abcdefgh +// fuel: 2000000 +module test.buffered_model +''' + HELPERS + "fn main(src: cap,dst: cap,heap: cap) -> u64 effects [fs.read,fs.write,mem.alloc] {\nlet blank: [u8;1] = [0u8;1];\n" + "\n".join(calls) + "\nreturn 42;\n}\n" +path = ROOT / "model.aji" +if "--write" in sys.argv: + path.write_text(expected) +assert path.read_text() == expected, "Buffered I/O fixture differs from independent byte oracle" +print("buffered I/O oracle passed (48 read streams, 64 exact prefixes, 96 segmented writes; bytes, guards, EOF and zero capacity)") diff --git a/tools/conformance.zig b/tools/conformance.zig index 1eb9951..246c7a1 100644 --- a/tools/conformance.zig +++ b/tools/conformance.zig @@ -39,6 +39,8 @@ const Outcome = enum { pass, fail, pending }; /// runs always use a limit). const default_fuel: u64 = 1_000_000; +const ModuleBinding = struct { name: []const u8, path: []const u8 }; + const Header = struct { expect: Expect, fuel: u64, @@ -57,6 +59,7 @@ const Header = struct { /// `.aji` only: a reference AIR program (relative to the conformance /// root) whose observable run must equal this one's. equivalent: ?[]const u8 = null, + modules: []const ModuleBinding = &.{}, }; pub fn main(init: std.process.Init) !void { @@ -151,10 +154,15 @@ const stress_quanta = [_]u64{ 1, 2, 7 }; fn runSource(arena: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, rel: []const u8, path: []const u8, source: []const u8) !Result { const header = parseHeader(arena, source) catch |err| return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "bad header: {t}", .{err}) }; - const report = try aji.check.checkFile(arena, path, source); + var modules: std.ArrayList(aji.frontend.modules.Source) = .empty; + for (header.modules) |binding| { + const text = dir.readFileAlloc(io, binding.path, arena, .limited(64 << 20)) catch |err| return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "module {s}: {t}", .{ binding.path, err }) }; + try modules.append(arena, .{ .name = binding.name, .file = binding.path, .source = text }); + } + const report = try aji.check.checkWithModules(arena, path, source, modules.items); if (report.status == .unimplemented) return .{ .outcome = .pending, .detail = report.missing_stage }; if (report.lowered) |lowered| { - const again = try aji.frontend.compile(arena, path, source); + const again = try aji.frontend.compileWithModules(arena, path, source, modules.items); if (again != .ok or !std.mem.eql(u8, again.ok.air, lowered.air)) return .{ .outcome = .fail, .detail = "lowering is not deterministic" }; const parsed = try aji.air.parse.parse(arena, path, lowered.air); if (parsed.module) |m| { @@ -452,7 +460,7 @@ fn formatExpect(e: Expect, w: *std.Io.Writer) std.Io.Writer.Error!void { } } -const HeaderError = error{ BadGrant, MissingExpect, MissingPhase, MissingSpec, MissingRunResult, UnknownKey, UnknownCode, BadExpect, OutOfMemory, InvalidCharacter, Overflow }; +const HeaderError = error{ BadModule, BadGrant, MissingExpect, MissingPhase, MissingSpec, MissingRunResult, UnknownKey, UnknownCode, BadExpect, OutOfMemory, InvalidCharacter, Overflow }; fn parseHeader(arena: std.mem.Allocator, source: []const u8) HeaderError!Header { var expect: ?Expect = null; @@ -470,6 +478,7 @@ fn parseHeader(arena: std.mem.Allocator, source: []const u8) HeaderError!Header var want_stderr: ?[]const u8 = null; var spec: ?[]const u8 = null; var equivalent: ?[]const u8 = null; + var modules: std.ArrayList(ModuleBinding) = .empty; var lines = std.mem.splitScalar(u8, source, '\n'); while (lines.next()) |line| { @@ -549,6 +558,10 @@ fn parseHeader(arena: std.mem.Allocator, source: []const u8) HeaderError!Header phase = try std.fmt.parseInt(u8, value, 10); } else if (std.mem.eql(u8, key, "spec")) { spec = value; + } else if (std.mem.eql(u8, key, "module")) { + const eq = std.mem.indexOfScalar(u8, value, '=') orelse return error.BadModule; + if (eq == 0 or eq + 1 == value.len) return error.BadModule; + try modules.append(arena, .{ .name = value[0..eq], .path = value[eq + 1 ..] }); } else if (std.mem.eql(u8, key, "equivalent")) { equivalent = value; } else return error.UnknownKey; @@ -574,6 +587,7 @@ fn parseHeader(arena: std.mem.Allocator, source: []const u8) HeaderError!Header .phase = phase orelse return error.MissingPhase, .spec = spec orelse return error.MissingSpec, .equivalent = equivalent, + .modules = modules.items, }; } diff --git a/tools/deque_vectors.py b/tools/deque_vectors.py new file mode 100644 index 0000000..2a7de95 --- /dev/null +++ b/tools/deque_vectors.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +"""Check the public Deque fixture's byte vectors against Python's deque oracle.""" +from collections import deque +from pathlib import Path +import re + +FIXTURE = Path(__file__).resolve().parents[1] / "tests/conformance/source/deque/model.aji" +SEEDS = (3, 19, 42, 91) + + +def vectors(operations, values, indices): + queue = deque() + capacity = 3 + result = [list(operations), list(values), list(indices), [], [], [], []] + for operation, value, index in zip(operations, values, indices): + assert operation < 6 and value in range(1, 64) and index < 9 + failed = 0 + returned = 0 + if operation in (0, 1): + if len(queue) == capacity: + failed = 1 + elif operation == 0: + queue.append(value) + else: + queue.appendleft(value) + elif operation in (2, 3): + if not queue: + failed = 1 + elif operation == 2: + returned = queue.popleft() + else: + returned = queue.pop() + elif operation == 4: + capacity = max(capacity, index) + else: + if index >= len(queue): + failed = 1 + else: + returned = queue[index] + queue[index] = value + result[3].append(failed) + result[4].append(returned) + result[5].append(len(queue)) + result[6].extend(list(queue) + [0] * (8 - len(queue))) + return [bytes(values) for values in result] + + +def main(): + calls = re.findall(r' trace\(heap, (.*?)\);', FIXTURE.read_text()) + assert len(calls) == len(SEEDS), len(calls) + for seed, call in zip(SEEDS, calls): + strings = re.findall(r'ref b"((?:\\x[0-9a-f]{2})*)"', call) + actual = [bytes.fromhex(value.replace("\\x", "")) for value in strings] + assert len(actual) == 7 and all(len(row) == 32 for row in actual[:6]), seed + assert actual == vectors(*actual[:3]), f"fixture disagrees with Python deque for seed {seed}" + print(f"deque oracle vectors passed ({len(SEEDS)} seeds, {len(SEEDS) * 32} operations)") + + +if __name__ == "__main__": + main() diff --git a/tools/eval/languages/aji_source.json b/tools/eval/languages/aji_source.json index 6717f2b..4e8ac5a 100644 --- a/tools/eval/languages/aji_source.json +++ b/tools/eval/languages/aji_source.json @@ -18,7 +18,7 @@ }, "doc_groups": { "quick_reference": ["QUICK.md"], - "source_docs": ["language/", "diagnostics/"], + "source_docs": ["language/", "diagnostics/", "library/"], "air_docs": ["air/"] }, "source_extensions": [ diff --git a/tools/hash_vectors.py b/tools/hash_vectors.py new file mode 100644 index 0000000..ca11d66 --- /dev/null +++ b/tools/hash_vectors.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""Check recorded FNV/CRC vectors with arbitrary precision and a forward CRC.""" +from pathlib import Path +import re + +FIXTURES = Path(__file__).resolve().parents[1] / "tests/conformance/source/hash" + + +def reflect(value, width): + return int(f"{value:0{width}b}"[::-1], 2) + + +def crc32c(data, previous=0): + # Forward polynomial and left shifts: independent of Aji's reflected loop. + state = reflect(previous ^ 0xffffffff, 32) + for byte in data: + state ^= reflect(byte, 8) << 24 + for _ in range(8): + top = state >> 31 + state = ((state << 1) & 0xffffffff) ^ (0x1edc6f41 if top else 0) + return reflect(state, 32) ^ 0xffffffff + + +def fnv1a64(data, previous=0xcbf29ce484222325): + for byte in data: + previous = ((previous ^ byte) * 1099511628211) % (1 << 64) + return previous + + +def main(): + # RFC 9923 FNV-1a; RFC 3720 B.4 numeric CRCs (its wire bytes are LE). + assert fnv1a64(b"foobar") == 0x85944171f73967e8 + assert crc32c(b"123456789") == 0xe3069283 + assert crc32c(bytes(32)) == 0x8a9136aa + assert crc32c(bytes([255]) * 32) == 0x62a8ab43 + assert crc32c(bytes(range(32))) == 0x46dd794e + assert crc32c(bytes(range(31, -1, -1))) == 0x113fdb5c + pattern = r'fixture\(ref (b"(?:\\x[0-9a-f]{2})*"|empty\[0\.\.0\]), (0x[0-9a-f]+)u64, (0x[0-9a-f]+)u32, (0x[0-9a-f]+)u64, (0x[0-9a-f]+)u32\);' + count = 0 + for name, expected_count in (("known", 10), ("single_bytes", 256), ("patterns", 20)): + rows = re.findall(pattern, (FIXTURES / f"{name}.aji").read_text()) + assert len(rows) == expected_count, (name, len(rows)) + for escaped, *numbers in rows: + data = bytes.fromhex(escaped[2:-1].replace("\\x", "")) if escaped.startswith('b"') else b"" + expected = (fnv1a64(data), crc32c(data), fnv1a64(data, (1 << 64) - 1), crc32c(data, 0x12345678)) + assert tuple(int(number, 16) for number in numbers) == expected, (name, data.hex()) + count += 1 + print(f"hash oracle vectors passed ({count} inputs, {count * 4} fresh/continuation results)") + + +if __name__ == "__main__": + main() diff --git a/tools/hashmap_vectors.py b/tools/hashmap_vectors.py new file mode 100644 index 0000000..a6a7abf --- /dev/null +++ b/tools/hashmap_vectors.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Check public general-map traces against Python dicts and the specified pop order. + +The oracle models associations, bounded insertion, returned owners and dense +order; it does not model hashing, bucket placement, tombstones or rehashing. +--write regenerates the public .aji fixtures, which conformance executes. +""" +from pathlib import Path +import random +import sys + +ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/hashmap" +KEYS = """struct Key { id: u64, salt: u64 } +fn hash(key: ref) -> u64 effects [] { return key.id % 4u64; } +fn equal(a: ref, b: ref) -> bool effects [] { return a.id == b.id; } +""" + + +def trace(owning): + value_type = "own" if owning else "u64" + args = f"Key, {value_type}, fn hash, fn equal" + entry_type = f"std.hashmap.Entry" + state, dense, capacity, lines = {}, [], 2, [] + rng = random.Random(301029 + int(owning)) + domain = [0, 1, 2, 3, 4, 5, 6, 7, 2**64 - 1] + + def check_entry(key, salt, value): + if owning: + return ("let (key,value) = struct.unpack(move entry); let number = own.take(move value); " + f"assert(key.id == {key}u64); assert(key.salt == {salt}u64); assert(number == {value}u64);") + return f"assert(entry.key.id == {key}u64); assert(entry.key.salt == {salt}u64); assert(entry.value == {value}u64);" + + for step in range(96): + lines.append("{") + action = rng.choice(["insert"] * 4 + ["remove"] * 2 + ["pop", "reserve", "get"]) + key = rng.choice(domain) + if action == "insert": + value, salt = rng.randrange(1, 500), step + 1 + if key in state: + tag, previous = "replaced", state[key] + expected = check_entry(key, *previous) + state[key] = salt, value + elif len(state) == capacity: + tag, expected = "full", check_entry(key, salt, value) + else: + tag, expected = "inserted", "" + state[key] = salt, value + dense.append(key) + operand = f"{value}u64" + if owning: + lines.append(f"let item = own.new({value}u64, heap) or trap;") + operand = "move item" + arms = [] + for variant in ("inserted", "replaced", "full"): + payload = "" if variant == "inserted" else "(entry)" + arms.append(f"std.hashmap.InsertResult::::{variant}{payload} => {{ {expected if variant == tag else 'trap;'} }}") + lines.append(f"match std.hashmap.insert::<{args}>(q, Key {{ id: {key}, salt: {salt} }}, {operand}) {{ " + ", ".join(arms) + " }") + elif action in ("remove", "pop"): + if action == "remove": + lines.append(f"let query = Key {{ id: {key}, salt: 0 }};") + call, present = f"std.hashmap.remove::<{args}>(q, ref query)", key in state + if present: + index, last = dense.index(key), dense.pop() + if index < len(dense): + dense[index] = last + else: + call, present = f"std.hashmap.pop::<{args}>(q)", bool(dense) + if present: + key = dense.pop() + expected = check_entry(key, *state.pop(key)) if present else "trap;" + lines.append(f"match {call} {{ std.option.Option::<{entry_type}>::some(entry) => {{ {expected} }}, std.option.Option::<{entry_type}>::none => {{ {'trap;' if present else ''} }} }}") + elif action == "reserve": + new = rng.choice([0, 2, 3, 4, 6, 8]) + capacity = max(capacity, new) + lines.append(f"match std.hashmap.reserve::<{args}>(q, {new}usize, heap) {{ std.hashmap.ReserveResult::ok => {{}}, std.hashmap.ReserveResult::err(error) => {{ trap; }} }}") + lines.append(f"assert(std.hashmap.len::<{args}>(ref q) == {len(state)}usize); assert(std.hashmap.capacity::<{args}>(ref q) == {capacity}usize);") + for candidate in domain: + lines.append(f"{{ let query = Key {{ id: {candidate}, salt: 0 }}; assert(std.hashmap.contains::<{args}>(ref q, ref query) == {str(candidate in state).lower()});") + if not owning: + some = f"assert(value == {state[candidate][1]}u64);" if candidate in state else "trap;" + none = "trap;" if candidate in state else "" + lines.append(f"match std.hashmap.get::<{args}>(ref q, ref query) {{ std.option.Option::::some(value) => {{ {some} }}, std.option.Option::::none => {{ {none} }} }}") + lines.append("}") + for index, candidate in enumerate(dense): + salt, value = state[candidate] + suffix = "" if owning else f" assert(view[{index}usize].value == {value}u64);" + lines.append(f"{{ ref storage = q.entries; ref view = buffer.view(storage); assert(view[{index}usize].key.id == {candidate}u64); assert(view[{index}usize].key.salt == {salt}u64);{suffix} }}") + lines.append("}") + for key in reversed(dense): + lines.append(f"{{ let entry = extracted::<{entry_type}>(std.hashmap.pop::<{args}>(q)); " + check_entry(key, *state[key]) + " }") + return (f"fn main(heap: cap) -> u64 effects [mem.alloc] {{\n let map = opened::<{args}>(2, heap);\n {{ mut q = map;\n" + + "\n".join(lines) + f"\n }} released::<{args}>(move map); return 42;\n}}\n") + + +for owning in (False, True): + name = "model_owner" if owning else "model" + path = ROOT / (name + ".aji") + if "--write" in sys.argv: + base = (ROOT / "copy.aji").read_text() + preamble = base[base.index("module test.hashmap"):base.index("struct Key")] + path.write_text("// expect: run\n// result: 42\n// phase: 6\n// spec: docs/spec/16-standard-library.md §2.14\n// grant: heap=mem.alloc:1120\n// fuel: 4000000\n" + preamble + KEYS + trace(owning)) + text = path.read_text() + assert KEYS in text, name + " has the wrong public key policy" + assert text[text.index("fn main("):] == trace(owning), name + " differs from the independent oracle" + +print("general hash-map oracle passed (2 seeds, 192 operations; Copy/owning values, all keys and dense order)") diff --git a/tools/hashset_vectors.py b/tools/hashset_vectors.py new file mode 100644 index 0000000..3ba393f --- /dev/null +++ b/tools/hashset_vectors.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +"""Public set/representative oracle; does not model buckets/probing/rehash. + +Use --write to regenerate fixtures; conformance executes them with fuel. +""" +from pathlib import Path +import random +import sys + +ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/hashset" + + +def trace(owning): + args = "Key,fn hash,fn equal" + members, markers, dense, capacity = set(), {}, [], 2 + lines = [] + rng = random.Random(31001 + int(owning)) + domain = [0, 1, 2, 3, 7, 2**64 - 1] + + def check(marker, key=None): + if owning: + body = "let (id,owner) = struct.unpack(move key); " + if key is not None: + body += f"assert(id == {key}u64); " + return body + f"assert(own.take(move owner) == {marker}u64);" + return (f"assert(key.id == {key}u64); " if key is not None else "") + f"assert(key.marker == {marker}u64);" + + for step in range(40): + lines.append("{") + op, key = rng.choice(["insert"] * 4 + ["remove", "pop", "reserve"]), rng.choice(domain) + if op == "insert": + marker = step + 1 + tag = "present" if key in members else "full" if len(members) == capacity else "inserted" + if tag == "inserted": + members.add(key) + markers[key] = marker + dense.append(key) + value = f"Key {{ id: {key},marker: {marker} }}" + if owning: + lines.append(f"let incoming = Key {{ id: {key},owner: own.new({marker}u64,heap) or trap }};") + value = "move incoming" + arms = [] + for variant in ("inserted", "present", "full"): + payload = "" if variant == "inserted" else "(key)" + body = "" if variant == "inserted" else check(marker, key) + arms.append(f"std.hashset.InsertResult::::{variant}{payload} => {{ {body if tag == variant else 'trap;'} }}") + lines.append(f"match std.hashset.insert::<{args}>(q,{value}) {{ " + ", ".join(arms) + " }") + elif op in ("remove", "pop"): + if op == "remove": + if owning: + lines.append(f"let query = Key {{ id: {key},owner: own.new(0u64,heap) or trap }};") + else: + lines.append(f"let query = Key {{ id: {key},marker: 0 }};") + call, present = f"std.hashset.remove::<{args}>(q,ref query)", key in members + if present: + index, last = dense.index(key), dense.pop() + if index < len(dense): + dense[index] = last + else: + call, present = f"std.hashset.pop::<{args}>(q)", bool(dense) + if present: + key = dense.pop() + body = check(markers.pop(key), key) if present else "trap;" + if present: + members.remove(key) + lines.append(f"match {call} {{ std.option.Option::::some(key) => {{ {body} }}, std.option.Option::::none => {{ {'trap;' if present else ''} }} }}") + if owning and op == "remove": + lines.append("let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64);") + elif op == "reserve": + new = rng.choice([0, 2, 3, 4]) + capacity = max(capacity, new) + lines.append(f"match std.hashset.reserve::<{args}>(q,{new}usize,heap) {{ std.hashset.ReserveResult::ok => {{}}, std.hashset.ReserveResult::err(error) => {{ trap; }} }}") + lines.append(f"assert(std.hashset.len::<{args}>(ref q) == {len(members)}usize); assert(std.hashset.capacity::<{args}>(ref q) == {capacity}usize);") + for query in domain: + value = f"Key {{ id: {query},marker: 0 }}" + if owning: + value = f"Key {{ id: {query},owner: own.new(0u64,heap) or trap }}" + lines.append(f"{{ let query = {value}; assert(std.hashset.contains::<{args}>(ref q,ref query) == {str(query in members).lower()});") + if owning: + lines.append("let (id,owner) = struct.unpack(move query); assert(own.take(move owner) == 0u64);") + lines.append("}") + lines.append("}") + for key in reversed(dense): + lines.append(f"{{ let key = extracted::(std.hashset.pop::<{args}>(q)); " + check(markers[key], key) + " }") + return (f"fn main(heap: cap) -> u64 effects [mem.alloc] {{\n let set = opened::<{args}>(2,heap);\n {{ mut q = set;\n" + + "\n".join(lines) + f"\n }} released::<{args}>(move set); return 42;\n}}\n") + + +for owning in (False, True): + name = "model_owner" if owning else "model" + path = ROOT / (name + ".aji") + keys = ("struct Key { id: u64, owner: own }\n" if owning else "struct Key { id: u64, marker: u64 }\n") + ( + "fn hash(key: ref) -> u64 effects [] { return key.id % 3u64; }\n" + "fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; }\n") + if "--write" in sys.argv: + base = (ROOT / "copy.aji").read_text() + preamble = base[base.index("module test.hashset"):base.index("struct Key")] + path.write_text("// expect: run\n// result: 42\n// phase: 6\n// spec: docs/spec/16-standard-library.md §2.15\n// grant: heap=mem.alloc:512\n// fuel: 2000000\n" + preamble + keys + trace(owning)) + text = path.read_text() + assert keys in text, name + " has the wrong public key policy" + assert text[text.index("fn main("):] == trace(owning), name + " differs from the independent set oracle" + +print("hash-set oracle passed (2 seeds, 80 operations; Copy/owner keys, duplicate representatives and all membership)") diff --git a/tools/heap_vectors.py b/tools/heap_vectors.py new file mode 100644 index 0000000..b66f011 --- /dev/null +++ b/tools/heap_vectors.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Public heapq/sorted oracles; no dense entries/index/sift model. + +Use --write to regenerate deterministic fixtures, executed with fuel. +""" +import heapq +from itertools import permutations +from pathlib import Path +import random +import sys + +ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/heap" +COMMON = (ROOT / "copy.aji").read_text().split("fn before(")[0] +COMMON = COMMON[COMMON.index("module test.heap"):] + + +def trace(owning): + rng = random.Random(32001 + int(owning)) + queue, capacity, lines = [], 2, [] + policy = "a.priority > b.priority" if owning else "a.priority < b.priority" + field = "owner: own" if owning else "marker: u64" + keys = f"struct Item {{ priority: u64, id: u64, {field} }}\n" + keys += f"fn before(a: ref,b: ref) -> bool effects [] {{ return {policy} or (a.priority == b.priority and a.id < b.id); }}\n" + keys += "fn checked(item: Item,priority: u64,id: u64) -> void effects [] {\n" + keys += ("let (actual_priority,actual_id,owner) = struct.unpack(move item); assert(actual_priority == priority); assert(actual_id == id); assert(own.take(move owner) == id);\n" if owning else + "assert(item.priority == priority); assert(item.id == id); assert(item.marker == id);\n") + keys += "}\n" + + def pop(): + if queue: + priority, identifier = heapq.heappop(queue) + if owning: + priority = -priority + return f"checked(extracted::(std.heap.pop::(q)),{priority}u64,{identifier}u64);" + return "match std.heap.pop::(q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } }" + + for step in range(80): + lines.append("{") + operation = rng.choice(["push"] * 4 + ["pop"] * 2 + ["reserve"]) + if operation == "push": + priority, identifier = rng.choice([0, 1, 2, 3, 7, 2**64 - 1]), step + 1 + value = f"Item {{ priority: {priority},id: {identifier},marker: {identifier} }}" + if owning: + lines.append(f"let incoming = Item {{ priority: {priority},id: {identifier},owner: own.new({identifier}u64,heap) or trap }};") + value = "move incoming" + full = len(queue) == capacity + if not full: + heapq.heappush(queue, (-priority if owning else priority, identifier)) + success = "trap;" if full else "" + failure = f"checked({'move item' if owning else 'item'},{priority}u64,{identifier}u64);" if full else "trap;" + lines.append(f"match std.heap.push::(q,{value}) {{ std.heap.PushResult::::ok => {{ {success} }}, std.heap.PushResult::::full(item) => {{ {failure} }} }}") + elif operation == "pop": + lines.append(pop()) + else: + request = rng.choice([0, 2, 4, 8]) + capacity = max(capacity, request) + lines.append(f"match std.heap.reserve::(q,{request}usize,heap) {{ std.heap.ReserveResult::ok => {{}}, std.heap.ReserveResult::err(error) => {{ trap; }} }}") + lines.append(f"assert(std.heap.len::(ref q) == {len(queue)}usize); assert(std.heap.capacity::(ref q) == {capacity}usize);") + if not owning: + if queue: + priority, identifier = queue[0] + lines.append(f"checked(extracted::(std.heap.peek::(ref q)),{priority}u64,{identifier}u64);") + else: + lines.append("match std.heap.peek::(ref q) { std.option.Option::::none => {}, std.option.Option::::some(item) => { trap; } }") + lines.append("}") + while queue: + lines.append(pop()) + return keys + "fn main(heap: cap) -> u64 effects [mem.alloc] {\n let value = opened::(2,heap);\n { mut q = value;\n" + "\n".join(lines) + "\n } released::(move value); return 42;\n}\n" + + +def exhaustive(): + text = """fn before(a: ref,b: ref) -> bool effects [] { return *a < *b; } +fn check(values: slice,heap: cap) -> void effects [mem.alloc] { + let value = opened::(5,heap); + { mut q = value; + for i in 0usize..5usize { pushed::(std.heap.push::(q,values[i])); } + for i in 0usize..5usize { assert(extracted::(std.heap.peek::(ref q)) == i as! u64); assert(extracted::(std.heap.pop::(q)) == i as! u64); } + } released::(move value); +} +fn main(heap: cap) -> u64 effects [mem.alloc] { +""" + for values in permutations(range(5)): + assert sorted(values) == list(range(5)) + text += "{ let values: [u64;5] = [" + ",".join(str(value) + "u64" for value in values) + "]; check(ref values,heap); }\n" + return text + "return 42;\n}\n" + + +for name, body, budget in (("model", trace(False), 2048), ("model_owner", trace(True), 2048), + ("permutations", exhaustive(), 120)): + path = ROOT / (name + ".aji") + expected = "// expect: run\n// result: 42\n// phase: 6\n// spec: docs/spec/16-standard-library.md §2.16\n" + f"// grant: heap=mem.alloc:{budget}\n// fuel: 2000000\n" + COMMON + body + if "--write" in sys.argv: + path.write_text(expected) + assert path.read_text() == expected, name + " differs from the independent heap oracle" + +print("heap oracle passed (2 seeds, 160 operations, min/max Copy/owners, all 120 permutations of five elements)") diff --git a/tools/io_vectors.py b/tools/io_vectors.py new file mode 100644 index 0000000..700c1c2 --- /dev/null +++ b/tools/io_vectors.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Independent public byte-prefix oracle for std.io; --write regenerates fixture.""" +from pathlib import Path +import sys + +ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/io" +HELPERS = '''import std.io; +import std.bytes; +fn prepare(contents: slice,dst: cap) -> void effects [fs.write] { + let file = fs.create(dst,b"/case/input") or trap; fs.write_all(file,contents) or trap; fs.close(move file) or trap; +} +fn reads(contents: slice,capacity: usize,prefix: usize,filled: bool,src: cap,dst: cap) -> void effects [fs.read,fs.write] { + prepare(contents,dst); + for mode in 0usize..2usize { + let file = fs.open_read(src,b"/case/input") or trap; var bytes: [u8;12] = [255u8;12]; + if mode == 0usize { + match std.io.read_exact_file(mut file,mut bytes[1usize..capacity+1usize]) { + std.io.ReadExactResult::ok => { assert(filled); }, std.io.ReadExactResult::eof(count) => { assert(not filled); assert(count == prefix); }, std.io.ReadExactResult::err(error) => { trap; } + } + } else { + match std.io.read_to_end_file(mut file,mut bytes[1usize..capacity+1usize]) { + std.io.ReadToEndResult::full(count) => { assert(filled); assert(count == capacity); }, std.io.ReadToEndResult::eof(count) => { assert(not filled); assert(count == prefix); }, std.io.ReadToEndResult::err(error) => { trap; } + } + } + assert(std.bytes.equal(ref bytes[1usize..prefix+1usize],ref contents[0usize..prefix])); + assert(bytes[0] == 255u8); for i in prefix+1usize..12usize { assert(bytes[i] == 255u8); } + fs.close(move file) or trap; + } +} +fn copies(contents: slice,capacity: usize,limit: usize,append: bool,tag: u64,count: usize,expected: slice,tail: slice,src: cap,dst: cap) -> void effects [fs.read,fs.write] { + prepare(contents,dst); let input = fs.open_read(src,b"/case/input") or trap; + var bytes: [u8;8] = [255u8;8]; var result: std.io.CopyResult = std.io.CopyResult::limit(0usize); + if append { + let base = fs.create(dst,b"/case/output") or trap; fs.write_all(base,b"old:") or trap; fs.close(move base) or trap; + let output = fs.open_append(dst,b"/case/output") or trap; + result = std.io.copy_file_append(mut input,mut output,mut bytes[1usize..capacity+1usize],limit); fs.close(move output) or trap; + } else { + let output = fs.create(dst,b"/case/output") or trap; + result = std.io.copy_file(mut input,mut output,mut bytes[1usize..capacity+1usize],limit); fs.close(move output) or trap; + } + match result { + std.io.CopyResult::eof(actual) => { assert(tag == 0u64); assert(actual == count); }, + std.io.CopyResult::limit(actual) => { assert(tag == 1u64); assert(actual == count); }, + std.io.CopyResult::err(error) => { assert(tag == 2u64); assert(error.read == 0usize); assert(error.confirmed_written == 0usize); } + } + assert(bytes[0] == 255u8); for i in capacity+1usize..8usize { assert(bytes[i] == 255u8); } + var remaining: [u8;12] = [0u8;12]; + match std.io.read_to_end_file(mut input,mut remaining) { std.io.ReadToEndResult::eof(actual) => { assert(actual == tail.len); assert(std.bytes.equal(ref remaining[0usize..actual],tail)); }, std.io.ReadToEndResult::full(actual) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + fs.close(move input) or trap; + let output = fs.open_read(src,b"/case/output") or trap; var actual: [u8;12] = [0u8;12]; + match std.io.read_to_end_file(mut output,mut actual) { std.io.ReadToEndResult::eof(count) => { assert(count == expected.len); assert(std.bytes.equal(ref actual[0usize..count],expected)); }, std.io.ReadToEndResult::full(count) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } + fs.close(move output) or trap; +} +''' + + +def literal(text): + if not text: + return "ref blank[0usize..0usize]" + return 'b"' + text + '"' + + +calls = [] +for length in range(9): + text = "abcdefgh"[:length] + for capacity in range(9): + prefix = text[:capacity] + calls.append(f"reads({literal(text)},{capacity}usize,{len(prefix)}usize,{str(capacity <= length).lower()},src,dst);") + +for append in (False, True): + for length in (0, 1, 2, 4, 7): + text = "abcdefg"[:length] + for capacity in (0, 1, 2, 3, 5): + for limit in (0, 1, 2, 4, 8): + copied = text[:limit] if capacity or not limit else "" + tag = 1 if not limit else 2 if not capacity else 1 if limit <= length else 0 + expected = ("old:" if append else "") + copied + tail = text[len(copied):] + calls.append(f"copies({literal(text)},{capacity}usize,{limit}usize,{str(append).lower()},{tag}u64,{len(copied)}usize,{literal(expected)},{literal(tail)},src,dst);") + +expected = '''// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.17 +// grant: src=fs.read:/case +// grant: dst=fs.write:/case +// file: /case/input=abcdefg +// file: /case/output=old:abcdefg +// fuel: 2000000 +module test.io +''' + HELPERS + "fn main(src: cap,dst: cap) -> u64 effects [fs.read,fs.write] {\nlet blank: [u8;1] = [0u8;1];\n" + "\n".join(calls) + "\nreturn 42;\n}\n" +path = ROOT / "model.aji" +if "--write" in sys.argv: + path.write_text(expected) +assert path.read_text() == expected, "I/O fixture differs from independent prefix/count oracle" +print("I/O oracle passed (162 read checks, 250 copy/append checks; data, guards, cursor tails, limits and empty scratch)") diff --git a/tools/map_vectors.py b/tools/map_vectors.py new file mode 100644 index 0000000..e241fb3 --- /dev/null +++ b/tools/map_vectors.py @@ -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) -> 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' 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::(q, {key}) {{ std.option.Option::::some(returned) => {some}, std.option.Option::::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.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::>::none => {{}}, std.option.Option::>::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)") diff --git a/tools/path_vectors.py b/tools/path_vectors.py new file mode 100644 index 0000000..3232ba8 --- /dev/null +++ b/tools/path_vectors.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +"""Forward-stack byte oracle, independent of reverse source algorithm.""" +from itertools import product +from pathlib import Path +import sys + +ROOT = Path(__file__).resolve().parents[1] / "tests/conformance/source/path" +HELPERS = '''import std.path; +import std.bytes; +fn written(result: std.path.WriteResult) -> usize effects [] { + match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } +} +fn query(path: slice,absolute: bool,bs: usize,be: usize,pe: usize,es: usize,ee: usize) -> void effects [] { + assert(std.path.is_absolute(path) == absolute); + let base = std.path.basename(path); let parent = std.path.parent(path); let extension = std.path.extension(path); + assert(base.start == bs); assert(base.end == be); assert(parent.start == 0usize); assert(parent.end == pe); assert(extension.start == es); assert(extension.end == ee); + assert(base.start <= base.end); assert(base.end <= path.len); assert(parent.end <= path.len); assert(extension.start <= extension.end); assert(extension.end <= path.len); +} +fn normalized(path: slice,expected: slice) -> void effects [] { + for capacity in 0usize..expected.len+2usize { + var bytes: [u8;64] = [255u8;64]; + match std.path.normalize(mut bytes[1usize..capacity+1usize],path) { + std.path.WriteResult::ok(n) => { assert(capacity >= expected.len); assert(n == expected.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],expected)); for i in n+1usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::short_output => { assert(capacity < expected.len); for i in 0usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; } + } + assert(bytes[0] == 255u8); + } + var twice: [u8;64] = [255u8;64]; let n = written(std.path.normalize(mut twice,expected)); assert(std.bytes.equal(ref twice[0usize..n],expected)); +} +fn joined(base: slice,child: slice,expected: slice) -> void effects [] { + for capacity in 0usize..expected.len+2usize { + var bytes: [u8;64] = [255u8;64]; + match std.path.join(mut bytes[1usize..capacity+1usize],base,child) { + std.path.WriteResult::ok(n) => { assert(capacity >= expected.len); assert(n == expected.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],expected)); for i in n+1usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::short_output => { assert(capacity < expected.len); for i in 0usize..64usize { assert(bytes[i] == 255u8); } }, + std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; } + } + assert(bytes[0] == 255u8); + } +} +fn invalid(base: slice,child: slice) -> void effects [] { + for capacity in 0usize..3usize { var bytes: [u8;4] = [255u8;4]; + match std.path.join(mut bytes[0usize..capacity],base,child) { std.path.WriteResult::invalid_input => {}, std.path.WriteResult::ok(n) => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } + for i in 0usize..4usize { assert(bytes[i] == 255u8); } + } +} +''' + + +def normal(path): + assert b"\0" not in path + rooted = path.startswith(b"/") + parts = [] + for part in path.split(b"/"): + if part in (b"", b"."): + continue + if part == b"..": + if parts and parts[-1] != b"..": + parts.pop() + elif not rooted: + parts.append(part) + else: + parts.append(part) + result = b"/".join(parts) + return b"/" + result if rooted else result or b"." + + +def joining(base, child): + if child.startswith(b"/"): + return normal(child) + return normal(base + (b"/" if base and child else b"") + child) + + +def queries(path): + trimmed = path.rstrip(b"/") + end = len(trimmed) + start = trimmed.rfind(b"/") + 1 if trimmed else 0 + prefix = len(path[:start].rstrip(b"/")) + if path.startswith(b"/") and not prefix: + prefix = 1 + dot = path[start:end].rfind(b".") + ext = start + dot + 1 if 0 < dot < end - start - 1 else end + return path.startswith(b"/"), start, end, prefix, ext, end + + +def literal(value): + if not value: + return "ref blank[0usize..0usize]" + encoded = "".join(chr(byte) if 32 <= byte <= 126 and byte not in (34, 92) else f"\\x{byte:02x}" for byte in value) + return 'b"' + encoded + '"' + + +paths = {b"", b"/", b"///", b"//a//b///", b".profile", b".profile.json", b"a..b", b"a.", b"a/../b", b"a/../../b", b"/../../a", b"../a/..", b"x\\y/../z", b"C:\\file.txt", b"a/\xff.bin", b"\x80\xfe", b"/a/\xff/.."} +for size in range(1, 4): + for parts in product((b"a", b".", b".."), repeat=size): + path = b"/".join(parts) + paths.update((path, b"/" + path, path + b"//")) +paths = sorted(paths) +# Independently sanity-check canonical algebra before materializing fixtures. +for path in paths: + assert normal(normal(path)) == normal(path) + result = normal(path) + assert b"//" not in result and (result == b"/" or not result.endswith(b"/")) +calls = [] +for path in paths: + absolute, *indices = queries(path) + calls.append(f"query({literal(path)},{str(absolute).lower()}," + ",".join(f"{n}usize" for n in indices) + ");") + calls.append(f"normalized({literal(path)},{literal(normal(path))});") +pairs = list(product((b"", b"a", b"/a", b"a/b/", b"../a", b"/", b"a/.."), (b"", b"b", b"..", b"../b", b"../../b", b"/b", b"//../b/"))) +for base, child in pairs: + calls.append(f"joined({literal(base)},{literal(child)},{literal(joining(base,child))});") +invalids = ((b"late/name/\0", b"/b"), (b"a", b"b/\0"), (b"\0", b""), (b"", b"\0")) +for base, child in invalids: + calls.append(f"invalid({literal(base)},{literal(child)});") +# Keep each batch's byte literals in a separate frame. Holding every literal +# in main's frame adds hundreds of roots to every per-instruction GC pass, +# without exercising a different path contract. All vectors/capacities remain. +batches = [calls[index:index + 16] for index in range(0, len(calls), 16)] +functions = [] +for index, batch in enumerate(batches): + functions.append(f'fn batch_{index}() -> void effects [] {{\nlet blank: [u8;1] = [0u8;1];\n' + "\n".join(batch) + '\n}\n') +expected = '''// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/16-standard-library.md §2.19 +// fuel: 2000000 +module test.path_model +''' + HELPERS + "\n".join(functions) + 'fn main() -> u64 effects [] {\n' + "\n".join(f"batch_{index}();" for index in range(len(batches))) + '\nreturn 42;\n}\n' +path = ROOT / "model.aji" +if "--write" in sys.argv: + path.write_text(expected) +assert path.read_text() == expected, "Path fixture differs from independent forward-stack oracle" +print(f"path oracle passed ({len(paths)} paths/queries/idempotence, {len(pairs)} joins, 4 malformed pairs; all short/exact/extra capacities)") diff --git a/tools/source_coverage.py b/tools/source_coverage.py index dd166ad..9b41126 100644 --- a/tools/source_coverage.py +++ b/tools/source_coverage.py @@ -20,6 +20,56 @@ TESTS = os.path.join(ROOT, "tests", "conformance", "source") # (area, construct, regex, needs a reject test) CHECKLIST = [ + ("hashmap", "explicit general key policy and owning insert", r"std\.hashmap\.(insert|contains|get)::<", True), + ("hashmap", "explicit general growth/extraction/drain", r"std\.hashmap\.(reserve|remove|pop|free)::<", True), + ("hashset", "explicit membership and duplicate owner return", r"std\.hashset\.(insert|contains)::<", True), + ("hashset", "explicit set growth/extraction/drain", r"std\.hashset\.(reserve|remove|pop|free)::<", True), + ("heap", "explicit order and bounded owning push", r"std\.heap\.push::<", True), + ("heap", "Copy peek and moving pop", r"std\.heap\.(peek|pop)::<", True), + ("heap", "explicit heap growth and drain", r"std\.heap\.(reserve|free)::<", True), + ("path", "raw byte components and ranges", r"std\.path\.(is_absolute|basename|parent|extension)\(", True), + ("path", "caller-buffer normalization and join", r"std\.path\.(normalize|join)\(", True), + ("buffered io", "owned reader construction and explicit termination", r"std\.io\.reader\.(new|finish|discard)\(", True), + ("buffered io", "borrowed cached reads and exact prefixes", r"std\.io\.reader\.(read|read_exact)\(", True), + ("buffered io", "owned writer construction and explicit termination", r"std\.io\.writer\.(new|finish|discard)\(", True), + ("buffered io", "borrowed writes and explicit flush", r"std\.io\.writer\.(write|flush)\(", True), + ("io", "exact reads with explicit effects and borrowed destinations", r"std\.io\.read_exact_(stdin|file|stream)\(", True), + ("io", "bounded file read/copy and explicit progress", r"std\.io\.(read_to_end_file|copy_file|copy_file_append)\(", True), + ("static functions", "explicit callable contract", r"[A-Z]\w*: fn\(", True), + ("static functions", "explicit named operation argument", r"(?:<|, )fn [a-z]\w*(?:\.|>|:)", True), + ("static functions", "forwarded static operation", r"(?:<|, )fn [A-Z]\w*", True), + ("static functions", "named static worker", r"task\.spawn\(\w+, [A-Z]\w*[,)]", True), + ("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), + ("deque", "bounded owning ring ends", r"std\.deque\.(push_front|push_back|pop_front|pop_back)", True), + ("deque", "explicit growth, replacement and drain", r"std\.deque\.(reserve|replace|free)", True), + ("buffers", "initialized buffer allocation and drain", r"buffer\.(new|push|pop|free)", True), + ("buffers", "explicit reserve and borrowed views", r"buffer\.(reserve|view)", True), + ("buffers", "safe owning Vec", r"std\.vec\.", True), + ("linear aggregates", "complete struct unpack", r"struct\.unpack\(", True), + ("linear aggregates", "complete array unpack", r"array\.unpack\(", True), + ("linear aggregates", "ordered array literal", r"\[move \w+,", True), + ("linear aggregates", "consuming enum match", r"match move ", True), + ("linear aggregates", "borrowed complete exchange", r"value\.swap\(", True), + ("linear aggregates", "ownership-preserving heap allocation", r"own\.pack\(", True), + ("generics", "generic function declaration", r"fn \w+<", True), + ("generics", "generic struct/enum declaration", r"(?:struct|enum) \w+<", True), + ("generics", "explicit function/worker application", r"[a-z]\w*::<", True), + ("generics", "applied generic type", r": (?:[a-z]\w*\.)*[A-Z]\w*<", True), + ("generics", "generic constructor/pattern", r"[A-Z]\w*::<", True), + ("generics", "structural property constraint", r"[A-Z]\w*: (?:Copy|Send|Share|Freeze|Local)", True), + ("modules", "package module import", r"^import app\.", True), + ("modules", "qualified package call", r"app\.\w+\.[a-z]\w*\(", True), + ("modules", "qualified struct literal", r"app\.\w+\.[A-Z]\w* \{", True), + ("modules", "qualified task worker", r"task\.spawn\(\w+, app\.", True), + ("stdlib", "qualified standard enum type", r": std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.[A-Z]\w*\b", True), + ("stdlib", "qualified standard enum constructor", r"std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.[A-Z]\w*::\w+(?:\(|;)", True), + ("stdlib", "qualified standard enum match", r"std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.[A-Z]\w*::\w+(?:\([^)]*\))? =>", True), + ("stdlib", "built-in module import", r"^import std\.", True), + ("stdlib", "qualified standard call", r"std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.\w+\(", True), ("scalars", "checked arithmetic", r"[^%]\+ [a-z0-9]", False), ("scalars", "wrapping arithmetic `+%`", r"\+%", False), ("scalars", "`as` (lossless widening)", r"\bas [ui]\d", True),