@@ -11,7 +11,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
11
11
use rustc_data_structures:: profiling:: { QueryInvocationId , SelfProfilerRef } ;
12
12
use rustc_data_structures:: sharded:: { self , Sharded } ;
13
13
use 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 } ;
15
15
use rustc_data_structures:: unord:: UnordMap ;
16
16
use rustc_index:: IndexVec ;
17
17
use rustc_macros:: { Decodable , Encodable } ;
@@ -224,6 +224,15 @@ impl<D: Deps> DepGraph<D> {
224
224
D :: with_deps ( TaskDepsRef :: Ignore , op)
225
225
}
226
226
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
+
227
236
/// Used to wrap the deserialization of a query result from disk,
228
237
/// This method enforces that no new `DepNodes` are created during
229
238
/// query result deserialization.
@@ -278,6 +287,7 @@ impl<D: Deps> DepGraph<D> {
278
287
}
279
288
280
289
#[ inline( always) ]
290
+ /// A helper for `codegen_cranelift`.
281
291
pub fn with_task < Ctxt : HasDepContext < Deps = D > , A : Debug , R > (
282
292
& self ,
283
293
key : DepNode ,
@@ -477,6 +487,12 @@ impl<D: Deps> DepGraph<D> {
477
487
return ;
478
488
}
479
489
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 ,
480
496
TaskDepsRef :: Forbid => {
481
497
// Reading is forbidden in this context. ICE with a useful error message.
482
498
panic_on_forbidden_read ( data, dep_node_index)
@@ -583,6 +599,7 @@ impl<D: Deps> DepGraph<D> {
583
599
edges. push ( DepNodeIndex :: FOREVER_RED_NODE ) ;
584
600
}
585
601
TaskDepsRef :: Ignore => { }
602
+ TaskDepsRef :: Replay { .. } => { }
586
603
TaskDepsRef :: Forbid => {
587
604
panic ! ( "Cannot summarize when dependencies are not recorded." )
588
605
}
@@ -1284,6 +1301,18 @@ pub enum TaskDepsRef<'a> {
1284
1301
/// to ensure that the decoding process doesn't itself
1285
1302
/// require the execution of any queries.
1286
1303
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
+ } ,
1287
1316
}
1288
1317
1289
1318
#[ derive( Debug ) ]
0 commit comments