-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Small resolver cleanups #15040
Open
Eh2406
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
Eh2406:small_cleanups
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Small resolver cleanups #15040
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,6 @@ | |
//! over the place. | ||
|
||
use std::collections::{BTreeMap, HashMap, HashSet}; | ||
use std::mem; | ||
use std::rc::Rc; | ||
use std::time::{Duration, Instant}; | ||
|
||
|
@@ -142,9 +141,7 @@ pub fn resolve( | |
let mut past_conflicting_activations = conflict_cache::ConflictCache::new(); | ||
|
||
let resolver_ctx = loop { | ||
let resolver_ctx = ResolverContext::new(); | ||
let resolver_ctx = activate_deps_loop( | ||
resolver_ctx, | ||
&mut registry, | ||
summaries, | ||
first_version, | ||
|
@@ -199,13 +196,13 @@ pub fn resolve( | |
/// If all dependencies can be activated and resolved to a version in the | ||
/// dependency graph, `cx` is returned. | ||
fn activate_deps_loop( | ||
mut resolver_ctx: ResolverContext, | ||
registry: &mut RegistryQueryer<'_>, | ||
summaries: &[(Summary, ResolveOpts)], | ||
first_version: Option<VersionOrdering>, | ||
gctx: Option<&GlobalContext>, | ||
past_conflicting_activations: &mut conflict_cache::ConflictCache, | ||
) -> CargoResult<ResolverContext> { | ||
let mut resolver_ctx = ResolverContext::new(); | ||
let mut backtrack_stack = Vec::new(); | ||
let mut remaining_deps = RemainingDeps::new(); | ||
|
||
|
@@ -759,22 +756,8 @@ impl RemainingCandidates { | |
) -> Option<(Summary, bool)> { | ||
for b in self.remaining.iter() { | ||
let b_id = b.package_id(); | ||
// The `links` key in the manifest dictates that there's only one | ||
// package in a dependency graph, globally, with that particular | ||
// `links` key. If this candidate links to something that's already | ||
// linked to by a different package then we've gotta skip this. | ||
if let Some(link) = b.links() { | ||
if let Some(&a) = cx.links.get(&link) { | ||
if a != b_id { | ||
conflicting_prev_active | ||
.entry(a) | ||
.or_insert_with(|| ConflictReason::Links(link)); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
// Otherwise the condition for being a valid candidate relies on | ||
// The condition for being a valid candidate relies on | ||
// semver. Cargo dictates that you can't duplicate multiple | ||
// semver-compatible versions of a crate. For example we can't | ||
// simultaneously activate `foo 1.0.2` and `foo 1.2.0`. We can, | ||
|
@@ -791,12 +774,27 @@ impl RemainingCandidates { | |
} | ||
} | ||
|
||
// Otherwise the `links` key in the manifest dictates that there's only one | ||
weihanglo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// package in a dependency graph, globally, with that particular | ||
// `links` key. If this candidate links to something that's already | ||
// linked to by a different package then we've gotta skip this. | ||
if let Some(link) = b.links() { | ||
if let Some(&a) = cx.links.get(&link) { | ||
if a != b_id { | ||
conflicting_prev_active | ||
.entry(a) | ||
.or_insert_with(|| ConflictReason::Links(link)); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
// Well if we made it this far then we've got a valid dependency. We | ||
// want this iterator to be inherently "peekable" so we don't | ||
// necessarily return the item just yet. Instead we stash it away to | ||
// get returned later, and if we replaced something then that was | ||
// actually the candidate to try first so we return that. | ||
if let Some(r) = mem::replace(&mut self.has_another, Some(b.clone())) { | ||
if let Some(r) = self.has_another.replace(b.clone()) { | ||
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. that's what I get for trying to manually cherry pick. |
||
return Some((r, true)); | ||
} | ||
} | ||
|
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.
Thinking about this more, I wonder if this was a (failed) attempt to reuse memory. Perhaps
let mut resolver_ctx = ResolverContext::new();
outside the loop andresolver_ctx.clear()
inside the loop was the original intent.