@@ -77,31 +77,24 @@ impl CallGraph {
77
77
fn reachable_funcs < ' a > (
78
78
cg : & ' a CallGraph ,
79
79
h : & impl HugrView ,
80
- roots : impl IntoIterator < Item = Node > ,
80
+ entry_points : impl IntoIterator < Item = Node > ,
81
81
) -> impl Iterator < Item = Node > + ' a {
82
- let mut entry_points = roots . into_iter ( ) . collect_vec ( ) ;
82
+ let mut roots = entry_points . into_iter ( ) . collect_vec ( ) ;
83
83
let mut b = if h. get_optype ( h. root ( ) ) . is_module ( ) {
84
- if entry_points. is_empty ( ) {
85
- entry_points. push (
86
- h. children ( h. root ( ) )
87
- . filter ( |n| {
88
- h. get_optype ( * n)
89
- . as_func_defn ( )
90
- . is_some_and ( |fd| fd. name == "main" )
91
- } )
92
- . exactly_one ( )
93
- . ok ( )
94
- . expect ( "No entry_points provided, Module must contain `main`" ) ,
95
- ) ;
84
+ if roots. is_empty ( ) {
85
+ roots. extend ( h. children ( h. root ( ) ) . filter ( |n| {
86
+ h. get_optype ( * n)
87
+ . as_func_defn ( )
88
+ . is_some_and ( |fd| fd. name == "main" )
89
+ } ) ) ;
90
+ assert ! ( !roots. is_empty( ) , "No entry_points for Module and no `main`" ) ;
96
91
}
97
- let mut entry_points = entry_points
98
- . into_iter ( )
99
- . map ( |i| cg. node_to_g . get ( & i) . unwrap ( ) ) ;
100
- let mut b = Bfs :: new ( & cg. g , * entry_points. next ( ) . unwrap ( ) ) ;
101
- b. stack . extend ( entry_points) ;
92
+ let mut roots = roots. into_iter ( ) . map ( |i| cg. node_to_g . get ( & i) . unwrap ( ) ) ;
93
+ let mut b = Bfs :: new ( & cg. g , * roots. next ( ) . unwrap ( ) ) ;
94
+ b. stack . extend ( roots) ;
102
95
b
103
96
} else {
104
- assert ! ( entry_points . is_empty( ) ) ;
97
+ assert ! ( roots . is_empty( ) ) ;
105
98
Bfs :: new ( & cg. g , * cg. node_to_g . get ( & h. root ( ) ) . unwrap ( ) )
106
99
} ;
107
100
std:: iter:: from_fn ( move || b. next ( & cg. g ) ) . map ( |i| * cg. g . node_weight ( i) . unwrap ( ) )
0 commit comments