Auto merge of #4834 - aidanhs:aphs-better-backtrack, r=alexcrichton
authorbors <bors@rust-lang.org>
Tue, 6 Feb 2018 17:05:37 +0000 (17:05 +0000)
committerbors <bors@rust-lang.org>
Tue, 6 Feb 2018 17:05:37 +0000 (17:05 +0000)
commitb7c2cfb86b81c4fce7f9d98db7a9d424eb0bc106
tree0134e9629796a3d3559aa1b21792a4409c994d7e
parenta99768918b5696d5ae9d4ae0b93bfd39ab8f3ca6
parenta85f9b6cf2142a5061ed4b4020be160444b5c49a
Auto merge of #4834 - aidanhs:aphs-better-backtrack, r=alexcrichton

Make resolution backtracking smarter

There's no need to try every candidate for every dependency when backtracking - instead, only try candidates if they *could* change the eventual failure that caused backtracking in the first place, i.e.
1. if we've backtracked past the parent of the dep that failed
2. the number of activations for the dep has changed (activations are only ever added during resolution I believe)

The two new tests before:
```
$ /usr/bin/time cargo test --test resolve -- --test-threads 1 --nocapture resolving_with_constrained_sibling_
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running target/debug/deps/resolve-19b2a13e5a19eed8
38.45user 2.16system 0:42.00elapsed 96%CPU (0avgtext+0avgdata 47672maxresident)k
0inputs+1664096outputs (0major+10921minor)pagefaults 0swaps
```
After:
```
$ /usr/bin/time cargo test --test resolve -- --test-threads 1 --nocapture resolving_with_constrained_sibling_
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running target/debug/deps/resolve-19b2a13e5a19eed8
[...]
0.36user 0.01system 0:00.49elapsed 76%CPU (0avgtext+0avgdata 47464maxresident)k
0inputs+32outputs (0major+11602minor)pagefaults 0swaps
```

You observe the issue yourself with the following (it should fail, but hangs for a while instead - I didn't bother timing it and waiting for it to finish. With this PR it terminates almost instantly):
```
$ cargo new --bin x
     Created binary (application) `x` project
$ /bin/echo -e 'serde = "=1.0.9"\nrust-s3 = "0.8"' >> x/Cargo.toml
$ cd x && cargo build
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Resolving dependency graph...
```
src/cargo/core/resolver/mod.rs