diff options
| author | bors <bors@rust-lang.org> | 2023-11-22 11:44:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-22 11:44:56 +0000 |
| commit | a6b8ae582a89321e24ea942d9c3eb73229809487 (patch) | |
| tree | 7c6fe59fa97a8961d1af7cd27421e8198b464166 /compiler/rustc_interface/src | |
| parent | 5a9e0e87877857f601480d16739b4edd9cb3a426 (diff) | |
| parent | 971010ea5a8635dc55ad436c785bb1efe3a67cdd (diff) | |
| download | rust-a6b8ae582a89321e24ea942d9c3eb73229809487.tar.gz rust-a6b8ae582a89321e24ea942d9c3eb73229809487.zip | |
Auto merge of #118086 - nnethercote:queries-cleanups, r=bjorn3
Queries cleanups r? `@bjorn3`
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/queries.rs | 62 |
3 files changed, 31 insertions, 45 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 6225424fe4a..91fd4b4a1d0 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -38,18 +38,12 @@ 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 { - sess: Session, - codegen_backend: Box<dyn CodegenBackend>, + pub sess: Session, + pub codegen_backend: Box<dyn CodegenBackend>, pub(crate) override_queries: Option<fn(&Session, &mut Providers)>, } impl Compiler { - pub fn session(&self) -> &Session { - &self.sess - } - pub fn codegen_backend(&self) -> &dyn CodegenBackend { - &*self.codegen_backend - } pub fn build_output_filenames( &self, sess: &Session, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 0fc2bb7a2d4..99bea647bd5 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -645,10 +645,10 @@ pub fn create_global_ctxt<'tcx>( // incr. comp. yet. dep_graph.assert_ignored(); - let sess = &compiler.session(); + let sess = &compiler.sess; let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess); - let codegen_backend = compiler.codegen_backend(); + let codegen_backend = &compiler.codegen_backend; let mut providers = *DEFAULT_QUERY_PROVIDERS; codegen_backend.provide(&mut providers); diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 3fee2d28981..1c65cf19cde 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -17,7 +17,8 @@ use rustc_middle::dep_graph::DepGraph; use rustc_middle::ty::{GlobalCtxt, TyCtxt}; use rustc_session::config::{self, CrateType, OutputFilenames, OutputType}; use rustc_session::cstore::Untracked; -use rustc_session::{output::find_crate_name, Session}; +use rustc_session::output::find_crate_name; +use rustc_session::Session; use rustc_span::symbol::sym; use std::any::Any; use std::cell::{RefCell, RefMut}; @@ -101,17 +102,10 @@ impl<'tcx> Queries<'tcx> { } } - fn session(&self) -> &Session { - self.compiler.session() - } - - fn codegen_backend(&self) -> &dyn CodegenBackend { - self.compiler.codegen_backend() - } - pub fn parse(&self) -> Result<QueryResult<'_, ast::Crate>> { - self.parse - .compute(|| passes::parse(self.session()).map_err(|mut parse_error| parse_error.emit())) + self.parse.compute(|| { + passes::parse(&self.compiler.sess).map_err(|mut parse_error| parse_error.emit()) + }) } #[deprecated = "pre_configure may be made private in the future. If you need it please open an issue with your use case."] @@ -119,7 +113,7 @@ impl<'tcx> Queries<'tcx> { self.pre_configure.compute(|| { let mut krate = self.parse()?.steal(); - let sess = self.session(); + let sess = &self.compiler.sess; rustc_builtin_macros::cmdline_attrs::inject( &mut krate, &sess.parse_sess, @@ -134,7 +128,7 @@ impl<'tcx> Queries<'tcx> { pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> { self.gcx.compute(|| { - let sess = self.session(); + let sess = &self.compiler.sess; #[allow(deprecated)] let (krate, pre_configured_attrs) = self.pre_configure()?.steal(); @@ -150,7 +144,7 @@ impl<'tcx> Queries<'tcx> { let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?; let cstore = FreezeLock::new(Box::new(CStore::new( - self.codegen_backend().metadata_loader(), + self.compiler.codegen_backend.metadata_loader(), stable_crate_id, )) as _); let definitions = FreezeLock::new(Definitions::new(stable_crate_id)); @@ -186,22 +180,6 @@ impl<'tcx> Queries<'tcx> { }) } - pub fn ongoing_codegen(&'tcx self) -> Result<Box<dyn Any>> { - self.global_ctxt()?.enter(|tcx| { - // Don't do code generation if there were any errors - self.session().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.session().diagnostic().flush_delayed(); - - // Hook for UI tests. - Self::check_for_rustc_errors_attr(tcx); - - Ok(passes::start_codegen(self.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. @@ -236,8 +214,20 @@ impl<'tcx> Queries<'tcx> { } } - pub fn linker(&'tcx self, ongoing_codegen: Box<dyn Any>) -> Result<Linker> { + pub fn codegen_and_build_linker(&'tcx self) -> Result<Linker> { 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(), @@ -304,6 +294,7 @@ impl Compiler { where F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T, { + // Must declare `_timer` first so that it is dropped after `queries`. let mut _timer = None; let queries = Queries::new(self); let ret = f(&queries); @@ -316,15 +307,16 @@ impl Compiler { // after this point, they'll show up as "<unknown>" in self-profiling data. { let _prof_timer = - queries.session().prof.generic_activity("self_profile_alloc_query_strings"); + queries.compiler.sess.prof.generic_activity("self_profile_alloc_query_strings"); gcx.enter(rustc_query_impl::alloc_self_profile_query_strings); } - self.session() - .time("serialize_dep_graph", || gcx.enter(rustc_incremental::save_dep_graph)); + self.sess.time("serialize_dep_graph", || gcx.enter(rustc_incremental::save_dep_graph)); } - _timer = Some(self.session().timer("free_global_ctxt")); + // The timer's lifetime spans the dropping of `queries`, which contains + // the global context. + _timer = Some(self.sess.timer("free_global_ctxt")); ret } |
