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.
40 lines
5.4 KiB
Markdown
40 lines
5.4 KiB
Markdown
# 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<V> 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<V> supports observational metadata access for owning V; a linear key/value enum would not. Both tags are explicitly charged. General HashMap<K,V> 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.
|