Auto merge of #115613 - oli-obk:create_def_forever_red, r= · rust-lang/rust@ffbd260 (original) (raw)
1
1
`use std::assert_matches::assert_matches;
`
2
2
`use std::fmt::Debug;
`
3
3
`use std::hash::Hash;
`
4
``
`-
use std:📑:PhantomData;
`
5
4
`use std::sync::Arc;
`
6
5
`use std::sync::atomic::{AtomicU32, Ordering};
`
7
6
``
`@@ -208,6 +207,10 @@ impl<D: Deps> DepGraph {
`
208
207
`}
`
209
208
`}
`
210
209
``
``
210
`+
pub(crate) fn with_replay(&self, created_def_ids: &AtomicU32, op: impl FnOnce() -> R) -> R {
`
``
211
`+
D::with_deps(TaskDepsRef::Replay { created_def_ids }, op)
`
``
212
`+
}
`
``
213
+
211
214
`pub fn with_ignore<OP, R>(&self, op: OP) -> R
`
212
215
`where
`
213
216
`OP: FnOnce() -> R,
`
`@@ -362,7 +365,7 @@ impl<D: Deps> DepGraphData {
`
362
365
`node: Some(key),
`
363
366
`reads: EdgesVec::new(),
`
364
367
`read_set: Default::default(),
`
365
``
`-
phantom_data: PhantomData,
`
``
368
`+
created_def_ids: 0,
`
366
369
`});
`
367
370
`(with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads)
`
368
371
`};
`
`@@ -478,6 +481,12 @@ impl<D: Deps> DepGraph {
`
478
481
`return;
`
479
482
`}
`
480
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,
`
481
490
`TaskDepsRef::Forbid => {
`
482
491
`// Reading is forbidden in this context. ICE with a useful error message.
`
483
492
`panic_on_forbidden_read(data, dep_node_index)
`
`@@ -528,7 +537,9 @@ impl<D: Deps> DepGraph {
`
528
537
`pub fn record_diagnostic<Qcx: QueryContext>(&self, qcx: Qcx, diagnostic: &DiagInner) {
`
529
538
`if let Some(ref data) = self.data {
`
530
539
`D::read_deps(|task_deps| match task_deps {
`
531
``
`-
TaskDepsRef::EvalAlways | TaskDepsRef::Ignore => return,
`
``
540
`+
TaskDepsRef::EvalAlways | TaskDepsRef::Ignore | TaskDepsRef::Replay { .. } => {
`
``
541
`+
return;
`
``
542
`+
}
`
532
543
`TaskDepsRef::Forbid | TaskDepsRef::Allow(..) => {
`
533
544
`self.read_index(data.encode_diagnostic(qcx, diagnostic));
`
534
545
`}
`
`@@ -609,7 +620,7 @@ impl<D: Deps> DepGraph {
`
609
620
` edges.push(DepNodeIndex::FOREVER_RED_NODE);
`
610
621
`}
`
611
622
`TaskDepsRef::Ignore => {}
`
612
``
`-
TaskDepsRef::Forbid => {
`
``
623
`+
TaskDepsRef::Replay { .. } | TaskDepsRef::Forbid => {
`
613
624
`panic!("Cannot summarize when dependencies are not recorded.")
`
614
625
`}
`
615
626
`});
`
`@@ -1319,6 +1330,17 @@ pub enum TaskDepsRef<'a> {
`
1319
1330
`/// to ensure that the decoding process doesn't itself
`
1320
1331
`/// require the execution of any queries.
`
1321
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
`+
},
`
1322
1344
`}
`
1323
1345
``
1324
1346
`#[derive(Debug)]
`
`@@ -1327,7 +1349,8 @@ pub struct TaskDeps {
`
1327
1349
`node: Option,
`
1328
1350
`reads: EdgesVec,
`
1329
1351
`read_set: FxHashSet,
`
1330
``
`-
phantom_data: PhantomData,
`
``
1352
`` +
/// Every new DefId
created increases this counter so that they can be replayed.
``
``
1353
`+
created_def_ids: u32,
`
1331
1354
`}
`
1332
1355
``
1333
1356
`impl Default for TaskDeps {
`
`@@ -1337,10 +1360,19 @@ impl Default for TaskDeps {
`
1337
1360
`node: None,
`
1338
1361
`reads: EdgesVec::new(),
`
1339
1362
`read_set: FxHashSet::with_capacity_and_hasher(128, Default::default()),
`
1340
``
`-
phantom_data: PhantomData,
`
``
1363
`+
created_def_ids: 0,
`
1341
1364
`}
`
1342
1365
`}
`
1343
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
+
1344
1376
`// A data structure that stores Option values as a contiguous
`
1345
1377
`// array, using one u32 per entry.
`
1346
1378
`pub(super) struct DepNodeColorMap {
`