From d6d56e1e6194df172f1ddbedfbef1af64a180ef4 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Fri, 8 Sep 2023 13:58:55 +0200 Subject: [PATCH] refactor: remove repo from pool --- crates/rattler_libsolv_rs/src/id.rs | 11 ----------- crates/rattler_libsolv_rs/src/lib.rs | 2 +- crates/rattler_libsolv_rs/src/pool.rs | 19 +++---------------- crates/rattler_libsolv_rs/src/solvable.rs | 11 ++--------- crates/rattler_libsolv_rs/src/solver/mod.rs | 4 ++-- crates/rattler_solve/src/libsolv_rs/input.rs | 8 ++------ crates/rattler_solve/src/libsolv_rs/mod.rs | 9 +-------- 7 files changed, 11 insertions(+), 53 deletions(-) diff --git a/crates/rattler_libsolv_rs/src/id.rs b/crates/rattler_libsolv_rs/src/id.rs index b3a552c1f..cf00f4960 100644 --- a/crates/rattler_libsolv_rs/src/id.rs +++ b/crates/rattler_libsolv_rs/src/id.rs @@ -1,16 +1,5 @@ use crate::arena::ArenaId; -/// The id associated to a libsolv repo -#[repr(transparent)] -#[derive(Clone, Copy, Eq, PartialEq, Hash)] -pub struct RepoId(u32); - -impl RepoId { - pub(crate) fn new(id: u32) -> Self { - Self(id) - } -} - /// The id associated to a package name #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/crates/rattler_libsolv_rs/src/lib.rs b/crates/rattler_libsolv_rs/src/lib.rs index 5869ada4c..7df56c157 100644 --- a/crates/rattler_libsolv_rs/src/lib.rs +++ b/crates/rattler_libsolv_rs/src/lib.rs @@ -20,7 +20,7 @@ mod solve_jobs; mod solver; mod transaction; -pub use id::{NameId, RepoId, SolvableId, VersionSetId}; +pub use id::{NameId, SolvableId, VersionSetId}; pub use pool::Pool; pub use solvable::PackageSolvable; pub use solve_jobs::SolveJobs; diff --git a/crates/rattler_libsolv_rs/src/pool.rs b/crates/rattler_libsolv_rs/src/pool.rs index 0d6ff6a2d..4fecb83a1 100644 --- a/crates/rattler_libsolv_rs/src/pool.rs +++ b/crates/rattler_libsolv_rs/src/pool.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::fmt::{Display, Formatter}; use crate::arena::Arena; -use crate::id::{NameId, RepoId, SolvableId, VersionSetId}; +use crate::id::{NameId, SolvableId, VersionSetId}; use crate::mapping::Mapping; use crate::solvable::{PackageSolvable, Solvable}; use crate::{PackageName, VersionSet}; @@ -16,9 +16,6 @@ pub struct Pool { /// All the solvables that have been registered pub(crate) solvables: Arena>, - /// The total amount of registered repos - total_repos: u32, - /// Interned package names package_names: Arena, @@ -48,7 +45,6 @@ impl Default for Pool { Self { solvables, - total_repos: 0, names_to_ids: Default::default(), package_names: Arena::new(), @@ -68,20 +64,11 @@ impl Pool { Self::default() } - /// Registers a new repo (i.e. a source of packages) - pub fn new_repo(&mut self) -> RepoId { - let id = RepoId::new(self.total_repos); - self.total_repos += 1; - id - } - /// Adds a package to a repo and returns it's [`SolvableId`] - pub fn add_package(&mut self, repo_id: RepoId, name_id: NameId, record: VS::V) -> SolvableId { + pub fn add_package(&mut self, name_id: NameId, record: VS::V) -> SolvableId { assert!(self.solvables.len() <= u32::MAX as usize); - let solvable_id = self - .solvables - .alloc(Solvable::new_package(repo_id, name_id, record)); + let solvable_id = self.solvables.alloc(Solvable::new_package(name_id, record)); self.packages_by_name[name_id].push(solvable_id); diff --git a/crates/rattler_libsolv_rs/src/solvable.rs b/crates/rattler_libsolv_rs/src/solvable.rs index 51d7a890d..249493969 100644 --- a/crates/rattler_libsolv_rs/src/solvable.rs +++ b/crates/rattler_libsolv_rs/src/solvable.rs @@ -1,5 +1,5 @@ +use crate::id::NameId; use crate::id::VersionSetId; -use crate::id::{NameId, RepoId}; use std::fmt::{Display, Formatter}; @@ -8,7 +8,6 @@ use std::fmt::{Display, Formatter}; /// Contains a reference to the `PackageRecord` that corresponds to the solvable (the `'a` lifetime /// comes from the original `PackageRecord`) pub struct PackageSolvable { - pub(crate) repo_id: RepoId, pub(crate) dependencies: Vec, pub(crate) constrains: Vec, pub(crate) inner: V, @@ -16,11 +15,6 @@ pub struct PackageSolvable { } impl PackageSolvable { - /// Returns the [`RepoId`] associated to this solvable - pub fn repo_id(&self) -> RepoId { - self.repo_id - } - /// Gets the record associated to this solvable pub fn inner(&self) -> &V { &self.inner @@ -60,10 +54,9 @@ impl Solvable { } } - pub(crate) fn new_package(repo_id: RepoId, name: NameId, record: V) -> Self { + pub(crate) fn new_package(name: NameId, record: V) -> Self { Self { inner: SolvableInner::Package(PackageSolvable { - repo_id, inner: record, name, dependencies: Vec::new(), diff --git a/crates/rattler_libsolv_rs/src/solver/mod.rs b/crates/rattler_libsolv_rs/src/solver/mod.rs index bce95a054..402329d1e 100644 --- a/crates/rattler_libsolv_rs/src/solver/mod.rs +++ b/crates/rattler_libsolv_rs/src/solver/mod.rs @@ -924,7 +924,7 @@ impl> Sol mod test { use super::*; use crate::solvable::Solvable; - use crate::{id::RepoId, VersionTrait}; + use crate::VersionTrait; use std::fmt::{Debug, Display, Formatter}; use std::ops::Range; use std::str::FromStr; @@ -1102,7 +1102,7 @@ mod test { // Add the package let version = package_version; let name_id = pool.intern_package_name(package_name); - let package_id = pool.add_package(RepoId::new(0), name_id, version); + let package_id = pool.add_package(name_id, version); // And its the dependencies for dep in dependencies { diff --git a/crates/rattler_solve/src/libsolv_rs/input.rs b/crates/rattler_solve/src/libsolv_rs/input.rs index 3ff14d8f6..5b8d724e3 100644 --- a/crates/rattler_solve/src/libsolv_rs/input.rs +++ b/crates/rattler_solve/src/libsolv_rs/input.rs @@ -5,7 +5,7 @@ use crate::libsolv_rs::{SolverMatchSpec, SolverPackageRecord}; use rattler_conda_types::package::ArchiveType; use rattler_conda_types::{GenericVirtualPackage, RepoDataRecord}; use rattler_conda_types::{MatchSpec, NamelessMatchSpec, ParseMatchSpecError}; -use rattler_libsolv_rs::{Pool, RepoId, SolvableId, VersionSetId}; +use rattler_libsolv_rs::{Pool, SolvableId, VersionSetId}; use std::cmp::Ordering; use std::collections::HashMap; use std::str::FromStr; @@ -18,7 +18,6 @@ use std::str::FromStr; /// Panics if the repo does not belong to the pool pub(super) fn add_repodata_records<'a>( pool: &mut Pool>, - repo_id: RepoId, repo_datas: impl IntoIterator, parse_match_spec_cache: &mut HashMap, ) -> Result, ParseMatchSpecError> { @@ -62,8 +61,7 @@ pub(super) fn add_repodata_records<'a>( // Add the package to the pool let name_id = pool.intern_package_name(record.name.as_normalized()); - let solvable_id = - pool.add_package(repo_id, name_id, SolverPackageRecord::Record(repo_data)); + let solvable_id = pool.add_package(name_id, SolverPackageRecord::Record(repo_data)); // Dependencies for match_spec_str in record.depends.iter() { @@ -83,13 +81,11 @@ pub(super) fn add_repodata_records<'a>( pub(super) fn add_virtual_packages<'a>( pool: &mut Pool>, - repo_id: RepoId, packages: &'a [GenericVirtualPackage], ) { for package in packages { let package_name_id = pool.intern_package_name(package.name.as_normalized()); pool.add_package( - repo_id, package_name_id, SolverPackageRecord::VirtualPackage(package), ); diff --git a/crates/rattler_solve/src/libsolv_rs/mod.rs b/crates/rattler_solve/src/libsolv_rs/mod.rs index b50dad2e7..b904b0b12 100644 --- a/crates/rattler_solve/src/libsolv_rs/mod.rs +++ b/crates/rattler_solve/src/libsolv_rs/mod.rs @@ -213,8 +213,7 @@ impl super::SolverImpl for Solver { let mut parse_match_spec_cache = HashMap::new(); // Add virtual packages - let repo_id = pool.new_repo(); - add_virtual_packages(&mut pool, repo_id, &task.virtual_packages); + add_virtual_packages(&mut pool, &task.virtual_packages); // Create repos for all channel + platform combinations for repodata in task.available_packages.into_iter().map(IntoRepoData::into) { @@ -222,29 +221,23 @@ impl super::SolverImpl for Solver { continue; } - let repo_id = pool.new_repo(); add_repodata_records( &mut pool, - repo_id, repodata.records.iter().copied(), &mut parse_match_spec_cache, )?; } // Create a special pool for records that are already installed or locked. - let repo_id = pool.new_repo(); let installed_solvables = add_repodata_records( &mut pool, - repo_id, &task.locked_packages, &mut parse_match_spec_cache, )?; // Create a special pool for records that are pinned and cannot be changed. - let repo_id = pool.new_repo(); let pinned_solvables = add_repodata_records( &mut pool, - repo_id, &task.pinned_packages, &mut parse_match_spec_cache, )?;