Skip to content

Typed map<K, V> support is limited to HashMap with the default hasher #14832

Open

Description

@jrandolf

Today map<K, V> can only be used through the typed API and bindgen! as HashMap<K, V> with the default hasher (std's RandomState, or hashbrown's default hasher without std). 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 against list.
  • bindgen! has no way to choose the type (no map_type option, and with doesn't apply to map aliases).
  • additional_derives: [Hash] (or Ord) 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 Duplicate keys in map<K, V> leak handles #14812 comes from.

For comparison, guest-side wit-bindgen has a map_type option plus a small WitMap trait, with BTreeMap as the no_std-friendly default and HashMap available behind std. Would something similar make sense here: impls for BTreeMap and HashMap<K, V, S>, an entries-preserving type for "just give me the list", and a bindgen! option to pick between them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions