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

Try the async version of resolvo #504

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["crates/*"]
resolver = "2"

# See: https://docs.rs/insta/latest/insta/#optional-faster-runs
[profile.dev.package.insta]
Expand Down Expand Up @@ -144,3 +145,6 @@ walkdir = "2.4.0"
windows-sys = { version = "0.52.0", default-features = false }
zip = { version = "0.6.6", default-features = false }
zstd = { version = "0.13.0", default-features = false }

[patch.crates-io]
resolvo = { git = "https://github.com/baszalmstra/resolvo.git", branch = "refactor/concurrent-metadata-fetch" }
3 changes: 3 additions & 0 deletions crates/rattler_solve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ hex = { workspace = true }
tempfile = { workspace = true }
rattler_libsolv_c = { workspace = true, optional = true }
resolvo = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
futures = { workspace = true, optional = true }

[dev-dependencies]
criterion = { workspace = true }
Expand All @@ -41,6 +43,7 @@ url = { workspace = true }
[features]
default = ["libsolv_c"]
libsolv_c = ["rattler_libsolv_c", "libc"]
resolvo = ["dep:resolvo", "dep:tokio", "dep:futures"]

[[bench]]
name = "bench"
Expand Down
23 changes: 18 additions & 5 deletions crates/rattler_solve/src/resolvo/conda_util.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::resolvo::{CondaDependencyProvider, SolverMatchSpec};
use futures::future::FutureExt;
use rattler_conda_types::Version;
use resolvo::{Dependencies, SolvableId, SolverCache, VersionSetId};
use std::cmp::Ordering;
use std::collections::HashMap;

/// Returns the order of two candidates based on the order used by conda.
#[allow(clippy::too_many_arguments)]
pub(super) fn compare_candidates<'a>(
Expand Down Expand Up @@ -47,11 +47,19 @@
Ordering::Equal => {}
};

// return Ordering::Equal;

// Otherwise, compare the dependencies of the variants. If there are similar
// dependencies select the variant that selects the highest version of the dependency.
let (a_dependencies, b_dependencies) = match (
solver.get_or_cache_dependencies(a),
solver.get_or_cache_dependencies(b),
solver
.get_or_cache_dependencies(a)
.now_or_never()

Check failure on line 57 in crates/rattler_solve/src/resolvo/conda_util.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

the method `now_or_never` exists for enum `Result<&Dependencies, Box<dyn Any>>`, but its trait bounds were not satisfied
.expect("get_or_cache_dependencies failed"),
solver
.get_or_cache_dependencies(b)
.now_or_never()

Check failure on line 61 in crates/rattler_solve/src/resolvo/conda_util.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

the method `now_or_never` exists for enum `Result<&Dependencies, Box<dyn Any>>`, but its trait bounds were not satisfied
.expect("get_or_cache_dependencies failed"),
) {
(Ok(a_deps), Ok(b_deps)) => (a_deps, b_deps),
// If either call fails, it's likely due to solver cancellation; thus, we can't compare dependencies
Expand Down Expand Up @@ -147,7 +155,10 @@
match_spec_highest_version
.entry(match_spec_id)
.or_insert_with(|| {
let candidates = solver.get_or_cache_matching_candidates(match_spec_id);
let candidates = solver
.get_or_cache_matching_candidates(match_spec_id)
.now_or_never()

Check failure on line 160 in crates/rattler_solve/src/resolvo/conda_util.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

the method `now_or_never` exists for enum `Result<&[SolvableId], Box<dyn Any>>`, but its trait bounds were not satisfied
.expect("get_or_cache_matching_candidates failed");

// Err only happens on cancellation, so we will not continue anyways
let candidates = if let Ok(candidates) = candidates {
Expand All @@ -156,9 +167,11 @@
return None;
};

let pool = solver.pool();

candidates
.iter()
.map(|id| solver.pool().resolve_solvable(*id).inner())
.map(|id| pool.resolve_solvable(*id).inner())
.fold(None, |init, record| {
Some(init.map_or_else(
|| {
Expand Down
25 changes: 15 additions & 10 deletions crates/rattler_solve/src/resolvo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SolvableId, Solver as LibSolvRsSolver, SolverCache, UnsolvableOrCancelled, VersionSet,
VersionSetId,
};
use std::rc::Rc;
use std::{
cell::RefCell,
cmp::Ordering,
Expand Down Expand Up @@ -157,7 +158,7 @@
/// Dependency provider for conda
#[derive(Default)]
pub(crate) struct CondaDependencyProvider<'a> {
pool: Pool<SolverMatchSpec<'a>, String>,
pool: Rc<Pool<SolverMatchSpec<'a>, String>>,

records: HashMap<NameId, Candidates>,

Expand All @@ -178,7 +179,7 @@
match_specs: &[MatchSpec],
stop_time: Option<std::time::SystemTime>,
) -> Self {
let pool = Pool::default();
let pool = Rc::new(Pool::default());
let mut records: HashMap<NameId, Candidates> = HashMap::default();

// Add virtual packages to the records
Expand Down Expand Up @@ -348,11 +349,11 @@
}

impl<'a> DependencyProvider<SolverMatchSpec<'a>> for CondaDependencyProvider<'a> {
fn pool(&self) -> &Pool<SolverMatchSpec<'a>, String> {
&self.pool
fn pool(&self) -> Rc<Pool<SolverMatchSpec<'a>, String>> {

Check failure on line 352 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

method `pool` has an incompatible type for trait
self.pool.clone()
}

fn sort_candidates(
async fn sort_candidates(

Check failure on line 356 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

method `sort_candidates` has an incompatible type for trait
&self,
solver: &SolverCache<SolverMatchSpec<'a>, String, Self>,
solvables: &mut [SolvableId],
Expand All @@ -363,11 +364,11 @@
});
}

fn get_candidates(&self, name: NameId) -> Option<Candidates> {
async fn get_candidates(&self, name: NameId) -> Option<Candidates> {

Check failure on line 367 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

method `get_candidates` has an incompatible type for trait
self.records.get(&name).cloned()
}

fn get_dependencies(&self, solvable: SolvableId) -> Dependencies {
async fn get_dependencies(&self, solvable: SolvableId) -> Dependencies {

Check failure on line 371 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

method `get_dependencies` has an incompatible type for trait
let mut dependencies = KnownDependencies::default();
let SolverPackageRecord::Record(rec) = self.pool.resolve_solvable(solvable).inner() else {
return Dependencies::Known(dependencies);
Expand Down Expand Up @@ -433,6 +434,9 @@
&mut self,
task: SolverTask<TAvailablePackagesIterator>,
) -> Result<Vec<RepoDataRecord>, SolveError> {
let runtime = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
let stop_time = task
.timeout
.map(|timeout| std::time::SystemTime::now() + timeout);
Expand All @@ -446,6 +450,7 @@
task.specs.clone().as_ref(),
stop_time,
);
let pool = provider.pool.clone();

// Construct the requirements that the solver needs to satisfy.
let root_requirements = task
Expand All @@ -460,14 +465,14 @@
.collect();

// Construct a solver and solve the problems in the queue
let mut solver = LibSolvRsSolver::new(provider);
let mut solver = LibSolvRsSolver::new(provider, runtime);

Check failure on line 468 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

this function takes 1 argument but 2 arguments were supplied

Check failure on line 468 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Check intra-doc links

this function takes 1 argument but 2 arguments were supplied
let solvables = solver
.solve(root_requirements)
.map_err(|unsolvable_or_cancelled| {
match unsolvable_or_cancelled {
UnsolvableOrCancelled::Unsolvable(problem) => {
SolveError::Unsolvable(vec![problem
.display_user_friendly(&solver, &CondaSolvableDisplay)
.display_user_friendly(&solver, pool, &CondaSolvableDisplay)

Check failure on line 475 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

this method takes 2 arguments but 3 arguments were supplied
.to_string()])
}
// We are not doing this as of yet
Expand All @@ -479,7 +484,7 @@
// Get the resulting packages from the solver.
let required_records = solvables
.into_iter()
.filter_map(|id| match *solver.pool().resolve_solvable(id).inner() {
.filter_map(|id| match *solver.pool.resolve_solvable(id).inner() {

Check failure on line 487 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

attempted to take value of method `pool` on type `resolvo::Solver<SolverMatchSpec<'_>, String, CondaDependencyProvider<'_>>`
SolverPackageRecord::Record(rec) => Some(rec.clone()),
SolverPackageRecord::VirtualPackage(_) => None,
})
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.70.0
1.75.0
Loading