Skip to content

Commit 74bf0d5

Browse files
committed
Update visit_item_likes_in_module
1 parent 3ed32d1 commit 74bf0d5

File tree

13 files changed

+87
-66
lines changed

13 files changed

+87
-66
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ macro_rules! define_dep_nodes {
276276
/// Construct a DepNode from the given DepKind and DefPathHash. This
277277
/// method will assert that the given DepKind actually requires a
278278
/// single DefId/DefPathHash parameter.
279-
pub fn from_def_path_hash(kind: DepKind,
280-
def_path_hash: DefPathHash)
279+
pub fn from_def_path_hash(def_path_hash: DefPathHash,
280+
kind: DepKind)
281281
-> DepNode {
282282
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
283283
DepNode {
@@ -333,7 +333,7 @@ macro_rules! define_dep_nodes {
333333
}
334334

335335
if kind.has_params() {
336-
Ok(def_path_hash.to_dep_node(kind))
336+
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
337337
} else {
338338
Ok(DepNode::new_no_params(kind))
339339
}
@@ -390,12 +390,6 @@ impl fmt::Debug for DepNode {
390390
}
391391
}
392392

393-
impl DefPathHash {
394-
pub fn to_dep_node(self, kind: DepKind) -> DepNode {
395-
DepNode::from_def_path_hash(kind, self)
396-
}
397-
}
398-
399393
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
400394
// We use this for most things when incr. comp. is turned off.
401395
[] 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
@@ -4,7 +4,6 @@
44
//! There are also some rather random cases (like const initializer
55
//! expressions) that are mostly just leftovers.
66
7-
use rustc_data_structures::fingerprint::Fingerprint;
87
use rustc_data_structures::fx::FxHashMap;
98
use rustc_data_structures::stable_hasher::StableHasher;
109
use rustc_hir as hir;
@@ -17,10 +16,11 @@ use rustc_span::Span;
1716
use syntax::ast;
1817
use syntax::node_id::NodeMap;
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
@@ -567,15 +567,7 @@ impl<'hir> Map<'hir> {
567567
where
568568
V: ItemLikeVisitor<'hir>,
569569
{
570-
let hir_id = self.as_local_hir_id(module).unwrap();
571-
572-
// Read the module so we'll be re-executed if new items
573-
// appear immediately under in the module. If some new item appears
574-
// in some nested item in the module, we'll be re-executed due to reads
575-
// in the expect_* calls the loops below
576-
self.read(hir_id);
577-
578-
let module = &self.krate.modules[&hir_id];
570+
let module = self.tcx.hir_module_items(module);
579571

580572
for id in &module.items {
581573
visitor.visit_item(self.expect_item(*id));
@@ -644,7 +636,7 @@ impl<'hir> Map<'hir> {
644636
if self.dep_graph.is_fully_enabled() {
645637
let hir_id_owner = hir_id.owner;
646638
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
647-
self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody));
639+
self.dep_graph.read(DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody));
648640
}
649641

650642
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
@@ -107,6 +107,12 @@ pub fn provide(providers: &mut Providers<'_>) {
107107
hir_to_node_id: early.hir_to_node_id,
108108
})
109109
};
110+
providers.hir_module_items = |tcx, id| {
111+
assert_eq!(id.krate, LOCAL_CRATE);
112+
let hir = tcx.hir();
113+
let module = hir.as_local_hir_id(id).unwrap();
114+
&hir.untracked_krate().modules[&module]
115+
};
110116
providers.hir_owner = |tcx, id| {
111117
assert_eq!(id.krate, LOCAL_CRATE);
112118
*tcx.hir().map.owner_map.get(&id.index).unwrap()

src/librustc/ich/hcx.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
215202
match hcx.node_id_hashing_mode {

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

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

121121
self.node_id_hashing_mode = prev_hash_node_ids;
122122
}
123+
124+
#[inline]
125+
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
126+
self.local_def_path_hash(def_index)
127+
}
123128
}
124129

125130
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/def_id.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use rustc_data_structures::fingerprint::Fingerprint;
12
use rustc_data_structures::AtomicRef;
23
use rustc_index::vec::Idx;
4+
use rustc_macros::HashStable_Generic;
35
use rustc_serialize::{Decoder, Encoder};
6+
use std::borrow::Borrow;
47
use std::fmt;
58
use std::{u32, u64};
69

@@ -100,6 +103,28 @@ impl rustc_serialize::UseSpecializedDecodable for CrateNum {
100103
}
101104
}
102105

106+
#[derive(
107+
Copy,
108+
Clone,
109+
Hash,
110+
PartialEq,
111+
Eq,
112+
PartialOrd,
113+
Ord,
114+
Debug,
115+
RustcEncodable,
116+
RustcDecodable,
117+
HashStable_Generic
118+
)]
119+
pub struct DefPathHash(pub Fingerprint);
120+
121+
impl Borrow<Fingerprint> for DefPathHash {
122+
#[inline]
123+
fn borrow(&self) -> &Fingerprint {
124+
&self.0
125+
}
126+
}
127+
103128
rustc_index::newtype_index! {
104129
/// A DefIndex is an index into the hir-map for a crate, identifying a
105130
/// particular definition. It should really be considered an interned

src/librustc_hir/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ pub struct WhereEqPredicate<'hir> {
579579
pub rhs_ty: &'hir Ty<'hir>,
580580
}
581581

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

src/librustc_hir/stable_hash_impls.rs

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

3-
use crate::def_id::DefId;
3+
use crate::def_id::{DefId, DefIndex, DefPathHash};
44
use crate::hir::{
55
BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
66
VisibilityKind,
77
};
8-
use crate::hir_id::HirId;
8+
use crate::hir_id::{HirId, ItemLocalId};
99

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

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

src/librustc_incremental/assert_dep_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl IfThisChanged<'tcx> {
120120
if attr.check_name(sym::rustc_if_this_changed) {
121121
let dep_node_interned = self.argument(attr);
122122
let dep_node = match dep_node_interned {
123-
None => def_path_hash.to_dep_node(DepKind::Hir),
123+
None => DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
124124
Some(n) => match DepNode::from_label_string(&n.as_str(), def_path_hash) {
125125
Ok(n) => n,
126126
Err(()) => {

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::rmeta::table::{FixedSizeEncoding, Table};
44
use crate::rmeta::*;
55

6-
use rustc::dep_graph::{self, DepNodeIndex};
6+
use rustc::dep_graph::{self, DepNode, DepNodeIndex};
77
use rustc::hir::exports::Export;
88
use rustc::hir::map::definitions::DefPathTable;
99
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
@@ -1536,7 +1536,8 @@ impl<'a, 'tcx> CrateMetadata {
15361536
// would always write the same value.
15371537

15381538
let def_path_hash = self.def_path_hash(CRATE_DEF_INDEX);
1539-
let dep_node = def_path_hash.to_dep_node(dep_graph::DepKind::CrateMetadata);
1539+
let dep_node =
1540+
DepNode::from_def_path_hash(def_path_hash, dep_graph::DepKind::CrateMetadata);
15401541

15411542
dep_node_index = tcx.dep_graph.dep_node_index_of(&dep_node);
15421543
assert!(dep_node_index != DepNodeIndex::INVALID);

0 commit comments

Comments
 (0)