Skip to content

Commit

Permalink
add the original optimization in for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed May 15, 2019
1 parent c0be9ce commit 8080c98
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ fn activate_deps_loop(
&cx,
registry,
&mut past_conflicting_activations,
&parent,
&dep,
&conflicting_activations,
) {
Expand Down Expand Up @@ -854,10 +855,11 @@ fn generalize_conflicting(
cx: &Context,
registry: &mut RegistryQueryer<'_>,
past_conflicting_activations: &mut conflict_cache::ConflictCache,
parent: &Summary,
dep: &Dependency,
conflicting_activations: &ConflictMap,
) -> Option<ConflictMap> {
if conflicting_activations.len() != 1 {
if conflicting_activations.is_empty() {
return None;
}
// We need to determine the `ContextAge` that this `conflicting_activations` will jump to, and why.
Expand All @@ -869,6 +871,16 @@ fn generalize_conflicting(
let backtrack_critical_reason: ConflictReason =
conflicting_activations[&backtrack_critical_id].clone();

if cx
.parents
.is_path_from_to(&parent.package_id(), &backtrack_critical_id)
{
// We are a descendant of the trigger of the problem.
// The best generalization of this is to let things bubble up
// and let `backtrack_critical_id` figure this out.
return None;
}

// we will need to know the range of versions we can use
let our_candidates = registry
.query(dep)
Expand Down Expand Up @@ -905,10 +917,6 @@ fn generalize_conflicting(
None
};

if !(our_activation_key.is_some() || our_link.is_some()) {
return None;
}

let our_candidates: HashSet<PackageId> =
our_candidates.iter().map(|our| our.package_id()).collect();

Expand All @@ -920,6 +928,9 @@ fn generalize_conflicting(
})
{
'dep: for critical_parents_dep in critical_parents_deps.iter() {
// A dep is equivalent to one of the things it can resolve to.
// Thus, if all the things it can resolve to have already ben determined
// to be conflicting, then we can just say that we conflict with the parent.
let mut con = conflicting_activations.clone();
con.remove(&backtrack_critical_id);
con.insert(*critical_parent, backtrack_critical_reason.clone());
Expand All @@ -928,6 +939,8 @@ fn generalize_conflicting(
.query(critical_parents_dep)
.expect("an already used dep now error!?")
.iter()
.rev()
// the last one to be tried is the least likely to be in the cache, so start with that.
{
if (our_activation_key
.map_or(false, |our| other.package_id().as_activations_key() == our)
Expand All @@ -950,9 +963,32 @@ fn generalize_conflicting(
) {
con.extend(conflicting.into_iter());
continue;
} else {
continue 'dep;
}

if let Some(conflicting) = past_conflicting_activations.find(
dep,
&|id| {
if id == other.package_id() {
// we are imagining that we used other instead
Some(backtrack_critical_age)
} else {
cx.is_active(id).filter(|&age|
// we only care about things that are older then critical_age
age < backtrack_critical_age)
}
},
Some(other.package_id()),
) {
con.extend(
conflicting
.iter()
.filter(|(&id, _)| id != other.package_id())
.map(|(&id, r)| (id, r.clone())),
);
continue;
}

continue 'dep;
}

if cfg!(debug_assertions) {
Expand Down

0 comments on commit 8080c98

Please sign in to comment.