]> git.lizzy.rs Git - rust.git/commitdiff
Reuse Hash impls for session data structures
authorMark Rousskov <mark.simulacrum@gmail.com>
Fri, 3 Aug 2018 22:41:30 +0000 (16:41 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Thu, 9 Aug 2018 16:00:25 +0000 (10:00 -0600)
src/librustc/ich/fingerprint.rs
src/librustc/session/config.rs
src/librustc/session/mod.rs
src/librustc_data_structures/stable_hasher.rs

index a6e35d78dcb5aaef76b09a3ed1cb7c9f03cd4b76..f00c5a649d274a95e311acb735888b09402f957a 100644 (file)
@@ -92,14 +92,7 @@ fn finish(hasher: stable_hasher::StableHasher<Self>) -> Self {
     }
 }
 
-impl<CTX> stable_hasher::HashStable<CTX> for Fingerprint {
-    #[inline]
-    fn hash_stable<W: stable_hasher::StableHasherResult>(&self,
-                                          _: &mut CTX,
-                                          hasher: &mut stable_hasher::StableHasher<W>) {
-        ::std::hash::Hash::hash(self, hasher);
-    }
-}
+impl_stable_hash_via_hash!(Fingerprint);
 
 impl serialize::UseSpecializedEncodable for Fingerprint { }
 
index dddf921aec68c232ac664de80e8aaef21c2ed5af..ef1052d562e5584db33003e9672eb28d6f42bc9a 100644 (file)
 use session::{early_error, early_warn, Session};
 use session::search_paths::SearchPaths;
 
-use ich::StableHashingContext;
 use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
 use rustc_target::spec::{Target, TargetTriple};
-use rustc_data_structures::stable_hasher::ToStableHashKey;
 use lint;
 use middle::cstore;
 
@@ -126,25 +124,7 @@ pub enum OutputType {
     DepInfo,
 }
 
-
-impl_stable_hash_for!(enum self::OutputType {
-    Bitcode,
-    Assembly,
-    LlvmAssembly,
-    Mir,
-    Metadata,
-    Object,
-    Exe,
-    DepInfo
-});
-
-impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for OutputType {
-    type KeyType = OutputType;
-    #[inline]
-    fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> Self::KeyType {
-        *self
-    }
-}
+impl_stable_hash_via_hash!(OutputType);
 
 impl OutputType {
     fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
@@ -233,9 +213,7 @@ fn default() -> ErrorOutputType {
 #[derive(Clone, Hash)]
 pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
 
-impl_stable_hash_for!(tuple_struct self::OutputTypes {
-    map
-});
+impl_stable_hash_via_hash!(OutputTypes);
 
 impl OutputTypes {
     pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
@@ -512,7 +490,7 @@ pub fn get_input(&mut self) -> Option<&mut String> {
     }
 }
 
-#[derive(Clone)]
+#[derive(Clone, Hash)]
 pub struct OutputFilenames {
     pub out_directory: PathBuf,
     pub out_filestem: String,
@@ -521,13 +499,7 @@ pub struct OutputFilenames {
     pub outputs: OutputTypes,
 }
 
-impl_stable_hash_for!(struct self::OutputFilenames {
-    out_directory,
-    out_filestem,
-    single_output_file,
-    extra,
-    outputs
-});
+impl_stable_hash_via_hash!(OutputFilenames);
 
 pub const RUST_CGU_EXT: &str = "rcgu";
 
index 9a3ce50fcbdce90afe83140e8a1d03e178b19b6a..6bbb4d9c6688d5d212569c1b4ccd2867ada15b7f 100644 (file)
@@ -1235,7 +1235,7 @@ fn from(fingerprint: Fingerprint) -> CrateDisambiguator {
     }
 }
 
-impl_stable_hash_for!(tuple_struct CrateDisambiguator { fingerprint });
+impl_stable_hash_via_hash!(CrateDisambiguator);
 
 /// Holds data on the current incremental compilation session, if there is one.
 #[derive(Debug)]
index a8f689e5c81a385af248ab709c0114e4094eee6c..9f1c7dac1194ef3c48f20b46a11e092232204642 100644 (file)
@@ -183,13 +183,16 @@ pub trait ToStableHashKey<HCX> {
 
 // Implement HashStable by just calling `Hash::hash()`. This works fine for
 // self-contained values that don't depend on the hashing context `CTX`.
+#[macro_export]
 macro_rules! impl_stable_hash_via_hash {
     ($t:ty) => (
-        impl<CTX> HashStable<CTX> for $t {
+        impl<CTX> $crate::stable_hasher::HashStable<CTX> for $t {
             #[inline]
-            fn hash_stable<W: StableHasherResult>(&self,
-                                                  _: &mut CTX,
-                                                  hasher: &mut StableHasher<W>) {
+            fn hash_stable<W: $crate::stable_hasher::StableHasherResult>(
+                &self,
+                _: &mut CTX,
+                hasher: &mut $crate::stable_hasher::StableHasher<W>
+            ) {
                 ::std::hash::Hash::hash(self, hasher);
             }
         }