-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Faster resolver: clean code and the backtrack_stack
#5187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
15c757a
617856e
1291c50
68e9577
59249d1
f5a0f28
dd9ff1f
c771a4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -951,12 +951,9 @@ fn activate_deps_loop( | |
&& past_conflicting_activations | ||
.get(&dep) | ||
.and_then(|past_bad| { | ||
past_bad.iter().find(|conflicting| { | ||
conflicting | ||
.iter() | ||
// note: a lot of redundant work in is_active for similar debs | ||
.all(|(con, _)| cx.is_active(con)) | ||
}) | ||
past_bad | ||
.iter() | ||
.find(|conflicting| cx.is_conflicting(None, conflicting)) | ||
}) | ||
.is_some(); | ||
|
||
|
@@ -1091,12 +1088,9 @@ fn activate_deps_loop( | |
.filter_map(|(_, (deb, _, _))| { | ||
past_conflicting_activations.get(&deb).and_then(|past_bad| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may actually be a great place to use past_conflicting_activations.get(&deb)?
.iter()
.find(|conflicts| cx.is_conflicting(None, conflicts)) (also this may want to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So much better! |
||
// for each dependency check all of its cashed conflicts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/cashed/cached/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks spelling is not my strong suit! I know I'd mess this one up at some point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh no worries, it's also not mine! |
||
past_bad.iter().find(|conflicting| { | ||
conflicting | ||
past_bad | ||
.iter() | ||
// note: a lot of redundant work in is_active for similar debs | ||
.all(|(con, _)| cx.is_active(con)) | ||
}) | ||
.find(|conflicting| cx.is_conflicting(None, conflicting)) | ||
}) | ||
}) | ||
.next() | ||
|
@@ -1123,6 +1117,14 @@ fn activate_deps_loop( | |
conflicting_activations | ||
); | ||
past.push(conflicting_activations.clone()); | ||
// also clean the `backtrack_stack` so we don't | ||
// backtrack to a place where we will try this again. | ||
backtrack_stack.retain(|bframe| { | ||
!bframe.context_backup.is_conflicting( | ||
Some(parent.package_id()), | ||
&conflicting_activations, | ||
) | ||
}); | ||
} | ||
} | ||
// if not has_another we we activate for the better error messages | ||
|
@@ -1195,11 +1197,9 @@ fn find_candidate<'a>( | |
frame.context_backup.prev_active(&frame.dep), | ||
&frame.context_backup.links, | ||
); | ||
if frame.context_backup.is_active(parent.package_id()) | ||
&& conflicting_activations | ||
.iter() | ||
// note: a lot of redundant work in is_active for similar debs | ||
.all(|(con, _)| frame.context_backup.is_active(con)) | ||
if frame | ||
.context_backup | ||
.is_conflicting(Some(parent.package_id()), conflicting_activations) | ||
{ | ||
continue; | ||
} | ||
|
@@ -1643,6 +1643,20 @@ impl Context { | |
.unwrap_or(false) | ||
} | ||
|
||
/// checks whether all of `parent` and the keys of `conflicting activations` | ||
/// are still active | ||
fn is_conflicting( | ||
&self, | ||
parent: Option<&PackageId>, | ||
conflicting_activations: &HashMap<PackageId, ConflictReason>, | ||
) -> bool { | ||
parent.map(|p| self.is_active(p)).unwrap_or(true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a little tidier as: conflicting_activations.keys().chain(parent).all(|id| self.is_active(id)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
&& conflicting_activations | ||
.keys() | ||
// note: a lot of redundant work in is_active for similar debs | ||
.all(|con| self.is_active(con)) | ||
} | ||
|
||
/// Return all dependencies and the features we want from them. | ||
fn resolve_features<'b>( | ||
&mut self, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
filter_map
+next
combo can be replaced withfind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like?
I'd love to find the elegant way to do this, just haven't found it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right yeah, don't worry about this it's fine as-is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted a PR to the std to make this code prettier :) rust-lang/rust#49098