Skip to content

Commit

Permalink
Add a reason to the NoVersions incompatibility (#22)
Browse files Browse the repository at this point in the history
* Add a `reason` to the `NoVersions` incompatibility

* Make optional
  • Loading branch information
zanieb authored and konstin committed Mar 22, 2024
1 parent 941adc5 commit 7da0615
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
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 @@ -66,7 +66,7 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
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
29 changes: 17 additions & 12 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub type IncompId<P, VS> = Id<Incompatibility<P, VS>>;
pub enum Kind<P: Package, VS: VersionSet> {
/// 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.
NoVersions(P, VS),
/// There are no versions in the given range for this package. A string reason may be included.
NoVersions(P, VS, Option<String>),
/// The package is unavailable for versions in the range. A string reason is included.
Unavailable(P, VS, String),
/// Incompatibility coming from the dependencies of a given package.
Expand Down Expand Up @@ -87,14 +87,14 @@ impl<P: Package, VS: VersionSet> Incompatibility<P, VS> {

/// Create an incompatibility to remember
/// that a given set does not contain any version.
pub fn no_versions(package: P, term: Term<VS>) -> Self {
pub fn no_versions(package: P, term: Term<VS>, reason: Option<String>) -> 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),
kind: Kind::NoVersions(package, set, reason),
}
}

Expand Down Expand Up @@ -254,15 +254,20 @@ impl<P: Package, VS: VersionSet> Incompatibility<P, VS> {
Kind::NotRoot(package, version) => {
DerivationTree::External(External::NotRoot(package, version))
}
Kind::NoVersions(package, set) => {
DerivationTree::External(External::NoVersions(package, set))
}
Kind::Unavailable(package, set, reason) => {
DerivationTree::External(External::Unavailable(package, set, reason))
}
Kind::FromDependencyOf(package, set, dep_package, dep_set) => DerivationTree::External(
External::FromDependencyOf(package, set, dep_package, dep_set),
Kind::NoVersions(package, set, reason) => DerivationTree::External(
External::NoVersions(package.clone(), set.clone(), reason.clone()),
),
Kind::Unavailable(package, set, reason) => DerivationTree::External(
External::Unavailable(package.clone(), set.clone(), reason.clone()),
),
Kind::FromDependencyOf(package, set, dep_package, dep_set) => {
DerivationTree::External(External::FromDependencyOf(
package.clone(),
set.clone(),
dep_package.clone(),
dep_set.clone(),
))
}
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub enum DerivationTree<P: Package, VS: VersionSet> {
pub enum External<P: Package, VS: VersionSet> {
/// 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.
NoVersions(P, VS),
/// There are no versions in the given set for this package. A string reason is included.
NoVersions(P, VS, Option<String>),
/// The package is unusable in the given set. A string reason is included.
Unavailable(P, VS, String),
/// Incompatibility coming from the dependencies of a given package.
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<P: Package, VS: VersionSet> DerivationTree<P, VS> {
packages.insert(p);
packages.insert(p2);
}
External::NoVersions(p, _)
External::NoVersions(p, _, _)
| External::NotRoot(p, _)
| External::Unavailable(p, ..) => {
packages.insert(p);
Expand Down Expand Up @@ -113,14 +113,14 @@ impl<P: Package, VS: VersionSet> DerivationTree<P, VS> {
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 All @@ -144,9 +144,9 @@ impl<P: Package, VS: VersionSet> DerivationTree<P, VS> {
DerivationTree::External(External::NotRoot(_, _)) => {
panic!("How did we end up with a NoVersions merged with a NotRoot?")
}
DerivationTree::External(External::NoVersions(_, r)) => Some(DerivationTree::External(
External::NoVersions(package, set.union(&r)),
)),
//
// Cannot be merged because the reason may not match
DerivationTree::External(External::NoVersions(_, _, _)) => None,
// Cannot be merged because the reason may not match
DerivationTree::External(External::Unavailable(_, _, _)) => None,
DerivationTree::External(External::FromDependencyOf(p1, r1, p2, r2)) => {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<P: Package, VS: VersionSet> fmt::Display for External<P, VS> {
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
3 changes: 2 additions & 1 deletion src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ 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());
let inc =
Incompatibility::no_versions(next.clone(), term_intersection.clone(), None);
state.add_incompatibility(inc);
continue;
}
Expand Down

0 comments on commit 7da0615

Please sign in to comment.