Skip to content

Commit

Permalink
Auto merge of #6980 - Eh2406:varisat, r=alexcrichton
Browse files Browse the repository at this point in the history
Test the Resolver against the varisat Library

Resolution can be reduced to the SAT problem. So this is an alternative implementation of the resolver that uses a SAT library for the hard work. This is intended to be easy to read, as compared to the real resolver, and run as part of the test sweet to make sure the real resolver works as expected. Part of #6120.

Some notes on performance:
The initial version did not support public & private deps:
~64 loc, `O(nln(n))` vars, `O(nln(n) + n*d)` clauses, 0.5x slower on `prop_passes_validation`
The final version:
~163 loc, `O(dn^2`) vars, `O(dn^3)`  clauses, 1.5x slower on `prop_passes_validation`

That comparison makes me feel better about spending months trying to get public & private deps to be fast enough for stabilization.
  • Loading branch information
bors committed May 28, 2019
2 parents 66ff186 + e08d032 commit a7648c7
Show file tree
Hide file tree
Showing 3 changed files with 323 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ features = [
[dev-dependencies]
bufstream = "0.1"
proptest = "0.9.1"
varisat = "0.2.1"

[[bin]]
name = "cargo"
Expand Down
26 changes: 20 additions & 6 deletions tests/testsuite/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::support::registry::Package;
use crate::support::resolver::{
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, dep_req_kind, loc_names, names,
pkg, pkg_dep, pkg_id, pkg_loc, registry, registry_strategy, remove_dep, resolve,
resolve_and_validated, resolve_with_config, PrettyPrintRegistry, ToDep, ToPkgId,
resolve_and_validated, resolve_with_config, PrettyPrintRegistry, SatResolve, ToDep, ToPkgId,
};

use proptest::prelude::*;
Expand Down Expand Up @@ -41,6 +41,7 @@ proptest! {
PrettyPrintRegistry(input) in registry_strategy(50, 20, 60)
) {
let reg = registry(input.clone());
let mut sat_resolve = SatResolve::new(&reg);
// there is only a small chance that any one
// crate will be interesting.
// So we try some of the most complicated.
Expand All @@ -49,6 +50,7 @@ proptest! {
pkg_id("root"),
vec![dep_req(&this.name(), &format!("={}", this.version()))],
&reg,
Some(&mut sat_resolve),
);
}
}
Expand Down Expand Up @@ -236,6 +238,18 @@ proptest! {
}
}

#[test]
fn pub_fail() {
let input = vec![
pkg!(("a", "0.0.4")),
pkg!(("a", "0.0.5")),
pkg!(("e", "0.0.6") => [dep_req_kind("a", "<= 0.0.4", Kind::Normal, true),]),
pkg!(("kB", "0.0.3") => [dep_req("a", ">= 0.0.5"),dep("e"),]),
];
let reg = registry(input.clone());
assert!(resolve_and_validated(pkg_id("root"), vec![dep("kB")], &reg, None).is_err());
}

#[test]
fn basic_public_dependency() {
let reg = registry(vec![
Expand All @@ -245,7 +259,7 @@ fn basic_public_dependency() {
pkg!("C" => [dep("A"), dep("B")]),
]);

let res = resolve_and_validated(pkg_id("root"), vec![dep("C")], &reg).unwrap();
let res = resolve_and_validated(pkg_id("root"), vec![dep("C")], &reg, None).unwrap();
assert_same(
&res,
&names(&[
Expand Down Expand Up @@ -281,7 +295,7 @@ fn public_dependency_filling_in() {
pkg!("d" => [dep("c"), dep("a"), dep("b")]),
]);

let res = resolve_and_validated(pkg_id("root"), vec![dep("d")], &reg).unwrap();
let res = resolve_and_validated(pkg_id("root"), vec![dep("d")], &reg, None).unwrap();
assert_same(
&res,
&names(&[
Expand Down Expand Up @@ -316,7 +330,7 @@ fn public_dependency_filling_in_and_update() {
pkg!("C" => [dep("A"),dep("B")]),
pkg!("D" => [dep("B"),dep("C")]),
]);
let res = resolve_and_validated(pkg_id("root"), vec![dep("D")], &reg).unwrap();
let res = resolve_and_validated(pkg_id("root"), vec![dep("D")], &reg, None).unwrap();
assert_same(
&res,
&names(&[
Expand Down Expand Up @@ -1407,7 +1421,7 @@ fn conflict_store_bug() {
];

let reg = registry(input);
let _ = resolve_and_validated(pkg_id("root"), vec![dep("j")], &reg);
let _ = resolve_and_validated(pkg_id("root"), vec![dep("j")], &reg, None);
}

#[test]
Expand Down Expand Up @@ -1435,5 +1449,5 @@ fn conflict_store_more_then_one_match() {
]),
];
let reg = registry(input);
let _ = resolve_and_validated(pkg_id("root"), vec![dep("nA")], &reg);
let _ = resolve_and_validated(pkg_id("root"), vec![dep("nA")], &reg, None);
}
Loading

0 comments on commit a7648c7

Please sign in to comment.