Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add the original optimization in for good measure
  • Loading branch information
Eh2406 committed May 15, 2019
commit 8080c98a1d751a97e77dadbe65d3fce4aff6fc1e
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in need of some rustfmt here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fmt on save, but it seems to be some kind of fmt bug. If the comment is in the callback fmt will not move it.

}
},
Some(other.package_id()),
) {
con.extend(
conflicting
.iter()
.filter(|(&id, _)| id != other.package_id())
.map(|(&id, r)| (id, r.clone())),
);
continue;
}

continue 'dep;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be a comment here indicating why we're breaking to the outer loop and cancelling this part of the search?

}

if cfg!(debug_assertions) {
Expand Down