@@ -199,11 +199,27 @@ impl DepGraph {
199199 -> ( R , DepNodeIndex )
200200 where C : DepGraphSafe + StableHashingContextProvider < ContextType =HCX > ,
201201 R : HashStable < HCX > ,
202+ {
203+ self . with_task_impl ( key, cx, arg, task,
204+ |data, key| data. borrow_mut ( ) . push_task ( key) ,
205+ |data, key| data. borrow_mut ( ) . pop_task ( key) )
206+ }
207+
208+ fn with_task_impl < C , A , R , HCX > ( & self ,
209+ key : DepNode ,
210+ cx : C ,
211+ arg : A ,
212+ task : fn ( C , A ) -> R ,
213+ push : fn ( & RefCell < CurrentDepGraph > , DepNode ) ,
214+ pop : fn ( & RefCell < CurrentDepGraph > , DepNode ) -> DepNodeIndex )
215+ -> ( R , DepNodeIndex )
216+ where C : DepGraphSafe + StableHashingContextProvider < ContextType =HCX > ,
217+ R : HashStable < HCX > ,
202218 {
203219 if let Some ( ref data) = self . data {
204220 debug_assert ! ( !data. colors. borrow( ) . contains_key( & key) ) ;
205221
206- data. current . borrow_mut ( ) . push_task ( key) ;
222+ push ( & data. current , key) ;
207223 if cfg ! ( debug_assertions) {
208224 profq_msg ( ProfileQueriesMsg :: TaskBegin ( key. clone ( ) ) )
209225 } ;
@@ -220,7 +236,7 @@ impl DepGraph {
220236 profq_msg ( ProfileQueriesMsg :: TaskEnd )
221237 } ;
222238
223- let dep_node_index = data. current . borrow_mut ( ) . pop_task ( key) ;
239+ let dep_node_index = pop ( & data. current , key) ;
224240
225241 let mut stable_hasher = StableHasher :: new ( ) ;
226242 result. hash_stable ( & mut hcx, & mut stable_hasher) ;
@@ -290,6 +306,22 @@ impl DepGraph {
290306 }
291307 }
292308
309+ /// Execute something within an "eval-always" task which is a task
310+ // that runs whenever anything changes.
311+ pub fn with_eval_always_task < C , A , R , HCX > ( & self ,
312+ key : DepNode ,
313+ cx : C ,
314+ arg : A ,
315+ task : fn ( C , A ) -> R )
316+ -> ( R , DepNodeIndex )
317+ where C : DepGraphSafe + StableHashingContextProvider < ContextType =HCX > ,
318+ R : HashStable < HCX > ,
319+ {
320+ self . with_task_impl ( key, cx, arg, task,
321+ |data, key| data. borrow_mut ( ) . push_eval_always_task ( key) ,
322+ |data, key| data. borrow_mut ( ) . pop_eval_always_task ( key) )
323+ }
324+
293325 #[ inline]
294326 pub fn read ( & self , v : DepNode ) {
295327 if let Some ( ref data) = self . data {
@@ -788,6 +820,24 @@ impl CurrentDepGraph {
788820 }
789821 }
790822
823+ fn push_eval_always_task ( & mut self , key : DepNode ) {
824+ self . task_stack . push ( OpenTask :: EvalAlways { node : key } ) ;
825+ }
826+
827+ fn pop_eval_always_task ( & mut self , key : DepNode ) -> DepNodeIndex {
828+ let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
829+
830+ if let OpenTask :: EvalAlways {
831+ node,
832+ } = popped_node {
833+ debug_assert_eq ! ( node, key) ;
834+ let krate_idx = self . node_to_node_index [ & DepNode :: new_no_params ( DepKind :: Krate ) ] ;
835+ self . alloc_node ( node, vec ! [ krate_idx] )
836+ } else {
837+ bug ! ( "pop_eval_always_task() - Expected eval always task to be popped" ) ;
838+ }
839+ }
840+
791841 fn read_index ( & mut self , source : DepNodeIndex ) {
792842 match self . task_stack . last_mut ( ) {
793843 Some ( & mut OpenTask :: Regular {
@@ -818,7 +868,8 @@ impl CurrentDepGraph {
818868 reads. push ( source) ;
819869 }
820870 }
821- Some ( & mut OpenTask :: Ignore ) | None => {
871+ Some ( & mut OpenTask :: Ignore ) |
872+ Some ( & mut OpenTask :: EvalAlways { .. } ) | None => {
822873 // ignore
823874 }
824875 }
@@ -851,4 +902,7 @@ enum OpenTask {
851902 read_set : FxHashSet < DepNodeIndex > ,
852903 } ,
853904 Ignore ,
905+ EvalAlways {
906+ node : DepNode ,
907+ } ,
854908}
0 commit comments