@@ -67,6 +67,15 @@ pub enum DepNodeColor {
6767 Green ( DepNodeIndex )
6868}
6969
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+
7079struct DepGraphData {
7180 /// The old, initial encoding of the dependency graph. This will soon go
7281 /// away.
@@ -94,6 +103,9 @@ struct DepGraphData {
94103 work_products : RefCell < FxHashMap < WorkProductId , WorkProduct > > ,
95104
96105 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 > > ,
97109}
98110
99111impl DepGraph {
@@ -108,6 +120,7 @@ impl DepGraph {
108120 current : RefCell :: new ( CurrentDepGraph :: new ( ) ) ,
109121 previous : prev_graph,
110122 colors : RefCell :: new ( FxHashMap ( ) ) ,
123+ loaded_from_cache : RefCell :: new ( FxHashMap ( ) ) ,
111124 } ) ) ,
112125 fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
113126 }
@@ -256,16 +269,9 @@ impl DepGraph {
256269 data. current . borrow_mut ( ) . push_anon_task ( ) ;
257270 let result = op ( ) ;
258271 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) ;
269275 ( result, DepNodeIndex {
270276 legacy : dep_node_index_legacy,
271277 new : dep_node_index_new,
@@ -594,6 +600,25 @@ impl DepGraph {
594600 }
595601 } ) . unwrap_or ( false )
596602 }
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+ }
597622}
598623
599624/// A "work product" is an intermediate result that we save into the
@@ -630,11 +655,6 @@ impl DepGraph {
630655#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
631656pub struct WorkProduct {
632657 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-
638658 /// Saved files associated with this CGU
639659 pub saved_files : Vec < ( OutputType , String ) > ,
640660}
@@ -644,15 +664,26 @@ pub(super) struct CurrentDepGraph {
644664 edges : IndexVec < DepNodeIndexNew , Vec < DepNodeIndexNew > > ,
645665 node_to_node_index : FxHashMap < DepNode , DepNodeIndexNew > ,
646666
667+ anon_id_seed : Fingerprint ,
668+
647669 task_stack : Vec < OpenTask > ,
648670}
649671
650672impl CurrentDepGraph {
651673 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+
652682 CurrentDepGraph {
653683 nodes : IndexVec :: new ( ) ,
654684 edges : IndexVec :: new ( ) ,
655685 node_to_node_index : FxHashMap ( ) ,
686+ anon_id_seed : stable_hasher. finish ( ) ,
656687 task_stack : Vec :: new ( ) ,
657688 }
658689 }
@@ -696,14 +727,14 @@ impl CurrentDepGraph {
696727 } ) ;
697728 }
698729
699- fn pop_anon_task ( & mut self , kind : DepKind ) -> ( Option < DepNode > , DepNodeIndexNew ) {
730+ fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNodeIndexNew {
700731 let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
701732
702733 if let OpenTask :: Anon {
703734 read_set : _,
704735 reads
705736 } = popped_node {
706- let mut fingerprint = Fingerprint :: zero ( ) ;
737+ let mut fingerprint = self . anon_id_seed ;
707738 let mut hasher = StableHasher :: new ( ) ;
708739
709740 for & read in reads. iter ( ) {
@@ -725,9 +756,9 @@ impl CurrentDepGraph {
725756 } ;
726757
727758 if let Some ( & index) = self . node_to_node_index . get ( & target_dep_node) {
728- ( None , index)
759+ index
729760 } else {
730- ( Some ( target_dep_node ) , self . alloc_node ( target_dep_node, reads) )
761+ self . alloc_node ( target_dep_node, reads)
731762 }
732763 } else {
733764 bug ! ( "pop_anon_task() - Expected anonymous task to be popped" )
0 commit comments