diff --git a/Cargo.lock b/Cargo.lock index 4bd99b7fbe7ac..16e54b5ea5501 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -275,6 +275,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -1017,6 +1026,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -3227,8 +3237,10 @@ checksum = "5be1bdc7edf596692617627bbfeaba522131b18e06ca4df2b6b689e3c5d5ce84" [[package]] name = "rustc-stable-hash" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c9f15eec8235d7cb775ee6f81891db79b98fd54ba1ad8fae565b88ef1ae4e2" +source = "git+https://github.com/Urgau/rustc-stable-hash.git?rev=543696a#543696a0b6299c4cc8a8c9c30651e5cc0056655a" +dependencies = [ + "blake2", +] [[package]] name = "rustc_abi" @@ -5067,6 +5079,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "suggest-tests" version = "0.1.0" diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index a44ed82850480..b27e8ab2e2ad9 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -23,7 +23,7 @@ use std::{cmp, fmt, mem}; pub use rustc_ast_ir::{Movability, Mutability}; use rustc_data_structures::packed::Pu128; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::sync::Lrc; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; @@ -105,7 +105,7 @@ impl PartialEq for Path { } impl HashStable for Path { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.segments.len().hash_stable(hcx, hasher); for segment in &self.segments { segment.ident.hash_stable(hcx, hasher); @@ -1723,7 +1723,7 @@ impl HashStable for AttrArgs where CTX: crate::HashStableContext, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { mem::discriminant(self).hash_stable(ctx, hasher); match self { AttrArgs::Empty => {} @@ -1759,7 +1759,7 @@ impl HashStable for DelimArgs where CTX: crate::HashStableContext, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let DelimArgs { dspan, delim, tokens } = self; dspan.hash_stable(ctx, hasher); delim.hash_stable(ctx, hasher); diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 27e9f3d137ffd..8759b27dba533 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -43,7 +43,7 @@ pub mod token; pub mod tokenstream; pub mod visit; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; pub use self::ast::*; pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens}; @@ -52,11 +52,19 @@ pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTok /// This is a hack to allow using the `HashStable_Generic` derive macro /// instead of implementing everything in `rustc_middle`. pub trait HashStableContext: rustc_span::HashStableContext { - fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher); + fn hash_attr( + &mut self, + _: &ast::Attribute, + hasher: &mut GenericStableHasher, + ); } impl HashStable for ast::Attribute { - fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut AstCtx, + hasher: &mut GenericStableHasher, + ) { hcx.hash_attr(self, hasher) } } diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index 97c714df8fd2f..90b0c35695743 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -21,7 +21,7 @@ use std::fmt::{self, Debug, Display}; use std::ops::{Deref, DerefMut}; use std::{slice, vec}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; /// An owned smart pointer. /// @@ -203,7 +203,7 @@ impl HashStable for P where T: ?Sized + HashStable, { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { (**self).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 43d87b96ead90..000337f13e79c 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::fmt; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_data_structures::sync::Lrc; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::edition::Edition; @@ -1055,7 +1055,7 @@ impl HashStable for Nonterminal where CTX: crate::HashStableContext, { - fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut GenericStableHasher) { panic!("interpolated tokens should not be present in the HIR") } } diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 057b4455dca89..56642ed9ada60 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -16,7 +16,7 @@ use std::borrow::Cow; use std::{cmp, fmt, iter}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_data_structures::sync::{self, Lrc}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_serialize::{Decodable, Encodable}; @@ -99,7 +99,7 @@ impl HashStable for TokenStream where CTX: crate::HashStableContext, { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { for sub_tt in self.trees() { sub_tt.hash_stable(hcx, hasher); } @@ -151,7 +151,7 @@ impl Decodable for LazyAttrTokenStream { } impl HashStable for LazyAttrTokenStream { - fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut GenericStableHasher) { panic!("Attempted to compute stable hash for LazyAttrTokenStream"); } } diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index b6fee1bf24a78..423021eb51487 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -15,7 +15,7 @@ use rustc_codegen_ssa::{ errors as ssa_errors, CodegenResults, CompiledModule, CrateInfo, ModuleKind, }; use rustc_data_structures::profiling::SelfProfilerRef; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_data_structures::sync::{par_map, IntoDynSyncSend}; use rustc_metadata::fs::copy_to_stdout; use rustc_metadata::EncodedMetadata; @@ -43,7 +43,7 @@ enum OngoingModuleCodegen { } impl HashStable for OngoingModuleCodegen { - fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) { + fn hash_stable(&self, _: &mut HCX, _: &mut GenericStableHasher) { // do nothing } } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index 25b2df9c52c3a..effc2fea62c22 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, StableBlake2sHasher256}; use rustc_macros::HashStable; use rustc_middle::bug; use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; @@ -94,7 +94,7 @@ impl<'tcx> UniqueTypeId<'tcx> { /// /// Right now this takes the form of a hex-encoded opaque hash value. pub fn generate_unique_id_string(self, tcx: TyCtxt<'tcx>) -> String { - let mut hasher = StableHasher::new(); + let mut hasher = StableBlake2sHasher256::new(); tcx.with_stable_hashing_context(|mut hcx| { hcx.while_hashing_spans(false, |hcx| self.hash_stable(hcx, &mut hasher)) }); diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index bfb1d217eae8a..2fe6450619dd5 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -107,12 +107,12 @@ pub enum TypeKind { // for now we content ourselves with providing a no-op HashStable // implementation for CGUs. mod temp_stable_hash_impls { - use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; + use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use crate::ModuleCodegen; impl HashStable for ModuleCodegen { - fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) { + fn hash_stable(&self, _: &mut HCX, _: &mut GenericStableHasher) { // do nothing } } diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 3794a6e043c6d..b00f6777f9e04 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -15,7 +15,7 @@ jobserver_crate = { version = "0.1.28", package = "jobserver" } measureme = "11" rustc-hash = "1.1.0" rustc-rayon = { version = "0.5.0", optional = true } -rustc-stable-hash = { version = "0.1.0", features = ["nightly"] } +rustc-stable-hash = { git = "https://github.com/Urgau/rustc-stable-hash.git", rev = "543696a", features = ["nightly"] } rustc_arena = { path = "../rustc_arena" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_index = { path = "../rustc_index", package = "rustc_index" } diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index efc56dc93373b..11f190f941774 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -1,6 +1,7 @@ use std::hash::{Hash, Hasher}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +use rustc_stable_hash::hashers::Blake2s256Hash; use crate::stable_hasher::{ impl_stable_traits_for_trivial_type, FromStableHash, Hash64, StableHasherHash, @@ -157,15 +158,27 @@ impl FingerprintHasher for crate::unhash::Unhasher { } } -impl FromStableHash for Fingerprint { - type Hash = StableHasherHash; - +impl FromStableHash for Fingerprint { #[inline] - fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self { + fn from(StableHasherHash([_0, _1]): StableHasherHash) -> Self { Fingerprint(_0, _1) } } +impl FromStableHash for Fingerprint { + #[inline] + fn from(Blake2s256Hash(bytes): Blake2s256Hash) -> Self { + let p0 = u64::from_le_bytes(bytes[0..8].try_into().unwrap()); + let p1 = u64::from_le_bytes(bytes[8..16].try_into().unwrap()); + let p2 = u64::from_le_bytes(bytes[16..24].try_into().unwrap()); + let p3 = u64::from_le_bytes(bytes[24..32].try_into().unwrap()); + + // See https://stackoverflow.com/a/27952689 on why this function is + // implemented this way. + Fingerprint(p0.wrapping_mul(3).wrapping_add(p1), p2.wrapping_mul(3).wrapping_add(p3)) + } +} + impl_stable_traits_for_trivial_type!(Fingerprint); impl Encodable for Fingerprint { diff --git a/compiler/rustc_data_structures/src/hashes.rs b/compiler/rustc_data_structures/src/hashes.rs index f98c8de1eb097..e8f268c16940f 100644 --- a/compiler/rustc_data_structures/src/hashes.rs +++ b/compiler/rustc_data_structures/src/hashes.rs @@ -15,6 +15,7 @@ use std::fmt; use std::ops::BitXorAssign; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +use rustc_stable_hash::hashers::Blake2s256Hash; use crate::stable_hasher::{FromStableHash, StableHasherHash}; @@ -58,11 +59,9 @@ impl Decodable for Hash64 { } } -impl FromStableHash for Hash64 { - type Hash = StableHasherHash; - +impl FromStableHash for Hash64 { #[inline] - fn from(StableHasherHash([_0, __1]): Self::Hash) -> Self { + fn from(StableHasherHash([_0, __1]): StableHasherHash) -> Self { Self { inner: _0 } } } @@ -125,15 +124,25 @@ impl Decodable for Hash128 { } } -impl FromStableHash for Hash128 { - type Hash = StableHasherHash; - +impl FromStableHash for Hash128 { #[inline] - fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self { + fn from(StableHasherHash([_0, _1]): StableHasherHash) -> Self { Self { inner: u128::from(_0) | (u128::from(_1) << 64) } } } +impl FromStableHash for Hash128 { + #[inline] + fn from(Blake2s256Hash(bytes): Blake2s256Hash) -> Self { + let p0 = u128::from_le_bytes(bytes[0..16].try_into().unwrap()); + let p1 = u128::from_le_bytes(bytes[16..32].try_into().unwrap()); + + // See https://stackoverflow.com/a/27952689 on why this function is + // implemented this way. + Self { inner: p0.wrapping_mul(3).wrapping_add(p1) } + } +} + impl fmt::Debug for Hash128 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index 850b052f564b7..32e8870cf0002 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher}; use std::ops::Deref; use std::ptr; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; mod private { #[derive(Clone, Copy, Debug)] @@ -104,7 +104,7 @@ impl HashStable for Interned<'_, T> where T: HashStable, { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.0.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/packed.rs b/compiler/rustc_data_structures/src/packed.rs index f54b12b5b532d..005b8c3a823ac 100644 --- a/compiler/rustc_data_structures/src/packed.rs +++ b/compiler/rustc_data_structures/src/packed.rs @@ -3,7 +3,7 @@ use std::fmt; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; /// A packed 128-bit integer. Useful for reducing the size of structures in /// some cases. @@ -55,7 +55,7 @@ impl fmt::UpperHex for Pu128 { impl HashStable for Pu128 { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { { self.0 }.hash_stable(ctx, hasher) } } diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 066ea03b4ace4..bbe21249d547e 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -5,7 +5,7 @@ use std::ops::{Bound, Index, IndexMut, RangeBounds}; use rustc_macros::{Decodable_Generic, Encodable_Generic}; -use crate::stable_hasher::{HashStable, StableHasher, StableOrd}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable, StableOrd}; mod index_map; @@ -311,7 +311,7 @@ impl FromIterator<(K, V)> for SortedMap { impl + StableOrd, V: HashStable, CTX> HashStable for SortedMap { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.data.hash_stable(ctx, hasher); } } diff --git a/compiler/rustc_data_structures/src/sorted_map/index_map.rs b/compiler/rustc_data_structures/src/sorted_map/index_map.rs index e9a5fb5197548..0aadd0f249e45 100644 --- a/compiler/rustc_data_structures/src/sorted_map/index_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map/index_map.rs @@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher}; use rustc_index::{Idx, IndexVec}; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; /// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of /// an item by key and *O*(1) lookup by index. @@ -131,7 +131,7 @@ where K: HashStable, V: HashStable, { - fn hash_stable(&self, ctx: &mut C, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut C, hasher: &mut GenericStableHasher) { let SortedIndexMultiMap { items, // We can ignore this field because it is not observable from the outside. diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 9673f94d7a433..51f4a06adaff0 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -10,10 +10,21 @@ use smallvec::SmallVec; #[cfg(test)] mod tests; +pub use rustc_stable_hash::hashers::StableBlake2sHasher256; pub use rustc_stable_hash::{ - FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher, + FromStableHash, IntoStableHash, SipHasher128Hash as StableHasherHash, + StableHasher as GenericStableHasher, StableSipHasher128 as StableHasher, }; +pub trait ExtendedHasher: + rustc_stable_hash::ExtendedHasher> + Default +{ +} + +impl ExtendedHasher for rustc_stable_hash::hashers::SipHasher128 {} +impl ExtendedHasher for rustc_stable_hash::hashers::Blake2sHasher256 {} + +use crate::fingerprint::Fingerprint; pub use crate::hashes::{Hash128, Hash64}; /// Something that implements `HashStable` can be hashed in a way that is @@ -43,7 +54,7 @@ pub use crate::hashes::{Hash128, Hash64}; /// `StableHasher` takes care of endianness and `isize`/`usize` platform /// differences. pub trait HashStable { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher); + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher); } /// Implement this for types that can be turned into stable keys like, for @@ -139,7 +150,11 @@ macro_rules! impl_stable_traits_for_trivial_type { ($t:ty) => { impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable(&self, _: &mut CTX, hasher: &mut $crate::stable_hasher::StableHasher) { + fn hash_stable( + &self, + _: &mut CTX, + hasher: &mut $crate::stable_hasher::GenericStableHasher, + ) { ::std::hash::Hash::hash(self, hasher); } } @@ -180,7 +195,7 @@ impl_stable_traits_for_trivial_type!(Hash64); // hashing we want to hash the full 128-bit hash. impl HashStable for Hash128 { #[inline] - fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut GenericStableHasher) { self.as_u128().hash(hasher); } } @@ -194,38 +209,39 @@ impl StableOrd for Hash128 { } impl HashStable for ! { - fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) { + fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut GenericStableHasher) { unreachable!() } } impl HashStable for PhantomData { - fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {} + fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut GenericStableHasher) { + } } impl HashStable for NonZero { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.get().hash_stable(ctx, hasher) } } impl HashStable for NonZero { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.get().hash_stable(ctx, hasher) } } impl HashStable for f32 { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let val: u32 = self.to_bits(); val.hash_stable(ctx, hasher); } } impl HashStable for f64 { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let val: u64 = self.to_bits(); val.hash_stable(ctx, hasher); } @@ -233,21 +249,21 @@ impl HashStable for f64 { impl HashStable for ::std::cmp::Ordering { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { (*self as i8).hash_stable(ctx, hasher); } } impl, CTX> HashStable for (T1,) { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let (ref _0,) = *self; _0.hash_stable(ctx, hasher); } } impl, T2: HashStable, CTX> HashStable for (T1, T2) { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let (ref _0, ref _1) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -268,7 +284,7 @@ where T2: HashStable, T3: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let (ref _0, ref _1, ref _2) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -292,7 +308,7 @@ where T3: HashStable, T4: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { let (ref _0, ref _1, ref _2, ref _3) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -313,7 +329,11 @@ impl StableOrd for ( } impl, CTX> HashStable for [T] { - default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + default fn hash_stable( + &self, + ctx: &mut CTX, + hasher: &mut GenericStableHasher, + ) { self.len().hash_stable(ctx, hasher); for item in self { item.hash_stable(ctx, hasher); @@ -322,7 +342,7 @@ impl, CTX> HashStable for [T] { } impl HashStable for [u8] { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.len().hash_stable(ctx, hasher); hasher.write(self); } @@ -330,7 +350,7 @@ impl HashStable for [u8] { impl, CTX> HashStable for Vec { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self[..].hash_stable(ctx, hasher); } } @@ -342,7 +362,7 @@ where R: BuildHasher, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.len().hash_stable(ctx, hasher); for kv in self { kv.hash_stable(ctx, hasher); @@ -356,7 +376,7 @@ where R: BuildHasher, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.len().hash_stable(ctx, hasher); for key in self { key.hash_stable(ctx, hasher); @@ -369,35 +389,35 @@ where A: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self[..].hash_stable(ctx, hasher); } } impl, CTX> HashStable for Box { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { (**self).hash_stable(ctx, hasher); } } impl, CTX> HashStable for ::std::rc::Rc { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { (**self).hash_stable(ctx, hasher); } } impl, CTX> HashStable for ::std::sync::Arc { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { (**self).hash_stable(ctx, hasher); } } impl HashStable for str { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.as_bytes().hash_stable(ctx, hasher); } } @@ -412,7 +432,7 @@ impl StableOrd for &str { impl HashStable for String { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self[..].hash_stable(hcx, hasher); } } @@ -443,7 +463,7 @@ impl, T2: ToStableHashKey> ToStableHashKey HashStable for bool { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { (if *self { 1u8 } else { 0u8 }).hash_stable(ctx, hasher); } } @@ -460,7 +480,7 @@ where T: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { if let Some(ref value) = *self { 1u8.hash_stable(ctx, hasher); value.hash_stable(ctx, hasher); @@ -483,7 +503,7 @@ where T2: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { mem::discriminant(self).hash_stable(ctx, hasher); match *self { Ok(ref x) => x.hash_stable(ctx, hasher), @@ -497,14 +517,14 @@ where T: HashStable + ?Sized, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { (**self).hash_stable(ctx, hasher); } } impl HashStable for ::std::mem::Discriminant { #[inline] - fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut GenericStableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -514,7 +534,7 @@ where T: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.start().hash_stable(ctx, hasher); self.end().hash_stable(ctx, hasher); } @@ -524,7 +544,7 @@ impl HashStable for IndexSlice where T: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.len().hash_stable(ctx, hasher); for v in &self.raw { v.hash_stable(ctx, hasher); @@ -536,7 +556,7 @@ impl HashStable for IndexVec where T: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.len().hash_stable(ctx, hasher); for v in &self.raw { v.hash_stable(ctx, hasher); @@ -545,13 +565,13 @@ where } impl HashStable for BitSet { - fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut GenericStableHasher) { ::std::hash::Hash::hash(self, hasher); } } impl HashStable for bit_set::BitMatrix { - fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut GenericStableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -560,7 +580,7 @@ impl HashStable for bit_set::FiniteBitSet where T: HashStable + bit_set::FiniteBitSetTy, { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.0.hash_stable(hcx, hasher); } } @@ -579,7 +599,7 @@ where K: HashStable + StableOrd, V: HashStable, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); @@ -591,7 +611,7 @@ impl HashStable for ::std::collections::BTreeSet where K: HashStable + StableOrd, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); diff --git a/compiler/rustc_data_structures/src/stable_hasher/tests.rs b/compiler/rustc_data_structures/src/stable_hasher/tests.rs index aab50a13af0e6..9b68ea407e040 100644 --- a/compiler/rustc_data_structures/src/stable_hasher/tests.rs +++ b/compiler/rustc_data_structures/src/stable_hasher/tests.rs @@ -45,7 +45,11 @@ fn test_attribute_permutation() { } impl HashStable for Foo { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut CTX, + hasher: &mut GenericStableHasher, + ) { self.a.hash_stable(hcx, hasher); self.b.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_data_structures/src/steal.rs b/compiler/rustc_data_structures/src/steal.rs index 0f2c0eee27d2f..782c3910186c1 100644 --- a/compiler/rustc_data_structures/src/steal.rs +++ b/compiler/rustc_data_structures/src/steal.rs @@ -1,4 +1,4 @@ -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use crate::sync::{MappedReadGuard, ReadGuard, RwLock}; /// The `Steal` struct is intended to used as the value for a query. @@ -63,7 +63,7 @@ impl Steal { } impl> HashStable for Steal { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.borrow().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/svh.rs b/compiler/rustc_data_structures/src/svh.rs index 391a7c9f30dbf..1d3dc14465953 100644 --- a/compiler/rustc_data_structures/src/svh.rs +++ b/compiler/rustc_data_structures/src/svh.rs @@ -42,7 +42,11 @@ impl fmt::Display for Svh { impl stable_hasher::HashStable for Svh { #[inline] - fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) { + fn hash_stable( + &self, + ctx: &mut T, + hasher: &mut stable_hasher::GenericStableHasher, + ) { let Svh { hash } = *self; hash.hash_stable(ctx, hasher); } diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs index 2914eece6796b..1b923153d88a0 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -277,7 +277,11 @@ unsafe impl Tag for Tag2 { #[cfg(test)] impl crate::stable_hasher::HashStable for Tag2 { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut crate::stable_hasher::StableHasher) { + fn hash_stable( + &self, + hcx: &mut HCX, + hasher: &mut crate::stable_hasher::GenericStableHasher, + ) { (*self as u8).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs index 25e107b0f413c..e1a03c479c462 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs @@ -7,7 +7,7 @@ use std::ops::{Deref, DerefMut}; use std::ptr::NonNull; use super::{Pointer, Tag}; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; /// A [`Copy`] tagged pointer. /// @@ -273,7 +273,7 @@ where P: Pointer + HashStable, T: Tag + HashStable, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.with_pointer_ref(|ptr| ptr.hash_stable(hcx, hasher)); self.tag().hash_stable(hcx, hasher); } diff --git a/compiler/rustc_data_structures/src/tagged_ptr/drop.rs b/compiler/rustc_data_structures/src/tagged_ptr/drop.rs index 319a8cdd3990a..7c6bd8bde3b0b 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/drop.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/drop.rs @@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher}; use std::ops::{Deref, DerefMut}; use super::{CopyTaggedPtr, Pointer, Tag}; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; /// A tagged pointer that supports pointers that implement [`Drop`]. /// @@ -142,7 +142,7 @@ where P: Pointer + HashStable, T: Tag + HashStable, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.raw.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index bafb16a8b5e67..752056b178acb 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -12,7 +12,9 @@ use rustc_hash::{FxHashMap, FxHashSet}; use rustc_macros::{Decodable_Generic, Encodable_Generic}; use crate::fingerprint::Fingerprint; -use crate::stable_hasher::{HashStable, StableCompare, StableHasher, ToStableHashKey}; +use crate::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, StableCompare, ToStableHashKey, +}; /// `UnordItems` is the order-less version of `Iterator`. It only contains methods /// that don't (easily) expose an ordering of the underlying items. @@ -401,7 +403,7 @@ impl> From> for UnordSet impl> HashStable for UnordSet { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -619,7 +621,7 @@ where impl, V: HashStable> HashStable for UnordMap { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -682,7 +684,7 @@ impl> From> for UnordBag { impl> HashStable for UnordBag { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -711,11 +713,12 @@ where fn hash_iter_order_independent< HCX, T: HashStable, + H: ExtendedHasher, I: Iterator + ExactSizeIterator, >( mut it: I, hcx: &mut HCX, - hasher: &mut StableHasher, + hasher: &mut GenericStableHasher, ) { let len = it.len(); len.hash_stable(hcx, hasher); @@ -731,7 +734,7 @@ fn hash_iter_order_independent< _ => { let mut accumulator = Fingerprint::ZERO; for item in it { - let mut item_hasher = StableHasher::new(); + let mut item_hasher = GenericStableHasher::::new(); item.hash_stable(hcx, &mut item_hasher); let item_fingerprint: Fingerprint = item_hasher.finish(); accumulator = accumulator.combine_commutative(item_fingerprint); diff --git a/compiler/rustc_hir/src/diagnostic_items.rs b/compiler/rustc_hir/src/diagnostic_items.rs index 23a83a5011b5a..0d45af688d34f 100644 --- a/compiler/rustc_hir/src/diagnostic_items.rs +++ b/compiler/rustc_hir/src/diagnostic_items.rs @@ -1,5 +1,5 @@ use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_span::def_id::DefIdMap; use rustc_span::Symbol; @@ -13,7 +13,7 @@ pub struct DiagnosticItems { impl HashStable for DiagnosticItems { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { self.name_to_id.hash_stable(ctx, hasher); } } diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index f2142359935b9..ca7a26ac41ad5 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -1,6 +1,8 @@ use std::fmt::{self, Debug}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, StableOrd, ToStableHashKey, +}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::def_id::DefPathHash; use rustc_span::HashStableContext; @@ -52,7 +54,7 @@ impl rustc_index::Idx for OwnerId { impl HashStable for OwnerId { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index e7398fd222636..e4804fca74850 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -9,7 +9,7 @@ use rustc_ast as ast; use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; @@ -137,7 +137,7 @@ macro_rules! language_item_table { } impl HashStable for LangItem { - fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut GenericStableHasher) { ::std::hash::Hash::hash(self, hasher); } } diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index fe169e989ec9f..0e7f3d23c31f3 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,4 +1,6 @@ -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, ToStableHashKey, +}; use rustc_span::def_id::DefPathHash; use crate::hir::{ @@ -87,7 +89,11 @@ impl ToStableHashKey for ForeignItemId // in "DefPath Mode". impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<'tcx> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut HirCtx, + hasher: &mut GenericStableHasher, + ) { // We ignore the `nodes` and `bodies` fields since these refer to information included in // `hash` which is hashed in the collector and used for the crate hash. // `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing @@ -99,7 +105,11 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<' } impl<'tcx, HirCtx: crate::HashStableContext> HashStable for AttributeMap<'tcx> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut HirCtx, + hasher: &mut GenericStableHasher, + ) { // We ignore the `map` since it refers to information included in `opt_hash` which is // hashed in the collector and used for the crate hash. let AttributeMap { opt_hash, map: _ } = *self; @@ -108,7 +118,11 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for AttributeMap } impl HashStable for Crate<'_> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut HirCtx, + hasher: &mut GenericStableHasher, + ) { let Crate { owners: _, opt_hir_hash } = self; opt_hir_hash.unwrap().hash_stable(hcx, hasher) } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 0f07de43e80ed..fa5f34c816696 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -2,7 +2,7 @@ use rustc_ast::node_id::NodeId; use rustc_ast::{AttrId, Attribute}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::stable_hasher::{ - HashStable, StableCompare, StableHasher, ToStableHashKey, + ExtendedHasher, GenericStableHasher, HashStable, StableCompare, ToStableHashKey, }; use rustc_error_messages::{DiagMessage, MultiSpan}; use rustc_hir::def::Namespace; @@ -135,7 +135,7 @@ impl LintExpectationId { impl HashStable for LintExpectationId { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { match self { LintExpectationId::Stable { hir_id, @@ -529,7 +529,7 @@ impl LintId { impl HashStable for LintId { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.lint_name_raw().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index 6b3210cad7be6..63f8be607c73d 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -111,10 +111,10 @@ fn hash_stable_derive_with_mode( ), quote! { #[inline] - fn hash_stable( + fn hash_stable<__H: ::rustc_data_structures::stable_hasher::ExtendedHasher>( &self, __hcx: &mut #context, - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + __hasher: &mut ::rustc_data_structures::stable_hasher::GenericStableHasher<__H>) { #discriminant match *self { #body } } diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index db70f53b7b498..54ed92bd1305b 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -5,7 +5,7 @@ use std::hash::Hash; use rustc_data_structures::fx::{FxIndexMap, IndexEntry}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_hir::def::DefKind; use rustc_macros::HashStable; use rustc_query_system::ich::StableHashingContext; @@ -278,7 +278,11 @@ impl Default for EffectiveVisibilities { } impl<'a> HashStable> for EffectiveVisibilities { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { let EffectiveVisibilities { ref map } = *self; map.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index c08bfc1fa95f4..7cc094f2f5102 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::graph; use rustc_data_structures::graph::dominators::{dominators, Dominators}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_data_structures::sync::OnceLock; use rustc_index::{IndexSlice, IndexVec}; use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; @@ -186,5 +186,5 @@ impl Decodable for Cache { impl HashStable for Cache { #[inline] - fn hash_stable(&self, _: &mut CTX, _: &mut StableHasher) {} + fn hash_stable(&self, _: &mut CTX, _: &mut GenericStableHasher) {} } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 46c4d586f6ad9..5dfbfdce218ac 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -994,11 +994,15 @@ pub enum BindingForm<'tcx> { TrivialTypeTraversalImpls! { BindingForm<'tcx> } mod binding_form_impl { - use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; + use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_query_system::ich::StableHashingContext; impl<'a, 'tcx> HashStable> for super::BindingForm<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { use super::BindingForm::*; std::mem::discriminant(self).hash_stable(hcx, hasher); diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 204f61b4804e4..2a17f17015678 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -7,7 +7,9 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::intern::Interned; -use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, HashingControls, +}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -143,7 +145,11 @@ impl Hash for AdtDefData { } impl<'a> HashStable> for AdtDefData { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { thread_local! { static CACHE: RefCell> = Default::default(); } @@ -154,7 +160,7 @@ impl<'a> HashStable> for AdtDefData { *cache.borrow_mut().entry((addr, hashing_controls)).or_insert_with(|| { let ty::AdtDefData { did, ref variants, ref flags, ref repr } = *self; - let mut hasher = StableHasher::new(); + let mut hasher = GenericStableHasher::::new(); did.hash_stable(hcx, &mut hasher); variants.hash_stable(hcx, &mut hasher); flags.hash_stable(hcx, &mut hasher); diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 0024a2ae756ea..322ebd7e9537d 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -139,7 +139,11 @@ pub struct ScalarInt { // Cannot derive these, as the derives take references to the fields, and we // can't take references to fields of packed structs. impl crate::ty::HashStable for ScalarInt { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut crate::ty::StableHasher) { + fn hash_stable( + &self, + hcx: &mut CTX, + hasher: &mut crate::ty::GenericStableHasher, + ) { // Using a block `{self.data}` here to force a copy instead of using `self.data` // directly, because `hash_stable` takes `&self` and would thus borrow `self.data`. // Since `Self` is a packed struct, that would create a possibly unaligned reference, diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index b5b7b8bcfef00..29114896eb122 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -7,7 +7,7 @@ use std::ptr; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{ - HashStable, HashingControls, StableHasher, ToStableHashKey, + ExtendedHasher, GenericStableHasher, HashStable, HashingControls, StableHasher, ToStableHashKey, }; use rustc_query_system::ich::StableHashingContext; use tracing::trace; @@ -15,11 +15,15 @@ use tracing::trace; use crate::middle::region; use crate::{mir, ty}; -impl<'a, 'tcx, H, T> HashStable> for &'tcx ty::list::RawList +impl<'a, 'tcx, HCX, T> HashStable> for &'tcx ty::list::RawList where T: HashStable>, { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { thread_local! { static CACHE: RefCell> = RefCell::new(Default::default()); @@ -31,6 +35,10 @@ where return hash; } + // FIXME: This caching doesn't work with a generic stable hasher. + // We therefor force the use of `StableHasher`. We should figure out + // a way to have to either cache for each hasher or only cache with + // the primary `StableHasher` hasher. let mut hasher = StableHasher::new(); self[..].hash_stable(hcx, &mut hasher); @@ -59,14 +67,22 @@ where } impl<'a, 'tcx> HashStable> for ty::GenericArg<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { self.unpack().hash_stable(hcx, hasher); } } // AllocIds get resolved to whatever they point to (to be stable) impl<'a> HashStable> for mir::interpret::AllocId { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { ty::tls::with_opt(|tcx| { trace!("hashing {:?}", *self); let tcx = tcx.expect("can't hash AllocIds during hir lowering"); @@ -77,7 +93,11 @@ impl<'a> HashStable> for mir::interpret::AllocId { // CtfeProvenance is an AllocId and a bool. impl<'a> HashStable> for mir::interpret::CtfeProvenance { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { self.alloc_id().hash_stable(hcx, hasher); self.immutable().hash_stable(hcx, hasher); } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9736428e6f7c7..91ef21152bd4a 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -29,7 +29,7 @@ use rustc_ast::node_id::NodeMap; pub use rustc_ast_ir::{try_visit, Movability, Mutability}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_data_structures::steal::Steal; use rustc_data_structures::tagged_ptr::CopyTaggedPtr; use rustc_errors::{Diag, ErrorGuaranteed, StashKey}; @@ -529,7 +529,11 @@ impl<'tcx> From> for Term<'tcx> { } impl<'a, 'tcx> HashStable> for Term<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { self.unpack().hash_stable(hcx, hasher); } } @@ -1017,7 +1021,11 @@ impl<'tcx> fmt::Debug for ParamEnv<'tcx> { } impl<'a, 'tcx> HashStable> for ParamEnv<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { self.caller_bounds().hash_stable(hcx, hasher); self.reveal().hash_stable(hcx, hasher); } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 365f434a264e2..0401ef08f7f46 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -4,7 +4,7 @@ use std::{fmt, iter}; use rustc_apfloat::Float as _; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableBlake2sHasher256}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; @@ -134,7 +134,7 @@ impl<'tcx> TyCtxt<'tcx> { let ty = self.erase_regions(ty); self.with_stable_hashing_context(|mut hcx| { - let mut hasher = StableHasher::new(); + let mut hasher = StableBlake2sHasher256::new(); hcx.while_hashing_spans(false, |hcx| ty.hash_stable(hcx, &mut hasher)); hasher.finish() }) diff --git a/compiler/rustc_query_system/src/dep_graph/dep_node.rs b/compiler/rustc_query_system/src/dep_graph/dep_node.rs index dfd0527252d60..3a969ab076be8 100644 --- a/compiler/rustc_query_system/src/dep_graph/dep_node.rs +++ b/compiler/rustc_query_system/src/dep_graph/dep_node.rs @@ -46,7 +46,9 @@ use std::fmt; use std::hash::Hash; use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, StableHasher, StableOrd, ToStableHashKey, +}; use rustc_data_structures::AtomicRef; use rustc_hir::definitions::DefPathHash; use rustc_macros::{Decodable, Encodable}; @@ -291,7 +293,7 @@ impl WorkProductId { impl HashStable for WorkProductId { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.hash.hash_stable(hcx, hasher) } } diff --git a/compiler/rustc_query_system/src/ich/hcx.rs b/compiler/rustc_query_system/src/ich/hcx.rs index 756ad3b1a2dda..beeafe10084f2 100644 --- a/compiler/rustc_query_system/src/ich/hcx.rs +++ b/compiler/rustc_query_system/src/ich/hcx.rs @@ -1,5 +1,7 @@ use rustc_ast as ast; -use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, HashingControls, +}; use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::definitions::DefPathHash; @@ -88,7 +90,11 @@ impl<'a> StableHashingContext<'a> { impl<'a> HashStable> for ast::NodeId { #[inline] - fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) { + fn hash_stable( + &self, + _: &mut StableHashingContext<'a>, + _: &mut GenericStableHasher, + ) { panic!("Node IDs should not appear in incremental state"); } } diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 8d7a6e4fa9b0c..8e012eea0c512 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -4,7 +4,7 @@ use std::assert_matches::assert_matches; use rustc_ast as ast; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; use rustc_span::SourceFile; use smallvec::SmallVec; @@ -13,7 +13,11 @@ use crate::ich::StableHashingContext; impl<'ctx> rustc_target::HashStableContext for StableHashingContext<'ctx> {} impl<'a> HashStable> for [ast::Attribute] { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { if self.is_empty() { self.len().hash_stable(hcx, hasher); return; @@ -36,7 +40,11 @@ impl<'a> HashStable> for [ast::Attribute] { } impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> { - fn hash_attr(&mut self, attr: &ast::Attribute, hasher: &mut StableHasher) { + fn hash_attr( + &mut self, + attr: &ast::Attribute, + hasher: &mut GenericStableHasher, + ) { // Make sure that these have been filtered out. debug_assert!(!attr.ident().is_some_and(|ident| self.is_ignored_attr(ident.name))); debug_assert!(!attr.is_doc_comment()); @@ -60,7 +68,11 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> { impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {} impl<'a> HashStable> for SourceFile { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut GenericStableHasher, + ) { let SourceFile { name: _, // We hash the smaller stable_id instead of this stable_id, @@ -107,7 +119,11 @@ impl<'a> HashStable> for SourceFile { } impl<'tcx> HashStable> for rustc_feature::Features { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'tcx>, + hasher: &mut GenericStableHasher, + ) { // Unfortunately we cannot exhaustively list fields here, since the // struct is macro generated. self.declared_lang_features.hash_stable(hcx, hasher); diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index a45b676acae73..538823f26dca3 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -3,7 +3,8 @@ use std::hash::{BuildHasherDefault, Hash, Hasher}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{ - Hash64, HashStable, StableHasher, StableOrd, ToStableHashKey, + ExtendedHasher, GenericStableHasher, Hash64, HashStable, StableHasher, StableOrd, + ToStableHashKey, }; use rustc_data_structures::unhash::Unhasher; use rustc_data_structures::AtomicRef; @@ -404,21 +405,21 @@ rustc_data_structures::define_id_collections!( impl HashStable for DefId { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } impl HashStable for LocalDefId { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } impl HashStable for CrateNum { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 434df35a5156f..072cdcb930a1c 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -31,7 +31,9 @@ use std::hash::Hash; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::stable_hasher::{Hash64, HashStable, HashingControls, StableHasher}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, Hash64, HashStable, HashingControls, StableHasher, +}; use rustc_data_structures::sync::{Lock, Lrc, WorkerLocal}; use rustc_data_structures::unhash::UnhashMap; use rustc_index::IndexVec; @@ -1536,7 +1538,7 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut ctx: impl HashStableContex } impl HashStable for SyntaxContext { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { const TAG_EXPANSION: u8 = 0; const TAG_NO_EXPANSION: u8 = 1; @@ -1552,7 +1554,7 @@ impl HashStable for SyntaxContext { } impl HashStable for ExpnId { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { assert_default_hashing_controls(ctx, "ExpnId"); let hash = if *self == ExpnId::root() { // Avoid fetching TLS storage for a trivial often-used value. diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 35fe28c5d425b..b3f694d898445 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -58,7 +58,7 @@ use hygiene::Transparency; pub use hygiene::{ DesugaringKind, ExpnData, ExpnHash, ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext, }; -use rustc_data_structures::stable_hasher::HashingControls; +use rustc_data_structures::stable_hasher::{HashingControls, StableHasher}; pub mod def_id; use def_id::{CrateNum, DefId, DefIndex, DefPathHash, LocalDefId, StableCrateId, LOCAL_CRATE}; pub mod edit_distance; @@ -83,7 +83,9 @@ use std::{fmt, iter}; use md5::{Digest, Md5}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{Hash128, Hash64, HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, Hash128, Hash64, HashStable, +}; use rustc_data_structures::sync::{FreezeLock, FreezeWriteGuard, Lock, Lrc}; use sha1::Sha1; use sha2::Sha256; @@ -2274,8 +2276,8 @@ impl Decodable for BytePos { } } -impl HashStable for RelativeBytePos { - fn hash_stable(&self, hcx: &mut H, hasher: &mut StableHasher) { +impl HashStable for RelativeBytePos { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut GenericStableHasher) { self.0.hash_stable(hcx, hasher); } } @@ -2419,7 +2421,7 @@ where /// codepoint offsets. For the purpose of the hash that's sufficient. /// Also, hashing filenames is expensive so we avoid doing it twice when the /// span starts and ends in the same file, which is almost always the case. - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { const TAG_VALID_SPAN: u8 = 0; const TAG_INVALID_SPAN: u8 = 1; const TAG_RELATIVE_SPAN: u8 = 2; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9cb729ec48588..fde00437e2410 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -8,7 +8,7 @@ use std::{fmt, str}; use rustc_arena::DroplessArena; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::stable_hasher::{ - HashStable, StableCompare, StableHasher, ToStableHashKey, + ExtendedHasher, GenericStableHasher, HashStable, StableCompare, ToStableHashKey, }; use rustc_data_structures::sync::Lock; use rustc_macros::{symbols, Decodable, Encodable, HashStable_Generic}; @@ -2364,7 +2364,7 @@ impl ToString for Symbol { impl HashStable for Symbol { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { self.as_str().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 7a8c612057fa2..a5a4f5b4dc3c8 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -2,7 +2,7 @@ use std::fmt; use derive_where::derive_where; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; #[cfg(feature = "nightly")] use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable}; use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic}; @@ -126,7 +126,7 @@ impl fmt::Debug for InferConst { #[cfg(feature = "nightly")] impl HashStable for InferConst { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { match self { InferConst::Var(_) | InferConst::EffectVar(_) => { panic!("const variables should not be hashed: {self:?}") diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index e0b3973700783..5b79cbb6a6a56 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -2,7 +2,7 @@ use std::fmt; use derive_where::derive_where; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; #[cfg(feature = "nightly")] use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable}; @@ -215,7 +215,7 @@ where I::PlaceholderRegion: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { std::mem::discriminant(self).hash_stable(hcx, hasher); match self { ReErased | ReStatic | ReError(_) => { diff --git a/compiler/rustc_type_ir/src/ty_info.rs b/compiler/rustc_type_ir/src/ty_info.rs index a999566745070..98183bd384211 100644 --- a/compiler/rustc_type_ir/src/ty_info.rs +++ b/compiler/rustc_type_ir/src/ty_info.rs @@ -5,7 +5,9 @@ use std::ops::Deref; #[cfg(feature = "nightly")] use rustc_data_structures::fingerprint::Fingerprint; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ + ExtendedHasher, GenericStableHasher, HashStable, StableHasher, +}; use crate::{DebruijnIndex, TypeFlags}; @@ -97,7 +99,7 @@ impl Hash for WithCachedTypeInfo { #[cfg(feature = "nightly")] impl, CTX> HashStable for WithCachedTypeInfo { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut GenericStableHasher) { if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) { // No cached hash available. This can only mean that incremental is disabled. // We don't cache stable hashes in non-incremental mode, because they are used @@ -106,6 +108,9 @@ impl, CTX> HashStable for WithCachedTypeInfo { // We need to build the hash as if we cached it and then hash that hash, as // otherwise the hashes will differ between cached and non-cached mode. let stable_hash: Fingerprint = { + // FIXME: Using the generic stable hasher creates a cache coherency issue + // so for now always use the `StableHasher` instead. + // let mut hasher = GenericStableHasher::::new(); let mut hasher = StableHasher::new(); self.internee.hash_stable(hcx, &mut hasher); hasher.finish() diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 7e48f1b20a868..838dcaf1686e0 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -3,7 +3,7 @@ use std::fmt; use derive_where::derive_where; use rustc_ast_ir::Mutability; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{ExtendedHasher, GenericStableHasher, HashStable}; #[cfg(feature = "nightly")] use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue}; #[cfg(feature = "nightly")] @@ -791,7 +791,7 @@ impl UnifyKey for FloatVid { #[cfg(feature = "nightly")] impl HashStable for InferTy { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut GenericStableHasher) { use InferTy::*; std::mem::discriminant(self).hash_stable(ctx, hasher); match self { diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 89011bbb48f5c..7838c7f5a40c8 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -98,6 +98,7 @@ const EXCEPTIONS: ExceptionList = &[ ("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0 // cargo/... (because of serde) ("self_cell", "Apache-2.0"), // rustc (fluent translations) ("snap", "BSD-3-Clause"), // rustc + ("subtle", "BSD-3-Clause"), // rustc ("wasm-encoder", "Apache-2.0 WITH LLVM-exception"), // rustc ("wasm-metadata", "Apache-2.0 WITH LLVM-exception"), // rustc ("wasmparser", "Apache-2.0 WITH LLVM-exception"), // rustc @@ -258,6 +259,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "arrayvec", "autocfg", "bitflags", + "blake2", "block-buffer", "byteorder", // via ruzstd in object in thorin-dwp "cc", @@ -393,6 +395,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "stacker", "static_assertions", "strsim", + "subtle", "syn", "synstructure", "tempfile", diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 55f937aeacf50..7d813333458e7 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -8,6 +8,8 @@ const ALLOWED_SOURCES: &[&str] = &[ r#""registry+https://github.com/rust-lang/crates.io-index""#, // This is `rust_team_data` used by `site` in src/tools/rustc-perf, r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#, + // WIP Blake2 in rustc-stable-hash + r#""git+https://github.com/Urgau/rustc-stable-hash.git?rev=543696a#543696a0b6299c4cc8a8c9c30651e5cc0056655a""#, ]; /// Checks for external package sources. `root` is the path to the directory that contains the