@@ -207,6 +207,10 @@ impl<D: Deps> DepGraph<D> {
207
207
}
208
208
}
209
209
210
+ pub ( crate ) fn with_replay < R > ( & self , created_def_ids : & AtomicU32 , op : impl FnOnce ( ) -> R ) -> R {
211
+ D :: with_deps ( TaskDepsRef :: Replay { created_def_ids } , op)
212
+ }
213
+
210
214
pub fn with_ignore < OP , R > ( & self , op : OP ) -> R
211
215
where
212
216
OP : FnOnce ( ) -> R ,
@@ -361,6 +365,7 @@ impl<D: Deps> DepGraphData<D> {
361
365
node : Some ( key) ,
362
366
reads : EdgesVec :: new ( ) ,
363
367
read_set : Default :: default ( ) ,
368
+ created_def_ids : 0 ,
364
369
} ) ;
365
370
( with_deps ( TaskDepsRef :: Allow ( & task_deps) ) , task_deps. into_inner ( ) . reads )
366
371
} ;
@@ -476,6 +481,12 @@ impl<D: Deps> DepGraph<D> {
476
481
return ;
477
482
}
478
483
TaskDepsRef :: Ignore => return ,
484
+ // We don't need to record dependencies when rerunning a query
485
+ // because we have no disk cache entry to load. The dependencies
486
+ // are preserved.
487
+ // FIXME: assert that the dependencies don't change instead of
488
+ // recording them.
489
+ TaskDepsRef :: Replay { .. } => return ,
479
490
TaskDepsRef :: Forbid => {
480
491
// Reading is forbidden in this context. ICE with a useful error message.
481
492
panic_on_forbidden_read ( data, dep_node_index)
@@ -526,7 +537,9 @@ impl<D: Deps> DepGraph<D> {
526
537
pub fn record_diagnostic < Qcx : QueryContext > ( & self , qcx : Qcx , diagnostic : & DiagInner ) {
527
538
if let Some ( ref data) = self . data {
528
539
D :: read_deps ( |task_deps| match task_deps {
529
- TaskDepsRef :: EvalAlways | TaskDepsRef :: Ignore => return ,
540
+ TaskDepsRef :: EvalAlways | TaskDepsRef :: Ignore | TaskDepsRef :: Replay { .. } => {
541
+ return ;
542
+ }
530
543
TaskDepsRef :: Forbid | TaskDepsRef :: Allow ( ..) => {
531
544
self . read_index ( data. encode_diagnostic ( qcx, diagnostic) ) ;
532
545
}
@@ -607,7 +620,7 @@ impl<D: Deps> DepGraph<D> {
607
620
edges. push ( DepNodeIndex :: FOREVER_RED_NODE ) ;
608
621
}
609
622
TaskDepsRef :: Ignore => { }
610
- TaskDepsRef :: Forbid => {
623
+ TaskDepsRef :: Replay { .. } | TaskDepsRef :: Forbid => {
611
624
panic ! ( "Cannot summarize when dependencies are not recorded." )
612
625
}
613
626
} ) ;
@@ -1317,6 +1330,17 @@ pub enum TaskDepsRef<'a> {
1317
1330
/// to ensure that the decoding process doesn't itself
1318
1331
/// require the execution of any queries.
1319
1332
Forbid ,
1333
+ /// Side effects from the previous run made available to
1334
+ /// queries when they are reexecuted because their result was not
1335
+ /// available in the cache. Whenever the query creates a new `DefId`,
1336
+ /// it is checked against the entries in `QuerySideEffects::definitions`
1337
+ /// to ensure that the new `DefId`s are the same as the ones that were
1338
+ /// created the last time the query was executed.
1339
+ Replay {
1340
+ /// Every new `DefId` created increases this counter so that we produce the same ones
1341
+ /// as the original execution created.
1342
+ created_def_ids : & ' a AtomicU32 ,
1343
+ } ,
1320
1344
}
1321
1345
1322
1346
#[ derive( Debug ) ]
@@ -1325,6 +1349,8 @@ pub struct TaskDeps {
1325
1349
node : Option < DepNode > ,
1326
1350
reads : EdgesVec ,
1327
1351
read_set : FxHashSet < DepNodeIndex > ,
1352
+ /// Every new `DefId` created increases this counter so that they can be replayed.
1353
+ created_def_ids : u32 ,
1328
1354
}
1329
1355
1330
1356
impl Default for TaskDeps {
@@ -1334,9 +1360,19 @@ impl Default for TaskDeps {
1334
1360
node : None ,
1335
1361
reads : EdgesVec :: new ( ) ,
1336
1362
read_set : FxHashSet :: with_capacity_and_hasher ( 128 , Default :: default ( ) ) ,
1363
+ created_def_ids : 0 ,
1337
1364
}
1338
1365
}
1339
1366
}
1367
+
1368
+ impl TaskDeps {
1369
+ pub fn next_def_id_idx ( & mut self ) -> u32 {
1370
+ let idx = self . created_def_ids ;
1371
+ self . created_def_ids += 1 ;
1372
+ idx
1373
+ }
1374
+ }
1375
+
1340
1376
// A data structure that stores Option<DepNodeColor> values as a contiguous
1341
1377
// array, using one u32 per entry.
1342
1378
pub ( super ) struct DepNodeColorMap {
0 commit comments