@@ -72,6 +72,16 @@ struct DepGraphData {
7272 loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
7373}
7474
75+ pub fn hash_result < R > ( hcx : & mut StableHashingContext < ' _ > , result : & R ) -> Option < Fingerprint >
76+ where
77+ R : for < ' a > HashStable < StableHashingContext < ' a > > ,
78+ {
79+ let mut stable_hasher = StableHasher :: new ( ) ;
80+ result. hash_stable ( hcx, & mut stable_hasher) ;
81+
82+ Some ( stable_hasher. finish ( ) )
83+ }
84+
7585impl DepGraph {
7686
7787 pub fn new ( prev_graph : PreviousDepGraph ,
@@ -169,14 +179,16 @@ impl DepGraph {
169179 /// `arg` parameter.
170180 ///
171181 /// [rustc guide]: https://rust-lang.github.io/rustc-guide/incremental-compilation.html
172- pub fn with_task < ' gcx , C , A , R > ( & self ,
173- key : DepNode ,
174- cx : C ,
175- arg : A ,
176- task : fn ( C , A ) -> R )
177- -> ( R , DepNodeIndex )
178- where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
179- R : HashStable < StableHashingContext < ' gcx > > ,
182+ pub fn with_task < ' a , C , A , R > (
183+ & self ,
184+ key : DepNode ,
185+ cx : C ,
186+ arg : A ,
187+ task : fn ( C , A ) -> R ,
188+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
189+ ) -> ( R , DepNodeIndex )
190+ where
191+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
180192 {
181193 self . with_task_impl ( key, cx, arg, false , task,
182194 |_key| Some ( TaskDeps {
@@ -187,17 +199,18 @@ impl DepGraph {
187199 } ) ,
188200 |data, key, fingerprint, task| {
189201 data. borrow_mut ( ) . complete_task ( key, task. unwrap ( ) , fingerprint)
190- } )
202+ } ,
203+ hash_result)
191204 }
192205
193206 /// Creates a new dep-graph input with value `input`
194- pub fn input_task < ' gcx , C , R > ( & self ,
207+ pub fn input_task < ' a , C , R > ( & self ,
195208 key : DepNode ,
196209 cx : C ,
197210 input : R )
198211 -> ( R , DepNodeIndex )
199- where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
200- R : HashStable < StableHashingContext < ' gcx > > ,
212+ where C : DepGraphSafe + StableHashingContextProvider < ' a > ,
213+ R : for < ' b > HashStable < StableHashingContext < ' b > > ,
201214 {
202215 fn identity_fn < C , A > ( _: C , arg : A ) -> A {
203216 arg
@@ -207,10 +220,11 @@ impl DepGraph {
207220 |_| None ,
208221 |data, key, fingerprint, _| {
209222 data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) , fingerprint)
210- } )
223+ } ,
224+ hash_result :: < R > )
211225 }
212226
213- fn with_task_impl < ' gcx , C , A , R > (
227+ fn with_task_impl < ' a , C , A , R > (
214228 & self ,
215229 key : DepNode ,
216230 cx : C ,
@@ -221,11 +235,11 @@ impl DepGraph {
221235 finish_task_and_alloc_depnode : fn ( & Lock < CurrentDepGraph > ,
222236 DepNode ,
223237 Fingerprint ,
224- Option < TaskDeps > ) -> DepNodeIndex
238+ Option < TaskDeps > ) -> DepNodeIndex ,
239+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
225240 ) -> ( R , DepNodeIndex )
226241 where
227- C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
228- R : HashStable < StableHashingContext < ' gcx > > ,
242+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
229243 {
230244 if let Some ( ref data) = self . data {
231245 let task_deps = create_task ( key) . map ( |deps| Lock :: new ( deps) ) ;
@@ -260,31 +274,33 @@ impl DepGraph {
260274 profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd )
261275 } ;
262276
263- let mut stable_hasher = StableHasher :: new ( ) ;
264- result. hash_stable ( & mut hcx, & mut stable_hasher) ;
265-
266- let current_fingerprint = stable_hasher. finish ( ) ;
277+ let current_fingerprint = hash_result ( & mut hcx, & result) ;
267278
268279 let dep_node_index = finish_task_and_alloc_depnode (
269280 & data. current ,
270281 key,
271- current_fingerprint,
282+ current_fingerprint. unwrap_or ( Fingerprint :: ZERO ) ,
272283 task_deps. map ( |lock| lock. into_inner ( ) ) ,
273284 ) ;
274285
275286 // Determine the color of the new DepNode.
276287 if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
277288 let prev_fingerprint = data. previous . fingerprint_by_index ( prev_index) ;
278289
279- let color = if current_fingerprint == prev_fingerprint {
280- DepNodeColor :: Green ( dep_node_index)
290+ let color = if let Some ( current_fingerprint) = current_fingerprint {
291+ if current_fingerprint == prev_fingerprint {
292+ DepNodeColor :: Green ( dep_node_index)
293+ } else {
294+ DepNodeColor :: Red
295+ }
281296 } else {
297+ // Mark the node as Red if we can't hash the result
282298 DepNodeColor :: Red
283299 } ;
284300
285301 debug_assert ! ( data. colors. get( prev_index) . is_none( ) ,
286- "DepGraph::with_task() - Duplicate DepNodeColor \
287- insertion for {:?}", key) ;
302+ "DepGraph::with_task() - Duplicate DepNodeColor \
303+ insertion for {:?}", key) ;
288304
289305 data. colors . insert ( prev_index, color) ;
290306 }
@@ -333,14 +349,16 @@ impl DepGraph {
333349
334350 /// Execute something within an "eval-always" task which is a task
335351 // that runs whenever anything changes.
336- pub fn with_eval_always_task < ' gcx , C , A , R > ( & self ,
337- key : DepNode ,
338- cx : C ,
339- arg : A ,
340- task : fn ( C , A ) -> R )
341- -> ( R , DepNodeIndex )
342- where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
343- R : HashStable < StableHashingContext < ' gcx > > ,
352+ pub fn with_eval_always_task < ' a , C , A , R > (
353+ & self ,
354+ key : DepNode ,
355+ cx : C ,
356+ arg : A ,
357+ task : fn ( C , A ) -> R ,
358+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
359+ ) -> ( R , DepNodeIndex )
360+ where
361+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
344362 {
345363 self . with_task_impl ( key, cx, arg, false , task,
346364 |_| None ,
@@ -350,7 +368,8 @@ impl DepGraph {
350368 & DepNode :: new_no_params ( DepKind :: Krate )
351369 ] ;
352370 current. alloc_node ( key, smallvec ! [ krate_idx] , fingerprint)
353- } )
371+ } ,
372+ hash_result)
354373 }
355374
356375 #[ inline]
0 commit comments