rustdoc: Eliminate uses of EarlyDocLinkResolver::all_traits
This commit is contained in:
parent
84365fff0a
commit
175474549c
4 changed files with 118 additions and 134 deletions
|
@ -597,11 +597,6 @@ impl CStore {
|
||||||
self.get_crate_data(cnum).get_proc_macro_quoted_span(id, sess)
|
self.get_crate_data(cnum).get_proc_macro_quoted_span(id, sess)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decodes all traits in the crate (for rustdoc).
|
|
||||||
pub fn traits_in_crate_untracked(&self, cnum: CrateNum) -> impl Iterator<Item = DefId> + '_ {
|
|
||||||
self.get_crate_data(cnum).get_traits()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decodes all trait impls in the crate (for rustdoc).
|
/// Decodes all trait impls in the crate (for rustdoc).
|
||||||
pub fn trait_impls_in_crate_untracked(
|
pub fn trait_impls_in_crate_untracked(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -13,13 +13,13 @@ pub(crate) struct BlanketImplFinder<'a, 'tcx> {
|
||||||
|
|
||||||
impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||||
pub(crate) fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> {
|
pub(crate) fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> {
|
||||||
let param_env = self.cx.tcx.param_env(item_def_id);
|
let cx = &mut self.cx;
|
||||||
let ty = self.cx.tcx.bound_type_of(item_def_id);
|
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);
|
trace!("get_blanket_impls({:?})", ty);
|
||||||
let mut impls = Vec::new();
|
let mut impls = Vec::new();
|
||||||
self.cx.with_all_traits(|cx, all_traits| {
|
for trait_def_id in cx.tcx.all_traits() {
|
||||||
for &trait_def_id in all_traits {
|
|
||||||
if !cx.cache.access_levels.is_public(trait_def_id)
|
if !cx.cache.access_levels.is_public(trait_def_id)
|
||||||
|| cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
|
|| cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
|
||||||
{
|
{
|
||||||
|
@ -108,21 +108,29 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||||
),
|
),
|
||||||
// FIXME(eddyb) compute both `trait_` and `for_` from
|
// FIXME(eddyb) compute both `trait_` and `for_` from
|
||||||
// the post-inference `trait_ref`, as it's more accurate.
|
// the post-inference `trait_ref`, as it's more accurate.
|
||||||
trait_: Some(clean_trait_ref_with_bindings(cx, trait_ref.0, ThinVec::new())),
|
trait_: Some(clean_trait_ref_with_bindings(
|
||||||
|
cx,
|
||||||
|
trait_ref.0,
|
||||||
|
ThinVec::new(),
|
||||||
|
)),
|
||||||
for_: clean_middle_ty(ty.0, cx, None),
|
for_: clean_middle_ty(ty.0, cx, None),
|
||||||
items: cx.tcx
|
items: cx
|
||||||
|
.tcx
|
||||||
.associated_items(impl_def_id)
|
.associated_items(impl_def_id)
|
||||||
.in_definition_order()
|
.in_definition_order()
|
||||||
.map(|x| clean_middle_assoc_item(x, cx))
|
.map(|x| clean_middle_assoc_item(x, cx))
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
polarity: ty::ImplPolarity::Positive,
|
polarity: ty::ImplPolarity::Positive,
|
||||||
kind: ImplKind::Blanket(Box::new(clean_middle_ty(trait_ref.0.self_ty(), cx, None))),
|
kind: ImplKind::Blanket(Box::new(clean_middle_ty(
|
||||||
|
trait_ref.0.self_ty(),
|
||||||
|
cx,
|
||||||
|
None,
|
||||||
|
))),
|
||||||
}))),
|
}))),
|
||||||
cfg: None,
|
cfg: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
impls
|
impls
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ pub(crate) struct ResolverCaches {
|
||||||
/// Traits in scope for a given module.
|
/// Traits in scope for a given module.
|
||||||
/// See `collect_intra_doc_links::traits_implemented_by` for more details.
|
/// See `collect_intra_doc_links::traits_implemented_by` for more details.
|
||||||
pub(crate) traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
|
pub(crate) traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
|
||||||
pub(crate) all_traits: Option<Vec<DefId>>,
|
|
||||||
pub(crate) all_trait_impls: Option<Vec<DefId>>,
|
pub(crate) all_trait_impls: Option<Vec<DefId>>,
|
||||||
pub(crate) all_macro_rules: FxHashMap<Symbol, Res<NodeId>>,
|
pub(crate) all_macro_rules: FxHashMap<Symbol, Res<NodeId>>,
|
||||||
}
|
}
|
||||||
|
@ -134,12 +133,6 @@ impl<'tcx> DocContext<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn with_all_traits(&mut self, f: impl FnOnce(&mut Self, &[DefId])) {
|
|
||||||
let all_traits = self.resolver_caches.all_traits.take();
|
|
||||||
f(self, all_traits.as_ref().expect("`all_traits` are already borrowed"));
|
|
||||||
self.resolver_caches.all_traits = all_traits;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn with_all_trait_impls(&mut self, f: impl FnOnce(&mut Self, &[DefId])) {
|
pub(crate) fn with_all_trait_impls(&mut self, f: impl FnOnce(&mut Self, &[DefId])) {
|
||||||
let all_trait_impls = self.resolver_caches.all_trait_impls.take();
|
let all_trait_impls = self.resolver_caches.all_trait_impls.take();
|
||||||
f(self, all_trait_impls.as_ref().expect("`all_trait_impls` are already borrowed"));
|
f(self, all_trait_impls.as_ref().expect("`all_trait_impls` are already borrowed"));
|
||||||
|
@ -353,14 +346,8 @@ pub(crate) fn run_global_ctxt(
|
||||||
});
|
});
|
||||||
rustc_passes::stability::check_unused_or_stable_features(tcx);
|
rustc_passes::stability::check_unused_or_stable_features(tcx);
|
||||||
|
|
||||||
let auto_traits = resolver_caches
|
let auto_traits =
|
||||||
.all_traits
|
tcx.all_traits().filter(|&trait_def_id| tcx.trait_is_auto(trait_def_id)).collect();
|
||||||
.as_ref()
|
|
||||||
.expect("`all_traits` are already borrowed")
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.filter(|&trait_def_id| tcx.trait_is_auto(trait_def_id))
|
|
||||||
.collect();
|
|
||||||
let access_levels = tcx.privacy_access_levels(()).map_id(Into::into);
|
let access_levels = tcx.privacy_access_levels(()).map_id(Into::into);
|
||||||
|
|
||||||
let mut ctxt = DocContext {
|
let mut ctxt = DocContext {
|
||||||
|
|
|
@ -37,7 +37,6 @@ pub(crate) fn early_resolve_intra_doc_links(
|
||||||
markdown_links: Default::default(),
|
markdown_links: Default::default(),
|
||||||
doc_link_resolutions: Default::default(),
|
doc_link_resolutions: Default::default(),
|
||||||
traits_in_scope: Default::default(),
|
traits_in_scope: Default::default(),
|
||||||
all_traits: Default::default(),
|
|
||||||
all_trait_impls: Default::default(),
|
all_trait_impls: Default::default(),
|
||||||
all_macro_rules: Default::default(),
|
all_macro_rules: Default::default(),
|
||||||
document_private_items,
|
document_private_items,
|
||||||
|
@ -63,7 +62,6 @@ pub(crate) fn early_resolve_intra_doc_links(
|
||||||
markdown_links: Some(link_resolver.markdown_links),
|
markdown_links: Some(link_resolver.markdown_links),
|
||||||
doc_link_resolutions: link_resolver.doc_link_resolutions,
|
doc_link_resolutions: link_resolver.doc_link_resolutions,
|
||||||
traits_in_scope: link_resolver.traits_in_scope,
|
traits_in_scope: link_resolver.traits_in_scope,
|
||||||
all_traits: Some(link_resolver.all_traits),
|
|
||||||
all_trait_impls: Some(link_resolver.all_trait_impls),
|
all_trait_impls: Some(link_resolver.all_trait_impls),
|
||||||
all_macro_rules: link_resolver.all_macro_rules,
|
all_macro_rules: link_resolver.all_macro_rules,
|
||||||
}
|
}
|
||||||
|
@ -81,7 +79,6 @@ struct EarlyDocLinkResolver<'r, 'ra> {
|
||||||
markdown_links: FxHashMap<String, Vec<PreprocessedMarkdownLink>>,
|
markdown_links: FxHashMap<String, Vec<PreprocessedMarkdownLink>>,
|
||||||
doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option<Res<ast::NodeId>>>,
|
doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option<Res<ast::NodeId>>>,
|
||||||
traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
|
traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
|
||||||
all_traits: Vec<DefId>,
|
|
||||||
all_trait_impls: Vec<DefId>,
|
all_trait_impls: Vec<DefId>,
|
||||||
all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
||||||
document_private_items: bool,
|
document_private_items: bool,
|
||||||
|
@ -122,8 +119,6 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
|
||||||
loop {
|
loop {
|
||||||
let crates = Vec::from_iter(self.resolver.cstore().crates_untracked());
|
let crates = Vec::from_iter(self.resolver.cstore().crates_untracked());
|
||||||
for &cnum in &crates[start_cnum..] {
|
for &cnum in &crates[start_cnum..] {
|
||||||
let all_traits =
|
|
||||||
Vec::from_iter(self.resolver.cstore().traits_in_crate_untracked(cnum));
|
|
||||||
let all_trait_impls =
|
let all_trait_impls =
|
||||||
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
|
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
|
||||||
let all_inherent_impls =
|
let all_inherent_impls =
|
||||||
|
@ -132,20 +127,18 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
|
||||||
self.resolver.cstore().incoherent_impls_in_crate_untracked(cnum),
|
self.resolver.cstore().incoherent_impls_in_crate_untracked(cnum),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Querying traits in scope is expensive so we try to prune the impl and traits lists
|
// Querying traits in scope is expensive so we try to prune the impl lists using
|
||||||
// using privacy, private traits and impls from other crates are never documented in
|
// privacy, private traits and impls from other crates are never documented in
|
||||||
// the current crate, and links in their doc comments are not resolved.
|
// the current crate, and links in their doc comments are not resolved.
|
||||||
for &def_id in &all_traits {
|
|
||||||
if self.resolver.cstore().visibility_untracked(def_id).is_public() {
|
|
||||||
self.resolve_doc_links_extern_impl(def_id, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for &(trait_def_id, impl_def_id, simplified_self_ty) in &all_trait_impls {
|
for &(trait_def_id, impl_def_id, simplified_self_ty) in &all_trait_impls {
|
||||||
if self.resolver.cstore().visibility_untracked(trait_def_id).is_public()
|
if self.resolver.cstore().visibility_untracked(trait_def_id).is_public()
|
||||||
&& simplified_self_ty.and_then(|ty| ty.def()).map_or(true, |ty_def_id| {
|
&& simplified_self_ty.and_then(|ty| ty.def()).map_or(true, |ty_def_id| {
|
||||||
self.resolver.cstore().visibility_untracked(ty_def_id).is_public()
|
self.resolver.cstore().visibility_untracked(ty_def_id).is_public()
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
|
if self.visited_mods.insert(trait_def_id) {
|
||||||
|
self.resolve_doc_links_extern_impl(trait_def_id, false);
|
||||||
|
}
|
||||||
self.resolve_doc_links_extern_impl(impl_def_id, false);
|
self.resolve_doc_links_extern_impl(impl_def_id, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +151,6 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
|
||||||
self.resolve_doc_links_extern_impl(impl_def_id, true);
|
self.resolve_doc_links_extern_impl(impl_def_id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.all_traits.extend(all_traits);
|
|
||||||
self.all_trait_impls
|
self.all_trait_impls
|
||||||
.extend(all_trait_impls.into_iter().map(|(_, def_id, _)| def_id));
|
.extend(all_trait_impls.into_iter().map(|(_, def_id, _)| def_id));
|
||||||
}
|
}
|
||||||
|
@ -307,15 +299,20 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
|
||||||
{
|
{
|
||||||
if let Some(def_id) = child.res.opt_def_id() && !def_id.is_local() {
|
if let Some(def_id) = child.res.opt_def_id() && !def_id.is_local() {
|
||||||
let scope_id = match child.res {
|
let scope_id = match child.res {
|
||||||
Res::Def(DefKind::Variant, ..) => self.resolver.parent(def_id),
|
Res::Def(
|
||||||
|
DefKind::Variant
|
||||||
|
| DefKind::AssocTy
|
||||||
|
| DefKind::AssocFn
|
||||||
|
| DefKind::AssocConst,
|
||||||
|
..,
|
||||||
|
) => self.resolver.parent(def_id),
|
||||||
_ => def_id,
|
_ => def_id,
|
||||||
};
|
};
|
||||||
self.resolve_doc_links_extern_outer(def_id, scope_id); // Outer attribute scope
|
self.resolve_doc_links_extern_outer(def_id, scope_id); // Outer attribute scope
|
||||||
if let Res::Def(DefKind::Mod, ..) = child.res {
|
if let Res::Def(DefKind::Mod, ..) = child.res {
|
||||||
self.resolve_doc_links_extern_inner(def_id); // Inner attribute scope
|
self.resolve_doc_links_extern_inner(def_id); // Inner attribute scope
|
||||||
}
|
}
|
||||||
// `DefKind::Trait`s are processed in `process_extern_impls`.
|
if let Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, ..) = child.res {
|
||||||
if let Res::Def(DefKind::Mod | DefKind::Enum, ..) = child.res {
|
|
||||||
self.process_module_children_or_reexports(def_id);
|
self.process_module_children_or_reexports(def_id);
|
||||||
}
|
}
|
||||||
if let Res::Def(DefKind::Struct | DefKind::Union | DefKind::Variant, _) =
|
if let Res::Def(DefKind::Struct | DefKind::Union | DefKind::Variant, _) =
|
||||||
|
@ -357,9 +354,6 @@ impl Visitor<'_> for EarlyDocLinkResolver<'_, '_> {
|
||||||
self.parent_scope.module = old_module;
|
self.parent_scope.module = old_module;
|
||||||
} else {
|
} else {
|
||||||
match &item.kind {
|
match &item.kind {
|
||||||
ItemKind::Trait(..) => {
|
|
||||||
self.all_traits.push(self.resolver.local_def_id(item.id).to_def_id());
|
|
||||||
}
|
|
||||||
ItemKind::Impl(box ast::Impl { of_trait: Some(..), .. }) => {
|
ItemKind::Impl(box ast::Impl { of_trait: Some(..), .. }) => {
|
||||||
self.all_trait_impls.push(self.resolver.local_def_id(item.id).to_def_id());
|
self.all_trait_impls.push(self.resolver.local_def_id(item.id).to_def_id());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue