Skip to content

Commit 57ad505

Browse files
committed
Auto merge of rust-lang#119084 - aliemjay:perf-env-bounds, r=compiler-errors
fast path for declared_generic_bounds_from_env ~2% perf gain for diesel
2 parents 3a539c0 + 27e964d commit 57ad505

File tree

1 file changed

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

1 file changed

+12
-2
lines changed

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

+12-2
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,20 @@ 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 (&p, erased_ty.kind()) {
245+
// In outlive routines, all types are expected to be fully normalized.
246+
// And therefore we can safely use structural equality for alias types.
247+
(GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {}
248+
(GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {}
249+
(GenericKind::Alias(a1), ty::Alias(_, a2)) if a1.def_id == a2.def_id => {}
250+
_ => return None,
251+
}
252+
243253
let p_ty = p.to_ty(tcx);
244254
let erased_p_ty = self.tcx.erase_regions(p_ty);
245255
(erased_p_ty == erased_ty)
246-
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p.to_ty(tcx), r)))
256+
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r)))
247257
});
248258

249259
param_bounds

0 commit comments

Comments
 (0)