about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-05-23 19:02:26 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-05-23 19:02:26 +0200
commitf15e4b30c0d217b647e443333902ca7a948e0f58 (patch)
treecd1c17b85b02c162afc5c975d2fe7fbc670b74ca /src
parent810dbf7770cfaa52ed5cdc2f833fa11e4034c029 (diff)
downloadrust-f15e4b30c0d217b647e443333902ca7a948e0f58.tar.gz
rust-f15e4b30c0d217b647e443333902ca7a948e0f58.zip
fix Predicate perf regression
Diffstat (limited to 'src')
-rw-r--r--src/librustc_infer/traits/util.rs30
-rw-r--r--src/librustc_middle/ty/mod.rs7
2 files changed, 17 insertions, 20 deletions
diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs
index 03f20c13068..17b7b4e680f 100644
--- a/src/librustc_infer/traits/util.rs
+++ b/src/librustc_infer/traits/util.rs
@@ -10,50 +10,44 @@ pub fn anonymize_predicate<'tcx>(
     tcx: TyCtxt<'tcx>,
     pred: ty::Predicate<'tcx>,
 ) -> ty::Predicate<'tcx> {
-    match pred.kind() {
+    let kind = pred.kind();
+    let new = match kind {
         &ty::PredicateKind::Trait(ref data, constness) => {
             ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
-                .to_predicate(tcx)
         }
 
         ty::PredicateKind::RegionOutlives(data) => {
             ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
-                .to_predicate(tcx)
         }
 
         ty::PredicateKind::TypeOutlives(data) => {
             ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
-                .to_predicate(tcx)
         }
 
         ty::PredicateKind::Projection(data) => {
-            ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
+            ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data))
         }
 
-        &ty::PredicateKind::WellFormed(data) => {
-            ty::PredicateKind::WellFormed(data).to_predicate(tcx)
-        }
+        &ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
 
-        &ty::PredicateKind::ObjectSafe(data) => {
-            ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
-        }
+        &ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
 
         &ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
-            ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
+            ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
         }
 
         ty::PredicateKind::Subtype(data) => {
-            ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
+            ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data))
         }
 
         &ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
-            ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
+            ty::PredicateKind::ConstEvaluatable(def_id, substs)
         }
 
-        ty::PredicateKind::ConstEquate(c1, c2) => {
-            ty::PredicateKind::ConstEquate(c1, c2).to_predicate(tcx)
-        }
-    }
+        ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
+    };
+
+    if new != *kind { new.to_predicate(tcx) } else { pred }
 }
 
 struct PredicateSet<'tcx> {
diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs
index 877784bc506..8fa7061998f 100644
--- a/src/librustc_middle/ty/mod.rs
+++ b/src/librustc_middle/ty/mod.rs
@@ -1032,6 +1032,7 @@ impl<'tcx> PartialEq for Predicate<'tcx> {
 impl<'tcx> Eq for Predicate<'tcx> {}
 
 impl<'tcx> Predicate<'tcx> {
+    #[inline(always)]
     pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
         self.kind
     }
@@ -1166,7 +1167,8 @@ impl<'tcx> Predicate<'tcx> {
         // this trick achieves that).
 
         let substs = &trait_ref.skip_binder().substs;
-        let predicate = match self.kind() {
+        let kind = self.kind();
+        let new = match kind {
             &PredicateKind::Trait(ref binder, constness) => {
                 PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
             }
@@ -1195,7 +1197,7 @@ impl<'tcx> Predicate<'tcx> {
             }
         };
 
-        predicate.to_predicate(tcx)
+        if new != *kind { new.to_predicate(tcx) } else { self }
     }
 }
 
@@ -1314,6 +1316,7 @@ pub trait ToPredicate<'tcx> {
 }
 
 impl ToPredicate<'tcx> for PredicateKind<'tcx> {
+    #[inline(always)]
     fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         tcx.mk_predicate(*self)
     }