From ae1aa6540761e54a76b8f7984cf93cd3a0d011d0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 3 May 2026 11:55:03 +0900 Subject: refactor: switch internal maps/sets from HashMap to IndexMap Adopt indexmap workspace-wide so iteration order is deterministic and follows insertion order. The non-deterministic order of std HashMap otherwise leaks into resolver decisions when multiple valid solutions exist (e.g. cyclic require pairs under prefer-lowest), making behavior flaky and divergent from Composer's PHP-array semantics. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/mozart-sat-resolver/src/pool.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/mozart-sat-resolver/src/pool.rs') diff --git a/crates/mozart-sat-resolver/src/pool.rs b/crates/mozart-sat-resolver/src/pool.rs index 0312c24..9268675 100644 --- a/crates/mozart-sat-resolver/src/pool.rs +++ b/crates/mozart-sat-resolver/src/pool.rs @@ -1,5 +1,5 @@ +use indexmap::IndexMap; use mozart_semver::VersionConstraint; -use std::collections::HashMap; use std::fmt; /// Unique identifier for a package in the pool. 1-based. @@ -122,9 +122,9 @@ pub struct Pool { /// All packages, indexed by (id - 1). packages: Vec, /// Index: package name → list of package IDs providing that name. - package_by_name: HashMap>, + package_by_name: IndexMap>, /// Cache for what_provides results. - provider_cache: HashMap<(String, String), Vec>, + provider_cache: IndexMap<(String, String), Vec>, /// Packages that are fixed/locked but unacceptable (e.g. failed stability). unacceptable_fixed_packages: Vec, } @@ -133,7 +133,7 @@ impl Pool { /// Create a new pool from a list of package inputs. pub fn new(inputs: Vec, unacceptable_fixed_ids: Vec) -> Self { let mut packages: Vec = Vec::with_capacity(inputs.len()); - let mut package_by_name: HashMap> = HashMap::new(); + let mut package_by_name: IndexMap> = IndexMap::new(); // Collect alias links (alias_idx, target_name, target_normalized) for // a second pass once every input has a stable ID. let mut pending_aliases: Vec<(usize, String, String)> = Vec::new(); @@ -189,7 +189,7 @@ impl Pool { Pool { packages, package_by_name, - provider_cache: HashMap::new(), + provider_cache: IndexMap::new(), unacceptable_fixed_packages: unacceptable_fixed_ids, } } -- cgit v1.3.1