Skip to content

Commit

Permalink
perf: don't reuse the same incompatibility repeatedly
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed May 11, 2021
1 parent 9b2518e commit 285aba7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct State<P: Package, V: Version> {
root_version: V,

incompatibilities: Map<P, Vec<IncompId<P, V>>>,
used_incompatibilities: rustc_hash::FxHashSet<IncompId<P, V>>,

/// Partial solution.
/// TODO: remove pub.
Expand Down Expand Up @@ -52,6 +53,7 @@ impl<P: Package, V: Version> State<P, V> {
root_package,
root_version,
incompatibilities,
used_incompatibilities: rustc_hash::FxHashSet::default(),
partial_solution: PartialSolution::empty(),
incompatibility_store,
unit_propagation_buffer: vec![],
Expand Down Expand Up @@ -100,6 +102,9 @@ impl<P: Package, V: Version> State<P, V> {
let mut conflict_id = None;
// We only care about incompatibilities if it contains the current package.
for &incompat_id in self.incompatibilities[&current_package].iter().rev() {
if self.used_incompatibilities.contains(&incompat_id) {
continue;
}
let current_incompat = &self.incompatibility_store[incompat_id];
match self.partial_solution.relation(current_incompat) {
// If the partial solution satisfies the incompatibility
Expand All @@ -110,20 +115,25 @@ impl<P: Package, V: Version> State<P, V> {
}
Relation::AlmostSatisfied(package_almost) => {
self.unit_propagation_buffer.push(package_almost.clone());
self.used_incompatibilities.insert(incompat_id);
// Add (not term) to the partial solution with incompat as cause.
self.partial_solution.add_derivation(
package_almost,
incompat_id,
&self.incompatibility_store,
);
}
Relation::Contradicted(_) => {
self.used_incompatibilities.insert(incompat_id);
}
_ => {}
}
}
if let Some(incompat_id) = conflict_id {
let (package_almost, root_cause) = self.conflict_resolution(incompat_id)?;
self.unit_propagation_buffer.clear();
self.unit_propagation_buffer.push(package_almost.clone());
self.used_incompatibilities.insert(root_cause);
// Add to the partial solution with incompat as cause.
self.partial_solution.add_derivation(
package_almost,
Expand Down Expand Up @@ -200,6 +210,7 @@ impl<P: Package, V: Version> State<P, V> {
) {
self.partial_solution
.backtrack(decision_level, &self.incompatibility_store);
self.used_incompatibilities.clear();
if incompat_changed {
self.merge_incompatibility(incompat);
}
Expand Down

0 comments on commit 285aba7

Please sign in to comment.