From: Mark Rousskov Date: Fri, 3 Aug 2018 22:41:30 +0000 (-0600) Subject: Reuse Hash impls for session data structures X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=ac4439c5b6494963bfbee36e34668f844e703015;p=rust.git Reuse Hash impls for session data structures --- diff --git a/src/librustc/ich/fingerprint.rs b/src/librustc/ich/fingerprint.rs index a6e35d78dcb..f00c5a649d2 100644 --- a/src/librustc/ich/fingerprint.rs +++ b/src/librustc/ich/fingerprint.rs @@ -92,14 +92,7 @@ fn finish(hasher: stable_hasher::StableHasher) -> Self { } } -impl stable_hasher::HashStable for Fingerprint { - #[inline] - fn hash_stable(&self, - _: &mut CTX, - hasher: &mut stable_hasher::StableHasher) { - ::std::hash::Hash::hash(self, hasher); - } -} +impl_stable_hash_via_hash!(Fingerprint); impl serialize::UseSpecializedEncodable for Fingerprint { } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index dddf921aec6..ef1052d562e 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -16,10 +16,8 @@ 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> 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>); -impl_stable_hash_for!(tuple_struct self::OutputTypes { - map -}); +impl_stable_hash_via_hash!(OutputTypes); impl OutputTypes { pub fn new(entries: &[(OutputType, Option)]) -> 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"; diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 9a3ce50fcbd..6bbb4d9c668 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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)] diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index a8f689e5c81..9f1c7dac119 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -183,13 +183,16 @@ pub trait ToStableHashKey { // 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 HashStable for $t { + impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable(&self, - _: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable( + &self, + _: &mut CTX, + hasher: &mut $crate::stable_hasher::StableHasher + ) { ::std::hash::Hash::hash(self, hasher); } }