Skip to content

Commit 81647c6

Browse files
Rollup merge of #81275 - jyn514:time-render, r=wesleywiser
Fix <unknown> queries and add more timing info to render_html Closes #81251. ## Fix `<unknown>` queries This happened because `alloc_query_strings` was never called. ## Add more timing info to render_html This still has some issues I'm not sure how to work out: - `create_renderer` and `renderer_after_krate` aren't shown by default. I want something like `verbose_generic_activity_with_arg`, but it doesn't exist. I'm also not sure how to show activities that aren't on by default - I tried `-Z self-profile -Z self-profile-args=all`, but it didn't show up. r? `@wesleywiser`
2 parents 7038bb1 + ca72f9e commit 81647c6

File tree

7 files changed

+48
-35
lines changed

7 files changed

+48
-35
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

compiler/rustc_lint/src/early.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,9 @@ pub fn check_ast_crate<T: EarlyLintPass>(
379379
// All of the buffered lints should have been emitted at this point.
380380
// If not, that means that we somehow buffered a lint for a node id
381381
// that was not lint-checked (perhaps it doesn't exist?). This is a bug.
382-
//
383-
// Rustdoc runs everybody-loops before the early lints and removes
384-
// function bodies, so it's totally possible for linted
385-
// node ids to not exist (e.g., macros defined within functions for the
386-
// unused_macro lint) anymore. So we only run this check
387-
// when we're not in rustdoc mode. (see issue #47639)
388-
if !sess.opts.actually_rustdoc {
389-
for (_id, lints) in buffered.map {
390-
for early_lint in lints {
391-
sess.delay_span_bug(early_lint.span, "failed to process buffered lint here");
392-
}
382+
for (_id, lints) in buffered.map {
383+
for early_lint in lints {
384+
sess.delay_span_bug(early_lint.span, "failed to process buffered lint here");
393385
}
394386
}
395387
}

src/librustdoc/formats/renderer.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::formats::cache::{Cache, CACHE_KEY};
1212
/// backend renderer has hooks for initialization, documenting an item, entering and exiting a
1313
/// module, and cleanup/finalizing output.
1414
crate trait FormatRenderer<'tcx>: Clone {
15+
/// Gives a description of the renderer. Used for performance profiling.
16+
fn descr() -> &'static str;
17+
1518
/// Sets up any state required for the renderer. When this is called the cache has already been
1619
/// populated.
1720
fn init(
@@ -57,16 +60,20 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
5760
edition: Edition,
5861
tcx: TyCtxt<'tcx>,
5962
) -> Result<(), Error> {
60-
let (krate, mut cache) = Cache::from_krate(
61-
render_info.clone(),
62-
options.document_private,
63-
&options.extern_html_root_urls,
64-
&options.output,
65-
krate,
66-
);
67-
68-
let (mut format_renderer, mut krate) =
69-
T::init(krate, options, render_info, edition, &mut cache, tcx)?;
63+
let (krate, mut cache) = tcx.sess.time("create_format_cache", || {
64+
Cache::from_krate(
65+
render_info.clone(),
66+
options.document_private,
67+
&options.extern_html_root_urls,
68+
&options.output,
69+
krate,
70+
)
71+
});
72+
let prof = &tcx.sess.prof;
73+
74+
let (mut format_renderer, mut krate) = prof
75+
.extra_verbose_generic_activity("create_renderer", T::descr())
76+
.run(|| T::init(krate, options, render_info, edition, &mut cache, tcx))?;
7077

7178
let cache = Arc::new(cache);
7279
// Freeze the cache now that the index has been built. Put an Arc into TLS for future
@@ -83,6 +90,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
8390
// Render the crate documentation
8491
let mut work = vec![(format_renderer.clone(), item)];
8592

93+
let unknown = rustc_span::Symbol::intern("<unknown item>");
8694
while let Some((mut cx, item)) = work.pop() {
8795
if item.is_mod() {
8896
// modules are special because they add a namespace. We also need to
@@ -91,6 +99,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
9199
if name.is_empty() {
92100
panic!("Unexpected module with empty name");
93101
}
102+
let _timer = prof.generic_activity_with_arg("render_mod_item", name.as_str());
94103

95104
cx.mod_item_in(&item, &name, &cache)?;
96105
let module = match *item.kind {
@@ -104,9 +113,10 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
104113

105114
cx.mod_item_out(&name)?;
106115
} else if item.name.is_some() {
107-
cx.item(item, &cache)?;
116+
prof.generic_activity_with_arg("render_item", &*item.name.unwrap_or(unknown).as_str())
117+
.run(|| cx.item(item, &cache))?;
108118
}
109119
}
110-
111-
format_renderer.after_krate(&krate, &cache, diag)
120+
prof.extra_verbose_generic_activity("renderer_after_krate", T::descr())
121+
.run(|| format_renderer.after_krate(&krate, &cache, diag))
112122
}

src/librustdoc/html/render/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ crate fn initial_ids() -> Vec<String> {
383383

384384
/// Generates the documentation for `crate` into the directory `dst`
385385
impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
386+
fn descr() -> &'static str {
387+
"html"
388+
}
389+
386390
fn init(
387391
mut krate: clean::Crate,
388392
options: RenderOptions,

src/librustdoc/json/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ impl JsonRenderer<'_> {
125125
}
126126

127127
impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
128+
fn descr() -> &'static str {
129+
"json"
130+
}
131+
128132
fn init(
129133
krate: clean::Crate,
130134
options: RenderOptions,

src/librustdoc/lib.rs

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

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

545545
global_ctxt.enter(|tcx| {
546546
let (mut krate, render_info, render_opts) = sess.time("run_global_ctxt", || {

0 commit comments

Comments
 (0)