From 02bace8476c690a253f2dbdbe0f1fb75d402c8f6 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Fri, 12 Dec 2025 16:35:48 +0300 Subject: [PATCH 1/2] Add a sanity check in case of any duplicate nodes --- compiler/rustc_query_system/src/dep_graph/graph.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index b2c72f19b78be..b85f226d108c6 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -1384,7 +1384,9 @@ impl DepNodeColorMap { #[inline] pub(super) fn insert_red(&self, index: SerializedDepNodeIndex) { - self.values[index].store(COMPRESSED_RED, Ordering::Release) + let value = self.values[index].swap(COMPRESSED_RED, Ordering::Release); + // Sanity check for duplicate nodes + assert_eq!(value, COMPRESSED_UNKNOWN, "trying to encode a dep node twice"); } } From c7b5fb56950c3a7999fa9348096ee55d2773ace2 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Fri, 12 Dec 2025 16:44:17 +0300 Subject: [PATCH 2/2] Also check in case it tries to mark red node as green --- compiler/rustc_query_system/src/dep_graph/graph.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index b85f226d108c6..8634274c3a751 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -1363,7 +1363,10 @@ impl DepNodeColorMap { Ordering::Relaxed, ) { Ok(_) => Ok(()), - Err(v) => Err(DepNodeIndex::from_u32(v)), + Err(v) => Err({ + assert_ne!(v, COMPRESSED_RED, "tried to mark a red node as green"); + DepNodeIndex::from_u32(v) + }), } }