Skip to content

Commit 4a2dcf4

Browse files
committed
change PublicDependency to store the age for each edge
1 parent a8a79b4 commit 4a2dcf4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,13 @@ impl Graph<PackageId, Rc<Vec<Dependency>>> {
245245
#[derive(Clone, Debug, Default)]
246246
pub struct PublicDependency {
247247
/// For each active package the set of all the names it can see,
248-
/// for each name the exact package that name resolves to and whether it exports that visibility.
249-
inner: im_rc::HashMap<PackageId, im_rc::HashMap<InternedString, (PackageId, bool)>>,
248+
/// for each name the exact package that name resolves to,
249+
/// the `ContextAge` when it was first visible,
250+
/// and the `ContextAge` when it was first exported.
251+
inner: im_rc::HashMap<
252+
PackageId,
253+
im_rc::HashMap<InternedString, (PackageId, ContextAge, Option<ContextAge>)>,
254+
>,
250255
}
251256

252257
impl PublicDependency {
@@ -260,7 +265,7 @@ impl PublicDependency {
260265
.get(&candidate_pid) // if we have seen it before
261266
.iter()
262267
.flat_map(|x| x.values()) // all the things we have stored
263-
.filter(|x| x.1) // as publicly exported
268+
.filter(|x| x.2.is_some()) // as publicly exported
264269
.map(|x| x.0)
265270
.chain(Some(candidate_pid)) // but even if not we know that everything exports itself
266271
.collect()
@@ -270,6 +275,7 @@ impl PublicDependency {
270275
candidate_pid: PackageId,
271276
parent_pid: PackageId,
272277
is_public: bool,
278+
age: ContextAge,
273279
parents: &Graph<PackageId, Rc<Vec<Dependency>>>,
274280
) {
275281
// one tricky part is that `candidate_pid` may already be active and
@@ -284,21 +290,22 @@ impl PublicDependency {
284290
im_rc::hashmap::Entry::Occupied(mut o) => {
285291
// the (transitive) parent can already see something by `c`s name, it had better be `c`.
286292
assert_eq!(o.get().0, c);
287-
if o.get().1 {
293+
if o.get().2.is_some() {
288294
// The previous time the parent saw `c`, it was a public dependency.
289295
// So all of its parents already know about `c`
290296
// and we can save some time by stopping now.
291297
continue;
292298
}
293299
if public {
294300
// Mark that `c` has now bean seen publicly
295-
o.insert((c, public));
301+
let old_age = o.get().1;
302+
o.insert((c, old_age, if public { Some(age) } else { None }));
296303
}
297304
}
298305
im_rc::hashmap::Entry::Vacant(v) => {
299306
// The (transitive) parent does not have anything by `c`s name,
300307
// so we add `c`.
301-
v.insert((c, public));
308+
v.insert((c, age, if public { Some(age) } else { None }));
302309
}
303310
}
304311
// if `candidate_pid` was a private dependency of `p` then `p` parents can't see `c` thru `p`
@@ -331,7 +338,7 @@ impl PublicDependency {
331338
// So, adding `b` will cause `p` to have a public dependency conflict on `t`.
332339
return Err((p, ConflictReason::PublicDependency));
333340
}
334-
if o.1 {
341+
if o.2.is_some() {
335342
// The previous time the parent saw `t`, it was a public dependency.
336343
// So all of its parents already know about `t`
337344
// and we can save some time by stopping now.

src/cargo/core/resolver/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,13 @@ fn activate(
604604
// and associate dep with that edge
605605
.push(dep.clone());
606606
if let Some(public_dependency) = cx.public_dependency.as_mut() {
607-
public_dependency.add_edge(candidate_pid, parent_pid, dep.is_public(), &cx.parents);
607+
public_dependency.add_edge(
608+
candidate_pid,
609+
parent_pid,
610+
dep.is_public(),
611+
cx.age,
612+
&cx.parents,
613+
);
608614
}
609615
}
610616

0 commit comments

Comments
 (0)