Skip to content

Commit 8b0440a

Browse files
committed
Don't cache stable hashes in types outside of incremental mode
1 parent 8d4f4e4 commit 8b0440a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Diff for: compiler/rustc_middle/src/ty/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ impl<'tcx> CtxtInterners<'tcx> {
153153
.intern(kind, |kind| {
154154
let flags = super::flags::FlagComputation::for_kind(&kind);
155155

156-
let stable_hash = if flags.flags.intersects(TypeFlags::HAS_RE_INFER) {
156+
// It's impossible to hash inference regions (and will ICE), so we don't need to try to cache them.
157+
// Without incremental, we rarely stable-hash types, so let's not do it proactively.
158+
let stable_hash = if flags.flags.intersects(TypeFlags::HAS_RE_INFER)
159+
|| sess.opts.incremental.is_none()
160+
{
157161
Fingerprint::ZERO
158162
} else {
159163
let mut hasher = StableHasher::new();

Diff for: compiler/rustc_middle/src/ty/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,20 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Ty<'tcx> {
464464
stable_hash,
465465
} = self.0.0;
466466

467-
assert_ne!(*stable_hash, Fingerprint::ZERO, "{:#?}", kind);
468-
stable_hash.hash_stable(hcx, hasher);
467+
if *stable_hash == Fingerprint::ZERO {
468+
// No cached hash available. This can only mean that incremental is disabled.
469+
// We don't cache stable hashes in non-incremental mode, because they are used
470+
// so rarely that the performance actually suffers.
471+
472+
let stable_hash: Fingerprint = {
473+
let mut hasher = StableHasher::new();
474+
kind.hash_stable(hcx, &mut hasher);
475+
hasher.finish()
476+
};
477+
stable_hash.hash_stable(hcx, hasher);
478+
} else {
479+
stable_hash.hash_stable(hcx, hasher);
480+
}
469481
}
470482
}
471483

0 commit comments

Comments
 (0)