From 971010ea5a8635dc55ad436c785bb1efe3a67cdd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 20 Nov 2023 15:09:05 +1100 Subject: [PATCH] Merge `Queries::{ongoing_codegen,linker}`. There is no real need for them to be separate. --- compiler/rustc_driver_impl/src/lib.rs | 3 +-- compiler/rustc_interface/src/queries.rs | 30 ++++++++++------------ tests/run-make-fulldeps/issue-19371/foo.rs | 3 +-- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 19730e81c85..5ab14fbc687 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -453,7 +453,7 @@ fn run_compiler( return early_exit(); } - let ongoing_codegen = queries.ongoing_codegen()?; + let linker = queries.codegen_and_build_linker()?; // This must run after monomorphization so that all generic types // have been instantiated. @@ -467,7 +467,6 @@ fn run_compiler( sess.code_stats.print_vtable_sizes(crate_name); } - let linker = queries.linker(ongoing_codegen)?; Ok(Some(linker)) })?; diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 9fb9778cd56..1c65cf19cde 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -180,22 +180,6 @@ pub fn global_ctxt(&'tcx self) -> Result> }) } - pub fn ongoing_codegen(&'tcx self) -> Result> { - self.global_ctxt()?.enter(|tcx| { - // Don't do code generation if there were any errors - self.compiler.sess.compile_status()?; - - // If we have any delayed bugs, for example because we created TyKind::Error earlier, - // it's likely that codegen will only cause more ICEs, obscuring the original problem - self.compiler.sess.diagnostic().flush_delayed(); - - // Hook for UI tests. - Self::check_for_rustc_errors_attr(tcx); - - Ok(passes::start_codegen(&*self.compiler.codegen_backend, tcx)) - }) - } - /// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used /// to write UI tests that actually test that compilation succeeds without reporting /// an error. @@ -230,8 +214,20 @@ fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) { } } - pub fn linker(&'tcx self, ongoing_codegen: Box) -> Result { + pub fn codegen_and_build_linker(&'tcx self) -> Result { self.global_ctxt()?.enter(|tcx| { + // Don't do code generation if there were any errors + self.compiler.sess.compile_status()?; + + // If we have any delayed bugs, for example because we created TyKind::Error earlier, + // it's likely that codegen will only cause more ICEs, obscuring the original problem + self.compiler.sess.diagnostic().flush_delayed(); + + // Hook for UI tests. + Self::check_for_rustc_errors_attr(tcx); + + let ongoing_codegen = passes::start_codegen(&*self.compiler.codegen_backend, tcx); + Ok(Linker { dep_graph: tcx.dep_graph.clone(), output_filenames: tcx.output_filenames(()).clone(), diff --git a/tests/run-make-fulldeps/issue-19371/foo.rs b/tests/run-make-fulldeps/issue-19371/foo.rs index e46aef9ea89..a0bbe3851e8 100644 --- a/tests/run-make-fulldeps/issue-19371/foo.rs +++ b/tests/run-make-fulldeps/issue-19371/foo.rs @@ -69,8 +69,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { interface::run_compiler(config, |compiler| { let linker = compiler.enter(|queries| { queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?; - let ongoing_codegen = queries.ongoing_codegen()?; - queries.linker(ongoing_codegen) + queries.codegen_and_build_linker() }); linker.unwrap().link(&compiler.sess, &*compiler.codegen_backend).unwrap(); });