Get rid of of the global_ctxt query
This commit is contained in:
parent
ed14192604
commit
6ece803632
6 changed files with 48 additions and 70 deletions
|
@ -45,7 +45,7 @@ use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::{ColorConfig, DiagCtxt, ErrCode, FatalError, PResult, markdown};
|
use rustc_errors::{ColorConfig, DiagCtxt, ErrCode, FatalError, PResult, markdown};
|
||||||
use rustc_feature::find_gated_cfg;
|
use rustc_feature::find_gated_cfg;
|
||||||
use rustc_interface::util::{self, get_codegen_backend};
|
use rustc_interface::util::{self, get_codegen_backend};
|
||||||
use rustc_interface::{Linker, interface, passes};
|
use rustc_interface::{Linker, create_and_enter_global_ctxt, interface, passes};
|
||||||
use rustc_lint::unerased_lint_store;
|
use rustc_lint::unerased_lint_store;
|
||||||
use rustc_metadata::creader::MetadataLoader;
|
use rustc_metadata::creader::MetadataLoader;
|
||||||
use rustc_metadata::locator;
|
use rustc_metadata::locator;
|
||||||
|
@ -400,7 +400,9 @@ fn run_compiler(
|
||||||
// If pretty printing is requested: Figure out the representation, print it and exit
|
// If pretty printing is requested: Figure out the representation, print it and exit
|
||||||
if let Some(pp_mode) = sess.opts.pretty {
|
if let Some(pp_mode) = sess.opts.pretty {
|
||||||
if pp_mode.needs_ast_map() {
|
if pp_mode.needs_ast_map() {
|
||||||
queries.global_ctxt().enter(|tcx| {
|
let krate = queries.parse().steal();
|
||||||
|
|
||||||
|
create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
||||||
tcx.ensure().early_lint_checks(());
|
tcx.ensure().early_lint_checks(());
|
||||||
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
|
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
|
||||||
passes::write_dep_info(tcx);
|
passes::write_dep_info(tcx);
|
||||||
|
@ -425,7 +427,9 @@ fn run_compiler(
|
||||||
return early_exit();
|
return early_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
queries.global_ctxt().enter(|tcx| {
|
let krate = queries.parse().steal();
|
||||||
|
|
||||||
|
create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
||||||
// Make sure name resolution and macro expansion is run.
|
// Make sure name resolution and macro expansion is run.
|
||||||
let _ = tcx.resolver_for_lowering();
|
let _ = tcx.resolver_for_lowering();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
|
|
||||||
mod callbacks;
|
mod callbacks;
|
||||||
mod errors;
|
pub mod errors;
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
pub mod passes;
|
pub mod passes;
|
||||||
mod proc_macro_decls;
|
mod proc_macro_decls;
|
||||||
|
@ -17,7 +17,7 @@ pub mod util;
|
||||||
|
|
||||||
pub use callbacks::setup_callbacks;
|
pub use callbacks::setup_callbacks;
|
||||||
pub use interface::{Config, run_compiler};
|
pub use interface::{Config, run_compiler};
|
||||||
pub use passes::DEFAULT_QUERY_PROVIDERS;
|
pub use passes::{DEFAULT_QUERY_PROVIDERS, create_and_enter_global_ctxt};
|
||||||
pub use queries::{Linker, Queries};
|
pub use queries::{Linker, Queries};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -41,7 +41,7 @@ use tracing::{info, instrument};
|
||||||
use crate::interface::Compiler;
|
use crate::interface::Compiler;
|
||||||
use crate::{errors, proc_macro_decls, util};
|
use crate::{errors, proc_macro_decls, util};
|
||||||
|
|
||||||
pub(crate) fn parse<'a>(sess: &'a Session) -> ast::Crate {
|
pub fn parse<'a>(sess: &'a Session) -> ast::Crate {
|
||||||
let krate = sess
|
let krate = sess
|
||||||
.time("parse_crate", || {
|
.time("parse_crate", || {
|
||||||
let mut parser = unwrap_or_emit_fatal(match &sess.io.input {
|
let mut parser = unwrap_or_emit_fatal(match &sess.io.input {
|
||||||
|
@ -709,7 +709,22 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
|
||||||
*providers
|
*providers
|
||||||
});
|
});
|
||||||
|
|
||||||
pub(crate) fn create_global_ctxt<'tcx>(
|
pub fn create_and_enter_global_ctxt<'tcx, T>(
|
||||||
|
compiler: &'tcx Compiler,
|
||||||
|
krate: rustc_ast::Crate,
|
||||||
|
f: impl for<'a> FnOnce(TyCtxt<'a>) -> T,
|
||||||
|
) -> T {
|
||||||
|
let gcx_cell = OnceLock::new();
|
||||||
|
let arena = WorkerLocal::new(|_| Arena::default());
|
||||||
|
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());
|
||||||
|
|
||||||
|
let gcx = create_global_ctxt(compiler, krate, &gcx_cell, &arena, &hir_arena);
|
||||||
|
let ret = gcx.enter(f);
|
||||||
|
gcx.finish();
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_global_ctxt<'tcx>(
|
||||||
compiler: &'tcx Compiler,
|
compiler: &'tcx Compiler,
|
||||||
mut krate: rustc_ast::Crate,
|
mut krate: rustc_ast::Crate,
|
||||||
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
|
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
|
||||||
|
|
|
@ -7,9 +7,7 @@ use rustc_codegen_ssa::CodegenResults;
|
||||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||||
use rustc_data_structures::steal::Steal;
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::svh::Svh;
|
use rustc_data_structures::svh::Svh;
|
||||||
use rustc_data_structures::sync::{OnceLock, WorkerLocal};
|
|
||||||
use rustc_hir::def_id::LOCAL_CRATE;
|
use rustc_hir::def_id::LOCAL_CRATE;
|
||||||
use rustc_middle::arena::Arena;
|
|
||||||
use rustc_middle::dep_graph::DepGraph;
|
use rustc_middle::dep_graph::DepGraph;
|
||||||
use rustc_middle::ty::{GlobalCtxt, TyCtxt};
|
use rustc_middle::ty::{GlobalCtxt, TyCtxt};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
|
@ -65,51 +63,18 @@ impl<'a, 'tcx> QueryResult<'a, &'tcx GlobalCtxt<'tcx>> {
|
||||||
|
|
||||||
pub struct Queries<'tcx> {
|
pub struct Queries<'tcx> {
|
||||||
compiler: &'tcx Compiler,
|
compiler: &'tcx Compiler,
|
||||||
gcx_cell: OnceLock<GlobalCtxt<'tcx>>,
|
|
||||||
|
|
||||||
arena: WorkerLocal<Arena<'tcx>>,
|
|
||||||
hir_arena: WorkerLocal<rustc_hir::Arena<'tcx>>,
|
|
||||||
|
|
||||||
parse: Query<ast::Crate>,
|
parse: Query<ast::Crate>,
|
||||||
// This just points to what's in `gcx_cell`.
|
|
||||||
gcx: Query<&'tcx GlobalCtxt<'tcx>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Queries<'tcx> {
|
impl<'tcx> Queries<'tcx> {
|
||||||
pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> {
|
pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> {
|
||||||
Queries {
|
Queries { compiler, parse: Query { result: RefCell::new(None) } }
|
||||||
compiler,
|
|
||||||
gcx_cell: OnceLock::new(),
|
|
||||||
arena: WorkerLocal::new(|_| Arena::default()),
|
|
||||||
hir_arena: WorkerLocal::new(|_| rustc_hir::Arena::default()),
|
|
||||||
parse: Query { result: RefCell::new(None) },
|
|
||||||
gcx: Query { result: RefCell::new(None) },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn finish(&'tcx self) {
|
|
||||||
if let Some(gcx) = self.gcx_cell.get() {
|
|
||||||
gcx.finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(&self) -> QueryResult<'_, ast::Crate> {
|
pub fn parse(&self) -> QueryResult<'_, ast::Crate> {
|
||||||
self.parse.compute(|| passes::parse(&self.compiler.sess))
|
self.parse.compute(|| passes::parse(&self.compiler.sess))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn global_ctxt(&'tcx self) -> QueryResult<'tcx, &'tcx GlobalCtxt<'tcx>> {
|
|
||||||
self.gcx.compute(|| {
|
|
||||||
let krate = self.parse().steal();
|
|
||||||
|
|
||||||
passes::create_global_ctxt(
|
|
||||||
self.compiler,
|
|
||||||
krate,
|
|
||||||
&self.gcx_cell,
|
|
||||||
&self.arena,
|
|
||||||
&self.hir_arena,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Linker {
|
pub struct Linker {
|
||||||
|
@ -192,16 +157,7 @@ impl Compiler {
|
||||||
where
|
where
|
||||||
F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T,
|
F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T,
|
||||||
{
|
{
|
||||||
// Must declare `_timer` first so that it is dropped after `queries`.
|
|
||||||
let _timer;
|
|
||||||
let queries = Queries::new(self);
|
let queries = Queries::new(self);
|
||||||
let ret = f(&queries);
|
f(&queries)
|
||||||
|
|
||||||
// The timer's lifetime spans the dropping of `queries`, which contains
|
|
||||||
// the global context.
|
|
||||||
_timer = self.sess.timer("free_global_ctxt");
|
|
||||||
queries.finish();
|
|
||||||
|
|
||||||
ret
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,23 +175,26 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
|
||||||
..
|
..
|
||||||
} = interface::run_compiler(config, |compiler| {
|
} = interface::run_compiler(config, |compiler| {
|
||||||
compiler.enter(|queries| {
|
compiler.enter(|queries| {
|
||||||
let collector = queries.global_ctxt().enter(|tcx| {
|
let krate = queries.parse().steal();
|
||||||
let crate_name = tcx.crate_name(LOCAL_CRATE).to_string();
|
|
||||||
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
|
||||||
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
|
|
||||||
let enable_per_target_ignores = options.enable_per_target_ignores;
|
|
||||||
|
|
||||||
let mut collector = CreateRunnableDocTests::new(options, opts);
|
let collector =
|
||||||
let hir_collector = HirCollector::new(
|
rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
||||||
ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()),
|
let crate_name = tcx.crate_name(LOCAL_CRATE).to_string();
|
||||||
enable_per_target_ignores,
|
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
||||||
tcx,
|
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
|
||||||
);
|
let enable_per_target_ignores = options.enable_per_target_ignores;
|
||||||
let tests = hir_collector.collect_crate();
|
|
||||||
tests.into_iter().for_each(|t| collector.add_test(t));
|
|
||||||
|
|
||||||
collector
|
let mut collector = CreateRunnableDocTests::new(options, opts);
|
||||||
});
|
let hir_collector = HirCollector::new(
|
||||||
|
ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()),
|
||||||
|
enable_per_target_ignores,
|
||||||
|
tcx,
|
||||||
|
);
|
||||||
|
let tests = hir_collector.collect_crate();
|
||||||
|
tests.into_iter().for_each(|t| collector.add_test(t));
|
||||||
|
|
||||||
|
collector
|
||||||
|
});
|
||||||
compiler.sess.dcx().abort_if_errors();
|
compiler.sess.dcx().abort_if_errors();
|
||||||
|
|
||||||
collector
|
collector
|
||||||
|
|
|
@ -857,12 +857,12 @@ fn main_args(
|
||||||
}
|
}
|
||||||
|
|
||||||
compiler.enter(|queries| {
|
compiler.enter(|queries| {
|
||||||
let mut gcx = queries.global_ctxt();
|
let krate = queries.parse().steal();
|
||||||
if sess.dcx().has_errors().is_some() {
|
if sess.dcx().has_errors().is_some() {
|
||||||
sess.dcx().fatal("Compilation failed, aborting rustdoc");
|
sess.dcx().fatal("Compilation failed, aborting rustdoc");
|
||||||
}
|
}
|
||||||
|
|
||||||
gcx.enter(|tcx| {
|
rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
||||||
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
|
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
|
||||||
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
|
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue