Skip to content

Commit 684d560

Browse files
committed
Expose internal interfaces used by uv
1 parent e9170cb commit 684d560

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

src/internal/arena.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type FnvIndexSet<V> = indexmap::IndexSet<V, rustc_hash::FxBuildHasher>;
1212
/// that we actually don't need since it is phantom.
1313
///
1414
/// <https://github.com/rust-lang/rust/issues/26925>
15-
pub(crate) struct Id<T> {
15+
pub struct Id<T> {
1616
raw: u32,
1717
_ty: PhantomData<fn() -> T>,
1818
}
@@ -73,7 +73,7 @@ impl<T> Id<T> {
7373
/// to have references between those items.
7474
/// They are all dropped at once when the arena is dropped.
7575
#[derive(Clone, PartialEq, Eq)]
76-
pub(crate) struct Arena<T> {
76+
pub struct Arena<T> {
7777
data: Vec<T>,
7878
}
7979

src/internal/core.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ use crate::{DependencyProvider, DerivationTree, Map, NoSolutionError, VersionSet
1414

1515
/// Current state of the PubGrub algorithm.
1616
#[derive(Clone)]
17-
pub(crate) struct State<DP: DependencyProvider> {
17+
pub struct State<DP: DependencyProvider> {
18+
/// The root package and version.
1819
pub root_package: Id<DP::P>,
1920
root_version: DP::V,
2021

22+
/// All incompatibilities indexed by package.
2123
#[allow(clippy::type_complexity)]
22-
incompatibilities: Map<Id<DP::P>, Vec<IncompDpId<DP>>>,
24+
pub incompatibilities: Map<Id<DP::P>, Vec<IncompDpId<DP>>>,
2325

2426
/// Store the ids of incompatibilities that are already contradicted.
2527
/// For each one keep track of the decision level when it was found to be contradicted.
@@ -32,14 +34,13 @@ pub(crate) struct State<DP: DependencyProvider> {
3234
merged_dependencies: Map<(Id<DP::P>, Id<DP::P>), SmallVec<IncompDpId<DP>>>,
3335

3436
/// Partial solution.
35-
/// TODO: remove pub.
36-
pub(crate) partial_solution: PartialSolution<DP>,
37+
pub partial_solution: PartialSolution<DP>,
3738

3839
/// The store is the reference storage for all incompatibilities.
39-
pub(crate) incompatibility_store: Arena<Incompatibility<DP::P, DP::VS, DP::M>>,
40+
pub incompatibility_store: Arena<Incompatibility<DP::P, DP::VS, DP::M>>,
4041

4142
/// The store is the reference storage for all packages.
42-
pub(crate) package_store: HashArena<DP::P>,
43+
pub package_store: HashArena<DP::P>,
4344

4445
/// This is a stack of work to be done in `unit_propagation`.
4546
/// It can definitely be a local variable to that method, but
@@ -49,7 +50,7 @@ pub(crate) struct State<DP: DependencyProvider> {
4950

5051
impl<DP: DependencyProvider> State<DP> {
5152
/// Initialization of PubGrub state.
52-
pub(crate) fn init(root_package: DP::P, root_version: DP::V) -> Self {
53+
pub fn init(root_package: DP::P, root_version: DP::V) -> Self {
5354
let mut incompatibility_store = Arena::new();
5455
let mut package_store = HashArena::new();
5556
let root_package = package_store.alloc(root_package);
@@ -73,7 +74,7 @@ impl<DP: DependencyProvider> State<DP> {
7374
}
7475

7576
/// Add an incompatibility to the state.
76-
pub(crate) fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
77+
pub fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
7778
let id = self.incompatibility_store.alloc(incompat);
7879
self.merge_incompatibility(id);
7980
}
@@ -107,10 +108,7 @@ impl<DP: DependencyProvider> State<DP> {
107108
/// Unit propagation is the core mechanism of the solving algorithm.
108109
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
109110
#[cold]
110-
pub(crate) fn unit_propagation(
111-
&mut self,
112-
package: Id<DP::P>,
113-
) -> Result<(), NoSolutionError<DP>> {
111+
pub fn unit_propagation(&mut self, package: Id<DP::P>) -> Result<(), NoSolutionError<DP>> {
114112
self.unit_propagation_buffer.clear();
115113
self.unit_propagation_buffer.push(package);
116114
while let Some(current_package) = self.unit_propagation_buffer.pop() {

src/internal/incompatibility.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ use crate::{
2828
/// during conflict resolution. More about all this in
2929
/// [PubGrub documentation](https://github.com/dart-lang/pub/blob/master/doc/solver.md#incompatibility).
3030
#[derive(Debug, Clone)]
31-
pub(crate) struct Incompatibility<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
31+
pub struct Incompatibility<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
3232
package_terms: SmallMap<Id<P>, Term<VS>>,
33-
kind: Kind<P, VS, M>,
33+
/// The reason for the incompatibility.
34+
pub kind: Kind<P, VS, M>,
3435
}
3536

3637
/// Type alias of unique identifiers for incompatibilities.
@@ -42,8 +43,9 @@ pub(crate) type IncompDpId<DP> = IncompId<
4243
<DP as DependencyProvider>::M,
4344
>;
4445

46+
/// The reason for the incompatibility.
4547
#[derive(Debug, Clone)]
46-
enum Kind<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
48+
pub enum Kind<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
4749
/// Initial incompatibility aiming at picking the root package for the first decision.
4850
///
4951
/// This incompatibility drives the resolution, it requires that we pick the (virtual) root
@@ -104,7 +106,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
104106
}
105107

106108
/// Create an incompatibility to remember that a given set does not contain any version.
107-
pub(crate) fn no_versions(package: Id<P>, term: Term<VS>) -> Self {
109+
pub fn no_versions(package: Id<P>, term: Term<VS>) -> Self {
108110
let set = match &term {
109111
Term::Positive(r) => r.clone(),
110112
Term::Negative(_) => panic!("No version should have a positive term"),
@@ -117,7 +119,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
117119

118120
/// Create an incompatibility for a reason outside pubgrub.
119121
#[allow(dead_code)] // Used by uv
120-
pub(crate) fn custom_term(package: Id<P>, term: Term<VS>, metadata: M) -> Self {
122+
pub fn custom_term(package: Id<P>, term: Term<VS>, metadata: M) -> Self {
121123
let set = match &term {
122124
Term::Positive(r) => r.clone(),
123125
Term::Negative(_) => panic!("No version should have a positive term"),
@@ -129,7 +131,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
129131
}
130132

131133
/// Create an incompatibility for a reason outside pubgrub.
132-
pub(crate) fn custom_version(package: Id<P>, version: VS::V, metadata: M) -> Self {
134+
pub fn custom_version(package: Id<P>, version: VS::V, metadata: M) -> Self {
133135
let set = VS::singleton(version);
134136
let term = Term::Positive(set.clone());
135137
Self {
@@ -139,7 +141,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
139141
}
140142

141143
/// Build an incompatibility from a given dependency.
142-
pub(crate) fn from_dependency(package: Id<P>, versions: VS, dep: (Id<P>, VS)) -> Self {
144+
pub fn from_dependency(package: Id<P>, versions: VS, dep: (Id<P>, VS)) -> Self {
143145
let (p2, set2) = dep;
144146
Self {
145147
package_terms: if set2 == VS::empty() {
@@ -345,6 +347,7 @@ impl<'a, P: Package, VS: VersionSet + 'a, M: Eq + Clone + Debug + Display + 'a>
345347
}
346348

347349
impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibility<P, VS, M> {
350+
/// Display the incompatibility.
348351
pub fn display<'a>(&'a self, package_store: &'a HashArena<P>) -> impl Display + 'a {
349352
match self.iter().collect::<Vec<_>>().as_slice() {
350353
[] => "version solving failed".into(),

src/internal/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ mod partial_solution;
99
mod small_map;
1010
mod small_vec;
1111

12-
pub(crate) use arena::{Arena, HashArena, Id};
13-
pub(crate) use core::State;
14-
pub(crate) use incompatibility::{IncompDpId, IncompId, Incompatibility, Relation};
12+
pub(crate) use arena::{Arena, HashArena};
13+
pub(crate) use incompatibility::{IncompDpId, IncompId, Relation};
1514
pub(crate) use partial_solution::{DecisionLevel, PartialSolution, SatisfierSearch};
1615
pub(crate) use small_map::SmallMap;
1716
pub(crate) use small_vec::SmallVec;
17+
18+
// uv-specific additions
19+
pub use arena::Id;
20+
pub use core::State;
21+
pub use incompatibility::{Incompatibility, Kind};

src/internal/partial_solution.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl DecisionLevel {
2828
/// The partial solution contains all package assignments,
2929
/// organized by package and historically ordered.
3030
#[derive(Clone, Debug)]
31-
pub(crate) struct PartialSolution<DP: DependencyProvider> {
31+
pub struct PartialSolution<DP: DependencyProvider> {
3232
next_global_index: u32,
3333
current_decision_level: DecisionLevel,
3434
/// `package_assignments` is primarily a HashMap from a package to its
@@ -166,7 +166,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
166166
}
167167

168168
/// Add a decision.
169-
pub(crate) fn add_decision(&mut self, package: Id<DP::P>, version: DP::V) {
169+
pub fn add_decision(&mut self, package: Id<DP::P>, version: DP::V) {
170170
// Check that add_decision is never used in the wrong context.
171171
if cfg!(debug_assertions) {
172172
match self.package_assignments.get_mut(&package) {
@@ -266,7 +266,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
266266
}
267267

268268
#[cold]
269-
pub(crate) fn pick_highest_priority_pkg(
269+
pub fn pick_highest_priority_pkg(
270270
&mut self,
271271
prioritizer: impl Fn(Id<DP::P>, &DP::VS) -> DP::Priority,
272272
) -> Option<Id<DP::P>> {
@@ -297,7 +297,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
297297
/// If a partial solution has, for every positive derivation,
298298
/// a corresponding decision that satisfies that assignment,
299299
/// it's a total solution and version solving has succeeded.
300-
pub(crate) fn extract_solution(&self) -> impl Iterator<Item = (Id<DP::P>, DP::V)> + '_ {
300+
pub fn extract_solution(&self) -> impl Iterator<Item = (Id<DP::P>, DP::V)> + '_ {
301301
self.package_assignments
302302
.iter()
303303
.take(self.current_decision_level.0 as usize)
@@ -402,10 +402,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
402402
}
403403

404404
/// Retrieve intersection of terms related to package.
405-
pub(crate) fn term_intersection_for_package(
406-
&self,
407-
package: Id<DP::P>,
408-
) -> Option<&Term<DP::VS>> {
405+
pub fn term_intersection_for_package(&self, package: Id<DP::P>) -> Option<&Term<DP::VS>> {
409406
self.package_assignments
410407
.get(&package)
411408
.map(|pa| pa.assignments_intersection.term())

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,7 @@ pub use version_ranges::Ranges;
236236
pub use version_ranges::Ranges as Range;
237237
pub use version_set::VersionSet;
238238

239+
// uv-specific additions
240+
pub use internal::{Id, Incompatibility, Kind, State};
241+
239242
mod internal;

src/term.rs

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

7575
/// Unwrap the set contained in a positive term.
7676
/// Will panic if used on a negative set.
77-
pub(crate) fn unwrap_positive(&self) -> &VS {
77+
pub fn unwrap_positive(&self) -> &VS {
7878
match self {
7979
Self::Positive(set) => set,
8080
_ => panic!("Negative term cannot unwrap positive set"),

0 commit comments

Comments
 (0)