Skip to content

Commit a31bb34

Browse files
committed
Make HashStable::hash_stable generic over ExtendedHasher
1 parent 4bd7fdc commit a31bb34

File tree

44 files changed

+276
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+276
-148
lines changed

compiler/rustc_ast/src/ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{cmp, fmt, mem};
2323

2424
pub use rustc_ast_ir::{Movability, Mutability};
2525
use rustc_data_structures::packed::Pu128;
26-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
26+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
2727
use rustc_data_structures::stack::ensure_sufficient_stack;
2828
use rustc_data_structures::sync::Lrc;
2929
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
@@ -105,7 +105,7 @@ impl PartialEq<Symbol> for Path {
105105
}
106106

107107
impl<CTX: rustc_span::HashStableContext> HashStable<CTX> for Path {
108-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
108+
fn hash_stable<H: ExtendedHasher>(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
109109
self.segments.len().hash_stable(hcx, hasher);
110110
for segment in &self.segments {
111111
segment.ident.hash_stable(hcx, hasher);
@@ -1719,7 +1719,7 @@ impl<CTX> HashStable<CTX> for AttrArgs
17191719
where
17201720
CTX: crate::HashStableContext,
17211721
{
1722-
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
1722+
fn hash_stable<H: ExtendedHasher>(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
17231723
mem::discriminant(self).hash_stable(ctx, hasher);
17241724
match self {
17251725
AttrArgs::Empty => {}
@@ -1755,7 +1755,7 @@ impl<CTX> HashStable<CTX> for DelimArgs
17551755
where
17561756
CTX: crate::HashStableContext,
17571757
{
1758-
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
1758+
fn hash_stable<H: ExtendedHasher>(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
17591759
let DelimArgs { dspan, delim, tokens } = self;
17601760
dspan.hash_stable(ctx, hasher);
17611761
delim.hash_stable(ctx, hasher);

compiler/rustc_ast/src/lib.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub mod token;
4343
pub mod tokenstream;
4444
pub mod visit;
4545

46-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
46+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
4747

4848
pub use self::ast::*;
4949
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
@@ -52,11 +52,19 @@ pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTok
5252
/// This is a hack to allow using the `HashStable_Generic` derive macro
5353
/// instead of implementing everything in `rustc_middle`.
5454
pub trait HashStableContext: rustc_span::HashStableContext {
55-
fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher);
55+
fn hash_attr<H: ExtendedHasher>(
56+
&mut self,
57+
_: &ast::Attribute,
58+
hasher: &mut GenericStableHasher<H>,
59+
);
5660
}
5761

5862
impl<AstCtx: crate::HashStableContext> HashStable<AstCtx> for ast::Attribute {
59-
fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) {
63+
fn hash_stable<H: ExtendedHasher>(
64+
&self,
65+
hcx: &mut AstCtx,
66+
hasher: &mut GenericStableHasher<H>,
67+
) {
6068
hcx.hash_attr(self, hasher)
6169
}
6270
}

compiler/rustc_ast/src/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::fmt::{self, Debug, Display};
2121
use std::ops::{Deref, DerefMut};
2222
use std::{slice, vec};
2323

24-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
24+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
2525
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2626
/// An owned smart pointer.
2727
///
@@ -203,7 +203,7 @@ impl<CTX, T> HashStable<CTX> for P<T>
203203
where
204204
T: ?Sized + HashStable<CTX>,
205205
{
206-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
206+
fn hash_stable<H: ExtendedHasher>(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
207207
(**self).hash_stable(hcx, hasher);
208208
}
209209
}

compiler/rustc_ast/src/token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22
use std::fmt;
33

4-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
55
use rustc_data_structures::sync::Lrc;
66
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
77
use rustc_span::edition::Edition;
@@ -1055,7 +1055,7 @@ impl<CTX> HashStable<CTX> for Nonterminal
10551055
where
10561056
CTX: crate::HashStableContext,
10571057
{
1058-
fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) {
1058+
fn hash_stable<H: ExtendedHasher>(&self, _hcx: &mut CTX, _hasher: &mut GenericStableHasher<H>) {
10591059
panic!("interpolated tokens should not be present in the HIR")
10601060
}
10611061
}

compiler/rustc_ast/src/tokenstream.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use std::borrow::Cow;
1717
use std::{cmp, fmt, iter};
1818

19-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
19+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
2020
use rustc_data_structures::sync::{self, Lrc};
2121
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2222
use rustc_serialize::{Decodable, Encodable};
@@ -99,7 +99,7 @@ impl<CTX> HashStable<CTX> for TokenStream
9999
where
100100
CTX: crate::HashStableContext,
101101
{
102-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
102+
fn hash_stable<H: ExtendedHasher>(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
103103
for sub_tt in self.trees() {
104104
sub_tt.hash_stable(hcx, hasher);
105105
}
@@ -151,7 +151,7 @@ impl<D: SpanDecoder> Decodable<D> for LazyAttrTokenStream {
151151
}
152152

153153
impl<CTX> HashStable<CTX> for LazyAttrTokenStream {
154-
fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) {
154+
fn hash_stable<H: ExtendedHasher>(&self, _hcx: &mut CTX, _hasher: &mut GenericStableHasher<H>) {
155155
panic!("Attempted to compute stable hash for LazyAttrTokenStream");
156156
}
157157
}

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_codegen_ssa::{
1515
errors as ssa_errors, CodegenResults, CompiledModule, CrateInfo, ModuleKind,
1616
};
1717
use rustc_data_structures::profiling::SelfProfilerRef;
18-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
18+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
1919
use rustc_data_structures::sync::{par_map, IntoDynSyncSend};
2020
use rustc_metadata::fs::copy_to_stdout;
2121
use rustc_metadata::EncodedMetadata;
@@ -43,7 +43,7 @@ enum OngoingModuleCodegen {
4343
}
4444

4545
impl<HCX> HashStable<HCX> for OngoingModuleCodegen {
46-
fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) {
46+
fn hash_stable<H: ExtendedHasher>(&self, _: &mut HCX, _: &mut GenericStableHasher<H>) {
4747
// do nothing
4848
}
4949
}

compiler/rustc_codegen_ssa/src/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ pub enum TypeKind {
105105
// for now we content ourselves with providing a no-op HashStable
106106
// implementation for CGUs.
107107
mod temp_stable_hash_impls {
108-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
108+
use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
109109

110110
use crate::ModuleCodegen;
111111

112112
impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
113-
fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) {
113+
fn hash_stable<H: ExtendedHasher>(&self, _: &mut HCX, _: &mut GenericStableHasher<H>) {
114114
// do nothing
115115
}
116116
}

compiler/rustc_data_structures/src/intern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher};
44
use std::ops::Deref;
55
use std::ptr;
66

7-
use crate::stable_hasher::{HashStable, StableHasher};
7+
use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
88

99
mod private {
1010
#[derive(Clone, Copy, Debug)]
@@ -104,7 +104,7 @@ impl<T, CTX> HashStable<CTX> for Interned<'_, T>
104104
where
105105
T: HashStable<CTX>,
106106
{
107-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
107+
fn hash_stable<H: ExtendedHasher>(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
108108
self.0.hash_stable(hcx, hasher);
109109
}
110110
}

compiler/rustc_data_structures/src/packed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33

44
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
55

6-
use crate::stable_hasher::{HashStable, StableHasher};
6+
use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
77

88
/// A packed 128-bit integer. Useful for reducing the size of structures in
99
/// some cases.
@@ -55,7 +55,7 @@ impl fmt::UpperHex for Pu128 {
5555

5656
impl<CTX> HashStable<CTX> for Pu128 {
5757
#[inline]
58-
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
58+
fn hash_stable<H: ExtendedHasher>(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
5959
{ self.0 }.hash_stable(ctx, hasher)
6060
}
6161
}

compiler/rustc_data_structures/src/sorted_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{Bound, Index, IndexMut, RangeBounds};
55

66
use rustc_macros::{Decodable_Generic, Encodable_Generic};
77

8-
use crate::stable_hasher::{HashStable, StableHasher, StableOrd};
8+
use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable, StableOrd};
99

1010
mod index_map;
1111

@@ -311,7 +311,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for SortedMap<K, V> {
311311

312312
impl<K: HashStable<CTX> + StableOrd, V: HashStable<CTX>, CTX> HashStable<CTX> for SortedMap<K, V> {
313313
#[inline]
314-
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
314+
fn hash_stable<H: ExtendedHasher>(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher<H>) {
315315
self.data.hash_stable(ctx, hasher);
316316
}
317317
}

compiler/rustc_data_structures/src/sorted_map/index_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher};
44

55
use rustc_index::{Idx, IndexVec};
66

7-
use crate::stable_hasher::{HashStable, StableHasher};
7+
use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable};
88

99
/// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of
1010
/// an item by key and *O*(1) lookup by index.
@@ -131,7 +131,7 @@ where
131131
K: HashStable<C>,
132132
V: HashStable<C>,
133133
{
134-
fn hash_stable(&self, ctx: &mut C, hasher: &mut StableHasher) {
134+
fn hash_stable<H: ExtendedHasher>(&self, ctx: &mut C, hasher: &mut GenericStableHasher<H>) {
135135
let SortedIndexMultiMap {
136136
items,
137137
// We can ignore this field because it is not observable from the outside.

0 commit comments

Comments
 (0)