@@ -5,9 +5,9 @@ use crate::lib::builders::{
5
5
use crate :: lib:: canister_info:: CanisterInfo ;
6
6
use crate :: lib:: environment:: Environment ;
7
7
use crate :: lib:: error:: { BuildError , DfxError , DfxResult } ;
8
+ use crate :: lib:: graph:: traverse_filtered:: BfsFiltered ;
8
9
use crate :: lib:: metadata:: dfx:: DfxMetadata ;
9
10
use crate :: lib:: metadata:: names:: { CANDID_ARGS , CANDID_SERVICE , DFX } ;
10
- use crate :: lib:: graph:: traverse_filtered:: DfsFiltered ;
11
11
use crate :: lib:: wasm:: file:: { compress_bytes, read_wasm_module} ;
12
12
use crate :: util:: assets;
13
13
use anyhow:: { anyhow, bail, Context } ;
@@ -22,7 +22,7 @@ use ic_wasm::metadata::{add_metadata, remove_metadata, Kind};
22
22
use ic_wasm:: optimize:: OptLevel ;
23
23
use itertools:: Itertools ;
24
24
use petgraph:: graph:: { DiGraph , NodeIndex } ;
25
- use petgraph:: visit:: Dfs ;
25
+ use petgraph:: visit:: Bfs ;
26
26
use rand:: { thread_rng, RngCore } ;
27
27
use slog:: { error, info, trace, warn, Logger } ;
28
28
use std:: cell:: RefCell ;
@@ -583,55 +583,56 @@ impl CanisterPool {
583
583
let source_ids = & self . imports . borrow ( ) . nodes ;
584
584
let start: Vec < _ > =
585
585
real_canisters_to_build. iter ( ) . map ( |name| MotokoImport :: Canister ( name. clone ( ) ) ) . collect ( ) ; // `clone` is inefficient.
586
- let start = start. into_iter ( ) . map ( |node| * source_ids. get ( & node) . unwrap ( ) ) . collect ( ) ;
586
+ let start = start. into_iter ( ) . map ( |node| * source_ids. get ( & node) . unwrap ( ) ) ;
587
587
// // Transform the graph of file dependencies to graph of canister dependencies.
588
588
// // For this do DFS for each of `real_canisters_to_build`.
589
589
let mut dest_graph: DiGraph < CanisterId , ( ) > = DiGraph :: new ( ) ;
590
590
let mut dest_id_set = HashMap :: new ( ) ;
591
- let dfs = Dfs :: from_parts ( start, HashSet :: new ( ) ) ; // TODO: Use `FixedBitSet` instead of `HashMap`?
592
- let mut filtered_dfs = DfsFiltered :: new ( dfs) ;
593
- // let dest_id_set = &mut dest_id_set;
594
- let mut nodes_map = HashMap :: new ( ) ; // from source graph to dest graph
595
- filtered_dfs. traverse (
596
- source_graph,
597
- |& s| {
598
- let source_id = source_graph. node_weight ( s) ;
599
- if let Some ( MotokoImport :: Canister ( _parent_name) ) = source_id {
600
- true
601
- } else {
602
- false
603
- }
604
- } ,
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" ) ;
591
+ for start_node in start {
592
+ let bfs = Bfs :: new ( & source_graph, start_node) ;
593
+ let mut filtered_bfs = BfsFiltered :: new ( bfs) ;
594
+ let mut nodes_map = HashMap :: new ( ) ; // from source graph to dest graph
595
+ filtered_bfs. traverse (
596
+ source_graph,
597
+ |& s| {
598
+ let source_id = source_graph. node_weight ( s) ;
599
+ if let Some ( MotokoImport :: Canister ( _parent_name) ) = source_id {
600
+ true
601
+ } else {
602
+ false
621
603
}
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, ( ) ) ;
633
- }
634
- ) ;
604
+ } ,
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, ( ) ) ;
633
+ }
634
+ ) ;
635
+ }
635
636
// let source_graph = &self.imports.borrow().graph;
636
637
// let mut dest_graph: DiGraph<CanisterId, ()> = DiGraph::new();
637
638
// let mut dest_id_set = HashMap::new();
0 commit comments