Skip to content

Commit c096176

Browse files
committed
Auto merge of #92227 - Kobzol:rustdoc-doc-hidden, r=jyn514
Rustdoc: use `is_doc_hidden` method on more places While profiling `rustdoc`, I noticed that finding out if some item is marked with `#[doc(hidden)]` is relatively hot, so I tried to optimize it. I noticed that there is already a method called `is_doc_hidden` on `TyCtxt`, but it wasn't used much, so I replaced the manual calls to `attrs(...).has_word(...)` with this method. Just by doing that, perf. was improved locally, although I'm not sure if the semantics of the previous calls and this method are the same? As another step, I tried to querify `is_doc_hidden`, but I didn't include that here until we see the perf. results from the first commit and until I find whether this change is OK at all :) Can I ask for a perf. run? Thanks. r? `@jyn514`
2 parents 67491a2 + 0ec3199 commit c096176

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

src/librustdoc/clean/inline.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
1717

1818
use crate::clean::{
1919
self, clean_fn_decl_from_did_and_sig, clean_ty_generics, utils, Attributes, AttributesExt,
20-
Clean, ImplKind, ItemId, NestedAttributesExt, Type, Visibility,
20+
Clean, ImplKind, ItemId, Type, Visibility,
2121
};
2222
use crate::core::DocContext;
2323
use crate::formats::item_type::ItemType;
@@ -421,7 +421,7 @@ crate fn build_impl(
421421
associated_trait.def_id,
422422
)
423423
.unwrap(); // SAFETY: For all impl items there exists trait item that has the same name.
424-
!tcx.get_attrs(trait_item.def_id).lists(sym::doc).has_word(sym::hidden)
424+
!tcx.is_doc_hidden(trait_item.def_id)
425425
} else {
426426
true
427427
}
@@ -456,7 +456,7 @@ crate fn build_impl(
456456
let mut stack: Vec<&Type> = vec![&for_];
457457

458458
if let Some(did) = trait_.as_ref().map(|t| t.def_id()) {
459-
if tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
459+
if tcx.is_doc_hidden(did) {
460460
return;
461461
}
462462
}
@@ -466,7 +466,7 @@ crate fn build_impl(
466466

467467
while let Some(ty) = stack.pop() {
468468
if let Some(did) = ty.def_id(&cx.cache) {
469-
if tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
469+
if tcx.is_doc_hidden(did) {
470470
return;
471471
}
472472
}

src/librustdoc/passes/collect_trait_impls.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
4747
inline::build_impl(cx, None, def_id, None, &mut new_items);
4848

4949
// FIXME(eddyb) is this `doc(hidden)` check needed?
50-
if !cx.tcx.get_attrs(def_id).lists(sym::doc).has_word(sym::hidden) {
50+
if !cx.tcx.is_doc_hidden(def_id) {
5151
let impls = get_auto_trait_and_blanket_impls(cx, def_id);
5252
new_items.extend(impls.filter(|i| cx.inlined.insert(i.def_id)));
5353
}
@@ -176,13 +176,7 @@ impl<'a, 'tcx> DocVisitor for SyntheticImplCollector<'a, 'tcx> {
176176
fn visit_item(&mut self, i: &Item) {
177177
if i.is_struct() || i.is_enum() || i.is_union() {
178178
// FIXME(eddyb) is this `doc(hidden)` check needed?
179-
if !self
180-
.cx
181-
.tcx
182-
.get_attrs(i.def_id.expect_def_id())
183-
.lists(sym::doc)
184-
.has_word(sym::hidden)
185-
{
179+
if !self.cx.tcx.is_doc_hidden(i.def_id.expect_def_id()) {
186180
self.impls
187181
.extend(get_auto_trait_and_blanket_impls(self.cx, i.def_id.expect_def_id()));
188182
}

src/librustdoc/visit_lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use rustc_hir::def::{DefKind, Res};
33
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
44
use rustc_middle::middle::privacy::{AccessLevel, AccessLevels};
55
use rustc_middle::ty::TyCtxt;
6-
use rustc_span::symbol::sym;
7-
8-
use crate::clean::{AttributesExt, NestedAttributesExt};
96

107
// FIXME: this may not be exhaustive, but is sufficient for rustdocs current uses
118

@@ -39,7 +36,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
3936

4037
// Updates node level and returns the updated level
4138
fn update(&mut self, did: DefId, level: Option<AccessLevel>) -> Option<AccessLevel> {
42-
let is_hidden = self.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden);
39+
let is_hidden = self.tcx.is_doc_hidden(did);
4340

4441
let old_level = self.access_levels.map.get(&did).cloned();
4542
// Accessibility levels can only grow

0 commit comments

Comments
 (0)