Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some timing info to rustdoc #74590

Merged
merged 9 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use std::rc::Rc;

use crate::clean;
use crate::clean::{AttributesExt, MAX_DEF_ID};
use crate::config::RenderInfo;
use crate::config::{Options as RustdocOptions, RenderOptions};
use crate::config::{OutputFormat, RenderInfo};
use crate::passes::{self, Condition::*, ConditionalPass};

pub use rustc_session::config::{CodegenOptions, DebuggingOptions, Input, Options};
Expand Down Expand Up @@ -280,7 +280,9 @@ where
(lint_opts, lint_caps)
}

pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) {
pub fn run_core(
options: RustdocOptions,
) -> (clean::Crate, RenderInfo, RenderOptions, Lrc<Session>) {
// Parse, resolve, and typecheck the given crate.

let RustdocOptions {
Expand All @@ -299,8 +301,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
lint_opts,
describe_lints,
lint_cap,
mut default_passes,
mut manual_passes,
default_passes,
manual_passes,
display_warnings,
render_options,
output_format,
Expand Down Expand Up @@ -407,7 +409,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
let hir = tcx.hir();
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(def_id)));
debug!("visiting body for {:?}", def_id);
tcx.sess.time("emit_ignored_resolution_errors", || {
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
});
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)
};
}),
Expand All @@ -429,6 +433,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
// actually be loaded, just in case they're only referred to inside
// intra-doc-links
resolver.borrow_mut().access(|resolver| {
sess.time("load_extern_crates", || {
for extern_name in &extern_names {
resolver
.resolve_str_path_error(
Expand All @@ -442,6 +447,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
});
}
});
});

// Now we're good to clone the resolver because everything should be loaded
resolver.clone()
Expand All @@ -453,7 +459,31 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt

let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).take();

let (krate, render_info, opts) = sess.time("run_global_ctxt", || {
global_ctxt.enter(|tcx| {
run_global_ctxt(
tcx,
resolver,
default_passes,
manual_passes,
render_options,
output_format,
)
})
});
(krate, render_info, opts, Lrc::clone(sess))
})
})
}

fn run_global_ctxt(
tcx: TyCtxt<'_>,
resolver: Rc<RefCell<interface::BoxedResolver>>,
mut default_passes: passes::DefaultPassOption,
mut manual_passes: Vec<String>,
render_options: RenderOptions,
output_format: Option<OutputFormat>,
) -> (clean::Crate, RenderInfo, RenderOptions) {
// Certain queries assume that some checks were run elsewhere
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
// so type-check everything other than function bodies in this crate before running lints.
Expand All @@ -472,13 +502,15 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
}
});
tcx.sess.abort_if_errors();
sess.time("missing_docs", || {
tcx.sess.time("missing_docs", || {
rustc_lint::check_crate(tcx, rustc_lint::builtin::MissingDoc::new);
});
tcx.sess.time("check_mod_attrs", || {
for &module in tcx.hir().krate().modules.keys() {
let local_def_id = tcx.hir().local_def_id(module);
tcx.ensure().check_mod_attrs(local_def_id);
}
});

let access_levels = tcx.privacy_access_levels(LOCAL_CRATE);
// Convert from a HirId set to a DefId set since we don't always have easy access
Expand Down Expand Up @@ -519,7 +551,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
};
debug!("crate: {:?}", tcx.hir().krate());

let mut krate = clean::krate(&mut ctxt);
let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt));

if let Some(ref m) = krate.module {
if let None | Some("") = m.doc_value() {
Expand All @@ -530,9 +562,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS,
ctxt.as_local_hir_id(m.def_id).unwrap(),
|lint| {
let mut diag = lint.build(
"no documentation found for this crate's top-level module",
);
let mut diag =
lint.build("no documentation found for this crate's top-level module");
diag.help(help);
diag.emit();
},
Expand All @@ -541,10 +572,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
}

fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler) {
let mut msg = diag.struct_warn(&format!(
"the `#![doc({})]` attribute is considered deprecated",
name
));
let mut msg = diag
.struct_warn(&format!("the `#![doc({})]` attribute is considered deprecated", name));
msg.warn(
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
for more information",
Expand Down Expand Up @@ -618,16 +647,13 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
};
if run {
debug!("running pass {}", p.pass.name);
krate = (p.pass.run)(krate, &ctxt);
krate = ctxt.tcx.sess.time(p.pass.name, || (p.pass.run)(krate, &ctxt));
}
}

ctxt.sess().abort_if_errors();

(krate, ctxt.renderinfo.into_inner(), ctxt.render_options)
})
})
})
}

/// Due to https://github.com/rust-lang/rust/pull/73566,
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ fn main_options(options: config::Options) -> MainResult {
let crate_name = options.crate_name.clone();
let crate_version = options.crate_version.clone();
let output_format = options.output_format;
let (mut krate, renderinfo, renderopts) = core::run_core(options);
let (mut krate, renderinfo, renderopts, sess) = core::run_core(options);

info!("finished with rustc");

Expand All @@ -524,11 +524,11 @@ fn main_options(options: config::Options) -> MainResult {
let (error_format, edition, debugging_options) = diag_opts;
let diag = core::new_handler(error_format, None, &debugging_options);
match output_format {
None | Some(config::OutputFormat::Html) => {
None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
run_renderer::<html::render::Context>(krate, renderopts, renderinfo, &diag, edition)
}
Some(config::OutputFormat::Json) => {
}),
Some(config::OutputFormat::Json) => sess.time("render_json", || {
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition)
}
}),
}
}
4 changes: 4 additions & 0 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {

for &cnum in cx.tcx.crates().iter() {
for &(did, _) in cx.tcx.all_trait_implementations(cnum).iter() {
cx.tcx.sess.time("build_extern_trait_impl", || {
inline::build_impl(cx, did, None, &mut new_items);
});
}
}

Expand Down Expand Up @@ -87,7 +89,9 @@ pub fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
for &trait_did in cx.tcx.all_traits(LOCAL_CRATE).iter() {
for &impl_node in cx.tcx.hir().trait_impls(trait_did) {
let impl_did = cx.tcx.hir().local_def_id(impl_node);
cx.tcx.sess.time("build_local_trait_impl", || {
inline::build_impl(cx, impl_did.to_def_id(), None, &mut new_items);
});
}
}

Expand Down