@@ -19,21 +19,24 @@ use super::debug::EdgeFilter;
1919
2020pub struct DepGraphEdges {
2121 nodes : Vec < DepNode > ,
22- indices : FxHashMap < DepNode , IdIndex > ,
23- edges : FxHashSet < ( IdIndex , IdIndex ) > ,
22+ indices : FxHashMap < DepNode , DepNodeIndex > ,
23+ edges : FxHashSet < ( DepNodeIndex , DepNodeIndex ) > ,
2424 task_stack : Vec < OpenTask > ,
2525 forbidden_edge : Option < EdgeFilter > ,
2626}
2727
2828#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
29- struct IdIndex {
29+ pub struct DepNodeIndex {
3030 index : u32
3131}
3232
33- impl IdIndex {
34- fn new ( v : usize ) -> IdIndex {
33+ impl DepNodeIndex {
34+
35+ pub const INVALID : DepNodeIndex = DepNodeIndex { index : :: std:: u32:: MAX } ;
36+
37+ fn new ( v : usize ) -> DepNodeIndex {
3538 assert ! ( ( v & 0xFFFF_FFFF ) == v) ;
36- IdIndex { index : v as u32 }
39+ DepNodeIndex { index : v as u32 }
3740 }
3841
3942 fn index ( self ) -> usize {
@@ -80,7 +83,7 @@ impl DepGraphEdges {
8083 }
8184 }
8285
83- fn id ( & self , index : IdIndex ) -> DepNode {
86+ fn id ( & self , index : DepNodeIndex ) -> DepNode {
8487 self . nodes [ index. index ( ) ]
8588 }
8689
@@ -101,7 +104,7 @@ impl DepGraphEdges {
101104 } ) ;
102105 }
103106
104- pub fn pop_task ( & mut self , key : DepNode ) {
107+ pub fn pop_task ( & mut self , key : DepNode ) -> DepNodeIndex {
105108 let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
106109
107110 if let OpenTask :: Regular {
@@ -117,6 +120,8 @@ impl DepGraphEdges {
117120 let source_id = self . get_or_create_node ( read) ;
118121 self . edges . insert ( ( source_id, target_id) ) ;
119122 }
123+
124+ target_id
120125 } else {
121126 bug ! ( "pop_task() - Expected regular task to be popped" )
122127 }
@@ -129,7 +134,7 @@ impl DepGraphEdges {
129134 } ) ;
130135 }
131136
132- pub fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNode {
137+ pub fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNodeIndex {
133138 let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
134139
135140 if let OpenTask :: Anon {
@@ -155,8 +160,8 @@ impl DepGraphEdges {
155160 hash : fingerprint,
156161 } ;
157162
158- if self . indices . contains_key ( & target_dep_node) {
159- return target_dep_node ;
163+ if let Some ( & index ) = self . indices . get ( & target_dep_node) {
164+ return index ;
160165 }
161166
162167 let target_id = self . get_or_create_node ( target_dep_node) ;
@@ -166,7 +171,7 @@ impl DepGraphEdges {
166171 self . edges . insert ( ( source_id, target_id) ) ;
167172 }
168173
169- target_dep_node
174+ target_id
170175 } else {
171176 bug ! ( "pop_anon_task() - Expected anonymous task to be popped" )
172177 }
@@ -210,6 +215,11 @@ impl DepGraphEdges {
210215 }
211216 }
212217
218+ pub fn read_index ( & mut self , source : DepNodeIndex ) {
219+ let dep_node = self . nodes [ source. index ( ) ] ;
220+ self . read ( dep_node) ;
221+ }
222+
213223 pub fn query ( & self ) -> DepGraphQuery {
214224 let edges: Vec < _ > = self . edges . iter ( )
215225 . map ( |& ( i, j) | ( self . id ( i) , self . id ( j) ) )
@@ -229,7 +239,7 @@ impl DepGraphEdges {
229239 }
230240
231241 #[ inline]
232- fn get_or_create_node ( & mut self , dep_node : DepNode ) -> IdIndex {
242+ fn get_or_create_node ( & mut self , dep_node : DepNode ) -> DepNodeIndex {
233243 let DepGraphEdges {
234244 ref mut indices,
235245 ref mut nodes,
@@ -239,7 +249,7 @@ impl DepGraphEdges {
239249 * indices. entry ( dep_node) . or_insert_with ( || {
240250 let next_id = nodes. len ( ) ;
241251 nodes. push ( dep_node) ;
242- IdIndex :: new ( next_id)
252+ DepNodeIndex :: new ( next_id)
243253 } )
244254 }
245255}
0 commit comments