Skip to content

Commit 2b65107

Browse files
zaniebkonstin
authored andcommitted
Initial divergences from upstream (#1)
1 parent 3549dc5 commit 2b65107

File tree

8 files changed

+46
-13
lines changed

8 files changed

+46
-13
lines changed

src/internal/core.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub struct State<P: Package, VS: VersionSet, Priority: Ord + Clone> {
2525
root_package: P,
2626
root_version: VS::V,
2727

28-
incompatibilities: Map<P, Vec<IncompId<P, VS>>>,
28+
/// All incompatibilities indexed by package.
29+
pub incompatibilities: Map<P, Vec<IncompId<P, VS>>>,
2930

3031
/// Store the ids of incompatibilities that are already contradicted.
3132
/// For each one keep track of the decision level when it was found to be contradicted.

src/internal/incompatibility.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ use crate::version_set::VersionSet;
3434
#[derive(Debug, Clone)]
3535
pub struct Incompatibility<P: Package, VS: VersionSet> {
3636
package_terms: SmallMap<P, Term<VS>>,
37-
kind: Kind<P, VS>,
37+
/// The reason for the incompatibility.
38+
pub kind: Kind<P, VS>,
3839
}
3940

4041
/// Type alias of unique identifiers for incompatibilities.
4142
pub type IncompId<P, VS> = Id<Incompatibility<P, VS>>;
4243

44+
/// The reason for the incompatibility.
4345
#[derive(Debug, Clone)]
44-
enum Kind<P: Package, VS: VersionSet> {
46+
pub enum Kind<P: Package, VS: VersionSet> {
4547
/// Initial incompatibility aiming at picking the root package for the first decision.
4648
NotRoot(P, VS::V),
4749
/// There are no versions in the given range for this package.
@@ -123,6 +125,8 @@ impl<P: Package, VS: VersionSet> Incompatibility<P, VS> {
123125
}
124126
}
125127

128+
/// Return the two packages where this incompatibility when the incompatibility was created
129+
/// through a dependency edge between the two.
126130
pub fn as_dependency(&self) -> Option<(&P, &P)> {
127131
match &self.kind {
128132
Kind::FromDependencyOf(p1, _, p2, _) => Some((p1, p2)),

src/internal/partial_solution.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> PartialSolution<P, VS, P
257257
}
258258
}
259259

260+
pub fn prioritized_packages(&self) -> impl Iterator<Item = (&P, &VS)> {
261+
let check_all = self.changed_this_decision_level
262+
== self.current_decision_level.0.saturating_sub(1) as usize;
263+
let current_decision_level = self.current_decision_level;
264+
self.package_assignments
265+
.get_range(self.changed_this_decision_level..)
266+
.unwrap()
267+
.iter()
268+
.filter(move |(_, pa)| {
269+
// We only actually need to update the package if its Been changed
270+
// since the last time we called prioritize.
271+
// Which means it's highest decision level is the current decision level,
272+
// or if we backtracked in the mean time.
273+
check_all || pa.highest_decision_level == current_decision_level
274+
})
275+
.filter_map(|(p, pa)| pa.assignments_intersection.potential_package_filter(p))
276+
}
277+
260278
pub fn pick_highest_priority_pkg(
261279
&mut self,
262280
prioritizer: impl Fn(&P, &VS) -> Priority,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
//! do not exist in your cache.
222222
223223
#![warn(missing_docs)]
224+
#![allow(clippy::all, unreachable_pub)]
224225

225226
pub mod error;
226227
pub mod package;

src/range.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<V: Ord> Range<V> {
217217
.segments
218218
.last()
219219
.expect("if there is a first element, there must be a last element");
220-
(start.as_ref(), end.1.as_ref())
220+
(bound_as_ref(start), bound_as_ref(&end.1))
221221
})
222222
}
223223

@@ -335,6 +335,15 @@ fn within_bounds<V: PartialOrd>(v: &V, segment: &Interval<V>) -> Ordering {
335335
Ordering::Greater
336336
}
337337

338+
/// Implementation of [`Bound::as_ref`] which is currently marked as unstable.
339+
fn bound_as_ref<V>(bound: &Bound<V>) -> Bound<&V> {
340+
match bound {
341+
Included(v) => Included(v),
342+
Excluded(v) => Excluded(v),
343+
Unbounded => Unbounded,
344+
}
345+
}
346+
338347
fn valid_segment<T: PartialOrd>(start: &Bound<T>, end: &Bound<T>) -> bool {
339348
match (start, end) {
340349
(Included(s), Included(e)) => s <= e,
@@ -561,7 +570,7 @@ impl<V: Display + Eq> Display for Range<V> {
561570
} else {
562571
for (idx, segment) in self.segments.iter().enumerate() {
563572
if idx > 0 {
564-
write!(f, " | ")?;
573+
write!(f, ", ")?;
565574
}
566575
match segment {
567576
(Unbounded, Unbounded) => write!(f, "*")?,
@@ -570,9 +579,9 @@ impl<V: Display + Eq> Display for Range<V> {
570579
(Included(v), Unbounded) => write!(f, ">={v}")?,
571580
(Included(v), Included(b)) => {
572581
if v == b {
573-
write!(f, "{v}")?
582+
write!(f, "=={v}")?
574583
} else {
575-
write!(f, ">={v}, <={b}")?
584+
write!(f, ">={v},<={b}")?
576585
}
577586
}
578587
(Included(v), Excluded(b)) => write!(f, ">={v}, <{b}")?,

src/solver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ use std::convert::Infallible;
7575
use std::error::Error;
7676

7777
use crate::error::PubGrubError;
78-
use crate::internal::core::State;
79-
use crate::internal::incompatibility::Incompatibility;
78+
pub use crate::internal::core::State;
79+
pub use crate::internal::incompatibility::{Incompatibility, Kind};
8080
use crate::package::Package;
8181
use crate::type_aliases::{DependencyConstraints, Map, SelectedDependencies};
8282
use crate::version_set::VersionSet;

src/term.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<VS: VersionSet> Term<VS> {
6464

6565
/// Unwrap the set contained in a positive term.
6666
/// Will panic if used on a negative set.
67-
pub(crate) fn unwrap_positive(&self) -> &VS {
67+
pub fn unwrap_positive(&self) -> &VS {
6868
match self {
6969
Self::Positive(set) => set,
7070
_ => panic!("Negative term cannot unwrap positive set"),

tests/examples.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ fn confusing_with_lots_of_holes() {
231231
};
232232
assert_eq!(
233233
&DefaultStringReporter::report(&derivation_tree),
234-
r#"Because there is no available version for bar and foo 1 | 2 | 3 | 4 | 5 depends on bar, foo 1 | 2 | 3 | 4 | 5 is forbidden.
235-
And because there is no version of foo in <1 | >1, <2 | >2, <3 | >3, <4 | >4, <5 | >5 and root 1 depends on foo, root 1 is forbidden."#
234+
r#"Because there is no available version for bar and foo ==1, ==2, ==3, ==4, ==5 depends on bar, foo ==1, ==2, ==3, ==4, ==5 is forbidden.
235+
And because there is no version of foo in <1, >1, <2, >2, <3, >3, <4, >4, <5, >5 and root ==1 depends on foo, root ==1 is forbidden."#
236236
);
237237
derivation_tree.collapse_no_versions();
238238
assert_eq!(
239239
&DefaultStringReporter::report(&derivation_tree),
240-
"Because foo depends on bar and root 1 depends on foo, root 1 is forbidden."
240+
"Because foo depends on bar and root ==1 depends on foo, root ==1 is forbidden."
241241
);
242242
}

0 commit comments

Comments
 (0)