From 2b2b925158888c35f68e5a9c4dfa372e348e8c27 Mon Sep 17 00:00:00 2001 From: Makro Date: Tue, 28 Jul 2026 06:35:50 +0000 Subject: [PATCH] Fix ICE when dumping the dep graph with the parallel frontend --- .../rustc_middle/src/dep_graph/retained.rs | 4 +++- tests/run-make/dep-graph/rmake.rs | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/retained.rs b/compiler/rustc_middle/src/dep_graph/retained.rs index 7949a47346845..e02b2773e8645 100644 --- a/compiler/rustc_middle/src/dep_graph/retained.rs +++ b/compiler/rustc_middle/src/dep_graph/retained.rs @@ -26,6 +26,8 @@ impl RetainedDepGraph { Self { inner, indices } } + /// Adds `node` at its dep-graph index. Indices are allocated to threads in batches, so the + /// index space is sparse and the slots skipped over hold no node. pub fn push(&mut self, index: DepNodeIndex, node: DepNode, edges: &[DepNodeIndex]) { let source = NodeIndex(index.as_usize()); self.inner.add_node_with_idx(source, node); @@ -37,7 +39,7 @@ impl RetainedDepGraph { } pub fn nodes(&self) -> Vec<&DepNode> { - self.inner.all_nodes().iter().map(|n| n.data.as_ref().unwrap()).collect() + self.inner.all_nodes().iter().filter_map(|n| n.data.as_ref()).collect() } pub fn edges(&self) -> Vec<(&DepNode, &DepNode)> { diff --git a/tests/run-make/dep-graph/rmake.rs b/tests/run-make/dep-graph/rmake.rs index 351418997f1dd..db2570ad82f61 100644 --- a/tests/run-make/dep-graph/rmake.rs +++ b/tests/run-make/dep-graph/rmake.rs @@ -1,18 +1,22 @@ -// Just verify that we successfully run and produce dep graphs when requested. +// Just verify that we successfully run and produce dep graphs when requested. The parallel +// frontend is covered too, because it leaves unused dep-graph indices that the dump must skip. //@ ignore-cross-compile use run_make_support::{path, rustc}; fn main() { - rustc() - .input("foo.rs") - .incremental(path("incr")) - .arg("-Zquery-dep-graph") - .arg("-Zdump-dep-graph") - .env("RUST_DEP_GRAPH", path("dep-graph")) - .run(); + for threads in ["1", "2"] { + rustc() + .input("foo.rs") + .incremental(path(format!("incr-{threads}"))) + .arg("-Zquery-dep-graph") + .arg("-Zdump-dep-graph") + .arg(format!("-Zthreads={threads}")) + .env("RUST_DEP_GRAPH", path(format!("dep-graph-{threads}"))) + .run(); - assert!(path("dep-graph.txt").is_file()); - assert!(path("dep-graph.dot").is_file()); + assert!(path(format!("dep-graph-{threads}.txt")).is_file()); + assert!(path(format!("dep-graph-{threads}.dot")).is_file()); + } }