diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-03-07 13:31:49 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-03-31 14:54:04 +0000 |
| commit | 6ffd654683900a81adda24b3a86e4c30fee31214 (patch) | |
| tree | 763903156d5b6a536e945f53ca57b4cfb55af891 /compiler/rustc_data_structures/src | |
| parent | 33d0ce95a947d1311af01ad6d3e39b1075c50417 (diff) | |
| download | rust-6ffd654683900a81adda24b3a86e4c30fee31214.tar.gz rust-6ffd654683900a81adda24b3a86e4c30fee31214.zip | |
Check that the cached stable hash is the right one if debug assertions are enabled
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/intern.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index 1b187cd306e..bd62f30372e 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -160,9 +160,7 @@ impl<T: Hash> Hash for InTy<T> { impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for InTy<T> { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - let stable_hash = self.stable_hash; - - if stable_hash == Fingerprint::ZERO { + if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) { // 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. @@ -174,9 +172,15 @@ impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for InTy<T hcx.with_def_path_and_no_spans(|hcx| self.internee.hash_stable(hcx, &mut hasher)); hasher.finish() }; + if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO { + assert_eq!( + stable_hash, self.stable_hash, + "cached stable hash does not match freshly computed stable hash" + ); + } stable_hash.hash_stable(hcx, hasher); } else { - stable_hash.hash_stable(hcx, hasher); + self.stable_hash.hash_stable(hcx, hasher); } } } |
