Skip to content

Commit

Permalink
Make incompatibilities pub again
Browse files Browse the repository at this point in the history
I must have dropped this when rebasing
  • Loading branch information
konstin committed May 2, 2024
1 parent d832378 commit 36d2cbc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 32 deletions.
40 changes: 25 additions & 15 deletions examples/caching_dependency_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,37 @@ impl<DP: DependencyProvider<M = String>> DependencyProvider for CachingDependenc
&self,
package: &DP::P,
version: &DP::V,
) -> Result<Dependencies<DP::P, DP::VS, DP::M>, DP::Err> {
) -> Result<Dependencies<impl IntoIterator<Item = (Self::P, Self::VS)> + Clone, Self::M>, DP::Err>
{
let mut cache = self.cached_dependencies.borrow_mut();
match cache.get_dependencies(package, version) {
Ok(Dependencies::Unavailable(_)) => {
let dependencies = self.remote_dependencies.get_dependencies(package, version);
match dependencies {
Ok(Dependencies::Available(dependencies)) => {
cache.add_dependencies(
package.clone(),
version.clone(),
dependencies.clone(),
);
Ok(Dependencies::Available(dependencies))
}
Ok(Dependencies::Unavailable(reason)) => Ok(Dependencies::Unavailable(reason)),
error @ Err(_) => error,
}
// Code below to end the borrow.
}
Ok(dependencies) => {
return Ok(match dependencies {
Dependencies::Unavailable(reason) => Dependencies::Unavailable(reason),
Dependencies::Available(available) => Dependencies::Available(
available.into_iter().collect::<Vec<(Self::P, Self::VS)>>(),
),
})
}
Ok(dependencies) => Ok(dependencies),
Err(_) => unreachable!(),
}
let dependencies = self.remote_dependencies.get_dependencies(package, version);
match dependencies {
Ok(Dependencies::Available(dependencies)) => {
cache.add_dependencies(package.clone(), version.clone(), dependencies.clone());
Ok(Dependencies::Available(
dependencies
.clone()
.into_iter()
.collect::<Vec<(Self::P, Self::VS)>>(),
))
}
Ok(Dependencies::Unavailable(reason)) => Ok(Dependencies::Unavailable(reason)),
Err(err) => Err(err),
}
}

fn choose_version(&self, package: &DP::P, range: &DP::VS) -> Result<Option<DP::V>, DP::Err> {
Expand Down
2 changes: 1 addition & 1 deletion examples/unsat_root_message_no_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ReportFormatter<Package, Range<SemanticVersion>, String> for CustomReportFo
External::NotRoot(package, version) => {
format!("we are solving dependencies of {package} {version}")
}
External::NoVersions(package, set, _) => {
External::NoVersions(package, set) => {
if set == &Range::full() {
format!("there is no available version for {package}")
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct State<DP: DependencyProvider> {

/// The set of incompatibilities for each package.
#[allow(clippy::type_complexity)]
incompatibilities: Map<DP::P, Vec<IncompDpId<DP>>>,
pub incompatibilities: Map<DP::P, Vec<IncompDpId<DP>>>,

/// Store the ids of incompatibilities that are already contradicted.
/// For each one keep track of the decision level when it was found to be contradicted.
Expand Down
4 changes: 2 additions & 2 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
}

/// Create an incompatibility to remember that a given set does not contain any version.
pub fn no_versions(package: P, term: Term<VS>, reason: Option<String>) -> Self {
pub fn no_versions(package: P, term: Term<VS>) -> Self {
let set = match &term {
Term::Positive(r) => r.clone(),
Term::Negative(_) => panic!("No version should have a positive term"),
};
Self {
package_terms: SmallMap::One([(package.clone(), term)]),
kind: Kind::NoVersions(package, set, reason),
kind: Kind::NoVersions(package, set),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
//! &self,
//! package: &String,
//! version: &SemanticVersion,
//! ) -> Result<Dependencies<String, SemVS, Self::M>, Infallible> {
//! unimplemented!()
//! ) -> Result<Dependencies<impl IntoIterator<Item = (Self::P, Self::VS)> + Clone, Self::M>, Infallible> {
//! Ok(Dependencies::Available([]))
//! }
//!
//! type Err = Infallible;
Expand Down
10 changes: 5 additions & 5 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum External<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
/// Initial incompatibility aiming at picking the root package for the first decision.
NotRoot(P, VS::V),
/// There are no versions in the given set for this package. A string reason is included.
NoVersions(P, VS, Option<String>),
NoVersions(P, VS),
/// Incompatibility coming from the dependencies of a given package.
FromDependencyOf(P, VS, P, VS),
/// The package is unusable for reasons outside pubgrub.
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
packages.insert(p);
packages.insert(p2);
}
External::NoVersions(p, _, _)
External::NoVersions(p, _)
| External::NotRoot(p, _)
| External::Custom(p, _, _) => {
packages.insert(p);
Expand Down Expand Up @@ -112,14 +112,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
Arc::make_mut(&mut derived.cause1),
Arc::make_mut(&mut derived.cause2),
) {
(DerivationTree::External(External::NoVersions(p, r, _)), ref mut cause2) => {
(DerivationTree::External(External::NoVersions(p, r)), ref mut cause2) => {
cause2.collapse_no_versions();
*self = cause2
.clone()
.merge_no_versions(p.to_owned(), r.to_owned())
.unwrap_or_else(|| self.to_owned());
}
(ref mut cause1, DerivationTree::External(External::NoVersions(p, r, _))) => {
(ref mut cause1, DerivationTree::External(External::NoVersions(p, r))) => {
cause1.collapse_no_versions();
*self = cause1
.clone()
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> fmt::Display
Self::NotRoot(package, version) => {
write!(f, "we are solving dependencies of {} {}", package, version)
}
Self::NoVersions(package, set, _) => {
Self::NoVersions(package, set) => {
if set == &VS::full() {
write!(f, "there is no available version for {}", package)
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ pub fn resolve<DP: DependencyProvider>(
// Pick the next compatible version.
let v = match decision {
None => {
let inc =
Incompatibility::no_versions(next.clone(), term_intersection.clone(), None);
let inc = Incompatibility::no_versions(next.clone(), term_intersection.clone());
state.add_incompatibility(inc);
continue;
}
Expand Down Expand Up @@ -193,7 +192,7 @@ pub fn resolve<DP: DependencyProvider>(
/// An enum used by [DependencyProvider] that holds information about package dependencies.
/// For each [Package] there is a set of versions allowed as a dependency.
#[derive(Clone)]
pub enum Dependencies<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
pub enum Dependencies<T, M: Eq + Clone + Debug + Display> {
/// Package dependencies are unavailable with the reason why they are missing.
Unavailable(M),
/// Container for all available package versions.
Expand Down Expand Up @@ -284,7 +283,10 @@ pub trait DependencyProvider {
&self,
package: &Self::P,
version: &Self::V,
) -> Result<Dependencies<impl IntoIterator<Item = (Self::P, Self::VS)> + Clone, Self::M>, Self::Err>;
) -> Result<
Dependencies<impl IntoIterator<Item = (Self::P, Self::VS)> + Clone, Self::M>,
Self::Err,
>;

/// This is called fairly regularly during the resolution,
/// if it returns an Err then resolution will be terminated.
Expand Down
5 changes: 3 additions & 2 deletions tests/proptest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<P: Package, VS: VersionSet> DependencyProvider for OldestVersionsDependency
&self,
p: &P,
v: &VS::V,
) -> Result<Dependencies<P, VS, Self::M>, Infallible> {
) -> Result<Dependencies<impl IntoIterator<Item = (P, VS)> + Clone, Self::M>, Infallible> {
self.0.get_dependencies(p, v)
}

Expand Down Expand Up @@ -90,7 +90,8 @@ impl<DP: DependencyProvider> DependencyProvider for TimeoutDependencyProvider<DP
&self,
p: &DP::P,
v: &DP::V,
) -> Result<Dependencies<DP::P, DP::VS, DP::M>, DP::Err> {
) -> Result<Dependencies<impl IntoIterator<Item = (DP::P, DP::VS)> + Clone, DP::M>, DP::Err>
{
self.dp.get_dependencies(p, v)
}

Expand Down

0 comments on commit 36d2cbc

Please sign in to comment.