Skip to content

Commit 7f96381

Browse files
committed
Expose internal interfaces used by uv
1 parent 51d38dd commit 7f96381

File tree

7 files changed

+34
-27
lines changed

7 files changed

+34
-27
lines changed

src/internal/arena.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ops::{Index, Range};
1010
/// that we actually don't need since it is phantom.
1111
///
1212
/// <https://github.com/rust-lang/rust/issues/26925>
13-
pub(crate) struct Id<T> {
13+
pub struct Id<T> {
1414
raw: u32,
1515
_ty: PhantomData<fn() -> T>,
1616
}
@@ -71,7 +71,7 @@ impl<T> Id<T> {
7171
/// to have references between those items.
7272
/// They are all dropped at once when the arena is dropped.
7373
#[derive(Clone, PartialEq, Eq)]
74-
pub(crate) struct Arena<T> {
74+
pub struct Arena<T> {
7575
data: Vec<T>,
7676
}
7777

src/internal/core.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ 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> {
1818
root_package: DP::P,
1919
root_version: DP::V,
2020

21+
/// All incompatibilities indexed by package.
2122
#[allow(clippy::type_complexity)]
22-
incompatibilities: Map<DP::P, Vec<IncompDpId<DP>>>,
23+
pub incompatibilities: Map<DP::P, Vec<IncompDpId<DP>>>,
2324

2425
/// Store the ids of incompatibilities that are already contradicted.
2526
/// For each one keep track of the decision level when it was found to be contradicted.
@@ -32,11 +33,10 @@ pub(crate) struct State<DP: DependencyProvider> {
3233
merged_dependencies: Map<(DP::P, DP::P), SmallVec<IncompDpId<DP>>>,
3334

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

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

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

4747
impl<DP: DependencyProvider> State<DP> {
4848
/// Initialization of PubGrub state.
49-
pub(crate) fn init(root_package: DP::P, root_version: DP::V) -> Self {
49+
pub fn init(root_package: DP::P, root_version: DP::V) -> Self {
5050
let mut incompatibility_store = Arena::new();
5151
let not_root_id = incompatibility_store.alloc(Incompatibility::not_root(
5252
root_package.clone(),
@@ -67,7 +67,7 @@ impl<DP: DependencyProvider> State<DP> {
6767
}
6868

6969
/// Add an incompatibility to the state.
70-
pub(crate) fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
70+
pub fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
7171
let id = self.incompatibility_store.alloc(incompat);
7272
self.merge_incompatibility(id);
7373
}
@@ -98,7 +98,7 @@ impl<DP: DependencyProvider> State<DP> {
9898

9999
/// Unit propagation is the core mechanism of the solving algorithm.
100100
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
101-
pub(crate) fn unit_propagation(&mut self, package: DP::P) -> Result<(), NoSolutionError<DP>> {
101+
pub fn unit_propagation(&mut self, package: DP::P) -> Result<(), NoSolutionError<DP>> {
102102
self.unit_propagation_buffer.clear();
103103
self.unit_propagation_buffer.push(package);
104104
while let Some(current_package) = self.unit_propagation_buffer.pop() {

src/internal/incompatibility.rs

Lines changed: 9 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<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: P, term: Term<VS>) -> Self {
109+
pub fn no_versions(package: 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: P, term: Term<VS>, metadata: M) -> Self {
122+
pub fn custom_term(package: 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: P, version: VS::V, metadata: M) -> Self {
134+
pub fn custom_version(package: 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: P, versions: VS, dep: (P, VS)) -> Self {
144+
pub fn from_dependency(package: P, versions: VS, dep: (P, VS)) -> Self {
143145
let (p2, set2) = dep;
144146
Self {
145147
package_terms: if set2 == VS::empty() {

src/internal/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ mod small_map;
1010
mod small_vec;
1111

1212
pub(crate) use arena::{Arena, Id};
13-
pub(crate) use core::State;
14-
pub(crate) use incompatibility::{IncompDpId, IncompId, Incompatibility, Relation};
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 core::State;
20+
pub use incompatibility::{Incompatibility, Kind};

src/internal/partial_solution.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use std::hash::BuildHasherDefault;
99
use priority_queue::PriorityQueue;
1010
use rustc_hash::FxHasher;
1111

12-
use super::small_vec::SmallVec;
13-
use crate::internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap};
12+
use crate::internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap, SmallVec};
1413
use crate::{DependencyProvider, Package, SelectedDependencies, Term, VersionSet};
1514

1615
type FnvIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
@@ -27,7 +26,7 @@ impl DecisionLevel {
2726
/// The partial solution contains all package assignments,
2827
/// organized by package and historically ordered.
2928
#[derive(Clone, Debug)]
30-
pub(crate) struct PartialSolution<DP: DependencyProvider> {
29+
pub struct PartialSolution<DP: DependencyProvider> {
3130
next_global_index: u32,
3231
current_decision_level: DecisionLevel,
3332
/// `package_assignments` is primarily a HashMap from a package to its
@@ -158,7 +157,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
158157
}
159158

160159
/// Add a decision.
161-
pub(crate) fn add_decision(&mut self, package: DP::P, version: DP::V) {
160+
pub fn add_decision(&mut self, package: DP::P, version: DP::V) {
162161
// Check that add_decision is never used in the wrong context.
163162
if cfg!(debug_assertions) {
164163
match self.package_assignments.get_mut(&package) {
@@ -257,7 +256,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
257256
}
258257
}
259258

260-
pub(crate) fn pick_highest_priority_pkg(
259+
pub fn pick_highest_priority_pkg(
261260
&mut self,
262261
prioritizer: impl Fn(&DP::P, &DP::VS) -> DP::Priority,
263262
) -> Option<DP::P> {
@@ -288,7 +287,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
288287
/// If a partial solution has, for every positive derivation,
289288
/// a corresponding decision that satisfies that assignment,
290289
/// it's a total solution and version solving has succeeded.
291-
pub(crate) fn extract_solution(&self) -> SelectedDependencies<DP> {
290+
pub fn extract_solution(&self) -> SelectedDependencies<DP> {
292291
self.package_assignments
293292
.iter()
294293
.take(self.current_decision_level.0 as usize)
@@ -398,7 +397,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
398397
}
399398

400399
/// Retrieve intersection of terms related to package.
401-
pub(crate) fn term_intersection_for_package(&self, package: &DP::P) -> Option<&Term<DP::VS>> {
400+
pub fn term_intersection_for_package(&self, package: &DP::P) -> Option<&Term<DP::VS>> {
402401
self.package_assignments
403402
.get(package)
404403
.map(|pa| pa.assignments_intersection.term())

src/lib.rs

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

237+
// uv-specific additions
238+
pub use internal::{Incompatibility, Kind, State};
239+
237240
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)