@@ -59,6 +59,13 @@ impl DepNodeIndex {
59
59
} ;
60
60
}
61
61
62
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
63
+ pub enum DepNodeColor {
64
+ Red ,
65
+ Green ,
66
+ Gray
67
+ }
68
+
62
69
struct DepGraphData {
63
70
/// The old, initial encoding of the dependency graph. This will soon go
64
71
/// away.
@@ -74,6 +81,8 @@ struct DepGraphData {
74
81
/// nodes and edges as well as all fingerprints of nodes that have them.
75
82
previous : PreviousDepGraph ,
76
83
84
+ colors : RefCell < FxHashMap < DepNode , DepNodeColor > > ,
85
+
77
86
/// When we load, there may be `.o` files, cached mir, or other such
78
87
/// things available to us. If we find that they are not dirty, we
79
88
/// load the path to the file storing those work-products here into
@@ -97,6 +106,7 @@ impl DepGraph {
97
106
dep_node_debug : RefCell :: new ( FxHashMap ( ) ) ,
98
107
current : RefCell :: new ( CurrentDepGraph :: new ( ) ) ,
99
108
previous : prev_graph,
109
+ colors : RefCell :: new ( FxHashMap ( ) ) ,
100
110
} ) ) ,
101
111
fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
102
112
}
@@ -192,11 +202,23 @@ impl DepGraph {
192
202
let mut stable_hasher = StableHasher :: new ( ) ;
193
203
result. hash_stable ( & mut hcx, & mut stable_hasher) ;
194
204
205
+ let current_fingerprint = stable_hasher. finish ( ) ;
206
+
195
207
assert ! ( self . fingerprints
196
208
. borrow_mut( )
197
- . insert( key, stable_hasher . finish ( ) )
209
+ . insert( key, current_fingerprint )
198
210
. is_none( ) ) ;
199
211
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
+
200
222
( result, DepNodeIndex {
201
223
legacy : dep_node_index_legacy,
202
224
new : dep_node_index_new,
@@ -228,7 +250,16 @@ impl DepGraph {
228
250
data. current . borrow_mut ( ) . push_anon_task ( ) ;
229
251
let result = op ( ) ;
230
252
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
+
232
263
( result, DepNodeIndex {
233
264
legacy : dep_node_index_legacy,
234
265
new : dep_node_index_new,
@@ -275,10 +306,22 @@ impl DepGraph {
275
306
self . fingerprints . borrow ( ) [ dep_node]
276
307
}
277
308
278
- pub fn prev_fingerprint_of ( & self , dep_node : & DepNode ) -> Fingerprint {
309
+ pub fn prev_fingerprint_of ( & self , dep_node : & DepNode ) -> Option < Fingerprint > {
279
310
self . data . as_ref ( ) . unwrap ( ) . previous . fingerprint_of ( dep_node)
280
311
}
281
312
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
+
282
325
/// Indicates that a previous work product exists for `v`. This is
283
326
/// invoked during initial start-up based on what nodes are clean
284
327
/// (and what files exist in the incr. directory).
@@ -485,7 +528,7 @@ impl CurrentDepGraph {
485
528
} ) ;
486
529
}
487
530
488
- fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNodeIndexNew {
531
+ fn pop_anon_task ( & mut self , kind : DepKind ) -> ( Option < DepNode > , DepNodeIndexNew ) {
489
532
let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
490
533
491
534
if let OpenTask :: Anon {
@@ -514,10 +557,10 @@ impl CurrentDepGraph {
514
557
} ;
515
558
516
559
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) )
518
563
}
519
-
520
- self . alloc_node ( target_dep_node, reads)
521
564
} else {
522
565
bug ! ( "pop_anon_task() - Expected anonymous task to be popped" )
523
566
}
0 commit comments