From 89c63c306b14a1bc1536dd9009caf7fee69d6474 Mon Sep 17 00:00:00 2001 From: "A.Shakhmatov" Date: Wed, 7 Oct 2026 00:53:50 +0300 Subject: [PATCH] cli: add standard hashes and propose owning map contract Embed std.hash with four ordinary safe byte functions: FNV-1a 64 and Castagnoli CRC-32C, each with fresh and numeric continuation forms. Specify exact constants, empty/chunk semantics, arbitrary continuation states, target-independent numeric results and explicit serialization. No heap allocation, authority, AIR, verifier or runtime change. Propose the next U64Map contract: exact key equality, bounded insert, returned replacement/full ownership, tombstones, moving drain and failure-preserving peak-charged rehash. Keep general HashMap key hash/equality policy open as Q-037. A checked slot prerequisite confirms read-only Copy key/state fields over Option, with explicit accounting for both tags and owning payload cleanup; no map module is registered. Validation: unit tests, 797 full conformance cases, 12 new fixtures; all 11 hash cases with per-instruction collection and 12 schedule seeds across four quanta, plus owning slot collection; 84 source/AIR, package and hosted CLI checks; independent forward-polynomial CRC and arbitrary precision FNV oracles for 286 inputs / 1144 results; 95/95 source coverage; Zig formatting, whitespace and reference generation. Published vectors come from RFC 9923 and RFC 3720, with explicit numeric/wire conventions. Reference cost: source excluding AIR 53,993 -> 55,281 cl100k (+2.4%); Quick Reference 7,747 -> 7,806 (+0.8%); AIR remains 175,736 bytes. Map design remains outside both bundles. No empirical MCC or native throughput claim; CRC initially uses eight bit steps per byte. --- .github/workflows/ci.yml | 2 + CONTRIBUTING.md | 1 + build.zig | 1 + docs/agent/README.md | 2 + docs/agent/quick-reference.md | 2 + docs/agent/source-notes.md | 2 +- docs/design/hash-map.md | 52 ++++ docs/design/open-questions.md | 6 + docs/plan/phase-6-source-language.md | 2 +- docs/plan/standard-library.md | 10 +- docs/reference/std.md | 15 + docs/rfcs/0026-standard-hash-foundation.md | 39 +++ docs/spec/16-standard-library.md | 19 +- examples/std/hash.aji | 19 ++ src/frontend/stdlib.zig | 1 + std/README.md | 2 + std/hash.aji | 30 ++ tests/conformance/source/hash/alias.aji | 12 + tests/conformance/source/hash/borrow.aji | 22 ++ tests/conformance/source/hash/generic.aji | 6 + tests/conformance/source/hash/known.aji | 28 ++ tests/conformance/source/hash/map_storage.aji | 48 +++ .../source/hash/missing_import.aji | 5 + tests/conformance/source/hash/patterns.aji | 37 +++ tests/conformance/source/hash/shared.aji | 25 ++ .../conformance/source/hash/single_bytes.aji | 273 ++++++++++++++++++ tests/conformance/source/hash/streaming.aji | 41 +++ tests/conformance/source/hash/wrong_slice.aji | 6 + tests/conformance/source/hash/wrong_state.aji | 6 + tests/hosted/source_hash.py | 89 ++++++ tools/hash_vectors.py | 52 ++++ tools/source_coverage.py | 2 + 32 files changed, 852 insertions(+), 5 deletions(-) create mode 100644 docs/design/hash-map.md create mode 100644 docs/rfcs/0026-standard-hash-foundation.md create mode 100644 examples/std/hash.aji create mode 100644 std/hash.aji create mode 100644 tests/conformance/source/hash/alias.aji create mode 100644 tests/conformance/source/hash/borrow.aji create mode 100644 tests/conformance/source/hash/generic.aji create mode 100644 tests/conformance/source/hash/known.aji create mode 100644 tests/conformance/source/hash/map_storage.aji create mode 100644 tests/conformance/source/hash/missing_import.aji create mode 100644 tests/conformance/source/hash/patterns.aji create mode 100644 tests/conformance/source/hash/shared.aji create mode 100644 tests/conformance/source/hash/single_bytes.aji create mode 100644 tests/conformance/source/hash/streaming.aji create mode 100644 tests/conformance/source/hash/wrong_slice.aji create mode 100644 tests/conformance/source/hash/wrong_state.aji create mode 100644 tests/hosted/source_hash.py create mode 100644 tools/hash_vectors.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0687379..be78f90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,8 @@ jobs: - 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: 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 8a51103..f1be912 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,6 +21,7 @@ python3 tests/hosted/source_generics.py # explicit generics, constraints and pro 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 (cd tools/eval && python3 -m unittest discover tests) # evaluation harness self-tests zig fmt --check build.zig src tools ``` diff --git a/build.zig b/build.zig index 3a0f0a6..6a37be9 100644 --- a/build.zig +++ b/build.zig @@ -32,6 +32,7 @@ pub fn build(b: *std.Build) void { 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_math_aji", .{ .root_source_file = b.path("std/math.aji") }); mod.addAnonymousImport("std_option_aji", .{ .root_source_file = b.path("std/option.aji") }); mod.addAnonymousImport("std_result_aji", .{ .root_source_file = b.path("std/result.aji") }); diff --git a/docs/agent/README.md b/docs/agent/README.md index 37f1f72..e8052c8 100644 --- a/docs/agent/README.md +++ b/docs/agent/README.md @@ -111,3 +111,5 @@ RFC 0023 whole-value linear aggregates (cl100k, relative to generics): Quick Ref 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. diff --git a/docs/agent/quick-reference.md b/docs/agent/quick-reference.md index 8844e30..6ec5d1c 100644 --- a/docs/agent/quick-reference.md +++ b/docs/agent/quick-reference.md @@ -361,6 +361,8 @@ The usual enum rules apply: missing arm `E7004`, wrong enum/payload `E7005`, unk `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.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`: diff --git a/docs/agent/source-notes.md b/docs/agent/source-notes.md index 740df15..694f009 100644 --- a/docs/agent/source-notes.md +++ b/docs/agent/source-notes.md @@ -8,7 +8,7 @@ The other files in `/docs` hold the full rules. Open one only when this page is | Need | Read | |---|---| -| built-in bytes/math/text/formatting, option/result, owning Vec and Deque, signatures and failure contracts | `/docs/library/std.md` | +| built-in bytes/math/text/formatting/hash, option/result, owning Vec and Deque, 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 and specialization limits | `/docs/language/generics.md` | diff --git a/docs/design/hash-map.md b/docs/design/hash-map.md new file mode 100644 index 0000000..a1a7ce8 --- /dev/null +++ b/docs/design/hash-map.md @@ -0,0 +1,52 @@ +# Owning hash map contract proposal + +Status: proposed STD-6d design; no map module is implemented or registered yet. Spec 16 defines the available std.hash API only. This document fixes the next implementation scope and review cases; it does not override the specification. + +## Key policy and scope + +The eventual collection gate still requires HashMap>. Current type parameters are types, not hashing/equality operations (spec 15 §15); Copy supplies neither. Source has no callbacks, methods, user traits or value generic parameters. Treating a digest as key identity is incorrect because different keys can collide. Adding a language feature solely to make this API look generic would add more agent concepts before establishing their general value. + +Start with `std.map.U64Map`: exact u64 keys, generic Copy or linear values, existing source primitives only. Users with genuine numeric identifiers can use it directly. Bytes/struct keys cannot be converted to digests and then treated as unique numeric keys; general key hashing/equality is Q-037. Byte-key ownership needs a separate owning representation contract. Do not name this specialization HashMap or claim that it satisfies the general-key gate. + +## Proposed public API + +Ten generic functions, each explicitly specialized `::`; only new/reserve declare effects [mem.alloc] and take cap. All other functions declare effects []. Names/types below are proposed, unavailable calls today. + +| 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 would be 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. These become executable conformance examples with the implementation; this proposal is not evidence that they run today. + +Before marking the specialization done, test exact collisions, tombstones before matching keys, wraparound, a table with no empty slots, full-table replacement, zero capacity and all scalar keys. Compare mixed operations and all associations with an independent Python dict oracle. Include Copy/owner/file/sender cleanup, repeated reuse, peak-charge failure, exact failure-state preservation, cross-authority refunds and invalid-representation safety. Verify canonical AIR/package/hosted behavior, GC after each instruction and schedules for valid workers. Integrate normative rules in spec 16 and the API reference, register the module, measure bundle costs and report the remaining general-key gate explicitly. + +## Agent complexity impact + +This proposal adds no language concept, verifier state, syntax, diagnostic, callback, trait or runtime feature. The future library adds key equality, probing and returned replacement ownership; the latter reuses existing complete-value patterns. Ten operations avoid independent entry/cursor/borrow lifetimes. Public representation invariants increase documentation needs, so full details belong on demand. This draft stays outside the source/AIR bundles; the runnable hash increment measures its own cost in RFC 0026. No performance or Model Capability Compression result is inferred from the proposal or from benchmark tasks. diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index b170888..b404a95 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -268,3 +268,9 @@ During STD-4 validation, existing `from` declarations still return the frontend' 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 Proposed):** 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. + +**Open for general keys.** The [owning map proposal](hash-map.md) starts with an honest U64Map specialization, exact numeric equality and existing safe primitives. This does not complete the HashMap> collection gate. General key support must either use an independently specified concrete representation or justify a generally useful vertical language facility; it must not silently infer hashing/equality or introduce map-only compiler magic. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index cfd8a1c..17835c3 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -141,4 +141,4 @@ Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) a | P6-9 | todo | Port reference programs and examples to `.aji` | P6-5 | `tests/programs/`, `examples/` | exit criterion passes | | P6-10 | todo | Phase exit review | all | plan status | exit criterion passes | -The [standard-library track](standard-library.md) implements ten compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints on the branch. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer 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. Remaining maps/sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6. +The [standard-library track](standard-library.md) implements eleven compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints on the branch. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer and safe std.vec, explicit growth, returned failure ownership and draining (spec 15 §17). STD-6c/RFC 0025 adds safe owning Deque with existing source primitives. STD-6d.1/RFC 0026 adds pure std.hash; the next map contract is proposed with general key policy Q-037. Remaining maps/sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6. diff --git a/docs/plan/standard-library.md b/docs/plan/standard-library.md index eac66fe..374eb50 100644 --- a/docs/plan/standard-library.md +++ b/docs/plan/standard-library.md @@ -20,7 +20,7 @@ Without external source dependencies, Aji should support ordinary CLI tools, sto |---|---|---| | 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 branch implementation | compiler-pinned, closed registry; six modules; qualified enum types/constructors/patterns; no package lookup | +| Built-in standard imports and enum types | STD-0/1a/2a/2b branch implementation | compiler-pinned, closed registry; eleven modules; qualified enum types/constructors/patterns; no package lookup | | General modules/imported struct literals | STD-3 branch implementation (P6-3; RFC Proposed) | explicit manifest mapping, direct qualified names, ordinary verifier | | User generics/structural constraints | STD-4 branch implementation (P6-4; RFC Proposed) | needed for reusable `Vec`, `HashMap`, option/result | | `linear_aggregates` | STD-5 branch implementation (RFC Proposed) | whole-value owning structs/enums/fixed arrays; initialized buffer/std.vec implemented by STD-6a/b | @@ -57,7 +57,9 @@ SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protob | STD-6a | done (branch implementation; RFC 0024 Proposed) | 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 (branch implementation; RFC 0024 Proposed) | safe std.vec for Copy/owners/files/channel endpoints | STD-6a | explicit reserve, bounded push, moving pop/replace, empty-only free; deterministic and failure/cleanup tests | | STD-6c | done (branch implementation; RFC 0025 Proposed) | safe std.deque for Copy/owners/files/endpoints | STD-6a/b | bounded ring, both ends, failure-preserving explicit growth, complete resource transfer and empty-only free | -| STD-6d | todo | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap>, recoverable failures and explicit draining | +| STD-6d | todo (hash foundation done; maps proposed) | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap>, recoverable failures and explicit draining | +| STD-6d.1 | done (branch implementation; RFC 0026 Proposed) | pure std.hash: FNV-1a 64 / CRC32C, fresh/extend | STD-1b | four safe functions, exact byte/chunk conventions, independent public vectors and CLI/profile checks | +| STD-6d.2 | proposed; not implemented | U64Map first; general HashMap key policy Q-037 | STD-6d.1 | [reviewable contract](../design/hash-map.md), then executable safe map with ownership/failure/collision tests; general-key gate remains open | | STD-7 | todo | concrete I/O adapters, buffered I/O and lexical paths | STD-1b/2a/2b; STD-3 for public types | short reads, EOF, capacity and write failures covered; paths never grant filesystem authority | | STD-8 | todo | filesystem gaps, args/env capability RFC, time/random distinctions and structured log | STD-3/7; vertical runtime feature where needed | CLI/storage milestone examples work in deterministic and hosted profiles; all authority is granted at entry | | STD-9 | todo | independent integration application and API review | STD-6/7/8 | integration gate; public application is not private benchmark material | @@ -130,3 +132,7 @@ Source/AIR tests cover nested ownership, allocation success/failure, repeated ex 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 contract proposal](../design/hash-map.md) specifies numeric-key U64Map, bounded insert, returned replacement/full ownership, tombstone lookup, moving removal/drain and explicit peak-charged rehash. No map module is implemented; Q-037 keeps general key policy explicit, and HashMap>/HashSet/BinaryHeap remain required by STD-6d. diff --git a/docs/reference/std.md b/docs/reference/std.md index 1d8c628..f5b9a85 100644 --- a/docs/reference/std.md +++ b/docs/reference/std.md @@ -72,6 +72,21 @@ Missing enum arm: `E7004`; duplicate/wildcard enum arm: `E7006`; unknown type/va 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 | diff --git a/docs/rfcs/0026-standard-hash-foundation.md b/docs/rfcs/0026-standard-hash-foundation.md new file mode 100644 index 0000000..87d2687 --- /dev/null +++ b/docs/rfcs/0026-standard-hash-foundation.md @@ -0,0 +1,39 @@ +# RFC 0026: Non-cryptographic hash foundation + +Status: Proposed +Scope: STD-6d.1 pure library; next map contract remains a design proposal + +## 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/spec/16-standard-library.md b/docs/spec/16-standard-library.md index 15a5369..58197a4 100644 --- a/docs/spec/16-standard-library.md +++ b/docs/spec/16-standard-library.md @@ -10,7 +10,7 @@ APIs SHOULD offer one canonical operation for a common need, small documentation ## 2. Bootstrap module registry -The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.math`, `std.option`, `std.result`, `std.utf8`, `std.vec` and `std.deque`. They are implemented in safe `.aji`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/math.aji`, `std/option.aji`, `std/result.aji`, `std/utf8.aji`, `std/vec.aji` and `std/deque.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile and have no concurrency effects. Modules other than std.vec/std.deque declare effects [] and allocate no heap memory. std.vec/std.deque new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11); their other functions allocate no heap. Ordinary interpreter fuel limits apply. +The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.hash`, `std.math`, `std.option`, `std.result`, `std.utf8`, `std.vec` and `std.deque`. They are implemented in safe `.aji`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/hash.aji`, `std/math.aji`, `std/option.aji`, `std/result.aji`, `std/utf8.aji`, `std/vec.aji` and `std/deque.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile and have no concurrency effects. Modules other than std.vec/std.deque declare effects [] and allocate no heap memory. std.vec/std.deque new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11); their other functions allocate no heap. Ordinary interpreter fuel limits apply. ### 2.1 `std.math` @@ -184,3 +184,20 @@ Every function supplies explicit `::` specialization: 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. 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/src/frontend/stdlib.zig b/src/frontend/stdlib.zig index ba716dd..eb7498c 100644 --- a/src/frontend/stdlib.zig +++ b/src/frontend/stdlib.zig @@ -8,6 +8,7 @@ pub const registry = [_]Source{ .{ .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.math", .file = "std/math.aji", .source = @embedFile("std_math_aji") }, .{ .name = "std.option", .file = "std/option.aji", .source = @embedFile("std_option_aji") }, .{ .name = "std.result", .file = "std/result.aji", .source = @embedFile("std_result_aji") }, diff --git a/std/README.md b/std/README.md index fa4e191..7b2fab9 100644 --- a/std/README.md +++ b/std/README.md @@ -40,3 +40,5 @@ STD-5 supports whole-value owning structs/enums/fixed arrays and individual own< `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. The next owning map contract is a [proposal](../docs/design/hash-map.md), not an available std module. 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/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/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/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/source_coverage.py b/tools/source_coverage.py index 1458aae..0f89d67 100644 --- a/tools/source_coverage.py +++ b/tools/source_coverage.py @@ -20,6 +20,8 @@ TESTS = os.path.join(ROOT, "tests", "conformance", "source") # (area, construct, regex, needs a reject test) CHECKLIST = [ + ("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),