Auto merge of #118086 - nnethercote:queries-cleanups, r=bjorn3
Queries cleanups r? `@bjorn3`
This commit is contained in:
commit
a6b8ae582a
8 changed files with 47 additions and 59 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue