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/src/commands/install.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/mozart/src/commands/install.rs') diff --git a/crates/mozart/src/commands/install.rs b/crates/mozart/src/commands/install.rs index 9555ba7..b38194e 100644 --- a/crates/mozart/src/commands/install.rs +++ b/crates/mozart/src/commands/install.rs @@ -1,4 +1,5 @@ use clap::Args; +use indexmap::IndexSet; use mozart_core::console; use mozart_core::console_format; use mozart_registry::installed; @@ -6,7 +7,7 @@ use mozart_registry::installer_executor::{ ExecuteContext, FilesystemExecutor, InstallerExecutor, PackageOperation, }; use mozart_registry::lockfile; -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; use std::path::{Path, PathBuf}; #[derive(Args)] @@ -198,7 +199,7 @@ pub fn compute_operations<'a>( } // Compute removals: packages in installed but not in locked - let locked_names: HashSet = locked.iter().map(|p| p.name.to_lowercase()).collect(); + let locked_names: IndexSet = locked.iter().map(|p| p.name.to_lowercase()).collect(); let removals: Vec = installed .packages @@ -254,7 +255,7 @@ fn topological_sort<'a>( // Identify root packages: those not pulled in by any other package's // requires (counting provides/replaces as a match). - let mut required_by_others: HashSet = HashSet::new(); + let mut required_by_others: IndexSet = IndexSet::new(); for pkg in &sorted { let pkg_lower = pkg.name.to_lowercase(); for dep in pkg.require.keys() { @@ -276,8 +277,8 @@ fn topological_sort<'a>( .copied() .collect(); - let mut visited: HashSet = HashSet::new(); - let mut processed: HashSet = HashSet::new(); + let mut visited: IndexSet = IndexSet::new(); + let mut processed: IndexSet = IndexSet::new(); let mut ordered: Vec<&'a lockfile::LockedPackage> = Vec::with_capacity(packages.len()); while let Some(pkg) = stack.pop() { @@ -444,7 +445,7 @@ fn check_platform_requirements_against( return Vec::new(); } - let ignored: HashSet = ignore_platform_req + let ignored: IndexSet = ignore_platform_req .iter() .map(|s| s.to_lowercase()) .collect(); @@ -503,7 +504,7 @@ fn warn_platform_requirements( return; } - let ignored_set: HashSet = ignore_platform_req + let ignored_set: IndexSet = ignore_platform_req .iter() .map(|s| s.to_lowercase()) .collect(); -- cgit v1.3.1