Skip to content

Commit 59ebe8e

Browse files
Make a newtype for DefPathHash so they are not confused with content hashes
1 parent f89d8d1 commit 59ebe8e

File tree

10 files changed

+36
-30
lines changed

10 files changed

+36
-30
lines changed

src/librustc/hir/map/definitions.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use util::nodemap::NodeMap;
3636
pub struct DefPathTable {
3737
index_to_key: [Vec<DefKey>; 2],
3838
key_to_index: FxHashMap<DefKey, DefIndex>,
39-
def_path_hashes: [Vec<Fingerprint>; 2],
39+
def_path_hashes: [Vec<DefPathHash>; 2],
4040
}
4141

4242
// Unfortunately we have to provide a manual impl of Clone because of the
@@ -57,7 +57,7 @@ impl DefPathTable {
5757

5858
fn allocate(&mut self,
5959
key: DefKey,
60-
def_path_hash: Fingerprint,
60+
def_path_hash: DefPathHash,
6161
address_space: DefIndexAddressSpace)
6262
-> DefIndex {
6363
let index = {
@@ -81,7 +81,7 @@ impl DefPathTable {
8181
}
8282

8383
#[inline(always)]
84-
pub fn def_path_hash(&self, index: DefIndex) -> Fingerprint {
84+
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
8585
self.def_path_hashes[index.address_space().index()]
8686
[index.as_array_index()]
8787
}
@@ -148,8 +148,8 @@ impl Decodable for DefPathTable {
148148
let index_to_key_lo: Vec<DefKey> = Decodable::decode(d)?;
149149
let index_to_key_hi: Vec<DefKey> = Decodable::decode(d)?;
150150

151-
let def_path_hashes_lo: Vec<Fingerprint> = Decodable::decode(d)?;
152-
let def_path_hashes_hi: Vec<Fingerprint> = Decodable::decode(d)?;
151+
let def_path_hashes_lo: Vec<DefPathHash> = Decodable::decode(d)?;
152+
let def_path_hashes_hi: Vec<DefPathHash> = Decodable::decode(d)?;
153153

154154
let index_to_key = [index_to_key_lo, index_to_key_hi];
155155
let def_path_hashes = [def_path_hashes_lo, def_path_hashes_hi];
@@ -216,25 +216,25 @@ pub struct DefKey {
216216
}
217217

218218
impl DefKey {
219-
fn compute_stable_hash(&self, parent_hash: Fingerprint) -> Fingerprint {
219+
fn compute_stable_hash(&self, parent_hash: DefPathHash) -> DefPathHash {
220220
let mut hasher = StableHasher::new();
221221

222222
// We hash a 0u8 here to disambiguate between regular DefPath hashes,
223223
// and the special "root_parent" below.
224224
0u8.hash(&mut hasher);
225225
parent_hash.hash(&mut hasher);
226226
self.disambiguated_data.hash(&mut hasher);
227-
hasher.finish()
227+
DefPathHash(hasher.finish())
228228
}
229229

230-
fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> Fingerprint {
230+
fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> DefPathHash {
231231
let mut hasher = StableHasher::new();
232232
// Disambiguate this from a regular DefPath hash,
233233
// see compute_stable_hash() above.
234234
1u8.hash(&mut hasher);
235235
crate_name.hash(&mut hasher);
236236
crate_disambiguator.hash(&mut hasher);
237-
hasher.finish()
237+
DefPathHash(hasher.finish())
238238
}
239239
}
240240

@@ -372,6 +372,12 @@ pub enum DefPathData {
372372
Typeof,
373373
}
374374

375+
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
376+
RustcEncodable, RustcDecodable)]
377+
pub struct DefPathHash(pub Fingerprint);
378+
379+
impl_stable_hash_for!(tuple_struct DefPathHash { fingerprint });
380+
375381
impl Definitions {
376382
/// Create new empty definition map.
377383
pub fn new() -> Definitions {
@@ -404,7 +410,7 @@ impl Definitions {
404410
}
405411

406412
#[inline(always)]
407-
pub fn def_path_hash(&self, index: DefIndex) -> Fingerprint {
413+
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
408414
self.table.def_path_hash(index)
409415
}
410416

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use self::MapEntry::*;
1313
use self::collector::NodeCollector;
1414
pub use self::def_collector::{DefCollector, MacroInvocationData};
1515
pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData,
16-
DisambiguatedDefPathData};
16+
DisambiguatedDefPathData, DefPathHash};
1717

1818
use dep_graph::{DepGraph, DepNode};
1919

src/librustc/ich/hcx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use hir;
1212
use hir::def_id::DefId;
13+
use hir::map::DefPathHash;
1314
use ich::{self, CachingCodemapView};
1415
use session::config::DebugInfoLevel::NoDebugInfo;
1516
use ty;
@@ -115,7 +116,7 @@ impl<'a, 'tcx: 'a> StableHashingContext<'a, 'tcx> {
115116
}
116117

117118
#[inline]
118-
pub fn def_path_hash(&mut self, def_id: DefId) -> ich::Fingerprint {
119+
pub fn def_path_hash(&mut self, def_id: DefId) -> DefPathHash {
119120
self.tcx.def_path_hash(def_id)
120121
}
121122

src/librustc/middle/cstore.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub trait CrateStore {
281281
-> Option<DefId>;
282282
fn def_key(&self, def: DefId) -> DefKey;
283283
fn def_path(&self, def: DefId) -> hir_map::DefPath;
284-
fn def_path_hash(&self, def: DefId) -> ich::Fingerprint;
284+
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
285285
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
286286
fn item_children(&self, did: DefId) -> Vec<def::Export>;
287287
fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;
@@ -412,8 +412,8 @@ impl CrateStore for DummyCrateStore {
412412
fn def_path(&self, def: DefId) -> hir_map::DefPath {
413413
bug!("relative_def_path")
414414
}
415-
fn def_path_hash(&self, def: DefId) -> ich::Fingerprint {
416-
bug!("wa")
415+
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash {
416+
bug!("def_path_hash")
417417
}
418418
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
419419
fn item_children(&self, did: DefId) -> Vec<def::Export> { bug!("item_children") }

src/librustc/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use dep_graph::DepNode;
1919
use hir::{map as hir_map, FreevarMap, TraitMap};
2020
use hir::def::{Def, CtorKind, ExportMap};
2121
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
22-
use ich::{self, StableHashingContext};
22+
use ich::StableHashingContext;
2323
use middle::const_val::ConstVal;
2424
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
2525
use middle::privacy::AccessLevels;
@@ -2244,7 +2244,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22442244
}
22452245

22462246
#[inline]
2247-
pub fn def_path_hash(self, def_id: DefId) -> ich::Fingerprint {
2247+
pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash {
22482248
if def_id.is_local() {
22492249
self.hir.definitions().def_path_hash(def_id.index)
22502250
} else {

src/librustc/ty/sty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! This module contains TypeVariants and its major components
1212
1313
use hir::def_id::DefId;
14+
use hir::map::DefPathHash;
1415

1516
use middle::region;
1617
use ty::subst::Substs;
@@ -29,7 +30,6 @@ use util::nodemap::FxHashMap;
2930
use serialize;
3031

3132
use hir;
32-
use ich;
3333

3434
use self::InferTy::*;
3535
use self::TypeVariants::*;
@@ -850,7 +850,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> {
850850
self.item_name // safe to skip the binder to access a name
851851
}
852852

853-
pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (ich::Fingerprint, InternedString) {
853+
pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (DefPathHash, InternedString) {
854854
// We want something here that is stable across crate boundaries.
855855
// The DefId isn't but the `deterministic_hash` of the corresponding
856856
// DefPath is.
@@ -885,7 +885,7 @@ impl<'a, 'tcx, 'gcx> PolyExistentialProjection<'tcx> {
885885
self.skip_binder().item_name()
886886
}
887887

888-
pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (ich::Fingerprint, InternedString) {
888+
pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (DefPathHash, InternedString) {
889889
self.skip_binder().sort_key(tcx)
890890
}
891891

src/librustc/ty/trait_def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use ich::Fingerprint;
12+
use hir::map::DefPathHash;
1313
use traits::specialization_graph;
1414
use ty::fast_reject;
1515
use ty::fold::TypeFoldable;
@@ -33,7 +33,7 @@ pub struct TraitDef {
3333

3434
/// The ICH of this trait's DefPath, cached here so it doesn't have to be
3535
/// recomputed all the time.
36-
pub def_path_hash: Fingerprint,
36+
pub def_path_hash: DefPathHash,
3737
}
3838

3939
// We don't store the list of impls in a flat list because each cached list of
@@ -95,7 +95,7 @@ impl<'a, 'gcx, 'tcx> TraitDef {
9595
unsafety: hir::Unsafety,
9696
paren_sugar: bool,
9797
has_default_impl: bool,
98-
def_path_hash: Fingerprint)
98+
def_path_hash: DefPathHash)
9999
-> TraitDef {
100100
TraitDef {
101101
def_id,

src/librustc_incremental/calculate_svh/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use std::hash::Hash;
3232
use rustc::dep_graph::DepNode;
3333
use rustc::hir;
3434
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
35+
use rustc::hir::map::DefPathHash;
3536
use rustc::hir::itemlikevisit::ItemLikeVisitor;
3637
use rustc::ich::{Fingerprint, StableHashingContext};
3738
use rustc::ty::TyCtxt;
@@ -218,7 +219,7 @@ impl<'a, 'tcx: 'a> ComputeItemHashesVisitor<'a, 'tcx> {
218219
{
219220
let tcx = self.hcx.tcx();
220221

221-
let mut impls: Vec<(Fingerprint, Fingerprint)> = krate
222+
let mut impls: Vec<(DefPathHash, Fingerprint)> = krate
222223
.trait_impls
223224
.iter()
224225
.map(|(&trait_id, impls)| {

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
1717
ExternCrate, NativeLibrary, MetadataLoader, LinkMeta,
1818
LinkagePreference, LoadedMacro, EncodedMetadata};
1919
use rustc::hir::def;
20-
use rustc::ich;
2120
use rustc::middle::lang_items;
2221
use rustc::session::Session;
2322
use rustc::ty::{self, TyCtxt};
2423
use rustc::ty::maps::Providers;
2524
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
2625

2726
use rustc::dep_graph::{DepNode, GlobalMetaDataKind};
28-
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData};
27+
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData, DefPathHash};
2928
use rustc::util::nodemap::{NodeSet, DefIdMap};
3029
use rustc_back::PanicStrategy;
3130

@@ -334,7 +333,7 @@ impl CrateStore for cstore::CStore {
334333
self.get_crate_data(def.krate).def_path(def.index)
335334
}
336335

337-
fn def_path_hash(&self, def: DefId) -> ich::Fingerprint {
336+
fn def_path_hash(&self, def: DefId) -> DefPathHash {
338337
self.get_crate_data(def.krate).def_path_hash(def.index)
339338
}
340339

src/librustc_metadata/decoder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
1414
use schema::*;
1515

1616
use rustc::dep_graph::{DepGraph, DepNode, GlobalMetaDataKind};
17-
use rustc::hir::map::{DefKey, DefPath, DefPathData};
17+
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
1818
use rustc::hir;
19-
use rustc::ich;
2019

2120
use rustc::middle::cstore::LinkagePreference;
2221
use rustc::hir::def::{self, Def, CtorKind};
@@ -1109,7 +1108,7 @@ impl<'a, 'tcx> CrateMetadata {
11091108
}
11101109

11111110
#[inline]
1112-
pub fn def_path_hash(&self, index: DefIndex) -> ich::Fingerprint {
1111+
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
11131112
self.def_path_table.def_path_hash(index)
11141113
}
11151114

0 commit comments

Comments
 (0)