diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2018-08-03 16:41:30 -0600 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2018-08-09 10:00:25 -0600 |
| commit | ac4439c5b6494963bfbee36e34668f844e703015 (patch) | |
| tree | 15f455473d159a63b2d6eb7db03c54758d1d9cf2 | |
| parent | 7f138e1e558828506f8eb801b77f0bfc60d738e0 (diff) | |
| download | rust-ac4439c5b6494963bfbee36e34668f844e703015.tar.gz rust-ac4439c5b6494963bfbee36e34668f844e703015.zip | |
Reuse Hash impls for session data structures
| -rw-r--r-- | src/librustc/ich/fingerprint.rs | 9 | ||||
| -rw-r--r-- | src/librustc/session/config.rs | 36 | ||||
| -rw-r--r-- | src/librustc/session/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/stable_hasher.rs | 11 |
4 files changed, 13 insertions, 45 deletions
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 @@ impl stable_hasher::StableHasherResult for Fingerprint { } } -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 { } 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 std::str::FromStr; 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 @@ impl Default for 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 @@ impl Input { } } -#[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 @@ impl From<Fingerprint> for 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<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); } } |
