Skip to content

Commit e9d166f

Browse files
committed
Clean up the collector
1 parent fa09db8 commit e9d166f

File tree

6 files changed

+34
-139
lines changed

6 files changed

+34
-139
lines changed

src/librustc/hir/map/collector.rs

Lines changed: 25 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::arena::Arena;
2-
use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex};
32
use crate::hir::map::definitions::{self, DefPathHash};
4-
use crate::hir::map::{Entry, HirEntryMap, Map};
3+
use crate::hir::map::{Entry, Map};
54
use crate::hir::{HirItem, HirOwner, HirOwnerItems};
65
use crate::ich::StableHashingContext;
76
use crate::middle::cstore::CrateStore;
@@ -35,70 +34,38 @@ pub(super) struct NodeCollector<'a, 'hir> {
3534
owner_map: FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
3635
owner_items_map: FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
3736

38-
/// The node map
39-
map: HirEntryMap<'hir>,
4037
/// The parent of this node
4138
parent_node: hir::HirId,
4239

43-
// These fields keep track of the currently relevant DepNodes during
44-
// the visitor's traversal.
4540
current_dep_node_owner: DefIndex,
46-
current_signature_dep_index: DepNodeIndex,
47-
current_full_dep_index: DepNodeIndex,
48-
currently_in_body: bool,
4941

50-
dep_graph: &'a DepGraph,
5142
definitions: &'a definitions::Definitions,
5243
hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
5344

5445
hcx: StableHashingContext<'a>,
5546

5647
// We are collecting `DepNode::HirBody` hashes here so we can compute the
57-
// crate hash from then later on.
48+
// crate hash from them later on.
5849
hir_body_nodes: Vec<(DefPathHash, Fingerprint)>,
5950
}
6051

61-
fn input_dep_node_and_hash(
62-
dep_graph: &DepGraph,
52+
fn hash(
6353
hcx: &mut StableHashingContext<'_>,
64-
dep_node: DepNode,
6554
input: impl for<'a> HashStable<StableHashingContext<'a>>,
66-
) -> (DepNodeIndex, Fingerprint) {
67-
let dep_node_index = dep_graph.input_task(dep_node, &mut *hcx, &input).1;
68-
69-
let hash = if dep_graph.is_fully_enabled() {
70-
dep_graph.fingerprint_of(dep_node_index)
71-
} else {
72-
let mut stable_hasher = StableHasher::new();
73-
input.hash_stable(hcx, &mut stable_hasher);
74-
stable_hasher.finish()
75-
};
76-
77-
(dep_node_index, hash)
55+
) -> Fingerprint {
56+
let mut stable_hasher = StableHasher::new();
57+
input.hash_stable(hcx, &mut stable_hasher);
58+
stable_hasher.finish()
7859
}
7960

80-
fn alloc_hir_dep_nodes(
81-
dep_graph: &DepGraph,
61+
fn hash_body(
8262
hcx: &mut StableHashingContext<'_>,
8363
def_path_hash: DefPathHash,
8464
item_like: impl for<'a> HashStable<StableHashingContext<'a>>,
8565
hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
86-
) -> (DepNodeIndex, DepNodeIndex) {
87-
let sig = dep_graph
88-
.input_task(
89-
DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
90-
&mut *hcx,
91-
HirItemLike { item_like: &item_like, hash_bodies: false },
92-
)
93-
.1;
94-
let (full, hash) = input_dep_node_and_hash(
95-
dep_graph,
96-
hcx,
97-
DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody),
98-
HirItemLike { item_like: &item_like, hash_bodies: true },
99-
);
66+
) {
67+
let hash = hash(hcx, HirItemLike { item_like: &item_like });
10068
hir_body_nodes.push((def_path_hash, hash));
101-
(sig, full)
10269
}
10370

10471
fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(Symbol, Fingerprint, Svh)> {
@@ -121,7 +88,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
12188
sess: &'a Session,
12289
arena: &'hir Arena<'hir>,
12390
krate: &'hir Crate<'hir>,
124-
dep_graph: &'a DepGraph,
12591
definitions: &'a definitions::Definitions,
12692
hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
12793
mut hcx: StableHashingContext<'a>,
@@ -130,8 +96,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
13096

13197
let mut hir_body_nodes = Vec::new();
13298

133-
// Allocate `DepNode`s for the root module.
134-
let (root_mod_sig_dep_index, root_mod_full_dep_index) = {
99+
{
135100
let Crate {
136101
ref item,
137102
// These fields are handled separately:
@@ -147,40 +112,31 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
147112
proc_macros: _,
148113
} = *krate;
149114

150-
alloc_hir_dep_nodes(
151-
dep_graph,
152-
&mut hcx,
153-
root_mod_def_path_hash,
154-
item,
155-
&mut hir_body_nodes,
156-
)
115+
hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes)
157116
};
158117

159118
let mut collector = NodeCollector {
160119
arena,
161120
krate,
162121
source_map: sess.source_map(),
163-
map: IndexVec::from_elem_n(IndexVec::new(), definitions.def_index_count()),
164122
parent_node: hir::CRATE_HIR_ID,
165-
current_signature_dep_index: root_mod_sig_dep_index,
166-
current_full_dep_index: root_mod_full_dep_index,
167123
current_dep_node_owner: CRATE_DEF_INDEX,
168-
currently_in_body: false,
169-
dep_graph,
170124
definitions,
171125
hir_to_node_id,
172126
hcx,
173127
hir_body_nodes,
174-
owner_map: FxHashMap::default(),
175-
owner_items_map: FxHashMap::default(),
128+
owner_map: FxHashMap::with_capacity_and_hasher(
129+
definitions.def_index_count(),
130+
Default::default(),
131+
),
132+
owner_items_map: FxHashMap::with_capacity_and_hasher(
133+
definitions.def_index_count(),
134+
Default::default(),
135+
),
176136
};
177137
collector.insert_entry(
178138
hir::CRATE_HIR_ID,
179-
Entry {
180-
parent: hir::CRATE_HIR_ID,
181-
dep_node: root_mod_sig_dep_index,
182-
node: Node::Crate(&krate.item),
183-
},
139+
Entry { parent: hir::CRATE_HIR_ID, node: Node::Crate(&krate.item) },
184140
);
185141

186142
collector
@@ -192,7 +148,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
192148
cstore: &dyn CrateStore,
193149
commandline_args_hash: u64,
194150
) -> (
195-
HirEntryMap<'hir>,
196151
FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
197152
FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
198153
Svh,
@@ -239,7 +194,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
239194
let crate_hash: Fingerprint = stable_hasher.finish();
240195

241196
let svh = Svh::new(crate_hash.to_smaller_hash());
242-
(self.map, self.owner_map, self.owner_items_map, svh)
197+
(self.owner_map, self.owner_items_map, svh)
243198
}
244199

245200
fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
@@ -266,26 +221,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
266221
items.items[id.local_id] =
267222
Some(HirItem { parent: entry.parent.local_id, node: entry.node });
268223
}
269-
270-
debug!("hir_map: {:?} => {:?}", id, entry);
271-
let local_map = &mut self.map[id.owner];
272-
let len = local_map.len();
273-
if i >= len {
274-
local_map.extend(repeat(None).take(i - len + 1));
275-
}
276-
local_map[id.local_id] = Some(entry);
277224
}
278225

279226
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
280-
let entry = Entry {
281-
parent: self.parent_node,
282-
dep_node: if self.currently_in_body {
283-
self.current_full_dep_index
284-
} else {
285-
self.current_signature_dep_index
286-
},
287-
node,
288-
};
227+
let entry = Entry { parent: self.parent_node, node };
289228

290229
// Make sure that the DepNode of some node coincides with the HirId
291230
// owner of that node.
@@ -340,29 +279,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
340279
f: F,
341280
) {
342281
let prev_owner = self.current_dep_node_owner;
343-
let prev_signature_dep_index = self.current_signature_dep_index;
344-
let prev_full_dep_index = self.current_full_dep_index;
345-
let prev_in_body = self.currently_in_body;
346282

347283
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
348284

349-
let (signature_dep_index, full_dep_index) = alloc_hir_dep_nodes(
350-
self.dep_graph,
351-
&mut self.hcx,
352-
def_path_hash,
353-
item_like,
354-
&mut self.hir_body_nodes,
355-
);
356-
self.current_signature_dep_index = signature_dep_index;
357-
self.current_full_dep_index = full_dep_index;
285+
hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes);
358286

359287
self.current_dep_node_owner = dep_node_owner;
360-
self.currently_in_body = false;
361288
f(self);
362-
self.currently_in_body = prev_in_body;
363289
self.current_dep_node_owner = prev_owner;
364-
self.current_full_dep_index = prev_full_dep_index;
365-
self.current_signature_dep_index = prev_signature_dep_index;
366290
}
367291
}
368292

@@ -391,10 +315,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
391315
}
392316

393317
fn visit_nested_body(&mut self, id: BodyId) {
394-
let prev_in_body = self.currently_in_body;
395-
self.currently_in_body = true;
396318
self.visit_body(self.krate.body(id));
397-
self.currently_in_body = prev_in_body;
398319
}
399320

400321
fn visit_param(&mut self, param: &'hir Param<'hir>) {
@@ -617,19 +538,16 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
617538
}
618539
}
619540

620-
// This is a wrapper structure that allows determining if span values within
621-
// the wrapped item should be hashed or not.
622541
struct HirItemLike<T> {
623542
item_like: T,
624-
hash_bodies: bool,
625543
}
626544

627545
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
628546
where
629547
T: HashStable<StableHashingContext<'hir>>,
630548
{
631549
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
632-
hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
550+
hcx.while_hashing_hir_bodies(true, |hcx| {
633551
self.item_like.hash_stable(hcx, hasher);
634552
});
635553
}

src/librustc/hir/map/hir_id_validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
88
use rustc_hir::{HirId, ItemLocalId};*/
99

1010
pub fn check_crate(hir_map: &EarlyMap<'_>, sess: &rustc_session::Session) {
11-
hir_map.dep_graph.assert_ignored();
12-
/*
11+
/*hir_map.dep_graph.assert_ignored();
12+
1313
let errors = Lock::new(Vec::new());
1414
1515
par_iter(&hir_map.krate.modules).for_each(|(module_id, _)| {

src/librustc/hir/map/mod.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub use self::definitions::{
44
};
55

66
use crate::arena::Arena;
7-
use crate::dep_graph::{DepGraph, DepNodeIndex};
87
use crate::hir::{HirOwner, HirOwnerItems};
98
use crate::middle::cstore::CrateStoreDyn;
109
use crate::ty::query::Providers;
@@ -18,7 +17,6 @@ use rustc_hir::intravisit;
1817
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1918
use rustc_hir::print::Nested;
2019
use rustc_hir::*;
21-
use rustc_index::vec::IndexVec;
2220
use rustc_span::hygiene::MacroKind;
2321
use rustc_span::source_map::Spanned;
2422
use rustc_span::symbol::kw;
@@ -34,7 +32,6 @@ mod hir_id_validator;
3432
#[derive(Copy, Clone, Debug)]
3533
pub struct Entry<'hir> {
3634
parent: HirId,
37-
dep_node: DepNodeIndex,
3835
node: Node<'hir>,
3936
}
4037

@@ -132,26 +129,16 @@ fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
132129
}
133130
}
134131

135-
/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
136-
/// but it is implemented as 2 layers of arrays.
137-
/// - first we have `A = IndexVec<DefIndex, B>` mapping `DefIndex`s to an inner value
138-
/// - which is `B = IndexVec<ItemLocalId, Option<Entry<'hir>>` which gives you the `Entry`.
139-
pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Option<Entry<'hir>>>>;
140-
141132
/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
142133
pub struct EarlyMap<'hir> {
143134
pub krate: &'hir Crate<'hir>,
144135

145-
pub dep_graph: DepGraph,
146-
147136
/// The SVH of the local crate.
148137
pub crate_hash: Svh,
149138

150139
pub(super) owner_map: FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
151140
pub(super) owner_items_map: FxHashMap<DefIndex, &'hir HirOwnerItems<'hir>>,
152141

153-
pub(super) map: HirEntryMap<'hir>,
154-
155142
pub(crate) definitions: &'hir Definitions,
156143

157144
/// The reverse mapping of `node_to_hir_id`.
@@ -164,8 +151,6 @@ pub struct Map<'hir> {
164151

165152
pub(super) krate: &'hir Crate<'hir>,
166153

167-
pub dep_graph: DepGraph,
168-
169154
/// The SVH of the local crate.
170155
pub crate_hash: Svh,
171156

@@ -383,15 +368,11 @@ impl<'hir> Map<'hir> {
383368
fn get_entry(&self, id: HirId) -> Entry<'hir> {
384369
if id.local_id == ItemLocalId::from_u32_const(0) {
385370
let owner = self.tcx.hir_owner(id.owner_def_id());
386-
Entry { parent: owner.parent, node: owner.node, dep_node: DepNodeIndex::INVALID }
371+
Entry { parent: owner.parent, node: owner.node }
387372
} else {
388373
let owner = self.tcx.hir_owner_items(id.owner_def_id());
389374
let item = owner.items[id.local_id].as_ref().unwrap();
390-
Entry {
391-
parent: HirId { owner: id.owner, local_id: item.parent },
392-
node: item.node,
393-
dep_node: DepNodeIndex::INVALID,
394-
}
375+
Entry { parent: HirId { owner: id.owner, local_id: item.parent }, node: item.node }
395376
}
396377
}
397378

@@ -1069,7 +1050,6 @@ pub fn map_crate<'hir>(
10691050
arena: &'hir Arena<'hir>,
10701051
cstore: &CrateStoreDyn,
10711052
krate: &'hir Crate<'hir>,
1072-
dep_graph: DepGraph,
10731053
definitions: Definitions,
10741054
) -> EarlyMap<'hir> {
10751055
let _prof_timer = sess.prof.generic_activity("build_hir_map");
@@ -1081,11 +1061,11 @@ pub fn map_crate<'hir>(
10811061
.map(|(node_id, &hir_id)| (hir_id, node_id))
10821062
.collect();
10831063

1084-
let (map, owner_map, owner_items_map, crate_hash) = {
1064+
let (owner_map, owner_items_map, crate_hash) = {
10851065
let hcx = crate::ich::StableHashingContext::new(sess, krate, &definitions, cstore);
10861066

10871067
let mut collector =
1088-
NodeCollector::root(sess, arena, krate, &dep_graph, &definitions, &hir_to_node_id, hcx);
1068+
NodeCollector::root(sess, arena, krate, &definitions, &hir_to_node_id, hcx);
10891069
intravisit::walk_crate(&mut collector, krate);
10901070

10911071
let crate_disambiguator = sess.local_crate_disambiguator();
@@ -1095,9 +1075,7 @@ pub fn map_crate<'hir>(
10951075

10961076
let map = EarlyMap {
10971077
krate,
1098-
dep_graph,
10991078
crate_hash,
1100-
map,
11011079
owner_map,
11021080
owner_items_map: owner_items_map.into_iter().map(|(k, v)| (k, &*v)).collect(),
11031081
hir_to_node_id,

src/librustc/hir/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ pub fn provide(providers: &mut Providers<'_>) {
100100
tcx,
101101
krate: early.krate,
102102

103-
dep_graph: early.dep_graph,
104-
105103
crate_hash: early.crate_hash,
106104

107105
owner_map: early.owner_map,

0 commit comments

Comments
 (0)