Skip to content

Commit 6ffd654

Browse files
committed
Check that the cached stable hash is the right one if debug assertions are enabled
1 parent 33d0ce9 commit 6ffd654

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/rustc_data_structures/src/intern.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ impl<T: Hash> Hash for InTy<T> {
160160

161161
impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for InTy<T> {
162162
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
163-
let stable_hash = self.stable_hash;
164-
165-
if stable_hash == Fingerprint::ZERO {
163+
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
166164
// No cached hash available. This can only mean that incremental is disabled.
167165
// We don't cache stable hashes in non-incremental mode, because they are used
168166
// so rarely that the performance actually suffers.
@@ -174,9 +172,15 @@ impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for InTy<T
174172
hcx.with_def_path_and_no_spans(|hcx| self.internee.hash_stable(hcx, &mut hasher));
175173
hasher.finish()
176174
};
175+
if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO {
176+
assert_eq!(
177+
stable_hash, self.stable_hash,
178+
"cached stable hash does not match freshly computed stable hash"
179+
);
180+
}
177181
stable_hash.hash_stable(hcx, hasher);
178182
} else {
179-
stable_hash.hash_stable(hcx, hasher);
183+
self.stable_hash.hash_stable(hcx, hasher);
180184
}
181185
}
182186
}

0 commit comments

Comments
 (0)