From ca72f9ed7065a601bd2b1ec80889ec7bad177598 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 22 Jan 2021 13:46:52 -0500 Subject: [PATCH] Calculate self-profile strings in `Compiler::enter` instead in codegen This avoids each tool having to separately find and call `self_profile_alloc_strings`. - Don't compute the global context if it hasn't yet been computed This avoids giving extraneous errors about unresolved names if an error occurs during parsing. --- compiler/rustc_interface/src/passes.rs | 7 ------- compiler/rustc_interface/src/queries.rs | 16 +++++++++++++--- src/librustdoc/lib.rs | 9 +++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index ead2512d3b2..7031234e108 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1017,13 +1017,6 @@ pub fn start_codegen<'tcx>( tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx)); tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx)); - // We assume that no queries are run past here. If there are new queries - // after this point, they'll show up as "" in self-profiling data. - { - let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings"); - tcx.alloc_self_profile_query_strings(); - } - info!("Post-codegen\n{:?}", tcx.debug_stats()); if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) { diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 9c49f926d41..ac6b6d03115 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -417,9 +417,19 @@ impl Compiler { let queries = Queries::new(&self); let ret = f(&queries); - if self.session().opts.debugging_opts.query_stats { - if let Ok(gcx) = queries.global_ctxt() { - gcx.peek_mut().print_stats(); + // NOTE: intentionally does not compute the global context if it hasn't been built yet, + // since that likely means there was a parse error. + if let Some(Ok(gcx)) = &mut *queries.global_ctxt.result.borrow_mut() { + // We assume that no queries are run past here. If there are new queries + // after this point, they'll show up as "" in self-profiling data. + { + let _prof_timer = + queries.session().prof.generic_activity("self_profile_alloc_query_strings"); + gcx.enter(|tcx| tcx.alloc_self_profile_query_strings()); + } + + if self.session().opts.debugging_opts.query_stats { + gcx.print_stats(); } } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 19d2de58ffb..780a3b509c7 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -539,7 +539,7 @@ fn main_options(options: config::Options) -> MainResult { sess.fatal("Compilation failed, aborting rustdoc"); } - let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).take(); + let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).peek_mut(); global_ctxt.enter(|tcx| { let (mut krate, render_info, render_opts) = sess.time("run_global_ctxt", || { @@ -568,7 +568,7 @@ fn main_options(options: config::Options) -> MainResult { info!("going to format"); let (error_format, edition, debugging_options) = diag_opts; let diag = core::new_handler(error_format, None, &debugging_options); - let main_result = match output_format { + match output_format { None | Some(config::OutputFormat::Html) => sess.time("render_html", || { run_renderer::>( krate, @@ -589,10 +589,7 @@ fn main_options(options: config::Options) -> MainResult { tcx, ) }), - }; - // NOTE: this is normally called in codegen, but rustdoc never goes to codegen. - tcx.alloc_self_profile_query_strings(); - main_result + } }) }) })