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<V> contract: exact key equality, bounded insert,
returned replacement/full ownership, tombstones, moving drain and
failure-preserving peak-charged rehash. Keep general HashMap<K,V> key
hash/equality policy open as Q-037. A checked slot prerequisite confirms
read-only Copy key/state fields over Option<V>, 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.
This commit is contained in:
dev committed 2026-10-07 00:53:50 +03:00
1 parent 93405f69ce
commit 89c63c306b
32 files changed
+852 -5

No files matched your search

+18 -1
View File
@@ -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 `::<T>` specialization:
Only new/reserve declare effects [mem.alloc] and require cap<mem.alloc>. Each slot charges accounted_size(Option<T>) (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<u8>) -> u64` | FNV-1a 64, initial state `0xcbf29ce484222325` |
| `fnv1a64_extend(state: u64, data: slice<u8>) -> u64` | continue from the supplied FNV state |
| `crc32c(data: slice<u8>) -> u32` | reflected CRC-32C (Castagnoli), initial/final XOR `0xffffffff` |
| `crc32c_extend(checksum: u32, data: slice<u8>) -> 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.