Skip to content

Commit

Permalink
rustc: use LocalDefId instead of DefIndex in ich.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 19, 2020
1 parent f3ec069 commit 2b0a21e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIndex};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_session::Session;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -124,15 +124,15 @@ impl<'a> StableHashingContext<'a> {
#[inline]
pub fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
if let Some(def_id) = def_id.as_local() {
self.definitions.def_path_hash(def_id.local_def_index)
self.local_def_path_hash(def_id)
} else {
self.cstore.def_path_hash(def_id)
}
}

#[inline]
pub fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
self.definitions.def_path_hash(def_index)
pub fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
self.definitions.def_path_hash(def_id.local_def_index)
}

#[inline]
Expand Down
25 changes: 5 additions & 20 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
use rustc_attr as attr;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
use smallvec::SmallVec;
use std::mem;

Expand All @@ -21,7 +21,7 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
NodeIdHashingMode::HashDefPath => {
let hir::HirId { owner, local_id } = hir_id;

hcx.local_def_path_hash(owner.local_def_index).hash_stable(hcx, hasher);
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher);
local_id.hash_stable(hcx, hasher);
}
}
Expand Down Expand Up @@ -116,8 +116,8 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
}

#[inline]
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
self.local_def_path_hash(def_index)
fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
self.local_def_path_hash(def_id)
}
}

Expand Down Expand Up @@ -197,21 +197,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
}
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::def_id::DefIndex {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.local_def_path_hash(*self).hash_stable(hcx, hasher);
}
}

impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
type KeyType = DefPathHash;

#[inline]
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
hcx.local_def_path_hash(*self)
}
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
Expand All @@ -231,7 +216,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {

let import_keys = import_ids
.iter()
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner.local_def_index), hir_id.local_id))
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner), hir_id.local_id))
.collect();
(hcx.def_path_hash(*def_id), import_keys)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_hir/stable_hash_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::hir::{
VisibilityKind,
};
use crate::hir_id::{HirId, ItemLocalId};
use rustc_span::def_id::{DefIndex, DefPathHash};
use rustc_span::def_id::{DefPathHash, LocalDefId};

/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
Expand All @@ -21,15 +21,15 @@ pub trait HashStableContext:
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash;
fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash;
}

impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
type KeyType = (DefPathHash, ItemLocalId);

#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
let def_path_hash = hcx.local_def_path_hash(self.owner.local_def_index);
let def_path_hash = hcx.local_def_path_hash(self.owner);
(def_path_hash, self.local_id)
}
}
Expand Down

0 comments on commit 2b0a21e

Please sign in to comment.