0317.
All-size SWAR SwissTable probing, fast 64-bit mixing, and
single-probe map.update
- Status: Accepted; supersedes 0063 scalar fallback threshold
- Date: 2026-11-28
- Plan: M27.3
- Review: Memory and representation
Context
ADR-0063
introduced 7-bit tag bytes and 8-way portable C11 SWAR group
probing only above 16,384 entry capacity, retaining scalar linear
probing for smaller maps such as word-freq (8,193
keys) and bench/maps (10,000 keys). Meanwhile,
trt_map_hash used a multi-stage FNV/Murmur3 loop, and
common map updates written as
m = m.set(k, m.get_or(k, d) + 1) only fused into a
single hmapslot probe for direct integer-arithmetic
self-assignments — leaving record-field updates
(s = s with { counts: s.counts.update(k, 0) { n -> n + 1 } })
and general value updates (vec, str,
records, conditional logic) paying two full hashes and two
probes.
Decision
- All-size SWAR SwissTable (
>= 16index slots). Every allocated map has at least 8 entry capacity (16 index slots plus 7 cloned tail tags). Remove thecap <= 16384scalar fallback intrt_map_probeso all non-trivial maps use portable 64-bit SWAR 8-way tag-group probing with a single 64-bit group load per iteration, preceded by direct-hit and direct-empty home-slot fast paths and skipping tombstone mask extraction whenm->tombstones == 0. - Fast 64-bit
wyhash/rapidhash-class mixer. Replace the FNV/Murmur3 body oftrt_map_hashwith awymix(128-bit multiply-xor-fold viaunsigned __int128when__SIZEOF_INT128__is available and not__TINYC__, with a portable C11 32-bit-splituint64_tfallback). All unaligned loads usememcpy(strict C11, no UB),TRT_MAP_SEEDcontinues to seed the mixer, and theuint32_thash output and dense insertion-ordered entry layout remain unchanged. - Single-probe
m.update(key, default_val) { v -> new_v }onmap<K, V>. Reuse the existing trailing-block method-call grammar (zero parser or compact codec changes). Evaluation order is strictly left-to-right:m,key,default_val, then the block{ v -> new_v }receiving the existing value (if present) ordefault_val(if absent). Lowering emits ordinary Core IR (MapFind+If(MapValueAt / default)+ block +MapSet), so ADR-0278 ownership analysis automatically rewrites unique self-updates and record-field takes (s = s with { counts: s.counts.update(...) }) toMapSetUnique,regions/placehandles arena promotion,--report=copiesreports remaining copy sites, andtenon interphas exact parity without new IR opcodes.cgen/map.rsgeneralizesupsertto fuseMapFind+MapValueAt/default- pure/non-aliasing update body +
MapSet[Unique]into a singlehmapslothash and probe for any value type and destination local (including record-field takes), falling back cleanly to 2-probe IR when the body referencesmor may observe an aliased map.
- pure/non-aliasing update body +
Alternatives considered
- Dedicated
MapUpdateIR intrinsic. Would require duplicating ownership analysis, region placement, promotion, and interpreter evaluation logic for an inline closure body; lowering toMapFind+If+MapSetwith a C single-probe peephole reuses the full ADR-0278 pipeline. - Platform SIMD intrinsics (SSE2/NEON) for 16-byte groups. Adds target ifdefs and breaks TinyCC portability; portable 64-bit SWAR with direct-hit and direct-empty fast paths stays pure C11.
Consequences
- All map sizes (
>= 16index slots) benefit from 8-way tag filtering without changing dense entry layout, insertion order,TRT_MAP_SEEDdeterminism, tombstone compaction, or sanitizer/poison hygiene. map.updategives agents a concise, single-probe update idiom that composes withwithrecord updates and--report=copies.docs/spec/LANGUAGE.mdaddsupdate(k, init) { v -> … }underMapswithin the 6,250-token spec budget.