Skip to content

Commit acf4e0b

Browse files
committed
Auto merge of #30087 - petrochenkov:indi, r=nrc
I've measured the time/memory consumption before and after - the difference is lost in statistical noise, so it's mostly a code simplification. Sizes of `enum`s are not affected. r? @nrc I wonder if AST/HIR visitors could run faster if `P`s are systematically removed (except for cases where they control `enum` sizes). Theoretically they should. Remaining unnecessary `P`s can't be easily removed because many folders accept `P<X>`s as arguments, but these folders can be converted to accept `X`s instead without loss of efficiency. When I have a mood for some mindless refactoring again, I'll probably try to convert the folders, remove remaining `P`s and measure again.
2 parents 8864f2c + ca88e9c commit acf4e0b

File tree

26 files changed

+176
-193
lines changed

26 files changed

+176
-193
lines changed

src/librustc/front/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
140140
for v in &enum_definition.variants {
141141
let variant_def_index =
142142
self.insert_def(v.node.data.id(),
143-
NodeVariant(&**v),
143+
NodeVariant(v),
144144
DefPathData::EnumVariant(v.node.name));
145145

146146
for field in v.node.data.fields() {

src/librustc/front/map/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,13 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
852852
II::Item(i) => II::Item(i.map(|i| fld.fold_item(i))),
853853
II::TraitItem(d, ti) => {
854854
II::TraitItem(fld.fold_ops.new_def_id(d),
855-
fld.fold_trait_item(ti))
855+
ti.map(|ti| fld.fold_trait_item(ti)))
856856
}
857857
II::ImplItem(d, ii) => {
858858
II::ImplItem(fld.fold_ops.new_def_id(d),
859-
fld.fold_impl_item(ii))
859+
ii.map(|ii| fld.fold_impl_item(ii)))
860860
}
861-
II::Foreign(i) => II::Foreign(fld.fold_foreign_item(i))
861+
II::Foreign(i) => II::Foreign(i.map(|i| fld.fold_foreign_item(i)))
862862
};
863863

864864
let ii_parent = map.forest.inlined_items.alloc(InlinedParent {

src/librustc/middle/cfg/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
6262
fn block(&mut self, blk: &hir::Block, pred: CFGIndex) -> CFGIndex {
6363
let mut stmts_exit = pred;
6464
for stmt in &blk.stmts {
65-
stmts_exit = self.stmt(&**stmt, stmts_exit);
65+
stmts_exit = self.stmt(stmt, stmts_exit);
6666
}
6767

6868
let expr_exit = self.opt_expr(&blk.expr, stmts_exit);

src/librustc/middle/const_eval.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
6161
enum_def: DefId,
6262
variant_def: DefId)
6363
-> Option<&'a Expr> {
64-
fn variant_expr<'a>(variants: &'a [P<hir::Variant>], id: ast::NodeId)
64+
fn variant_expr<'a>(variants: &'a [hir::Variant], id: ast::NodeId)
6565
-> Option<&'a Expr> {
6666
for variant in variants {
6767
if variant.node.data.id() == id {
@@ -77,7 +77,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
7777
None => None,
7878
Some(ast_map::NodeItem(it)) => match it.node {
7979
hir::ItemEnum(hir::EnumDef { ref variants }, _) => {
80-
variant_expr(&variants[..], variant_node_id)
80+
variant_expr(variants, variant_node_id)
8181
}
8282
_ => None
8383
},

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
637637
debug!("walk_block(blk.id={})", blk.id);
638638

639639
for stmt in &blk.stmts {
640-
self.walk_stmt(&**stmt);
640+
self.walk_stmt(stmt);
641641
}
642642

643643
if let Some(ref tail_expr) = blk.expr {

src/librustc/middle/infer/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1501,15 +1501,15 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
15011501
self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
15021502
});
15031503
let new_bindings = data.bindings.map(|b| {
1504-
P(hir::TypeBinding {
1504+
hir::TypeBinding {
15051505
id: b.id,
15061506
name: b.name,
15071507
ty: self.rebuild_arg_ty_or_output(&*b.ty,
15081508
lifetime,
15091509
anon_nums,
15101510
region_names),
15111511
span: b.span
1512-
})
1512+
}
15131513
});
15141514
hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
15151515
lifetimes: new_lts,

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
866866
-> LiveNode {
867867
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
868868
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
869-
self.propagate_through_stmt(&**stmt, succ)
869+
self.propagate_through_stmt(stmt, succ)
870870
})
871871
}
872872

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ fn resolve_block(visitor: &mut RegionResolutionVisitor, blk: &hir::Block) {
720720
parent: stmt_extent,
721721
};
722722
}
723-
visitor.visit_stmt(&**statement)
723+
visitor.visit_stmt(statement)
724724
}
725725
walk_list!(visitor, visit_expr, &blk.expr);
726726
}

src/librustc_front/fold.rs

+98-111
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub trait Folder : Sized {
4747
noop_fold_view_path(view_path, self)
4848
}
4949

50-
fn fold_foreign_item(&mut self, ni: P<ForeignItem>) -> P<ForeignItem> {
50+
fn fold_foreign_item(&mut self, ni: ForeignItem) -> ForeignItem {
5151
noop_fold_foreign_item(ni, self)
5252
}
5353

@@ -67,11 +67,11 @@ pub trait Folder : Sized {
6767
noop_fold_item_underscore(i, self)
6868
}
6969

70-
fn fold_trait_item(&mut self, i: P<TraitItem>) -> P<TraitItem> {
70+
fn fold_trait_item(&mut self, i: TraitItem) -> TraitItem {
7171
noop_fold_trait_item(i, self)
7272
}
7373

74-
fn fold_impl_item(&mut self, i: P<ImplItem>) -> P<ImplItem> {
74+
fn fold_impl_item(&mut self, i: ImplItem) -> ImplItem {
7575
noop_fold_impl_item(i, self)
7676
}
7777

@@ -83,7 +83,7 @@ pub trait Folder : Sized {
8383
noop_fold_block(b, self)
8484
}
8585

86-
fn fold_stmt(&mut self, s: P<Stmt>) -> P<Stmt> {
86+
fn fold_stmt(&mut self, s: Stmt) -> Stmt {
8787
noop_fold_stmt(s, self)
8888
}
8989

@@ -107,7 +107,7 @@ pub trait Folder : Sized {
107107
noop_fold_ty(t, self)
108108
}
109109

110-
fn fold_ty_binding(&mut self, t: P<TypeBinding>) -> P<TypeBinding> {
110+
fn fold_ty_binding(&mut self, t: TypeBinding) -> TypeBinding {
111111
noop_fold_ty_binding(t, self)
112112
}
113113

@@ -119,7 +119,7 @@ pub trait Folder : Sized {
119119
noop_fold_foreign_mod(nm, self)
120120
}
121121

122-
fn fold_variant(&mut self, v: P<Variant>) -> P<Variant> {
122+
fn fold_variant(&mut self, v: Variant) -> Variant {
123123
noop_fold_variant(v, self)
124124
}
125125

@@ -333,15 +333,13 @@ pub fn noop_fold_decl<T: Folder>(d: P<Decl>, fld: &mut T) -> P<Decl> {
333333
})
334334
}
335335

336-
pub fn noop_fold_ty_binding<T: Folder>(b: P<TypeBinding>, fld: &mut T) -> P<TypeBinding> {
337-
b.map(|TypeBinding { id, name, ty, span }| {
338-
TypeBinding {
339-
id: fld.new_id(id),
340-
name: name,
341-
ty: fld.fold_ty(ty),
342-
span: fld.new_span(span),
343-
}
344-
})
336+
pub fn noop_fold_ty_binding<T: Folder>(b: TypeBinding, fld: &mut T) -> TypeBinding {
337+
TypeBinding {
338+
id: fld.new_id(b.id),
339+
name: b.name,
340+
ty: fld.fold_ty(b.ty),
341+
span: fld.new_span(b.span),
342+
}
345343
}
346344

347345
pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
@@ -402,18 +400,16 @@ pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod { abi, items }: ForeignMod,
402400
}
403401
}
404402

405-
pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
406-
v.map(|Spanned { node: Variant_ { name, attrs, data, disr_expr }, span }| {
407-
Spanned {
408-
node: Variant_ {
409-
name: name,
410-
attrs: fold_attrs(attrs, fld),
411-
data: fld.fold_variant_data(data),
412-
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
413-
},
414-
span: fld.new_span(span),
415-
}
416-
})
403+
pub fn noop_fold_variant<T: Folder>(v: Variant, fld: &mut T) -> Variant {
404+
Spanned {
405+
node: Variant_ {
406+
name: v.node.name,
407+
attrs: fold_attrs(v.node.attrs, fld),
408+
data: fld.fold_variant_data(v.node.data),
409+
disr_expr: v.node.disr_expr.map(|e| fld.fold_expr(e)),
410+
},
411+
span: fld.new_span(v.span),
412+
}
417413
}
418414

419415
pub fn noop_fold_name<T: Folder>(n: Name, _: &mut T) -> Name {
@@ -814,51 +810,47 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
814810
}
815811
}
816812

817-
pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>,
813+
pub fn noop_fold_trait_item<T: Folder>(i: TraitItem,
818814
folder: &mut T)
819-
-> P<TraitItem> {
820-
i.map(|TraitItem { id, name, attrs, node, span }| {
821-
TraitItem {
822-
id: folder.new_id(id),
823-
name: folder.fold_name(name),
824-
attrs: fold_attrs(attrs, folder),
825-
node: match node {
826-
ConstTraitItem(ty, default) => {
827-
ConstTraitItem(folder.fold_ty(ty), default.map(|x| folder.fold_expr(x)))
828-
}
829-
MethodTraitItem(sig, body) => {
830-
MethodTraitItem(noop_fold_method_sig(sig, folder),
831-
body.map(|x| folder.fold_block(x)))
832-
}
833-
TypeTraitItem(bounds, default) => {
834-
TypeTraitItem(folder.fold_bounds(bounds),
835-
default.map(|x| folder.fold_ty(x)))
836-
}
837-
},
838-
span: folder.new_span(span),
839-
}
840-
})
815+
-> TraitItem {
816+
TraitItem {
817+
id: folder.new_id(i.id),
818+
name: folder.fold_name(i.name),
819+
attrs: fold_attrs(i.attrs, folder),
820+
node: match i.node {
821+
ConstTraitItem(ty, default) => {
822+
ConstTraitItem(folder.fold_ty(ty), default.map(|x| folder.fold_expr(x)))
823+
}
824+
MethodTraitItem(sig, body) => {
825+
MethodTraitItem(noop_fold_method_sig(sig, folder),
826+
body.map(|x| folder.fold_block(x)))
827+
}
828+
TypeTraitItem(bounds, default) => {
829+
TypeTraitItem(folder.fold_bounds(bounds),
830+
default.map(|x| folder.fold_ty(x)))
831+
}
832+
},
833+
span: folder.new_span(i.span),
834+
}
841835
}
842836

843-
pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T) -> P<ImplItem> {
844-
i.map(|ImplItem { id, name, attrs, node, vis, span }| {
845-
ImplItem {
846-
id: folder.new_id(id),
847-
name: folder.fold_name(name),
848-
attrs: fold_attrs(attrs, folder),
849-
vis: vis,
850-
node: match node {
851-
ImplItemKind::Const(ty, expr) => {
852-
ImplItemKind::Const(folder.fold_ty(ty), folder.fold_expr(expr))
853-
}
854-
ImplItemKind::Method(sig, body) => {
855-
ImplItemKind::Method(noop_fold_method_sig(sig, folder), folder.fold_block(body))
856-
}
857-
ImplItemKind::Type(ty) => ImplItemKind::Type(folder.fold_ty(ty)),
858-
},
859-
span: folder.new_span(span),
860-
}
861-
})
837+
pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T) -> ImplItem {
838+
ImplItem {
839+
id: folder.new_id(i.id),
840+
name: folder.fold_name(i.name),
841+
attrs: fold_attrs(i.attrs, folder),
842+
vis: i.vis,
843+
node: match i.node {
844+
ImplItemKind::Const(ty, expr) => {
845+
ImplItemKind::Const(folder.fold_ty(ty), folder.fold_expr(expr))
846+
}
847+
ImplItemKind::Method(sig, body) => {
848+
ImplItemKind::Method(noop_fold_method_sig(sig, folder), folder.fold_block(body))
849+
}
850+
ImplItemKind::Type(ty) => ImplItemKind::Type(folder.fold_ty(ty)),
851+
},
852+
span: folder.new_span(i.span),
853+
}
862854
}
863855

864856
pub fn noop_fold_mod<T: Folder>(Mod { inner, item_ids }: Mod, folder: &mut T) -> Mod {
@@ -935,24 +927,22 @@ pub fn noop_fold_item<T: Folder>(item: Item, folder: &mut T) -> Item {
935927
}
936928
}
937929

938-
pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) -> P<ForeignItem> {
939-
ni.map(|ForeignItem { id, name, attrs, node, span, vis }| {
940-
ForeignItem {
941-
id: folder.new_id(id),
942-
name: folder.fold_name(name),
943-
attrs: fold_attrs(attrs, folder),
944-
node: match node {
945-
ForeignItemFn(fdec, generics) => {
946-
ForeignItemFn(folder.fold_fn_decl(fdec), folder.fold_generics(generics))
947-
}
948-
ForeignItemStatic(t, m) => {
949-
ForeignItemStatic(folder.fold_ty(t), m)
950-
}
951-
},
952-
vis: vis,
953-
span: folder.new_span(span),
954-
}
955-
})
930+
pub fn noop_fold_foreign_item<T: Folder>(ni: ForeignItem, folder: &mut T) -> ForeignItem {
931+
ForeignItem {
932+
id: folder.new_id(ni.id),
933+
name: folder.fold_name(ni.name),
934+
attrs: fold_attrs(ni.attrs, folder),
935+
node: match ni.node {
936+
ForeignItemFn(fdec, generics) => {
937+
ForeignItemFn(folder.fold_fn_decl(fdec), folder.fold_generics(generics))
938+
}
939+
ForeignItemStatic(t, m) => {
940+
ForeignItemStatic(folder.fold_ty(t), m)
941+
}
942+
},
943+
vis: ni.vis,
944+
span: folder.new_span(ni.span),
945+
}
956946
}
957947

958948
pub fn noop_fold_method_sig<T: Folder>(sig: MethodSig, folder: &mut T) -> MethodSig {
@@ -1147,32 +1137,29 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: &
11471137
}
11481138
}
11491139

1150-
pub fn noop_fold_stmt<T: Folder>(stmt: P<Stmt>, folder: &mut T)
1151-
-> P<Stmt> {
1152-
stmt.map(|Spanned { node, span }| {
1153-
let span = folder.new_span(span);
1154-
match node {
1155-
StmtDecl(d, id) => {
1156-
let id = folder.new_id(id);
1157-
Spanned {
1158-
node: StmtDecl(folder.fold_decl(d), id),
1159-
span: span
1160-
}
1140+
pub fn noop_fold_stmt<T: Folder>(stmt: Stmt, folder: &mut T) -> Stmt {
1141+
let span = folder.new_span(stmt.span);
1142+
match stmt.node {
1143+
StmtDecl(d, id) => {
1144+
let id = folder.new_id(id);
1145+
Spanned {
1146+
node: StmtDecl(folder.fold_decl(d), id),
1147+
span: span
11611148
}
1162-
StmtExpr(e, id) => {
1163-
let id = folder.new_id(id);
1164-
Spanned {
1165-
node: StmtExpr(folder.fold_expr(e), id),
1166-
span: span,
1167-
}
1149+
}
1150+
StmtExpr(e, id) => {
1151+
let id = folder.new_id(id);
1152+
Spanned {
1153+
node: StmtExpr(folder.fold_expr(e), id),
1154+
span: span,
11681155
}
1169-
StmtSemi(e, id) => {
1170-
let id = folder.new_id(id);
1171-
Spanned {
1172-
node: StmtSemi(folder.fold_expr(e), id),
1173-
span: span,
1174-
}
1156+
}
1157+
StmtSemi(e, id) => {
1158+
let id = folder.new_id(id);
1159+
Spanned {
1160+
node: StmtSemi(folder.fold_expr(e), id),
1161+
span: span,
11751162
}
11761163
}
1177-
})
1164+
}
11781165
}

0 commit comments

Comments
 (0)