Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ use std::fmt;
#[cfg(not(bootstrap))]
pub use std::{assert_matches, debug_assert_matches};

// This allows derive macros to reference this crate
extern crate self as rustc_data_structures;

pub use atomic_ref::AtomicRef;
pub use ena::{snapshot_vec, undo_log, unify};
// Re-export `hashbrown::hash_table`, because it's part of our API
Expand Down
23 changes: 4 additions & 19 deletions compiler/rustc_data_structures/src/sorted_map/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::hash::{Hash, Hasher};

use rustc_index::{Idx, IndexVec};

use crate::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable_NoContext;

/// 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.
Expand All @@ -24,11 +23,13 @@ use crate::stable_hasher::{HashStable, StableHasher};
/// in-place.
///
/// [`SortedMap`]: super::SortedMap
#[derive(Clone, Debug)]
#[derive(Clone, Debug, HashStable_NoContext)]
pub struct SortedIndexMultiMap<I: Idx, K, V> {
/// The elements of the map in insertion order.
items: IndexVec<I, (K, V)>,

// We can ignore this field because it is not observable from the outside.
#[stable_hasher(ignore)]
/// Indices of the items in the set, sorted by the item's key.
idx_sorted_by_item_key: Vec<I>,
}
Expand Down Expand Up @@ -126,22 +127,6 @@ where
}
}

impl<I: Idx, K, V, C> HashStable<C> for SortedIndexMultiMap<I, K, V>
where
K: HashStable<C>,
V: HashStable<C>,
{
fn hash_stable(&self, ctx: &mut C, hasher: &mut StableHasher) {
let SortedIndexMultiMap {
items,
// We can ignore this field because it is not observable from the outside.
idx_sorted_by_item_key: _,
} = self;

items.hash_stable(ctx, hasher)
}
}

impl<I: Idx, K: Ord, V> FromIterator<(K, V)> for SortedIndexMultiMap<I, K, V> {
fn from_iter<J>(iter: J) -> Self
where
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_data_structures/src/svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@

use std::fmt;

use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};

use crate::fingerprint::Fingerprint;
use crate::stable_hasher;

#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable_NoContext, Decodable_NoContext, Hash)]
#[derive(
Copy,
Clone,
PartialEq,
Eq,
Debug,
Encodable_NoContext,
Decodable_NoContext,
Hash,
HashStable_NoContext
)]
pub struct Svh {
hash: Fingerprint,
}
Expand All @@ -39,11 +48,3 @@ impl fmt::Display for Svh {
f.pad(&self.to_hex())
}
}

impl<T> stable_hasher::HashStable<T> for Svh {
#[inline]
fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) {
let Svh { hash } = *self;
hash.hash_stable(ctx, hasher);
}
}
12 changes: 3 additions & 9 deletions compiler/rustc_hir/src/diagnostic_items.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable_Generic;
use rustc_span::Symbol;
use rustc_span::def_id::DefIdMap;

use crate::def_id::DefId;

#[derive(Debug, Default)]
#[derive(Debug, Default, HashStable_Generic)]
pub struct DiagnosticItems {
#[stable_hasher(ignore)]
pub id_to_name: DefIdMap<Symbol>,
pub name_to_id: FxIndexMap<Symbol, DefId>,
}

impl<CTX: crate::HashStableContext> HashStable<CTX> for DiagnosticItems {
#[inline]
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
self.name_to_id.hash_stable(ctx, hasher);
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ decl_derive!(
hash_stable::hash_stable_generic_derive
);
decl_derive!(
[HashStable_NoContext] =>
[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`.
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_hir::def_id::DefId;
use rustc_hir::definitions::DefPathHash;
use rustc_macros::{Decodable, Encodable};
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_span::Symbol;

use super::{KeyFingerprintStyle, SerializedDepNodeIndex};
Expand Down Expand Up @@ -290,7 +290,9 @@ pub struct DepKindVTable<'tcx> {
/// some independent path or string that persists between runs without
/// the need to be mapped or unmapped. (This ensures we can serialize
/// them even in the absence of a tcx.)
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, HashStable
)]
pub struct WorkProductId {
hash: Fingerprint,
}
Expand All @@ -302,13 +304,6 @@ impl WorkProductId {
WorkProductId { hash: hasher.finish() }
}
}

impl<HCX> HashStable<HCX> for WorkProductId {
#[inline]
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
self.hash.hash_stable(hcx, hasher)
}
}
impl<HCX> ToStableHashKey<HCX> for WorkProductId {
type KeyType = Fingerprint;
#[inline]
Expand Down
21 changes: 1 addition & 20 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ pub struct VarBindingForm<'tcx> {
pub introductions: Vec<VarBindingIntroduction>,
}

#[derive(Clone, Debug, TyEncodable, TyDecodable)]
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum BindingForm<'tcx> {
/// This is a binding for a non-`self` binding, or a `self` that has an explicit type.
Var(VarBindingForm<'tcx>),
Expand All @@ -909,25 +909,6 @@ pub struct VarBindingIntroduction {
pub is_shorthand: bool,
}

mod binding_form_impl {
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

use crate::ich::StableHashingContext;

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for super::BindingForm<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
use super::BindingForm::*;
std::mem::discriminant(self).hash_stable(hcx, hasher);

match self {
Var(binding) => binding.hash_stable(hcx, hasher),
ImplicitSelf(kind) => kind.hash_stable(hcx, hasher),
RefForGuard(local) => local.hash_stable(hcx, hasher),
}
}
}
}

/// `BlockTailInfo` is attached to the `LocalDecl` for temporaries
/// created during evaluation of expressions in a block tail
/// expression; that is, a block like `{ STMT_1; STMT_2; EXPR }`.
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2653,7 +2653,7 @@ impl_pos! {
pub struct BytePos(pub u32);

/// A byte offset relative to file beginning.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, HashStable_Generic)]
pub struct RelativeBytePos(pub u32);

/// A character offset.
Expand All @@ -2677,12 +2677,6 @@ impl<D: Decoder> Decodable<D> for BytePos {
}
}

impl<H: HashStableContext> HashStable<H> for RelativeBytePos {
fn hash_stable(&self, hcx: &mut H, hasher: &mut StableHasher) {
self.0.hash_stable(hcx, hasher);
}
}

impl<S: Encoder> Encodable<S> for RelativeBytePos {
fn encode(&self, s: &mut S) {
s.emit_u32(self.0);
Expand Down
20 changes: 2 additions & 18 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Note that these are similar to but not always identical to LLVM's feature names,
//! and Rust adds some features that do not correspond to LLVM features at all.
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable_Generic;
use rustc_span::{Symbol, sym};

use crate::spec::{Abi, Arch, FloatAbi, RustcAbi, Target};
Expand All @@ -12,7 +12,7 @@ use crate::spec::{Abi, Arch, FloatAbi, RustcAbi, Target};
pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];

/// Stability information for target features.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, HashStable_Generic)]
pub enum Stability {
/// This target feature is stable, it can be used in `#[target_feature]` and
/// `#[cfg(target_feature)]`.
Expand All @@ -32,22 +32,6 @@ pub enum Stability {
}
use Stability::*;

impl<CTX> HashStable<CTX> for Stability {
#[inline]
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
std::mem::discriminant(self).hash_stable(hcx, hasher);
match self {
Stability::Stable => {}
Stability::Unstable(nightly_feature) => {
nightly_feature.hash_stable(hcx, hasher);
}
Stability::Forbidden { reason } => {
reason.hash_stable(hcx, hasher);
}
}
}
}

impl Stability {
/// Returns whether the feature can be used in `cfg(target_feature)` ever.
/// (It might still be nightly-only even if this returns `true`, so make sure to also check
Expand Down
Loading