@@ -207,6 +207,10 @@ impl<D: Deps> DepGraph<D> {
207207 }
208208 }
209209
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+
210214 pub fn with_ignore < OP , R > ( & self , op : OP ) -> R
211215 where
212216 OP : FnOnce ( ) -> R ,
@@ -361,6 +365,7 @@ impl<D: Deps> DepGraphData<D> {
361365 node : Some ( key) ,
362366 reads : EdgesVec :: new ( ) ,
363367 read_set : Default :: default ( ) ,
368+ created_def_ids : 0 ,
364369 } ) ;
365370 ( with_deps ( TaskDepsRef :: Allow ( & task_deps) ) , task_deps. into_inner ( ) . reads )
366371 } ;
@@ -476,6 +481,12 @@ impl<D: Deps> DepGraph<D> {
476481 return ;
477482 }
478483 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 ,
479490 TaskDepsRef :: Forbid => {
480491 // Reading is forbidden in this context. ICE with a useful error message.
481492 panic_on_forbidden_read ( data, dep_node_index)
@@ -526,7 +537,9 @@ impl<D: Deps> DepGraph<D> {
526537 pub fn record_diagnostic < Qcx : QueryContext > ( & self , qcx : Qcx , diagnostic : & DiagInner ) {
527538 if let Some ( ref data) = self . data {
528539 D :: read_deps ( |task_deps| match task_deps {
529- TaskDepsRef :: EvalAlways | TaskDepsRef :: Ignore => return ,
540+ TaskDepsRef :: EvalAlways | TaskDepsRef :: Ignore | TaskDepsRef :: Replay { .. } => {
541+ return ;
542+ }
530543 TaskDepsRef :: Forbid | TaskDepsRef :: Allow ( ..) => {
531544 self . read_index ( data. encode_diagnostic ( qcx, diagnostic) ) ;
532545 }
@@ -607,7 +620,7 @@ impl<D: Deps> DepGraph<D> {
607620 edges. push ( DepNodeIndex :: FOREVER_RED_NODE ) ;
608621 }
609622 TaskDepsRef :: Ignore => { }
610- TaskDepsRef :: Forbid => {
623+ TaskDepsRef :: Replay { .. } | TaskDepsRef :: Forbid => {
611624 panic ! ( "Cannot summarize when dependencies are not recorded." )
612625 }
613626 } ) ;
@@ -1317,6 +1330,17 @@ pub enum TaskDepsRef<'a> {
13171330 /// to ensure that the decoding process doesn't itself
13181331 /// require the execution of any queries.
13191332 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+ } ,
13201344}
13211345
13221346#[ derive( Debug ) ]
@@ -1325,6 +1349,8 @@ pub struct TaskDeps {
13251349 node : Option < DepNode > ,
13261350 reads : EdgesVec ,
13271351 read_set : FxHashSet < DepNodeIndex > ,
1352+ /// Every new `DefId` created increases this counter so that they can be replayed.
1353+ created_def_ids : u32 ,
13281354}
13291355
13301356impl Default for TaskDeps {
@@ -1334,9 +1360,19 @@ impl Default for TaskDeps {
13341360 node : None ,
13351361 reads : EdgesVec :: new ( ) ,
13361362 read_set : FxHashSet :: with_capacity_and_hasher ( 128 , Default :: default ( ) ) ,
1363+ created_def_ids : 0 ,
13371364 }
13381365 }
13391366}
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+
13401376// A data structure that stores Option<DepNodeColor> values as a contiguous
13411377// array, using one u32 per entry.
13421378pub ( super ) struct DepNodeColorMap {
0 commit comments