Skip to content

Commit 3e0a07f

Browse files
committed
get the one test to pass
1 parent 8c4c380 commit 3e0a07f

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub struct Context {
2727
pub activations: Activations,
2828
pub resolve_features: im_rc::HashMap<PackageId, Rc<HashSet<InternedString>>>,
2929
pub links: im_rc::HashMap<InternedString, PackageId>,
30+
pub public_dependency:
31+
im_rc::HashMap<PackageId, im_rc::HashMap<InternedString, (PackageId, bool)>>,
3032

3133
// This is somewhat redundant with the `resolve_graph` that stores the same data,
3234
// but for querying in the opposite order.
@@ -50,6 +52,7 @@ impl Context {
5052
resolve_graph: RcList::new(),
5153
resolve_features: im_rc::HashMap::new(),
5254
links: im_rc::HashMap::new(),
55+
public_dependency: im_rc::HashMap::new(),
5356
parents: Graph::new(),
5457
resolve_replacements: RcList::new(),
5558
activations: im_rc::HashMap::new(),

src/cargo/core/resolver/mod.rs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,12 @@ fn activate_deps_loop(
257257
let mut backtracked = false;
258258

259259
loop {
260-
let next = remaining_candidates.next(&mut conflicting_activations, &cx, &dep);
260+
let next = remaining_candidates.next(
261+
&mut conflicting_activations,
262+
&cx,
263+
&dep,
264+
parent.package_id(),
265+
);
261266

262267
let (candidate, has_another) = next.ok_or(()).or_else(|_| {
263268
// If we get here then our `remaining_candidates` was just
@@ -596,6 +601,33 @@ fn activate(
596601
.link(candidate.summary.package_id(), parent.package_id()),
597602
)
598603
.push(dep.clone());
604+
let mut stack = vec![(parent.package_id(), dep.is_public())];
605+
while let Some((p, public)) = stack.pop() {
606+
match cx
607+
.public_dependency
608+
.entry(p)
609+
.or_default()
610+
.entry(candidate.summary.name())
611+
{
612+
im_rc::hashmap::Entry::Occupied(mut o) => {
613+
assert_eq!(o.get().0, candidate.summary.package_id());
614+
if o.get().1 {
615+
continue;
616+
}
617+
if public {
618+
o.insert((candidate.summary.package_id(), public));
619+
}
620+
}
621+
im_rc::hashmap::Entry::Vacant(v) => {
622+
v.insert((candidate.summary.package_id(), public));
623+
}
624+
}
625+
if public {
626+
for &(grand, ref d) in cx.parents.edges(&p) {
627+
stack.push((grand, d.iter().any(|x| x.is_public())));
628+
}
629+
}
630+
}
599631
}
600632

601633
let activated = cx.flag_activated(&candidate.summary, method)?;
@@ -692,10 +724,11 @@ impl RemainingCandidates {
692724
conflicting_prev_active: &mut BTreeMap<PackageId, ConflictReason>,
693725
cx: &Context,
694726
dep: &Dependency,
727+
parent: PackageId,
695728
) -> Option<(Candidate, bool)> {
696729
let prev_active = cx.prev_active(dep);
697730

698-
for (_, b) in self.remaining.by_ref() {
731+
'main: for (_, b) in self.remaining.by_ref() {
699732
// The `links` key in the manifest dictates that there's only one
700733
// package in a dependency graph, globally, with that particular
701734
// `links` key. If this candidate links to something that's already
@@ -731,6 +764,26 @@ impl RemainingCandidates {
731764
}
732765
}
733766

767+
let mut stack = vec![(parent, dep.is_public())];
768+
while let Some((p, public)) = stack.pop() {
769+
// TODO: dont look at the same thing more then once
770+
if let Some(o) = cx
771+
.public_dependency
772+
.get(&p)
773+
.and_then(|x| x.get(&b.summary.name()))
774+
{
775+
if o.0 != b.summary.package_id() {
776+
// TODO: conflicting_prev_active
777+
continue 'main;
778+
}
779+
}
780+
if public {
781+
for &(grand, ref d) in cx.parents.edges(&p) {
782+
stack.push((grand, d.iter().any(|x| x.is_public())));
783+
}
784+
}
785+
}
786+
734787
// Well if we made it this far then we've got a valid dependency. We
735788
// want this iterator to be inherently "peekable" so we don't
736789
// necessarily return the item just yet. Instead we stash it away to
@@ -789,6 +842,7 @@ fn find_candidate(
789842
&mut frame.conflicting_activations,
790843
&frame.context,
791844
&frame.dep,
845+
frame.parent.package_id(),
792846
);
793847
let (candidate, has_another) = match next {
794848
Some(pair) => pair,

0 commit comments

Comments
 (0)