Skip to content

Commit b40e6ba

Browse files
committed
Update visit_item_likes_in_module
1 parent 38e613c commit b40e6ba

File tree

13 files changed

+88
-66
lines changed

13 files changed

+88
-66
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ macro_rules! define_dep_nodes {
223223
/// Construct a DepNode from the given DepKind and DefPathHash. This
224224
/// method will assert that the given DepKind actually requires a
225225
/// single DefId/DefPathHash parameter.
226-
pub fn from_def_path_hash(kind: DepKind,
227-
def_path_hash: DefPathHash)
226+
pub fn from_def_path_hash(def_path_hash: DefPathHash,
227+
kind: DepKind)
228228
-> DepNode {
229229
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
230230
DepNode {
@@ -280,7 +280,7 @@ macro_rules! define_dep_nodes {
280280
}
281281

282282
if kind.has_params() {
283-
Ok(def_path_hash.to_dep_node(kind))
283+
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
284284
} else {
285285
Ok(DepNode::new_no_params(kind))
286286
}
@@ -337,12 +337,6 @@ impl fmt::Debug for DepNode {
337337
}
338338
}
339339

340-
impl DefPathHash {
341-
pub fn to_dep_node(self, kind: DepKind) -> DepNode {
342-
DepNode::from_def_path_hash(kind, self)
343-
}
344-
}
345-
346340
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
347341
// We use this for most things when incr. comp. is turned off.
348342
[] Null,

src/librustc/hir/map/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ fn alloc_hir_dep_nodes(
8686
) -> (DepNodeIndex, DepNodeIndex) {
8787
let sig = dep_graph
8888
.input_task(
89-
def_path_hash.to_dep_node(DepKind::Hir),
89+
DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
9090
&mut *hcx,
9191
HirItemLike { item_like: &item_like, hash_bodies: false },
9292
)
9393
.1;
9494
let (full, hash) = input_dep_node_and_hash(
9595
dep_graph,
9696
hcx,
97-
def_path_hash.to_dep_node(DepKind::HirBody),
97+
DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody),
9898
HirItemLike { item_like: &item_like, hash_bodies: true },
9999
);
100100
hir_body_nodes.push((def_path_hash, hash));

src/librustc/hir/map/definitions.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
use rustc_ast::ast;
88
use rustc_ast::node_id::NodeMap;
9-
use rustc_data_structures::fingerprint::Fingerprint;
109
use rustc_data_structures::fx::FxHashMap;
1110
use rustc_data_structures::stable_hasher::StableHasher;
1211
use rustc_hir as hir;
@@ -17,10 +16,11 @@ use rustc_span::hygiene::ExpnId;
1716
use rustc_span::symbol::{sym, Symbol};
1817
use rustc_span::Span;
1918

20-
use std::borrow::Borrow;
2119
use std::fmt::Write;
2220
use std::hash::Hash;
2321

22+
pub use rustc_hir::def_id::DefPathHash;
23+
2424
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
2525
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
2626
/// stores the `DefIndex` of its parent.
@@ -282,28 +282,6 @@ pub enum DefPathData {
282282
ImplTrait,
283283
}
284284

285-
#[derive(
286-
Copy,
287-
Clone,
288-
Hash,
289-
PartialEq,
290-
Eq,
291-
PartialOrd,
292-
Ord,
293-
Debug,
294-
RustcEncodable,
295-
RustcDecodable,
296-
HashStable
297-
)]
298-
pub struct DefPathHash(pub Fingerprint);
299-
300-
impl Borrow<Fingerprint> for DefPathHash {
301-
#[inline]
302-
fn borrow(&self) -> &Fingerprint {
303-
&self.0
304-
}
305-
}
306-
307285
impl Definitions {
308286
pub fn def_path_table(&self) -> &DefPathTable {
309287
&self.table

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,7 @@ impl<'hir> Map<'hir> {
562562
where
563563
V: ItemLikeVisitor<'hir>,
564564
{
565-
let hir_id = self.as_local_hir_id(module).unwrap();
566-
567-
// Read the module so we'll be re-executed if new items
568-
// appear immediately under in the module. If some new item appears
569-
// in some nested item in the module, we'll be re-executed due to reads
570-
// in the expect_* calls the loops below
571-
self.read(hir_id);
572-
573-
let module = &self.krate.modules[&hir_id];
565+
let module = self.tcx.hir_module_items(module);
574566

575567
for id in &module.items {
576568
visitor.visit_item(self.expect_item(*id));
@@ -639,7 +631,7 @@ impl<'hir> Map<'hir> {
639631
if self.dep_graph.is_fully_enabled() {
640632
let hir_id_owner = hir_id.owner;
641633
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
642-
self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody));
634+
self.dep_graph.read(DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody));
643635
}
644636

645637
self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)

src/librustc/hir/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ pub fn provide(providers: &mut Providers<'_>) {
114114
hir_to_node_id: early.hir_to_node_id,
115115
})
116116
};
117+
providers.hir_module_items = |tcx, id| {
118+
assert_eq!(id.krate, LOCAL_CRATE);
119+
let hir = tcx.hir();
120+
let module = hir.as_local_hir_id(id).unwrap();
121+
&hir.untracked_krate().modules[&module]
122+
};
117123
providers.hir_owner = |tcx, id| {
118124
assert_eq!(id.krate, LOCAL_CRATE);
119125
*tcx.hir().map.owner_map.get(&id.index).unwrap()

src/librustc/ich/hcx.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ty::{fast_reject, TyCtxt};
77

88
use rustc_ast::ast;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
10+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1111
use rustc_data_structures::sync::Lrc;
1212
use rustc_hir as hir;
1313
use rustc_hir::def_id::{DefId, DefIndex};
@@ -197,19 +197,6 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
197197

198198
impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}
199199

200-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::HirId {
201-
type KeyType = (DefPathHash, hir::ItemLocalId);
202-
203-
#[inline]
204-
fn to_stable_hash_key(
205-
&self,
206-
hcx: &StableHashingContext<'a>,
207-
) -> (DefPathHash, hir::ItemLocalId) {
208-
let def_path_hash = hcx.local_def_path_hash(self.owner);
209-
(def_path_hash, self.local_id)
210-
}
211-
}
212-
213200
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
214201
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
215202
panic!("Node IDs should not appear in incremental state");

src/librustc/ich/impls_hir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
66
use rustc_attr as attr;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
88
use rustc_hir as hir;
9-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
9+
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
1010
use smallvec::SmallVec;
1111
use std::mem;
1212

@@ -114,6 +114,11 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
114114

115115
self.node_id_hashing_mode = prev_hash_node_ids;
116116
}
117+
118+
#[inline]
119+
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
120+
self.local_def_path_hash(def_index)
121+
}
117122
}
118123

119124
impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {

src/librustc/query/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ rustc_queries! {
6161
desc { "index HIR" }
6262
}
6363

64+
query hir_module_items(key: DefId) -> &'tcx hir::ModuleItems {
65+
eval_always
66+
}
67+
6468
query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> {
6569
eval_always
6670
}

src/librustc_hir/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ pub struct WhereEqPredicate<'hir> {
597597
pub rhs_ty: &'hir Ty<'hir>,
598598
}
599599

600-
#[derive(RustcEncodable, RustcDecodable, Debug)]
600+
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
601601
pub struct ModuleItems {
602602
// Use BTreeSets here so items are in the same order as in the
603603
// list of all items in Crate

src/librustc_hir/stable_hash_impls.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
22

33
use crate::hir::{
44
BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
55
VisibilityKind,
66
};
7-
use crate::hir_id::HirId;
7+
use crate::hir_id::{HirId, ItemLocalId};
8+
use rustc_span::def_id::{DefIndex, DefPathHash};
89

910
/// Requirements for a `StableHashingContext` to be used in this crate.
1011
/// This is a hack to allow using the `HashStable_Generic` derive macro
@@ -20,6 +21,35 @@ pub trait HashStableContext:
2021
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
2122
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
2223
fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
24+
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash;
25+
}
26+
27+
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
28+
type KeyType = (DefPathHash, ItemLocalId);
29+
30+
#[inline]
31+
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
32+
let def_path_hash = hcx.local_def_path_hash(self.owner);
33+
(def_path_hash, self.local_id)
34+
}
35+
}
36+
37+
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
38+
type KeyType = (DefPathHash, ItemLocalId);
39+
40+
#[inline]
41+
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
42+
self.hir_id.to_stable_hash_key(hcx)
43+
}
44+
}
45+
46+
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
47+
type KeyType = (DefPathHash, ItemLocalId);
48+
49+
#[inline]
50+
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
51+
self.hir_id.to_stable_hash_key(hcx)
52+
}
2353
}
2454

2555
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {

0 commit comments

Comments
 (0)