Skip to content

Commit 26286c7

Browse files
committed
Auto merge of #66931 - cjgillot:hirene-preamble, r=eddyb
Allocate HIR on an arena 1/4 This PR is the first in a series of 4, aiming at allocating the HIR on an arena, as a memory optimisation. 1. This first PR lays the groundwork and migrates some low-hanging fruits. 2. The second PR will migrate `hir::Expr`, `hir::Pat` and related. 3. The third PR will migrate `hir::Ty` and related. 4. The final PR will be dedicated to eventual cleanups. In order to make the transition as gradual as possible, some lowering routines receive `Box`-allocated data and move it into the arena. This is a bit wasteful, but hopefully temporary. Nonetheless, special care should be taken to avoid double arena allocations. Work mentored by @Zoxc.
2 parents 3982d35 + baa49b2 commit 26286c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+856
-781
lines changed

src/librustc/arena.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ macro_rules! arena_types {
9393
rustc::hir::def_id::CrateNum
9494
>
9595
>,
96-
[few] hir_forest: rustc::hir::map::Forest,
9796
[few] diagnostic_items: rustc_data_structures::fx::FxHashMap<
9897
syntax::symbol::Symbol,
9998
rustc::hir::def_id::DefId,
@@ -123,6 +122,21 @@ macro_rules! arena_types {
123122
[few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>,
124123
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
125124
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc::hir::HirId, rustc::hir::Upvar>,
125+
126+
// HIR types
127+
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
128+
[] attribute: syntax::ast::Attribute,
129+
[few] global_asm: rustc::hir::GlobalAsm,
130+
[] fn_decl: rustc::hir::FnDecl,
131+
[] foreign_item: rustc::hir::ForeignItem<$tcx>,
132+
[] impl_item_ref: rustc::hir::ImplItemRef,
133+
[few] macro_def: rustc::hir::MacroDef<$tcx>,
134+
[] param: rustc::hir::Param,
135+
[] path: rustc::hir::Path,
136+
[] struct_field: rustc::hir::StructField<$tcx>,
137+
[] trait_item_ref: rustc::hir::TraitItemRef,
138+
[] ty: rustc::hir::Ty,
139+
[] variant: rustc::hir::Variant<$tcx>,
126140
], $tcx);
127141
)
128142
}

src/librustc/hir/check_attr.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use crate::hir::{self, HirId, HirVec, Attribute, Item, ItemKind, TraitItem, TraitItemKind};
7+
use crate::hir::{self, HirId, Attribute, Item, ItemKind, TraitItem, TraitItemKind};
88
use crate::hir::DUMMY_HIR_ID;
99
use crate::hir::def_id::DefId;
1010
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
@@ -86,7 +86,7 @@ impl Display for Target {
8686
}
8787

8888
impl Target {
89-
pub(crate) fn from_item(item: &Item) -> Target {
89+
pub(crate) fn from_item(item: &Item<'_>) -> Target {
9090
match item.kind {
9191
ItemKind::ExternCrate(..) => Target::ExternCrate,
9292
ItemKind::Use(..) => Target::Use,
@@ -107,7 +107,7 @@ impl Target {
107107
}
108108
}
109109

110-
fn from_trait_item(trait_item: &TraitItem) -> Target {
110+
fn from_trait_item(trait_item: &TraitItem<'_>) -> Target {
111111
match trait_item.kind {
112112
TraitItemKind::Const(..) => Target::AssocConst,
113113
TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => {
@@ -120,15 +120,15 @@ impl Target {
120120
}
121121
}
122122

123-
fn from_foreign_item(foreign_item: &hir::ForeignItem) -> Target {
123+
fn from_foreign_item(foreign_item: &hir::ForeignItem<'_>) -> Target {
124124
match foreign_item.kind {
125125
hir::ForeignItemKind::Fn(..) => Target::ForeignFn,
126126
hir::ForeignItemKind::Static(..) => Target::ForeignStatic,
127127
hir::ForeignItemKind::Type => Target::ForeignTy,
128128
}
129129
}
130130

131-
fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem) -> Target {
131+
fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
132132
match impl_item.kind {
133133
hir::ImplItemKind::Const(..) => Target::AssocConst,
134134
hir::ImplItemKind::Method(..) => {
@@ -158,10 +158,10 @@ impl CheckAttrVisitor<'tcx> {
158158
fn check_attributes(
159159
&self,
160160
hir_id: HirId,
161-
attrs: &HirVec<Attribute>,
161+
attrs: &'hir [Attribute],
162162
span: &Span,
163163
target: Target,
164-
item: Option<&Item>,
164+
item: Option<&Item<'_>>,
165165
) {
166166
let mut is_valid = true;
167167
for attr in attrs {
@@ -241,7 +241,7 @@ impl CheckAttrVisitor<'tcx> {
241241
fn check_track_caller(
242242
&self,
243243
attr_span: &Span,
244-
attrs: &HirVec<Attribute>,
244+
attrs: &'hir [Attribute],
245245
span: &Span,
246246
target: Target,
247247
) -> bool {
@@ -332,10 +332,10 @@ impl CheckAttrVisitor<'tcx> {
332332
/// Checks if the `#[repr]` attributes on `item` are valid.
333333
fn check_repr(
334334
&self,
335-
attrs: &HirVec<Attribute>,
335+
attrs: &'hir [Attribute],
336336
span: &Span,
337337
target: Target,
338-
item: Option<&Item>,
338+
item: Option<&Item<'_>>,
339339
) {
340340
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
341341
// ```
@@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> {
477477
}
478478
}
479479

480-
fn check_used(&self, attrs: &HirVec<Attribute>, target: Target) {
480+
fn check_used(&self, attrs: &'hir [Attribute], target: Target) {
481481
for attr in attrs {
482482
if attr.check_name(sym::used) && target != Target::Static {
483483
self.tcx.sess
@@ -492,25 +492,25 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
492492
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
493493
}
494494

495-
fn visit_item(&mut self, item: &'tcx Item) {
495+
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
496496
let target = Target::from_item(item);
497-
self.check_attributes(item.hir_id, &item.attrs, &item.span, target, Some(item));
497+
self.check_attributes(item.hir_id, item.attrs, &item.span, target, Some(item));
498498
intravisit::walk_item(self, item)
499499
}
500500

501-
fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem) {
501+
fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem<'tcx>) {
502502
let target = Target::from_trait_item(trait_item);
503503
self.check_attributes(trait_item.hir_id, &trait_item.attrs, &trait_item.span, target, None);
504504
intravisit::walk_trait_item(self, trait_item)
505505
}
506506

507-
fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem) {
507+
fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem<'tcx>) {
508508
let target = Target::from_foreign_item(f_item);
509509
self.check_attributes(f_item.hir_id, &f_item.attrs, &f_item.span, target, None);
510510
intravisit::walk_foreign_item(self, f_item)
511511
}
512512

513-
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
513+
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
514514
let target = Target::from_impl_item(self.tcx, impl_item);
515515
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
516516
intravisit::walk_impl_item(self, impl_item)
@@ -527,9 +527,9 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
527527
}
528528
}
529529

530-
fn is_c_like_enum(item: &Item) -> bool {
530+
fn is_c_like_enum(item: &Item<'_>) -> bool {
531531
if let ItemKind::Enum(ref def, _) = item.kind {
532-
for variant in &def.variants {
532+
for variant in def.variants {
533533
match variant.data {
534534
hir::VariantData::Unit(..) => { /* continue */ }
535535
_ => return false,

src/librustc/hir/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl CtorKind {
340340
}
341341
}
342342

343-
pub fn from_hir(vdata: &hir::VariantData) -> CtorKind {
343+
pub fn from_hir(vdata: &hir::VariantData<'_>) -> CtorKind {
344344
match *vdata {
345345
hir::VariantData::Tuple(..) => CtorKind::Fn,
346346
hir::VariantData::Unit(..) => CtorKind::Const,

0 commit comments

Comments
 (0)