From 16f519afe8dab9c4d3c9062f53fb32245f88a4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 24 May 2024 16:20:09 +0000 Subject: [PATCH 1/3] don't return speculatively loaded crates from postorder_cnums --- compiler/rustc_metadata/src/creader.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 44a3e9760e1e1..2c27c75229086 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -235,7 +235,9 @@ impl CStore { pub(crate) fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec { let mut deps = Vec::new(); if cnum == LOCAL_CRATE { - for (cnum, _) in self.iter_crate_data() { + for cnum in + self.iter_crate_data().filter_map(|(cnum, data)| data.used().then_some(cnum)) + { self.push_dependencies_in_postorder(&mut deps, cnum); } } else { From 77413d48bf8198b1b74e5a1b445e28e0a5d9e620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 29 May 2024 09:29:16 +0000 Subject: [PATCH 2/3] add non-regression run-make test for issues 125474, 125484, and 125646 --- .../dependency.rs | 1 + .../issue-125484-used-dependencies/main.rs | 9 +++++++++ .../issue-125484-used-dependencies/rmake.rs | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/run-make/issue-125484-used-dependencies/dependency.rs create mode 100644 tests/run-make/issue-125484-used-dependencies/main.rs create mode 100644 tests/run-make/issue-125484-used-dependencies/rmake.rs diff --git a/tests/run-make/issue-125484-used-dependencies/dependency.rs b/tests/run-make/issue-125484-used-dependencies/dependency.rs new file mode 100644 index 0000000000000..d15abba59766b --- /dev/null +++ b/tests/run-make/issue-125484-used-dependencies/dependency.rs @@ -0,0 +1 @@ +// Empty diff --git a/tests/run-make/issue-125484-used-dependencies/main.rs b/tests/run-make/issue-125484-used-dependencies/main.rs new file mode 100644 index 0000000000000..0c1a1f8208ad0 --- /dev/null +++ b/tests/run-make/issue-125484-used-dependencies/main.rs @@ -0,0 +1,9 @@ +pub type Foo = something::same::Thing; + +mod something { + pub mod same { + pub struct Thing; + } +} + +fn main() {} diff --git a/tests/run-make/issue-125484-used-dependencies/rmake.rs b/tests/run-make/issue-125484-used-dependencies/rmake.rs new file mode 100644 index 0000000000000..3aaeb7848918e --- /dev/null +++ b/tests/run-make/issue-125484-used-dependencies/rmake.rs @@ -0,0 +1,20 @@ +// Non-regression test for issues #125474, #125484, #125646, with the repro taken from #125484. Some +// queries use "used dependencies" while others use "speculatively loaded dependencies", and an +// indexing ICE appeared in some cases when these were unexpectedly used in the same context. + +// FIXME: this should probably be a UI test instead of a run-make test, but I *cannot* find a way to +// make compiletest annotations reproduce the ICE with the minimizations from issues #125474 and +// #125484. + +extern crate run_make_support; + +use run_make_support::{rustc, tmp_dir}; + +fn main() { + // The dependency is not itself significant, apart from sharing a name with one of main's + // modules. + rustc().crate_name("same").crate_type("lib").input("dependency.rs").run(); + + // Here, an ICE would happen when building the linker command. + rustc().input("main.rs").extern_("same", tmp_dir().join("libsame.rlib")).run(); +} From f225db1fa404708155be1b0d7f8b5c87085bb3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 29 May 2024 10:24:42 +0000 Subject: [PATCH 3/3] review nits --- tests/run-make/issue-125484-used-dependencies/rmake.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/run-make/issue-125484-used-dependencies/rmake.rs b/tests/run-make/issue-125484-used-dependencies/rmake.rs index 3aaeb7848918e..b75e82b42db7b 100644 --- a/tests/run-make/issue-125484-used-dependencies/rmake.rs +++ b/tests/run-make/issue-125484-used-dependencies/rmake.rs @@ -6,14 +6,12 @@ // make compiletest annotations reproduce the ICE with the minimizations from issues #125474 and // #125484. -extern crate run_make_support; - use run_make_support::{rustc, tmp_dir}; fn main() { // The dependency is not itself significant, apart from sharing a name with one of main's // modules. - rustc().crate_name("same").crate_type("lib").input("dependency.rs").run(); + rustc().crate_name("same").crate_type("rlib").input("dependency.rs").run(); // Here, an ICE would happen when building the linker command. rustc().input("main.rs").extern_("same", tmp_dir().join("libsame.rlib")).run();