diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-11-17 08:15:36 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-11-17 17:14:17 +1100 |
| commit | de91b6d24962a4662786bbf0fab71854b3976af1 (patch) | |
| tree | c71b34df8f2bbf744202de76dc62e37dde38ff5a /compiler/rustc_interface/src | |
| parent | 3560122bfc2c2d1901a7bfe71882e40b6228f68c (diff) | |
| download | rust-de91b6d24962a4662786bbf0fab71854b3976af1.tar.gz rust-de91b6d24962a4662786bbf0fab71854b3976af1.zip | |
Move `Session` out of `Linker`.
It can easily be passed in. And that removes the single clone of `Compiler::session`, which means it no longer needs to be `Lrc`.
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/queries.rs | 26 |
2 files changed, 13 insertions, 19 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index d113e038966..e054d0a8f0b 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -38,13 +38,13 @@ pub type Result<T> = result::Result<T, ErrorGuaranteed>; /// Can be used to run `rustc_interface` queries. /// Created by passing [`Config`] to [`run_compiler`]. pub struct Compiler { - pub(crate) sess: Lrc<Session>, + pub(crate) sess: Session, codegen_backend: Lrc<dyn CodegenBackend>, pub(crate) override_queries: Option<fn(&Session, &mut Providers)>, } impl Compiler { - pub fn session(&self) -> &Lrc<Session> { + pub fn session(&self) -> &Session { &self.sess } pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> { @@ -492,7 +492,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se sess.lint_store = Some(Lrc::new(lint_store)); let compiler = Compiler { - sess: Lrc::new(sess), + sess, codegen_backend: Lrc::from(codegen_backend), override_queries: config.override_queries, }; diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index c30ff6c4831..8345753c2e9 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -101,9 +101,10 @@ impl<'tcx> Queries<'tcx> { } } - fn session(&self) -> &Lrc<Session> { + fn session(&self) -> &Session { &self.compiler.sess } + fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> { self.compiler.codegen_backend() } @@ -238,7 +239,6 @@ impl<'tcx> Queries<'tcx> { pub fn linker(&'tcx self, ongoing_codegen: Box<dyn Any>) -> Result<Linker> { self.global_ctxt()?.enter(|tcx| { Ok(Linker { - sess: self.session().clone(), codegen_backend: self.codegen_backend().clone(), dep_graph: tcx.dep_graph.clone(), prepare_outputs: tcx.output_filenames(()).clone(), @@ -255,7 +255,6 @@ impl<'tcx> Queries<'tcx> { pub struct Linker { // compilation inputs - sess: Lrc<Session>, codegen_backend: Lrc<dyn CodegenBackend>, // compilation outputs @@ -267,30 +266,25 @@ pub struct Linker { } impl Linker { - pub fn link(self) -> Result<()> { - let (codegen_results, work_products) = self.codegen_backend.join_codegen( - self.ongoing_codegen, - &self.sess, - &self.prepare_outputs, - )?; + pub fn link(self, sess: &Session) -> Result<()> { + let (codegen_results, work_products) = + self.codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.prepare_outputs)?; - self.sess.compile_status()?; + sess.compile_status()?; - let sess = &self.sess; let dep_graph = self.dep_graph; sess.time("serialize_work_products", || { rustc_incremental::save_work_product_index(sess, &dep_graph, work_products) }); - let prof = self.sess.prof.clone(); + let prof = sess.prof.clone(); prof.generic_activity("drop_dep_graph").run(move || drop(dep_graph)); // Now that we won't touch anything in the incremental compilation directory // any more, we can finalize it (which involves renaming it) - rustc_incremental::finalize_session_directory(&self.sess, self.crate_hash); + rustc_incremental::finalize_session_directory(sess, self.crate_hash); - if !self - .sess + if !sess .opts .output_types .keys() @@ -307,7 +301,7 @@ impl Linker { } let _timer = sess.prof.verbose_generic_activity("link_crate"); - self.codegen_backend.link(&self.sess, codegen_results, &self.prepare_outputs) + self.codegen_backend.link(sess, codegen_results, &self.prepare_outputs) } } |
