Skip to content

[DO NOT MERGE] Perf test for rustdoc #91257

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

Closed
wants to merge 3 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
9 changes: 7 additions & 2 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ crate struct Context<'tcx> {
pub(super) deref_id_map: RefCell<FxHashMap<DefId, String>>,
/// The map used to ensure all generated 'id=' attributes are unique.
pub(super) id_map: RefCell<IdMap>,

pub(super) nixon_hack: RefCell<FxHashMap<clean::ItemId, String>>,
/// Shared mutable state.
///
/// Issue for improving the situation: [#82381][]
Expand All @@ -72,8 +74,9 @@ crate struct Context<'tcx> {
}

// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Context<'_>, 144);
// FIXME: Reenable before asking for review
// #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
// rustc_data_structures::static_assert_size!(Context<'_>, 144);

/// Shared mutable state used in [`Context`] and elsewhere.
crate struct SharedContext<'tcx> {
Expand Down Expand Up @@ -517,6 +520,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
render_redirect_pages: false,
id_map: RefCell::new(id_map),
deref_id_map: RefCell::new(FxHashMap::default()),
nixon_hack: RefCell::new(FxHashMap::default()),
shared: Rc::new(scx),
include_sources,
};
Expand All @@ -541,6 +545,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
dst: self.dst.clone(),
render_redirect_pages: self.render_redirect_pages,
deref_id_map: RefCell::new(FxHashMap::default()),
nixon_hack: RefCell::new(FxHashMap::default()),
id_map: RefCell::new(IdMap::new()),
shared: Rc::clone(&self.shared),
include_sources: self.include_sources,
Expand Down
49 changes: 48 additions & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,8 @@ fn render_impl(
);
write!(w, "<summary>")
}

write!(w, "{}:{} ", file!(), line!());
render_impl_summary(
w,
cx,
Expand All @@ -1624,6 +1626,7 @@ fn render_impl(
rendering_params.is_on_foreign_type,
aliases,
);
write!(w, "{}:{} ", file!(), line!());
if toggled {
write!(w, "</summary>")
}
Expand Down Expand Up @@ -1691,6 +1694,7 @@ pub(crate) fn render_impl_summary(
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
aliases: &[String],
) {
// This is where the ID is created
let id = cx.derive_id(match i.inner_impl().trait_ {
Some(ref t) => {
if is_on_foreign_type {
Expand All @@ -1701,6 +1705,9 @@ pub(crate) fn render_impl_summary(
}
None => "impl".to_string(),
});

cx.nixon_hack.borrow_mut().insert(i.impl_item.def_id, id.clone());

let aliases = if aliases.is_empty() {
String::new()
} else {
Expand Down Expand Up @@ -2215,6 +2222,7 @@ fn get_id_for_impl_on_foreign_type(
}

fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String, String)> {
//
match *item.kind {
clean::ItemKind::ImplItem(ref i) => {
i.trait_.as_ref().map(|trait_| {
Expand Down Expand Up @@ -2306,6 +2314,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
.filter(|i| {
i.inner_impl().for_.def_id(cache).map_or(false, |d| !cache.paths.contains_key(&d))
})
// FIXME: Dont do the filter map dance
.filter_map(|i| extract_for_impl_name(&i.impl_item, cx))
.collect::<Vec<_>>();

Expand All @@ -2325,7 +2334,45 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean

sidebar_assoc_items(cx, buf, it);

buf.push_str("<h3 class=\"sidebar-title\"><a href=\"#implementors\">Implementors</a></h3>");
let did = it.def_id.expect_def_id();

if let Some(implementors) = cache.implementors.get(&did) {
let mut res = implementors
.iter()
.filter(|i| {
i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d))
&& i.inner_impl().polarity == ty::ImplPolarity::Positive
})
// FIXME: Dont do the filter map dance
// .filter_map(|i| extract_for_impl_name(&i.impl_item, cx))
.map(|i| {
(
format!("{:#}", i.inner_impl().for_.print(cx)),
cx.nixon_hack
.borrow()
.get(&i.impl_item.def_id)
.unwrap_or_else(|| panic!("Not in index {:#?}", i))
.clone(),
)
})
.collect::<Vec<_>>();

if !res.is_empty() {
res.sort_unstable();

buf.push_str(
"<h3 class=\"sidebar-title\">\
<a href=\"#implementors\">Implementors</a>\
</h3>
<div class=\"sidebar-links\">",
);
for (name, id) in res.into_iter() {
write!(buf, "<a href=\"#{}\">{}</a>", id, Escape(&name));
}
buf.push_str("</div>");
}
}

if t.is_auto {
buf.push_str(
"<h3 class=\"sidebar-title\"><a \
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
"Implementors",
"<div class=\"item-list\" id=\"implementors-list\">",
);

write!(w, "<!-- {}:{} -->", file!(), line!());

for implementor in concrete {
render_implementor(cx, implementor, it, w, &implementor_dups, &[]);
}
Expand Down