Skip to content

Commit 9cff499

Browse files
committed
it compiled (will test)
1 parent 31ff714 commit 9cff499

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/dfx/src/lib/graph/traverse_filtered.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ impl<NodeId, VM> DfsFiltered<NodeId, VM> {
1919
where C: FnMut(&NodeId, &NodeId) -> (),
2020
G: IntoNeighbors<NodeId = NodeId> + DataMap<NodeWeight = NodeWeight>,
2121
P: FnMut(&NodeId) -> bool,
22-
NodeId: Copy + PartialEq,
22+
NodeId: Copy + Eq,
2323
VM: VisitMap<NodeId>,
2424
{
25-
while let Some(item) = &self.base.next(graph) {
26-
if (&mut predicate)(item) {
27-
let parent = self.base.stack.iter().map(|e| *e).rev().find(&mut predicate);
28-
if let Some(parent) = &parent {
29-
(&mut call)(parent, item);
25+
while let Some(source_item_id) = &self.base.next(graph) {
26+
if (&mut predicate)(source_item_id) {
27+
let source_parent_id = self.base.stack.iter().map(|e| *e).rev().find(&mut predicate);
28+
if let Some(source_parent_id) = &source_parent_id {
29+
(&mut call)(source_parent_id, &source_item_id);
3030
}
3131
}
3232
}

src/dfx/src/lib/models/canister.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ impl CanisterPool {
591591
let dfs = Dfs::from_parts(start, HashSet::new()); // TODO: Use `FixedBitSet` instead of `HashMap`?
592592
let mut filtered_dfs = DfsFiltered::new(dfs);
593593
// let dest_id_set = &mut dest_id_set;
594+
let mut nodes_map = HashMap::new(); // from source graph to dest graph
594595
filtered_dfs.traverse(
595596
source_graph,
596597
|&s| {
@@ -601,10 +602,34 @@ impl CanisterPool {
601602
false
602603
}
603604
},
604-
|&parent_id, &child_id| {
605-
let parent_id = *dest_id_set.entry(parent_id).or_insert_with(|| parent_id);
606-
let child_id = *dest_id_set.entry(child_id).or_insert_with(|| child_id);
607-
dest_graph.add_edge(parent_id, child_id, ());
605+
|&source_parent_id, &source_child_id| {
606+
// FIXME: Is the chain of `unwrap`s and `panic`s correct?
607+
let parent = source_graph.node_weight(source_parent_id).unwrap();
608+
let parent_name = match parent {
609+
MotokoImport::Canister(name) => name,
610+
_ => {
611+
panic!("programming error");
612+
}
613+
};
614+
let parent_canister = self.get_first_canister_with_name(&parent_name).unwrap().canister_id();
615+
616+
let child = source_graph.node_weight(source_child_id).unwrap();
617+
let child_name = match child {
618+
MotokoImport::Canister(name) => name,
619+
_ => {
620+
panic!("programming error");
621+
}
622+
};
623+
let child_canister = self.get_first_canister_with_name(&child_name).unwrap().canister_id();
624+
625+
let dest_parent_id = *dest_id_set.entry(source_parent_id).or_insert_with(|| dest_graph.add_node(parent_canister));
626+
nodes_map.insert(source_parent_id, dest_parent_id);
627+
let dest_child_id = *dest_id_set.entry(source_child_id).or_insert_with(|| dest_graph.add_node(child_canister));
628+
nodes_map.insert(source_child_id, dest_child_id);
629+
nodes_map.entry(source_parent_id).or_insert_with(
630+
|| dest_graph.add_node(*dest_graph.node_weight(source_parent_id).unwrap()) // FIXME: `unwrap()`?
631+
);
632+
dest_graph.add_edge(dest_parent_id, dest_child_id, ());
608633
}
609634
);
610635
// let source_graph = &self.imports.borrow().graph;

0 commit comments

Comments
 (0)