@@ -79,6 +79,16 @@ struct DepGraphData {
7979 loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
8080}
8181
82+ pub fn hash_result < R > ( hcx : & mut StableHashingContext < ' _ > , result : & R ) -> Option < Fingerprint >
83+ where
84+ R : for < ' a > HashStable < StableHashingContext < ' a > > ,
85+ {
86+ let mut stable_hasher = StableHasher :: new ( ) ;
87+ result. hash_stable ( hcx, & mut stable_hasher) ;
88+
89+ Some ( stable_hasher. finish ( ) )
90+ }
91+
8292impl DepGraph {
8393
8494 pub fn new ( prev_graph : PreviousDepGraph ,
@@ -178,14 +188,16 @@ impl DepGraph {
178188 /// `arg` parameter.
179189 ///
180190 /// [rustc guide]: https://rust-lang.github.io/rustc-guide/incremental-compilation.html
181- pub fn with_task < ' gcx , C , A , R > ( & self ,
182- key : DepNode ,
183- cx : C ,
184- arg : A ,
185- task : fn ( C , A ) -> R )
186- -> ( R , DepNodeIndex )
187- where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
188- R : HashStable < StableHashingContext < ' gcx > > ,
191+ pub fn with_task < ' a , C , A , R > (
192+ & self ,
193+ key : DepNode ,
194+ cx : C ,
195+ arg : A ,
196+ task : fn ( C , A ) -> R ,
197+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
198+ ) -> ( R , DepNodeIndex )
199+ where
200+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
189201 {
190202 self . with_task_impl ( key, cx, arg, false , task,
191203 |_key| Some ( TaskDeps {
@@ -196,17 +208,18 @@ impl DepGraph {
196208 } ) ,
197209 |data, key, fingerprint, task| {
198210 data. borrow_mut ( ) . complete_task ( key, task. unwrap ( ) , fingerprint)
199- } )
211+ } ,
212+ hash_result)
200213 }
201214
202215 /// Creates a new dep-graph input with value `input`
203- pub fn input_task < ' gcx , C , R > ( & self ,
216+ pub fn input_task < ' a , C , R > ( & self ,
204217 key : DepNode ,
205218 cx : C ,
206219 input : R )
207220 -> ( R , DepNodeIndex )
208- where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
209- R : HashStable < StableHashingContext < ' gcx > > ,
221+ where C : DepGraphSafe + StableHashingContextProvider < ' a > ,
222+ R : for < ' b > HashStable < StableHashingContext < ' b > > ,
210223 {
211224 fn identity_fn < C , A > ( _: C , arg : A ) -> A {
212225 arg
@@ -216,10 +229,11 @@ impl DepGraph {
216229 |_| None ,
217230 |data, key, fingerprint, _| {
218231 data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) , fingerprint)
219- } )
232+ } ,
233+ hash_result :: < R > )
220234 }
221235
222- fn with_task_impl < ' gcx , C , A , R > (
236+ fn with_task_impl < ' a , C , A , R > (
223237 & self ,
224238 key : DepNode ,
225239 cx : C ,
@@ -230,11 +244,11 @@ impl DepGraph {
230244 finish_task_and_alloc_depnode : fn ( & Lock < CurrentDepGraph > ,
231245 DepNode ,
232246 Fingerprint ,
233- Option < TaskDeps > ) -> DepNodeIndex
247+ Option < TaskDeps > ) -> DepNodeIndex ,
248+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
234249 ) -> ( R , DepNodeIndex )
235250 where
236- C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
237- R : HashStable < StableHashingContext < ' gcx > > ,
251+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
238252 {
239253 if let Some ( ref data) = self . data {
240254 let task_deps = create_task ( key) . map ( |deps| Lock :: new ( deps) ) ;
@@ -269,31 +283,33 @@ impl DepGraph {
269283 profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd )
270284 } ;
271285
272- let mut stable_hasher = StableHasher :: new ( ) ;
273- result. hash_stable ( & mut hcx, & mut stable_hasher) ;
274-
275- let current_fingerprint = stable_hasher. finish ( ) ;
286+ let current_fingerprint = hash_result ( & mut hcx, & result) ;
276287
277288 let dep_node_index = finish_task_and_alloc_depnode (
278289 & data. current ,
279290 key,
280- current_fingerprint,
291+ current_fingerprint. unwrap_or ( Fingerprint :: ZERO ) ,
281292 task_deps. map ( |lock| lock. into_inner ( ) ) ,
282293 ) ;
283294
284295 // Determine the color of the new DepNode.
285296 if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
286297 let prev_fingerprint = data. previous . fingerprint_by_index ( prev_index) ;
287298
288- let color = if current_fingerprint == prev_fingerprint {
289- DepNodeColor :: Green ( dep_node_index)
299+ let color = if let Some ( current_fingerprint) = current_fingerprint {
300+ if current_fingerprint == prev_fingerprint {
301+ DepNodeColor :: Green ( dep_node_index)
302+ } else {
303+ DepNodeColor :: Red
304+ }
290305 } else {
306+ // Mark the node as Red if we can't hash the result
291307 DepNodeColor :: Red
292308 } ;
293309
294310 debug_assert ! ( data. colors. get( prev_index) . is_none( ) ,
295- "DepGraph::with_task() - Duplicate DepNodeColor \
296- insertion for {:?}", key) ;
311+ "DepGraph::with_task() - Duplicate DepNodeColor \
312+ insertion for {:?}", key) ;
297313
298314 data. colors . insert ( prev_index, color) ;
299315 }
@@ -342,14 +358,16 @@ impl DepGraph {
342358
343359 /// Execute something within an "eval-always" task which is a task
344360 // that runs whenever anything changes.
345- pub fn with_eval_always_task < ' gcx , C , A , R > ( & self ,
346- key : DepNode ,
347- cx : C ,
348- arg : A ,
349- task : fn ( C , A ) -> R )
350- -> ( R , DepNodeIndex )
351- where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
352- R : HashStable < StableHashingContext < ' gcx > > ,
361+ pub fn with_eval_always_task < ' a , C , A , R > (
362+ & self ,
363+ key : DepNode ,
364+ cx : C ,
365+ arg : A ,
366+ task : fn ( C , A ) -> R ,
367+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
368+ ) -> ( R , DepNodeIndex )
369+ where
370+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
353371 {
354372 self . with_task_impl ( key, cx, arg, false , task,
355373 |_| None ,
@@ -359,7 +377,8 @@ impl DepGraph {
359377 & DepNode :: new_no_params ( DepKind :: Krate )
360378 ] ;
361379 current. alloc_node ( key, smallvec ! [ krate_idx] , fingerprint)
362- } )
380+ } ,
381+ hash_result)
363382 }
364383
365384 #[ inline]
0 commit comments