Skip to content

Commit

Permalink
Auto merge of rust-lang#119084 - aliemjay:perf-env-bounds, r=<try>
Browse files Browse the repository at this point in the history
fast path for declared_generic_bounds_from_env

~2% perf gain for diesel
  • Loading branch information
bors committed Dec 18, 2023
2 parents a7690a3 + 20e222a commit e0a7b59
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::infer::outlives::components::{compute_alias_components_recursive, Component};
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::region_constraints::VerifyIfEq;
use crate::infer::VerifyBound;
use crate::infer::{GenericKind, VerifyBound};
use rustc_data_structures::sso::SsoHashSet;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
Expand Down Expand Up @@ -240,10 +240,19 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
"declared_generic_bounds_from_env_for_erased_ty: region_bound_pair = {:?}",
(r, p)
);
// Fast path for the common case.
match (erased_ty.kind(), &p) {
(ty::Alias(_, a1), GenericKind::Alias(a2)) if a1.def_id != a2.def_id => {
return None;
}
(ty::Param(p1), GenericKind::Param(p2)) if p1 != p2 => return None,
_ => {}
}

let p_ty = p.to_ty(tcx);
let erased_p_ty = self.tcx.erase_regions(p_ty);
(erased_p_ty == erased_ty)
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p.to_ty(tcx), r)))
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r)))
});

param_bounds
Expand Down

0 comments on commit e0a7b59

Please sign in to comment.