Skip to content

Commit 4131f45

Browse files
committed
Sync with cargo/solana changes
Make our implementation compatible with pubgrub-rs/pubgrub#298
1 parent 3d3738b commit 4131f45

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 = "251e93bd42b9cf4705e633a2a95a137be4087358" }
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 = "251e93bd42b9cf4705e633a2a95a137be4087358" }
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;
@@ -328,17 +328,9 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
328328
loop {
329329
// Run unit propagation.
330330
let result = state.pubgrub.unit_propagation(state.next);
331-
// End the mutable borrow of `state.pubgrub`.
332-
let result = result.map(|conflict| {
333-
conflict.map(|conflict| {
334-
conflict
335-
.map(|(package, term)| (package, term.clone()))
336-
.collect::<Vec<_>>()
337-
})
338-
});
339331
match result {
340332
Err(err) => {
341-
// If unit propagation failed, the is no solution.
333+
// If unit propagation failed, there is no solution.
342334
return Err(self.convert_no_solution_err(
343335
err,
344336
state.fork_urls,
@@ -349,14 +341,13 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
349341
&self.capabilities,
350342
));
351343
}
352-
Ok(Some(conflict)) => {
353-
// Conflict tracking: If the version was rejected due to its dependencies,
354-
// record culprit and affected.
355-
state.record_conflict(state.next, None, &conflict);
344+
Ok(conflicts) => {
345+
for (affected, incompatibility) in conflicts {
346+
// Conflict tracking: If there was a conflict, track affected and
347+
// culprit for all root cause incompatibilities
348+
state.record_conflict(affected, None, incompatibility);
349+
}
356350
}
357-
// There was no conflict, or we've already rejected the last version due to its
358-
// dependencies.
359-
Ok(None) => {}
360351
}
361352

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

23582346
// Conflict tracking: If the version was rejected due to its dependencies, record culprit
23592347
// and affected.
2360-
if let Some(conflict) = conflict {
2361-
self.record_conflict(for_package, Some(for_version), &conflict);
2348+
if let Some(incompatibility) = conflict {
2349+
self.record_conflict(for_package, Some(for_version), incompatibility);
23622350
}
23632351
Ok(())
23642352
}
@@ -2367,15 +2355,15 @@ impl ForkState {
23672355
&mut self,
23682356
affected: Id<PubGrubPackage>,
23692357
version: Option<&Version>,
2370-
conflict: &[(Id<PubGrubPackage>, Term<Ranges<Version>>)],
2358+
incompatibility: IncompId<PubGrubPackage, Ranges<Version>, UnavailableReason>,
23712359
) {
23722360
let mut culprit_is_real = false;
2373-
for (incompatible, _term) in conflict {
2374-
if *incompatible == affected {
2361+
for (incompatible, _term) in self.pubgrub.incompatibility_store[incompatibility].iter() {
2362+
if incompatible == affected {
23752363
continue;
23762364
}
23772365
if self.pubgrub.package_store[affected].name()
2378-
== self.pubgrub.package_store[*incompatible].name()
2366+
== self.pubgrub.package_store[incompatible].name()
23792367
{
23802368
// Don't track conflicts between a marker package and the main package, when the
23812369
// marker is "copying" the obligations from the main package through conflicts.
@@ -2385,21 +2373,21 @@ impl ForkState {
23852373
let culprit_count = self
23862374
.conflict_tracker
23872375
.culprit
2388-
.entry(*incompatible)
2376+
.entry(incompatible)
23892377
.or_default();
23902378
*culprit_count += 1;
23912379
if *culprit_count == CONFLICT_THRESHOLD {
2392-
self.conflict_tracker.depriotize.push(*incompatible);
2380+
self.conflict_tracker.depriotize.push(incompatible);
23932381
}
23942382
}
23952383
// Don't track conflicts between a marker package and the main package, when the
23962384
// marker is "copying" the obligations from the main package through conflicts.
23972385
if culprit_is_real {
23982386
if tracing::enabled!(Level::DEBUG) {
2399-
let incompatibility = conflict
2387+
let incompatibility = self.pubgrub.incompatibility_store[incompatibility]
24002388
.iter()
24012389
.map(|(package, _term)| {
2402-
format!("{:?}", self.pubgrub.package_store[*package].clone(),)
2390+
format!("{:?}", self.pubgrub.package_store[package].clone(),)
24032391
})
24042392
.join(", ");
24052393
if let Some(version) = version {

0 commit comments

Comments
 (0)