Skip to content

Back ordered dictionaries [K: V] with IndexMap (codegen + lifting) #44

Description

@antoniusnaumann

Spec (Galvan by Example)

  • collections/index.md: [K: V] (ordered dictionary) maps to IndexMap<K, V> — the "currently BTreeMap" caveat was removed.
  • interop/liftings.md: Rust IndexMap<K, V> lifts to [K: V]; BTreeMap is no longer in the lifting table.

Ordered = insertion order (IndexMap), not key order (BTreeMap).

Current behavior

  • Codegen emits ::std::collections::BTreeMap for both the type (galvan-transpiler/src/transpile_item/type.rs:17-22) and literals (codegen/expression.rs:738-739); indexmap is not a dependency anywhere.
  • Lifting is inverted vs the book: classify_wrapper lifts BTreeMap → ordered dict and leaves IndexMap nominal (galvan-rustdoc/src/interop/lift_wrappers.rs:150-174).

Implementation sketch

  • Add indexmap to the runtime crate (root Cargo.toml) and re-export from src/std/mod.rs
  • Type lowering → ::galvan::std::IndexMap<K, V>; literal lowering → ::galvan::std::IndexMap::from([...])
  • Lifting swap in lift_wrappers.rs: indexmap::IndexMap (path-aware, like the std checks) → ordered dict; BTreeMap falls through to a nominal imported type
  • Update galvan-rustdoc/LIFTINGS.md (the authoritative contract) and its tests

Watch out

Iteration order changes from sorted to insertion order — audit existing ordered-dict e2e tests/examples for implicit sorted-order assumptions.

Docs

Remove the BTreeMap [!WARNING] in collections/ordered_dictionaries.md and regenerate its Generated Rust blocks.

Part of aligning the implementation with the Galvan by Example book (the book is the spec).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrust-interopRustdoc-backed Rust interop feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions