Expand description
Deterministic content hashing for cache boundaries (design note
docs/incremental-dependencies.md §4, §5).
Incremental builds compare content boundaries: “did these bytes change?”
, and the §4 hash sketches all share one shape: H(engine_version, …fields).
ContentHasher is the one place that shape is implemented, so every
boundary (bibliography sources, page layout output, future source/asset
hashes per §9.4) folds its fields the same way instead of re-deriving FNV in
each crate.
§What it guarantees
- Engine-version stamped.
ContentHasher::newfoldsCARGO_PKG_VERSIONfirst, so bumping the engine invalidates every hash (§5 rule 2). Callers cannot forget it. - Portable & deterministic. The state is FNV-1a over 128 bits: fully
specified, endianness-pinned (fixed little-endian widths), and independent
of pointer identity or hash-map order. Unlike
std’s randomly-seededSipHash, which §4 rules out, two runs of the same input always agree. - Unambiguous framing.
fieldlength-prefixes its bytes, so concatenated variable-length fields cannot collide across a different split. Fixed-width numbers (u32) need no prefix.
§Interim hasher
FNV-1a is an interim choice: the design note prefers
BLAKE3-truncated-to-128, and the §9.4 slice may swap the construction. That
swap stays internal; the ContentHasher API is unchanged, but it does
change hash values, which the stamped engine version absorbs. FNV is not
collision-hardened; nothing yet relies on adversarial collision resistance.
Structs§
- Content
Hash - Opaque content / dependency hash.
- Content
Hasher - An incremental builder for a deterministic
ContentHashover a sequence of typed fields (design note §4).
Constants§
- ENGINE_
VERSION 🔒 - Engine version stamped into every hash (§5 rule 2).
- FNV_
OFFSET_ 🔒BASIS - FNV-1a 128-bit offset basis (FNV spec).
- FNV_
PRIME 🔒 - FNV-1a 128-bit prime (FNV spec):
2^88 + 2^8 + 0x3b.