Skip to content

Commit

Permalink
Sync with cargo/solana changes
Browse files Browse the repository at this point in the history
Make our implementation compatible with pubgrub-rs/pubgrub#298
  • Loading branch information
konstin committed Dec 16, 2024
1 parent 3d3738b commit 4131f45
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ petgraph = { version = "0.6.5" }
platform-info = { version = "2.0.3" }
proc-macro2 = { version = "1.0.86" }
procfs = { version = "0.17.0", default-features = false, features = ["flate2"] }
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "251e93bd42b9cf4705e633a2a95a137be4087358" }
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "05e8d12cea8d72c6d2d017900e478d0abd28fef4" }
quote = { version = "1.0.37" }
rayon = { version = "1.10.0" }
reflink-copy = { version = "0.1.19" }
Expand Down Expand Up @@ -175,7 +175,7 @@ unicode-width = { version = "0.1.13" }
unscanny = { version = "0.1.0" }
url = { version = "2.5.2", features = ["serde"] }
urlencoding = { version = "2.1.3" }
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "251e93bd42b9cf4705e633a2a95a137be4087358" }
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "05e8d12cea8d72c6d2d017900e478d0abd28fef4" }
walkdir = { version = "2.5.0" }
which = { version = "7.0.0", features = ["regex"] }
windows-registry = { version = "0.3.0" }
Expand Down
14 changes: 9 additions & 5 deletions crates/uv-resolver/src/dependency_provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::convert::Infallible;

use pubgrub::{Dependencies, DependencyProvider, Range};
use pubgrub::{Dependencies, DependencyProvider, PackageResolutionStatistics, Range};

use uv_pep440::Version;

Expand All @@ -17,13 +17,17 @@ impl DependencyProvider for UvDependencyProvider {
type V = Version;
type VS = Range<Version>;
type M = UnavailableReason;
type Priority = Option<PubGrubPriority>;
type Err = Infallible;

fn prioritize(&self, _package: &Self::P, _range: &Self::VS) -> Self::Priority {
fn prioritize(
&self,
_package: &Self::P,
_range: &Self::VS,
_stats: &PackageResolutionStatistics,
) -> Self::Priority {
unimplemented!()
}
type Priority = Option<PubGrubPriority>;

type Err = Infallible;

fn choose_version(
&self,
Expand Down
48 changes: 18 additions & 30 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use dashmap::DashMap;
use either::Either;
use futures::{FutureExt, StreamExt};
use itertools::Itertools;
use pubgrub::{Id, Incompatibility, Range, Ranges, State, Term};
use pubgrub::{Id, IncompId, Incompatibility, Range, Ranges, State};
use rustc_hash::{FxHashMap, FxHashSet};
use tokio::sync::mpsc::{self, Receiver, Sender};
use tokio::sync::oneshot;
Expand Down Expand Up @@ -328,17 +328,9 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
loop {
// Run unit propagation.
let result = state.pubgrub.unit_propagation(state.next);
// End the mutable borrow of `state.pubgrub`.
let result = result.map(|conflict| {
conflict.map(|conflict| {
conflict
.map(|(package, term)| (package, term.clone()))
.collect::<Vec<_>>()
})
});
match result {
Err(err) => {
// If unit propagation failed, the is no solution.
// If unit propagation failed, there is no solution.
return Err(self.convert_no_solution_err(
err,
state.fork_urls,
Expand All @@ -349,14 +341,13 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
&self.capabilities,
));
}
Ok(Some(conflict)) => {
// Conflict tracking: If the version was rejected due to its dependencies,
// record culprit and affected.
state.record_conflict(state.next, None, &conflict);
Ok(conflicts) => {
for (affected, incompatibility) in conflicts {
// Conflict tracking: If there was a conflict, track affected and
// culprit for all root cause incompatibilities
state.record_conflict(affected, None, incompatibility);
}
}
// There was no conflict, or we've already rejected the last version due to its
// dependencies.
Ok(None) => {}
}

// Pre-visit all candidate packages, to allow metadata to be fetched in parallel.
Expand Down Expand Up @@ -2351,14 +2342,11 @@ impl ForkState {
(package, version)
}),
);
// End the mutable borrow of `self.pubgrub`
let conflict: Option<Vec<_>> =
conflict.map(|x| x.map(|(package, term)| (package, term.clone())).collect());

// Conflict tracking: If the version was rejected due to its dependencies, record culprit
// and affected.
if let Some(conflict) = conflict {
self.record_conflict(for_package, Some(for_version), &conflict);
if let Some(incompatibility) = conflict {
self.record_conflict(for_package, Some(for_version), incompatibility);
}
Ok(())
}
Expand All @@ -2367,15 +2355,15 @@ impl ForkState {
&mut self,
affected: Id<PubGrubPackage>,
version: Option<&Version>,
conflict: &[(Id<PubGrubPackage>, Term<Ranges<Version>>)],
incompatibility: IncompId<PubGrubPackage, Ranges<Version>, UnavailableReason>,
) {
let mut culprit_is_real = false;
for (incompatible, _term) in conflict {
if *incompatible == affected {
for (incompatible, _term) in self.pubgrub.incompatibility_store[incompatibility].iter() {
if incompatible == affected {
continue;
}
if self.pubgrub.package_store[affected].name()
== self.pubgrub.package_store[*incompatible].name()
== self.pubgrub.package_store[incompatible].name()
{
// Don't track conflicts between a marker package and the main package, when the
// marker is "copying" the obligations from the main package through conflicts.
Expand All @@ -2385,21 +2373,21 @@ impl ForkState {
let culprit_count = self
.conflict_tracker
.culprit
.entry(*incompatible)
.entry(incompatible)
.or_default();
*culprit_count += 1;
if *culprit_count == CONFLICT_THRESHOLD {
self.conflict_tracker.depriotize.push(*incompatible);
self.conflict_tracker.depriotize.push(incompatible);
}
}
// Don't track conflicts between a marker package and the main package, when the
// marker is "copying" the obligations from the main package through conflicts.
if culprit_is_real {
if tracing::enabled!(Level::DEBUG) {
let incompatibility = conflict
let incompatibility = self.pubgrub.incompatibility_store[incompatibility]
.iter()
.map(|(package, _term)| {
format!("{:?}", self.pubgrub.package_store[*package].clone(),)
format!("{:?}", self.pubgrub.package_store[package].clone(),)
})
.join(", ");
if let Some(version) = version {
Expand Down

0 comments on commit 4131f45

Please sign in to comment.