Skip to content

Commit a7a1341

Browse files
committed
address suggestions
1 parent 997b3dc commit a7a1341

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

src/cargo/core/resolver/conflict_cache.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ pub(super) struct ConflictCache {
4141
}
4242

4343
impl ConflictCache {
44-
pub(super) fn new() -> ConflictCache {
44+
pub fn new() -> ConflictCache {
4545
ConflictCache {
4646
con_from_dep: HashMap::new(),
4747
dep_from_pid: HashMap::new(),
4848
}
4949
}
50-
pub(super) fn filter_conflicting<F>(
50+
/// Finds any known set of conflicts, if any,
51+
/// which are activated in `cx` and pass the `filter` specified?
52+
pub fn find_conflicting<F>(
5153
&self,
5254
cx: &Context,
5355
dep: &Dependency,
@@ -56,21 +58,24 @@ impl ConflictCache {
5658
where
5759
for<'r> F: FnMut(&'r &HashMap<PackageId, ConflictReason>) -> bool,
5860
{
59-
self.con_from_dep.get(dep).and_then(|past_bad| {
60-
past_bad
61-
.iter()
62-
.filter(filter)
63-
.find(|conflicting| cx.is_conflicting(None, conflicting))
64-
})
61+
self.con_from_dep
62+
.get(dep)?
63+
.iter()
64+
.filter(filter)
65+
.find(|conflicting| cx.is_conflicting(None, conflicting))
6566
}
66-
pub(super) fn conflicting(
67+
pub fn conflicting(
6768
&self,
6869
cx: &Context,
6970
dep: &Dependency,
7071
) -> Option<&HashMap<PackageId, ConflictReason>> {
71-
self.filter_conflicting(cx, dep, |_| true)
72+
self.find_conflicting(cx, dep, |_| true)
7273
}
73-
pub(super) fn insert(&mut self, dep: &Dependency, con: &HashMap<PackageId, ConflictReason>) {
74+
75+
/// Add to the cache a conflict of the form:
76+
/// `dep` is known to be unresolvable if
77+
/// all the `PackageId` entries are activated
78+
pub fn insert(&mut self, dep: &Dependency, con: &HashMap<PackageId, ConflictReason>) {
7479
let past = self.con_from_dep
7580
.entry(dep.clone())
7681
.or_insert_with(Vec::new);
@@ -85,7 +90,7 @@ impl ConflictCache {
8590
}
8691
}
8792
}
88-
pub(super) fn get_dep_from_pid(&self, pid: &PackageId) -> Option<&HashSet<Dependency>> {
93+
pub fn dependencies_conflicting_with(&self, pid: &PackageId) -> Option<&HashSet<Dependency>> {
8994
self.dep_from_pid.get(pid)
9095
}
9196
}

src/cargo/core/resolver/mod.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,12 @@ impl DepsFrame {
596596
.unwrap_or(0)
597597
}
598598

599-
fn flatten<'s>(&'s self) -> Box<Iterator<Item = (PackageId, Dependency)> + 's> {
599+
fn flatten<'s>(&'s self) -> Box<Iterator<Item = (&PackageId, Dependency)> + 's> {
600600
// TODO: with impl Trait the Box can be removed
601601
Box::new(
602602
self.remaining_siblings
603603
.clone()
604-
.map(move |(_, (d, _, _))| (self.parent.package_id().clone(), d)),
604+
.map(move |(_, (d, _, _))| (self.parent.package_id(), d)),
605605
)
606606
}
607607
}
@@ -1238,18 +1238,20 @@ fn activate_deps_loop(
12381238
})
12391239
.next()
12401240
{
1241-
let mut conflicting = conflicting.clone();
1242-
1243-
// If one of our deps conflicts with
1241+
// If one of our deps is known unresolvable
12441242
// then we will not succeed.
12451243
// How ever if we are part of the reason that
12461244
// one of our deps conflicts then
12471245
// we can make a stronger statement
12481246
// because we will definitely be activated when
12491247
// we try our dep.
1250-
conflicting.remove(&pid);
1248+
conflicting_activations.extend(
1249+
conflicting
1250+
.iter()
1251+
.filter(|&(p, _)| p != &pid)
1252+
.map(|(p, r)| (p.clone(), r.clone())),
1253+
);
12511254

1252-
conflicting_activations.extend(conflicting);
12531255
has_past_conflicting_dep = true;
12541256
}
12551257
}
@@ -1261,16 +1263,18 @@ fn activate_deps_loop(
12611263
// ourselves are incompatible with that dep, so we know that deps
12621264
// parent conflict with us.
12631265
if !has_past_conflicting_dep {
1264-
if let Some(rel_deps) = past_conflicting_activations.get_dep_from_pid(&pid)
1266+
if let Some(known_related_bad_deps) =
1267+
past_conflicting_activations.dependencies_conflicting_with(&pid)
12651268
{
12661269
if let Some((other_parent, conflict)) = remaining_deps
12671270
.iter()
12681271
.flat_map(|other| other.flatten())
12691272
// for deps related to us
1270-
.filter(|&(_, ref other_dep)| rel_deps.contains(other_dep))
1273+
.filter(|&(_, ref other_dep)|
1274+
known_related_bad_deps.contains(other_dep))
12711275
.filter_map(|(other_parent, other_dep)| {
12721276
past_conflicting_activations
1273-
.filter_conflicting(
1277+
.find_conflicting(
12741278
&cx,
12751279
&other_dep,
12761280
|con| con.contains_key(&pid)
@@ -1279,19 +1283,22 @@ fn activate_deps_loop(
12791283
})
12801284
.next()
12811285
{
1282-
let mut conflict = conflict.clone();
12831286
let rel = conflict.get(&pid).unwrap().clone();
1287+
12841288
// The conflict we found is
12851289
// "other dep will not succeed if we are activated."
12861290
// We want to add
12871291
// "our dep will not succeed if other dep is in remaining_deps"
12881292
// but that is not how the cache is set up.
12891293
// So we add the less general but much faster,
12901294
// "our dep will not succeed if other dep's parent is activated".
1291-
conflict.insert(other_parent.clone(), rel);
1292-
conflict.remove(&pid);
1293-
1294-
conflicting_activations.extend(conflict);
1295+
conflicting_activations.extend(
1296+
conflict
1297+
.iter()
1298+
.filter(|&(p, _)| p != &pid)
1299+
.map(|(p, r)| (p.clone(), r.clone())),
1300+
);
1301+
conflicting_activations.insert(other_parent.clone(), rel);
12951302
has_past_conflicting_dep = true;
12961303
}
12971304
}

tests/testsuite/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ fn resolving_with_constrained_cousins_backtrack() {
825825
reglist.push(
826826
pkg!((format!("level{}", DEPTH).as_str(), "1.0.0") => [dep_req("backtrack_trap0", "*"),
827827
dep_req("cloaking", "*")
828-
]),
828+
]),
829829
);
830830

831831
let reg = registry(reglist.clone());

0 commit comments

Comments
 (0)