Skip to content

Commit ac4439c

Browse files
Reuse Hash impls for session data structures
1 parent 7f138e1 commit ac4439c

File tree

4 files changed

+13
-45
lines changed

4 files changed

+13
-45
lines changed

src/librustc/ich/fingerprint.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,7 @@ impl stable_hasher::StableHasherResult for Fingerprint {
9292
}
9393
}
9494

95-
impl<CTX> stable_hasher::HashStable<CTX> for Fingerprint {
96-
#[inline]
97-
fn hash_stable<W: stable_hasher::StableHasherResult>(&self,
98-
_: &mut CTX,
99-
hasher: &mut stable_hasher::StableHasher<W>) {
100-
::std::hash::Hash::hash(self, hasher);
101-
}
102-
}
95+
impl_stable_hash_via_hash!(Fingerprint);
10396

10497
impl serialize::UseSpecializedEncodable for Fingerprint { }
10598

src/librustc/session/config.rs

+4-32
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ use std::str::FromStr;
1616
use session::{early_error, early_warn, Session};
1717
use session::search_paths::SearchPaths;
1818

19-
use ich::StableHashingContext;
2019
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
2120
use rustc_target::spec::{Target, TargetTriple};
22-
use rustc_data_structures::stable_hasher::ToStableHashKey;
2321
use lint;
2422
use middle::cstore;
2523

@@ -126,25 +124,7 @@ pub enum OutputType {
126124
DepInfo,
127125
}
128126

129-
130-
impl_stable_hash_for!(enum self::OutputType {
131-
Bitcode,
132-
Assembly,
133-
LlvmAssembly,
134-
Mir,
135-
Metadata,
136-
Object,
137-
Exe,
138-
DepInfo
139-
});
140-
141-
impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for OutputType {
142-
type KeyType = OutputType;
143-
#[inline]
144-
fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> Self::KeyType {
145-
*self
146-
}
147-
}
127+
impl_stable_hash_via_hash!(OutputType);
148128

149129
impl OutputType {
150130
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
@@ -233,9 +213,7 @@ impl Default for ErrorOutputType {
233213
#[derive(Clone, Hash)]
234214
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
235215

236-
impl_stable_hash_for!(tuple_struct self::OutputTypes {
237-
map
238-
});
216+
impl_stable_hash_via_hash!(OutputTypes);
239217

240218
impl OutputTypes {
241219
pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
@@ -512,7 +490,7 @@ impl Input {
512490
}
513491
}
514492

515-
#[derive(Clone)]
493+
#[derive(Clone, Hash)]
516494
pub struct OutputFilenames {
517495
pub out_directory: PathBuf,
518496
pub out_filestem: String,
@@ -521,13 +499,7 @@ pub struct OutputFilenames {
521499
pub outputs: OutputTypes,
522500
}
523501

524-
impl_stable_hash_for!(struct self::OutputFilenames {
525-
out_directory,
526-
out_filestem,
527-
single_output_file,
528-
extra,
529-
outputs
530-
});
502+
impl_stable_hash_via_hash!(OutputFilenames);
531503

532504
pub const RUST_CGU_EXT: &str = "rcgu";
533505

src/librustc/session/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ impl From<Fingerprint> for CrateDisambiguator {
12351235
}
12361236
}
12371237

1238-
impl_stable_hash_for!(tuple_struct CrateDisambiguator { fingerprint });
1238+
impl_stable_hash_via_hash!(CrateDisambiguator);
12391239

12401240
/// Holds data on the current incremental compilation session, if there is one.
12411241
#[derive(Debug)]

src/librustc_data_structures/stable_hasher.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,16 @@ pub trait ToStableHashKey<HCX> {
183183

184184
// Implement HashStable by just calling `Hash::hash()`. This works fine for
185185
// self-contained values that don't depend on the hashing context `CTX`.
186+
#[macro_export]
186187
macro_rules! impl_stable_hash_via_hash {
187188
($t:ty) => (
188-
impl<CTX> HashStable<CTX> for $t {
189+
impl<CTX> $crate::stable_hasher::HashStable<CTX> for $t {
189190
#[inline]
190-
fn hash_stable<W: StableHasherResult>(&self,
191-
_: &mut CTX,
192-
hasher: &mut StableHasher<W>) {
191+
fn hash_stable<W: $crate::stable_hasher::StableHasherResult>(
192+
&self,
193+
_: &mut CTX,
194+
hasher: &mut $crate::stable_hasher::StableHasher<W>
195+
) {
193196
::std::hash::Hash::hash(self, hasher);
194197
}
195198
}

0 commit comments

Comments
 (0)