about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-02-24 13:43:23 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-02-24 13:44:21 +0000
commit8b0440a66942ac1f14707ae25a1efbbe7f24a686 (patch)
treeca9ead8c787441547f23d90764e07b1cd63e5f9a
parent8d4f4e42afc74be02cd3dc040a164a493b41a1bf (diff)
downloadrust-8b0440a66942ac1f14707ae25a1efbbe7f24a686.tar.gz
rust-8b0440a66942ac1f14707ae25a1efbbe7f24a686.zip
Don't cache stable hashes in types outside of incremental mode
-rw-r--r--compiler/rustc_middle/src/ty/context.rs6
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs16
2 files changed, 19 insertions, 3 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 6c0582a240e..2d43724d418 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -153,7 +153,11 @@ impl<'tcx> CtxtInterners<'tcx> {
                 .intern(kind, |kind| {
                     let flags = super::flags::FlagComputation::for_kind(&kind);
 
-                    let stable_hash = if flags.flags.intersects(TypeFlags::HAS_RE_INFER) {
+                    // It's impossible to hash inference regions (and will ICE), so we don't need to try to cache them.
+                    // Without incremental, we rarely stable-hash types, so let's not do it proactively.
+                    let stable_hash = if flags.flags.intersects(TypeFlags::HAS_RE_INFER)
+                        || sess.opts.incremental.is_none()
+                    {
                         Fingerprint::ZERO
                     } else {
                         let mut hasher = StableHasher::new();
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 7a14a568c1c..8f067de3665 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -464,8 +464,20 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Ty<'tcx> {
             stable_hash,
         } = self.0.0;
 
-        assert_ne!(*stable_hash, Fingerprint::ZERO, "{:#?}", kind);
-        stable_hash.hash_stable(hcx, hasher);
+        if *stable_hash == Fingerprint::ZERO {
+            // No cached hash available. This can only mean that incremental is disabled.
+            // We don't cache stable hashes in non-incremental mode, because they are used
+            // so rarely that the performance actually suffers.
+
+            let stable_hash: Fingerprint = {
+                let mut hasher = StableHasher::new();
+                kind.hash_stable(hcx, &mut hasher);
+                hasher.finish()
+            };
+            stable_hash.hash_stable(hcx, hasher);
+        } else {
+            stable_hash.hash_stable(hcx, hasher);
+        }
     }
 }