From 9ee0192095b7c8f9a0030b06c67474155f8ea9a0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 26 Aug 2022 13:52:41 +1000 Subject: Add prefix to every line of `-Zhir-stats` output. This is based on `-Zprint-type-sizes` which does the same thing. It makes the output provenance clearer, and helps with post-processing. E.g. if you have `-Zhir-stats` output from numerous compiler invocations you can now easily extract the pre-expansion stats separately from the post-expansion stats. --- src/test/ui/stats/hir-stats.stderr | 296 ++++++++++++++++++------------------- 1 file changed, 145 insertions(+), 151 deletions(-) (limited to 'src/test/ui') diff --git a/src/test/ui/stats/hir-stats.stderr b/src/test/ui/stats/hir-stats.stderr index eb828bb9a2c..13cb140246f 100644 --- a/src/test/ui/stats/hir-stats.stderr +++ b/src/test/ui/stats/hir-stats.stderr @@ -1,151 +1,145 @@ - -PRE EXPANSION AST STATS - -Name Accumulated Size Count Item Size ----------------------------------------------------------------- -ExprField 48 ( 0.6%) 1 48 -Crate 56 ( 0.7%) 1 56 -Attribute 64 ( 0.8%) 2 32 -- Normal 32 ( 0.4%) 1 -- DocComment 32 ( 0.4%) 1 -GenericArgs 64 ( 0.8%) 1 64 -- AngleBracketed 64 ( 0.8%) 1 -Local 72 ( 0.9%) 1 72 -WherePredicate 72 ( 0.9%) 1 72 -- BoundPredicate 72 ( 0.9%) 1 -Arm 96 ( 1.1%) 2 48 -ForeignItem 96 ( 1.1%) 1 96 -- Fn 96 ( 1.1%) 1 -FieldDef 160 ( 1.9%) 2 80 -Stmt 160 ( 1.9%) 5 32 -- Local 32 ( 0.4%) 1 -- MacCall 32 ( 0.4%) 1 -- Expr 96 ( 1.1%) 3 -Param 160 ( 1.9%) 4 40 -FnDecl 200 ( 2.4%) 5 40 -Variant 240 ( 2.8%) 2 120 -Block 288 ( 3.4%) 6 48 -GenericBound 352 ( 4.2%) 4 88 -- Trait 352 ( 4.2%) 4 -AssocItem 416 ( 4.9%) 4 104 -- TyAlias 208 ( 2.5%) 2 -- Fn 208 ( 2.5%) 2 -GenericParam 520 ( 6.1%) 5 104 -PathSegment 720 ( 8.5%) 30 24 -Expr 832 ( 9.8%) 8 104 -- Path 104 ( 1.2%) 1 -- Match 104 ( 1.2%) 1 -- Struct 104 ( 1.2%) 1 -- Lit 208 ( 2.5%) 2 -- Block 312 ( 3.7%) 3 -Pat 840 ( 9.9%) 7 120 -- Struct 120 ( 1.4%) 1 -- Wild 120 ( 1.4%) 1 -- Ident 600 ( 7.1%) 5 -Ty 1_344 (15.9%) 14 96 -- Rptr 96 ( 1.1%) 1 -- Ptr 96 ( 1.1%) 1 -- ImplicitSelf 192 ( 2.3%) 2 -- Path 960 (11.4%) 10 -Item 1_656 (19.6%) 9 184 -- Trait 184 ( 2.2%) 1 -- Enum 184 ( 2.2%) 1 -- ForeignMod 184 ( 2.2%) 1 -- Impl 184 ( 2.2%) 1 -- Fn 368 ( 4.4%) 2 -- Use 552 ( 6.5%) 3 ----------------------------------------------------------------- -Total 8_456 - - -POST EXPANSION AST STATS - -Name Accumulated Size Count Item Size ----------------------------------------------------------------- -ExprField 48 ( 0.5%) 1 48 -Crate 56 ( 0.6%) 1 56 -GenericArgs 64 ( 0.7%) 1 64 -- AngleBracketed 64 ( 0.7%) 1 -Local 72 ( 0.8%) 1 72 -WherePredicate 72 ( 0.8%) 1 72 -- BoundPredicate 72 ( 0.8%) 1 -Arm 96 ( 1.0%) 2 48 -ForeignItem 96 ( 1.0%) 1 96 -- Fn 96 ( 1.0%) 1 -InlineAsm 120 ( 1.3%) 1 120 -Attribute 128 ( 1.4%) 4 32 -- DocComment 32 ( 0.3%) 1 -- Normal 96 ( 1.0%) 3 -FieldDef 160 ( 1.7%) 2 80 -Stmt 160 ( 1.7%) 5 32 -- Local 32 ( 0.3%) 1 -- Semi 32 ( 0.3%) 1 -- Expr 96 ( 1.0%) 3 -Param 160 ( 1.7%) 4 40 -FnDecl 200 ( 2.2%) 5 40 -Variant 240 ( 2.6%) 2 120 -Block 288 ( 3.1%) 6 48 -GenericBound 352 ( 3.8%) 4 88 -- Trait 352 ( 3.8%) 4 -AssocItem 416 ( 4.5%) 4 104 -- TyAlias 208 ( 2.3%) 2 -- Fn 208 ( 2.3%) 2 -GenericParam 520 ( 5.7%) 5 104 -PathSegment 792 ( 8.6%) 33 24 -Pat 840 ( 9.1%) 7 120 -- Struct 120 ( 1.3%) 1 -- Wild 120 ( 1.3%) 1 -- Ident 600 ( 6.5%) 5 -Expr 936 (10.2%) 9 104 -- Path 104 ( 1.1%) 1 -- Match 104 ( 1.1%) 1 -- Struct 104 ( 1.1%) 1 -- InlineAsm 104 ( 1.1%) 1 -- Lit 208 ( 2.3%) 2 -- Block 312 ( 3.4%) 3 -Ty 1_344 (14.6%) 14 96 -- Rptr 96 ( 1.0%) 1 -- Ptr 96 ( 1.0%) 1 -- ImplicitSelf 192 ( 2.1%) 2 -- Path 960 (10.5%) 10 -Item 2_024 (22.0%) 11 184 -- Trait 184 ( 2.0%) 1 -- Enum 184 ( 2.0%) 1 -- ExternCrate 184 ( 2.0%) 1 -- ForeignMod 184 ( 2.0%) 1 -- Impl 184 ( 2.0%) 1 -- Fn 368 ( 4.0%) 2 -- Use 736 ( 8.0%) 4 ----------------------------------------------------------------- -Total 9_184 - - -HIR STATS - -Name Accumulated Size Count Item Size ----------------------------------------------------------------- -Param 64 ( 0.7%) 2 32 -Local 64 ( 0.7%) 1 64 -ForeignItem 72 ( 0.8%) 1 72 -FieldDef 96 ( 1.0%) 2 48 -Arm 96 ( 1.0%) 2 48 -Stmt 96 ( 1.0%) 3 32 -FnDecl 120 ( 1.3%) 3 40 -Attribute 128 ( 1.4%) 4 32 -Lifetime 128 ( 1.4%) 4 32 -Variant 160 ( 1.7%) 2 80 -ImplItem 176 ( 1.9%) 2 88 -GenericBound 192 ( 2.1%) 4 48 -TraitItem 192 ( 2.1%) 2 96 -WherePredicate 216 ( 2.3%) 3 72 -Block 288 ( 3.1%) 6 48 -QPath 408 ( 4.4%) 17 24 -Pat 440 ( 4.8%) 5 88 -Expr 672 ( 7.3%) 12 56 -Item 960 (10.4%) 12 80 -Ty 1_152 (12.4%) 16 72 -Path 1_296 (14.0%) 27 48 -PathSegment 2_240 (24.2%) 40 56 ----------------------------------------------------------------- -Total 9_256 - +ast-stats-1 PRE EXPANSION AST STATS +ast-stats-1 Name Accumulated Size Count Item Size +ast-stats-1 ---------------------------------------------------------------- +ast-stats-1 ExprField 48 ( 0.6%) 1 48 +ast-stats-1 Crate 56 ( 0.7%) 1 56 +ast-stats-1 Attribute 64 ( 0.8%) 2 32 +ast-stats-1 - Normal 32 ( 0.4%) 1 +ast-stats-1 - DocComment 32 ( 0.4%) 1 +ast-stats-1 GenericArgs 64 ( 0.8%) 1 64 +ast-stats-1 - AngleBracketed 64 ( 0.8%) 1 +ast-stats-1 Local 72 ( 0.9%) 1 72 +ast-stats-1 WherePredicate 72 ( 0.9%) 1 72 +ast-stats-1 - BoundPredicate 72 ( 0.9%) 1 +ast-stats-1 Arm 96 ( 1.1%) 2 48 +ast-stats-1 ForeignItem 96 ( 1.1%) 1 96 +ast-stats-1 - Fn 96 ( 1.1%) 1 +ast-stats-1 FieldDef 160 ( 1.9%) 2 80 +ast-stats-1 Stmt 160 ( 1.9%) 5 32 +ast-stats-1 - Local 32 ( 0.4%) 1 +ast-stats-1 - MacCall 32 ( 0.4%) 1 +ast-stats-1 - Expr 96 ( 1.1%) 3 +ast-stats-1 Param 160 ( 1.9%) 4 40 +ast-stats-1 FnDecl 200 ( 2.4%) 5 40 +ast-stats-1 Variant 240 ( 2.8%) 2 120 +ast-stats-1 Block 288 ( 3.4%) 6 48 +ast-stats-1 GenericBound 352 ( 4.2%) 4 88 +ast-stats-1 - Trait 352 ( 4.2%) 4 +ast-stats-1 AssocItem 416 ( 4.9%) 4 104 +ast-stats-1 - TyAlias 208 ( 2.5%) 2 +ast-stats-1 - Fn 208 ( 2.5%) 2 +ast-stats-1 GenericParam 520 ( 6.1%) 5 104 +ast-stats-1 PathSegment 720 ( 8.5%) 30 24 +ast-stats-1 Expr 832 ( 9.8%) 8 104 +ast-stats-1 - Path 104 ( 1.2%) 1 +ast-stats-1 - Match 104 ( 1.2%) 1 +ast-stats-1 - Struct 104 ( 1.2%) 1 +ast-stats-1 - Lit 208 ( 2.5%) 2 +ast-stats-1 - Block 312 ( 3.7%) 3 +ast-stats-1 Pat 840 ( 9.9%) 7 120 +ast-stats-1 - Struct 120 ( 1.4%) 1 +ast-stats-1 - Wild 120 ( 1.4%) 1 +ast-stats-1 - Ident 600 ( 7.1%) 5 +ast-stats-1 Ty 1_344 (15.9%) 14 96 +ast-stats-1 - Rptr 96 ( 1.1%) 1 +ast-stats-1 - Ptr 96 ( 1.1%) 1 +ast-stats-1 - ImplicitSelf 192 ( 2.3%) 2 +ast-stats-1 - Path 960 (11.4%) 10 +ast-stats-1 Item 1_656 (19.6%) 9 184 +ast-stats-1 - Trait 184 ( 2.2%) 1 +ast-stats-1 - Enum 184 ( 2.2%) 1 +ast-stats-1 - ForeignMod 184 ( 2.2%) 1 +ast-stats-1 - Impl 184 ( 2.2%) 1 +ast-stats-1 - Fn 368 ( 4.4%) 2 +ast-stats-1 - Use 552 ( 6.5%) 3 +ast-stats-1 ---------------------------------------------------------------- +ast-stats-1 Total 8_456 +ast-stats-1 +ast-stats-2 POST EXPANSION AST STATS +ast-stats-2 Name Accumulated Size Count Item Size +ast-stats-2 ---------------------------------------------------------------- +ast-stats-2 ExprField 48 ( 0.5%) 1 48 +ast-stats-2 Crate 56 ( 0.6%) 1 56 +ast-stats-2 GenericArgs 64 ( 0.7%) 1 64 +ast-stats-2 - AngleBracketed 64 ( 0.7%) 1 +ast-stats-2 Local 72 ( 0.8%) 1 72 +ast-stats-2 WherePredicate 72 ( 0.8%) 1 72 +ast-stats-2 - BoundPredicate 72 ( 0.8%) 1 +ast-stats-2 Arm 96 ( 1.0%) 2 48 +ast-stats-2 ForeignItem 96 ( 1.0%) 1 96 +ast-stats-2 - Fn 96 ( 1.0%) 1 +ast-stats-2 InlineAsm 120 ( 1.3%) 1 120 +ast-stats-2 Attribute 128 ( 1.4%) 4 32 +ast-stats-2 - DocComment 32 ( 0.3%) 1 +ast-stats-2 - Normal 96 ( 1.0%) 3 +ast-stats-2 FieldDef 160 ( 1.7%) 2 80 +ast-stats-2 Stmt 160 ( 1.7%) 5 32 +ast-stats-2 - Local 32 ( 0.3%) 1 +ast-stats-2 - Semi 32 ( 0.3%) 1 +ast-stats-2 - Expr 96 ( 1.0%) 3 +ast-stats-2 Param 160 ( 1.7%) 4 40 +ast-stats-2 FnDecl 200 ( 2.2%) 5 40 +ast-stats-2 Variant 240 ( 2.6%) 2 120 +ast-stats-2 Block 288 ( 3.1%) 6 48 +ast-stats-2 GenericBound 352 ( 3.8%) 4 88 +ast-stats-2 - Trait 352 ( 3.8%) 4 +ast-stats-2 AssocItem 416 ( 4.5%) 4 104 +ast-stats-2 - TyAlias 208 ( 2.3%) 2 +ast-stats-2 - Fn 208 ( 2.3%) 2 +ast-stats-2 GenericParam 520 ( 5.7%) 5 104 +ast-stats-2 PathSegment 792 ( 8.6%) 33 24 +ast-stats-2 Pat 840 ( 9.1%) 7 120 +ast-stats-2 - Struct 120 ( 1.3%) 1 +ast-stats-2 - Wild 120 ( 1.3%) 1 +ast-stats-2 - Ident 600 ( 6.5%) 5 +ast-stats-2 Expr 936 (10.2%) 9 104 +ast-stats-2 - Path 104 ( 1.1%) 1 +ast-stats-2 - Match 104 ( 1.1%) 1 +ast-stats-2 - Struct 104 ( 1.1%) 1 +ast-stats-2 - InlineAsm 104 ( 1.1%) 1 +ast-stats-2 - Lit 208 ( 2.3%) 2 +ast-stats-2 - Block 312 ( 3.4%) 3 +ast-stats-2 Ty 1_344 (14.6%) 14 96 +ast-stats-2 - Rptr 96 ( 1.0%) 1 +ast-stats-2 - Ptr 96 ( 1.0%) 1 +ast-stats-2 - ImplicitSelf 192 ( 2.1%) 2 +ast-stats-2 - Path 960 (10.5%) 10 +ast-stats-2 Item 2_024 (22.0%) 11 184 +ast-stats-2 - Trait 184 ( 2.0%) 1 +ast-stats-2 - Enum 184 ( 2.0%) 1 +ast-stats-2 - ExternCrate 184 ( 2.0%) 1 +ast-stats-2 - ForeignMod 184 ( 2.0%) 1 +ast-stats-2 - Impl 184 ( 2.0%) 1 +ast-stats-2 - Fn 368 ( 4.0%) 2 +ast-stats-2 - Use 736 ( 8.0%) 4 +ast-stats-2 ---------------------------------------------------------------- +ast-stats-2 Total 9_184 +ast-stats-2 +hir-stats HIR STATS +hir-stats Name Accumulated Size Count Item Size +hir-stats ---------------------------------------------------------------- +hir-stats Param 64 ( 0.7%) 2 32 +hir-stats Local 64 ( 0.7%) 1 64 +hir-stats ForeignItem 72 ( 0.8%) 1 72 +hir-stats FieldDef 96 ( 1.0%) 2 48 +hir-stats Arm 96 ( 1.0%) 2 48 +hir-stats Stmt 96 ( 1.0%) 3 32 +hir-stats FnDecl 120 ( 1.3%) 3 40 +hir-stats Attribute 128 ( 1.4%) 4 32 +hir-stats Lifetime 128 ( 1.4%) 4 32 +hir-stats Variant 160 ( 1.7%) 2 80 +hir-stats ImplItem 176 ( 1.9%) 2 88 +hir-stats GenericBound 192 ( 2.1%) 4 48 +hir-stats TraitItem 192 ( 2.1%) 2 96 +hir-stats WherePredicate 216 ( 2.3%) 3 72 +hir-stats Block 288 ( 3.1%) 6 48 +hir-stats QPath 408 ( 4.4%) 17 24 +hir-stats Pat 440 ( 4.8%) 5 88 +hir-stats Expr 672 ( 7.3%) 12 56 +hir-stats Item 960 (10.4%) 12 80 +hir-stats Ty 1_152 (12.4%) 16 72 +hir-stats Path 1_296 (14.0%) 27 48 +hir-stats PathSegment 2_240 (24.2%) 40 56 +hir-stats ---------------------------------------------------------------- +hir-stats Total 9_256 +hir-stats -- cgit 1.4.1-3-g733a5 From f26fdce9917992f71e561cef44a52fb5bd2e6de9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 29 Aug 2022 11:10:56 +1000 Subject: Improve HIR stats collector. Adds and removes some `visit_*` methods accordingly, improving coverage, and avoiding some double counting. Brings it in line with the AST stats collector. --- compiler/rustc_passes/src/hir_stats.rs | 244 ++++++++++++++++++++++++++------- src/test/ui/stats/hir-stats.stderr | 72 +++++++--- 2 files changed, 246 insertions(+), 70 deletions(-) (limited to 'src/test/ui') diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index 0540c944b03..c6728302428 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -168,6 +168,22 @@ impl<'k> StatCollector<'k> { } } +// Used to avoid boilerplate for types with many variants. +macro_rules! record_variants { + ( + ($self:ident, $val:expr, $kind:expr, $id:expr, $mod:ident, $ty:ty, $tykind:ident), + [$($variant:ident),*] + ) => { + match $kind { + $( + $mod::$tykind::$variant { .. } => { + $self.record_variant(stringify!($ty), stringify!($variant), $id, $val) + } + )* + } + }; +} + impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { fn visit_param(&mut self, param: &'v hir::Param<'v>) { self.record("Param", Id::Node(param.hir_id), param); @@ -200,12 +216,46 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_item(&mut self, i: &'v hir::Item<'v>) { - self.record("Item", Id::Node(i.hir_id()), i); + record_variants!( + (self, i, i.kind, Id::Node(i.hir_id()), hir, Item, ItemKind), + [ + ExternCrate, + Use, + Static, + Const, + Fn, + Macro, + Mod, + ForeignMod, + GlobalAsm, + TyAlias, + OpaqueTy, + Enum, + Struct, + Union, + Trait, + TraitAlias, + Impl + ] + ); hir_visit::walk_item(self, i) } + fn visit_body(&mut self, b: &'v hir::Body<'v>) { + self.record("Body", Id::None, b); + hir_visit::walk_body(self, b); + } + + fn visit_mod(&mut self, m: &'v hir::Mod<'v>, _s: Span, n: HirId) { + self.record("Mod", Id::None, m); + hir_visit::walk_mod(self, m, n) + } + fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) { - self.record("ForeignItem", Id::Node(i.hir_id()), i); + record_variants!( + (self, i, i.kind, Id::Node(i.hir_id()), hir, ForeignItem, ForeignItemKind), + [Fn, Static, Type] + ); hir_visit::walk_foreign_item(self, i) } @@ -220,7 +270,10 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) { - self.record("Stmt", Id::Node(s.hir_id), s); + record_variants!( + (self, s, s.kind, Id::Node(s.hir_id), hir, Stmt, StmtKind), + [Local, Item, Expr, Semi] + ); hir_visit::walk_stmt(self, s) } @@ -230,20 +283,80 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_pat(&mut self, p: &'v hir::Pat<'v>) { - self.record("Pat", Id::Node(p.hir_id), p); + record_variants!( + (self, p, p.kind, Id::Node(p.hir_id), hir, Pat, PatKind), + [Wild, Binding, Struct, TupleStruct, Or, Path, Tuple, Box, Ref, Lit, Range, Slice] + ); hir_visit::walk_pat(self, p) } - fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) { - self.record("Expr", Id::Node(ex.hir_id), ex); - hir_visit::walk_expr(self, ex) + fn visit_pat_field(&mut self, f: &'v hir::PatField<'v>) { + self.record("PatField", Id::Node(f.hir_id), f); + hir_visit::walk_pat_field(self, f) + } + + fn visit_expr(&mut self, e: &'v hir::Expr<'v>) { + record_variants!( + (self, e, e.kind, Id::Node(e.hir_id), hir, Expr, ExprKind), + [ + Box, ConstBlock, Array, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, + DropTemps, Let, If, Loop, Match, Closure, Block, Assign, AssignOp, Field, Index, + Path, AddrOf, Break, Continue, Ret, InlineAsm, Struct, Repeat, Yield, Err + ] + ); + hir_visit::walk_expr(self, e) + } + + fn visit_let_expr(&mut self, lex: &'v hir::Let<'v>) { + self.record("Let", Id::Node(lex.hir_id), lex); + hir_visit::walk_let_expr(self, lex) + } + + fn visit_expr_field(&mut self, f: &'v hir::ExprField<'v>) { + self.record("ExprField", Id::Node(f.hir_id), f); + hir_visit::walk_expr_field(self, f) } fn visit_ty(&mut self, t: &'v hir::Ty<'v>) { - self.record("Ty", Id::Node(t.hir_id), t); + record_variants!( + (self, t, t.kind, Id::Node(t.hir_id), hir, Ty, TyKind), + [ + Slice, + Array, + Ptr, + Rptr, + BareFn, + Never, + Tup, + Path, + OpaqueDef, + TraitObject, + Typeof, + Infer, + Err + ] + ); hir_visit::walk_ty(self, t) } + fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) { + self.record("GenericParam", Id::Node(p.hir_id), p); + hir_visit::walk_generic_param(self, p) + } + + fn visit_generics(&mut self, g: &'v hir::Generics<'v>) { + self.record("Generics", Id::None, g); + hir_visit::walk_generics(self, g) + } + + fn visit_where_predicate(&mut self, p: &'v hir::WherePredicate<'v>) { + record_variants!( + (self, p, p, Id::None, hir, WherePredicate, WherePredicate), + [BoundPredicate, RegionPredicate, EqPredicate] + ); + hir_visit::walk_where_predicate(self, p) + } + fn visit_fn( &mut self, fk: hir_visit::FnKind<'v>, @@ -256,24 +369,49 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_fn(self, fk, fd, b, s, id) } - fn visit_where_predicate(&mut self, predicate: &'v hir::WherePredicate<'v>) { - self.record("WherePredicate", Id::None, predicate); - hir_visit::walk_where_predicate(self, predicate) + fn visit_use(&mut self, p: &'v hir::Path<'v>, hir_id: hir::HirId) { + // This is `visit_use`, but the type is `Path` so record it that way. + self.record("Path", Id::None, p); + hir_visit::walk_use(self, p, hir_id) } fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) { - self.record("TraitItem", Id::Node(ti.hir_id()), ti); + record_variants!( + (self, ti, ti.kind, Id::Node(ti.hir_id()), hir, TraitItem, TraitItemKind), + [Const, Fn, Type] + ); hir_visit::walk_trait_item(self, ti) } + fn visit_trait_item_ref(&mut self, ti: &'v hir::TraitItemRef) { + self.record("TraitItemRef", Id::Node(ti.id.hir_id()), ti); + hir_visit::walk_trait_item_ref(self, ti) + } + fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { - self.record("ImplItem", Id::Node(ii.hir_id()), ii); + record_variants!( + (self, ii, ii.kind, Id::Node(ii.hir_id()), hir, ImplItem, ImplItemKind), + [Const, Fn, TyAlias] + ); hir_visit::walk_impl_item(self, ii) } - fn visit_param_bound(&mut self, bounds: &'v hir::GenericBound<'v>) { - self.record("GenericBound", Id::None, bounds); - hir_visit::walk_param_bound(self, bounds) + fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemRef) { + self.record("ForeignItemRef", Id::Node(fi.id.hir_id()), fi); + hir_visit::walk_foreign_item_ref(self, fi) + } + + fn visit_impl_item_ref(&mut self, ii: &'v hir::ImplItemRef) { + self.record("ImplItemRef", Id::Node(ii.id.hir_id()), ii); + hir_visit::walk_impl_item_ref(self, ii) + } + + fn visit_param_bound(&mut self, b: &'v hir::GenericBound<'v>) { + record_variants!( + (self, b, b, Id::None, hir, GenericBound, GenericBound), + [Trait, LangItemTrait, Outlives] + ); + hir_visit::walk_param_bound(self, b) } fn visit_field_def(&mut self, s: &'v hir::FieldDef<'v>) { @@ -286,14 +424,17 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_variant(self, v) } - fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) { - self.record("Lifetime", Id::Node(lifetime.hir_id), lifetime); - hir_visit::walk_lifetime(self, lifetime) - } - - fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) { - self.record("QPath", Id::None, qpath); - hir_visit::walk_qpath(self, qpath, id, span) + fn visit_generic_arg(&mut self, ga: &'v hir::GenericArg<'v>) { + record_variants!( + (self, ga, ga, Id::Node(ga.hir_id()), hir, GenericArg, GenericArg), + [Lifetime, Type, Const, Infer] + ); + match ga { + hir::GenericArg::Lifetime(lt) => self.visit_lifetime(lt), + hir::GenericArg::Type(ty) => self.visit_ty(ty), + hir::GenericArg::Const(ct) => self.visit_anon_const(&ct.value), + hir::GenericArg::Infer(inf) => self.visit_infer(inf), + } } fn visit_path(&mut self, path: &'v hir::Path<'v>, _id: hir::HirId) { @@ -306,6 +447,11 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_path_segment(self, path_span, path_segment) } + fn visit_generic_args(&mut self, sp: Span, ga: &'v hir::GenericArgs<'v>) { + self.record("GenericArgs", Id::None, ga); + hir_visit::walk_generic_args(self, sp, ga) + } + fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'v>) { self.record("TypeBinding", Id::Node(type_binding.hir_id), type_binding); hir_visit::walk_assoc_type_binding(self, type_binding) @@ -314,28 +460,17 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { fn visit_attribute(&mut self, attr: &'v ast::Attribute) { self.record("Attribute", Id::Attr(attr.id), attr); } -} -// Used to avoid boilerplate for types with many variants. -macro_rules! record_variants { - ( - ($self:ident, $val:expr, $kind:expr, $ty:ty, $tykind:ident), // mandatory pieces - [$($variant:ident),*] - ) => { - match $kind { - $( - ast::$tykind::$variant { .. } => { - $self.record_variant(stringify!($ty), stringify!($variant), Id::None, $val) - } - )* - } - }; + fn visit_inline_asm(&mut self, asm: &'v hir::InlineAsm<'v>, id: HirId) { + self.record("InlineAsm", Id::None, asm); + hir_visit::walk_inline_asm(self, asm, id); + } } impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) { record_variants!( - (self, i, i.kind, ForeignItem, ForeignItemKind), + (self, i, i.kind, Id::None, ast, ForeignItem, ForeignItemKind), [Static, Fn, TyAlias, MacCall] ); ast_visit::walk_foreign_item(self, i) @@ -343,7 +478,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_item(&mut self, i: &'v ast::Item) { record_variants!( - (self, i, i.kind, Item, ItemKind), + (self, i, i.kind, Id::None, ast, Item, ItemKind), [ ExternCrate, Use, @@ -379,7 +514,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_stmt(&mut self, s: &'v ast::Stmt) { record_variants!( - (self, s, s.kind, Stmt, StmtKind), + (self, s, s.kind, Id::None, ast, Stmt, StmtKind), [Local, Item, Expr, Semi, Empty, MacCall] ); ast_visit::walk_stmt(self, s) @@ -397,7 +532,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_pat(&mut self, p: &'v ast::Pat) { record_variants!( - (self, p, p.kind, Pat, PatKind), + (self, p, p.kind, Id::None, ast, Pat, PatKind), [ Wild, Ident, @@ -421,7 +556,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_expr(&mut self, e: &'v ast::Expr) { record_variants!( - (self, e, e.kind, Expr, ExprKind), + (self, e, e.kind, Id::None, ast, Expr, ExprKind), [ Box, Array, ConstBlock, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, Let, If, While, ForLoop, Loop, Match, Closure, Block, Async, Await, TryBlock, Assign, @@ -434,7 +569,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_ty(&mut self, t: &'v ast::Ty) { record_variants!( - (self, t, t.kind, Ty, TyKind), + (self, t, t.kind, Id::None, ast, Ty, TyKind), [ Slice, Array, @@ -466,7 +601,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_where_predicate(&mut self, p: &'v ast::WherePredicate) { record_variants!( - (self, p, p, WherePredicate, WherePredicate), + (self, p, p, Id::None, ast, WherePredicate, WherePredicate), [BoundPredicate, RegionPredicate, EqPredicate] ); ast_visit::walk_where_predicate(self, p) @@ -479,14 +614,17 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_assoc_item(&mut self, i: &'v ast::AssocItem, ctxt: ast_visit::AssocCtxt) { record_variants!( - (self, i, i.kind, AssocItem, AssocItemKind), + (self, i, i.kind, Id::None, ast, AssocItem, AssocItemKind), [Const, Fn, TyAlias, MacCall] ); ast_visit::walk_assoc_item(self, i, ctxt); } fn visit_param_bound(&mut self, b: &'v ast::GenericBound, _ctxt: BoundKind) { - record_variants!((self, b, b, GenericBound, GenericBound), [Trait, Outlives]); + record_variants!( + (self, b, b, Id::None, ast, GenericBound, GenericBound), + [Trait, Outlives] + ); ast_visit::walk_param_bound(self, b) } @@ -519,12 +657,18 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { // common, so we implement `visit_generic_args` and tolerate the double // counting in the former case. fn visit_generic_args(&mut self, sp: Span, g: &'v ast::GenericArgs) { - record_variants!((self, g, g, GenericArgs, GenericArgs), [AngleBracketed, Parenthesized]); + record_variants!( + (self, g, g, Id::None, ast, GenericArgs, GenericArgs), + [AngleBracketed, Parenthesized] + ); ast_visit::walk_generic_args(self, sp, g) } fn visit_attribute(&mut self, attr: &'v ast::Attribute) { - record_variants!((self, attr, attr.kind, Attribute, AttrKind), [Normal, DocComment]); + record_variants!( + (self, attr, attr.kind, Id::None, ast, Attribute, AttrKind), + [Normal, DocComment] + ); ast_visit::walk_attribute(self, attr) } diff --git a/src/test/ui/stats/hir-stats.stderr b/src/test/ui/stats/hir-stats.stderr index 13cb140246f..78f70997555 100644 --- a/src/test/ui/stats/hir-stats.stderr +++ b/src/test/ui/stats/hir-stats.stderr @@ -118,28 +118,60 @@ ast-stats-2 hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size hir-stats ---------------------------------------------------------------- -hir-stats Param 64 ( 0.7%) 2 32 -hir-stats Local 64 ( 0.7%) 1 64 -hir-stats ForeignItem 72 ( 0.8%) 1 72 +hir-stats ForeignItemRef 24 ( 0.2%) 1 24 +hir-stats Mod 32 ( 0.3%) 1 32 +hir-stats ExprField 40 ( 0.4%) 1 40 +hir-stats TraitItemRef 56 ( 0.6%) 2 28 +hir-stats Param 64 ( 0.6%) 2 32 +hir-stats Local 64 ( 0.6%) 1 64 +hir-stats InlineAsm 72 ( 0.7%) 1 72 +hir-stats ImplItemRef 72 ( 0.7%) 2 36 hir-stats FieldDef 96 ( 1.0%) 2 48 hir-stats Arm 96 ( 1.0%) 2 48 +hir-stats Body 96 ( 1.0%) 3 32 hir-stats Stmt 96 ( 1.0%) 3 32 -hir-stats FnDecl 120 ( 1.3%) 3 40 -hir-stats Attribute 128 ( 1.4%) 4 32 -hir-stats Lifetime 128 ( 1.4%) 4 32 -hir-stats Variant 160 ( 1.7%) 2 80 -hir-stats ImplItem 176 ( 1.9%) 2 88 -hir-stats GenericBound 192 ( 2.1%) 4 48 -hir-stats TraitItem 192 ( 2.1%) 2 96 -hir-stats WherePredicate 216 ( 2.3%) 3 72 -hir-stats Block 288 ( 3.1%) 6 48 -hir-stats QPath 408 ( 4.4%) 17 24 -hir-stats Pat 440 ( 4.8%) 5 88 -hir-stats Expr 672 ( 7.3%) 12 56 -hir-stats Item 960 (10.4%) 12 80 -hir-stats Ty 1_152 (12.4%) 16 72 -hir-stats Path 1_296 (14.0%) 27 48 -hir-stats PathSegment 2_240 (24.2%) 40 56 +hir-stats - Local 32 ( 0.3%) 1 +hir-stats - Semi 32 ( 0.3%) 1 +hir-stats - Expr 32 ( 0.3%) 1 +hir-stats FnDecl 120 ( 1.2%) 3 40 +hir-stats Attribute 128 ( 1.3%) 4 32 +hir-stats GenericArgs 144 ( 1.4%) 3 48 +hir-stats Variant 160 ( 1.6%) 2 80 +hir-stats GenericArg 160 ( 1.6%) 4 40 +hir-stats - Type 40 ( 0.4%) 1 +hir-stats - Lifetime 120 ( 1.2%) 3 +hir-stats GenericBound 192 ( 1.9%) 4 48 +hir-stats - Trait 192 ( 1.9%) 4 +hir-stats WherePredicate 216 ( 2.1%) 3 72 +hir-stats - BoundPredicate 216 ( 2.1%) 3 +hir-stats Block 288 ( 2.9%) 6 48 +hir-stats GenericParam 400 ( 4.0%) 5 80 +hir-stats Pat 440 ( 4.4%) 5 88 +hir-stats - Wild 88 ( 0.9%) 1 +hir-stats - Struct 88 ( 0.9%) 1 +hir-stats - Binding 264 ( 2.6%) 3 +hir-stats Generics 560 ( 5.5%) 10 56 +hir-stats Expr 672 ( 6.7%) 12 56 +hir-stats - Path 56 ( 0.6%) 1 +hir-stats - Struct 56 ( 0.6%) 1 +hir-stats - Match 56 ( 0.6%) 1 +hir-stats - InlineAsm 56 ( 0.6%) 1 +hir-stats - Lit 112 ( 1.1%) 2 +hir-stats - Block 336 ( 3.3%) 6 +hir-stats Item 960 ( 9.5%) 12 80 +hir-stats - Trait 80 ( 0.8%) 1 +hir-stats - Enum 80 ( 0.8%) 1 +hir-stats - ExternCrate 80 ( 0.8%) 1 +hir-stats - ForeignMod 80 ( 0.8%) 1 +hir-stats - Impl 80 ( 0.8%) 1 +hir-stats - Fn 160 ( 1.6%) 2 +hir-stats - Use 400 ( 4.0%) 5 +hir-stats Ty 1_080 (10.7%) 15 72 +hir-stats - Ptr 72 ( 0.7%) 1 +hir-stats - Rptr 72 ( 0.7%) 1 +hir-stats - Path 936 ( 9.3%) 13 +hir-stats Path 1_536 (15.2%) 32 48 +hir-stats PathSegment 2_240 (22.2%) 40 56 hir-stats ---------------------------------------------------------------- -hir-stats Total 9_256 +hir-stats Total 10_104 hir-stats -- cgit 1.4.1-3-g733a5