@@ -52,7 +52,7 @@ pub struct DepNodeIndex {
52
52
53
53
impl Idx for DepNodeIndex {
54
54
fn new ( idx : usize ) -> Self {
55
- assert ! ( ( idx & 0xFFFF_FFFF ) == idx) ;
55
+ debug_assert ! ( ( idx & 0xFFFF_FFFF ) == idx) ;
56
56
DepNodeIndex { index : idx as u32 }
57
57
}
58
58
fn index ( self ) -> usize {
@@ -228,20 +228,31 @@ impl DepGraph {
228
228
229
229
let current_fingerprint = stable_hasher. finish ( ) ;
230
230
231
- assert ! ( self . fingerprints
232
- . borrow_mut( )
233
- . insert( key, current_fingerprint)
234
- . is_none( ) ) ;
231
+ // Store the current fingerprint
232
+ {
233
+ let old_value = self . fingerprints
234
+ . borrow_mut ( )
235
+ . insert ( key, current_fingerprint) ;
236
+ debug_assert ! ( old_value. is_none( ) ,
237
+ "DepGraph::with_task() - Duplicate fingerprint \
238
+ insertion for {:?}", key) ;
239
+ }
235
240
236
- let prev_fingerprint = data. previous . fingerprint_of ( & key) ;
241
+ // Determine the color of the new DepNode.
242
+ {
243
+ let prev_fingerprint = data. previous . fingerprint_of ( & key) ;
237
244
238
- let color = if Some ( current_fingerprint) == prev_fingerprint {
239
- DepNodeColor :: Green ( dep_node_index)
240
- } else {
241
- DepNodeColor :: Red
242
- } ;
245
+ let color = if Some ( current_fingerprint) == prev_fingerprint {
246
+ DepNodeColor :: Green ( dep_node_index)
247
+ } else {
248
+ DepNodeColor :: Red
249
+ } ;
243
250
244
- assert ! ( data. colors. borrow_mut( ) . insert( key, color) . is_none( ) ) ;
251
+ let old_value = data. colors . borrow_mut ( ) . insert ( key, color) ;
252
+ debug_assert ! ( old_value. is_none( ) ,
253
+ "DepGraph::with_task() - Duplicate DepNodeColor \
254
+ insertion for {:?}", key) ;
255
+ }
245
256
246
257
( result, dep_node_index)
247
258
} else {
@@ -250,10 +261,12 @@ impl DepGraph {
250
261
let result = task ( cx, arg) ;
251
262
let mut stable_hasher = StableHasher :: new ( ) ;
252
263
result. hash_stable ( & mut hcx, & mut stable_hasher) ;
253
- assert ! ( self . fingerprints
254
- . borrow_mut( )
255
- . insert( key, stable_hasher. finish( ) )
256
- . is_none( ) ) ;
264
+ let old_value = self . fingerprints
265
+ . borrow_mut ( )
266
+ . insert ( key, stable_hasher. finish ( ) ) ;
267
+ debug_assert ! ( old_value. is_none( ) ,
268
+ "DepGraph::with_task() - Duplicate fingerprint \
269
+ insertion for {:?}", key) ;
257
270
( result, DepNodeIndex :: INVALID )
258
271
} else {
259
272
( task ( cx, arg) , DepNodeIndex :: INVALID )
@@ -549,16 +562,20 @@ impl DepGraph {
549
562
// ... copying the fingerprint from the previous graph too, so we don't
550
563
// have to recompute it ...
551
564
let fingerprint = data. previous . fingerprint_by_index ( prev_dep_node_index) ;
552
- assert ! ( self . fingerprints
553
- . borrow_mut( )
554
- . insert( * dep_node, fingerprint)
555
- . is_none( ) ) ;
565
+ let old_fingerprint = self . fingerprints
566
+ . borrow_mut ( )
567
+ . insert ( * dep_node, fingerprint) ;
568
+ debug_assert ! ( old_fingerprint. is_none( ) ,
569
+ "DepGraph::try_mark_green() - Duplicate fingerprint \
570
+ insertion for {:?}", dep_node) ;
556
571
557
572
// ... and finally storing a "Green" entry in the color map.
558
- assert ! ( data. colors
559
- . borrow_mut( )
560
- . insert( * dep_node, DepNodeColor :: Green ( dep_node_index) )
561
- . is_none( ) ) ;
573
+ let old_color = data. colors
574
+ . borrow_mut ( )
575
+ . insert ( * dep_node, DepNodeColor :: Green ( dep_node_index) ) ;
576
+ debug_assert ! ( old_color. is_none( ) ,
577
+ "DepGraph::try_mark_green() - Duplicate DepNodeColor \
578
+ insertion for {:?}", dep_node) ;
562
579
563
580
debug ! ( "try_mark_green({:?}) - END - successfully marked as green" , dep_node. kind) ;
564
581
Some ( dep_node_index)
@@ -637,9 +654,21 @@ pub(super) struct CurrentDepGraph {
637
654
nodes : IndexVec < DepNodeIndex , DepNode > ,
638
655
edges : IndexVec < DepNodeIndex , Vec < DepNodeIndex > > ,
639
656
node_to_node_index : FxHashMap < DepNode , DepNodeIndex > ,
640
- anon_id_seed : Fingerprint ,
641
657
task_stack : Vec < OpenTask > ,
642
658
forbidden_edge : Option < EdgeFilter > ,
659
+
660
+ // Anonymous DepNodes are nodes the ID of which we compute from the list of
661
+ // their edges. This has the beneficial side-effect that multiple anonymous
662
+ // nodes can be coalesced into one without changing the semantics of the
663
+ // dependency graph. However, the merging of nodes can lead to a subtle
664
+ // problem during red-green marking: The color of an anonymous node from
665
+ // the current session might "shadow" the color of the node with the same
666
+ // ID from the previous session. In order to side-step this problem, we make
667
+ // sure that anon-node IDs allocated in different sessions don't overlap.
668
+ // This is implemented by mixing a session-key into the ID fingerprint of
669
+ // each anon node. The session-key is just a random number generated when
670
+ // the DepGraph is created.
671
+ anon_id_seed : Fingerprint ,
643
672
}
644
673
645
674
impl CurrentDepGraph {
0 commit comments