Skip to content

Commit

Permalink
Switch over all StableHash impls to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Sep 28, 2019
1 parent f60e58e commit 14a5aef
Show file tree
Hide file tree
Showing 36 changed files with 184 additions and 461 deletions.
6 changes: 2 additions & 4 deletions src/librustc/hir/map/collector.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use syntax_pos::Span;
use std::iter::repeat; use std::iter::repeat;


use crate::ich::StableHashingContext; 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. /// A visitor that walks over the HIR and collects `Node`s into a HIR map.
pub(super) struct NodeCollector<'a, 'hir> { pub(super) struct NodeCollector<'a, 'hir> {
Expand Down Expand Up @@ -602,9 +602,7 @@ impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
where where
T: HashStable<StableHashingContext<'hir>>, T: HashStable<StableHashingContext<'hir>>,
{ {
fn hash_stable<W: StableHasherResult>(&self, fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
hcx: &mut StableHashingContext<'hir>,
hasher: &mut StableHasher<W>) {
hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| { hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
self.item_like.hash_stable(hcx, hasher); self.item_like.hash_stable(hcx, hasher);
}); });
Expand Down
7 changes: 2 additions & 5 deletions src/librustc/hir/ptr.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::{slice, vec};


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


use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
HashStable};
/// An owned smart pointer. /// An owned smart pointer.
#[derive(Hash, PartialEq, Eq)] #[derive(Hash, PartialEq, Eq)]
pub struct P<T: ?Sized> { pub struct P<T: ?Sized> {
Expand Down Expand Up @@ -133,9 +132,7 @@ impl<T: Decodable> Decodable for P<[T]> {
impl<CTX, T> HashStable<CTX> for P<T> impl<CTX, T> HashStable<CTX> for P<T>
where T: ?Sized + HashStable<CTX> where T: ?Sized + HashStable<CTX>
{ {
fn hash_stable<W: StableHasherResult>(&self, fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
hcx: &mut CTX,
hasher: &mut StableHasher<W>) {
(**self).hash_stable(hcx, hasher); (**self).hash_stable(hcx, hasher);
} }
} }
32 changes: 9 additions & 23 deletions src/librustc/ich/hcx.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::hygiene; use syntax_pos::hygiene;


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


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


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


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


impl<'a> HashStable<StableHashingContext<'a>> for DelimSpan { impl<'a> HashStable<StableHashingContext<'a>> for DelimSpan {
fn hash_stable<W: StableHasherResult>( fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>,
) {
self.open.hash_stable(hcx, hasher); self.open.hash_stable(hcx, hasher);
self.close.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>, hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>, hasher: &mut StableHasher,
blanket_impls: &[DefId], blanket_impls: &[DefId],
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>, non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
) where ) {
W: StableHasherResult,
{
{ {
let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls
.iter() .iter()
Expand Down
80 changes: 20 additions & 60 deletions src/librustc/ich/impls_hir.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ use crate::hir::map::DefPathHash;
use crate::hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX}; use crate::hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX};
use crate::ich::{StableHashingContext, NodeIdHashingMode, Fingerprint}; use crate::ich::{StableHashingContext, NodeIdHashingMode, Fingerprint};


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


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


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


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


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


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


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


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


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


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




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


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


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




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


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


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


fn hash_stable<W: StableHasherResult>(&self, fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
hcx.local_def_path_hash(*self).hash_stable(hcx, hasher); hcx.local_def_path_hash(*self).hash_stable(hcx, hasher);
} }
} }
Expand All @@ -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 { impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
fn hash_stable<W: StableHasherResult>(&self, fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
_: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
::std::hash::Hash::hash(self, hasher); ::std::hash::Hash::hash(self, hasher);
} }
} }


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


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


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

0 comments on commit 14a5aef

Please sign in to comment.