@@ -59,6 +59,13 @@ impl DepNodeIndex {
5959 } ;
6060}
6161
62+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
63+ pub enum DepNodeColor {
64+ Red ,
65+ Green ,
66+ Gray
67+ }
68+
6269struct DepGraphData {
6370 /// The old, initial encoding of the dependency graph. This will soon go
6471 /// away.
@@ -74,6 +81,8 @@ struct DepGraphData {
7481 /// nodes and edges as well as all fingerprints of nodes that have them.
7582 previous : PreviousDepGraph ,
7683
84+ colors : RefCell < FxHashMap < DepNode , DepNodeColor > > ,
85+
7786 /// When we load, there may be `.o` files, cached mir, or other such
7887 /// things available to us. If we find that they are not dirty, we
7988 /// load the path to the file storing those work-products here into
@@ -97,6 +106,7 @@ impl DepGraph {
97106 dep_node_debug : RefCell :: new ( FxHashMap ( ) ) ,
98107 current : RefCell :: new ( CurrentDepGraph :: new ( ) ) ,
99108 previous : prev_graph,
109+ colors : RefCell :: new ( FxHashMap ( ) ) ,
100110 } ) ) ,
101111 fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
102112 }
@@ -192,11 +202,23 @@ impl DepGraph {
192202 let mut stable_hasher = StableHasher :: new ( ) ;
193203 result. hash_stable ( & mut hcx, & mut stable_hasher) ;
194204
205+ let current_fingerprint = stable_hasher. finish ( ) ;
206+
195207 assert ! ( self . fingerprints
196208 . borrow_mut( )
197- . insert( key, stable_hasher . finish ( ) )
209+ . insert( key, current_fingerprint )
198210 . is_none( ) ) ;
199211
212+ let prev_fingerprint = data. previous . fingerprint_of ( & key) ;
213+
214+ let color = if Some ( current_fingerprint) == prev_fingerprint {
215+ DepNodeColor :: Green
216+ } else {
217+ DepNodeColor :: Red
218+ } ;
219+
220+ assert ! ( data. colors. borrow_mut( ) . insert( key, color) . is_none( ) ) ;
221+
200222 ( result, DepNodeIndex {
201223 legacy : dep_node_index_legacy,
202224 new : dep_node_index_new,
@@ -228,7 +250,16 @@ impl DepGraph {
228250 data. current . borrow_mut ( ) . push_anon_task ( ) ;
229251 let result = op ( ) ;
230252 let dep_node_index_legacy = data. edges . borrow_mut ( ) . pop_anon_task ( dep_kind) ;
231- let dep_node_index_new = data. current . borrow_mut ( ) . pop_anon_task ( dep_kind) ;
253+ let ( new_dep_node, dep_node_index_new) = data. current
254+ . borrow_mut ( )
255+ . pop_anon_task ( dep_kind) ;
256+ if let Some ( new_dep_node) = new_dep_node {
257+ assert ! ( data. colors
258+ . borrow_mut( )
259+ . insert( new_dep_node, DepNodeColor :: Red )
260+ . is_none( ) ) ;
261+ }
262+
232263 ( result, DepNodeIndex {
233264 legacy : dep_node_index_legacy,
234265 new : dep_node_index_new,
@@ -275,10 +306,22 @@ impl DepGraph {
275306 self . fingerprints . borrow ( ) [ dep_node]
276307 }
277308
278- pub fn prev_fingerprint_of ( & self , dep_node : & DepNode ) -> Fingerprint {
309+ pub fn prev_fingerprint_of ( & self , dep_node : & DepNode ) -> Option < Fingerprint > {
279310 self . data . as_ref ( ) . unwrap ( ) . previous . fingerprint_of ( dep_node)
280311 }
281312
313+ pub fn node_color ( & self , dep_node : & DepNode ) -> DepNodeColor {
314+ match self . data . as_ref ( ) . unwrap ( ) . colors . borrow ( ) . get ( dep_node) {
315+ Some ( & color) => {
316+ debug_assert ! ( color != DepNodeColor :: Gray ) ;
317+ color
318+ }
319+ None => {
320+ DepNodeColor :: Gray
321+ }
322+ }
323+ }
324+
282325 /// Indicates that a previous work product exists for `v`. This is
283326 /// invoked during initial start-up based on what nodes are clean
284327 /// (and what files exist in the incr. directory).
@@ -485,7 +528,7 @@ impl CurrentDepGraph {
485528 } ) ;
486529 }
487530
488- fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNodeIndexNew {
531+ fn pop_anon_task ( & mut self , kind : DepKind ) -> ( Option < DepNode > , DepNodeIndexNew ) {
489532 let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
490533
491534 if let OpenTask :: Anon {
@@ -514,10 +557,10 @@ impl CurrentDepGraph {
514557 } ;
515558
516559 if let Some ( & index) = self . node_to_node_index . get ( & target_dep_node) {
517- return index;
560+ ( None , index)
561+ } else {
562+ ( Some ( target_dep_node) , self . alloc_node ( target_dep_node, reads) )
518563 }
519-
520- self . alloc_node ( target_dep_node, reads)
521564 } else {
522565 bug ! ( "pop_anon_task() - Expected anonymous task to be popped" )
523566 }
0 commit comments