Overhaul stable hashing traits.

`std::hash::Hash` looks like this:
```
pub trait Hash {
    fn hash<H>(&self, state: &mut H)
       where H: Hasher;

    ...
}
```
The method is generic.

In contrast, `HashStable` looks like this:
```
pub trait HashStable<Hcx> {
    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
and impls look like this (in crates upstream of `rustc_middle`):
```
impl<Hcx: HashStableContext> HashStable<Hcx> for Path {
    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
        ...
    }
}
```
or this (in `rustc_middle` and crates downstream of `rustc_middle`):
```
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
    fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
	...
    }
}
```
Differences to `std::hash::Hash`:
- The trait is generic, rather than the method.
- The way impls are written depends their position in the crate graph.
- This explains why we have both `derive(HashStable)` and
  `derive(HashStable_Generic)`. The former is for the
  downstream-of-`rustc_middle` case, the latter is for the upstream of
  `rustc_middle` case.

Why the differences? It all boils down to `HashStable` and
`HashStableContext` being in different crates. But the previous commit
fixed that, which means `HashStable` can be simplified to this, with a
generic method:
```
pub trait HashStable {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
and all impls look like this:
```
impl HashStable for Path {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
        ...
    }
}
```

Other consequences:
- `derive(HashStable_Generic)` is no longer needed; `derive(HashStable)`
  can be used instead.
  - In this commit, `derive(HashStable_Generic` is made a synonym of
    `derive(HashStable)`. The next commit will remove this synonym,
    because it's a change that touches many lines.
- `#[stable_hash_generic]` is no longer needed (for `newtype_index`);
  `#[stable_hash]` can be used instead.
  - `#[stable_hash_no_context]` was already a synonym of
    `#[stable_hash_generic]`, so it's also removed in favour of just
    `#[stable_hash]`.
- The difference between `derive(HashStable)` and
  `derive(HashStable_NoContext)` now comes down to the difference
  between `synstructure::AddBounds::Generics` and
  `synstructure::AddBounds::Fields`, which is basically "vanilla derive"
  vs "(near) perfect derive".
  - I have improved the comments on `HashStableMode` to better
    explaining this subtle difference.
- `rustc_middle/src/ich/impls_syntax.rs` is no longer needed; the
  relevant impls can be defined in the crate that defines the relevant
  type.
- Occurrences of `for<'a> HashStable<StableHashingContext<'a>>` are
  replaced with with `HashStable`, hooray.
- The commit adds a `HashStableContext::hashing_controls` method, which
  is no big deal. (It's necessary for `AdtDefData::hash_stable`, which
  calls `hashing_controls` and used to have an `hcx` that was a
  concrete `StableHashingContext` but now has an `hcx` that is just
  `Hcx: HashStableContext`.)

Overall this is a big simplification, removing a lot of confusing
complexity in stable hashing traits.
This commit is contained in:
Nicholas Nethercote
2026-04-03 14:08:20 +11:00
parent a6318f677d
commit 36c9d23902
53 changed files with 442 additions and 439 deletions
+5 -3
View File
@@ -3,7 +3,9 @@ use std::fmt;
use std::hash::{Hash, Hasher};
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
use rustc_data_structures::stable_hasher::{
HashStable, HashStableContext, StableHasher, StableOrd,
};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable, Encodable};
#[cfg(feature = "nightly")]
@@ -240,9 +242,9 @@ impl Hash for ExternAbi {
}
#[cfg(feature = "nightly")]
impl<C> HashStable<C> for ExternAbi {
impl HashStable for ExternAbi {
#[inline]
fn hash_stable(&self, _: &mut C, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
Hash::hash(self, hasher);
}
}
+2 -2
View File
@@ -45,7 +45,7 @@ rustc_index::newtype_index! {
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
#[stable_hash_generic]
#[stable_hash]
#[encodable]
#[orderable]
#[gate_rustc_only]
@@ -70,7 +70,7 @@ rustc_index::newtype_index! {
///
/// `struct`s, `tuples`, and `unions`s are considered to have a single variant
/// with variant index zero, aka [`FIRST_VARIANT`].
#[stable_hash_generic]
#[stable_hash]
#[encodable]
#[orderable]
#[gate_rustc_only]
+2 -2
View File
@@ -120,8 +120,8 @@ impl PartialEq<&[Symbol]> for Path {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for Path {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for Path {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
segment.ident.hash_stable(hcx, hasher);
+8
View File
@@ -1,5 +1,6 @@
use std::fmt;
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
use rustc_span::LocalExpnId;
rustc_index::newtype_index! {
@@ -18,6 +19,13 @@ rustc_index::newtype_index! {
}
}
impl HashStable for NodeId {
#[inline]
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, _: &mut StableHasher) {
panic!("Node IDs should not appear in incremental state");
}
}
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);
/// When parsing and at the beginning of doing expansions, we initially give all AST nodes
+4 -7
View File
@@ -138,8 +138,8 @@ impl<D: SpanDecoder> Decodable<D> for LazyAttrTokenStream {
}
}
impl<Hcx> HashStable<Hcx> for LazyAttrTokenStream {
fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
impl HashStable for LazyAttrTokenStream {
fn hash_stable<Hcx: HashStableContext>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
panic!("Attempted to compute stable hash for LazyAttrTokenStream");
}
}
@@ -824,11 +824,8 @@ impl FromIterator<TokenTree> for TokenStream {
}
}
impl<Hcx> HashStable<Hcx> for TokenStream
where
Hcx: HashStableContext,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for TokenStream {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
for sub_tt in self.iter() {
sub_tt.hash_stable(hcx, hasher);
}
@@ -14,7 +14,7 @@ use rustc_codegen_ssa::back::write::produce_final_output_artifacts;
use rustc_codegen_ssa::base::determine_cgu_reuse;
use rustc_codegen_ssa::{CompiledModule, CompiledModules, ModuleKind};
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
use rustc_hir::attrs::Linkage as RLinkage;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
@@ -45,8 +45,8 @@ enum OngoingModuleCodegen {
Async(JoinHandle<Result<ModuleCodegenResult, String>>),
}
impl<Hcx> HashStable<Hcx> for OngoingModuleCodegen {
fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {
impl HashStable for OngoingModuleCodegen {
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, _: &mut StableHasher) {
// do nothing
}
}
+3 -3
View File
@@ -98,12 +98,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::{HashStable, HashStableContext, StableHasher};
use crate::ModuleCodegen;
impl<Hcx, M> HashStable<Hcx> for ModuleCodegen<M> {
fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {
impl<M> HashStable for ModuleCodegen<M> {
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, _: &mut StableHasher) {
// do nothing
}
}
+4 -4
View File
@@ -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::{HashStable, HashStableContext, StableHasher};
mod private {
#[derive(Clone, Copy, Debug)]
@@ -103,11 +103,11 @@ where
}
}
impl<T, Hcx> HashStable<Hcx> for Interned<'_, T>
impl<T> HashStable for Interned<'_, T>
where
T: HashStable<Hcx>,
T: HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.0.hash_stable(hcx, hasher);
}
}
+3 -3
View File
@@ -3,7 +3,7 @@ use std::fmt;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use crate::stable_hasher::{HashStable, StableHasher};
use crate::stable_hasher::{HashStable, HashStableContext, StableHasher};
/// A packed 128-bit integer. Useful for reducing the size of structures in
/// some cases.
@@ -60,9 +60,9 @@ impl fmt::UpperHex for Pu128 {
}
}
impl<Hcx> HashStable<Hcx> for Pu128 {
impl HashStable for Pu128 {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
{ self.0 }.hash_stable(hcx, hasher)
}
}
@@ -7,7 +7,7 @@ use std::ops::{Bound, Index, IndexMut, RangeBounds};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use crate::stable_hasher::{HashStable, StableHasher, StableOrd};
use crate::stable_hasher::{HashStable, HashStableContext, StableHasher, StableOrd};
mod index_map;
@@ -347,9 +347,9 @@ impl<K: Ord, V> FromIterator<(K, V)> for SortedMap<K, V> {
}
}
impl<K: HashStable<Hcx> + StableOrd, V: HashStable<Hcx>, Hcx> HashStable<Hcx> for SortedMap<K, V> {
impl<K: HashStable + StableOrd, V: HashStable> HashStable for SortedMap<K, V> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.data.hash_stable(hcx, hasher);
}
}
@@ -15,7 +15,7 @@ pub use rustc_stable_hash::{
FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher,
};
/// This trait lets `HashStable` and `derive(HashStable_Generic)` be used in
/// This trait lets `HashStable` and `derive(HashStable)` be used in
/// this crate (and other crates upstream of `rustc_middle`), while leaving
/// certain operations to be defined in `rustc_middle` where more things are
/// visible.
@@ -26,6 +26,9 @@ pub trait HashStableContext {
/// Compute a `DefPathHash`.
fn def_path_hash(&self, def_id: RawDefId) -> RawDefPathHash;
/// Get the hashing controls.
fn hashing_controls(&self) -> HashingControls;
/// Assert that the provided `HashStableContext` is configured with the default
/// `HashingControls`. We should always have bailed out before getting to here with a
fn assert_default_hashing_controls(&self, msg: &str);
@@ -43,7 +46,7 @@ pub struct RawDefId(pub u32, pub u32);
// `DefPathHash`.
pub struct RawDefPathHash(pub [u8; 16]);
/// Something that implements `HashStable<Hcx>` can be hashed in a way that is
/// Something that implements `HashStable` can be hashed in a way that is
/// stable across multiple compilation sessions.
///
/// Note that `HashStable` imposes rather more strict requirements than usual
@@ -69,16 +72,16 @@ pub struct RawDefPathHash(pub [u8; 16]);
/// - `hash_stable()` must be independent of the host architecture. The
/// `StableHasher` takes care of endianness and `isize`/`usize` platform
/// differences.
pub trait HashStable<Hcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
pub trait HashStable {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
/// Implement this for types that can be turned into stable keys like, for
/// example, for DefId that can be converted to a DefPathHash. This is used for
/// bringing maps into a predictable order before hashing them.
pub trait ToStableHashKey<Hcx> {
type KeyType: Ord + Sized + HashStable<Hcx>;
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType;
pub trait ToStableHashKey {
type KeyType: Ord + Sized + HashStable;
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> Self::KeyType;
}
/// Trait for marking a type as having a sort order that is
@@ -161,12 +164,16 @@ impl<T: StableOrd> StableCompare for T {
/// for examples). Therefore this macro is not exported and should only be used in the limited cases
/// here in this module.
///
/// Use `#[derive(HashStable_Generic)]` instead.
/// Use `#[derive(HashStable)]` instead.
macro_rules! impl_stable_traits_for_trivial_type {
($t:ty) => {
impl<Hcx> $crate::stable_hasher::HashStable<Hcx> for $t {
impl $crate::stable_hasher::HashStable for $t {
#[inline]
fn hash_stable(&self, _: &mut Hcx, hasher: &mut $crate::stable_hasher::StableHasher) {
fn hash_stable<Hcx>(
&self,
_: &mut Hcx,
hasher: &mut $crate::stable_hasher::StableHasher,
) {
::std::hash::Hash::hash(self, hasher);
}
}
@@ -205,9 +212,9 @@ impl_stable_traits_for_trivial_type!(Hash64);
// We need a custom impl as the default hash function will only hash half the bits. For stable
// hashing we want to hash the full 128-bit hash.
impl<Hcx> HashStable<Hcx> for Hash128 {
impl HashStable for Hash128 {
#[inline]
fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
self.as_u128().hash(hasher);
}
}
@@ -220,61 +227,61 @@ impl StableOrd for Hash128 {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<Hcx> HashStable<Hcx> for ! {
fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
impl HashStable for ! {
fn hash_stable<Hcx>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
unreachable!()
}
}
impl<Hcx, T> HashStable<Hcx> for PhantomData<T> {
fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {}
impl<T> HashStable for PhantomData<T> {
fn hash_stable<Hcx>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {}
}
impl<Hcx> HashStable<Hcx> for NonZero<u32> {
impl HashStable for NonZero<u32> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.get().hash_stable(hcx, hasher)
}
}
impl<Hcx> HashStable<Hcx> for NonZero<usize> {
impl HashStable for NonZero<usize> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.get().hash_stable(hcx, hasher)
}
}
impl<Hcx> HashStable<Hcx> for f32 {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for f32 {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let val: u32 = self.to_bits();
val.hash_stable(hcx, hasher);
}
}
impl<Hcx> HashStable<Hcx> for f64 {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for f64 {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let val: u64 = self.to_bits();
val.hash_stable(hcx, hasher);
}
}
impl<Hcx> HashStable<Hcx> for ::std::cmp::Ordering {
impl HashStable for ::std::cmp::Ordering {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
(*self as i8).hash_stable(hcx, hasher);
}
}
impl<T1: HashStable<Hcx>, Hcx> HashStable<Hcx> for (T1,) {
impl<T1: HashStable> HashStable for (T1,) {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let (ref _0,) = *self;
_0.hash_stable(hcx, hasher);
}
}
impl<T1: HashStable<Hcx>, T2: HashStable<Hcx>, Hcx> HashStable<Hcx> for (T1, T2) {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<T1: HashStable, T2: HashStable> HashStable for (T1, T2) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let (ref _0, ref _1) = *self;
_0.hash_stable(hcx, hasher);
_1.hash_stable(hcx, hasher);
@@ -289,13 +296,13 @@ impl<T1: StableOrd, T2: StableOrd> StableOrd for (T1, T2) {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<T1, T2, T3, Hcx> HashStable<Hcx> for (T1, T2, T3)
impl<T1, T2, T3> HashStable for (T1, T2, T3)
where
T1: HashStable<Hcx>,
T2: HashStable<Hcx>,
T3: HashStable<Hcx>,
T1: HashStable,
T2: HashStable,
T3: HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let (ref _0, ref _1, ref _2) = *self;
_0.hash_stable(hcx, hasher);
_1.hash_stable(hcx, hasher);
@@ -312,14 +319,14 @@ impl<T1: StableOrd, T2: StableOrd, T3: StableOrd> StableOrd for (T1, T2, T3) {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<T1, T2, T3, T4, Hcx> HashStable<Hcx> for (T1, T2, T3, T4)
impl<T1, T2, T3, T4> HashStable for (T1, T2, T3, T4)
where
T1: HashStable<Hcx>,
T2: HashStable<Hcx>,
T3: HashStable<Hcx>,
T4: HashStable<Hcx>,
T1: HashStable,
T2: HashStable,
T3: HashStable,
T4: HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let (ref _0, ref _1, ref _2, ref _3) = *self;
_0.hash_stable(hcx, hasher);
_1.hash_stable(hcx, hasher);
@@ -339,8 +346,12 @@ impl<T1: StableOrd, T2: StableOrd, T3: StableOrd, T4: StableOrd> StableOrd for (
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<T: HashStable<Hcx>, Hcx> HashStable<Hcx> for [T] {
default fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<T: HashStable> HashStable for [T] {
default fn hash_stable<Hcx: HashStableContext>(
&self,
hcx: &mut Hcx,
hasher: &mut StableHasher,
) {
self.len().hash_stable(hcx, hasher);
for item in self {
item.hash_stable(hcx, hasher);
@@ -348,28 +359,28 @@ impl<T: HashStable<Hcx>, Hcx> HashStable<Hcx> for [T] {
}
}
impl<Hcx> HashStable<Hcx> for [u8] {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for [u8] {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
hasher.write(self);
}
}
impl<T: HashStable<Hcx>, Hcx> HashStable<Hcx> for Vec<T> {
impl<T: HashStable> HashStable for Vec<T> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self[..].hash_stable(hcx, hasher);
}
}
impl<K, V, R, Hcx> HashStable<Hcx> for indexmap::IndexMap<K, V, R>
impl<K, V, R> HashStable for indexmap::IndexMap<K, V, R>
where
K: HashStable<Hcx> + Eq + Hash,
V: HashStable<Hcx>,
K: HashStable + Eq + Hash,
V: HashStable,
R: BuildHasher,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
for kv in self {
kv.hash_stable(hcx, hasher);
@@ -377,13 +388,13 @@ where
}
}
impl<K, R, Hcx> HashStable<Hcx> for indexmap::IndexSet<K, R>
impl<K, R> HashStable for indexmap::IndexSet<K, R>
where
K: HashStable<Hcx> + Eq + Hash,
K: HashStable + Eq + Hash,
R: BuildHasher,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
for key in self {
key.hash_stable(hcx, hasher);
@@ -391,40 +402,40 @@ where
}
}
impl<A, const N: usize, Hcx> HashStable<Hcx> for SmallVec<[A; N]>
impl<A, const N: usize> HashStable for SmallVec<[A; N]>
where
A: HashStable<Hcx>,
A: HashStable,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self[..].hash_stable(hcx, hasher);
}
}
impl<T: ?Sized + HashStable<Hcx>, Hcx> HashStable<Hcx> for Box<T> {
impl<T: ?Sized + HashStable> HashStable for Box<T> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
(**self).hash_stable(hcx, hasher);
}
}
impl<T: ?Sized + HashStable<Hcx>, Hcx> HashStable<Hcx> for ::std::rc::Rc<T> {
impl<T: ?Sized + HashStable> HashStable for ::std::rc::Rc<T> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
(**self).hash_stable(hcx, hasher);
}
}
impl<T: ?Sized + HashStable<Hcx>, Hcx> HashStable<Hcx> for ::std::sync::Arc<T> {
impl<T: ?Sized + HashStable> HashStable for ::std::sync::Arc<T> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
(**self).hash_stable(hcx, hasher);
}
}
impl<Hcx> HashStable<Hcx> for str {
impl HashStable for str {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.as_bytes().hash_stable(hcx, hasher);
}
}
@@ -437,9 +448,9 @@ impl StableOrd for &str {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<Hcx> HashStable<Hcx> for String {
impl HashStable for String {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self[..].hash_stable(hcx, hasher);
}
}
@@ -452,25 +463,25 @@ impl StableOrd for String {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<Hcx> ToStableHashKey<Hcx> for String {
impl ToStableHashKey for String {
type KeyType = String;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
self.clone()
}
}
impl<Hcx, T1: ToStableHashKey<Hcx>, T2: ToStableHashKey<Hcx>> ToStableHashKey<Hcx> for (T1, T2) {
impl<T1: ToStableHashKey, T2: ToStableHashKey> ToStableHashKey for (T1, T2) {
type KeyType = (T1::KeyType, T2::KeyType);
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> Self::KeyType {
(self.0.to_stable_hash_key(hcx), self.1.to_stable_hash_key(hcx))
}
}
impl<Hcx> HashStable<Hcx> for bool {
impl HashStable for bool {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
(if *self { 1u8 } else { 0u8 }).hash_stable(hcx, hasher);
}
}
@@ -482,12 +493,12 @@ impl StableOrd for bool {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<T, Hcx> HashStable<Hcx> for Option<T>
impl<T> HashStable for Option<T>
where
T: HashStable<Hcx>,
T: HashStable,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
if let Some(ref value) = *self {
1u8.hash_stable(hcx, hasher);
value.hash_stable(hcx, hasher);
@@ -504,13 +515,13 @@ impl<T: StableOrd> StableOrd for Option<T> {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<T1, T2, Hcx> HashStable<Hcx> for Result<T1, T2>
impl<T1, T2> HashStable for Result<T1, T2>
where
T1: HashStable<Hcx>,
T2: HashStable<Hcx>,
T1: HashStable,
T2: HashStable,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
Ok(ref x) => x.hash_stable(hcx, hasher),
@@ -519,39 +530,39 @@ where
}
}
impl<'a, T, Hcx> HashStable<Hcx> for &'a T
impl<'a, T> HashStable for &'a T
where
T: HashStable<Hcx> + ?Sized,
T: HashStable + ?Sized,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
(**self).hash_stable(hcx, hasher);
}
}
impl<T, Hcx> HashStable<Hcx> for ::std::mem::Discriminant<T> {
impl<T> HashStable for ::std::mem::Discriminant<T> {
#[inline]
fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}
impl<T, Hcx> HashStable<Hcx> for ::std::ops::RangeInclusive<T>
impl<T> HashStable for ::std::ops::RangeInclusive<T>
where
T: HashStable<Hcx>,
T: HashStable,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.start().hash_stable(hcx, hasher);
self.end().hash_stable(hcx, hasher);
}
}
impl<I: Idx, T, Hcx> HashStable<Hcx> for IndexSlice<I, T>
impl<I: Idx, T> HashStable for IndexSlice<I, T>
where
T: HashStable<Hcx>,
T: HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
for v in &self.raw {
v.hash_stable(hcx, hasher);
@@ -559,11 +570,11 @@ where
}
}
impl<I: Idx, T, Hcx> HashStable<Hcx> for IndexVec<I, T>
impl<I: Idx, T> HashStable for IndexVec<I, T>
where
T: HashStable<Hcx>,
T: HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
for v in &self.raw {
v.hash_stable(hcx, hasher);
@@ -571,14 +582,14 @@ where
}
}
impl<I: Idx, Hcx> HashStable<Hcx> for DenseBitSet<I> {
fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<I: Idx> HashStable for DenseBitSet<I> {
fn hash_stable<Hcx: HashStableContext>(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}
impl<R: Idx, C: Idx, Hcx> HashStable<Hcx> for bit_set::BitMatrix<R, C> {
fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<R: Idx, C: Idx> HashStable for bit_set::BitMatrix<R, C> {
fn hash_stable<Hcx: HashStableContext>(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}
@@ -591,15 +602,15 @@ impl_stable_traits_for_trivial_type!(::std::path::PathBuf);
// It is not safe to implement HashStable for HashSet, HashMap or any other collection type
// with unstable but observable iteration order.
// See https://github.com/rust-lang/compiler-team/issues/533 for further information.
impl<V, Hcx> !HashStable<Hcx> for std::collections::HashSet<V> {}
impl<K, V, Hcx> !HashStable<Hcx> for std::collections::HashMap<K, V> {}
impl<V> !HashStable for std::collections::HashSet<V> {}
impl<K, V> !HashStable for std::collections::HashMap<K, V> {}
impl<K, V, Hcx> HashStable<Hcx> for ::std::collections::BTreeMap<K, V>
impl<K, V> HashStable for ::std::collections::BTreeMap<K, V>
where
K: HashStable<Hcx> + StableOrd,
V: HashStable<Hcx>,
K: HashStable + StableOrd,
V: HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
for entry in self.iter() {
entry.hash_stable(hcx, hasher);
@@ -607,11 +618,11 @@ where
}
}
impl<K, Hcx> HashStable<Hcx> for ::std::collections::BTreeSet<K>
impl<K> HashStable for ::std::collections::BTreeSet<K>
where
K: HashStable<Hcx> + StableOrd,
K: HashStable + StableOrd,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.len().hash_stable(hcx, hasher);
for entry in self.iter() {
entry.hash_stable(hcx, hasher);
@@ -7,10 +7,25 @@ use super::*;
// ways). The expected values depend on the hashing algorithm used, so they
// need to be updated whenever StableHasher changes its hashing algorithm.
fn hash<T: HashStable<()>>(t: &T) -> Hash128 {
impl HashStableContext for () {
fn span_hash_stable(&mut self, _: RawSpan, _: &mut StableHasher) {
panic!();
}
fn def_path_hash(&self, _: RawDefId) -> RawDefPathHash {
panic!();
}
fn hashing_controls(&self) -> HashingControls {
panic!();
}
fn assert_default_hashing_controls(&self, _: &str) {
panic!();
}
}
fn hash<T: HashStable>(t: &T) -> Hash128 {
let mut h = StableHasher::new();
let ctx = &mut ();
t.hash_stable(ctx, &mut h);
let hcx = &mut ();
t.hash_stable(hcx, &mut h);
h.finish()
}
@@ -44,8 +59,12 @@ fn test_attribute_permutation() {
b: $ty,
}
impl<Hcx> HashStable<Hcx> for Foo {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for Foo {
fn hash_stable<Hcx: HashStableContext>(
&self,
hcx: &mut Hcx,
hasher: &mut StableHasher,
) {
self.a.hash_stable(hcx, hasher);
self.b.hash_stable(hcx, hasher);
}
+3 -3
View File
@@ -1,4 +1,4 @@
use crate::stable_hasher::{HashStable, StableHasher};
use crate::stable_hasher::{HashStable, HashStableContext, StableHasher};
use crate::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard, RwLock, WriteGuard};
/// The `Steal` struct is intended to used as the value for a query.
@@ -71,8 +71,8 @@ impl<T> Steal<T> {
}
}
impl<Hcx, T: HashStable<Hcx>> HashStable<Hcx> for Steal<T> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<T: HashStable> HashStable for Steal<T> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.borrow().hash_stable(hcx, hasher);
}
}
@@ -12,7 +12,7 @@ use std::ops::Deref;
use std::ptr::NonNull;
use crate::aligned::Aligned;
use crate::stable_hasher::{HashStable, StableHasher};
use crate::stable_hasher::{HashStable, HashStableContext, StableHasher};
/// This describes tags that the [`TaggedRef`] struct can hold.
///
@@ -259,12 +259,12 @@ impl<P, T: Tag> Hash for TaggedRef<'_, P, T> {
}
}
impl<'a, P, T, Hcx> HashStable<Hcx> for TaggedRef<'a, P, T>
impl<'a, P, T> HashStable for TaggedRef<'a, P, T>
where
P: HashStable<Hcx> + Aligned + ?Sized,
T: Tag + HashStable<Hcx>,
P: HashStable + Aligned + ?Sized,
T: Tag + HashStable,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.pointer().hash_stable(hcx, hasher);
self.tag().hash_stable(hcx, hasher);
}
@@ -32,8 +32,12 @@ unsafe impl Tag for Tag2 {
}
}
impl<Hcx> crate::stable_hasher::HashStable<Hcx> for Tag2 {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut crate::stable_hasher::StableHasher) {
impl HashStable for Tag2 {
fn hash_stable<Hcx: HashStableContext>(
&self,
hcx: &mut Hcx,
hasher: &mut crate::stable_hasher::StableHasher,
) {
(*self as u8).hash_stable(hcx, hasher);
}
}
+27 -18
View File
@@ -12,7 +12,9 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use crate::fingerprint::Fingerprint;
use crate::fx::{FxBuildHasher, FxHashMap, FxHashSet};
use crate::stable_hasher::{HashStable, StableCompare, StableHasher, ToStableHashKey};
use crate::stable_hasher::{
HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey,
};
/// `UnordItems` is the order-less version of `Iterator`. It only contains methods
/// that don't (easily) expose an ordering of the underlying items.
@@ -143,9 +145,9 @@ impl<'a, T: Copy + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> {
impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
#[inline]
pub fn into_sorted<Hcx>(self, hcx: &mut Hcx) -> Vec<T>
pub fn into_sorted<Hcx: HashStableContext>(self, hcx: &mut Hcx) -> Vec<T>
where
T: ToStableHashKey<Hcx>,
T: ToStableHashKey,
{
self.collect_sorted(hcx, true)
}
@@ -170,7 +172,8 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
#[inline]
pub fn collect_sorted<Hcx, C>(self, hcx: &mut Hcx, cache_sort_key: bool) -> C
where
T: ToStableHashKey<Hcx>,
Hcx: HashStableContext,
T: ToStableHashKey,
C: FromIterator<T> + BorrowMut<[T]>,
{
let mut items: C = self.0.collect();
@@ -317,7 +320,8 @@ impl<V: Eq + Hash> UnordSet<V> {
#[inline]
pub fn to_sorted<Hcx>(&self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<&V>
where
V: ToStableHashKey<Hcx>,
Hcx: HashStableContext,
V: ToStableHashKey,
{
to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&x| x)
}
@@ -359,7 +363,8 @@ impl<V: Eq + Hash> UnordSet<V> {
#[inline]
pub fn into_sorted<Hcx>(self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<V>
where
V: ToStableHashKey<Hcx>,
Hcx: HashStableContext,
V: ToStableHashKey,
{
to_sorted_vec(hcx, self.inner.into_iter(), cache_sort_key, |x| x)
}
@@ -415,9 +420,9 @@ impl<V: Hash + Eq, I: Iterator<Item = V>> From<UnordItems<V, I>> for UnordSet<V>
}
}
impl<Hcx, V: Hash + Eq + HashStable<Hcx>> HashStable<Hcx> for UnordSet<V> {
impl<V: Hash + Eq + HashStable> HashStable for UnordSet<V> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
hash_iter_order_independent(self.inner.iter(), hcx, hasher);
}
}
@@ -557,7 +562,8 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
#[inline]
pub fn to_sorted<Hcx>(&self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<(&K, &V)>
where
K: ToStableHashKey<Hcx>,
Hcx: HashStableContext,
K: ToStableHashKey,
{
to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&(k, _)| k)
}
@@ -584,7 +590,8 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
#[inline]
pub fn into_sorted<Hcx>(self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<(K, V)>
where
K: ToStableHashKey<Hcx>,
Hcx: HashStableContext,
K: ToStableHashKey,
{
to_sorted_vec(hcx, self.inner.into_iter(), cache_sort_key, |(k, _)| k)
}
@@ -616,7 +623,8 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
cache_sort_key: bool,
) -> impl Iterator<Item = &V>
where
K: ToStableHashKey<Hcx>,
Hcx: HashStableContext,
K: ToStableHashKey,
{
to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&(k, _)| k)
.into_iter()
@@ -642,9 +650,9 @@ where
}
}
impl<Hcx, K: Hash + Eq + HashStable<Hcx>, V: HashStable<Hcx>> HashStable<Hcx> for UnordMap<K, V> {
impl<K: Hash + Eq + HashStable, V: HashStable> HashStable for UnordMap<K, V> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
hash_iter_order_independent(self.inner.iter(), hcx, hasher);
}
}
@@ -705,9 +713,9 @@ impl<T, I: Iterator<Item = T>> From<UnordItems<T, I>> for UnordBag<T> {
}
}
impl<Hcx, V: Hash + Eq + HashStable<Hcx>> HashStable<Hcx> for UnordBag<V> {
impl<V: Hash + Eq + HashStable> HashStable for UnordBag<V> {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
hash_iter_order_independent(self.inner.iter(), hcx, hasher);
}
}
@@ -720,8 +728,9 @@ fn to_sorted_vec<Hcx, T, K, I>(
extract_key: fn(&T) -> &K,
) -> Vec<T>
where
Hcx: HashStableContext,
I: Iterator<Item = T>,
K: ToStableHashKey<Hcx>,
K: ToStableHashKey,
{
let mut items: Vec<T> = iter.collect();
if cache_sort_key {
@@ -734,8 +743,8 @@ where
}
fn hash_iter_order_independent<
Hcx,
T: HashStable<Hcx>,
Hcx: HashStableContext,
T: HashStable,
I: Iterator<Item = T> + ExactSizeIterator,
>(
mut it: I,
+27
View File
@@ -5,6 +5,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use rustc_data_structures::AtomicRef;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
use rustc_span::{Span, Symbol, sym};
use super::{Feature, to_nonzero};
@@ -119,6 +120,32 @@ impl Features {
}
}
impl HashStable for Features {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// Unfortunately we cannot exhaustively list fields here, since the
// struct has private fields (to ensure its invariant is maintained)
self.enabled_lang_features().hash_stable(hcx, hasher);
self.enabled_lib_features().hash_stable(hcx, hasher);
}
}
impl HashStable for EnabledLangFeature {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let EnabledLangFeature { gate_name, attr_sp, stable_since } = self;
gate_name.hash_stable(hcx, hasher);
attr_sp.hash_stable(hcx, hasher);
stable_since.hash_stable(hcx, hasher);
}
}
impl HashStable for EnabledLibFeature {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let EnabledLibFeature { gate_name, attr_sp } = self;
gate_name.hash_stable(hcx, hasher);
attr_sp.hash_stable(hcx, hasher);
}
}
macro_rules! declare_features {
($(
$(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr),
+3 -3
View File
@@ -4,7 +4,7 @@ use std::fmt::Debug;
use rustc_ast as ast;
use rustc_ast::NodeId;
use rustc_data_structures::stable_hasher::{HashStableContext, ToStableHashKey};
use rustc_data_structures::stable_hasher::ToStableHashKey;
use rustc_data_structures::unord::UnordMap;
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
@@ -712,11 +712,11 @@ impl IntoDiagArg for Namespace {
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for Namespace {
impl ToStableHashKey for Namespace {
type KeyType = Namespace;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> Namespace {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Namespace {
*self
}
}
+1 -1
View File
@@ -1250,7 +1250,7 @@ pub struct AttrItem {
pub span: Span,
}
/// The derived implementation of [`HashStable_Generic`] on [`Attribute`]s shouldn't hash
/// The derived implementation of [`HashStable`] on [`Attribute`]s shouldn't hash
/// [`AttrId`]s. By wrapping them in this, we make sure we never do.
#[derive(Copy, Debug, Encodable, Decodable, Clone)]
pub struct HashIgnoredAttrId {
+3 -3
View File
@@ -8,7 +8,7 @@
//! * Functions called by the compiler itself.
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
use rustc_macros::{BlobDecodable, Encodable, HashStable_Generic, PrintAttribute};
use rustc_span::{Symbol, kw, sym};
@@ -144,8 +144,8 @@ macro_rules! language_item_table {
}
}
impl<Hcx> HashStable<Hcx> for LangItem {
fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for LangItem {
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}
+19 -16
View File
@@ -9,48 +9,51 @@ use crate::hir::{
};
use crate::hir_id::ItemLocalId;
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for BodyId {
impl ToStableHashKey for BodyId {
type KeyType = (DefPathHash, ItemLocalId);
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
fn to_stable_hash_key<Hcx: HashStableContext>(
&self,
hcx: &mut Hcx,
) -> (DefPathHash, ItemLocalId) {
let BodyId { hir_id } = *self;
hir_id.to_stable_hash_key(hcx)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemId {
impl ToStableHashKey for ItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for TraitItemId {
impl ToStableHashKey for TraitItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ImplItemId {
impl ToStableHashKey for ImplItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ForeignItemId {
impl ToStableHashKey for ForeignItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
@@ -62,8 +65,8 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ForeignItemId {
// want to pick up on a reference changing its target, so we hash the NodeIds
// in "DefPath Mode".
impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<'tcx> HashStable for OwnerNodes<'tcx> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// 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
@@ -74,8 +77,8 @@ impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for OwnerNodes<'tcx> {
}
}
impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<'tcx> HashStable for AttributeMap<'tcx> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// 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, define_opaque: _, map: _ } = *self;
@@ -83,8 +86,8 @@ impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for AttributeMap<'tcx> {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for HashIgnoredAttrId {
fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
impl HashStable for HashIgnoredAttrId {
fn hash_stable<Hcx: HashStableContext>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
/* we don't hash HashIgnoredAttrId, we ignore them */
}
}
+12 -9
View File
@@ -55,18 +55,18 @@ impl rustc_index::Idx for OwnerId {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for OwnerId {
impl HashStable for OwnerId {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.to_stable_hash_key(hcx).hash_stable(hcx, hasher);
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for OwnerId {
impl ToStableHashKey for OwnerId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.to_def_id().to_stable_hash_key(hcx)
}
}
@@ -152,7 +152,7 @@ rustc_index::newtype_index! {
/// integers starting at zero, so a mapping that maps all or most nodes within
/// an "item-like" to something else can be implemented by a `Vec` instead of a
/// tree or hash map.
#[stable_hash_generic]
#[stable_hash]
#[encodable]
#[orderable]
pub struct ItemLocalId {}
@@ -177,21 +177,24 @@ pub const CRATE_HIR_ID: HirId =
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for HirId {
impl ToStableHashKey for HirId {
type KeyType = (DefPathHash, ItemLocalId);
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
fn to_stable_hash_key<Hcx: HashStableContext>(
&self,
hcx: &mut Hcx,
) -> (DefPathHash, ItemLocalId) {
let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
(def_path_hash, self.local_id)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemLocalId {
impl ToStableHashKey for ItemLocalId {
type KeyType = ItemLocalId;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> ItemLocalId {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> ItemLocalId {
*self
}
}
+8 -21
View File
@@ -24,8 +24,6 @@ impl Parse for Newtype {
let mut encodable = false;
let mut ord = false;
let mut stable_hash = false;
let mut stable_hash_generic = false;
let mut stable_hash_no_context = false;
let mut gate_rustc_only = quote! {};
let mut gate_rustc_only_cfg = quote! { all() };
@@ -48,14 +46,6 @@ impl Parse for Newtype {
stable_hash = true;
false
}
"stable_hash_generic" => {
stable_hash_generic = true;
false
}
"stable_hash_no_context" => {
stable_hash_no_context = true;
false
}
"max" => {
let Meta::NameValue(MetaNameValue { value: Expr::Lit(lit), .. }) = &attr.meta
else {
@@ -165,17 +155,14 @@ impl Parse for Newtype {
let hash_stable = if stable_hash {
quote! {
#gate_rustc_only
impl<'__ctx> ::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>> for #name {
fn hash_stable(&self, hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>, hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) {
self.as_u32().hash_stable(hcx, hasher)
}
}
}
} else if stable_hash_generic || stable_hash_no_context {
quote! {
#gate_rustc_only
impl<Hcx> ::rustc_data_structures::stable_hasher::HashStable<Hcx> for #name {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) {
impl ::rustc_data_structures::stable_hasher::HashStable for #name {
fn hash_stable<
__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext
>(
&self,
hcx: &mut __Hcx,
hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher
) {
self.as_u32().hash_stable(hcx, hasher)
}
}
+8 -8
View File
@@ -138,9 +138,9 @@ impl LintExpectationId {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for LintExpectationId {
impl HashStable for LintExpectationId {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
match self {
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
hir_id.hash_stable(hcx, hasher);
@@ -156,11 +156,11 @@ impl<Hcx: HashStableContext> HashStable<Hcx> for LintExpectationId {
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for LintExpectationId {
impl ToStableHashKey for LintExpectationId {
type KeyType = (DefPathHash, ItemLocalId, u16, u16);
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> Self::KeyType {
match self {
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx);
@@ -621,18 +621,18 @@ impl LintId {
}
}
impl<Hcx> HashStable<Hcx> for LintId {
impl HashStable for LintId {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.lint_name_raw().hash_stable(hcx, hasher);
}
}
impl<Hcx> ToStableHashKey<Hcx> for LintId {
impl ToStableHashKey for LintId {
type KeyType = &'static str;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> &'static str {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> &'static str {
self.lint_name_raw()
}
}
+21 -49
View File
@@ -1,6 +1,5 @@
use proc_macro2::Ident;
use quote::quote;
use syn::parse_quote;
struct Attributes {
ignore: bool,
@@ -42,12 +41,6 @@ pub(crate) fn hash_stable_derive(s: synstructure::Structure<'_>) -> proc_macro2:
hash_stable_derive_with_mode(s, HashStableMode::Normal)
}
pub(crate) fn hash_stable_generic_derive(
s: synstructure::Structure<'_>,
) -> proc_macro2::TokenStream {
hash_stable_derive_with_mode(s, HashStableMode::Generic)
}
pub(crate) fn hash_stable_no_context_derive(
s: synstructure::Structure<'_>,
) -> proc_macro2::TokenStream {
@@ -55,13 +48,19 @@ pub(crate) fn hash_stable_no_context_derive(
}
enum HashStableMode {
// Use the query-system aware stable hashing context.
// Do a normal derive, where any generic type parameter gets a `HashStable` bound.
// For example, in `struct Abc<T, U>(T, U)` the added bounds are `T: HashStable` and
// `U: HashStable`.
Normal,
// Emit a generic implementation that uses a crate-local `StableHashingContext`
// trait, when the crate is upstream of `rustc_middle`.
Generic,
// Emit a hash-stable implementation that takes no context,
// and emits per-field where clauses for (almost-)perfect derives.
// Do an (almost-)perfect derive, where any field with a generic type parameter gets a
// `HashStable` bound. For example, in `struct Def<T, U>(T, U::Assoc)` the added bounds are
// `T::HashStable` and `U::Assoc: HashStable` (not `U: HashStable`).
//
// This is used most commonly in `rustc_type_ir` for types like `TyKind<I: Interner>`.
// `Interner` does not impl `HashStable`, but the fields of `TyKind` do not use `I` itself,
// instead only using associated types from `I` such as `I::Region`. On types like `TyKind` we
// typically also see the use of `derive_where` for built-in traits such as `Debug`.
NoContext,
}
@@ -69,52 +68,25 @@ fn hash_stable_derive_with_mode(
mut s: synstructure::Structure<'_>,
mode: HashStableMode,
) -> proc_macro2::TokenStream {
let generic: syn::GenericParam = match mode {
HashStableMode::Normal => parse_quote!('__ctx),
HashStableMode::Generic | HashStableMode::NoContext => parse_quote!(__CTX),
let add_bounds = match mode {
HashStableMode::Normal => synstructure::AddBounds::Generics,
HashStableMode::NoContext => synstructure::AddBounds::Fields,
};
// no_context impl is able to derive by-field, which is closer to a perfect derive.
s.add_bounds(match mode {
HashStableMode::Normal | HashStableMode::Generic => synstructure::AddBounds::Generics,
HashStableMode::NoContext => synstructure::AddBounds::Fields,
});
// For generic impl, add `where __CTX: HashStableContext`.
match mode {
HashStableMode::Normal => {}
HashStableMode::Generic => {
s.add_where_predicate(parse_quote! {
__CTX: ::rustc_data_structures::stable_hasher::HashStableContext
});
}
HashStableMode::NoContext => {}
}
s.add_impl_generic(generic);
s.add_bounds(add_bounds);
let discriminant = hash_stable_discriminant(&mut s);
let body = hash_stable_body(&mut s);
let context: syn::Type = match mode {
HashStableMode::Normal => {
parse_quote!(::rustc_middle::ich::StableHashingContext<'__ctx>)
}
HashStableMode::Generic | HashStableMode::NoContext => parse_quote!(__CTX),
};
s.bound_impl(
quote!(
::rustc_data_structures::stable_hasher::HashStable<
#context
>
),
quote!(::rustc_data_structures::stable_hasher::HashStable),
quote! {
#[inline]
fn hash_stable(
fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(
&self,
__hcx: &mut #context,
__hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) {
__hcx: &mut __Hcx,
__hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher
) {
#discriminant
match *self { #body }
}
+6 -8
View File
@@ -58,17 +58,15 @@ pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream {
extension::extension(attr, input)
}
decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
decl_derive!(
[HashStable_Generic, attributes(stable_hasher)] =>
hash_stable::hash_stable_generic_derive
[HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive
);
decl_derive!(
[HashStable_NoContext, attributes(stable_hasher)] =>
/// `HashStable` implementation that has no `HashStableContext` bound and
/// which adds `where` bounds for `HashStable` based off of fields and not
/// generics. This is suitable for use in crates like `rustc_type_ir`.
hash_stable::hash_stable_no_context_derive
// FIXME: synonym of `HashStable`, will be removed shortly
[HashStable_Generic, attributes(stable_hasher)] => hash_stable::hash_stable_derive
);
decl_derive!(
[HashStable_NoContext, attributes(stable_hasher)] => hash_stable::hash_stable_no_context_derive
);
// Encoding and Decoding derives
@@ -231,10 +231,10 @@ impl WorkProductId {
WorkProductId { hash: hasher.finish() }
}
}
impl<Hcx> ToStableHashKey<Hcx> for WorkProductId {
impl ToStableHashKey for WorkProductId {
type KeyType = Fingerprint;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
self.hash
}
}
@@ -7,7 +7,6 @@ use rustc_hir::definitions::DefPathHash;
use rustc_hir::{HirId, ItemLocalId, OwnerId};
use crate::dep_graph::{DepNode, KeyFingerprintStyle};
use crate::ich::StableHashingContext;
use crate::ty::TyCtxt;
/// Trait for query keys as seen by dependency-node tracking.
@@ -30,7 +29,7 @@ pub trait DepNodeKey<'tcx>: Debug + Sized {
// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
impl<'tcx, T> DepNodeKey<'tcx> for T
where
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
T: HashStable + Debug,
{
#[inline(always)]
default fn key_fingerprint_style() -> KeyFingerprintStyle {
+1 -1
View File
@@ -123,7 +123,7 @@ pub struct DepGraphData {
pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Fingerprint
where
R: for<'a> HashStable<StableHashingContext<'a>>,
R: HashStable,
{
let mut stable_hasher = StableHasher::new();
result.hash_stable(hcx, &mut stable_hasher);
+2 -2
View File
@@ -76,8 +76,8 @@ impl<'hir> Crate<'hir> {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for Crate<'_> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for Crate<'_> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let Crate { opt_hir_hash, .. } = self;
opt_hir_hash.unwrap().hash_stable(hcx, hasher)
}
+5
View File
@@ -190,4 +190,9 @@ impl<'a> HashStableContext for StableHashingContext<'a> {
"Attempted hashing of {msg} with non-default HashingControls: {hashing_controls:?}"
);
}
#[inline]
fn hashing_controls(&self) -> HashingControls {
self.hashing_controls
}
}
@@ -1,40 +0,0 @@
//! This module contains `HashStable` implementations for various data types
//! from various crates in no particular order.
use rustc_ast as ast;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use super::StableHashingContext;
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
#[inline]
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
panic!("Node IDs should not appear in incremental state");
}
}
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
// Unfortunately we cannot exhaustively list fields here, since the
// struct has private fields (to ensure its invariant is maintained)
self.enabled_lang_features().hash_stable(hcx, hasher);
self.enabled_lib_features().hash_stable(hcx, hasher);
}
}
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::EnabledLangFeature {
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
let rustc_feature::EnabledLangFeature { gate_name, attr_sp, stable_since } = self;
gate_name.hash_stable(hcx, hasher);
attr_sp.hash_stable(hcx, hasher);
stable_since.hash_stable(hcx, hasher);
}
}
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::EnabledLibFeature {
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
let rustc_feature::EnabledLibFeature { gate_name, attr_sp } = self;
gate_name.hash_stable(hcx, hasher);
attr_sp.hash_stable(hcx, hasher);
}
}
-1
View File
@@ -3,4 +3,3 @@
pub use self::hcx::StableHashingContext;
mod hcx;
mod impls_syntax;
+3 -4
View File
@@ -6,12 +6,11 @@ use std::cmp::Ordering;
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::{HashStable, HashStableContext, StableHasher};
use rustc_hir::def::DefKind;
use rustc_macros::HashStable;
use rustc_span::def_id::{CRATE_DEF_ID, LocalDefId};
use crate::ich::StableHashingContext;
use crate::ty::{TyCtxt, Visibility};
/// Represents the levels of effective visibility an item can have.
@@ -279,8 +278,8 @@ impl<Id> Default for EffectiveVisibilities<Id> {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for EffectiveVisibilities {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
impl HashStable for EffectiveVisibilities {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let EffectiveVisibilities { ref map } = *self;
map.hash_stable(hcx, hasher);
}
@@ -2,7 +2,7 @@ use std::sync::{Arc, OnceLock};
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::{HashStable, HashStableContext, StableHasher};
use rustc_index::{IndexSlice, IndexVec};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
@@ -171,7 +171,7 @@ impl<D: Decoder> Decodable<D> for Cache {
}
}
impl<Hcx> HashStable<Hcx> for Cache {
impl HashStable for Cache {
#[inline]
fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {}
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, _: &mut StableHasher) {}
}
+7 -6
View File
@@ -5,7 +5,9 @@ use std::hash::Hash;
use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_data_structures::stable_hasher::{
HashStable, HashStableContext, StableHasher, ToStableHashKey,
};
use rustc_data_structures::unord::UnordMap;
use rustc_hashes::Hash128;
use rustc_hir::ItemId;
@@ -19,7 +21,6 @@ use tracing::debug;
use crate::dep_graph::dep_node::{make_compile_codegen_unit, make_compile_mono_item};
use crate::dep_graph::{DepNode, WorkProduct, WorkProductId};
use crate::ich::StableHashingContext;
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::{self, GenericArgs, Instance, InstanceKind, SymbolName, Ty, TyCtxt};
@@ -325,10 +326,10 @@ impl<'tcx> fmt::Display for MonoItem<'tcx> {
}
}
impl ToStableHashKey<StableHashingContext<'_>> for MonoItem<'_> {
impl ToStableHashKey for MonoItem<'_> {
type KeyType = Fingerprint;
fn to_stable_hash_key(&self, hcx: &mut StableHashingContext<'_>) -> Self::KeyType {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> Self::KeyType {
let mut hasher = StableHasher::new();
self.hash_stable(hcx, &mut hasher);
hasher.finish()
@@ -581,10 +582,10 @@ impl<'tcx> CodegenUnit<'tcx> {
}
}
impl ToStableHashKey<StableHashingContext<'_>> for CodegenUnit<'_> {
impl ToStableHashKey for CodegenUnit<'_> {
type KeyType = String;
fn to_stable_hash_key(&self, _: &mut StableHashingContext<'_>) -> Self::KeyType {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
// Codegen unit names are conceptually required to be stable across
// compilation session so that object file names match up.
self.name.to_string()
+1 -2
View File
@@ -11,7 +11,6 @@ use rustc_hir::hir_id::OwnerId;
use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol};
use crate::dep_graph::DepNodeIndex;
use crate::ich::StableHashingContext;
use crate::infer::canonical::CanonicalQueryInput;
use crate::mono::CollectionMode;
use crate::query::{DefIdCache, DefaultCache, SingleCache, VecCache};
@@ -24,7 +23,7 @@ use crate::{mir, traits};
#[derive(Copy, Clone, Debug)]
pub struct LocalCrate;
pub trait QueryKeyBounds = Copy + Debug + Eq + Hash + for<'a> HashStable<StableHashingContext<'a>>;
pub trait QueryKeyBounds = Copy + Debug + Eq + Hash + HashStable;
/// Controls what types can legally be used as the key for a query.
pub trait QueryKey: Sized + QueryKeyBounds {
+5 -4
View File
@@ -7,7 +7,9 @@ use rustc_abi::{FIRST_VARIANT, FieldIdx, ReprOptions, VariantIdx};
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::{
HashStable, HashStableContext, HashingControls, StableHasher,
};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::DefId;
@@ -23,7 +25,6 @@ use tracing::{debug, info, trace};
use super::{
AsyncDestructor, Destructor, FieldDef, GenericPredicates, Ty, TyCtxt, VariantDef, VariantDiscr,
};
use crate::ich::StableHashingContext;
use crate::mir::interpret::ErrorHandled;
use crate::ty::util::{Discr, IntTypeExt};
use crate::ty::{self, ConstKind};
@@ -151,8 +152,8 @@ impl Hash for AdtDefData {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for AdtDefData {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
impl HashStable for AdtDefData {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
thread_local! {
static CACHE: RefCell<FxHashMap<(usize, HashingControls), Fingerprint>> = Default::default();
}
+7 -2
View File
@@ -4,6 +4,7 @@ use std::num::NonZero;
use rustc_abi::Size;
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use crate::ty::TyCtxt;
@@ -151,8 +152,12 @@ 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<Hcx> crate::ty::HashStable<Hcx> for ScalarInt {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut crate::ty::StableHasher) {
impl HashStable for ScalarInt {
fn hash_stable<Hcx: HashStableContext>(
&self,
hcx: &mut Hcx,
hasher: &mut crate::ty::StableHasher,
) {
// 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,
+2 -2
View File
@@ -591,7 +591,7 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> {
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
/// allowed to feed queries for that `DefId`.
impl<KEY: Copy, Hcx> !HashStable<Hcx> for TyCtxtFeed<'_, KEY> {}
impl<KEY: Copy> !HashStable for TyCtxtFeed<'_, KEY> {}
/// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`.
/// Use this to pass around when you have a `TyCtxt` elsewhere.
@@ -606,7 +606,7 @@ pub struct Feed<'tcx, KEY: Copy> {
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
/// allowed to feed queries for that `DefId`.
impl<KEY: Copy, Hcx> !HashStable<Hcx> for Feed<'_, KEY> {}
impl<KEY: Copy> !HashStable for Feed<'_, KEY> {}
impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+15 -16
View File
@@ -7,19 +7,18 @@ 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,
HashStable, HashStableContext, HashingControls, StableHasher, ToStableHashKey,
};
use tracing::trace;
use crate::ich::StableHashingContext;
use crate::middle::region;
use crate::{mir, ty};
impl<'a, 'tcx, H, T> HashStable<StableHashingContext<'a>> for &'tcx ty::list::RawList<H, T>
impl<'tcx, H, T> HashStable for &'tcx ty::list::RawList<H, T>
where
T: HashStable<StableHashingContext<'a>>,
T: HashStable,
{
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// Note: this cache makes an *enormous* performance difference on certain benchmarks. E.g.
// without it, compiling `diesel-2.2.10` can be 74% slower, and compiling
// `deeply-nested-multi` can be ~4,000x slower(!)
@@ -46,29 +45,29 @@ where
}
}
impl<'a, 'tcx, H, T> ToStableHashKey<StableHashingContext<'a>> for &'tcx ty::list::RawList<H, T>
impl<'tcx, H, T> ToStableHashKey for &'tcx ty::list::RawList<H, T>
where
T: HashStable<StableHashingContext<'a>>,
T: HashStable,
{
type KeyType = Fingerprint;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut StableHashingContext<'a>) -> Fingerprint {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> Fingerprint {
let mut hasher = StableHasher::new();
self.hash_stable(hcx, &mut hasher);
hasher.finish()
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::GenericArg<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
impl<'tcx> HashStable for ty::GenericArg<'tcx> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.kind().hash_stable(hcx, hasher);
}
}
// AllocIds get resolved to whatever they point to (to be stable)
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
impl HashStable for mir::interpret::AllocId {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
ty::tls::with_opt(|tcx| {
trace!("hashing {:?}", *self);
let tcx = tcx.expect("can't hash AllocIds during hir lowering");
@@ -77,17 +76,17 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::CtfeProvenance {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
impl HashStable for mir::interpret::CtfeProvenance {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.into_parts().hash_stable(hcx, hasher);
}
}
impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
impl ToStableHashKey for region::Scope {
type KeyType = region::Scope;
#[inline]
fn to_stable_hash_key(&self, _: &mut StableHashingContext<'a>) -> region::Scope {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> region::Scope {
*self
}
}
+3 -4
View File
@@ -33,7 +33,7 @@ use rustc_ast::node_id::NodeMap;
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::Interned;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer};
@@ -117,7 +117,6 @@ pub use self::typeck_results::{
Rust2024IncompatiblePatInfo, TypeckResults, UserType, UserTypeAnnotationIndex, UserTypeKind,
};
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
use crate::ich::StableHashingContext;
use crate::metadata::{AmbigModChild, ModChild};
use crate::middle::privacy::EffectiveVisibilities;
use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, SourceInfo};
@@ -545,8 +544,8 @@ impl<'tcx> From<Const<'tcx>> for Term<'tcx> {
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Term<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
impl<'tcx> HashStable for Term<'tcx> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.kind().hash_stable(hcx, hasher);
}
}
+3 -5
View File
@@ -14,9 +14,7 @@ use std::{cmp, fs, iter};
use externs::{ExternOpt, split_extern_opt};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::stable_hasher::{
HashStableContext, StableHasher, StableOrd, ToStableHashKey,
};
use rustc_data_structures::stable_hasher::{StableHasher, StableOrd, ToStableHashKey};
use rustc_errors::emitter::HumanReadableErrorType;
use rustc_errors::{ColorConfig, DiagCtxtFlags};
use rustc_feature::UnstableFeatures;
@@ -638,10 +636,10 @@ macro_rules! define_output_types {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for OutputType {
impl ToStableHashKey for OutputType {
type KeyType = Self;
fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
*self
}
}
+14 -14
View File
@@ -427,59 +427,59 @@ rustc_data_structures::define_id_collections!(
LocalDefId
);
impl<Hcx: HashStableContext> HashStable<Hcx> for DefId {
impl HashStable for DefId {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.to_stable_hash_key(hcx).hash_stable(hcx, hasher);
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for LocalDefId {
impl HashStable for LocalDefId {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.to_stable_hash_key(hcx).local_hash().hash_stable(hcx, hasher);
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for CrateNum {
impl HashStable for CrateNum {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.as_def_id().to_stable_hash_key(hcx).stable_crate_id().hash_stable(hcx, hasher);
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for DefId {
impl ToStableHashKey for DefId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
DefPathHash::from_raw_def_path_hash(hcx.def_path_hash(self.to_raw_def_id()))
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for LocalDefId {
impl ToStableHashKey for LocalDefId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.to_def_id().to_stable_hash_key(hcx)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for CrateNum {
impl ToStableHashKey for CrateNum {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> DefPathHash {
self.as_def_id().to_stable_hash_key(hcx)
}
}
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for DefPathHash {
impl ToStableHashKey for DefPathHash {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> DefPathHash {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> DefPathHash {
*self
}
}
+6 -6
View File
@@ -1519,8 +1519,8 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContex
ExpnHash::new(LOCAL_CRATE.as_def_id().to_stable_hash_key(&mut hcx).stable_crate_id(), expn_hash)
}
impl<Hcx: HashStableContext> HashStable<Hcx> for SyntaxContext {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for SyntaxContext {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
const TAG_EXPANSION: u8 = 0;
const TAG_NO_EXPANSION: u8 = 1;
@@ -1535,8 +1535,8 @@ impl<Hcx: HashStableContext> HashStable<Hcx> for SyntaxContext {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for ExpnId {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for ExpnId {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
hcx.assert_default_hashing_controls("ExpnId");
let hash = if *self == ExpnId::root() {
// Avoid fetching TLS storage for a trivial often-used value.
@@ -1549,8 +1549,8 @@ impl<Hcx: HashStableContext> HashStable<Hcx> for ExpnId {
}
}
impl<Hcx: HashStableContext> HashStable<Hcx> for LocalExpnId {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for LocalExpnId {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.to_expn_id().hash_stable(hcx, hasher);
}
}
+2 -5
View File
@@ -2797,11 +2797,8 @@ impl InnerSpan {
}
}
impl<Hcx> HashStable<Hcx> for Span
where
Hcx: HashStableContext,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for Span {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// `span_hash_stable` does all the work.
hcx.span_hash_stable(self.to_raw_span(), hasher)
}
+7 -7
View File
@@ -8,7 +8,7 @@ use std::{fmt, str};
use rustc_arena::DroplessArena;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_data_structures::stable_hasher::{
HashStable, StableCompare, StableHasher, ToStableHashKey,
HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey,
};
use rustc_data_structures::sync::Lock;
use rustc_macros::{Decodable, Encodable, HashStable_Generic, symbols};
@@ -2631,17 +2631,17 @@ impl fmt::Display for Symbol {
}
}
impl<Hcx> HashStable<Hcx> for Symbol {
impl HashStable for Symbol {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.as_str().hash_stable(hcx, hasher);
}
}
impl<Hcx> ToStableHashKey<Hcx> for Symbol {
impl ToStableHashKey for Symbol {
type KeyType = String;
#[inline]
fn to_stable_hash_key(&self, _: &mut Hcx) -> String {
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> String {
self.as_str().to_string()
}
}
@@ -2691,9 +2691,9 @@ impl fmt::Debug for ByteSymbol {
}
}
impl<Hcx> HashStable<Hcx> for ByteSymbol {
impl HashStable for ByteSymbol {
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.as_byte_str().hash_stable(hcx, hasher);
}
}
+3 -3
View File
@@ -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::{HashStable, HashStableContext, StableHasher};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_type_ir_macros::{
@@ -117,8 +117,8 @@ impl fmt::Debug for InferConst {
}
#[cfg(feature = "nightly")]
impl<Hcx> HashStable<Hcx> for InferConst {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for InferConst {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
match self {
InferConst::Var(_) => {
panic!("const variables should not be hashed: {self:?}")
+5 -3
View File
@@ -7,7 +7,9 @@ use rustc_ast_ir::Mutability;
#[cfg(feature = "nightly")]
use rustc_data_structures::fingerprint::Fingerprint;
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_data_structures::stable_hasher::{
HashStable, HashStableContext, StableHasher, ToStableHashKey,
};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
@@ -50,11 +52,11 @@ pub enum SimplifiedType<DefId> {
}
#[cfg(feature = "nightly")]
impl<Hcx, DefId: HashStable<Hcx>> ToStableHashKey<Hcx> for SimplifiedType<DefId> {
impl<DefId: HashStable> ToStableHashKey for SimplifiedType<DefId> {
type KeyType = Fingerprint;
#[inline]
fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Fingerprint {
fn to_stable_hash_key<Hcx: HashStableContext>(&self, hcx: &mut Hcx) -> Fingerprint {
let mut hasher = StableHasher::new();
self.hash_stable(hcx, &mut hasher);
hasher.finish()
+3 -3
View File
@@ -125,7 +125,7 @@ rustc_index::newtype_index! {
/// is the outer fn.
///
/// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index
#[stable_hash_no_context]
#[stable_hash]
#[encodable]
#[orderable]
#[debug_format = "DebruijnIndex({})"]
@@ -335,7 +335,7 @@ rustc_index::newtype_index! {
/// declared, but a type name in a non-zero universe is a placeholder
/// type -- an idealized representative of "types in general" that we
/// use for checking generic functions.
#[stable_hash_no_context]
#[stable_hash]
#[encodable]
#[orderable]
#[debug_format = "U{}"]
@@ -390,7 +390,7 @@ impl Default for UniverseIndex {
}
rustc_index::newtype_index! {
#[stable_hash_generic]
#[stable_hash]
#[encodable]
#[orderable]
#[debug_format = "{}"]
+8 -8
View File
@@ -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::{HashStable, HashStableContext, StableHasher};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use rustc_type_ir_macros::GenericTypeVisitable;
@@ -16,7 +16,7 @@ rustc_index::newtype_index! {
#[orderable]
#[debug_format = "'?{}"]
#[gate_rustc_only]
#[stable_hash_no_context]
#[stable_hash]
pub struct RegionVid {}
}
@@ -217,15 +217,15 @@ impl<I: Interner> fmt::Debug for RegionKind<I> {
#[cfg(feature = "nightly")]
// This is not a derived impl because a derive would require `I: HashStable`
impl<Hcx, I: Interner> HashStable<Hcx> for RegionKind<I>
impl<I: Interner> HashStable for RegionKind<I>
where
I::EarlyParamRegion: HashStable<Hcx>,
I::LateParamRegion: HashStable<Hcx>,
I::DefId: HashStable<Hcx>,
I::Symbol: HashStable<Hcx>,
I::EarlyParamRegion: HashStable,
I::LateParamRegion: HashStable,
I::DefId: HashStable,
I::Symbol: HashStable,
{
#[inline]
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
std::mem::discriminant(self).hash_stable(hcx, hasher);
match self {
ReErased | ReStatic | ReError(_) => {
+3 -3
View File
@@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher};
use std::ops::Deref;
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
use rustc_type_ir_macros::GenericTypeVisitable;
use crate::{DebruijnIndex, TypeFlags};
@@ -83,8 +83,8 @@ impl<T: Hash> Hash for WithCachedTypeInfo<T> {
}
#[cfg(feature = "nightly")]
impl<T: HashStable<Hcx>, Hcx> HashStable<Hcx> for WithCachedTypeInfo<T> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<T: HashStable> HashStable for WithCachedTypeInfo<T> {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.internee.hash_stable(hcx, hasher);
}
}
+3 -3
View File
@@ -5,7 +5,7 @@ use derive_where::derive_where;
use rustc_abi::ExternAbi;
use rustc_ast_ir::Mutability;
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_type_ir::data_structures::{NoError, UnifyKey, UnifyValue};
@@ -706,8 +706,8 @@ impl UnifyKey for FloatVid {
}
#[cfg(feature = "nightly")]
impl<Hcx> HashStable<Hcx> for InferTy {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl HashStable for InferTy {
fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
use InferTy::*;
std::mem::discriminant(self).hash_stable(hcx, hasher);
match self {