about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-04-05 16:42:47 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-04-07 13:01:48 +0000
commit2e0ef701c2e8ecb03ccebdc268980ec6d62a4a39 (patch)
tree548cb7f1af301e818aceb243fa82933fe9786577 /compiler/rustc_data_structures/src
parent6ffd654683900a81adda24b3a86e4c30fee31214 (diff)
downloadrust-2e0ef701c2e8ecb03ccebdc268980ec6d62a4a39.tar.gz
rust-2e0ef701c2e8ecb03ccebdc268980ec6d62a4a39.zip
Document and rename the new wrapper type
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/intern.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs
index bd62f30372e..009b5d5340a 100644
--- a/compiler/rustc_data_structures/src/intern.rs
+++ b/compiler/rustc_data_structures/src/intern.rs
@@ -115,34 +115,41 @@ pub trait InternedHashingContext {
     fn with_def_path_and_no_spans(&mut self, f: impl FnOnce(&mut Self));
 }
 
+/// A helper type that you can wrap round your own type in order to automatically
+/// cache the stable hash on creation and not recompute it whenever the stable hash
+/// of the type is computed.
+/// This is only done in incremental mode. You can also opt out of caching by using
+/// StableHash::ZERO for the hash, in which case the hash gets computed each time.
+/// This is useful if you have values that you intern but never (can?) use for stable
+/// hashing.
 #[derive(Copy, Clone)]
-pub struct InTy<T> {
+pub struct WithStableHash<T> {
     pub internee: T,
     pub stable_hash: Fingerprint,
 }
 
-impl<T: PartialEq> PartialEq for InTy<T> {
+impl<T: PartialEq> PartialEq for WithStableHash<T> {
     #[inline]
     fn eq(&self, other: &Self) -> bool {
         self.internee.eq(&other.internee)
     }
 }
 
-impl<T: Eq> Eq for InTy<T> {}
+impl<T: Eq> Eq for WithStableHash<T> {}
 
-impl<T: Ord> PartialOrd for InTy<T> {
-    fn partial_cmp(&self, other: &InTy<T>) -> Option<Ordering> {
+impl<T: Ord> PartialOrd for WithStableHash<T> {
+    fn partial_cmp(&self, other: &WithStableHash<T>) -> Option<Ordering> {
         Some(self.internee.cmp(&other.internee))
     }
 }
 
-impl<T: Ord> Ord for InTy<T> {
-    fn cmp(&self, other: &InTy<T>) -> Ordering {
+impl<T: Ord> Ord for WithStableHash<T> {
+    fn cmp(&self, other: &WithStableHash<T>) -> Ordering {
         self.internee.cmp(&other.internee)
     }
 }
 
-impl<T> Deref for InTy<T> {
+impl<T> Deref for WithStableHash<T> {
     type Target = T;
 
     #[inline]
@@ -151,14 +158,14 @@ impl<T> Deref for InTy<T> {
     }
 }
 
-impl<T: Hash> Hash for InTy<T> {
+impl<T: Hash> Hash for WithStableHash<T> {
     #[inline]
     fn hash<H: Hasher>(&self, s: &mut H) {
         self.internee.hash(s)
     }
 }
 
-impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for InTy<T> {
+impl<T: HashStable<CTX>, CTX: InternedHashingContext> HashStable<CTX> for WithStableHash<T> {
     fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
         if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
             // No cached hash available. This can only mean that incremental is disabled.