Update visit_item_likes_in_module
This commit is contained in:
parent
38e613c4eb
commit
b40e6baec7
@ -223,8 +223,8 @@ macro_rules! define_dep_nodes {
|
|||||||
/// Construct a DepNode from the given DepKind and DefPathHash. This
|
/// Construct a DepNode from the given DepKind and DefPathHash. This
|
||||||
/// method will assert that the given DepKind actually requires a
|
/// method will assert that the given DepKind actually requires a
|
||||||
/// single DefId/DefPathHash parameter.
|
/// single DefId/DefPathHash parameter.
|
||||||
pub fn from_def_path_hash(kind: DepKind,
|
pub fn from_def_path_hash(def_path_hash: DefPathHash,
|
||||||
def_path_hash: DefPathHash)
|
kind: DepKind)
|
||||||
-> DepNode {
|
-> DepNode {
|
||||||
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
|
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
|
||||||
DepNode {
|
DepNode {
|
||||||
@ -280,7 +280,7 @@ macro_rules! define_dep_nodes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if kind.has_params() {
|
if kind.has_params() {
|
||||||
Ok(def_path_hash.to_dep_node(kind))
|
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
|
||||||
} else {
|
} else {
|
||||||
Ok(DepNode::new_no_params(kind))
|
Ok(DepNode::new_no_params(kind))
|
||||||
}
|
}
|
||||||
@ -337,12 +337,6 @@ impl fmt::Debug for DepNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
|
||||||
// We use this for most things when incr. comp. is turned off.
|
// We use this for most things when incr. comp. is turned off.
|
||||||
[] Null,
|
[] Null,
|
||||||
|
@ -86,7 +86,7 @@ fn alloc_hir_dep_nodes(
|
|||||||
) -> (DepNodeIndex, DepNodeIndex) {
|
) -> (DepNodeIndex, DepNodeIndex) {
|
||||||
let sig = dep_graph
|
let sig = dep_graph
|
||||||
.input_task(
|
.input_task(
|
||||||
def_path_hash.to_dep_node(DepKind::Hir),
|
DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
|
||||||
&mut *hcx,
|
&mut *hcx,
|
||||||
HirItemLike { item_like: &item_like, hash_bodies: false },
|
HirItemLike { item_like: &item_like, hash_bodies: false },
|
||||||
)
|
)
|
||||||
@ -94,7 +94,7 @@ fn alloc_hir_dep_nodes(
|
|||||||
let (full, hash) = input_dep_node_and_hash(
|
let (full, hash) = input_dep_node_and_hash(
|
||||||
dep_graph,
|
dep_graph,
|
||||||
hcx,
|
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 },
|
HirItemLike { item_like: &item_like, hash_bodies: true },
|
||||||
);
|
);
|
||||||
hir_body_nodes.push((def_path_hash, hash));
|
hir_body_nodes.push((def_path_hash, hash));
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_ast::node_id::NodeMap;
|
use rustc_ast::node_id::NodeMap;
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -17,10 +16,11 @@ use rustc_span::hygiene::ExpnId;
|
|||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
pub use rustc_hir::def_id::DefPathHash;
|
||||||
|
|
||||||
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
|
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
|
||||||
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
|
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
|
||||||
/// stores the `DefIndex` of its parent.
|
/// stores the `DefIndex` of its parent.
|
||||||
@ -282,28 +282,6 @@ pub enum DefPathData {
|
|||||||
ImplTrait,
|
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 {
|
impl Definitions {
|
||||||
pub fn def_path_table(&self) -> &DefPathTable {
|
pub fn def_path_table(&self) -> &DefPathTable {
|
||||||
&self.table
|
&self.table
|
||||||
|
@ -562,15 +562,7 @@ impl<'hir> Map<'hir> {
|
|||||||
where
|
where
|
||||||
V: ItemLikeVisitor<'hir>,
|
V: ItemLikeVisitor<'hir>,
|
||||||
{
|
{
|
||||||
let hir_id = self.as_local_hir_id(module).unwrap();
|
let module = self.tcx.hir_module_items(module);
|
||||||
|
|
||||||
// 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];
|
|
||||||
|
|
||||||
for id in &module.items {
|
for id in &module.items {
|
||||||
visitor.visit_item(self.expect_item(*id));
|
visitor.visit_item(self.expect_item(*id));
|
||||||
@ -639,7 +631,7 @@ impl<'hir> Map<'hir> {
|
|||||||
if self.dep_graph.is_fully_enabled() {
|
if self.dep_graph.is_fully_enabled() {
|
||||||
let hir_id_owner = hir_id.owner;
|
let hir_id_owner = hir_id.owner;
|
||||||
let def_path_hash = self.definitions.def_path_hash(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)
|
self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)
|
||||||
|
@ -114,6 +114,12 @@ pub fn provide(providers: &mut Providers<'_>) {
|
|||||||
hir_to_node_id: early.hir_to_node_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| {
|
providers.hir_owner = |tcx, id| {
|
||||||
assert_eq!(id.krate, LOCAL_CRATE);
|
assert_eq!(id.krate, LOCAL_CRATE);
|
||||||
*tcx.hir().map.owner_map.get(&id.index).unwrap()
|
*tcx.hir().map.owner_map.get(&id.index).unwrap()
|
||||||
|
@ -7,7 +7,7 @@ use crate::ty::{fast_reject, TyCtxt};
|
|||||||
|
|
||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
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_data_structures::sync::Lrc;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, DefIndex};
|
use rustc_hir::def_id::{DefId, DefIndex};
|
||||||
@ -197,19 +197,6 @@ 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> 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 {
|
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
|
||||||
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
|
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
|
||||||
panic!("Node IDs should not appear in incremental state");
|
panic!("Node IDs should not appear in incremental state");
|
||||||
|
@ -6,7 +6,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
|
|||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
||||||
use rustc_hir as hir;
|
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 smallvec::SmallVec;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
@ -114,6 +114,11 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
|
|||||||
|
|
||||||
self.node_id_hashing_mode = prev_hash_node_ids;
|
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 {
|
impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {
|
||||||
|
@ -61,6 +61,10 @@ rustc_queries! {
|
|||||||
desc { "index HIR" }
|
desc { "index HIR" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query hir_module_items(key: DefId) -> &'tcx hir::ModuleItems {
|
||||||
|
eval_always
|
||||||
|
}
|
||||||
|
|
||||||
query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> {
|
query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> {
|
||||||
eval_always
|
eval_always
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ pub struct WhereEqPredicate<'hir> {
|
|||||||
pub rhs_ty: &'hir Ty<'hir>,
|
pub rhs_ty: &'hir Ty<'hir>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable, RustcDecodable, Debug)]
|
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
|
||||||
pub struct ModuleItems {
|
pub struct ModuleItems {
|
||||||
// Use BTreeSets here so items are in the same order as in the
|
// Use BTreeSets here so items are in the same order as in the
|
||||||
// list of all items in Crate
|
// list of all items in Crate
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
||||||
|
|
||||||
use crate::hir::{
|
use crate::hir::{
|
||||||
BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
|
BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
|
||||||
VisibilityKind,
|
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.
|
/// Requirements for a `StableHashingContext` to be used in this crate.
|
||||||
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
||||||
@ -20,6 +21,35 @@ pub trait HashStableContext:
|
|||||||
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
|
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
|
||||||
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, 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 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 {
|
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
|
||||||
|
@ -120,7 +120,7 @@ impl IfThisChanged<'tcx> {
|
|||||||
if attr.check_name(sym::rustc_if_this_changed) {
|
if attr.check_name(sym::rustc_if_this_changed) {
|
||||||
let dep_node_interned = self.argument(attr);
|
let dep_node_interned = self.argument(attr);
|
||||||
let dep_node = match dep_node_interned {
|
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) {
|
Some(n) => match DepNode::from_label_string(&n.as_str(), def_path_hash) {
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
|
@ -4,7 +4,7 @@ use crate::creader::CrateMetadataRef;
|
|||||||
use crate::rmeta::table::{FixedSizeEncoding, Table};
|
use crate::rmeta::table::{FixedSizeEncoding, Table};
|
||||||
use crate::rmeta::*;
|
use crate::rmeta::*;
|
||||||
|
|
||||||
use rustc::dep_graph::{self, DepNodeIndex};
|
use rustc::dep_graph::{self, DepNode, DepNodeIndex};
|
||||||
use rustc::hir::exports::Export;
|
use rustc::hir::exports::Export;
|
||||||
use rustc::hir::map::definitions::DefPathTable;
|
use rustc::hir::map::definitions::DefPathTable;
|
||||||
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
|
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
|
||||||
@ -1607,7 +1607,8 @@ impl CrateMetadata {
|
|||||||
// would always write the same value.
|
// would always write the same value.
|
||||||
|
|
||||||
let def_path_hash = self.def_path_hash(CRATE_DEF_INDEX);
|
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);
|
dep_node_index = tcx.dep_graph.dep_node_index_of(&dep_node);
|
||||||
assert!(dep_node_index != DepNodeIndex::INVALID);
|
assert!(dep_node_index != DepNodeIndex::INVALID);
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
use crate::HashStableContext;
|
use crate::HashStableContext;
|
||||||
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::AtomicRef;
|
use rustc_data_structures::AtomicRef;
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
|
use rustc_macros::HashStable_Generic;
|
||||||
use rustc_serialize::{Decoder, Encoder};
|
use rustc_serialize::{Decoder, Encoder};
|
||||||
|
use std::borrow::Borrow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::{u32, u64};
|
use std::{u32, u64};
|
||||||
|
|
||||||
@ -102,6 +105,28 @@ impl ::std::fmt::Debug for CrateNum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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! {
|
rustc_index::newtype_index! {
|
||||||
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
||||||
/// particular definition. It should really be considered an interned
|
/// particular definition. It should really be considered an interned
|
||||||
|
Loading…
Reference in New Issue
Block a user