Skip to main content

Module tier_cache

Module tier_cache 

Source
Expand description

Tier cache (HOTSWAP §P12): persist a compiled FnBytecode keyed by (source, optimization-config, tier) so a re-run skips re-optimization.

Soundness rests on the key: a hit means the EXACT same source was compiled at the same config and tier. A FnBytecode’s Ops carry interner-relative Symbol indices, which are only meaningful within the interner that produced them — but re-parsing identical source reproduces the same interning order, so a same-source hit’s indices resolve to the same symbols. Changing one byte of source (or the config, or the tier) changes the key → a miss → recompile. (m8: tier is in the key.)

encode/decode/cache_key are platform-agnostic so the browser warm tier (P13) can store the same wire bytes through OPFS (Vfs); store/load are the desktop on-disk sidecar.

Functions§

cache_key
(compiler, source, config, tier) → a stable hex key. FNV-1a over the compiler stamp, the source bytes, the config bitset, and the tier.
decode
Deserialize a body; None on ANY corruption — a corrupt entry is genuinely just a miss (the VM recompiles). Rejects: a missing/garbled checksum line, a checksum that does not match the payload (truncation / bit-flip), or non-deserializable JSON.
encode
Serialize a body to the cache wire format — bit-exact (f64 by bits, Symbol by index), so a decoded body is byte-identical to the one that was stored. A checksum line precedes the JSON so corruption is caught on the way back in.
load
Load the body cached for (source, config, tier) from dir; None on miss or corruption.
store
Store fnbc under (source, config, tier) in dir (created if absent). Best-effort — a write failure just means the next run recompiles.