From 4a1759813379c860b0c7c8aebaad996218f1015a Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Thu, 7 Sep 2023 14:36:12 +0200 Subject: [PATCH 1/2] feat: move name type to pool --- crates/rattler_libsolv_rs/src/lib.rs | 4 ---- crates/rattler_libsolv_rs/src/pool.rs | 19 ++++++++++--------- crates/rattler_libsolv_rs/src/solver/mod.rs | 15 +++++++-------- crates/rattler_solve/src/libsolv_rs/mod.rs | 1 - 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/crates/rattler_libsolv_rs/src/lib.rs b/crates/rattler_libsolv_rs/src/lib.rs index 307b93aed..d5b505001 100644 --- a/crates/rattler_libsolv_rs/src/lib.rs +++ b/crates/rattler_libsolv_rs/src/lib.rs @@ -34,10 +34,6 @@ pub use mapping::Mapping; /// Version is a name and a version specification. pub trait VersionTrait: Display { - /// The name of the package associated with this record. - /// TODO: Can we move this to the Pool? - type Name: Display + Sized + Hash + Eq + Clone; - /// The version associated with this record. type Version: Display + Ord + Clone; diff --git a/crates/rattler_libsolv_rs/src/pool.rs b/crates/rattler_libsolv_rs/src/pool.rs index f1c3b5f54..ab50d1dfc 100644 --- a/crates/rattler_libsolv_rs/src/pool.rs +++ b/crates/rattler_libsolv_rs/src/pool.rs @@ -1,6 +1,7 @@ use std::collections::hash_map::Entry; use std::collections::HashMap; use std::fmt::{Display, Formatter}; +use std::hash::Hash; use crate::arena::Arena; use crate::id::{NameId, RepoId, SolvableId, VersionSetId}; @@ -12,7 +13,7 @@ use crate::{VersionSet, VersionTrait}; /// /// Because it stores solvables, it contains references to `PackageRecord`s (the `'a` lifetime comes /// from the original `PackageRecord`s) -pub struct Pool { +pub struct Pool { /// All the solvables that have been registered pub(crate) solvables: Arena>, @@ -20,10 +21,10 @@ pub struct Pool { total_repos: u32, /// Interned package names - package_names: Arena::Name>, + package_names: Arena, /// Map from package names to the id of their interned counterpart - pub(crate) names_to_ids: HashMap<::Name, NameId>, + pub(crate) names_to_ids: HashMap, /// Map from interned package names to the solvables that have that name pub(crate) packages_by_name: Mapping>, @@ -41,7 +42,7 @@ pub struct Pool { pub(crate) match_spec_to_forbidden: Mapping>, } -impl Default for Pool { +impl Default for Pool { fn default() -> Self { let mut solvables = Arena::new(); solvables.alloc(Solvable::new_root()); @@ -62,7 +63,7 @@ impl Default for Pool { } } -impl Pool { +impl Pool { /// Creates a new [`Pool`] pub fn new() -> Self { Self::default() @@ -133,9 +134,9 @@ impl Pool { } /// Interns a package name into the `Pool`, returning its `NameId` - pub fn intern_package_name(&mut self, name: N) -> NameId + pub fn intern_package_name(&mut self, name: NValue) -> NameId where - N: Into<::Name>, + NValue: Into, { match self.names_to_ids.entry(name.into()) { Entry::Occupied(e) => *e.get(), @@ -152,14 +153,14 @@ impl Pool { } /// Lookup the package name id associated to the provided name - pub fn lookup_package_name(&self, name: &::Name) -> Option { + pub fn lookup_package_name(&self, name: &Name) -> Option { self.names_to_ids.get(name).copied() } /// Returns the package name associated to the provided id /// /// Panics if the package name is not found in the pool - pub fn resolve_package_name(&self, name_id: NameId) -> &::Name { + pub fn resolve_package_name(&self, name_id: NameId) -> &Name { &self.package_names[name_id] } diff --git a/crates/rattler_libsolv_rs/src/solver/mod.rs b/crates/rattler_libsolv_rs/src/solver/mod.rs index 42da248bc..5e06b152f 100644 --- a/crates/rattler_libsolv_rs/src/solver/mod.rs +++ b/crates/rattler_libsolv_rs/src/solver/mod.rs @@ -956,7 +956,6 @@ mod test { } impl VersionTrait for Pack { - type Name = String; type Version = u32; fn version(&self) -> Self::Version { @@ -974,7 +973,7 @@ mod test { } impl Nameable for Pack { - type Name = ::Name; + type Name = String; fn name(&self) -> &Self::Name { &self.0 } @@ -988,7 +987,7 @@ mod test { } impl Nameable for Spec { - type Name = <::V as VersionTrait>::Name; + type Name = String; fn name(&self) -> &String { &self.name } @@ -1080,8 +1079,8 @@ mod test { /// packages: packages and its dependencies to add to the pool fn pool(packages: &[(&str, Vec<&str>)]) -> Pool where - VS: VersionSet + Nameable::Name> + FromStr, - VS::V: FromStr + Nameable::Name>, + VS: VersionSet + Nameable + FromStr, + VS::V: FromStr + Nameable, ::Err: Debug, <::V as FromStr>::Err: Debug, { @@ -1099,8 +1098,8 @@ mod test { dependencies: &Vec<&str>, constrains: &Vec<&str>, ) where - VS: VersionSet + Nameable::Name> + FromStr, - VS::V: FromStr + Nameable::Name>, + VS: VersionSet + Nameable + FromStr, + VS::V: FromStr + Nameable, ::Err: Debug, <::V as FromStr>::Err: Debug, { @@ -1126,7 +1125,7 @@ mod test { } /// Install the given version sets - fn install::Name>>( + fn install>( pool: &mut Pool, version_sets: &[&str], ) -> SolveJobs diff --git a/crates/rattler_solve/src/libsolv_rs/mod.rs b/crates/rattler_solve/src/libsolv_rs/mod.rs index 9de187848..83268c6f1 100644 --- a/crates/rattler_solve/src/libsolv_rs/mod.rs +++ b/crates/rattler_solve/src/libsolv_rs/mod.rs @@ -147,7 +147,6 @@ impl<'a> Display for SolverPackageRecord<'a> { } impl<'a> VersionTrait for SolverPackageRecord<'a> { - type Name = String; type Version = rattler_conda_types::Version; fn version(&self) -> Self::Version { From 09ecf32b876ae804d4abc5364b42df66c93cfc1b Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Thu, 7 Sep 2023 15:19:57 +0200 Subject: [PATCH 2/2] fix: removed unused import --- crates/rattler_libsolv_rs/src/pool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rattler_libsolv_rs/src/pool.rs b/crates/rattler_libsolv_rs/src/pool.rs index ab50d1dfc..b3248d447 100644 --- a/crates/rattler_libsolv_rs/src/pool.rs +++ b/crates/rattler_libsolv_rs/src/pool.rs @@ -7,7 +7,7 @@ use crate::arena::Arena; use crate::id::{NameId, RepoId, SolvableId, VersionSetId}; use crate::mapping::Mapping; use crate::solvable::{PackageSolvable, Solvable}; -use crate::{VersionSet, VersionTrait}; +use crate::VersionSet; /// A pool that stores data related to the available packages ///