Skip to content
Permalink
Browse files

Switch over all StableHash impls to new format

  • Loading branch information...
Mark-Simulacrum committed Sep 26, 2019
1 parent f60e58e commit 14a5aefb01bb4f18749ab56cd9fd37bf93c86a37
Showing with 184 additions and 461 deletions.
  1. +2 −4 src/librustc/hir/map/collector.rs
  2. +2 −5 src/librustc/hir/ptr.rs
  3. +9 −23 src/librustc/ich/hcx.rs
  4. +20 −60 src/librustc/ich/impls_hir.rs
  5. +12 −37 src/librustc/ich/impls_syntax.rs
  6. +15 −52 src/librustc/ich/impls_ty.rs
  7. +3 −8 src/librustc/lint/levels.rs
  8. +12 −12 src/librustc/macros.rs
  9. +2 −5 src/librustc/middle/exported_symbols.rs
  10. +2 −4 src/librustc/middle/region.rs
  11. +2 −4 src/librustc/mir/cache.rs
  12. +2 −6 src/librustc/mir/mod.rs
  13. +3 −8 src/librustc/mir/mono.rs
  14. +2 −5 src/librustc/traits/query/outlives_bounds.rs
  15. +2 −5 src/librustc/traits/specialize/specialization_graph.rs
  16. +2 −4 src/librustc/ty/context.rs
  17. +2 −5 src/librustc/ty/fast_reject.rs
  18. +10 −35 src/librustc/ty/layout.rs
  19. +5 −16 src/librustc/ty/mod.rs
  20. +2 −2 src/librustc/ty/query/job.rs
  21. +1 −4 src/librustc/ty/query/plumbing.rs
  22. +2 −5 src/librustc/ty/trait_def.rs
  23. +2 −2 src/librustc_codegen_llvm/debuginfo/metadata.rs
  24. +2 −5 src/librustc_codegen_ssa/common.rs
  25. +2 −2 src/librustc_codegen_utils/symbol_names/legacy.rs
  26. +1 −1 src/librustc_data_structures/fingerprint.rs
  27. +38 −102 src/librustc_data_structures/stable_hasher.rs
  28. +1 −5 src/librustc_data_structures/svh.rs
  29. +2 −4 src/librustc_data_structures/thin_vec.rs
  30. +4 −10 src/librustc_data_structures/transitive_relation.rs
  31. +2 −2 src/librustc_interface/util.rs
  32. +2 −2 src/librustc_macros/src/hash_stable.rs
  33. +2 −2 src/librustc_metadata/encoder.rs
  34. +4 −4 src/librustc_mir/interpret/snapshot.rs
  35. +2 −5 src/libsyntax/ptr.rs
  36. +6 −6 src/libsyntax_pos/lib.rs
@@ -17,7 +17,7 @@ use syntax_pos::Span;
use std::iter::repeat;

use crate::ich::StableHashingContext;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
pub(super) struct NodeCollector<'a, 'hir> {
@@ -602,9 +602,7 @@ impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
where
T: HashStable<StableHashingContext<'hir>>,
{
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'hir>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
self.item_like.hash_stable(hcx, hasher);
});
@@ -9,8 +9,7 @@ use std::{slice, vec};

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

use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
HashStable};
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
/// An owned smart pointer.
#[derive(Hash, PartialEq, Eq)]
pub struct P<T: ?Sized> {
@@ -133,9 +132,7 @@ impl<T: Decodable> Decodable for P<[T]> {
impl<CTX, T> HashStable<CTX> for P<T>
where T: ?Sized + HashStable<CTX>
{
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut CTX,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
(**self).hash_stable(hcx, hasher);
}
}
@@ -20,7 +20,7 @@ use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::hygiene;

use rustc_data_structures::stable_hasher::{
HashStable, StableHasher, StableHasherResult, ToStableHashKey,
HashStable, StableHasher, ToStableHashKey,
};
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use smallvec::SmallVec;
@@ -219,9 +219,7 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}

impl<'a> HashStable<StableHashingContext<'a>> for hir::BodyId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
if hcx.hash_bodies() {
hcx.body_resolver.body(*self).hash_stable(hcx, hasher);
}
@@ -230,9 +228,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::BodyId {

impl<'a> HashStable<StableHashingContext<'a>> for hir::HirId {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
match hcx.node_id_hashing_mode {
NodeIdHashingMode::Ignore => {
// Don't do anything.
@@ -263,9 +259,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::HirId {
}

impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
match hcx.node_id_hashing_mode {
NodeIdHashingMode::Ignore => {
// Don't do anything.
@@ -298,9 +292,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
/// codepoint offsets. For the purpose of the hash that's sufficient.
/// Also, hashing filenames is expensive so we avoid doing it twice when the
/// span starts and ends in the same file, which is almost always the case.
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
const TAG_VALID_SPAN: u8 = 0;
const TAG_INVALID_SPAN: u8 = 1;
const TAG_EXPANSION: u8 = 0;
@@ -379,24 +371,18 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
}

impl<'a> HashStable<StableHashingContext<'a>> for DelimSpan {
fn hash_stable<W: StableHasherResult>(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>,
) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.open.hash_stable(hcx, hasher);
self.close.hash_stable(hcx, hasher);
}
}

pub fn hash_stable_trait_impls<'a, W>(
pub fn hash_stable_trait_impls<'a>(
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>,
hasher: &mut StableHasher,
blanket_impls: &[DefId],
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
) where
W: StableHasherResult,
{
) {
{
let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls
.iter()
@@ -6,19 +6,15 @@ use crate::hir::map::DefPathHash;
use crate::hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX};
use crate::ich::{StableHashingContext, NodeIdHashingMode, Fingerprint};

use rustc_data_structures::stable_hasher::{
HashStable, ToStableHashKey, StableHasher, StableHasherResult,
};
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
use smallvec::SmallVec;
use std::mem;
use syntax::ast;
use syntax::attr;

impl<'a> HashStable<StableHashingContext<'a>> for DefId {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.def_path_hash(*self).hash_stable(hcx, hasher);
}
}
@@ -34,9 +30,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {

impl<'a> HashStable<StableHashingContext<'a>> for LocalDefId {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher);
}
}
@@ -52,9 +46,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalDefId {

impl<'a> HashStable<StableHashingContext<'a>> for CrateNum {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.def_path_hash(DefId {
krate: *self,
index: CRATE_DEF_INDEX
@@ -92,9 +84,7 @@ for hir::ItemLocalId {
// in "DefPath Mode".

impl<'a> HashStable<StableHashingContext<'a>> for hir::ItemId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::ItemId {
id
} = *self;
@@ -106,9 +96,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ItemId {
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItemId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::TraitItemId {
hir_id
} = * self;
@@ -120,9 +108,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItemId {
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItemId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::ImplItemId {
hir_id
} = * self;
@@ -138,9 +124,7 @@ impl_stable_hash_for!(struct ast::Label {
});

impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.while_hashing_hir_bodies(true, |hcx| {
let hir::Ty {
hir_id: _,
@@ -166,9 +150,7 @@ impl_stable_hash_for!(struct hir::Stmt {
impl_stable_hash_for_spanned!(ast::Name);

impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.while_hashing_hir_bodies(true, |hcx| {
let hir::Expr {
hir_id: _,
@@ -192,9 +174,7 @@ impl_stable_hash_for!(struct ast::Ident {
});

impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::TraitItem {
hir_id: _,
ident,
@@ -216,9 +196,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {


impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::ImplItem {
hir_id: _,
ident,
@@ -248,9 +226,7 @@ impl_stable_hash_for!(enum ast::CrateSugar {
});

impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
hir::VisibilityKind::Public |
@@ -273,9 +249,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
impl_stable_hash_for_spanned!(hir::VisibilityKind);

impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Mod {
inner: ref inner_span,
ref item_ids,
@@ -305,9 +279,7 @@ impl_stable_hash_for_spanned!(hir::Variant);


impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Item {
ident,
ref attrs,
@@ -328,9 +300,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::Body {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Body {
params,
value,
@@ -359,9 +329,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {

impl<'a> HashStable<StableHashingContext<'a>> for hir::def_id::DefIndex {

fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.local_def_path_hash(*self).hash_stable(hcx, hasher);
}
}
@@ -376,17 +344,13 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
}

impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
fn hash_stable<W: StableHasherResult>(&self,
_: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
let hir::TraitCandidate {
def_id,
@@ -418,17 +382,13 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
}

impl<'hir> HashStable<StableHashingContext<'hir>> for attr::InlineAttr {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'hir>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
}
}

impl<'hir> HashStable<StableHashingContext<'hir>> for attr::OptimizeAttr {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'hir>,
hasher: &mut StableHasher<W>) {
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
}
}

0 comments on commit 14a5aef

Please sign in to comment.
You can’t perform that action at this time.