diff options
| author | bors <bors@rust-lang.org> | 2025-02-17 11:18:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-17 11:18:33 +0000 |
| commit | 2162e9d4b18525e4eb542fed9985921276512d7c (patch) | |
| tree | e8df98cb0ac63ee1d77d4ef971502ae0f89e654b /compiler/rustc_data_structures/src | |
| parent | 273465e1f2932a30a5b56ac95859cdc86f3f33fa (diff) | |
| parent | 183fc30867571cc585020999b42b0f5244dfda4a (diff) | |
| download | rust-2162e9d4b18525e4eb542fed9985921276512d7c.tar.gz rust-2162e9d4b18525e4eb542fed9985921276512d7c.zip | |
Auto merge of #137164 - matthiaskrgr:rollup-dj5826k, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #137095 (Replace some u64 hashes with Hash64) - #137100 (HIR analysis: Remove unnecessary abstraction over list of clauses) - #137105 (Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.) - #137120 (Enable `relative-path-include-bytes-132203` rustdoc-ui test on Windows) - #137125 (Re-add missing empty lines in the releases notes) - #137145 (use add-core-stubs / minicore for a few more tests) - #137149 (Remove SSE ABI from i586-pc-windows-msvc) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/fingerprint.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/hashes.rs | 147 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/stable_hasher.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/tagged_ptr/tests.rs | 3 |
5 files changed, 5 insertions, 154 deletions
diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index 16c66824c5b..c7c0d0ab072 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -1,10 +1,9 @@ use std::hash::{Hash, Hasher}; +use rustc_hashes::Hash64; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; -use crate::stable_hasher::{ - FromStableHash, Hash64, StableHasherHash, impl_stable_traits_for_trivial_type, -}; +use crate::stable_hasher::{FromStableHash, StableHasherHash, impl_stable_traits_for_trivial_type}; #[cfg(test)] mod tests; diff --git a/compiler/rustc_data_structures/src/hashes.rs b/compiler/rustc_data_structures/src/hashes.rs deleted file mode 100644 index 8f4639fc2e6..00000000000 --- a/compiler/rustc_data_structures/src/hashes.rs +++ /dev/null @@ -1,147 +0,0 @@ -//! rustc encodes a lot of hashes. If hashes are stored as `u64` or `u128`, a `derive(Encodable)` -//! will apply varint encoding to the hashes, which is less efficient than directly encoding the 8 -//! or 16 bytes of the hash. -//! -//! The types in this module represent 64-bit or 128-bit hashes produced by a `StableHasher`. -//! `Hash64` and `Hash128` expose some utility functions to encourage users to not extract the inner -//! hash value as an integer type and accidentally apply varint encoding to it. -//! -//! In contrast with `Fingerprint`, users of these types cannot and should not attempt to construct -//! and decompose these types into constituent pieces. The point of these types is only to -//! connect the fact that they can only be produced by a `StableHasher` to their -//! `Encode`/`Decode` impls. - -use std::fmt; -use std::ops::BitXorAssign; - -use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; - -use crate::stable_hasher::{FromStableHash, StableHasherHash}; - -#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] -pub struct Hash64 { - inner: u64, -} - -impl Hash64 { - pub const ZERO: Hash64 = Hash64 { inner: 0 }; - - #[inline] - pub fn new(n: u64) -> Self { - Self { inner: n } - } - - #[inline] - pub fn as_u64(self) -> u64 { - self.inner - } -} - -impl BitXorAssign<u64> for Hash64 { - #[inline] - fn bitxor_assign(&mut self, rhs: u64) { - self.inner ^= rhs; - } -} - -impl<S: Encoder> Encodable<S> for Hash64 { - #[inline] - fn encode(&self, s: &mut S) { - s.emit_raw_bytes(&self.inner.to_le_bytes()); - } -} - -impl<D: Decoder> Decodable<D> for Hash64 { - #[inline] - fn decode(d: &mut D) -> Self { - Self { inner: u64::from_le_bytes(d.read_raw_bytes(8).try_into().unwrap()) } - } -} - -impl FromStableHash for Hash64 { - type Hash = StableHasherHash; - - #[inline] - fn from(StableHasherHash([_0, __1]): Self::Hash) -> Self { - Self { inner: _0 } - } -} - -impl fmt::Debug for Hash64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.inner.fmt(f) - } -} - -impl fmt::LowerHex for Hash64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::LowerHex::fmt(&self.inner, f) - } -} - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] -pub struct Hash128 { - inner: u128, -} - -// We expect Hash128 to be well mixed. So there's no point in hashing both parts. -// -// This also allows using Hash128-containing types in UnHash-based hashmaps, which would otherwise -// debug_assert! that we're hashing more than a single u64. -impl std::hash::Hash for Hash128 { - fn hash<H: std::hash::Hasher>(&self, h: &mut H) { - h.write_u64(self.truncate().as_u64()); - } -} - -impl Hash128 { - #[inline] - pub fn truncate(self) -> Hash64 { - Hash64 { inner: self.inner as u64 } - } - - #[inline] - pub fn wrapping_add(self, other: Self) -> Self { - Self { inner: self.inner.wrapping_add(other.inner) } - } - - #[inline] - pub fn as_u128(self) -> u128 { - self.inner - } -} - -impl<S: Encoder> Encodable<S> for Hash128 { - #[inline] - fn encode(&self, s: &mut S) { - s.emit_raw_bytes(&self.inner.to_le_bytes()); - } -} - -impl<D: Decoder> Decodable<D> for Hash128 { - #[inline] - fn decode(d: &mut D) -> Self { - Self { inner: u128::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap()) } - } -} - -impl FromStableHash for Hash128 { - type Hash = StableHasherHash; - - #[inline] - fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self { - Self { inner: u128::from(_0) | (u128::from(_1) << 64) } - } -} - -impl fmt::Debug for Hash128 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.inner.fmt(f) - } -} - -impl fmt::LowerHex for Hash128 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::LowerHex::fmt(&self.inner, f) - } -} diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 6ef73debadd..66d3834d857 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -84,7 +84,6 @@ pub mod vec_cache; pub mod work_queue; mod atomic_ref; -mod hashes; /// This calls the passed function while ensuring it won't be inlined into the caller. #[inline(never)] diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 9cd0cc499ca..ffbe54d6206 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -10,12 +10,11 @@ use smallvec::SmallVec; #[cfg(test)] mod tests; +use rustc_hashes::{Hash64, Hash128}; pub use rustc_stable_hash::{ FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher, }; -pub use crate::hashes::{Hash64, Hash128}; - /// Something that implements `HashStable<CTX>` can be hashed in a way that is /// stable across multiple compilation sessions. /// diff --git a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs index b1bdee18d6d..9c1e4cefa69 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs @@ -1,7 +1,8 @@ use std::ptr; +use rustc_hashes::Hash128; + use super::*; -use crate::hashes::Hash128; use crate::stable_hasher::{HashStable, StableHasher}; /// A tag type used in [`TaggedRef`] tests. |
