From fe28b2c278543bd897fa2bba9f6e935641c49b64 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 22 May 2024 14:48:44 -0400 Subject: [PATCH] Remove unused methods from `Resolution` (#3754) --- Cargo.lock | 1 - crates/distribution-types/Cargo.toml | 1 - crates/distribution-types/src/resolution.rs | 22 +++++---------------- crates/uv-dispatch/src/lib.rs | 4 +++- crates/uv-resolver/src/lock.rs | 4 ++-- crates/uv/src/commands/pip/operations.rs | 1 - crates/uv/src/commands/project/mod.rs | 2 +- 7 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 383cba0e9bdd..624f87b56e22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1111,7 +1111,6 @@ dependencies = [ "platform-tags", "pypi-types", "rkyv", - "rustc-hash", "schemars", "serde", "serde_json", diff --git a/crates/distribution-types/Cargo.toml b/crates/distribution-types/Cargo.toml index a91262b28322..9e0bde4d9153 100644 --- a/crates/distribution-types/Cargo.toml +++ b/crates/distribution-types/Cargo.toml @@ -30,7 +30,6 @@ indexmap = { workspace = true } itertools = { workspace = true } once_cell = { workspace = true } rkyv = { workspace = true } -rustc-hash = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/distribution-types/src/resolution.rs b/crates/distribution-types/src/resolution.rs index c05604aab4ec..c47339bbd1a7 100644 --- a/crates/distribution-types/src/resolution.rs +++ b/crates/distribution-types/src/resolution.rs @@ -1,4 +1,4 @@ -use rustc_hash::FxHashMap; +use std::collections::BTreeMap; use pep508_rs::VerbatimUrl; use uv_normalize::PackageName; @@ -10,19 +10,14 @@ use crate::{ /// A set of packages pinned at specific versions. #[derive(Debug, Default, Clone)] -pub struct Resolution(FxHashMap); +pub struct Resolution(BTreeMap); impl Resolution { /// Create a new resolution from the given pinned packages. - pub fn new(packages: FxHashMap) -> Self { + pub fn new(packages: BTreeMap) -> Self { Self(packages) } - /// Return the distribution for the given package name, if it exists. - pub fn get(&self, package_name: &PackageName) -> Option<&ResolvedDist> { - self.0.get(package_name) - } - /// Return the remote distribution for the given package name, if it exists. pub fn get_remote(&self, package_name: &PackageName) -> Option<&Dist> { match self.0.get(package_name) { @@ -44,11 +39,6 @@ impl Resolution { self.0.values() } - /// Iterate over the [`ResolvedDist`] entities in this resolution. - pub fn into_distributions(self) -> impl Iterator { - self.0.into_values() - } - /// Return the number of distributions in this resolution. pub fn len(&self) -> usize { self.0.len() @@ -60,10 +50,8 @@ impl Resolution { } /// Return the set of [`Requirement`]s that this resolution represents. - pub fn requirements(&self) -> Vec { - let mut requirements: Vec<_> = self.0.values().map(Requirement::from).collect(); - requirements.sort_unstable_by(|a, b| a.name.cmp(&b.name)); - requirements + pub fn requirements(&self) -> impl Iterator + '_ { + self.0.values().map(Requirement::from) } /// Return an iterator over the [`LocalEditable`] entities in this resolution. diff --git a/crates/uv-dispatch/src/lib.rs b/crates/uv-dispatch/src/lib.rs index 37d2d74c9c75..7304b17fe20a 100644 --- a/crates/uv-dispatch/src/lib.rs +++ b/crates/uv-dispatch/src/lib.rs @@ -192,12 +192,14 @@ impl<'a> BuildContext for BuildDispatch<'a> { // Determine the set of installed packages. let site_packages = SitePackages::from_executable(venv)?; + let requirements = resolution.requirements().collect::>(); + let Plan { cached, remote, reinstalls, extraneous: _, - } = Planner::with_requirements(&resolution.requirements()).build( + } = Planner::with_requirements(&requirements).build( site_packages, &Reinstall::None, &NoBinary::None, diff --git a/crates/uv-resolver/src/lock.rs b/crates/uv-resolver/src/lock.rs index d97b25bf03b7..8c70634990e9 100644 --- a/crates/uv-resolver/src/lock.rs +++ b/crates/uv-resolver/src/lock.rs @@ -2,7 +2,7 @@ // as we build out universal locking. #![allow(dead_code, unreachable_code, unused_variables)] -use std::collections::VecDeque; +use std::collections::{BTreeMap, VecDeque}; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -71,7 +71,7 @@ impl Lock { let mut queue: VecDeque<&Distribution> = VecDeque::new(); queue.push_back(root); - let mut map = FxHashMap::default(); + let mut map = BTreeMap::default(); while let Some(dist) = queue.pop_front() { for dep in &dist.dependencies { let dep_dist = self.find_by_id(&dep.id); diff --git a/crates/uv/src/commands/pip/operations.rs b/crates/uv/src/commands/pip/operations.rs index 895bc1e3324d..a0a69cad3515 100644 --- a/crates/uv/src/commands/pip/operations.rs +++ b/crates/uv/src/commands/pip/operations.rs @@ -296,7 +296,6 @@ pub(crate) async fn install( // despite not being explicitly requested. let requirements = resolution .requirements() - .into_iter() .filter(|requirement| { if requirement.source.is_editable() { !editables diff --git a/crates/uv/src/commands/project/mod.rs b/crates/uv/src/commands/project/mod.rs index c25f17933555..ca1202975270 100644 --- a/crates/uv/src/commands/project/mod.rs +++ b/crates/uv/src/commands/project/mod.rs @@ -285,7 +285,7 @@ pub(crate) async fn install( ) -> Result<(), Error> { let start = std::time::Instant::now(); - let requirements = resolution.requirements(); + let requirements = resolution.requirements().collect::>(); // Partition into those that should be linked from the cache (`local`), those that need to be // downloaded (`remote`), and those that should be removed (`extraneous`).