Skip to main content

Module map

Module map 

Source
Expand description

The submilli Map<K, V> — the Rust port of the prelude’s hand-written Wasm hashtable (codegen/prelude/map.rs).

The host owns the map end-to-end: it builds the backing struct, drives the open-addressing probe sequence, the insertion-order ledger, tombstones, and resize. Storage stays in the GC heap ($MapBacking { vtable, keys, values, size, order, order_len, hashes, order_positions, identity }); host fns read and write it through the struct ABI rather than holding a Rust HashMap.

Keys hash and compare through the object vtable — slot 3 (hash) and slot 2 (equals) via [dispatch_vtable_slot] — so get/set/has/delete are async (the dispatch may re-enter the guest for user-class keys). For string/array/number keys the slots are host fns, so the dispatch resolves without truly suspending. Cached bucket hashes avoid rehashing keys on resize; reverse ledger positions make deletion independent of ledger length.

Re-entrancy is closed by construction: equals/hash for user subtypes are compiler-generated structural functions that recurse only into other structural equals/hash, never back into Map.set/etc. So a mid-probe dispatch can’t mutate the map; no in-flight-mutation guard is needed.

Functions§

declare
install