From 46f1214fe6b7886709a35d8d2f2c0e1b56433b26 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 16 Nov 2023 12:47:23 -0600 Subject: [PATCH] Initial divergences from upstream (#1) --- src/internal/core.rs | 2 +- src/internal/incompatibility.rs | 4 ++-- src/internal/partial_solution.rs | 18 ++++++++++++++++++ src/lib.rs | 3 +-- src/range.rs | 21 +++++++++++++++------ src/solver.rs | 4 ++-- src/term.rs | 2 +- 7 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/internal/core.rs b/src/internal/core.rs index 06e3ae21..a4a23b34 100644 --- a/src/internal/core.rs +++ b/src/internal/core.rs @@ -24,7 +24,7 @@ pub struct State { root_package: P, root_version: VS::V, - incompatibilities: Map>>, + pub incompatibilities: Map>>, /// Store the ids of incompatibilities that are already contradicted /// and will stay that way until the next conflict and backtrack is operated. diff --git a/src/internal/incompatibility.rs b/src/internal/incompatibility.rs index b56a3c44..168c5218 100644 --- a/src/internal/incompatibility.rs +++ b/src/internal/incompatibility.rs @@ -31,14 +31,14 @@ use crate::version_set::VersionSet; #[derive(Debug, Clone)] pub struct Incompatibility { package_terms: SmallMap>, - kind: Kind, + pub kind: Kind, } /// Type alias of unique identifiers for incompatibilities. pub type IncompId = Id>; #[derive(Debug, Clone)] -enum Kind { +pub enum Kind { /// Initial incompatibility aiming at picking the root package for the first decision. NotRoot(P, VS::V), /// There are no versions in the given range for this package. diff --git a/src/internal/partial_solution.rs b/src/internal/partial_solution.rs index 057dea13..6a8a2bff 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -252,6 +252,24 @@ impl PartialSolution impl Iterator { + let check_all = self.changed_this_decision_level + == self.current_decision_level.0.saturating_sub(1) as usize; + let current_decision_level = self.current_decision_level; + self.package_assignments + .get_range(self.changed_this_decision_level..) + .unwrap() + .iter() + .filter(move |(_, pa)| { + // We only actually need to update the package if its Been changed + // since the last time we called prioritize. + // Which means it's highest decision level is the current decision level, + // or if we backtracked in the mean time. + check_all || pa.highest_decision_level == current_decision_level + }) + .filter_map(|(p, pa)| pa.assignments_intersection.potential_package_filter(p)) + } + pub fn pick_highest_priority_pkg( &mut self, prioritizer: impl Fn(&P, &VS) -> Priority, diff --git a/src/lib.rs b/src/lib.rs index 5f61fb51..0150c52a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -217,8 +217,7 @@ //! with a cache, you may want to know that some versions //! do not exist in your cache. -#![allow(clippy::rc_buffer)] -#![warn(missing_docs)] +#![allow(clippy::all, unreachable_pub)] pub mod error; pub mod package; diff --git a/src/range.rs b/src/range.rs index be7ff250..47e76e44 100644 --- a/src/range.rs +++ b/src/range.rs @@ -195,7 +195,7 @@ impl Range { .segments .last() .expect("if there is a first element, there must be a last element"); - (start.as_ref(), end.1.as_ref()) + (bound_as_ref(start), bound_as_ref(&end.1)) }) } @@ -264,6 +264,15 @@ impl Range { } } +/// Implementation of [`Bound::as_ref`] which is currently marked as unstable. +fn bound_as_ref(bound: &Bound) -> Bound<&V> { + match bound { + Included(v) => Included(v), + Excluded(v) => Excluded(v), + Unbounded => Unbounded, + } +} + fn valid_segment(start: &Bound, end: &Bound) -> bool { match (start, end) { (Included(s), Included(e)) => s <= e, @@ -298,7 +307,7 @@ impl Range { (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i <= e => Excluded(e), (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e < i => Included(i), - (s, Unbounded) | (Unbounded, s) => s.as_ref(), + (s, Unbounded) | (Unbounded, s) => bound_as_ref(s), _ => unreachable!(), } .cloned(); @@ -308,7 +317,7 @@ impl Range { (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i >= e => Excluded(e), (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e > i => Included(i), - (s, Unbounded) | (Unbounded, s) => s.as_ref(), + (s, Unbounded) | (Unbounded, s) => bound_as_ref(s), _ => unreachable!(), } .cloned(); @@ -364,7 +373,7 @@ impl Display for Range { } else { for (idx, segment) in self.segments.iter().enumerate() { if idx > 0 { - write!(f, " | ")?; + write!(f, ", ")?; } match segment { (Unbounded, Unbounded) => write!(f, "*")?, @@ -373,9 +382,9 @@ impl Display for Range { (Included(v), Unbounded) => write!(f, ">={v}")?, (Included(v), Included(b)) => { if v == b { - write!(f, "{v}")? + write!(f, "=={v}")? } else { - write!(f, ">={v}, <={b}")? + write!(f, ">={v},<={b}")? } } (Included(v), Excluded(b)) => write!(f, ">={v}, <{b}")?, diff --git a/src/solver.rs b/src/solver.rs index a1e5e06c..1728d1fe 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -73,8 +73,8 @@ use std::collections::{BTreeMap, BTreeSet as Set}; use std::error::Error; use crate::error::PubGrubError; -use crate::internal::core::State; -use crate::internal::incompatibility::Incompatibility; +pub use crate::internal::core::State; +pub use crate::internal::incompatibility::{Incompatibility, Kind}; use crate::package::Package; use crate::type_aliases::{DependencyConstraints, Map, SelectedDependencies}; use crate::version_set::VersionSet; diff --git a/src/term.rs b/src/term.rs index cf7aa6f7..895afdfe 100644 --- a/src/term.rs +++ b/src/term.rs @@ -64,7 +64,7 @@ impl Term { /// Unwrap the set contained in a positive term. /// Will panic if used on a negative set. - pub(crate) fn unwrap_positive(&self) -> &VS { + pub fn unwrap_positive(&self) -> &VS { match self { Self::Positive(set) => set, _ => panic!("Negative term cannot unwrap positive set"),