@@ -67,6 +67,15 @@ pub enum DepNodeColor {
67
67
Green ( DepNodeIndex )
68
68
}
69
69
70
+ impl DepNodeColor {
71
+ pub fn is_green ( self ) -> bool {
72
+ match self {
73
+ DepNodeColor :: Red => false ,
74
+ DepNodeColor :: Green ( _) => true ,
75
+ }
76
+ }
77
+ }
78
+
70
79
struct DepGraphData {
71
80
/// The old, initial encoding of the dependency graph. This will soon go
72
81
/// away.
@@ -94,6 +103,9 @@ struct DepGraphData {
94
103
work_products : RefCell < FxHashMap < WorkProductId , WorkProduct > > ,
95
104
96
105
dep_node_debug : RefCell < FxHashMap < DepNode , String > > ,
106
+
107
+ // Used for testing, only populated when -Zquery-dep-graph is specified.
108
+ loaded_from_cache : RefCell < FxHashMap < DepNodeIndexNew , bool > > ,
97
109
}
98
110
99
111
impl DepGraph {
@@ -108,6 +120,7 @@ impl DepGraph {
108
120
current : RefCell :: new ( CurrentDepGraph :: new ( ) ) ,
109
121
previous : prev_graph,
110
122
colors : RefCell :: new ( FxHashMap ( ) ) ,
123
+ loaded_from_cache : RefCell :: new ( FxHashMap ( ) ) ,
111
124
} ) ) ,
112
125
fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
113
126
}
@@ -256,16 +269,9 @@ impl DepGraph {
256
269
data. current . borrow_mut ( ) . push_anon_task ( ) ;
257
270
let result = op ( ) ;
258
271
let dep_node_index_legacy = data. edges . borrow_mut ( ) . pop_anon_task ( dep_kind) ;
259
- let ( new_dep_node, dep_node_index_new) = data. current
260
- . borrow_mut ( )
261
- . pop_anon_task ( dep_kind) ;
262
- if let Some ( new_dep_node) = new_dep_node {
263
- assert ! ( data. colors
264
- . borrow_mut( )
265
- . insert( new_dep_node, DepNodeColor :: Red )
266
- . is_none( ) ) ;
267
- }
268
-
272
+ let dep_node_index_new = data. current
273
+ . borrow_mut ( )
274
+ . pop_anon_task ( dep_kind) ;
269
275
( result, DepNodeIndex {
270
276
legacy : dep_node_index_legacy,
271
277
new : dep_node_index_new,
@@ -594,6 +600,25 @@ impl DepGraph {
594
600
}
595
601
} ) . unwrap_or ( false )
596
602
}
603
+
604
+ pub fn mark_loaded_from_cache ( & self , dep_node : DepNodeIndex , state : bool ) {
605
+ debug ! ( "mark_loaded_from_cache({:?}, {})" ,
606
+ self . data. as_ref( ) . unwrap( ) . current. borrow( ) . nodes[ dep_node. new] ,
607
+ state) ;
608
+
609
+ self . data
610
+ . as_ref ( )
611
+ . unwrap ( )
612
+ . loaded_from_cache
613
+ . borrow_mut ( )
614
+ . insert ( dep_node. new , state) ;
615
+ }
616
+
617
+ pub fn was_loaded_from_cache ( & self , dep_node : & DepNode ) -> Option < bool > {
618
+ let data = self . data . as_ref ( ) . unwrap ( ) ;
619
+ let dep_node_index = data. current . borrow ( ) . node_to_node_index [ dep_node] ;
620
+ data. loaded_from_cache . borrow ( ) . get ( & dep_node_index) . cloned ( )
621
+ }
597
622
}
598
623
599
624
/// A "work product" is an intermediate result that we save into the
@@ -630,11 +655,6 @@ impl DepGraph {
630
655
#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
631
656
pub struct WorkProduct {
632
657
pub cgu_name : String ,
633
- /// Extra hash used to decide if work-product is still suitable;
634
- /// note that this is *not* a hash of the work-product itself.
635
- /// See documentation on `WorkProduct` type for an example.
636
- pub input_hash : u64 ,
637
-
638
658
/// Saved files associated with this CGU
639
659
pub saved_files : Vec < ( OutputType , String ) > ,
640
660
}
@@ -644,15 +664,26 @@ pub(super) struct CurrentDepGraph {
644
664
edges : IndexVec < DepNodeIndexNew , Vec < DepNodeIndexNew > > ,
645
665
node_to_node_index : FxHashMap < DepNode , DepNodeIndexNew > ,
646
666
667
+ anon_id_seed : Fingerprint ,
668
+
647
669
task_stack : Vec < OpenTask > ,
648
670
}
649
671
650
672
impl CurrentDepGraph {
651
673
fn new ( ) -> CurrentDepGraph {
674
+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
675
+
676
+ let duration = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) ;
677
+ let nanos = duration. as_secs ( ) * 1_000_000_000 +
678
+ duration. subsec_nanos ( ) as u64 ;
679
+ let mut stable_hasher = StableHasher :: new ( ) ;
680
+ nanos. hash ( & mut stable_hasher) ;
681
+
652
682
CurrentDepGraph {
653
683
nodes : IndexVec :: new ( ) ,
654
684
edges : IndexVec :: new ( ) ,
655
685
node_to_node_index : FxHashMap ( ) ,
686
+ anon_id_seed : stable_hasher. finish ( ) ,
656
687
task_stack : Vec :: new ( ) ,
657
688
}
658
689
}
@@ -696,14 +727,14 @@ impl CurrentDepGraph {
696
727
} ) ;
697
728
}
698
729
699
- fn pop_anon_task ( & mut self , kind : DepKind ) -> ( Option < DepNode > , DepNodeIndexNew ) {
730
+ fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNodeIndexNew {
700
731
let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
701
732
702
733
if let OpenTask :: Anon {
703
734
read_set : _,
704
735
reads
705
736
} = popped_node {
706
- let mut fingerprint = Fingerprint :: zero ( ) ;
737
+ let mut fingerprint = self . anon_id_seed ;
707
738
let mut hasher = StableHasher :: new ( ) ;
708
739
709
740
for & read in reads. iter ( ) {
@@ -725,9 +756,9 @@ impl CurrentDepGraph {
725
756
} ;
726
757
727
758
if let Some ( & index) = self . node_to_node_index . get ( & target_dep_node) {
728
- ( None , index)
759
+ index
729
760
} else {
730
- ( Some ( target_dep_node ) , self . alloc_node ( target_dep_node, reads) )
761
+ self . alloc_node ( target_dep_node, reads)
731
762
}
732
763
} else {
733
764
bug ! ( "pop_anon_task() - Expected anonymous task to be popped" )
0 commit comments