Skip to content

Commit e0a7b59

Browse files
committed
Auto merge of #119084 - aliemjay:perf-env-bounds, r=<try>
fast path for declared_generic_bounds_from_env ~2% perf gain for diesel
2 parents a7690a3 + 20e222a commit e0a7b59

File tree

1 file changed

+11
-2
lines changed
  • compiler/rustc_infer/src/infer/outlives

1 file changed

+11
-2
lines changed

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::infer::outlives::components::{compute_alias_components_recursive, Component};
22
use crate::infer::outlives::env::RegionBoundPairs;
33
use crate::infer::region_constraints::VerifyIfEq;
4-
use crate::infer::VerifyBound;
4+
use crate::infer::{GenericKind, VerifyBound};
55
use rustc_data_structures::sso::SsoHashSet;
66
use rustc_middle::ty::GenericArg;
77
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
@@ -240,10 +240,19 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
240240
"declared_generic_bounds_from_env_for_erased_ty: region_bound_pair = {:?}",
241241
(r, p)
242242
);
243+
// Fast path for the common case.
244+
match (erased_ty.kind(), &p) {
245+
(ty::Alias(_, a1), GenericKind::Alias(a2)) if a1.def_id != a2.def_id => {
246+
return None;
247+
}
248+
(ty::Param(p1), GenericKind::Param(p2)) if p1 != p2 => return None,
249+
_ => {}
250+
}
251+
243252
let p_ty = p.to_ty(tcx);
244253
let erased_p_ty = self.tcx.erase_regions(p_ty);
245254
(erased_p_ty == erased_ty)
246-
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p.to_ty(tcx), r)))
255+
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r)))
247256
});
248257

249258
param_bounds

0 commit comments

Comments
 (0)