Skip to content

Commit a3e9172

Browse files
committed
Auto merge of rust-lang#139292 - compiler-errors:folder-experiment-7, r=<try>
Folder experiment: Micro-optimize RegionEraserVisitor **NOTE:** This is one of a series of perf experiments that I've come up with while sick in bed. I'm assigning them to lqd b/c you're a good reviewer and you'll hopefully be awake when these experiments finish, lol. r? lqd The region eraser is very hot, so let's see if we can avoid erasing types (and visiting consts and preds that don't have region-ful types) unnecessarily.
2 parents d5b4c2e + 9434486 commit a3e9172

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Diff for: compiler/rustc_middle/src/ty/erase_regions.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
4444
}
4545

4646
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
47-
if ty.has_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
47+
if !ty.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
48+
ty
49+
} else if ty.has_infer() {
50+
ty.super_fold_with(self)
51+
} else {
52+
self.tcx.erase_regions_ty(ty)
53+
}
4854
}
4955

5056
fn fold_binder<T>(&mut self, t: ty::Binder<'tcx, T>) -> ty::Binder<'tcx, T>
@@ -64,4 +70,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
6470
_ => self.tcx.lifetimes.re_erased,
6571
}
6672
}
73+
74+
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
75+
if ct.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
76+
ct.super_fold_with(self)
77+
} else {
78+
ct
79+
}
80+
}
81+
82+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
83+
if p.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
84+
p.super_fold_with(self)
85+
} else {
86+
p
87+
}
88+
}
6789
}

0 commit comments

Comments
 (0)