Skip to content

Commit 9694ab9

Browse files
committed
Use Arena inside hir::Body.
1 parent 42c03e4 commit 9694ab9

File tree

24 files changed

+69
-65
lines changed

24 files changed

+69
-65
lines changed

src/librustc/arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ macro_rules! arena_types {
130130
[] foreign_item: rustc::hir::ForeignItem<$tcx>,
131131
[] impl_item_ref: rustc::hir::ImplItemRef,
132132
[] macro_def: rustc::hir::MacroDef<$tcx>,
133+
[] param: rustc::hir::Param,
133134
[] path: rustc::hir::Path,
134135
[] struct_field: rustc::hir::StructField<$tcx>,
135136
[] trait_item_ref: rustc::hir::TraitItemRef,

src/librustc/hir/intravisit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub trait Visitor<'v>: Sized {
222222
walk_item(self, i)
223223
}
224224

225-
fn visit_body(&mut self, b: &'v Body) {
225+
fn visit_body(&mut self, b: &'v Body<'v>) {
226226
walk_body(self, b);
227227
}
228228

@@ -401,8 +401,8 @@ pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hi
401401
}
402402
}
403403

404-
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) {
405-
walk_list!(visitor, visit_param, &body.params);
404+
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
405+
walk_list!(visitor, visit_param, body.params);
406406
visitor.visit_expr(&body.value);
407407
}
408408

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub struct LoweringContext<'a, 'hir: 'a> {
9999

100100
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem<'hir>>,
101101
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem<'hir>>,
102-
bodies: BTreeMap<hir::BodyId, hir::Body>,
102+
bodies: BTreeMap<hir::BodyId, hir::Body<'hir>>,
103103
exported_macros: Vec<hir::MacroDef<'hir>>,
104104
non_exported_macro_attrs: Vec<ast::Attribute>,
105105

@@ -3428,7 +3428,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
34283428
}
34293429
}
34303430

3431-
fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body>) -> Vec<hir::BodyId> {
3431+
fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body<'hir>>) -> Vec<hir::BodyId> {
34323432
// Sorting by span ensures that we get things in order within a
34333433
// file, and also puts the files in a sensible order.
34343434
let mut body_ids: Vec<_> = bodies.keys().cloned().collect();

src/librustc/hir/lowering/item.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::ImplTraitTypeIdVisitor;
55
use super::AnonymousLifetimeMode;
66
use super::ParamMode;
77

8-
use crate::hir::{self, HirVec};
8+
use crate::hir;
99
use crate::hir::ptr::P;
1010
use crate::hir::def_id::DefId;
1111
use crate::hir::def::{Res, DefKind};
@@ -107,7 +107,7 @@ impl<'a, 'lowering, 'hir> Visitor<'a> for ItemLowerer<'a, 'lowering, 'hir> {
107107
}
108108
}
109109

110-
impl LoweringContext<'_, 'hir> {
110+
impl<'hir> LoweringContext<'_, 'hir> {
111111
// Same as the method above, but accepts `hir::GenericParam`s
112112
// instead of `ast::GenericParam`s.
113113
// This should only be used with generics that have already had their
@@ -1052,7 +1052,7 @@ impl LoweringContext<'_, 'hir> {
10521052
}
10531053
}
10541054

1055-
fn record_body(&mut self, params: HirVec<hir::Param>, value: hir::Expr) -> hir::BodyId {
1055+
fn record_body(&mut self, params: &'hir [hir::Param], value: hir::Expr) -> hir::BodyId {
10561056
let body = hir::Body {
10571057
generator_kind: self.generator_kind,
10581058
params,
@@ -1065,7 +1065,7 @@ impl LoweringContext<'_, 'hir> {
10651065

10661066
fn lower_body(
10671067
&mut self,
1068-
f: impl FnOnce(&mut LoweringContext<'_, '_>) -> (HirVec<hir::Param>, hir::Expr),
1068+
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param], hir::Expr),
10691069
) -> hir::BodyId {
10701070
let prev_gen_kind = self.generator_kind.take();
10711071
let (parameters, result) = f(self);
@@ -1089,7 +1089,9 @@ impl LoweringContext<'_, 'hir> {
10891089
body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr,
10901090
) -> hir::BodyId {
10911091
self.lower_body(|this| (
1092-
decl.inputs.iter().map(|x| this.lower_param(x)).collect(),
1092+
this.arena.alloc_from_iter(
1093+
decl.inputs.iter().map(|x| this.lower_param(x))
1094+
),
10931095
body(this),
10941096
))
10951097
}
@@ -1111,7 +1113,7 @@ impl LoweringContext<'_, 'hir> {
11111113
}
11121114

11131115
pub(super) fn lower_const_body(&mut self, span: Span, expr: Option<&Expr>) -> hir::BodyId {
1114-
self.lower_body(|this| (hir_vec![], match expr {
1116+
self.lower_body(|this| (&[], match expr {
11151117
Some(expr) => this.lower_expr(expr),
11161118
None => this.expr_err(span),
11171119
}))
@@ -1299,7 +1301,8 @@ impl LoweringContext<'_, 'hir> {
12991301
);
13001302
this.expr_block(P(body), AttrVec::new())
13011303
});
1302-
(HirVec::from(parameters), this.expr(body_span, async_expr, AttrVec::new()))
1304+
1305+
(this.arena.alloc_from_iter(parameters), this.expr(body_span, async_expr, AttrVec::new()))
13031306
})
13041307
}
13051308

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'hir> Map<'hir> {
459459
self.forest.krate.impl_item(id)
460460
}
461461

462-
pub fn body(&self, id: BodyId) -> &'hir Body {
462+
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
463463
self.read(id.hir_id);
464464

465465
// N.B., intentionally bypass `self.forest.krate()` so that we

src/librustc/hir/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ pub struct Crate<'hir> {
760760

761761
pub trait_items: BTreeMap<TraitItemId, TraitItem<'hir>>,
762762
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
763-
pub bodies: BTreeMap<BodyId, Body>,
763+
pub bodies: BTreeMap<BodyId, Body<'hir>>,
764764
pub trait_impls: BTreeMap<DefId, Vec<HirId>>,
765765

766766
/// A list of the body ids written out in the order in which they
@@ -787,7 +787,7 @@ impl Crate<'hir> {
787787
&self.impl_items[&id]
788788
}
789789

790-
pub fn body(&self, id: BodyId) -> &Body {
790+
pub fn body(&self, id: BodyId) -> &Body<'hir> {
791791
&self.bodies[&id]
792792
}
793793
}
@@ -1353,13 +1353,13 @@ pub struct BodyId {
13531353
/// All bodies have an **owner**, which can be accessed via the HIR
13541354
/// map using `body_owner_def_id()`.
13551355
#[derive(RustcEncodable, RustcDecodable, Debug)]
1356-
pub struct Body {
1357-
pub params: HirVec<Param>,
1356+
pub struct Body<'hir> {
1357+
pub params: &'hir [Param],
13581358
pub value: Expr,
13591359
pub generator_kind: Option<GeneratorKind>,
13601360
}
13611361

1362-
impl Body {
1362+
impl Body<'hir> {
13631363
pub fn id(&self) -> BodyId {
13641364
BodyId {
13651365
hir_id: self.value.hir_id,

src/librustc/ich/hcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>);
6161
impl<'tcx> BodyResolver<'tcx> {
6262
/// Returns a reference to the `hir::Body` with the given `BodyId`.
6363
/// **Does not do any tracking**; use carefully.
64-
fn body(self, id: hir::BodyId) -> &'tcx hir::Body {
64+
fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> {
6565
self.0.body(id)
6666
}
6767
}

src/librustc/ich/impls_hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Item<'_> {
266266
}
267267
}
268268

269-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Body {
269+
impl<'a> HashStable<StableHashingContext<'a>> for hir::Body<'_> {
270270
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
271271
let hir::Body {
272272
params,

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> {
8383
intravisit::walk_local(self, local);
8484
}
8585

86-
fn visit_body(&mut self, body: &'tcx Body) {
87-
for param in &body.params {
86+
fn visit_body(&mut self, body: &'tcx Body<'tcx>) {
87+
for param in body.params {
8888
if let (None, Some(ty)) = (
8989
self.found_arg_pattern,
9090
self.node_matches_type(param.hir_id),
@@ -113,7 +113,7 @@ fn closure_return_type_suggestion(
113113
span: Span,
114114
err: &mut DiagnosticBuilder<'_>,
115115
output: &FunctionRetTy,
116-
body: &Body,
116+
body: &Body<'_>,
117117
descr: &str,
118118
name: &str,
119119
ret: &str,

src/librustc/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ for LateContextAndPass<'a, 'tcx, T> {
924924
});
925925
}
926926

927-
fn visit_body(&mut self, body: &'tcx hir::Body) {
927+
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
928928
lint_callback!(self, check_body, body);
929929
hir_visit::walk_body(self, body);
930930
lint_callback!(self, check_body_post, body);

0 commit comments

Comments
 (0)