@@ -72,6 +72,16 @@ struct DepGraphData {
72
72
loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
73
73
}
74
74
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
+
75
85
impl DepGraph {
76
86
77
87
pub fn new ( prev_graph : PreviousDepGraph ,
@@ -169,14 +179,16 @@ impl DepGraph {
169
179
/// `arg` parameter.
170
180
///
171
181
/// [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 > ,
180
192
{
181
193
self . with_task_impl ( key, cx, arg, false , task,
182
194
|_key| Some ( TaskDeps {
@@ -187,17 +199,18 @@ impl DepGraph {
187
199
} ) ,
188
200
|data, key, fingerprint, task| {
189
201
data. borrow_mut ( ) . complete_task ( key, task. unwrap ( ) , fingerprint)
190
- } )
202
+ } ,
203
+ hash_result)
191
204
}
192
205
193
206
/// 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 ,
195
208
key : DepNode ,
196
209
cx : C ,
197
210
input : R )
198
211
-> ( 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 > > ,
201
214
{
202
215
fn identity_fn < C , A > ( _: C , arg : A ) -> A {
203
216
arg
@@ -207,10 +220,11 @@ impl DepGraph {
207
220
|_| None ,
208
221
|data, key, fingerprint, _| {
209
222
data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) , fingerprint)
210
- } )
223
+ } ,
224
+ hash_result :: < R > )
211
225
}
212
226
213
- fn with_task_impl < ' gcx , C , A , R > (
227
+ fn with_task_impl < ' a , C , A , R > (
214
228
& self ,
215
229
key : DepNode ,
216
230
cx : C ,
@@ -221,11 +235,11 @@ impl DepGraph {
221
235
finish_task_and_alloc_depnode : fn ( & Lock < CurrentDepGraph > ,
222
236
DepNode ,
223
237
Fingerprint ,
224
- Option < TaskDeps > ) -> DepNodeIndex
238
+ Option < TaskDeps > ) -> DepNodeIndex ,
239
+ hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
225
240
) -> ( R , DepNodeIndex )
226
241
where
227
- C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
228
- R : HashStable < StableHashingContext < ' gcx > > ,
242
+ C : DepGraphSafe + StableHashingContextProvider < ' a > ,
229
243
{
230
244
if let Some ( ref data) = self . data {
231
245
let task_deps = create_task ( key) . map ( |deps| Lock :: new ( deps) ) ;
@@ -260,31 +274,33 @@ impl DepGraph {
260
274
profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd )
261
275
} ;
262
276
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) ;
267
278
268
279
let dep_node_index = finish_task_and_alloc_depnode (
269
280
& data. current ,
270
281
key,
271
- current_fingerprint,
282
+ current_fingerprint. unwrap_or ( Fingerprint :: ZERO ) ,
272
283
task_deps. map ( |lock| lock. into_inner ( ) ) ,
273
284
) ;
274
285
275
286
// Determine the color of the new DepNode.
276
287
if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
277
288
let prev_fingerprint = data. previous . fingerprint_by_index ( prev_index) ;
278
289
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
+ }
281
296
} else {
297
+ // Mark the node as Red if we can't hash the result
282
298
DepNodeColor :: Red
283
299
} ;
284
300
285
301
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) ;
288
304
289
305
data. colors . insert ( prev_index, color) ;
290
306
}
@@ -333,14 +349,16 @@ impl DepGraph {
333
349
334
350
/// Execute something within an "eval-always" task which is a task
335
351
// 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 > ,
344
362
{
345
363
self . with_task_impl ( key, cx, arg, false , task,
346
364
|_| None ,
@@ -350,7 +368,8 @@ impl DepGraph {
350
368
& DepNode :: new_no_params ( DepKind :: Krate )
351
369
] ;
352
370
current. alloc_node ( key, smallvec ! [ krate_idx] , fingerprint)
353
- } )
371
+ } ,
372
+ hash_result)
354
373
}
355
374
356
375
#[ inline]
0 commit comments