]> git.lizzy.rs Git - rust.git/commitdiff
perf: Don't recurse into types that do not need normalizing
authorMarkus Westerlind <markus.westerlind@imperva.com>
Thu, 2 Jan 2020 11:14:23 +0000 (12:14 +0100)
committerMarkus Westerlind <markus.westerlind@imperva.com>
Thu, 2 Jan 2020 11:14:23 +0000 (12:14 +0100)
A bit speculative at this stage but profiling shows that type folding
takes up a substantial amount of time during normalization which may
indicate that many types may be folded despite there being nothing to
normalize

src/librustc/traits/project.rs

index c604bf59cbd794c25525209652984ad5afe6bd71..4b59521a348ef7ecc3b12b24b2f5974d6350a1f6 100644 (file)
@@ -316,6 +316,9 @@ fn tcx<'c>(&'c self) -> TyCtxt<'tcx> {
     }
 
     fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
+        if !ty.has_projections() {
+            return ty;
+        }
         // We don't want to normalize associated types that occur inside of region
         // binders, because they may contain bound regions, and we can't cope with that.
         //