Skip to content

Commit f15e4b3

Browse files
committed
fix Predicate perf regression
1 parent 810dbf7 commit f15e4b3

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/librustc_infer/traits/util.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,44 @@ pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
1111
pred: ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
13-
match pred.kind() {
13+
let kind = pred.kind();
14+
let new = match kind {
1415
&ty::PredicateKind::Trait(ref data, constness) => {
1516
ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
16-
.to_predicate(tcx)
1717
}
1818

1919
ty::PredicateKind::RegionOutlives(data) => {
2020
ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
21-
.to_predicate(tcx)
2221
}
2322

2423
ty::PredicateKind::TypeOutlives(data) => {
2524
ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
26-
.to_predicate(tcx)
2725
}
2826

2927
ty::PredicateKind::Projection(data) => {
30-
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
28+
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data))
3129
}
3230

33-
&ty::PredicateKind::WellFormed(data) => {
34-
ty::PredicateKind::WellFormed(data).to_predicate(tcx)
35-
}
31+
&ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
3632

37-
&ty::PredicateKind::ObjectSafe(data) => {
38-
ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
39-
}
33+
&ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
4034

4135
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
42-
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
36+
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
4337
}
4438

4539
ty::PredicateKind::Subtype(data) => {
46-
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
40+
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data))
4741
}
4842

4943
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
50-
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
44+
ty::PredicateKind::ConstEvaluatable(def_id, substs)
5145
}
5246

53-
ty::PredicateKind::ConstEquate(c1, c2) => {
54-
ty::PredicateKind::ConstEquate(c1, c2).to_predicate(tcx)
55-
}
56-
}
47+
ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
48+
};
49+
50+
if new != *kind { new.to_predicate(tcx) } else { pred }
5751
}
5852

5953
struct PredicateSet<'tcx> {

src/librustc_middle/ty/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ impl<'tcx> PartialEq for Predicate<'tcx> {
10321032
impl<'tcx> Eq for Predicate<'tcx> {}
10331033

10341034
impl<'tcx> Predicate<'tcx> {
1035+
#[inline(always)]
10351036
pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
10361037
self.kind
10371038
}
@@ -1166,7 +1167,8 @@ impl<'tcx> Predicate<'tcx> {
11661167
// this trick achieves that).
11671168

11681169
let substs = &trait_ref.skip_binder().substs;
1169-
let predicate = match self.kind() {
1170+
let kind = self.kind();
1171+
let new = match kind {
11701172
&PredicateKind::Trait(ref binder, constness) => {
11711173
PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
11721174
}
@@ -1195,7 +1197,7 @@ impl<'tcx> Predicate<'tcx> {
11951197
}
11961198
};
11971199

1198-
predicate.to_predicate(tcx)
1200+
if new != *kind { new.to_predicate(tcx) } else { self }
11991201
}
12001202
}
12011203

@@ -1314,6 +1316,7 @@ pub trait ToPredicate<'tcx> {
13141316
}
13151317

13161318
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
1319+
#[inline(always)]
13171320
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
13181321
tcx.mk_predicate(*self)
13191322
}

0 commit comments

Comments
 (0)