Skip to content

Commit 754b4a4

Browse files
authored
Rollup merge of #149916 - zetanumbers:double_node_sanity, r=petrochenkov
Add a sanity check in case of any duplicate nodes A simple check in case compiler tries to encode a dep node twice like in #141540. Also if we'd try to mark a red node as green as it may then create a bad `DepNodeIndex` like in #148295. If it prevents #141540 from emitting a faulty `dep-graph.bin` file via panic then it means you will be able to temporarily fix it by simply restarting cargo or rust-analyzer without cleaning up incremental cache.
2 parents aec4781 + c7b5fb5 commit 754b4a4

File tree

1 file changed

+7
-2
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+7
-2
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,10 @@ impl DepNodeColorMap {
13631363
Ordering::Relaxed,
13641364
) {
13651365
Ok(_) => Ok(()),
1366-
Err(v) => Err(DepNodeIndex::from_u32(v)),
1366+
Err(v) => Err({
1367+
assert_ne!(v, COMPRESSED_RED, "tried to mark a red node as green");
1368+
DepNodeIndex::from_u32(v)
1369+
}),
13671370
}
13681371
}
13691372

@@ -1384,7 +1387,9 @@ impl DepNodeColorMap {
13841387

13851388
#[inline]
13861389
pub(super) fn insert_red(&self, index: SerializedDepNodeIndex) {
1387-
self.values[index].store(COMPRESSED_RED, Ordering::Release)
1390+
let value = self.values[index].swap(COMPRESSED_RED, Ordering::Release);
1391+
// Sanity check for duplicate nodes
1392+
assert_eq!(value, COMPRESSED_UNKNOWN, "trying to encode a dep node twice");
13881393
}
13891394
}
13901395

0 commit comments

Comments
 (0)