Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove repo from pool #324

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions crates/rattler_libsolv_rs/src/id.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_libsolv_rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 3 additions & 16 deletions crates/rattler_libsolv_rs/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -16,9 +16,6 @@ pub struct Pool<VS: VersionSet, N: PackageName = String> {
/// All the solvables that have been registered
pub(crate) solvables: Arena<SolvableId, Solvable<VS::V>>,

/// The total amount of registered repos
total_repos: u32,

/// Interned package names
package_names: Arena<NameId, N>,

Expand Down Expand Up @@ -48,7 +45,6 @@ impl<VS: VersionSet, N: PackageName> Default for Pool<VS, N> {

Self {
solvables,
total_repos: 0,

names_to_ids: Default::default(),
package_names: Arena::new(),
Expand All @@ -68,20 +64,11 @@ impl<VS: VersionSet, N: PackageName> Pool<VS, N> {
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);

Expand Down
11 changes: 2 additions & 9 deletions crates/rattler_libsolv_rs/src/solvable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::id::NameId;
use crate::id::VersionSetId;
use crate::id::{NameId, RepoId};

use std::fmt::{Display, Formatter};

Expand All @@ -8,19 +8,13 @@ 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<V> {
pub(crate) repo_id: RepoId,
pub(crate) dependencies: Vec<VersionSetId>,
pub(crate) constrains: Vec<VersionSetId>,
pub(crate) inner: V,
pub(crate) name: NameId,
}

impl<V> PackageSolvable<V> {
/// 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
Expand Down Expand Up @@ -60,10 +54,9 @@ impl<V> Solvable<V> {
}
}

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(),
Expand Down
4 changes: 2 additions & 2 deletions crates/rattler_libsolv_rs/src/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ impl<VS: VersionSet, N: PackageName + Display, D: DependencyProvider<VS, N>> 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;
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions crates/rattler_solve/src/libsolv_rs/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SolverMatchSpec<'a>>,
repo_id: RepoId,
repo_datas: impl IntoIterator<Item = &'a RepoDataRecord>,
parse_match_spec_cache: &mut HashMap<String, VersionSetId>,
) -> Result<Vec<SolvableId>, ParseMatchSpecError> {
Expand Down Expand Up @@ -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() {
Expand All @@ -83,13 +81,11 @@ pub(super) fn add_repodata_records<'a>(

pub(super) fn add_virtual_packages<'a>(
pool: &mut Pool<SolverMatchSpec<'a>>,
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),
);
Expand Down
9 changes: 1 addition & 8 deletions crates/rattler_solve/src/libsolv_rs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,38 +213,31 @@ 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) {
if repodata.records.is_empty() {
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,
)?;
Expand Down