@@ -204,13 +204,31 @@ impl DepGraph {
204
204
where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
205
205
R : HashStable < StableHashingContext < ' gcx > > ,
206
206
{
207
- self . with_task_impl ( key, cx, arg, false , task,
207
+ self . with_task_impl ( key, cx, arg, false , true , task,
208
208
|key| OpenTask :: Regular ( Lock :: new ( RegularOpenTask {
209
209
node : key,
210
210
reads : SmallVec :: new ( ) ,
211
211
read_set : FxHashSet ( ) ,
212
212
} ) ) ,
213
- |data, key, task| data. borrow_mut ( ) . complete_task ( key, task) )
213
+ |data, key, task| data. borrow_mut ( ) . complete_task ( key, task, false ) )
214
+ }
215
+
216
+ pub fn with_forced_task < ' gcx , C , A , R > ( & self ,
217
+ key : DepNode ,
218
+ cx : C ,
219
+ arg : A ,
220
+ task : fn ( C , A ) -> R )
221
+ -> ( R , DepNodeIndex )
222
+ where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
223
+ R : HashStable < StableHashingContext < ' gcx > > ,
224
+ {
225
+ self . with_task_impl ( key, cx, arg, false , false , task,
226
+ |key| OpenTask :: Regular ( Lock :: new ( RegularOpenTask {
227
+ node : key,
228
+ reads : SmallVec :: new ( ) ,
229
+ read_set : FxHashSet ( ) ,
230
+ } ) ) ,
231
+ |data, key, task| data. borrow_mut ( ) . complete_task ( key, task, true ) )
214
232
}
215
233
216
234
/// Creates a new dep-graph input with value `input`
@@ -226,7 +244,7 @@ impl DepGraph {
226
244
arg
227
245
}
228
246
229
- self . with_task_impl ( key, cx, input, true , identity_fn,
247
+ self . with_task_impl ( key, cx, input, true , true , identity_fn,
230
248
|_| OpenTask :: Ignore ,
231
249
|data, key, _| data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) ) )
232
250
}
@@ -237,6 +255,7 @@ impl DepGraph {
237
255
cx : C ,
238
256
arg : A ,
239
257
no_tcx : bool ,
258
+ do_fingerprinting : bool ,
240
259
task : fn ( C , A ) -> R ,
241
260
create_task : fn ( DepNode ) -> OpenTask ,
242
261
finish_task_and_alloc_depnode : fn ( & Lock < CurrentDepGraph > ,
@@ -282,41 +301,58 @@ impl DepGraph {
282
301
283
302
let dep_node_index = finish_task_and_alloc_depnode ( & data. current , key, open_task) ;
284
303
285
- let mut stable_hasher = StableHasher :: new ( ) ;
286
- result. hash_stable ( & mut hcx, & mut stable_hasher) ;
304
+ if do_fingerprinting {
305
+ let mut stable_hasher = StableHasher :: new ( ) ;
306
+ result. hash_stable ( & mut hcx, & mut stable_hasher) ;
287
307
288
- let current_fingerprint = stable_hasher. finish ( ) ;
308
+ let current_fingerprint = stable_hasher. finish ( ) ;
289
309
290
- // Store the current fingerprint
291
- {
292
- let mut fingerprints = self . fingerprints . borrow_mut ( ) ;
310
+ // Store the current fingerprint
311
+ {
312
+ let mut fingerprints = self . fingerprints . borrow_mut ( ) ;
313
+
314
+ if dep_node_index. index ( ) >= fingerprints. len ( ) {
315
+ fingerprints. resize ( dep_node_index. index ( ) + 1 , Fingerprint :: ZERO ) ;
316
+ }
293
317
294
- if dep_node_index. index ( ) >= fingerprints. len ( ) {
295
- fingerprints. resize ( dep_node_index. index ( ) + 1 , Fingerprint :: ZERO ) ;
318
+ debug_assert ! ( fingerprints[ dep_node_index] == Fingerprint :: ZERO ,
319
+ "DepGraph::with_task() - Duplicate fingerprint \
320
+ insertion for {:?}", key) ;
321
+ fingerprints[ dep_node_index] = current_fingerprint;
296
322
}
297
323
298
- debug_assert ! ( fingerprints[ dep_node_index] == Fingerprint :: ZERO ,
299
- "DepGraph::with_task() - Duplicate fingerprint \
300
- insertion for {:?}", key) ;
301
- fingerprints[ dep_node_index] = current_fingerprint;
302
- }
324
+ // Determine the color of the new DepNode.
325
+ if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
326
+ let prev_fingerprint = data. previous . fingerprint_by_index ( prev_index) ;
303
327
304
- // Determine the color of the new DepNode.
305
- if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
306
- let prev_fingerprint = data. previous . fingerprint_by_index ( prev_index) ;
328
+ let color = if current_fingerprint == prev_fingerprint {
329
+ DepNodeColor :: Green ( dep_node_index)
330
+ } else {
331
+ DepNodeColor :: Red
332
+ } ;
307
333
308
- let color = if current_fingerprint == prev_fingerprint {
309
- DepNodeColor :: Green ( dep_node_index)
310
- } else {
311
- DepNodeColor :: Red
312
- } ;
334
+ let mut colors = data. colors . borrow_mut ( ) ;
335
+ debug_assert ! ( colors. get( prev_index) . is_none( ) ,
336
+ "DepGraph::with_task() - Duplicate DepNodeColor \
337
+ insertion for {:?}", key) ;
338
+
339
+ colors. insert ( prev_index, color) ;
340
+ }
341
+ } else {
342
+ // Always store a ZERO fingerprint
343
+ {
344
+ let mut fingerprints = self . fingerprints . borrow_mut ( ) ;
313
345
314
- let mut colors = data. colors . borrow_mut ( ) ;
315
- debug_assert ! ( colors. get( prev_index) . is_none( ) ,
316
- "DepGraph::with_task() - Duplicate DepNodeColor \
317
- insertion for {:?}", key) ;
346
+ if dep_node_index. index ( ) >= fingerprints. len ( ) {
347
+ fingerprints. resize ( dep_node_index. index ( ) + 1 , Fingerprint :: ZERO ) ;
348
+ }
349
+
350
+ fingerprints[ dep_node_index] = Fingerprint :: ZERO ;
351
+ }
318
352
319
- colors. insert ( prev_index, color) ;
353
+ if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
354
+ data. colors . borrow_mut ( ) . insert ( prev_index, DepNodeColor :: Red ) ;
355
+ }
320
356
}
321
357
322
358
( result, dep_node_index)
@@ -378,7 +414,7 @@ impl DepGraph {
378
414
}
379
415
380
416
/// Execute something within an "eval-always" task which is a task
381
- // that runs whenever anything changes.
417
+ /// that runs whenever anything changes.
382
418
pub fn with_eval_always_task < ' gcx , C , A , R > ( & self ,
383
419
key : DepNode ,
384
420
cx : C ,
@@ -388,7 +424,7 @@ impl DepGraph {
388
424
where C : DepGraphSafe + StableHashingContextProvider < ' gcx > ,
389
425
R : HashStable < StableHashingContext < ' gcx > > ,
390
426
{
391
- self . with_task_impl ( key, cx, arg, false , task,
427
+ self . with_task_impl ( key, cx, arg, false , true , task,
392
428
|key| OpenTask :: EvalAlways { node : key } ,
393
429
|data, key, task| data. borrow_mut ( ) . complete_eval_always_task ( key, task) )
394
430
}
@@ -939,7 +975,11 @@ impl CurrentDepGraph {
939
975
}
940
976
}
941
977
942
- fn complete_task ( & mut self , key : DepNode , task : OpenTask ) -> DepNodeIndex {
978
+ fn complete_task ( & mut self ,
979
+ key : DepNode ,
980
+ task : OpenTask ,
981
+ allow_existing_dep_node : bool )
982
+ -> DepNodeIndex {
943
983
if let OpenTask :: Regular ( task) = task {
944
984
let RegularOpenTask {
945
985
node,
@@ -970,7 +1010,16 @@ impl CurrentDepGraph {
970
1010
}
971
1011
}
972
1012
973
- self . alloc_node ( node, reads)
1013
+ if allow_existing_dep_node {
1014
+ if let Some ( & dep_node_index) = self . node_to_node_index . get ( & node) {
1015
+ self . edges [ dep_node_index] = reads;
1016
+ dep_node_index
1017
+ } else {
1018
+ self . alloc_node ( node, reads)
1019
+ }
1020
+ } else {
1021
+ self . alloc_node ( node, reads)
1022
+ }
974
1023
} else {
975
1024
bug ! ( "complete_task() - Expected regular task to be popped" )
976
1025
}
0 commit comments