@@ -11,7 +11,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111use rustc_data_structures:: profiling:: { QueryInvocationId , SelfProfilerRef } ;
1212use rustc_data_structures:: sharded:: { self , Sharded } ;
1313use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
14- use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc } ;
14+ use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , AtomicUsize , Lock , Lrc } ;
1515use rustc_data_structures:: unord:: UnordMap ;
1616use rustc_index:: IndexVec ;
1717use rustc_macros:: { Decodable , Encodable } ;
@@ -224,6 +224,15 @@ impl<D: Deps> DepGraph<D> {
224224 D :: with_deps ( TaskDepsRef :: Ignore , op)
225225 }
226226
227+ pub ( crate ) fn with_replay < R > (
228+ & self ,
229+ prev_side_effects : & QuerySideEffects ,
230+ created_def_ids : & AtomicUsize ,
231+ op : impl FnOnce ( ) -> R ,
232+ ) -> R {
233+ D :: with_deps ( TaskDepsRef :: Replay { prev_side_effects, created_def_ids } , op)
234+ }
235+
227236 /// Used to wrap the deserialization of a query result from disk,
228237 /// This method enforces that no new `DepNodes` are created during
229238 /// query result deserialization.
@@ -278,6 +287,7 @@ impl<D: Deps> DepGraph<D> {
278287 }
279288
280289 #[ inline( always) ]
290+ /// A helper for `codegen_cranelift`.
281291 pub fn with_task < Ctxt : HasDepContext < Deps = D > , A : Debug , R > (
282292 & self ,
283293 key : DepNode ,
@@ -477,6 +487,12 @@ impl<D: Deps> DepGraph<D> {
477487 return ;
478488 }
479489 TaskDepsRef :: Ignore => return ,
490+ // We don't need to record dependencies when rerunning a query
491+ // because we have no disk cache entry to load. The dependencies
492+ // are preserved.
493+ // FIXME: assert that the dependencies don't change instead of
494+ // recording them.
495+ TaskDepsRef :: Replay { .. } => return ,
480496 TaskDepsRef :: Forbid => {
481497 // Reading is forbidden in this context. ICE with a useful error message.
482498 panic_on_forbidden_read ( data, dep_node_index)
@@ -583,6 +599,7 @@ impl<D: Deps> DepGraph<D> {
583599 edges. push ( DepNodeIndex :: FOREVER_RED_NODE ) ;
584600 }
585601 TaskDepsRef :: Ignore => { }
602+ TaskDepsRef :: Replay { .. } => { }
586603 TaskDepsRef :: Forbid => {
587604 panic ! ( "Cannot summarize when dependencies are not recorded." )
588605 }
@@ -1284,6 +1301,18 @@ pub enum TaskDepsRef<'a> {
12841301 /// to ensure that the decoding process doesn't itself
12851302 /// require the execution of any queries.
12861303 Forbid ,
1304+ /// Side effects from the previous run made available to
1305+ /// queries when they are reexecuted because their result was not
1306+ /// available in the cache. Whenever the query creates a new `DefId`,
1307+ /// it is checked against the entries in `QuerySideEffects::definitions`
1308+ /// to ensure that the new `DefId`s are the same as the ones that were
1309+ /// created the last time the query was executed.
1310+ Replay {
1311+ prev_side_effects : & ' a QuerySideEffects ,
1312+ /// Every new `DefId` is pushed here so we can check
1313+ /// that they match the cached ones.
1314+ created_def_ids : & ' a AtomicUsize ,
1315+ } ,
12871316}
12881317
12891318#[ derive( Debug ) ]
0 commit comments