@@ -2,9 +2,8 @@ use crate::errors::GrimpResult;
22use crate :: graph:: { ExtendWithDescendants , Graph , ModuleToken } ;
33use derive_new:: new;
44use getset:: Getters ;
5- use itertools:: Itertools ;
65use rayon:: prelude:: * ;
7- use rustc_hash:: { FxHashMap , FxHashSet } ;
6+ use rustc_hash:: FxHashSet ;
87
98use tap:: prelude:: * ;
109
@@ -146,35 +145,18 @@ impl Graph {
146145 let excluded_modules =
147146 all_layers_modules - & ( & from_layer_with_descendants | & to_layer_with_descendants) ;
148147
149- // Disallow chains via these imports.
150- // We'll add chains to this set as we discover them.
151- let mut excluded_imports = FxHashMap :: default ( ) ;
148+ let chains = self . _find_shortest_chains (
149+ & from_layer_with_descendants,
150+ & to_layer_with_descendants,
151+ & excluded_modules,
152+ ) ?;
152153
153154 // Collect direct imports...
154155 let mut direct_imports = vec ! [ ] ;
155156 // ...and the middles of any indirect imports.
156157 let mut middles = vec ! [ ] ;
157- loop {
158- let chain = self . find_shortest_chain_with_excluded_modules_and_imports (
159- & from_layer_with_descendants,
160- & to_layer_with_descendants,
161- & excluded_modules,
162- & excluded_imports,
163- ) ?;
164-
165- if chain. is_none ( ) {
166- break ;
167- }
168- let chain = chain. unwrap ( ) ;
169-
170- // Exclude this chain from further searching.
171- for ( importer, imported) in chain. iter ( ) . tuple_windows ( ) {
172- excluded_imports
173- . entry ( * importer)
174- . or_default ( )
175- . insert ( * imported) ;
176- }
177158
159+ for chain in chains {
178160 let ( head, middle, tail) = self . split_chain ( & chain) ;
179161 match middle {
180162 Some ( middle) => middles. push ( middle) ,
0 commit comments