Skip to content

Commit e8cf62e

Browse files
committed
Sync with cargo/solana changes
Make our implementation compatible with pubgrub-rs/pubgrub#298
1 parent 16f851c commit e8cf62e

File tree

4 files changed

+31
-39
lines changed

4 files changed

+31
-39
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ petgraph = { version = "0.6.5" }
130130
platform-info = { version = "2.0.3" }
131131
proc-macro2 = { version = "1.0.86" }
132132
procfs = { version = "0.17.0", default-features = false, features = ["flate2"] }
133-
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "036aab424f917b0b8e9b878e402c05e733f312a3" }
133+
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "05e8d12cea8d72c6d2d017900e478d0abd28fef4" }
134134
quote = { version = "1.0.37" }
135135
rayon = { version = "1.10.0" }
136136
reflink-copy = { version = "0.1.19" }
@@ -175,7 +175,7 @@ unicode-width = { version = "0.1.13" }
175175
unscanny = { version = "0.1.0" }
176176
url = { version = "2.5.2", features = ["serde"] }
177177
urlencoding = { version = "2.1.3" }
178-
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "036aab424f917b0b8e9b878e402c05e733f312a3" }
178+
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "05e8d12cea8d72c6d2d017900e478d0abd28fef4" }
179179
walkdir = { version = "2.5.0" }
180180
which = { version = "7.0.0", features = ["regex"] }
181181
windows-registry = { version = "0.3.0" }

crates/uv-resolver/src/dependency_provider.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::Infallible;
22

3-
use pubgrub::{Dependencies, DependencyProvider, Range};
3+
use pubgrub::{Dependencies, DependencyProvider, PackageResolutionStatistics, Range};
44

55
use uv_pep440::Version;
66

@@ -17,13 +17,17 @@ impl DependencyProvider for UvDependencyProvider {
1717
type V = Version;
1818
type VS = Range<Version>;
1919
type M = UnavailableReason;
20+
type Priority = Option<PubGrubPriority>;
21+
type Err = Infallible;
2022

21-
fn prioritize(&self, _package: &Self::P, _range: &Self::VS) -> Self::Priority {
23+
fn prioritize(
24+
&self,
25+
_package: &Self::P,
26+
_range: &Self::VS,
27+
_stats: &PackageResolutionStatistics,
28+
) -> Self::Priority {
2229
unimplemented!()
2330
}
24-
type Priority = Option<PubGrubPriority>;
25-
26-
type Err = Infallible;
2731

2832
fn choose_version(
2933
&self,

crates/uv-resolver/src/resolver/mod.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use dashmap::DashMap;
1313
use either::Either;
1414
use futures::{FutureExt, StreamExt};
1515
use itertools::Itertools;
16-
use pubgrub::{Id, Incompatibility, Range, Ranges, State, Term};
16+
use pubgrub::{Id, IncompId, Incompatibility, Range, Ranges, State};
1717
use rustc_hash::{FxHashMap, FxHashSet};
1818
use tokio::sync::mpsc::{self, Receiver, Sender};
1919
use tokio::sync::oneshot;
@@ -336,17 +336,9 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
336336
} else {
337337
// Run unit propagation.
338338
let result = state.pubgrub.unit_propagation(state.next);
339-
// End the mutable borrow of `state.pubgrub`.
340-
let result = result.map(|conflict| {
341-
conflict.map(|conflict| {
342-
conflict
343-
.map(|(package, term)| (package, term.clone()))
344-
.collect::<Vec<_>>()
345-
})
346-
});
347339
match result {
348340
Err(err) => {
349-
// If unit propagation failed, the is no solution.
341+
// If unit propagation failed, there is no solution.
350342
return Err(self.convert_no_solution_err(
351343
err,
352344
state.fork_urls,
@@ -357,14 +349,13 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
357349
&self.capabilities,
358350
));
359351
}
360-
Ok(Some(conflict)) => {
361-
// Conflict tracking: If the version was rejected due to its dependencies,
362-
// record culprit and affected.
363-
state.record_conflict(state.next, None, &conflict);
352+
Ok(conflicts) => {
353+
for (affected, incompatibility) in conflicts {
354+
// Conflict tracking: If there was a conflict, track affected and
355+
// culprit for all root cause incompatibilities
356+
state.record_conflict(affected, None, incompatibility);
357+
}
364358
}
365-
// There was no conflict, or we've already rejected the last version due to its
366-
// dependencies.
367-
Ok(None) => {}
368359
}
369360

370361
// Pre-visit all candidate packages, to allow metadata to be fetched in parallel.
@@ -2412,14 +2403,11 @@ impl ForkState {
24122403
(package, version)
24132404
}),
24142405
);
2415-
// End the mutable borrow of `self.pubgrub`
2416-
let conflict: Option<Vec<_>> =
2417-
conflict.map(|x| x.map(|(package, term)| (package, term.clone())).collect());
24182406

24192407
// Conflict tracking: If the version was rejected due to its dependencies, record culprit
24202408
// and affected.
2421-
if let Some(conflict) = conflict {
2422-
self.record_conflict(for_package, Some(for_version), &conflict);
2409+
if let Some(incompatibility) = conflict {
2410+
self.record_conflict(for_package, Some(for_version), incompatibility);
24232411
}
24242412
Ok(())
24252413
}
@@ -2428,15 +2416,15 @@ impl ForkState {
24282416
&mut self,
24292417
affected: Id<PubGrubPackage>,
24302418
version: Option<&Version>,
2431-
conflict: &[(Id<PubGrubPackage>, Term<Ranges<Version>>)],
2419+
incompatibility: IncompId<PubGrubPackage, Ranges<Version>, UnavailableReason>,
24322420
) {
24332421
let mut culprit_is_real = false;
2434-
for (incompatible, _term) in conflict {
2435-
if *incompatible == affected {
2422+
for (incompatible, _term) in self.pubgrub.incompatibility_store[incompatibility].iter() {
2423+
if incompatible == affected {
24362424
continue;
24372425
}
24382426
if self.pubgrub.package_store[affected].name()
2439-
== self.pubgrub.package_store[*incompatible].name()
2427+
== self.pubgrub.package_store[incompatible].name()
24402428
{
24412429
// Don't track conflicts between a marker package and the main package, when the
24422430
// marker is "copying" the obligations from the main package through conflicts.
@@ -2446,21 +2434,21 @@ impl ForkState {
24462434
let culprit_count = self
24472435
.conflict_tracker
24482436
.culprit
2449-
.entry(*incompatible)
2437+
.entry(incompatible)
24502438
.or_default();
24512439
*culprit_count += 1;
24522440
if *culprit_count == CONFLICT_THRESHOLD {
2453-
self.conflict_tracker.depriotize.push(*incompatible);
2441+
self.conflict_tracker.depriotize.push(incompatible);
24542442
}
24552443
}
24562444
// Don't track conflicts between a marker package and the main package, when the
24572445
// marker is "copying" the obligations from the main package through conflicts.
24582446
if culprit_is_real {
24592447
if tracing::enabled!(Level::DEBUG) {
2460-
let incompatibility = conflict
2448+
let incompatibility = self.pubgrub.incompatibility_store[incompatibility]
24612449
.iter()
24622450
.map(|(package, _term)| {
2463-
format!("{:?}", self.pubgrub.package_store[*package].clone(),)
2451+
format!("{:?}", self.pubgrub.package_store[package].clone(),)
24642452
})
24652453
.join(", ");
24662454
if let Some(version) = version {

0 commit comments

Comments
 (0)