@@ -591,6 +591,7 @@ impl CanisterPool {
591
591
let dfs = Dfs :: from_parts ( start, HashSet :: new ( ) ) ; // TODO: Use `FixedBitSet` instead of `HashMap`?
592
592
let mut filtered_dfs = DfsFiltered :: new ( dfs) ;
593
593
// let dest_id_set = &mut dest_id_set;
594
+ let mut nodes_map = HashMap :: new ( ) ; // from source graph to dest graph
594
595
filtered_dfs. traverse (
595
596
source_graph,
596
597
|& s| {
@@ -601,10 +602,34 @@ impl CanisterPool {
601
602
false
602
603
}
603
604
} ,
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, ( ) ) ;
608
633
}
609
634
) ;
610
635
// let source_graph = &self.imports.borrow().graph;
0 commit comments