@@ -79,6 +79,16 @@ struct DepGraphData {
79
79
loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
80
80
}
81
81
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
+
82
92
impl DepGraph {
83
93
84
94
pub fn new ( prev_graph : PreviousDepGraph ,
@@ -178,14 +188,16 @@ impl DepGraph {
178
188
/// `arg` parameter.
179
189
///
180
190
/// [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 > ,
189
201
{
190
202
self . with_task_impl ( key, cx, arg, false , task,
191
203
|_key| Some ( TaskDeps {
@@ -196,17 +208,18 @@ impl DepGraph {
196
208
} ) ,
197
209
|data, key, fingerprint, task| {
198
210
data. borrow_mut ( ) . complete_task ( key, task. unwrap ( ) , fingerprint)
199
- } )
211
+ } ,
212
+ hash_result)
200
213
}
201
214
202
215
/// 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 ,
204
217
key : DepNode ,
205
218
cx : C ,
206
219
input : R )
207
220
-> ( 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 > > ,
210
223
{
211
224
fn identity_fn < C , A > ( _: C , arg : A ) -> A {
212
225
arg
@@ -216,10 +229,11 @@ impl DepGraph {
216
229
|_| None ,
217
230
|data, key, fingerprint, _| {
218
231
data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) , fingerprint)
219
- } )
232
+ } ,
233
+ hash_result :: < R > )
220
234
}
221
235
222
- fn with_task_impl < ' gcx , C , A , R > (
236
+ fn with_task_impl < ' a , C , A , R > (
223
237
& self ,
224
238
key : DepNode ,
225
239
cx : C ,
@@ -230,11 +244,11 @@ impl DepGraph {
230
244
finish_task_and_alloc_depnode : fn ( & Lock < CurrentDepGraph > ,
231
245
DepNode ,
232
246
Fingerprint ,
233
- Option < TaskDeps > ) -> DepNodeIndex
247
+ Option < TaskDeps > ) -> DepNodeIndex ,
248
+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
234
249
) -> ( R , DepNodeIndex )
235
250
where
236
- C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
237
- R : HashStable < StableHashingContext < ' gcx > > ,
251
+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
238
252
{
239
253
if let Some ( ref data) = self . data {
240
254
let task_deps = create_task ( key) . map ( |deps| Lock :: new ( deps) ) ;
@@ -269,31 +283,33 @@ impl DepGraph {
269
283
profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd )
270
284
} ;
271
285
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) ;
276
287
277
288
let dep_node_index = finish_task_and_alloc_depnode (
278
289
& data. current ,
279
290
key,
280
- current_fingerprint,
291
+ current_fingerprint. unwrap_or ( Fingerprint :: ZERO ) ,
281
292
task_deps. map ( |lock| lock. into_inner ( ) ) ,
282
293
) ;
283
294
284
295
// Determine the color of the new DepNode.
285
296
if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
286
297
let prev_fingerprint = data. previous . fingerprint_by_index ( prev_index) ;
287
298
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
+ }
290
305
} else {
306
+ // Mark the node as Red if we can't hash the result
291
307
DepNodeColor :: Red
292
308
} ;
293
309
294
310
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) ;
297
313
298
314
data. colors . insert ( prev_index, color) ;
299
315
}
@@ -342,14 +358,16 @@ impl DepGraph {
342
358
343
359
/// Execute something within an "eval-always" task which is a task
344
360
// 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 > ,
353
371
{
354
372
self . with_task_impl ( key, cx, arg, false , task,
355
373
|_| None ,
@@ -359,7 +377,8 @@ impl DepGraph {
359
377
& DepNode :: new_no_params ( DepKind :: Krate )
360
378
] ;
361
379
current. alloc_node ( key, smallvec ! [ krate_idx] , fingerprint)
362
- } )
380
+ } ,
381
+ hash_result)
363
382
}
364
383
365
384
#[ inline]
0 commit comments