-
Notifications
You must be signed in to change notification settings - Fork 38
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
Return and track affected and culprit on conflicts #298
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,31 @@ use log::{debug, info}; | |
use crate::internal::{Id, Incompatibility, State}; | ||
use crate::{DependencyConstraints, Map, Package, PubGrubError, SelectedDependencies, VersionSet}; | ||
|
||
/// Statistics on how often a package conflicted with other packages. | ||
#[derive(Debug, Default, Clone)] | ||
pub struct PackageResolutionStatistics { | ||
unit_propagation_affected: u32, | ||
unit_propagation_culprit: u32, | ||
dependencies_affected: u32, | ||
dependencies_culprit: u32, | ||
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.
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. Good catch |
||
} | ||
|
||
impl PackageResolutionStatistics { | ||
/// The number of conflicts this package was involved in. | ||
/// | ||
/// Processing packages with a high conflict count earlier usually speeds up resolution. | ||
/// | ||
/// Whenever a package is part of the root cause incompatibility of a conflict, we increase its | ||
/// count by one. Since the structure of the incompatibilities may change, this count too may | ||
/// change in the future. | ||
pub fn conflict_count(&self) -> u32 { | ||
self.unit_propagation_affected | ||
+ self.unit_propagation_culprit | ||
+ self.dependencies_affected | ||
+ self.dependencies_culprit | ||
} | ||
} | ||
|
||
/// Main function of the library. | ||
/// Finds a set of packages satisfying dependency bounds for a given package + version pair. | ||
#[cold] | ||
|
@@ -77,6 +102,7 @@ pub fn resolve<DP: DependencyProvider>( | |
version: impl Into<DP::V>, | ||
) -> Result<SelectedDependencies<DP>, PubGrubError<DP>> { | ||
let mut state: State<DP> = State::init(package.clone(), version.into()); | ||
let mut conflict_tracker: Map<Id<DP::P>, PackageResolutionStatistics> = Map::default(); | ||
let mut added_dependencies: Map<Id<DP::P>, Set<DP::V>> = Map::default(); | ||
let mut next = state.root_package; | ||
loop { | ||
|
@@ -88,7 +114,22 @@ pub fn resolve<DP: DependencyProvider>( | |
"unit_propagation: {:?} = '{}'", | ||
&next, state.package_store[next] | ||
); | ||
state.unit_propagation(next)?; | ||
let root_causes = state.unit_propagation(next)?; | ||
for (affected, incompat) in root_causes { | ||
conflict_tracker | ||
.entry(affected) | ||
.or_default() | ||
.unit_propagation_affected += 1; | ||
for (conflict_package, _) in state.incompatibility_store[incompat].iter() { | ||
if conflict_package == affected { | ||
continue; | ||
} | ||
conflict_tracker | ||
.entry(conflict_package) | ||
.or_default() | ||
.unit_propagation_culprit += 1; | ||
} | ||
} | ||
|
||
debug!( | ||
"Partial solution after unit propagation: {}", | ||
|
@@ -97,7 +138,11 @@ pub fn resolve<DP: DependencyProvider>( | |
|
||
let Some(highest_priority_pkg) = | ||
state.partial_solution.pick_highest_priority_pkg(|p, r| { | ||
dependency_provider.prioritize(&state.package_store[p], r) | ||
dependency_provider.prioritize( | ||
&state.package_store[p], | ||
r, | ||
conflict_tracker.entry(p).or_default(), | ||
) | ||
}) | ||
else { | ||
return Ok(state | ||
|
@@ -174,9 +219,23 @@ pub fn resolve<DP: DependencyProvider>( | |
let dep_incompats = | ||
state.add_incompatibility_from_dependencies(p, v.clone(), dependencies); | ||
|
||
state | ||
.partial_solution | ||
.add_version(p, v, dep_incompats, &state.incompatibility_store); | ||
if let Some(conflict) = state.partial_solution.add_version( | ||
p, | ||
v, | ||
dep_incompats, | ||
&state.incompatibility_store, | ||
) { | ||
conflict_tracker.entry(p).or_default().dependencies_affected += 1; | ||
for (incompat_package, _) in state.incompatibility_store[conflict].iter() { | ||
if incompat_package == p { | ||
continue; | ||
} | ||
conflict_tracker | ||
.entry(incompat_package) | ||
.or_default() | ||
.unit_propagation_culprit += 1; | ||
} | ||
} | ||
} else { | ||
// `dep_incompats` are already in `incompatibilities` so we know there are not satisfied | ||
// terms and can add the decision directly. | ||
|
@@ -254,7 +313,12 @@ pub trait DependencyProvider { | |
/// | ||
/// Note: the resolver may call this even when the range has not changed, | ||
/// if it is more efficient for the resolvers internal data structures. | ||
fn prioritize(&self, package: &Self::P, range: &Self::VS) -> Self::Priority; | ||
fn prioritize( | ||
&self, | ||
package: &Self::P, | ||
range: &Self::VS, | ||
package_conflicts_counts: &PackageResolutionStatistics, | ||
) -> Self::Priority; | ||
/// The type returned from `prioritize`. The resolver does not care what type this is | ||
/// as long as it can pick a largest one and clone it. | ||
/// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: like
unit_propagation_buffer
I bet thisVec
ends up expensive to allocate.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.
Changed it for a smallvec (it's used a lot less than
unit_propagation_buffer
)