Skip to content

Commit 25ab873

Browse files
committed
Reintroduce assertion.
1 parent 43e9502 commit 25ab873

File tree

3 files changed

+46
-0
lines changed
  • compiler
    • rustc_codegen_cranelift/src/driver
    • rustc_codegen_ssa/src
    • rustc_query_system/src/dep_graph

3 files changed

+46
-0
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,5 +522,12 @@ fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguR
522522
// know that later). If we are not doing LTO, there is only one optimized
523523
// version of each module, so we re-use that.
524524
let dep_node = cgu.codegen_dep_node(tcx);
525+
tcx.dep_graph.assert_nonexistent_node(&dep_node, || {
526+
format!(
527+
"CompileCodegenUnit dep-node for CGU `{}` already exists before marking.",
528+
cgu.name()
529+
)
530+
});
531+
525532
if tcx.try_mark_green(&dep_node) { CguReuse::PostLto } else { CguReuse::No }
526533
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,13 @@ fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguR
10091009
// know that later). If we are not doing LTO, there is only one optimized
10101010
// version of each module, so we re-use that.
10111011
let dep_node = cgu.codegen_dep_node(tcx);
1012+
tcx.dep_graph.assert_nonexistent_node(&dep_node, || {
1013+
format!(
1014+
"CompileCodegenUnit dep-node for CGU `{}` already exists before marking.",
1015+
cgu.name()
1016+
)
1017+
});
1018+
10121019
if tcx.try_mark_green(&dep_node) {
10131020
// We can re-use either the pre- or the post-thinlto state. If no LTO is
10141021
// being performed then we can use post-LTO artifacts, otherwise we must

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ impl<K: DepKind> DepGraphData<K> {
343343
task: fn(Ctxt, A) -> R,
344344
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
345345
) -> (R, DepNodeIndex) {
346+
self.assert_nonexistent_node(&key, || {
347+
format!(
348+
"forcing query with already existing `DepNode`\n\
349+
- query-key: {arg:?}\n\
350+
- dep-node: {key:?}"
351+
)
352+
});
353+
346354
let with_deps = |task_deps| K::with_deps(task_deps, || task(cx, arg));
347355
let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
348356
(with_deps(TaskDepsRef::EvalAlways), smallvec![])
@@ -633,6 +641,18 @@ impl<K: DepKind> DepGraph<K> {
633641
}
634642

635643
impl<K: DepKind> DepGraphData<K> {
644+
fn assert_nonexistent_node<S: std::fmt::Display>(
645+
&self,
646+
_dep_node: &DepNode<K>,
647+
_msg: impl FnOnce() -> S,
648+
) {
649+
#[cfg(debug_assertions)]
650+
if let Some(seen_dep_nodes) = &self.current.seen_dep_nodes {
651+
let seen = seen_dep_nodes.lock().contains(_dep_node);
652+
assert!(!seen, "{}", _msg());
653+
}
654+
}
655+
636656
fn node_color(&self, dep_node: &DepNode<K>) -> Option<DepNodeColor> {
637657
if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) {
638658
self.colors.get(prev_index)
@@ -940,6 +960,18 @@ impl<K: DepKind> DepGraph<K> {
940960
self.node_color(dep_node).is_some_and(|c| c.is_green())
941961
}
942962

963+
pub fn assert_nonexistent_node<S: std::fmt::Display>(
964+
&self,
965+
dep_node: &DepNode<K>,
966+
msg: impl FnOnce() -> S,
967+
) {
968+
if cfg!(debug_assertions)
969+
&& let Some(data) = &self.data
970+
{
971+
data.assert_nonexistent_node(dep_node, msg)
972+
}
973+
}
974+
943975
/// This method loads all on-disk cacheable query results into memory, so
944976
/// they can be written out to the new cache file again. Most query results
945977
/// will already be in memory but in the case where we marked something as

0 commit comments

Comments
 (0)