Skip to content

Commit 9d86b82

Browse files
committed
The topological sort in the SAT solver was messed up by a refactor
1 parent a7648c7 commit 9d86b82

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub type Activations =
5757
/// A type that represents when cargo treats two Versions as compatible.
5858
/// Versions `a` and `b` are compatible if their left-most nonzero digit is the
5959
/// same.
60-
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
60+
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
6161
pub enum SemverCompatibility {
6262
Major(NonZeroU64),
6363
Minor(NonZeroU64),

tests/testsuite/resolve.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,20 @@ fn public_dependency_skipping_in_backtracking() {
380380
resolve(pkg_id("root"), vec![dep("C")], &reg).unwrap();
381381
}
382382

383+
#[test]
384+
fn public_sat_topological_order() {
385+
let input = vec![
386+
pkg!(("a", "0.0.1")),
387+
pkg!(("a", "0.0.0")),
388+
pkg!(("b", "0.0.1") => [dep_req_kind("a", "= 0.0.1", Kind::Normal, true),]),
389+
pkg!(("b", "0.0.0") => [dep("bad"),]),
390+
pkg!("A" => [dep_req("a", "= 0.0.0"),dep_req_kind("b", "*", Kind::Normal, true)]),
391+
];
392+
393+
let reg = registry(input);
394+
assert!(resolve_and_validated(pkg_id("root"), vec![dep("A")], &reg, None).is_err());
395+
}
396+
383397
#[test]
384398
#[should_panic(expected = "assertion failed: !name.is_empty()")]
385399
fn test_dependency_with_empty_name() {

tests/testsuite/support/resolver.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ fn sat_at_most_one(solver: &mut impl varisat::ExtendFormula, vars: &[varisat::Va
203203
return;
204204
} else if vars.len() == 2 {
205205
solver.add_clause(&[vars[0].negative(), vars[1].negative()]);
206+
return;
206207
} else if vars.len() == 3 {
207208
solver.add_clause(&[vars[0].negative(), vars[1].negative()]);
208209
solver.add_clause(&[vars[0].negative(), vars[2].negative()]);
209210
solver.add_clause(&[vars[1].negative(), vars[2].negative()]);
211+
return;
210212
}
211213
// use the "Binary Encoding" from
212214
// https://www.it.uu.se/research/group/astra/ModRef10/papers/Alan%20M.%20Frisch%20and%20Paul%20A.%20Giannoros.%20SAT%20Encodings%20of%20the%20At-Most-k%20Constraint%20-%20ModRef%202010.pdf
@@ -305,6 +307,7 @@ impl SatResolve {
305307
.iter()
306308
.filter(|&p| dep.matches_id(*p))
307309
{
310+
graph.link(p.package_id(), m);
308311
by_key
309312
.entry(m.as_activations_key())
310313
.or_default()

0 commit comments

Comments
 (0)