Skip to content

Commit 097dbdf

Browse files
committed
invert parents to get graph
1 parent df62a57 commit 097dbdf

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use crate::util::CargoResult;
1313
use crate::util::Graph;
1414

1515
use super::errors::ActivateResult;
16-
use super::types::{
17-
ConflictMap, ConflictReason, DepInfo, GraphNode, Method, RcList, RegistryQueryer,
18-
};
16+
use super::types::{ConflictMap, ConflictReason, DepInfo, GraphNode, Method, RegistryQueryer};
1917

2018
pub use super::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
2119
pub use super::encode::{Metadata, WorkspaceResolve};
@@ -37,16 +35,9 @@ pub struct Context {
3735
pub public_dependency:
3836
Option<im_rc::HashMap<PackageId, im_rc::HashMap<InternedString, (PackageId, bool)>>>,
3937

40-
// This is somewhat redundant with the `resolve_graph` that stores the same data,
41-
// but for querying in the opposite order.
4238
/// a way to look up for a package in activations what packages required it
4339
/// and all of the exact deps that it fulfilled.
4440
pub parents: Graph<PackageId, Rc<Vec<Dependency>>>,
45-
46-
// These are two cheaply-cloneable lists (O(1) clone) which are effectively
47-
// hash maps but are built up as "construction lists". We'll iterate these
48-
// at the very end and actually construct the map that we're making.
49-
pub resolve_graph: RcList<GraphNode>,
5041
}
5142

5243
/// When backtracking it can be useful to know how far back to go.
@@ -94,7 +85,6 @@ impl PackageId {
9485
impl Context {
9586
pub fn new(check_public_visible_dependencies: bool) -> Context {
9687
Context {
97-
resolve_graph: RcList::new(),
9888
resolve_features: im_rc::HashMap::new(),
9989
links: im_rc::HashMap::new(),
10090
public_dependency: if check_public_visible_dependencies {
@@ -122,7 +112,6 @@ impl Context {
122112
);
123113
}
124114
im_rc::hashmap::Entry::Vacant(v) => {
125-
self.resolve_graph.push(GraphNode::Add(id));
126115
if let Some(link) = summary.links() {
127116
ensure!(
128117
self.links.insert(link, id).is_none(),
@@ -340,16 +329,15 @@ impl Context {
340329
}
341330

342331
pub fn graph(&self) -> Graph<PackageId, Vec<Dependency>> {
343-
let mut graph: Graph<PackageId, Vec<Dependency>> = Graph::new();
344-
let mut cur = &self.resolve_graph;
345-
while let Some(ref node) = cur.head {
346-
match node.0 {
347-
GraphNode::Add(ref p) => graph.add(p.clone()),
348-
GraphNode::Link(ref a, ref b, ref dep) => {
349-
graph.link(a.clone(), b.clone()).push(dep.clone());
350-
}
332+
let mut graph = Graph::new();
333+
self.activations
334+
.values()
335+
.for_each(|(r, _)| graph.add(r.package_id()));
336+
for i in self.parents.iter() {
337+
graph.add(*i);
338+
for (o, e) in self.parents.edges(i) {
339+
*graph.link(*o, *i) = e.to_vec();
351340
}
352-
cur = &node.1;
353341
}
354342
graph
355343
}

src/cargo/core/resolver/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,6 @@ fn activate(
606606
let candidate_pid = candidate.summary.package_id();
607607
if let Some((parent, dep)) = parent {
608608
let parent_pid = parent.package_id();
609-
cx.resolve_graph
610-
.push(GraphNode::Link(parent_pid, candidate_pid, dep.clone()));
611609
Rc::make_mut(
612610
// add a edge from candidate to parent in the parents graph
613611
cx.parents.link(candidate_pid, parent_pid),

0 commit comments

Comments
 (0)