Skip to content

Commit ca72f9e

Browse files
committed
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.
1 parent 1d1010f commit ca72f9e

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

compiler/rustc_interface/src/passes.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1017,13 +1017,6 @@ pub fn start_codegen<'tcx>(
10171017
tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx));
10181018
tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx));
10191019

1020-
// We assume that no queries are run past here. If there are new queries
1021-
// after this point, they'll show up as "<unknown>" in self-profiling data.
1022-
{
1023-
let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings");
1024-
tcx.alloc_self_profile_query_strings();
1025-
}
1026-
10271020
info!("Post-codegen\n{:?}", tcx.debug_stats());
10281021

10291022
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {

compiler/rustc_interface/src/queries.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,19 @@ impl Compiler {
417417
let queries = Queries::new(&self);
418418
let ret = f(&queries);
419419

420-
if self.session().opts.debugging_opts.query_stats {
421-
if let Ok(gcx) = queries.global_ctxt() {
422-
gcx.peek_mut().print_stats();
420+
// NOTE: intentionally does not compute the global context if it hasn't been built yet,
421+
// since that likely means there was a parse error.
422+
if let Some(Ok(gcx)) = &mut *queries.global_ctxt.result.borrow_mut() {
423+
// We assume that no queries are run past here. If there are new queries
424+
// after this point, they'll show up as "<unknown>" in self-profiling data.
425+
{
426+
let _prof_timer =
427+
queries.session().prof.generic_activity("self_profile_alloc_query_strings");
428+
gcx.enter(|tcx| tcx.alloc_self_profile_query_strings());
429+
}
430+
431+
if self.session().opts.debugging_opts.query_stats {
432+
gcx.print_stats();
423433
}
424434
}
425435

src/librustdoc/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ fn main_options(options: config::Options) -> MainResult {
539539
sess.fatal("Compilation failed, aborting rustdoc");
540540
}
541541

542-
let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).take();
542+
let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).peek_mut();
543543

544544
global_ctxt.enter(|tcx| {
545545
let (mut krate, render_info, render_opts) = sess.time("run_global_ctxt", || {
@@ -568,7 +568,7 @@ fn main_options(options: config::Options) -> MainResult {
568568
info!("going to format");
569569
let (error_format, edition, debugging_options) = diag_opts;
570570
let diag = core::new_handler(error_format, None, &debugging_options);
571-
let main_result = match output_format {
571+
match output_format {
572572
None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
573573
run_renderer::<html::render::Context<'_>>(
574574
krate,
@@ -589,10 +589,7 @@ fn main_options(options: config::Options) -> MainResult {
589589
tcx,
590590
)
591591
}),
592-
};
593-
// NOTE: this is normally called in codegen, but rustdoc never goes to codegen.
594-
tcx.alloc_self_profile_query_strings();
595-
main_result
592+
}
596593
})
597594
})
598595
})

0 commit comments

Comments
 (0)