Introduce 'ra
lifetime name.
`rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'ra`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`ra` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`.
This commit is contained in:
parent
c2f74c3f92
commit
d4fc76cbf3
11 changed files with 482 additions and 471 deletions
|
@ -11,9 +11,9 @@ use tracing::info;
|
|||
use crate::{NameBinding, NameBindingKind, Resolver};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ParentId<'a> {
|
||||
enum ParentId<'ra> {
|
||||
Def(LocalDefId),
|
||||
Import(NameBinding<'a>),
|
||||
Import(NameBinding<'ra>),
|
||||
}
|
||||
|
||||
impl ParentId<'_> {
|
||||
|
@ -25,13 +25,13 @@ impl ParentId<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) struct EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
||||
r: &'r mut Resolver<'a, 'tcx>,
|
||||
pub(crate) struct EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
||||
r: &'a mut Resolver<'ra, 'tcx>,
|
||||
def_effective_visibilities: EffectiveVisibilities,
|
||||
/// While walking import chains we need to track effective visibilities per-binding, and def id
|
||||
/// keys in `Resolver::effective_visibilities` are not enough for that, because multiple
|
||||
/// bindings can correspond to a single def id in imports. So we keep a separate table.
|
||||
import_effective_visibilities: EffectiveVisibilities<NameBinding<'a>>,
|
||||
import_effective_visibilities: EffectiveVisibilities<NameBinding<'ra>>,
|
||||
// It's possible to recalculate this at any point, but it's relatively expensive.
|
||||
current_private_vis: Visibility,
|
||||
changed: bool,
|
||||
|
@ -63,14 +63,14 @@ impl Resolver<'_, '_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
||||
impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
||||
/// Fills the `Resolver::effective_visibilities` table with public & exported items
|
||||
/// For now, this doesn't resolve macros (FIXME) and cannot resolve Impl, as we
|
||||
/// need access to a TyCtxt for that. Returns the set of ambiguous re-exports.
|
||||
pub(crate) fn compute_effective_visibilities<'c>(
|
||||
r: &'r mut Resolver<'a, 'tcx>,
|
||||
r: &'a mut Resolver<'ra, 'tcx>,
|
||||
krate: &'c Crate,
|
||||
) -> FxHashSet<NameBinding<'a>> {
|
||||
) -> FxHashSet<NameBinding<'ra>> {
|
||||
let mut visitor = EffectiveVisibilitiesVisitor {
|
||||
r,
|
||||
def_effective_visibilities: Default::default(),
|
||||
|
@ -127,7 +127,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
|||
// leading to it into the table. They are used by the `ambiguous_glob_reexports`
|
||||
// lint. For all bindings added to the table this way `is_ambiguity` returns true.
|
||||
let is_ambiguity =
|
||||
|binding: NameBinding<'a>, warn: bool| binding.ambiguity.is_some() && !warn;
|
||||
|binding: NameBinding<'ra>, warn: bool| binding.ambiguity.is_some() && !warn;
|
||||
let mut parent_id = ParentId::Def(module_id);
|
||||
let mut warn_ambiguity = binding.warn_ambiguity;
|
||||
while let NameBindingKind::Import { binding: nested_binding, .. } = binding.kind {
|
||||
|
@ -153,7 +153,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn effective_vis_or_private(&mut self, parent_id: ParentId<'a>) -> EffectiveVisibility {
|
||||
fn effective_vis_or_private(&mut self, parent_id: ParentId<'ra>) -> EffectiveVisibility {
|
||||
// Private nodes are only added to the table for caching, they could be added or removed at
|
||||
// any moment without consequences, so we don't set `changed` to true when adding them.
|
||||
*match parent_id {
|
||||
|
@ -190,7 +190,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn update_import(&mut self, binding: NameBinding<'a>, parent_id: ParentId<'a>) {
|
||||
fn update_import(&mut self, binding: NameBinding<'ra>, parent_id: ParentId<'ra>) {
|
||||
let nominal_vis = binding.vis.expect_local();
|
||||
let Some(cheap_private_vis) = self.may_update(nominal_vis, parent_id) else { return };
|
||||
let inherited_eff_vis = self.effective_vis_or_private(parent_id);
|
||||
|
@ -205,7 +205,12 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
fn update_def(&mut self, def_id: LocalDefId, nominal_vis: Visibility, parent_id: ParentId<'a>) {
|
||||
fn update_def(
|
||||
&mut self,
|
||||
def_id: LocalDefId,
|
||||
nominal_vis: Visibility,
|
||||
parent_id: ParentId<'ra>,
|
||||
) {
|
||||
let Some(cheap_private_vis) = self.may_update(nominal_vis, parent_id) else { return };
|
||||
let inherited_eff_vis = self.effective_vis_or_private(parent_id);
|
||||
let tcx = self.r.tcx;
|
||||
|
@ -224,8 +229,8 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'r, 'ast, 'tcx> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r, 'tcx> {
|
||||
fn visit_item(&mut self, item: &'ast ast::Item) {
|
||||
impl<'a, 'ra, 'tcx> Visitor<'a> for EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
||||
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||
let def_id = self.r.local_def_id(item.id);
|
||||
// Update effective visibilities of nested items.
|
||||
// If it's a mod, also make the visitor walk all of its items
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue