/// Construct a DepNode from the given DepKind and DefPathHash. This
/// method will assert that the given DepKind actually requires a
/// single DefId/DefPathHash parameter.
- pub fn from_def_path_hash(kind: DepKind,
- def_path_hash: DefPathHash)
+ pub fn from_def_path_hash(def_path_hash: DefPathHash,
+ kind: DepKind)
-> DepNode {
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
DepNode {
}
if kind.has_params() {
- Ok(def_path_hash.to_dep_node(kind))
+ Ok(DepNode::from_def_path_hash(def_path_hash, kind))
} else {
Ok(DepNode::new_no_params(kind))
}
}
}
-impl DefPathHash {
- pub fn to_dep_node(self, kind: DepKind) -> DepNode {
- DepNode::from_def_path_hash(kind, self)
- }
-}
-
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// We use this for most things when incr. comp. is turned off.
[] Null,
) -> (DepNodeIndex, DepNodeIndex) {
let sig = dep_graph
.input_task(
- def_path_hash.to_dep_node(DepKind::Hir),
+ DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
&mut *hcx,
HirItemLike { item_like: &item_like, hash_bodies: false },
)
let (full, hash) = input_dep_node_and_hash(
dep_graph,
hcx,
- def_path_hash.to_dep_node(DepKind::HirBody),
+ DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody),
HirItemLike { item_like: &item_like, hash_bodies: true },
);
hir_body_nodes.push((def_path_hash, hash));
use rustc_ast::ast;
use rustc_ast::node_id::NodeMap;
-use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_hir as hir;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
-use std::borrow::Borrow;
use std::fmt::Write;
use std::hash::Hash;
+pub use rustc_hir::def_id::DefPathHash;
+
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
/// stores the `DefIndex` of its parent.
ImplTrait,
}
-#[derive(
- Copy,
- Clone,
- Hash,
- PartialEq,
- Eq,
- PartialOrd,
- Ord,
- Debug,
- RustcEncodable,
- RustcDecodable,
- HashStable
-)]
-pub struct DefPathHash(pub Fingerprint);
-
-impl Borrow<Fingerprint> for DefPathHash {
- #[inline]
- fn borrow(&self) -> &Fingerprint {
- &self.0
- }
-}
-
impl Definitions {
pub fn def_path_table(&self) -> &DefPathTable {
&self.table
where
V: ItemLikeVisitor<'hir>,
{
- let hir_id = self.as_local_hir_id(module).unwrap();
-
- // Read the module so we'll be re-executed if new items
- // appear immediately under in the module. If some new item appears
- // in some nested item in the module, we'll be re-executed due to reads
- // in the expect_* calls the loops below
- self.read(hir_id);
-
- let module = &self.krate.modules[&hir_id];
+ let module = self.tcx.hir_module_items(module);
for id in &module.items {
visitor.visit_item(self.expect_item(*id));
if self.dep_graph.is_fully_enabled() {
let hir_id_owner = hir_id.owner;
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
- self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody));
+ self.dep_graph.read(DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody));
}
self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)
hir_to_node_id: early.hir_to_node_id,
})
};
+ providers.hir_module_items = |tcx, id| {
+ assert_eq!(id.krate, LOCAL_CRATE);
+ let hir = tcx.hir();
+ let module = hir.as_local_hir_id(id).unwrap();
+ &hir.untracked_krate().modules[&module]
+ };
providers.hir_owner = |tcx, id| {
assert_eq!(id.krate, LOCAL_CRATE);
*tcx.hir().map.owner_map.get(&id.index).unwrap()
use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
+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};
impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}
-impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::HirId {
- type KeyType = (DefPathHash, hir::ItemLocalId);
-
- #[inline]
- fn to_stable_hash_key(
- &self,
- hcx: &StableHashingContext<'a>,
- ) -> (DefPathHash, hir::ItemLocalId) {
- let def_path_hash = hcx.local_def_path_hash(self.owner);
- (def_path_hash, self.local_id)
- }
-}
-
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
panic!("Node IDs should not appear in incremental state");
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, LocalDefId, CRATE_DEF_INDEX};
+use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
use smallvec::SmallVec;
use std::mem;
self.node_id_hashing_mode = prev_hash_node_ids;
}
+
+ #[inline]
+ fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
+ self.local_def_path_hash(def_index)
+ }
}
impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {
desc { "index HIR" }
}
+ query hir_module_items(key: DefId) -> &'tcx hir::ModuleItems {
+ eval_always
+ }
+
query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> {
eval_always
}
pub rhs_ty: &'hir Ty<'hir>,
}
-#[derive(RustcEncodable, RustcDecodable, Debug)]
+#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct ModuleItems {
// Use BTreeSets here so items are in the same order as in the
// list of all items in Crate
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use crate::hir::{
BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
VisibilityKind,
};
-use crate::hir_id::HirId;
+use crate::hir_id::{HirId, ItemLocalId};
+use rustc_span::def_id::{DefIndex, DefPathHash};
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
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;
+}
+
+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);
+ (def_path_hash, self.local_id)
+ }
+}
+
+impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
+ type KeyType = (DefPathHash, ItemLocalId);
+
+ #[inline]
+ fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
+ self.hir_id.to_stable_hash_key(hcx)
+ }
+}
+
+impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
+ type KeyType = (DefPathHash, ItemLocalId);
+
+ #[inline]
+ fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
+ self.hir_id.to_stable_hash_key(hcx)
+ }
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
if attr.check_name(sym::rustc_if_this_changed) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
- None => def_path_hash.to_dep_node(DepKind::Hir),
+ None => DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
Some(n) => match DepNode::from_label_string(&n.as_str(), def_path_hash) {
Ok(n) => n,
Err(()) => {
use crate::rmeta::table::{FixedSizeEncoding, Table};
use crate::rmeta::*;
-use rustc::dep_graph::{self, DepNodeIndex};
+use rustc::dep_graph::{self, DepNode, DepNodeIndex};
use rustc::hir::exports::Export;
use rustc::hir::map::definitions::DefPathTable;
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
// would always write the same value.
let def_path_hash = self.def_path_hash(CRATE_DEF_INDEX);
- let dep_node = def_path_hash.to_dep_node(dep_graph::DepKind::CrateMetadata);
+ let dep_node =
+ DepNode::from_def_path_hash(def_path_hash, dep_graph::DepKind::CrateMetadata);
dep_node_index = tcx.dep_graph.dep_node_index_of(&dep_node);
assert!(dep_node_index != DepNodeIndex::INVALID);
use crate::HashStableContext;
+use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::AtomicRef;
use rustc_index::vec::Idx;
+use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decoder, Encoder};
+use std::borrow::Borrow;
use std::fmt;
use std::{u32, u64};
}
}
+#[derive(
+ Copy,
+ Clone,
+ Hash,
+ PartialEq,
+ Eq,
+ PartialOrd,
+ Ord,
+ Debug,
+ RustcEncodable,
+ RustcDecodable,
+ HashStable_Generic
+)]
+pub struct DefPathHash(pub Fingerprint);
+
+impl Borrow<Fingerprint> for DefPathHash {
+ #[inline]
+ fn borrow(&self) -> &Fingerprint {
+ &self.0
+ }
+}
+
rustc_index::newtype_index! {
/// A DefIndex is an index into the hir-map for a crate, identifying a
/// particular definition. It should really be considered an interned