Skip to content
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

Allocate HIR on an arena 1/4 #66931

Merged
merged 12 commits into from
Dec 22, 2019
Prev Previous commit
Next Next commit
Use Arena inside hir::ImplItem.
  • Loading branch information
cjgillot committed Dec 21, 2019
commit 5fec1ca0ff5727d1f4474f8dc3edf7c631baf712
4 changes: 2 additions & 2 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Target {
}
}

fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem) -> Target {
fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst,
hir::ImplItemKind::Method(..) => {
Expand Down Expand Up @@ -510,7 +510,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
intravisit::walk_foreign_item(self, f_item)
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
let target = Target::from_impl_item(self.tcx, impl_item);
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
intravisit::walk_impl_item(self, impl_item)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub trait Visitor<'v>: Sized {
fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) {
walk_trait_item_ref(self, ii)
}
fn visit_impl_item(&mut self, ii: &'v ImplItem) {
fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) {
walk_impl_item(self, ii)
}
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) {
Expand Down Expand Up @@ -893,14 +893,14 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
visitor.visit_defaultness(defaultness);
}

pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) {
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
// N.B., deliberately force a compilation error if/when new fields are added.
let ImplItem {
hir_id: _,
ident,
ref vis,
ref defaultness,
ref attrs,
attrs,
ref generics,
ref kind,
span: _,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/itemlikevisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use super::intravisit::Visitor;
pub trait ItemLikeVisitor<'hir> {
fn visit_item(&mut self, item: &'hir Item<'hir>);
fn visit_trait_item(&mut self, trait_item: &'hir TraitItem<'hir>);
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem);
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem<'hir>);
}

pub struct DeepVisitor<'v, V> {
Expand All @@ -73,7 +73,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V>
self.visitor.visit_trait_item(trait_item);
}

fn visit_impl_item(&mut self, impl_item: &'hir ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem<'hir>) {
self.visitor.visit_impl_item(impl_item);
}
}
Expand All @@ -82,7 +82,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V>
pub trait ParItemLikeVisitor<'hir> {
fn visit_item(&self, item: &'hir Item<'hir>);
fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>);
fn visit_impl_item(&self, impl_item: &'hir ImplItem);
fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>);
}

pub trait IntoVisitor<'hir> {
Expand All @@ -103,7 +103,7 @@ impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor<V>
self.0.into_visitor().visit_trait_item(trait_item);
}

fn visit_impl_item(&self, impl_item: &'hir ImplItem) {
fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>) {
self.0.into_visitor().visit_impl_item(impl_item);
}
}
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub struct LoweringContext<'a, 'hir: 'a> {
items: BTreeMap<hir::HirId, hir::Item<'hir>>,

trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem<'hir>>,
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>,
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem<'hir>>,
bodies: BTreeMap<hir::BodyId, hir::Body>,
exported_macros: Vec<hir::MacroDef<'hir>>,
non_exported_macro_attrs: Vec<ast::Attribute>,
Expand Down
10 changes: 6 additions & 4 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,14 @@ impl LoweringContext<'_, 'hir> {
self.expr(span, hir::ExprKind::Err, AttrVec::new())
}

fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem {
fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
let impl_item_def_id = self.resolver.definitions().local_def_id(i.id);

let (generics, kind) = match i.kind {
AssocItemKind::Const(ref ty, ref expr) => (
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::Const(
self.lower_ty(ty, ImplTraitContext::disallowed()),
self.arena.alloc(self.lower_ty(ty, ImplTraitContext::disallowed()).into_inner()),
self.lower_const_body(i.span, expr.as_deref()),
),
),
Expand All @@ -940,11 +940,13 @@ impl LoweringContext<'_, 'hir> {
let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
let kind = match ty {
None => {
hir::ImplItemKind::TyAlias(P(self.ty(i.span, hir::TyKind::Err)))
let ty = self.arena.alloc(self.ty(i.span, hir::TyKind::Err));
hir::ImplItemKind::TyAlias(ty)
}
Some(ty) => match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let ty = self.arena.alloc(ty.into_inner());
hir::ImplItemKind::TyAlias(ty)
}
Some(bs) => {
Expand All @@ -961,7 +963,7 @@ impl LoweringContext<'_, 'hir> {
hir::ImplItem {
hir_id: self.lower_node_id(i.id),
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
attrs: self.lower_attrs_arena(&i.attrs),
generics,
vis: self.lower_visibility(&i.vis, None),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl MaybeFnLike for ast::Item<'_> {
}
}

impl MaybeFnLike for ast::ImplItem {
impl MaybeFnLike for ast::ImplItem<'_> {
fn is_fn_like(&self) -> bool {
match self.kind {
ast::ImplItemKind::Method(..) => true,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
});
}

fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
debug_assert_eq!(ii.hir_id.owner,
self.definitions.opt_def_index(self.hir_to_node_id[&ii.hir_id]).unwrap());
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/hir_id_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
inner_visitor.check(i.hir_id, |this| intravisit::walk_trait_item(this, i));
}

fn visit_impl_item(&mut self, i: &'hir hir::ImplItem) {
fn visit_impl_item(&mut self, i: &'hir hir::ImplItem<'hir>) {
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
inner_visitor.check(i.hir_id, |this| intravisit::walk_impl_item(this, i));
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl<'hir> Map<'hir> {
self.forest.krate.trait_item(id)
}

pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem {
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
self.read(id.hir_id);

// N.B., intentionally bypass `self.forest.krate()` so that we
Expand Down Expand Up @@ -966,7 +966,7 @@ impl<'hir> Map<'hir> {
}
}

pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem {
pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem<'hir> {
match self.find(id) {
Some(Node::ImplItem(item)) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(id))
Expand Down Expand Up @@ -1253,7 +1253,7 @@ impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } }
impl Named for Variant { fn name(&self) -> Name { self.ident.name } }
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
impl Named for TraitItem<'_> { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem<'_> { fn name(&self) -> Name { self.ident.name } }

pub fn map_crate<'hir>(sess: &crate::session::Session,
cstore: &CrateStoreDyn,
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ pub struct Crate<'hir> {
pub items: BTreeMap<HirId, Item<'hir>>,

pub trait_items: BTreeMap<TraitItemId, TraitItem<'hir>>,
pub impl_items: BTreeMap<ImplItemId, ImplItem>,
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
pub bodies: BTreeMap<BodyId, Body>,
pub trait_impls: BTreeMap<DefId, Vec<HirId>>,

Expand All @@ -783,7 +783,7 @@ impl Crate<'hir> {
&self.trait_items[&id]
}

pub fn impl_item(&self, id: ImplItemId) -> &ImplItem {
pub fn impl_item(&self, id: ImplItemId) -> &ImplItem<'hir> {
&self.impl_items[&id]
}

Expand Down Expand Up @@ -1938,27 +1938,27 @@ pub struct ImplItemId {

/// Represents anything within an `impl` block.
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct ImplItem {
pub struct ImplItem<'hir> {
pub ident: Ident,
pub hir_id: HirId,
pub vis: Visibility,
pub defaultness: Defaultness,
pub attrs: HirVec<Attribute>,
pub attrs: &'hir [Attribute],
pub generics: Generics,
pub kind: ImplItemKind,
pub kind: ImplItemKind<'hir>,
pub span: Span,
}

/// Represents various kinds of content within an `impl`.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum ImplItemKind {
pub enum ImplItemKind<'hir> {
/// An associated constant of the given type, set to the constant result
/// of the expression.
Const(P<Ty>, BodyId),
Const(&'hir Ty, BodyId),
/// A method implementation with the given signature and body.
Method(FnSig, BodyId),
/// An associated type.
TyAlias(P<Ty>),
TyAlias(&'hir Ty),
/// An associated `type = impl Trait`.
OpaqueTy(GenericBounds),
}
Expand Down Expand Up @@ -2790,7 +2790,7 @@ pub enum Node<'hir> {
Item(&'hir Item<'hir>),
ForeignItem(&'hir ForeignItem<'hir>),
TraitItem(&'hir TraitItem<'hir>),
ImplItem(&'hir ImplItem),
ImplItem(&'hir ImplItem<'hir>),
Variant(&'hir Variant),
Field(&'hir StructField),
AnonConst(&'hir AnonConst),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ impl<'a> State<'a> {
self.ann.post(self, AnnNode::SubItem(ti.hir_id))
}

pub fn print_impl_item(&mut self, ii: &hir::ImplItem) {
pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
self.ann.pre(self, AnnNode::SubItem(ii.hir_id));
self.hardbreak_if_not_bol();
self.maybe_print_comment(ii.span.lo());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem<'_> {
}


impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::ImplItem {
hir_id: _,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

fn impl_item_scope_tag(item: &hir::ImplItem) -> &'static str {
fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
match item.kind {
hir::ImplItemKind::Method(..) => "method body",
hir::ImplItemKind::Const(..)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ for LateContextAndPass<'a, 'tcx, T> {
self.context.generics = generics;
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
let generics = self.context.generics.take();
self.context.generics = Some(&impl_item.generics);
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |cx| {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ macro_rules! late_lint_methods {
);
fn check_trait_item(a: &$hir hir::TraitItem<$hir>);
fn check_trait_item_post(a: &$hir hir::TraitItem<$hir>);
fn check_impl_item(a: &$hir hir::ImplItem);
fn check_impl_item_post(a: &$hir hir::ImplItem);
fn check_impl_item(a: &$hir hir::ImplItem<$hir>);
fn check_impl_item_post(a: &$hir hir::ImplItem<$hir>);
fn check_struct_def(a: &$hir hir::VariantData);
fn check_struct_def_post(a: &$hir hir::VariantData);
fn check_struct_field(a: &$hir hir::StructField);
Expand Down Expand Up @@ -655,7 +655,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
});
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| {
intravisit::walk_impl_item(builder, impl_item);
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/diagnostic_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
self.observe_item(&trait_item.attrs, trait_item.hir_id);
}

fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
self.observe_item(&impl_item.attrs, impl_item.hir_id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
// At present, lang items are always items, not trait items.
}

fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
// At present, lang items are always items, not impl items.
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: Codegen

fn method_might_be_inlined(
tcx: TyCtxt<'_>,
impl_item: &hir::ImplItem,
impl_item: &hir::ImplItem<'_>,
impl_src: DefId,
) -> bool {
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id());
Expand Down Expand Up @@ -389,7 +389,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx

fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}

fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
// processed in visit_item above
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
use self::hir::ImplItemKind::*;
match impl_item.kind {
Method(ref sig, _) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
});
}

fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
let kind = if self.in_trait_impl {
AnnotationKind::Prohibited
} else {
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
intravisit::walk_trait_item(self, ti);
}

fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
let impl_def_id = self.tcx.hir().local_def_id(
self.tcx.hir().get_parent_item(ii.hir_id));
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/symbol_names_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> {
self.process_attrs(trait_item.hir_id);
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
self.process_attrs(impl_item.hir_id);
}
}
2 changes: 1 addition & 1 deletion src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> {
intravisit::walk_trait_item(self, trait_item);
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
self.process_attrs(impl_item.hir_id, &impl_item.attrs);
intravisit::walk_impl_item(self, impl_item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
self.check_item(item.hir_id, item.span);
}

fn visit_impl_item(&mut self, item: &hir::ImplItem) {
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
self.check_item(item.hir_id, item.span);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/proc_macro_decls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'v> ItemLikeVisitor<'v> for Finder {
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {
}

fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}

Expand Down
Loading