11use rustc_data_structures:: fx:: FxHashMap ;
22use rustc_data_structures:: graph:: implementation:: { Direction , Graph , NodeIndex , INCOMING } ;
3+ use rustc_index:: vec:: IndexVec ;
34
45use super :: { DepKind , DepNode , DepNodeIndex } ;
56
67pub struct DepGraphQuery < K > {
78 pub graph : Graph < DepNode < K > , ( ) > ,
89 pub indices : FxHashMap < DepNode < K > , NodeIndex > ,
10+ pub dep_index_to_index : IndexVec < DepNodeIndex , Option < NodeIndex > > ,
911}
1012
1113impl < K : DepKind > DepGraphQuery < K > {
@@ -15,18 +17,25 @@ impl<K: DepKind> DepGraphQuery<K> {
1517
1618 let graph = Graph :: with_capacity ( node_count, edge_count) ;
1719 let indices = FxHashMap :: default ( ) ;
20+ let dep_index_to_index = IndexVec :: new ( ) ;
1821
19- DepGraphQuery { graph, indices }
22+ DepGraphQuery { graph, indices, dep_index_to_index }
2023 }
2124
2225 pub fn push ( & mut self , index : DepNodeIndex , node : DepNode < K > , edges : & [ DepNodeIndex ] ) {
2326 let source = self . graph . add_node ( node) ;
24- debug_assert_eq ! ( index. index( ) , source. 0 ) ;
27+ if index. index ( ) >= self . dep_index_to_index . len ( ) {
28+ self . dep_index_to_index . resize ( index. index ( ) + 1 , None ) ;
29+ }
30+ self . dep_index_to_index [ index] = Some ( source) ;
2531 self . indices . insert ( node, source) ;
2632
2733 for & target in edges. iter ( ) {
28- let target = NodeIndex ( target. index ( ) ) ;
29- self . graph . add_edge ( source, target, ( ) ) ;
34+ let target = self . dep_index_to_index [ target] ;
35+ // Skip missing edges.
36+ if let Some ( target) = target {
37+ self . graph . add_edge ( source, target, ( ) ) ;
38+ }
3039 }
3140 }
3241
0 commit comments