Skip to content

Commit 0f436fc

Browse files
zaniebkonstin
authored andcommitted
Initial divergences from upstream (#1)
1 parent d5ed801 commit 0f436fc

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

src/internal/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct State<DP: DependencyProvider> {
2525
root_package: DP::P,
2626
root_version: DP::V,
2727

28+
/// All incompatibilities indexed by package.
2829
#[allow(clippy::type_complexity)]
2930
incompatibilities: Map<DP::P, Vec<IncompDpId<DP>>>,
3031

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, M: Eq + Clone + Debug + Display> {
3636
package_terms: SmallMap<P, Term<VS>>,
37-
kind: Kind<P, VS, M>,
37+
/// The reason for the incompatibility.
38+
pub kind: Kind<P, VS, M>,
3839
}
3940

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

44+
/// The reason for the incompatibility.
4345
#[derive(Debug, Clone)]
44-
enum Kind<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
46+
pub enum Kind<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
4547
/// Initial incompatibility aiming at picking the root package for the first decision.
4648
///
4749
/// This incompatibility drives the resolution, it requires that we pick the (virtual) root
@@ -152,6 +154,8 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
152154
}
153155
}
154156

157+
/// Return the two packages where this incompatibility when the incompatibility was created
158+
/// through a dependency edge between the two.
155159
pub fn as_dependency(&self) -> Option<(&P, &P)> {
156160
match &self.kind {
157161
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
@@ -262,6 +262,24 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
262262
}
263263
}
264264

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

src/lib.rs

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

222223
pub mod error;
223224
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

@@ -334,6 +334,15 @@ fn within_bounds<V: PartialOrd>(version: &V, segment: &Interval<V>) -> Ordering
334334
Ordering::Greater
335335
}
336336

337+
/// Implementation of [`Bound::as_ref`] which is currently marked as unstable.
338+
fn bound_as_ref<V>(bound: &Bound<V>) -> Bound<&V> {
339+
match bound {
340+
Included(v) => Included(v),
341+
Excluded(v) => Excluded(v),
342+
Unbounded => Unbounded,
343+
}
344+
}
345+
337346
/// A valid segment is one where at least one version fits between start and end
338347
fn valid_segment<T: PartialOrd>(start: &Bound<T>, end: &Bound<T>) -> bool {
339348
match (start, end) {
@@ -728,7 +737,7 @@ impl<V: Display + Eq> Display for Range<V> {
728737
} else {
729738
for (idx, segment) in self.segments.iter().enumerate() {
730739
if idx > 0 {
731-
write!(f, " | ")?;
740+
write!(f, ", ")?;
732741
}
733742
match segment {
734743
(Unbounded, Unbounded) => write!(f, "*")?,
@@ -737,9 +746,9 @@ impl<V: Display + Eq> Display for Range<V> {
737746
(Included(v), Unbounded) => write!(f, ">={v}")?,
738747
(Included(v), Included(b)) => {
739748
if v == b {
740-
write!(f, "{v}")?
749+
write!(f, "=={v}")?
741750
} else {
742-
write!(f, ">={v}, <={b}")?
751+
write!(f, ">={v},<={b}")?
743752
}
744753
}
745754
(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
@@ -68,8 +68,8 @@ use std::error::Error;
6868
use std::fmt::{Debug, Display};
6969

7070
use crate::error::PubGrubError;
71-
use crate::internal::core::State;
72-
use crate::internal::incompatibility::Incompatibility;
71+
pub use crate::internal::core::State;
72+
pub use crate::internal::incompatibility::{Incompatibility, Kind};
7373
use crate::package::Package;
7474
use crate::type_aliases::{DependencyConstraints, Map, SelectedDependencies};
7575
use crate::version_set::VersionSet;

src/term.rs

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

7272
/// Unwrap the set contained in a positive term.
7373
/// Will panic if used on a negative set.
74-
pub(crate) fn unwrap_positive(&self) -> &VS {
74+
pub fn unwrap_positive(&self) -> &VS {
7575
match self {
7676
Self::Positive(set) => set,
7777
_ => 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)