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

[perftest] Use LTO for compiling rustdoc #102885

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ fn prepare_lto(
let module = SerializedModule::FromRlib(data.to_vec());
upstream_modules.push((module, CString::new(name).unwrap()));
}
Err(msg) => return Err(diag_handler.fatal(&msg)),
Err(msg) => {
eprintln!("Couldn't add bitcode from {name}");
return Err(diag_handler.fatal(&msg));
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl Step for Rustdoc {
features.push("jemalloc".to_string());
}

let cargo = prepare_tool_cargo(
let mut cargo = prepare_tool_cargo(
builder,
build_compiler,
Mode::ToolRustc,
Expand All @@ -551,6 +551,11 @@ impl Step for Rustdoc {
features.as_slice(),
);

if build_compiler.stage == 1 {
cargo.rustflag("-Cembed-bitcode=yes");
cargo.rustflag("-Clto=thin");
}

builder.info(&format!(
"Building rustdoc for stage{} ({})",
target_compiler.stage, target_compiler.host
Expand Down
25 changes: 18 additions & 7 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ where
let tcx = self.cx.tcx;
let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, &[]) };
if !self.cx.generated_synthetics.insert((ty, trait_def_id)) {
debug!("get_auto_trait_impl_for({:?}): already generated, aborting", trait_ref);
tracing::debug!(
"get_auto_trait_impl_for({:?}): already generated, aborting",
trait_ref
);
return None;
}

Expand All @@ -70,10 +73,12 @@ where
info.vid_to_region,
);

debug!(
tracing::debug!(
"find_auto_trait_generics(item_def_id={:?}, trait_def_id={:?}): \
finished with {:?}",
item_def_id, trait_def_id, new_generics
item_def_id,
trait_def_id,
new_generics
);

new_generics
Expand Down Expand Up @@ -139,7 +144,7 @@ where
let ty = tcx.type_of(item_def_id);
let f = auto_trait::AutoTraitFinder::new(tcx);

debug!("get_auto_trait_impls({:?})", ty);
tracing::debug!("get_auto_trait_impls({:?})", ty);
let auto_traits: Vec<_> = self.cx.auto_traits.iter().copied().collect();
let mut auto_traits: Vec<Item> = auto_traits
.into_iter()
Expand Down Expand Up @@ -432,10 +437,12 @@ where
mut existing_predicates: Vec<WherePredicate>,
vid_to_region: FxHashMap<ty::RegionVid, ty::Region<'tcx>>,
) -> Generics {
debug!(
tracing::debug!(
"param_env_to_generics(item_def_id={:?}, param_env={:?}, \
existing_predicates={:?})",
item_def_id, param_env, existing_predicates
item_def_id,
param_env,
existing_predicates
);

let tcx = self.cx.tcx;
Expand Down Expand Up @@ -466,7 +473,11 @@ where
);
let mut generic_params = raw_generics.params;

debug!("param_env_to_generics({:?}): generic_params={:?}", item_def_id, generic_params);
tracing::debug!(
"param_env_to_generics({:?}): generic_params={:?}",
item_def_id,
generic_params
);

let mut has_sized = FxHashSet::default();
let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
Expand Down
13 changes: 7 additions & 6 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
let param_env = cx.tcx.param_env(item_def_id);
let ty = cx.tcx.bound_type_of(item_def_id);

trace!("get_blanket_impls({:?})", ty);
tracing::trace!("get_blanket_impls({:?})", ty);
let mut impls = Vec::new();
for trait_def_id in cx.tcx.all_traits() {
if !cx.cache.access_levels.is_public(trait_def_id)
Expand All @@ -28,7 +28,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
// NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls
let trait_impls = cx.tcx.trait_impls_of(trait_def_id);
'blanket_impls: for &impl_def_id in trait_impls.blanket_impls() {
trace!(
tracing::trace!(
"get_blanket_impls: Considering impl for trait '{:?}' {:?}",
trait_def_id,
impl_def_id
Expand All @@ -55,7 +55,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
// FIXME(eddyb) ignoring `obligations` might cause false positives.
drop(obligations);

trace!(
tracing::trace!(
"invoking predicate_may_hold: param_env={:?}, impl_trait_ref={:?}, impl_ty={:?}",
param_env,
impl_trait_ref,
Expand All @@ -74,7 +74,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.to_predicate(infcx.tcx),
));
for predicate in predicates {
debug!("testing predicate {:?}", predicate);
tracing::debug!("testing predicate {:?}", predicate);
let obligation = traits::Obligation::new(
traits::ObligationCause::dummy(),
param_env,
Expand All @@ -87,9 +87,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
_ => continue 'blanket_impls,
}
}
debug!(
tracing::debug!(
"get_blanket_impls: found applicable impl for trait_ref={:?}, ty={:?}",
trait_ref, ty
trait_ref,
ty
);

cx.generated_synthetics.insert((ty.0, trait_def_id));
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) fn try_inline(
}
let mut ret = Vec::new();

debug!("attrs={:?}", attrs);
tracing::debug!("attrs={:?}", attrs);
let attrs_clone = attrs;

let kind = match res {
Expand Down Expand Up @@ -493,9 +493,9 @@ pub(crate) fn build_impl(
}

let (merged_attrs, cfg) = merge_attrs(cx, parent_module, load_attrs(cx, did), attrs);
trace!("merged_attrs={:?}", merged_attrs);
tracing::trace!("merged_attrs={:?}", merged_attrs);

trace!(
tracing::trace!(
"build_impl: impl {:?} for {:?}",
trait_.as_ref().map(|t| t.def_id()),
for_.def_id(&cx.cache)
Expand Down Expand Up @@ -715,7 +715,7 @@ pub(crate) fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
cx.active_extern_traits.insert(did);
}

debug!("record_extern_trait: {:?}", did);
tracing::debug!("record_extern_trait: {:?}", did);
let trait_ = build_external_trait(cx, did);

cx.external_traits.borrow_mut().insert(did, trait_);
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
let path = external_path(cx, trait_ref.def_id, true, bindings, trait_ref.substs);

debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
tracing::debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);

path
}
Expand Down Expand Up @@ -249,7 +249,7 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Life
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReErased => {
debug!("cannot clean region {:?}", region);
tracing::debug!("cannot clean region {:?}", region);
None
}
}
Expand Down Expand Up @@ -1587,11 +1587,11 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>>
.map(|resolved| infcx.resolve_vars_if_possible(resolved.value));
match normalized {
Ok(normalized_value) => {
debug!("normalized {:?} to {:?}", ty, normalized_value);
tracing::debug!("normalized {:?} to {:?}", ty, normalized_value);
Some(normalized_value)
}
Err(err) => {
debug!("failed to normalize {:?}: {:?}", ty, err);
tracing::debug!("failed to normalize {:?}: {:?}", ty, err);
None
}
}
Expand All @@ -1602,7 +1602,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
cx: &mut DocContext<'tcx>,
def_id: Option<DefId>,
) -> Type {
trace!("cleaning type: {:?}", ty);
tracing::trace!("cleaning type: {:?}", ty);
let ty = normalize(cx, ty).unwrap_or(ty);
match *ty.kind() {
ty::Never => Primitive(PrimitiveType::Never),
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl Item {
cx: &mut DocContext<'_>,
cfg: Option<Arc<Cfg>>,
) -> Item {
trace!("name={:?}, def_id={:?} cfg={:?}", name, def_id, cfg);
tracing::trace!("name={:?}, def_id={:?} cfg={:?}", name, def_id, cfg);

// Primitives and Keywords are written in the source code as private modules.
// The modules need to be private so that nobody actually uses them, but the
Expand Down Expand Up @@ -504,9 +504,9 @@ impl Item {
.map_or(&[][..], |v| v.as_slice())
.iter()
.filter_map(|ItemLink { link: s, link_text, page_id: did, ref fragment }| {
debug!(?did);
tracing::debug!(?did);
if let Ok((mut href, ..)) = href(*did, cx) {
debug!(?href);
tracing::debug!(?href);
if let Some(ref fragment) = *fragment {
fragment.render(&mut href, cx.tcx())
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ impl Attributes {
let mut other_attrs = ast::AttrVec::new();
for (attr, parent_module) in attrs {
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
trace!("got doc_str={doc_str:?}");
tracing::trace!("got doc_str={doc_str:?}");
let doc = beautify_doc_string(doc_str, comment_kind);
let kind = if attr.is_doc_comment() {
DocFragmentKind::SugaredDoc
Expand Down Expand Up @@ -1929,7 +1929,7 @@ impl PrimitiveType {
for &crate_num in tcx.crates(()) {
let e = ExternalCrate { crate_num };
let crate_name = e.name(tcx);
debug!(?crate_num, ?crate_name);
tracing::debug!(?crate_num, ?crate_name);
for &(def_id, prim) in &e.primitives(tcx) {
// HACK: try to link to std instead where possible
if crate_name == sym::core && primitive_locations.contains_key(&prim) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub(crate) fn build_deref_target_impls(

pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
use rustc_hir::*;
debug!("trying to get a name from pattern: {:?}", p);
tracing::debug!("trying to get a name from pattern: {:?}", p);

Symbol::intern(&match p.kind {
PatKind::Wild | PatKind::Struct(..) => return kw::Underscore,
Expand All @@ -217,7 +217,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
PatKind::Box(p) => return name_from_pat(&*p),
PatKind::Ref(p, _) => return name_from_pat(&*p),
PatKind::Lit(..) => {
warn!(
tracing::warn!(
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
);
return Symbol::intern("()");
Expand Down Expand Up @@ -450,7 +450,7 @@ pub(crate) fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String {

/// Given a type Path, resolve it to a Type using the TyCtxt
pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
debug!("resolve_type({:?})", path);
tracing::debug!("resolve_type({:?})", path);

match path.res {
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
Expand Down Expand Up @@ -489,7 +489,7 @@ pub(crate) fn get_auto_trait_and_blanket_impls(
/// [`href()`]: crate::html::format::href
pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
use DefKind::*;
debug!("register_res({:?})", res);
tracing::debug!("register_res({:?})", res);

let (kind, did) = match res {
Res::Def(
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub(crate) fn create_config(

let hir = tcx.hir();
let body = hir.body(hir.body_owned_by(def_id));
debug!("visiting body for {:?}", def_id);
tracing::debug!("visiting body for {:?}", def_id);
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)
};
Expand Down Expand Up @@ -376,7 +376,7 @@ pub(crate) fn run_global_ctxt(
ctxt.external_traits.borrow_mut().insert(sized_trait_did, sized_trait);
}

debug!("crate: {:?}", tcx.hir().krate());
tracing::debug!("crate: {:?}", tcx.hir().krate());

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

Expand Down Expand Up @@ -439,7 +439,7 @@ pub(crate) fn run_global_ctxt(
}
}

info!("Executing passes");
tracing::info!("Executing passes");

for p in passes::defaults(show_coverage) {
let run = match p.condition {
Expand All @@ -449,7 +449,7 @@ pub(crate) fn run_global_ctxt(
WhenNotDocumentHidden => !ctxt.render_options.document_hidden,
};
if run {
debug!("running pass {}", p.pass.name);
tracing::debug!("running pass {}", p.pass.name);
krate = tcx.sess.time(p.pass.name, || (p.pass.run)(krate, &mut ctxt));
}
}
Expand Down Expand Up @@ -489,7 +489,7 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> {
}

fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
debug!("visiting path {:?}", path);
tracing::debug!("visiting path {:?}", path);
if path.res == Res::Err {
// We have less context here than in rustc_resolve,
// so we can only emit the name and span.
Expand Down
14 changes: 7 additions & 7 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
}
});

debug!(?lint_opts);
tracing::debug!(?lint_opts);

let crate_types =
if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
Expand Down Expand Up @@ -715,7 +715,7 @@ pub(crate) fn make_test(
prog.extend([&main_pre, everything_else, &main_post].iter().cloned());
}

debug!("final doctest:\n{prog}");
tracing::debug!("final doctest:\n{prog}");

(prog, line_offset, supports_color)
}
Expand Down Expand Up @@ -756,7 +756,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
match maybe_new_parser_from_source_str(&sess, filename, source.to_owned()) {
Ok(p) => p,
Err(_) => {
debug!("Cannot build a parser to check mod attr so skipping...");
tracing::debug!("Cannot build a parser to check mod attr so skipping...");
return true;
}
};
Expand Down Expand Up @@ -865,9 +865,9 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) {
}
}

debug!("before:\n{before}");
debug!("crates:\n{crates}");
debug!("after:\n{after}");
tracing::debug!("before:\n{before}");
tracing::debug!("crates:\n{crates}");
tracing::debug!("after:\n{after}");

(before, after, crates)
}
Expand Down Expand Up @@ -1044,7 +1044,7 @@ impl Tester for Collector {
)
};

debug!("creating test {name}: {test}");
tracing::debug!("creating test {name}: {test}");
self.tests.push(test::TestDescAndFn {
desc: test::TestDesc {
name: test::DynTestName(name),
Expand Down
Loading