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

+1
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

+3-3
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

+2-2
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

+10-7
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

+1-1
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

+5-5
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

+1-1
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

+1-1
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

+3-3
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

+1-1
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);

src/librustc/lint/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ macro_rules! late_lint_methods {
8787
($macro:path, $args:tt, [$hir:tt]) => (
8888
$macro!($args, [$hir], [
8989
fn check_param(a: &$hir hir::Param);
90-
fn check_body(a: &$hir hir::Body);
91-
fn check_body_post(a: &$hir hir::Body);
90+
fn check_body(a: &$hir hir::Body<$hir>);
91+
fn check_body_post(a: &$hir hir::Body<$hir>);
9292
fn check_name(a: Span, b: ast::Name);
9393
fn check_crate(a: &$hir hir::Crate<$hir>);
9494
fn check_crate_post(a: &$hir hir::Crate<$hir>);
@@ -114,13 +114,13 @@ macro_rules! late_lint_methods {
114114
fn check_fn(
115115
a: hir::intravisit::FnKind<$hir>,
116116
b: &$hir hir::FnDecl,
117-
c: &$hir hir::Body,
117+
c: &$hir hir::Body<$hir>,
118118
d: Span,
119119
e: hir::HirId);
120120
fn check_fn_post(
121121
a: hir::intravisit::FnKind<$hir>,
122122
b: &$hir hir::FnDecl,
123-
c: &$hir hir::Body,
123+
c: &$hir hir::Body<$hir>,
124124
d: Span,
125125
e: hir::HirId
126126
);

src/librustc/middle/region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl<'tcx> ScopeTree {
715715
pub fn yield_in_scope_for_expr(&self,
716716
scope: Scope,
717717
expr_hir_id: hir::HirId,
718-
body: &'tcx hir::Body) -> Option<Span> {
718+
body: &'tcx hir::Body<'tcx>) -> Option<Span> {
719719
self.yield_in_scope(scope).and_then(|YieldData { span, expr_and_pat_count, .. }| {
720720
let mut visitor = ExprLocatorVisitor {
721721
hir_id: expr_hir_id,
@@ -1362,7 +1362,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
13621362
resolve_block(self, b);
13631363
}
13641364

1365-
fn visit_body(&mut self, body: &'tcx hir::Body) {
1365+
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
13661366
let body_id = body.id();
13671367
let owner_id = self.tcx.hir().body_owner(body_id);
13681368

@@ -1387,7 +1387,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
13871387

13881388
// The arguments and `self` are parented to the fn.
13891389
self.cx.var_parent = self.cx.parent.take();
1390-
for param in &body.params {
1390+
for param in body.params {
13911391
self.visit_pat(&param.pat);
13921392
}
13931393

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ fn signal_shadowing_problem(tcx: TyCtxt<'_>, name: ast::Name, orig: Original, sh
11671167

11681168
// Adds all labels in `b` to `ctxt.labels_in_fn`, signalling a warning
11691169
// if one of the label shadows a lifetime or another label.
1170-
fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
1170+
fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
11711171
struct GatherLabels<'a, 'tcx> {
11721172
tcx: TyCtxt<'tcx>,
11731173
scope: ScopeRef<'a>,

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
298298
cx: &LateContext<'_, '_>,
299299
fk: FnKind<'_>,
300300
_: &hir::FnDecl,
301-
_: &hir::Body,
301+
_: &hir::Body<'_>,
302302
_: Span,
303303
id: hir::HirId,
304304
) {

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fn construct_fn<'a, 'tcx, A>(
552552
abi: Abi,
553553
return_ty: Ty<'tcx>,
554554
return_ty_span: Span,
555-
body: &'tcx hir::Body,
555+
body: &'tcx hir::Body<'tcx>,
556556
) -> Body<'tcx>
557557
where
558558
A: Iterator<Item=ArgInfo<'tcx>>

src/librustc_mir/hair/pattern/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
7676
self.check_patterns(false, &loc.pat);
7777
}
7878

79-
fn visit_body(&mut self, body: &'tcx hir::Body) {
79+
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
8080
intravisit::walk_body(self, body);
8181

82-
for param in &body.params {
82+
for param in body.params {
8383
self.check_irrefutable(&param.pat, "function argument", None);
8484
self.check_patterns(false, &param.pat);
8585
}

src/librustc_passes/check_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ enum ConstKind {
7575
}
7676

7777
impl ConstKind {
78-
fn for_body(body: &hir::Body, hir_map: &Map<'_>) -> Option<Self> {
78+
fn for_body(body: &hir::Body<'_>, hir_map: &Map<'_>) -> Option<Self> {
7979
let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const();
8080

8181
let owner = hir_map.body_owner(body.id());
@@ -215,7 +215,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
215215
self.recurse_into(kind, |this| hir::intravisit::walk_anon_const(this, anon));
216216
}
217217

218-
fn visit_body(&mut self, body: &'tcx hir::Body) {
218+
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
219219
let kind = ConstKind::for_body(body, self.tcx.hir());
220220
self.recurse_into(kind, |this| hir::intravisit::walk_body(this, body));
221221
}

src/librustc_passes/liveness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn visit_fn<'tcx>(
371371

372372
let body = ir.tcx.hir().body(body_id);
373373

374-
for param in &body.params {
374+
for param in body.params {
375375
let is_shorthand = match param.pat.kind {
376376
rustc::hir::PatKind::Struct(..) => true,
377377
_ => false,
@@ -1463,8 +1463,8 @@ impl<'tcx> Liveness<'_, 'tcx> {
14631463
}
14641464
}
14651465

1466-
fn warn_about_unused_args(&self, body: &hir::Body, entry_ln: LiveNode) {
1467-
for p in &body.params {
1466+
fn warn_about_unused_args(&self, body: &hir::Body<'_>, entry_ln: LiveNode) {
1467+
for p in body.params {
14681468
self.check_unused_vars_in_pat(&p.pat, Some(entry_ln), |spans, hir_id, ln, var| {
14691469
if self.live_on_entry(ln, var).is_none() {
14701470
self.report_dead_assign(hir_id, spans, var, true);

0 commit comments

Comments
 (0)