Skip to content

Commit 42ad7ea

Browse files
authored
Cleanup internal imports (#243)
* Cleanup internal imports Imports now only come from two modules: `crate`, which contains all public symbols, and `crate::internal`, which contains all the internal symbols. I'm surprised the split works out so cleanly. All internal apis are now `pub(crate)`. Some of these will become public again in the uv fork. I used nightly rustfmt to group the imports. * Fix more lints * typo * typo * And in the test, too * Revert internal api abstraction * Revert "Revert internal api abstraction" This reverts commit dd9b290.
1 parent ff09b46 commit 42ad7ea

20 files changed

+153
-173
lines changed

benches/large_case.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
// SPDX-License-Identifier: MPL-2.0
22
use std::time::Duration;
33

4-
extern crate criterion;
5-
use self::criterion::*;
6-
7-
use pubgrub::package::Package;
8-
use pubgrub::range::Range;
9-
use pubgrub::solver::{resolve, OfflineDependencyProvider};
10-
use pubgrub::version::SemanticVersion;
11-
use pubgrub::version_set::VersionSet;
4+
use criterion::*;
125
use serde::de::Deserialize;
136

7+
use pubgrub::{resolve, OfflineDependencyProvider, Package, Range, SemanticVersion, VersionSet};
8+
149
fn bench<'a, P: Package + Deserialize<'a>, VS: VersionSet + Deserialize<'a>>(
1510
b: &mut Bencher,
1611
case: &'a str,

examples/unsat_root_message_no_version.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: MPL-2.0
22

3+
use std::fmt::{self, Display};
4+
35
use pubgrub::{
4-
resolve, Derived, OfflineDependencyProvider, PubGrubError, Range, Reporter, SemanticVersion,
6+
resolve, DefaultStringReporter, Derived, External, Map, OfflineDependencyProvider,
7+
PubGrubError, Range, ReportFormatter, Reporter, SemanticVersion, Term,
58
};
69

7-
use pubgrub::{DefaultStringReporter, External, Map, ReportFormatter, Term};
8-
use std::fmt::{self, Display};
9-
1010
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1111
pub enum Package {
1212
Root,

src/error.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
55
use thiserror::Error;
66

7-
use crate::report::DerivationTree;
8-
use crate::solver::DependencyProvider;
7+
use crate::{DependencyProvider, DerivationTree};
98

109
/// There is no solution for this set of dependencies.
1110
pub type NoSolutionError<DP> = DerivationTree<
@@ -21,10 +20,8 @@ pub enum PubGrubError<DP: DependencyProvider> {
2120
#[error("No solution")]
2221
NoSolution(NoSolutionError<DP>),
2322

24-
/// Error arising when the implementer of
25-
/// [DependencyProvider]
26-
/// returned an error in the method
27-
/// [get_dependencies](crate::solver::DependencyProvider::get_dependencies).
23+
/// Error arising when the implementer of [DependencyProvider] returned an error in the method
24+
/// [get_dependencies](DependencyProvider::get_dependencies).
2825
#[error("Retrieving dependencies of {package} {version} failed")]
2926
ErrorRetrievingDependencies {
3027
/// Package whose dependencies we want.
@@ -49,15 +46,13 @@ pub enum PubGrubError<DP: DependencyProvider> {
4946
version: DP::V,
5047
},
5148

52-
/// Error arising when the implementer of
53-
/// [DependencyProvider]
54-
/// returned an error in the method
55-
/// [choose_version](crate::solver::DependencyProvider::choose_version).
49+
/// Error arising when the implementer of [DependencyProvider] returned an error in the method
50+
/// [choose_version](DependencyProvider::choose_version).
5651
#[error("Decision making failed")]
5752
ErrorChoosingPackageVersion(#[source] DP::Err),
5853

5954
/// Error arising when the implementer of [DependencyProvider]
60-
/// returned an error in the method [should_cancel](crate::solver::DependencyProvider::should_cancel).
55+
/// returned an error in the method [should_cancel](DependencyProvider::should_cancel).
6156
#[error("We should cancel")]
6257
ErrorInShouldCancel(#[source] DP::Err),
6358

src/internal/arena.rs

Lines changed: 7 additions & 7 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 struct Id<T> {
13+
pub(crate) struct Id<T> {
1414
raw: u32,
1515
_ty: PhantomData<fn() -> T>,
1616
}
@@ -48,7 +48,7 @@ impl<T> fmt::Debug for Id<T> {
4848
}
4949

5050
impl<T> Id<T> {
51-
pub fn into_raw(self) -> usize {
51+
pub(crate) fn into_raw(self) -> usize {
5252
self.raw as usize
5353
}
5454
fn from(n: u32) -> Self {
@@ -57,7 +57,7 @@ impl<T> Id<T> {
5757
_ty: PhantomData,
5858
}
5959
}
60-
pub fn range_to_iter(range: Range<Self>) -> impl Iterator<Item = Self> {
60+
pub(crate) fn range_to_iter(range: Range<Self>) -> impl Iterator<Item = Self> {
6161
let start = range.start.raw;
6262
let end = range.end.raw;
6363
(start..end).map(Self::from)
@@ -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 struct Arena<T> {
74+
pub(crate) struct Arena<T> {
7575
data: Vec<T>,
7676
}
7777

@@ -91,17 +91,17 @@ impl<T> Default for Arena<T> {
9191
}
9292

9393
impl<T> Arena<T> {
94-
pub fn new() -> Self {
94+
pub(crate) fn new() -> Self {
9595
Self { data: Vec::new() }
9696
}
9797

98-
pub fn alloc(&mut self, value: T) -> Id<T> {
98+
pub(crate) fn alloc(&mut self, value: T) -> Id<T> {
9999
let raw = self.data.len();
100100
self.data.push(value);
101101
Id::from(raw as u32)
102102
}
103103

104-
pub fn alloc_iter<I: Iterator<Item = T>>(&mut self, values: I) -> Range<Id<T>> {
104+
pub(crate) fn alloc_iter<I: Iterator<Item = T>>(&mut self, values: I) -> Range<Id<T>> {
105105
let start = Id::from(self.data.len() as u32);
106106
values.for_each(|v| {
107107
self.alloc(v);

src/internal/core.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,15 @@
66
use std::collections::HashSet as Set;
77
use std::sync::Arc;
88

9-
use crate::error::NoSolutionError;
10-
use crate::internal::arena::Arena;
11-
use crate::internal::incompatibility::{Incompatibility, Relation};
12-
use crate::internal::partial_solution::SatisfierSearch::{
13-
DifferentDecisionLevels, SameDecisionLevels,
9+
use crate::internal::{
10+
Arena, DecisionLevel, IncompDpId, Incompatibility, PartialSolution, Relation, SatisfierSearch,
11+
SmallVec,
1412
};
15-
use crate::internal::partial_solution::{DecisionLevel, PartialSolution};
16-
use crate::internal::small_vec::SmallVec;
17-
use crate::report::DerivationTree;
18-
use crate::solver::DependencyProvider;
19-
use crate::type_aliases::{IncompDpId, Map};
20-
use crate::version_set::VersionSet;
13+
use crate::{DependencyProvider, DerivationTree, Map, NoSolutionError, VersionSet};
2114

2215
/// Current state of the PubGrub algorithm.
2316
#[derive(Clone)]
24-
pub struct State<DP: DependencyProvider> {
17+
pub(crate) struct State<DP: DependencyProvider> {
2518
root_package: DP::P,
2619
root_version: DP::V,
2720

@@ -40,10 +33,10 @@ pub struct State<DP: DependencyProvider> {
4033

4134
/// Partial solution.
4235
/// TODO: remove pub.
43-
pub partial_solution: PartialSolution<DP>,
36+
pub(crate) partial_solution: PartialSolution<DP>,
4437

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

4841
/// This is a stack of work to be done in `unit_propagation`.
4942
/// It can definitely be a local variable to that method, but
@@ -53,7 +46,7 @@ pub struct State<DP: DependencyProvider> {
5346

5447
impl<DP: DependencyProvider> State<DP> {
5548
/// Initialization of PubGrub state.
56-
pub fn init(root_package: DP::P, root_version: DP::V) -> Self {
49+
pub(crate) fn init(root_package: DP::P, root_version: DP::V) -> Self {
5750
let mut incompatibility_store = Arena::new();
5851
let not_root_id = incompatibility_store.alloc(Incompatibility::not_root(
5952
root_package.clone(),
@@ -74,13 +67,13 @@ impl<DP: DependencyProvider> State<DP> {
7467
}
7568

7669
/// Add an incompatibility to the state.
77-
pub fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
70+
pub(crate) fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
7871
let id = self.incompatibility_store.alloc(incompat);
7972
self.merge_incompatibility(id);
8073
}
8174

8275
/// Add an incompatibility to the state.
83-
pub fn add_incompatibility_from_dependencies(
76+
pub(crate) fn add_incompatibility_from_dependencies(
8477
&mut self,
8578
package: DP::P,
8679
version: DP::V,
@@ -105,7 +98,7 @@ impl<DP: DependencyProvider> State<DP> {
10598

10699
/// Unit propagation is the core mechanism of the solving algorithm.
107100
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
108-
pub fn unit_propagation(&mut self, package: DP::P) -> Result<(), NoSolutionError<DP>> {
101+
pub(crate) fn unit_propagation(&mut self, package: DP::P) -> Result<(), NoSolutionError<DP>> {
109102
self.unit_propagation_buffer.clear();
110103
self.unit_propagation_buffer.push(package);
111104
while let Some(current_package) = self.unit_propagation_buffer.pop() {
@@ -202,7 +195,7 @@ impl<DP: DependencyProvider> State<DP> {
202195
&self.incompatibility_store,
203196
);
204197
match satisfier_search_result {
205-
DifferentDecisionLevels {
198+
SatisfierSearch::DifferentDecisionLevels {
206199
previous_satisfier_level,
207200
} => {
208201
let package = package.clone();
@@ -214,7 +207,7 @@ impl<DP: DependencyProvider> State<DP> {
214207
log::info!("backtrack to {:?}", previous_satisfier_level);
215208
return Ok((package, current_incompat_id));
216209
}
217-
SameDecisionLevels { satisfier_cause } => {
210+
SatisfierSearch::SameDecisionLevels { satisfier_cause } => {
218211
let prior_cause = Incompatibility::prior_cause(
219212
current_incompat_id,
220213
satisfier_cause,
@@ -248,10 +241,10 @@ impl<DP: DependencyProvider> State<DP> {
248241

249242
/// Add this incompatibility into the set of all incompatibilities.
250243
///
251-
/// Pub collapses identical dependencies from adjacent package versions
244+
/// PubGrub collapses identical dependencies from adjacent package versions
252245
/// into individual incompatibilities.
253246
/// This substantially reduces the total number of incompatibilities
254-
/// and makes it much easier for Pub to reason about multiple versions of packages at once.
247+
/// and makes it much easier for PubGrub to reason about multiple versions of packages at once.
255248
///
256249
/// For example, rather than representing
257250
/// foo 1.0.0 depends on bar ^1.0.0 and

0 commit comments

Comments
 (0)