jrandolf opened issue #14832:
Today
map<K, V>can only be used through the typed API andbindgen!asHashMap<K, V>with the default hasher (std'sRandomState, or hashbrown's default hasher withoutstd). A few consequences:
- There's no support for
BTreeMap, custom hashers, or getting at the raw entries.Vec<(K, V)>doesn't work since it only typechecks againstlist.bindgen!has no way to choose the type (nomap_typeoption, andwithdoesn't apply to map aliases).additional_derives: [Hash](orOrd) fails for any record containing a map.- Lowering iterates a randomly-seeded
HashMap, so the order of entries the guest sees changes from run to run, which is surprising for embedders following the deterministic-execution guide.- Lifting deduplicates with last-wins semantics, which is where #14812 comes from.
For comparison, guest-side wit-bindgen has a
map_typeoption plus a smallWitMaptrait, withBTreeMapas the no_std-friendly default andHashMapavailable behindstd. Would something similar make sense here: impls forBTreeMapandHashMap<K, V, S>, an entries-preserving type for "just give me the list", and abindgen!option to pick between them?
alexcrichton added the wasm-proposal:component-model-map label to Issue #14832.
fitzgen closed issue #14832:
Today
map<K, V>can only be used through the typed API andbindgen!asHashMap<K, V>with the default hasher (std'sRandomState, or hashbrown's default hasher withoutstd). A few consequences:
- There's no support for
BTreeMap, custom hashers, or getting at the raw entries.Vec<(K, V)>doesn't work since it only typechecks againstlist.bindgen!has no way to choose the type (nomap_typeoption, andwithdoesn't apply to map aliases).additional_derives: [Hash](orOrd) fails for any record containing a map.- Lowering iterates a randomly-seeded
HashMap, so the order of entries the guest sees changes from run to run, which is surprising for embedders following the deterministic-execution guide.- Lifting deduplicates with last-wins semantics, which is where #14812 comes from.
For comparison, guest-side wit-bindgen has a
map_typeoption plus a smallWitMaptrait, withBTreeMapas the no_std-friendly default andHashMapavailable behindstd. Would something similar make sense here: impls forBTreeMapandHashMap<K, V, S>, an entries-preserving type for "just give me the list", and abindgen!option to pick between them?
Last updated: Oct 31 2026 at 23:03 UTC