@@ -241,7 +241,7 @@ fn dump_graph(query: &DepGraphQuery) {
241
241
let targets = node_set ( & query, & edge_filter. target ) ;
242
242
filter_nodes ( & query, & sources, & targets)
243
243
}
244
- Err ( _) => query. nodes ( ) . into_iter ( ) . collect ( ) ,
244
+ Err ( _) => query. nodes ( ) . into_iter ( ) . map ( |n| n . kind ) . collect ( ) ,
245
245
} ;
246
246
let edges = filter_edges ( & query, & nodes) ;
247
247
@@ -264,41 +264,41 @@ fn dump_graph(query: &DepGraphQuery) {
264
264
}
265
265
266
266
#[ allow( missing_docs) ]
267
- pub struct GraphvizDepGraph < ' q > ( FxHashSet < & ' q DepNode > , Vec < ( & ' q DepNode , & ' q DepNode ) > ) ;
267
+ pub struct GraphvizDepGraph ( FxHashSet < DepKind > , Vec < ( DepKind , DepKind ) > ) ;
268
268
269
- impl < ' a , ' q > dot:: GraphWalk < ' a > for GraphvizDepGraph < ' q > {
270
- type Node = & ' q DepNode ;
271
- type Edge = ( & ' q DepNode , & ' q DepNode ) ;
272
- fn nodes ( & self ) -> dot:: Nodes < ' _ , & ' q DepNode > {
269
+ impl < ' a > dot:: GraphWalk < ' a > for GraphvizDepGraph {
270
+ type Node = DepKind ;
271
+ type Edge = ( DepKind , DepKind ) ;
272
+ fn nodes ( & self ) -> dot:: Nodes < ' _ , DepKind > {
273
273
let nodes: Vec < _ > = self . 0 . iter ( ) . cloned ( ) . collect ( ) ;
274
274
nodes. into ( )
275
275
}
276
- fn edges ( & self ) -> dot:: Edges < ' _ , ( & ' q DepNode , & ' q DepNode ) > {
276
+ fn edges ( & self ) -> dot:: Edges < ' _ , ( DepKind , DepKind ) > {
277
277
self . 1 [ ..] . into ( )
278
278
}
279
- fn source ( & self , edge : & ( & ' q DepNode , & ' q DepNode ) ) -> & ' q DepNode {
279
+ fn source ( & self , edge : & ( DepKind , DepKind ) ) -> DepKind {
280
280
edge. 0
281
281
}
282
- fn target ( & self , edge : & ( & ' q DepNode , & ' q DepNode ) ) -> & ' q DepNode {
282
+ fn target ( & self , edge : & ( DepKind , DepKind ) ) -> DepKind {
283
283
edge. 1
284
284
}
285
285
}
286
286
287
- impl < ' a , ' q > dot:: Labeller < ' a > for GraphvizDepGraph < ' q > {
288
- type Node = & ' q DepNode ;
289
- type Edge = ( & ' q DepNode , & ' q DepNode ) ;
287
+ impl < ' a > dot:: Labeller < ' a > for GraphvizDepGraph {
288
+ type Node = DepKind ;
289
+ type Edge = ( DepKind , DepKind ) ;
290
290
fn graph_id ( & self ) -> dot:: Id < ' _ > {
291
291
dot:: Id :: new ( "DependencyGraph" ) . unwrap ( )
292
292
}
293
- fn node_id ( & self , n : & & ' q DepNode ) -> dot:: Id < ' _ > {
293
+ fn node_id ( & self , n : & DepKind ) -> dot:: Id < ' _ > {
294
294
let s: String = format ! ( "{:?}" , n)
295
295
. chars ( )
296
296
. map ( |c| if c == '_' || c. is_alphanumeric ( ) { c } else { '_' } )
297
297
. collect ( ) ;
298
298
debug ! ( "n={:?} s={:?}" , n, s) ;
299
299
dot:: Id :: new ( s) . unwrap ( )
300
300
}
301
- fn node_label ( & self , n : & & ' q DepNode ) -> dot:: LabelText < ' _ > {
301
+ fn node_label ( & self , n : & DepKind ) -> dot:: LabelText < ' _ > {
302
302
dot:: LabelText :: label ( format ! ( "{:?}" , n) )
303
303
}
304
304
}
@@ -323,7 +323,7 @@ fn filter_nodes<'q>(
323
323
query : & ' q DepGraphQuery ,
324
324
sources : & Option < FxHashSet < & ' q DepNode > > ,
325
325
targets : & Option < FxHashSet < & ' q DepNode > > ,
326
- ) -> FxHashSet < & ' q DepNode > {
326
+ ) -> FxHashSet < DepKind > {
327
327
if let Some ( sources) = sources {
328
328
if let Some ( targets) = targets {
329
329
walk_between ( query, sources, targets)
@@ -333,25 +333,25 @@ fn filter_nodes<'q>(
333
333
} else if let Some ( targets) = targets {
334
334
walk_nodes ( query, targets, INCOMING )
335
335
} else {
336
- query. nodes ( ) . into_iter ( ) . collect ( )
336
+ query. nodes ( ) . into_iter ( ) . map ( |n| n . kind ) . collect ( )
337
337
}
338
338
}
339
339
340
340
fn walk_nodes < ' q > (
341
341
query : & ' q DepGraphQuery ,
342
342
starts : & FxHashSet < & ' q DepNode > ,
343
343
direction : Direction ,
344
- ) -> FxHashSet < & ' q DepNode > {
344
+ ) -> FxHashSet < DepKind > {
345
345
let mut set = FxHashSet :: default ( ) ;
346
346
for & start in starts {
347
347
debug ! ( "walk_nodes: start={:?} outgoing?={:?}" , start, direction == OUTGOING ) ;
348
- if set. insert ( start) {
348
+ if set. insert ( start. kind ) {
349
349
let mut stack = vec ! [ query. indices[ start] ] ;
350
350
while let Some ( index) = stack. pop ( ) {
351
351
for ( _, edge) in query. graph . adjacent_edges ( index, direction) {
352
352
let neighbor_index = edge. source_or_target ( direction) ;
353
353
let neighbor = query. graph . node_data ( neighbor_index) ;
354
- if set. insert ( neighbor) {
354
+ if set. insert ( neighbor. kind ) {
355
355
stack. push ( neighbor_index) ;
356
356
}
357
357
}
@@ -365,7 +365,7 @@ fn walk_between<'q>(
365
365
query : & ' q DepGraphQuery ,
366
366
sources : & FxHashSet < & ' q DepNode > ,
367
367
targets : & FxHashSet < & ' q DepNode > ,
368
- ) -> FxHashSet < & ' q DepNode > {
368
+ ) -> FxHashSet < DepKind > {
369
369
// This is a bit tricky. We want to include a node only if it is:
370
370
// (a) reachable from a source and (b) will reach a target. And we
371
371
// have to be careful about cycles etc. Luckily efficiency is not
@@ -396,6 +396,7 @@ fn walk_between<'q>(
396
396
let index = query. indices [ n] ;
397
397
node_states[ index. 0 ] == State :: Included
398
398
} )
399
+ . map ( |n| n. kind )
399
400
. collect ( ) ;
400
401
401
402
fn recurse ( query : & DepGraphQuery , node_states : & mut [ State ] , node : NodeIndex ) -> bool {
@@ -433,11 +434,13 @@ fn walk_between<'q>(
433
434
434
435
fn filter_edges < ' q > (
435
436
query : & ' q DepGraphQuery ,
436
- nodes : & FxHashSet < & ' q DepNode > ,
437
- ) -> Vec < ( & ' q DepNode , & ' q DepNode ) > {
438
- query
437
+ nodes : & FxHashSet < DepKind > ,
438
+ ) -> Vec < ( DepKind , DepKind ) > {
439
+ let uniq : FxHashSet < _ > = query
439
440
. edges ( )
440
441
. into_iter ( )
441
- . filter ( |& ( source, target) | nodes. contains ( source) && nodes. contains ( target) )
442
- . collect ( )
442
+ . map ( |( s, t) | ( s. kind , t. kind ) )
443
+ . filter ( |( source, target) | nodes. contains ( source) && nodes. contains ( target) )
444
+ . collect ( ) ;
445
+ uniq. into_iter ( ) . collect ( )
443
446
}
0 commit comments