Skip to content

Hash trait and non-string Map keys #53

Description

@brianp

Re-filing the unfinished half of #16, which was closed when Set shipped — the Hash side never happened.

Current state (verified Aug 2026)

  • The runtime Map is a linear-scan, string-keyed assoc array (codegen/src/runtime/map.rs — keys are heap string pointers compared by content).
  • Set and Map keys are gated on Eq rather than the designed invisible-Hash-from-Eq model (protocols RFC: "Hash is not a protocol — it's an invisible consequence of Eq").
  • No Map[K,V] requires K includes Eq constraint is enforced on map literals — only key-type homogeneity (typecheck/src/check_expr.rs:185-215).
  • User-defined types cannot be Map/Set keys.

Scope

  1. Implicit hash derivation for Eq types (field-wise, matching the auto-derive pattern used for eq/cmp synthesis).
  2. Hash-based Map/Set runtime (replacing linear scan) with user-type and non-string key support.
  3. The key-constraint check on literals and constructors.

Tracked on the docs Roadmap page (Language section). Related history: #16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenJIT, AOT, FIR lowering, runtimegapSpecced or planned but not yet implementedmediumShould get done, not urgentrfcTied to a specific RFC or design docstdlibStandard library modules and builtinstype-systemType checker, inference, generics, traits

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions