Skip to content

Commit

Permalink
refactor: dont copy the term for Contradicted
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Apr 17, 2021
1 parent 81cdac3 commit 23e9657
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,16 @@ enum Kind<P: Package, V: Version> {
DerivedFrom(IncompId<P, V>, IncompId<P, V>),
}

/// A type alias for a pair of [Package] and a corresponding [Term].
pub type PackageTerm<P, V> = (P, Term<V>);

/// A Relation describes how a set of terms can be compared to an incompatibility.
/// Typically, the set of terms comes from the partial solution.
#[derive(Eq, PartialEq)]
pub enum Relation<P: Package, V: Version> {
pub enum Relation<P: Package> {
/// We say that a set of terms S satisfies an incompatibility I
/// if S satisfies every term in I.
Satisfied,
/// We say that S contradicts I
/// if S contradicts at least one term in I.
Contradicted(PackageTerm<P, V>),
Contradicted(P),
/// If S satisfies all but one of I's terms and is inconclusive for the remaining term,
/// we say S "almost satisfies" I and we call the remaining term the "unsatisfied term".
AlmostSatisfied(P),
Expand Down Expand Up @@ -166,13 +163,13 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
}

/// CF definition of Relation enum.
pub fn relation(&self, mut terms: impl FnMut(&P) -> Option<Term<V>>) -> Relation<P, V> {
pub fn relation(&self, mut terms: impl FnMut(&P) -> Option<Term<V>>) -> Relation<P> {
let mut relation = Relation::Satisfied;
for (package, incompat_term) in self.package_terms.iter() {
match terms(package).map(|term| incompat_term.relation_with(&term)) {
Some(term::Relation::Satisfied) => {}
Some(term::Relation::Contradicted) => {
return Relation::Contradicted((package.clone(), incompat_term.clone()));
return Relation::Contradicted(package.clone());
}
None | Some(term::Relation::Inconclusive) => {
// If a package is not present, the intersection is the same as [Term::any].
Expand Down
2 changes: 1 addition & 1 deletion src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<P: Package, V: Version> PartialSolution<P, V> {
}

/// Check if the terms in the partial solution satisfy the incompatibility.
pub fn relation(&mut self, incompat: &Incompatibility<P, V>) -> Relation<P, V> {
pub fn relation(&mut self, incompat: &Incompatibility<P, V>) -> Relation<P> {
incompat.relation(|package| self.memory.term_intersection_for_package(package).cloned())
}

Expand Down

0 comments on commit 23e9657

Please sign in to comment.