Skip to content

Commit 5d55009

Browse files
authored
Rollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco
Improve HIR stats #100398 improve the AST stats collection done by `-Zhir-stats`. This PR does the same for HIR stats collection. r? `@davidtwco`
2 parents 406e03f + f26fdce commit 5d55009

File tree

17 files changed

+466
-264
lines changed

17 files changed

+466
-264
lines changed

compiler/rustc_ast/src/ast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3045,13 +3045,16 @@ mod size_asserts {
30453045
static_assert_size!(Fn, 192);
30463046
static_assert_size!(ForeignItem, 96);
30473047
static_assert_size!(ForeignItemKind, 24);
3048+
static_assert_size!(GenericArg, 24);
30483049
static_assert_size!(GenericBound, 88);
30493050
static_assert_size!(Generics, 72);
30503051
static_assert_size!(Impl, 200);
30513052
static_assert_size!(Item, 184);
30523053
static_assert_size!(ItemKind, 112);
30533054
static_assert_size!(Lit, 48);
30543055
static_assert_size!(LitKind, 24);
3056+
static_assert_size!(Local, 72);
3057+
static_assert_size!(Param, 40);
30553058
static_assert_size!(Pat, 120);
30563059
static_assert_size!(PatKind, 96);
30573060
static_assert_size!(Path, 40);

compiler/rustc_ast_lowering/src/asm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
155155
let op = match *op {
156156
InlineAsmOperand::In { reg, ref expr } => hir::InlineAsmOperand::In {
157157
reg: lower_reg(reg),
158-
expr: self.lower_expr_mut(expr),
158+
expr: self.lower_expr(expr),
159159
},
160160
InlineAsmOperand::Out { reg, late, ref expr } => hir::InlineAsmOperand::Out {
161161
reg: lower_reg(reg),
162162
late,
163-
expr: expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
163+
expr: expr.as_ref().map(|expr| self.lower_expr(expr)),
164164
},
165165
InlineAsmOperand::InOut { reg, late, ref expr } => {
166166
hir::InlineAsmOperand::InOut {
167167
reg: lower_reg(reg),
168168
late,
169-
expr: self.lower_expr_mut(expr),
169+
expr: self.lower_expr(expr),
170170
}
171171
}
172172
InlineAsmOperand::SplitInOut { reg, late, ref in_expr, ref out_expr } => {
173173
hir::InlineAsmOperand::SplitInOut {
174174
reg: lower_reg(reg),
175175
late,
176-
in_expr: self.lower_expr_mut(in_expr),
177-
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
176+
in_expr: self.lower_expr(in_expr),
177+
out_expr: out_expr.as_ref().map(|expr| self.lower_expr(expr)),
178178
}
179179
}
180180
InlineAsmOperand::Const { ref anon_const } => {

compiler/rustc_ast_lowering/src/item.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
120120
self.with_lctx(CRATE_NODE_ID, |lctx| {
121121
let module = lctx.lower_mod(&c.items, &c.spans);
122122
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
123-
hir::OwnerNode::Crate(lctx.arena.alloc(module))
123+
hir::OwnerNode::Crate(module)
124124
})
125125
}
126126

@@ -158,14 +158,18 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
158158
}
159159

160160
impl<'hir> LoweringContext<'_, 'hir> {
161-
pub(super) fn lower_mod(&mut self, items: &[P<Item>], spans: &ModSpans) -> hir::Mod<'hir> {
162-
hir::Mod {
161+
pub(super) fn lower_mod(
162+
&mut self,
163+
items: &[P<Item>],
164+
spans: &ModSpans,
165+
) -> &'hir hir::Mod<'hir> {
166+
self.arena.alloc(hir::Mod {
163167
spans: hir::ModSpans {
164168
inner_span: self.lower_span(spans.inner_span),
165169
inject_use_span: self.lower_span(spans.inject_use_span),
166170
},
167171
item_ids: self.arena.alloc_from_iter(items.iter().flat_map(|x| self.lower_item_ref(x))),
168-
}
172+
})
169173
}
170174

171175
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
@@ -947,7 +951,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
947951
params: &'hir [hir::Param<'hir>],
948952
value: hir::Expr<'hir>,
949953
) -> hir::BodyId {
950-
let body = hir::Body { generator_kind: self.generator_kind, params, value };
954+
let body = hir::Body {
955+
generator_kind: self.generator_kind,
956+
params,
957+
value: self.arena.alloc(value),
958+
};
951959
let id = body.id();
952960
debug_assert_eq!(id.hir_id.owner, self.current_hir_id_owner);
953961
self.bodies.push((id.hir_id.local_id, self.arena.alloc(body)));

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11551155
}
11561156
_ => {}
11571157
}
1158-
GenericArg::Type(self.lower_ty_direct(&ty, itctx))
1158+
GenericArg::Type(self.lower_ty(&ty, itctx))
11591159
}
11601160
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
11611161
value: self.lower_anon_const(&ct),

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
358358
}
359359
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
360360
};
361-
let args = smallvec![GenericArg::Type(self.ty_tup(*inputs_span, inputs))];
361+
let args = smallvec![GenericArg::Type(self.arena.alloc(self.ty_tup(*inputs_span, inputs)))];
362362
let binding = self.output_ty_binding(output_ty.span, output_ty);
363363
(
364364
GenericArgsCtor {

compiler/rustc_hir/src/hir.rs

+36-20
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl InferArg {
265265
#[derive(Debug, HashStable_Generic)]
266266
pub enum GenericArg<'hir> {
267267
Lifetime(Lifetime),
268-
Type(Ty<'hir>),
268+
Type(&'hir Ty<'hir>),
269269
Const(ConstArg),
270270
Infer(InferArg),
271271
}
@@ -280,7 +280,7 @@ impl GenericArg<'_> {
280280
}
281281
}
282282

283-
pub fn id(&self) -> HirId {
283+
pub fn hir_id(&self) -> HirId {
284284
match self {
285285
GenericArg::Lifetime(l) => l.hir_id,
286286
GenericArg::Type(t) => t.hir_id,
@@ -1438,7 +1438,7 @@ pub struct BodyId {
14381438
#[derive(Debug, HashStable_Generic)]
14391439
pub struct Body<'hir> {
14401440
pub params: &'hir [Param<'hir>],
1441-
pub value: Expr<'hir>,
1441+
pub value: &'hir Expr<'hir>,
14421442
pub generator_kind: Option<GeneratorKind>,
14431443
}
14441444

@@ -2561,23 +2561,23 @@ pub enum TyKind<'hir> {
25612561
pub enum InlineAsmOperand<'hir> {
25622562
In {
25632563
reg: InlineAsmRegOrRegClass,
2564-
expr: Expr<'hir>,
2564+
expr: &'hir Expr<'hir>,
25652565
},
25662566
Out {
25672567
reg: InlineAsmRegOrRegClass,
25682568
late: bool,
2569-
expr: Option<Expr<'hir>>,
2569+
expr: Option<&'hir Expr<'hir>>,
25702570
},
25712571
InOut {
25722572
reg: InlineAsmRegOrRegClass,
25732573
late: bool,
2574-
expr: Expr<'hir>,
2574+
expr: &'hir Expr<'hir>,
25752575
},
25762576
SplitInOut {
25772577
reg: InlineAsmRegOrRegClass,
25782578
late: bool,
2579-
in_expr: Expr<'hir>,
2580-
out_expr: Option<Expr<'hir>>,
2579+
in_expr: &'hir Expr<'hir>,
2580+
out_expr: Option<&'hir Expr<'hir>>,
25812581
},
25822582
Const {
25832583
anon_const: AnonConst,
@@ -2991,7 +2991,7 @@ pub enum ItemKind<'hir> {
29912991
/// A MBE macro definition (`macro_rules!` or `macro`).
29922992
Macro(ast::MacroDef, MacroKind),
29932993
/// A module.
2994-
Mod(Mod<'hir>),
2994+
Mod(&'hir Mod<'hir>),
29952995
/// An external module, e.g. `extern { .. }`.
29962996
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef] },
29972997
/// Module-level inline assembly (from `global_asm!`).
@@ -3495,16 +3495,32 @@ impl<'hir> Node<'hir> {
34953495
mod size_asserts {
34963496
use super::*;
34973497
// These are in alphabetical order, which is easy to maintain.
3498-
static_assert_size!(Block<'static>, 48);
3499-
static_assert_size!(Expr<'static>, 56);
3500-
static_assert_size!(ForeignItem<'static>, 72);
3498+
static_assert_size!(Block<'_>, 48);
3499+
static_assert_size!(Body<'_>, 32);
3500+
static_assert_size!(Expr<'_>, 56);
3501+
static_assert_size!(ExprKind<'_>, 40);
3502+
static_assert_size!(FnDecl<'_>, 40);
3503+
static_assert_size!(ForeignItem<'_>, 72);
3504+
static_assert_size!(ForeignItemKind<'_>, 40);
3505+
static_assert_size!(GenericArg<'_>, 40);
35013506
static_assert_size!(GenericBound<'_>, 48);
3502-
static_assert_size!(Generics<'static>, 56);
3503-
static_assert_size!(ImplItem<'static>, 88);
3504-
static_assert_size!(Impl<'static>, 80);
3505-
static_assert_size!(Item<'static>, 80);
3506-
static_assert_size!(Pat<'static>, 88);
3507-
static_assert_size!(QPath<'static>, 24);
3508-
static_assert_size!(TraitItem<'static>, 96);
3509-
static_assert_size!(Ty<'static>, 72);
3507+
static_assert_size!(Generics<'_>, 56);
3508+
static_assert_size!(Impl<'_>, 80);
3509+
static_assert_size!(ImplItem<'_>, 88);
3510+
static_assert_size!(ImplItemKind<'_>, 40);
3511+
static_assert_size!(Item<'_>, 80);
3512+
static_assert_size!(ItemKind<'_>, 48);
3513+
static_assert_size!(Local<'_>, 64);
3514+
static_assert_size!(Param<'_>, 32);
3515+
static_assert_size!(Pat<'_>, 88);
3516+
static_assert_size!(PatKind<'_>, 64);
3517+
static_assert_size!(Path<'_>, 48);
3518+
static_assert_size!(PathSegment<'_>, 56);
3519+
static_assert_size!(QPath<'_>, 24);
3520+
static_assert_size!(Stmt<'_>, 32);
3521+
static_assert_size!(StmtKind<'_>, 16);
3522+
static_assert_size!(TraitItem<'_>, 96);
3523+
static_assert_size!(TraitItemKind<'_>, 56);
3524+
static_assert_size!(Ty<'_>, 72);
3525+
static_assert_size!(TyKind<'_>, 56);
35103526
}

compiler/rustc_interface/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
6868
}
6969

7070
if sess.opts.unstable_opts.hir_stats {
71-
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS");
71+
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
7272
}
7373

7474
Ok(krate)
@@ -415,7 +415,7 @@ pub fn configure_and_expand(
415415
}
416416

417417
if sess.opts.unstable_opts.hir_stats {
418-
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS");
418+
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS", "ast-stats-2");
419419
}
420420

421421
resolver.resolve_crate(&krate);

0 commit comments

Comments
 (0)