Skip to content

Commit

Permalink
Unrolled build for rust-lang#130208
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#130208 - nnethercote:rslv-lifetime, r=petrochenkov

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 `'rslv`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`rslv` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`.

r? ``@petrochenkov``
cc ``@oli-obk``
  • Loading branch information
rust-timer authored Sep 12, 2024
2 parents 8c0ec05 + d4fc76c commit 820de58
Show file tree
Hide file tree
Showing 11 changed files with 481 additions and 470 deletions.
92 changes: 46 additions & 46 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ use crate::{

type Res = def::Res<NodeId>;

impl<'a, Id: Into<DefId>> ToNameBinding<'a>
for (Module<'a>, ty::Visibility<Id>, Span, LocalExpnId)
impl<'ra, Id: Into<DefId>> ToNameBinding<'ra>
for (Module<'ra>, ty::Visibility<Id>, Span, LocalExpnId)
{
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> {
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> {
arenas.alloc_name_binding(NameBindingData {
kind: NameBindingKind::Module(self.0),
ambiguity: None,
Expand All @@ -54,8 +54,8 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a>
}
}

impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span, LocalExpnId) {
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> {
impl<'ra, Id: Into<DefId>> ToNameBinding<'ra> for (Res, ty::Visibility<Id>, Span, LocalExpnId) {
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> {
arenas.alloc_name_binding(NameBindingData {
kind: NameBindingKind::Res(self.0),
ambiguity: None,
Expand All @@ -67,12 +67,12 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span,
}
}

impl<'a, 'tcx> Resolver<'a, 'tcx> {
impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
/// otherwise, reports an error.
pub(crate) fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
pub(crate) fn define<T>(&mut self, parent: Module<'ra>, ident: Ident, ns: Namespace, def: T)
where
T: ToNameBinding<'a>,
T: ToNameBinding<'ra>,
{
let binding = def.to_name_binding(self.arenas);
let key = self.new_disambiguated_key(ident, ns);
Expand All @@ -97,7 +97,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
/// Reachable macros with block module parents exist due to `#[macro_export] macro_rules!`,
/// but they cannot use def-site hygiene, so the assumption holds
/// (<https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508>).
pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'a> {
pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'ra> {
loop {
match self.get_module(def_id) {
Some(module) => return module,
Expand All @@ -106,14 +106,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}

pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'a> {
pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'ra> {
self.get_module(def_id).expect("argument `DefId` is not a module")
}

/// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum,
/// or trait), then this function returns that module's resolver representation, otherwise it
/// returns `None`.
pub(crate) fn get_module(&mut self, def_id: DefId) -> Option<Module<'a>> {
pub(crate) fn get_module(&mut self, def_id: DefId) -> Option<Module<'ra>> {
if let module @ Some(..) = self.module_map.get(&def_id) {
return module.copied();
}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
None
}

pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {
pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'ra> {
match expn_id.expn_data().macro_def_id {
Some(def_id) => self.macro_def_scope(def_id),
None => expn_id
Expand All @@ -153,7 +153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}

pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'a> {
pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'ra> {
if let Some(id) = def_id.as_local() {
self.local_macro_def_scopes[&id]
} else {
Expand Down Expand Up @@ -186,15 +186,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
pub(crate) fn build_reduced_graph(
&mut self,
fragment: &AstFragment,
parent_scope: ParentScope<'a>,
) -> MacroRulesScopeRef<'a> {
parent_scope: ParentScope<'ra>,
) -> MacroRulesScopeRef<'ra> {
collect_definitions(self, fragment, parent_scope.expansion);
let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
fragment.visit_with(&mut visitor);
visitor.parent_scope.macro_rules
}

pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'ra>) {
for child in self.tcx.module_children(module.def_id()) {
let parent_scope = ParentScope::module(module, self);
self.build_reduced_graph_for_external_crate_res(child, parent_scope)
Expand All @@ -205,7 +205,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fn build_reduced_graph_for_external_crate_res(
&mut self,
child: &ModChild,
parent_scope: ParentScope<'a>,
parent_scope: ParentScope<'ra>,
) {
let parent = parent_scope.module;
let ModChild { ident, res, vis, ref reexport_chain } = *child;
Expand Down Expand Up @@ -273,18 +273,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}

struct BuildReducedGraphVisitor<'a, 'b, 'tcx> {
r: &'b mut Resolver<'a, 'tcx>,
parent_scope: ParentScope<'a>,
struct BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
r: &'a mut Resolver<'ra, 'tcx>,
parent_scope: ParentScope<'ra>,
}

impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for BuildReducedGraphVisitor<'a, '_, 'tcx> {
fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> {
impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for BuildReducedGraphVisitor<'_, 'ra, 'tcx> {
fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> {
self.r
}
}

impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
fn res(&self, def_id: impl Into<DefId>) -> Res {
let def_id = def_id.into();
Res::Def(self.r.tcx.def_kind(def_id), def_id)
Expand Down Expand Up @@ -424,7 +424,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
fn add_import(
&mut self,
module_path: Vec<Segment>,
kind: ImportKind<'a>,
kind: ImportKind<'ra>,
span: Span,
item: &ast::Item,
root_span: Span,
Expand Down Expand Up @@ -752,7 +752,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
}

/// Constructs the reduced graph for one item.
fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
fn build_reduced_graph_for_item(&mut self, item: &'a Item) {
let parent_scope = &self.parent_scope;
let parent = parent_scope.module;
let expansion = parent_scope.expansion;
Expand Down Expand Up @@ -918,7 +918,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
item: &Item,
local_def_id: LocalDefId,
vis: ty::Visibility,
parent: Module<'a>,
parent: Module<'ra>,
) {
let ident = item.ident;
let sp = item.span;
Expand Down Expand Up @@ -1040,7 +1040,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
fn add_macro_use_binding(
&mut self,
name: Symbol,
binding: NameBinding<'a>,
binding: NameBinding<'ra>,
span: Span,
allow_shadowing: bool,
) {
Expand All @@ -1050,7 +1050,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
}

/// Returns `true` if we should consider the underlying `extern crate` to be used.
fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool {
fn process_macro_use_imports(&mut self, item: &Item, module: Module<'ra>) -> bool {
let mut import_all = None;
let mut single_imports = Vec::new();
for attr in &item.attrs {
Expand Down Expand Up @@ -1188,7 +1188,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {

/// Visit invocation in context in which it can emit a named item (possibly `macro_rules`)
/// directly into its parent scope's module.
fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'a> {
fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'ra> {
let invoc_id = self.visit_invoc(id);
self.parent_scope.module.unexpanded_invocations.borrow_mut().insert(invoc_id);
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Invocation(invoc_id))
Expand Down Expand Up @@ -1221,7 +1221,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
}
}

fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> {
fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'ra> {
let parent_scope = self.parent_scope;
let expansion = parent_scope.expansion;
let feed = self.r.feed(item.id);
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {

macro_rules! method {
($visit:ident: $ty:ty, $invoc:path, $walk:ident) => {
fn $visit(&mut self, node: &'b $ty) {
fn $visit(&mut self, node: &'a $ty) {
if let $invoc(..) = node.kind {
self.visit_invoc(node.id);
} else {
Expand All @@ -1318,12 +1318,12 @@ macro_rules! method {
};
}

impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
method!(visit_expr: ast::Expr, ast::ExprKind::MacCall, walk_expr);
method!(visit_pat: ast::Pat, ast::PatKind::MacCall, walk_pat);
method!(visit_ty: ast::Ty, ast::TyKind::MacCall, walk_ty);

fn visit_item(&mut self, item: &'b Item) {
fn visit_item(&mut self, item: &'a Item) {
let orig_module_scope = self.parent_scope.module;
self.parent_scope.macro_rules = match item.kind {
ItemKind::MacroDef(..) => {
Expand Down Expand Up @@ -1357,15 +1357,15 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
self.parent_scope.module = orig_module_scope;
}

fn visit_stmt(&mut self, stmt: &'b ast::Stmt) {
fn visit_stmt(&mut self, stmt: &'a ast::Stmt) {
if let ast::StmtKind::MacCall(..) = stmt.kind {
self.parent_scope.macro_rules = self.visit_invoc_in_module(stmt.id);
} else {
visit::walk_stmt(self, stmt);
}
}

fn visit_foreign_item(&mut self, foreign_item: &'b ForeignItem) {
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
if let ForeignItemKind::MacCall(_) = foreign_item.kind {
self.visit_invoc_in_module(foreign_item.id);
return;
Expand All @@ -1375,7 +1375,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
visit::walk_item(self, foreign_item);
}

fn visit_block(&mut self, block: &'b Block) {
fn visit_block(&mut self, block: &'a Block) {
let orig_current_module = self.parent_scope.module;
let orig_current_macro_rules_scope = self.parent_scope.macro_rules;
self.build_reduced_graph_for_block(block);
Expand All @@ -1384,7 +1384,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
self.parent_scope.macro_rules = orig_current_macro_rules_scope;
}

fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) {
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
if let AssocItemKind::MacCall(_) = item.kind {
match ctxt {
AssocCtxt::Trait => {
Expand Down Expand Up @@ -1440,7 +1440,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
visit::walk_assoc_item(self, item, ctxt);
}

fn visit_attribute(&mut self, attr: &'b ast::Attribute) {
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
if !attr.is_doc_comment() && attr::is_builtin_attr(attr) {
self.r
.builtin_attrs
Expand All @@ -1449,47 +1449,47 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
visit::walk_attribute(self, attr);
}

fn visit_arm(&mut self, arm: &'b ast::Arm) {
fn visit_arm(&mut self, arm: &'a ast::Arm) {
if arm.is_placeholder {
self.visit_invoc(arm.id);
} else {
visit::walk_arm(self, arm);
}
}

fn visit_expr_field(&mut self, f: &'b ast::ExprField) {
fn visit_expr_field(&mut self, f: &'a ast::ExprField) {
if f.is_placeholder {
self.visit_invoc(f.id);
} else {
visit::walk_expr_field(self, f);
}
}

fn visit_pat_field(&mut self, fp: &'b ast::PatField) {
fn visit_pat_field(&mut self, fp: &'a ast::PatField) {
if fp.is_placeholder {
self.visit_invoc(fp.id);
} else {
visit::walk_pat_field(self, fp);
}
}

fn visit_generic_param(&mut self, param: &'b ast::GenericParam) {
fn visit_generic_param(&mut self, param: &'a ast::GenericParam) {
if param.is_placeholder {
self.visit_invoc(param.id);
} else {
visit::walk_generic_param(self, param);
}
}

fn visit_param(&mut self, p: &'b ast::Param) {
fn visit_param(&mut self, p: &'a ast::Param) {
if p.is_placeholder {
self.visit_invoc(p.id);
} else {
visit::walk_param(self, p);
}
}

fn visit_field_def(&mut self, sf: &'b ast::FieldDef) {
fn visit_field_def(&mut self, sf: &'a ast::FieldDef) {
if sf.is_placeholder {
self.visit_invoc(sf.id);
} else {
Expand All @@ -1501,7 +1501,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {

// Constructs the reduced graph for one variant. Variants exist in the
// type and value namespaces.
fn visit_variant(&mut self, variant: &'b ast::Variant) {
fn visit_variant(&mut self, variant: &'a ast::Variant) {
if variant.is_placeholder {
self.visit_invoc_in_module(variant.id);
return;
Expand Down Expand Up @@ -1542,7 +1542,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
visit::walk_variant(self, variant);
}

fn visit_crate(&mut self, krate: &'b ast::Crate) {
fn visit_crate(&mut self, krate: &'a ast::Crate) {
if krate.is_placeholder {
self.visit_invoc_in_module(krate.id);
} else {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl UnusedImport {
}
}

struct UnusedImportCheckVisitor<'a, 'b, 'tcx> {
r: &'a mut Resolver<'b, 'tcx>,
struct UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
r: &'a mut Resolver<'ra, 'tcx>,
/// All the (so far) unused imports, grouped path list
unused_imports: FxIndexMap<ast::NodeId, UnusedImport>,
extern_crate_items: Vec<ExternCrateToLint>,
Expand All @@ -78,7 +78,7 @@ struct ExternCrateToLint {
renames: bool,
}

impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
// We have information about whether `use` (import) items are actually
// used now. If an import is not used at all, we signal a lint error.
fn check_import(&mut self, id: ast::NodeId) {
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
}
}

impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
impl<'a, 'ra, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
fn visit_item(&mut self, item: &'a ast::Item) {
match item.kind {
// Ignore is_public import statements because there's no way to be sure
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ pub(crate) fn collect_definitions(
}

/// Creates `DefId`s for nodes in the AST.
struct DefCollector<'a, 'b, 'tcx> {
resolver: &'a mut Resolver<'b, 'tcx>,
struct DefCollector<'a, 'ra, 'tcx> {
resolver: &'a mut Resolver<'ra, 'tcx>,
parent_def: LocalDefId,
impl_trait_context: ImplTraitContext,
in_attr: bool,
expansion: LocalExpnId,
}

impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
fn create_def(
&mut self,
node_id: NodeId,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
}
}

impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
fn visit_item(&mut self, i: &'a Item) {
// Pick the def data. This need not be unique, but the more
// information we encapsulate into, the better
Expand Down
Loading

0 comments on commit 820de58

Please sign in to comment.