From 10364243dc4925a7fcf7f9e950d4c893570b7cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Wed, 31 Jan 2024 13:33:52 +0100 Subject: [PATCH] fix: merge nodes more aggressively when unsat --- src/problem.rs | 9 --------- tests/snapshots/solver__merge_installable.snap | 10 ++++++++++ tests/snapshots/solver__unsat_constrains_2.snap | 13 +------------ tests/solver.rs | 11 +++++++++++ 4 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 tests/snapshots/solver__merge_installable.snap diff --git a/src/problem.rs b/src/problem.rs index a01c06d..060e61a 100644 --- a/src/problem.rs +++ b/src/problem.rs @@ -248,7 +248,6 @@ pub enum ConflictCause { /// - They all have the same name /// - They all have the same predecessor nodes /// - They all have the same successor nodes -/// - None of them have incoming conflicting edges pub(crate) struct MergedProblemNode { pub ids: Vec, } @@ -370,14 +369,6 @@ impl ProblemGraph { } }; - if graph - .edges_directed(node_id, Direction::Incoming) - .any(|e| matches!(e.weight(), ProblemEdge::Conflict(..))) - { - // Nodes that are the target of a conflict should never be merged - continue; - } - let predecessors: Vec<_> = graph .edges_directed(node_id, Direction::Incoming) .map(|e| e.source()) diff --git a/tests/snapshots/solver__merge_installable.snap b/tests/snapshots/solver__merge_installable.snap new file mode 100644 index 0000000..116a4c7 --- /dev/null +++ b/tests/snapshots/solver__merge_installable.snap @@ -0,0 +1,10 @@ +--- +source: tests/solver.rs +expression: "solve_snapshot(provider, &[\"a 0..3\", \"a 3..5\"])" +--- +The following packages are incompatible +|-- a >=3, <5 can be installed with any of the following options: + |-- a 3 | 4 +|-- a >=0, <3 cannot be installed because there are no viable options: + |-- a 1 | 2, which conflicts with the versions reported above. + diff --git a/tests/snapshots/solver__unsat_constrains_2.snap b/tests/snapshots/solver__unsat_constrains_2.snap index ac86396..05bc545 100644 --- a/tests/snapshots/solver__unsat_constrains_2.snap +++ b/tests/snapshots/solver__unsat_constrains_2.snap @@ -1,21 +1,10 @@ --- source: tests/solver.rs -assertion_line: 703 expression: error --- The following packages are incompatible |-- a * cannot be installed because there are no viable options: - |-- a 2 would require - |-- b *, which cannot be installed because there are no viable options: - |-- b 2 would require - |-- c >=2, <3, which cannot be installed because there are no viable options: - |-- c 2 would constrain - |-- a >=3, <4 , which conflicts with any installable versions previously reported - |-- b 1 would require - |-- c >=1, <2, which cannot be installed because there are no viable options: - |-- c 1 would constrain - |-- a >=3, <4 , which conflicts with any installable versions previously reported - |-- a 1 would require + |-- a 1 | 2 would require |-- b *, which cannot be installed because there are no viable options: |-- b 2 would require |-- c >=2, <3, which cannot be installed because there are no viable options: diff --git a/tests/solver.rs b/tests/solver.rs index e9fc230..42b9ebc 100644 --- a/tests/solver.rs +++ b/tests/solver.rs @@ -912,6 +912,17 @@ fn test_merge_excluded() { insta::assert_snapshot!(solve_snapshot(provider, &["a"])); } +#[test] +fn test_merge_installable() { + let provider = BundleBoxProvider::from_packages(&[ + ("a", 1, vec![]), + ("a", 2, vec![]), + ("a", 3, vec![]), + ("a", 4, vec![]), + ]); + insta::assert_snapshot!(solve_snapshot(provider, &["a 0..3", "a 3..5"])); +} + #[test] fn test_root_excluded() { let mut provider = BundleBoxProvider::from_packages(&[("a", 1, vec![])]);