From aed8e1f3b635c379d03007b86cff4dd36cb49eb4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Nov 2023 08:34:55 +1100 Subject: Move `CodegenBackend` out of `Linker`. It can easily be passed in. And that removes the single clone of `Compiler::codegen_backend`, which means it no longer needs to be `Lrc`. --- compiler/rustc_interface/src/interface.rs | 13 +++++-------- compiler/rustc_interface/src/queries.rs | 17 ++++++----------- 2 files changed, 11 insertions(+), 19 deletions(-) (limited to 'compiler/rustc_interface/src') diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index e054d0a8f0b..6db26b976d9 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -39,7 +39,7 @@ pub type Result = result::Result; /// Created by passing [`Config`] to [`run_compiler`]. pub struct Compiler { pub(crate) sess: Session, - codegen_backend: Lrc, + codegen_backend: Box, pub(crate) override_queries: Option, } @@ -47,8 +47,8 @@ impl Compiler { pub fn session(&self) -> &Session { &self.sess } - pub fn codegen_backend(&self) -> &Lrc { - &self.codegen_backend + pub fn codegen_backend(&self) -> &dyn CodegenBackend { + &*self.codegen_backend } pub fn build_output_filenames( &self, @@ -491,11 +491,8 @@ pub fn run_compiler(config: Config, f: impl FnOnce(&Compiler) -> R + Se } sess.lint_store = Some(Lrc::new(lint_store)); - let compiler = Compiler { - sess, - codegen_backend: Lrc::from(codegen_backend), - override_queries: config.override_queries, - }; + let compiler = + Compiler { sess, codegen_backend, override_queries: config.override_queries }; rustc_span::set_source_map(compiler.sess.parse_sess.clone_source_map(), move || { let r = { diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 8345753c2e9..a3161be0c3d 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -7,7 +7,7 @@ use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; use rustc_data_structures::steal::Steal; use rustc_data_structures::svh::Svh; -use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, Lrc, OnceLock, WorkerLocal}; +use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal}; use rustc_hir::def_id::{StableCrateId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::definitions::Definitions; use rustc_incremental::setup_dep_graph; @@ -105,7 +105,7 @@ impl<'tcx> Queries<'tcx> { &self.compiler.sess } - fn codegen_backend(&self) -> &Lrc { + fn codegen_backend(&self) -> &dyn CodegenBackend { self.compiler.codegen_backend() } @@ -198,7 +198,7 @@ impl<'tcx> Queries<'tcx> { // Hook for UI tests. Self::check_for_rustc_errors_attr(tcx); - Ok(passes::start_codegen(&**self.codegen_backend(), tcx)) + Ok(passes::start_codegen(self.codegen_backend(), tcx)) }) } @@ -239,7 +239,6 @@ impl<'tcx> Queries<'tcx> { pub fn linker(&'tcx self, ongoing_codegen: Box) -> Result { self.global_ctxt()?.enter(|tcx| { Ok(Linker { - codegen_backend: self.codegen_backend().clone(), dep_graph: tcx.dep_graph.clone(), prepare_outputs: tcx.output_filenames(()).clone(), crate_hash: if tcx.needs_crate_hash() { @@ -254,10 +253,6 @@ impl<'tcx> Queries<'tcx> { } pub struct Linker { - // compilation inputs - codegen_backend: Lrc, - - // compilation outputs dep_graph: DepGraph, prepare_outputs: Arc, // Only present when incr. comp. is enabled. @@ -266,9 +261,9 @@ pub struct Linker { } impl Linker { - pub fn link(self, sess: &Session) -> Result<()> { + pub fn link(self, sess: &Session, codegen_backend: &dyn CodegenBackend) -> Result<()> { let (codegen_results, work_products) = - self.codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.prepare_outputs)?; + codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.prepare_outputs)?; sess.compile_status()?; @@ -301,7 +296,7 @@ impl Linker { } let _timer = sess.prof.verbose_generic_activity("link_crate"); - self.codegen_backend.link(sess, codegen_results, &self.prepare_outputs) + codegen_backend.link(sess, codegen_results, &self.prepare_outputs) } } -- cgit 1.4.1-3-g733a5