Skip to content

Commit 1851fc4

Browse files
committed
Reintroduce assertion.
1 parent 545ec63 commit 1851fc4

File tree

2 files changed

+39
-0
lines changed
  • compiler

2 files changed

+39
-0
lines changed

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,13 @@ pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) ->
10881088
// know that later). If we are not doing LTO, there is only one optimized
10891089
// version of each module, so we re-use that.
10901090
let dep_node = cgu.codegen_dep_node(tcx);
1091+
tcx.dep_graph.assert_nonexistent_node(&dep_node, || {
1092+
format!(
1093+
"CompileCodegenUnit dep-node for CGU `{}` already exists before marking.",
1094+
cgu.name()
1095+
)
1096+
});
1097+
10911098
if tcx.try_mark_green(&dep_node) {
10921099
// We can re-use either the pre- or the post-thinlto state. If no LTO is
10931100
// 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
@@ -346,6 +346,14 @@ impl<D: Deps> DepGraphData<D> {
346346
task: fn(Ctxt, A) -> R,
347347
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
348348
) -> (R, DepNodeIndex) {
349+
self.assert_nonexistent_node(&key, || {
350+
format!(
351+
"forcing query with already existing `DepNode`\n\
352+
- query-key: {arg:?}\n\
353+
- dep-node: {key:?}"
354+
)
355+
});
356+
349357
let with_deps = |task_deps| D::with_deps(task_deps, || task(cx, arg));
350358
let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
351359
(with_deps(TaskDepsRef::EvalAlways), EdgesVec::new())
@@ -620,6 +628,18 @@ impl<D: Deps> DepGraph<D> {
620628
}
621629

622630
impl<D: Deps> DepGraphData<D> {
631+
fn assert_nonexistent_node<S: std::fmt::Display>(
632+
&self,
633+
_dep_node: &DepNode,
634+
_msg: impl FnOnce() -> S,
635+
) {
636+
#[cfg(debug_assertions)]
637+
if let Some(seen_dep_nodes) = &self.current.seen_dep_nodes {
638+
let seen = seen_dep_nodes.lock().contains(_dep_node);
639+
assert!(!seen, "{}", _msg());
640+
}
641+
}
642+
623643
fn node_color(&self, dep_node: &DepNode) -> Option<DepNodeColor> {
624644
if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) {
625645
self.colors.get(prev_index)
@@ -914,6 +934,18 @@ impl<D: Deps> DepGraph<D> {
914934
self.node_color(dep_node).is_some_and(|c| c.is_green())
915935
}
916936

937+
pub fn assert_nonexistent_node<S: std::fmt::Display>(
938+
&self,
939+
dep_node: &DepNode,
940+
msg: impl FnOnce() -> S,
941+
) {
942+
if cfg!(debug_assertions)
943+
&& let Some(data) = &self.data
944+
{
945+
data.assert_nonexistent_node(dep_node, msg)
946+
}
947+
}
948+
917949
/// This method loads all on-disk cacheable query results into memory, so
918950
/// they can be written out to the new cache file again. Most query results
919951
/// will already be in memory but in the case where we marked something as

0 commit comments

Comments
 (0)