Skip to content

Commit 77e659a

Browse files
Remove some more things that were only needed for inlined-HIR DefIds
1 parent 45571f3 commit 77e659a

File tree

5 files changed

+2
-215
lines changed

5 files changed

+2
-215
lines changed

src/librustc/dep_graph/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ to see something like:
418418

419419
Hir(foo) -> Collect(bar)
420420
Collect(bar) -> TypeckItemBody(bar)
421-
421+
422422
That first edge looks suspicious to you. So you set
423423
`RUST_FORBID_DEP_GRAPH_EDGE` to `Hir&foo -> Collect&bar`, re-run, and
424424
then observe the backtrace. Voila, bug fixed!
@@ -440,6 +440,4 @@ To achieve this, the HIR map will detect if the def-id originates in
440440
an inlined node and add a dependency to a suitable `MetaData` node
441441
instead. If you are reading a HIR node and are not sure if it may be
442442
inlined or not, you can use `tcx.map.read(node_id)` and it will detect
443-
whether the node is inlined or not and do the right thing. You can
444-
also use `tcx.map.is_inlined_def_id()` and
445-
`tcx.map.is_inlined_node_id()` to test.
443+
whether the node is inlined or not and do the right thing.

src/librustc/dep_graph/visit.rs

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
4040
let task_id = (self.dep_node_fn)(item_def_id);
4141
let _task = self.tcx.dep_graph.in_task(task_id.clone());
4242
debug!("Started task {:?}", task_id);
43-
assert!(!self.tcx.map.is_inlined_def_id(item_def_id));
4443
self.tcx.dep_graph.read(DepNode::Hir(item_def_id));
4544
self.visitor.visit_item(i);
4645
debug!("Ended task {:?}", task_id);
@@ -51,7 +50,6 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
5150
let task_id = (self.dep_node_fn)(impl_item_def_id);
5251
let _task = self.tcx.dep_graph.in_task(task_id.clone());
5352
debug!("Started task {:?}", task_id);
54-
assert!(!self.tcx.map.is_inlined_def_id(impl_item_def_id));
5553
self.tcx.dep_graph.read(DepNode::Hir(impl_item_def_id));
5654
self.visitor.visit_impl_item(i);
5755
debug!("Ended task {:?}", task_id);

src/librustc/hir/map/def_collector.rs

-192
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,15 @@
99
// except according to those terms.
1010

1111
use hir::map::definitions::*;
12-
13-
use hir;
14-
use hir::intravisit::{self, Visitor, NestedVisitorMap};
1512
use hir::def_id::{CRATE_DEF_INDEX, DefIndex};
1613

17-
use middle::cstore::InlinedItem;
18-
1914
use syntax::ast::*;
2015
use syntax::ext::hygiene::Mark;
2116
use syntax::visit;
2217
use syntax::symbol::{Symbol, keywords};
2318

2419
/// Creates def ids for nodes in the HIR.
2520
pub struct DefCollector<'a> {
26-
// If we are walking HIR (c.f., AST), we need to keep a reference to the
27-
// crate.
28-
hir_crate: Option<&'a hir::Crate>,
2921
definitions: &'a mut Definitions,
3022
parent_def: Option<DefIndex>,
3123
pub visit_macro_invoc: Option<&'a mut FnMut(MacroInvocationData)>,
@@ -40,7 +32,6 @@ pub struct MacroInvocationData {
4032
impl<'a> DefCollector<'a> {
4133
pub fn new(definitions: &'a mut Definitions) -> Self {
4234
DefCollector {
43-
hir_crate: None,
4435
definitions: definitions,
4536
parent_def: None,
4637
visit_macro_invoc: None,
@@ -51,13 +42,6 @@ impl<'a> DefCollector<'a> {
5142
let root = self.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
5243
assert_eq!(root, CRATE_DEF_INDEX);
5344
self.parent_def = Some(root);
54-
55-
self.create_def_with_parent(Some(CRATE_DEF_INDEX), DUMMY_NODE_ID, DefPathData::Misc);
56-
}
57-
58-
pub fn walk_item(&mut self, ii: &'a InlinedItem, krate: &'a hir::Crate) {
59-
self.hir_crate = Some(krate);
60-
ii.visit(self);
6145
}
6246

6347
fn create_def(&mut self, node_id: NodeId, data: DefPathData) -> DefIndex {
@@ -95,16 +79,6 @@ impl<'a> DefCollector<'a> {
9579
self.create_def(expr.id, DefPathData::Initializer);
9680
}
9781

98-
fn visit_hir_const_integer(&mut self, expr: &hir::Expr) {
99-
// FIXME(eddyb) Closures should have separate
100-
// function definition IDs and expression IDs.
101-
if let hir::ExprClosure(..) = expr.node {
102-
return;
103-
}
104-
105-
self.create_def(expr.id, DefPathData::Initializer);
106-
}
107-
10882
fn visit_macro_invoc(&mut self, id: NodeId, const_integer: bool) {
10983
if let Some(ref mut visit) = self.visit_macro_invoc {
11084
visit(MacroInvocationData {
@@ -305,169 +279,3 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
305279
}
306280
}
307281
}
308-
309-
// We walk the HIR rather than the AST when reading items from metadata.
310-
impl<'ast> Visitor<'ast> for DefCollector<'ast> {
311-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
312-
// note however that we override `visit_body` below
313-
NestedVisitorMap::None
314-
}
315-
316-
fn visit_body(&mut self, id: hir::ExprId) {
317-
if let Some(krate) = self.hir_crate {
318-
self.visit_expr(krate.expr(id));
319-
}
320-
}
321-
322-
fn visit_item(&mut self, i: &'ast hir::Item) {
323-
debug!("visit_item: {:?}", i);
324-
325-
// Pick the def data. This need not be unique, but the more
326-
// information we encapsulate into
327-
let def_data = match i.node {
328-
hir::ItemDefaultImpl(..) | hir::ItemImpl(..) =>
329-
DefPathData::Impl,
330-
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) |
331-
hir::ItemTrait(..) | hir::ItemExternCrate(..) | hir::ItemMod(..) |
332-
hir::ItemForeignMod(..) | hir::ItemTy(..) =>
333-
DefPathData::TypeNs(i.name.as_str()),
334-
hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) =>
335-
DefPathData::ValueNs(i.name.as_str()),
336-
hir::ItemUse(..) => DefPathData::Misc,
337-
};
338-
let def = self.create_def(i.id, def_data);
339-
340-
self.with_parent(def, |this| {
341-
match i.node {
342-
hir::ItemEnum(ref enum_definition, _) => {
343-
for v in &enum_definition.variants {
344-
let variant_def_index =
345-
this.create_def(v.node.data.id(),
346-
DefPathData::EnumVariant(v.node.name.as_str()));
347-
348-
this.with_parent(variant_def_index, |this| {
349-
for field in v.node.data.fields() {
350-
this.create_def(field.id,
351-
DefPathData::Field(field.name.as_str()));
352-
}
353-
if let Some(ref expr) = v.node.disr_expr {
354-
this.visit_hir_const_integer(expr);
355-
}
356-
});
357-
}
358-
}
359-
hir::ItemStruct(ref struct_def, _) |
360-
hir::ItemUnion(ref struct_def, _) => {
361-
// If this is a tuple-like struct, register the constructor.
362-
if !struct_def.is_struct() {
363-
this.create_def(struct_def.id(),
364-
DefPathData::StructCtor);
365-
}
366-
367-
for field in struct_def.fields() {
368-
this.create_def(field.id, DefPathData::Field(field.name.as_str()));
369-
}
370-
}
371-
_ => {}
372-
}
373-
intravisit::walk_item(this, i);
374-
});
375-
}
376-
377-
fn visit_foreign_item(&mut self, foreign_item: &'ast hir::ForeignItem) {
378-
let def = self.create_def(foreign_item.id,
379-
DefPathData::ValueNs(foreign_item.name.as_str()));
380-
381-
self.with_parent(def, |this| {
382-
intravisit::walk_foreign_item(this, foreign_item);
383-
});
384-
}
385-
386-
fn visit_generics(&mut self, generics: &'ast hir::Generics) {
387-
for ty_param in generics.ty_params.iter() {
388-
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.name.as_str()));
389-
}
390-
391-
intravisit::walk_generics(self, generics);
392-
}
393-
394-
fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
395-
let def_data = match ti.node {
396-
hir::MethodTraitItem(..) | hir::ConstTraitItem(..) =>
397-
DefPathData::ValueNs(ti.name.as_str()),
398-
hir::TypeTraitItem(..) => DefPathData::TypeNs(ti.name.as_str()),
399-
};
400-
401-
let def = self.create_def(ti.id, def_data);
402-
self.with_parent(def, |this| {
403-
if let hir::ConstTraitItem(_, Some(ref expr)) = ti.node {
404-
this.create_def(expr.id, DefPathData::Initializer);
405-
}
406-
407-
intravisit::walk_trait_item(this, ti);
408-
});
409-
}
410-
411-
fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
412-
let def_data = match ii.node {
413-
hir::ImplItemKind::Method(..) | hir::ImplItemKind::Const(..) =>
414-
DefPathData::ValueNs(ii.name.as_str()),
415-
hir::ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name.as_str()),
416-
};
417-
418-
let def = self.create_def(ii.id, def_data);
419-
self.with_parent(def, |this| {
420-
if let hir::ImplItemKind::Const(_, ref expr) = ii.node {
421-
this.create_def(expr.id, DefPathData::Initializer);
422-
}
423-
424-
intravisit::walk_impl_item(this, ii);
425-
});
426-
}
427-
428-
fn visit_pat(&mut self, pat: &'ast hir::Pat) {
429-
let parent_def = self.parent_def;
430-
431-
if let hir::PatKind::Binding(_, _, name, _) = pat.node {
432-
let def = self.create_def(pat.id, DefPathData::Binding(name.node.as_str()));
433-
self.parent_def = Some(def);
434-
}
435-
436-
intravisit::walk_pat(self, pat);
437-
self.parent_def = parent_def;
438-
}
439-
440-
fn visit_expr(&mut self, expr: &'ast hir::Expr) {
441-
let parent_def = self.parent_def;
442-
443-
if let hir::ExprRepeat(_, ref count) = expr.node {
444-
self.visit_hir_const_integer(count);
445-
}
446-
447-
if let hir::ExprClosure(..) = expr.node {
448-
let def = self.create_def(expr.id, DefPathData::ClosureExpr);
449-
self.parent_def = Some(def);
450-
}
451-
452-
intravisit::walk_expr(self, expr);
453-
self.parent_def = parent_def;
454-
}
455-
456-
fn visit_ty(&mut self, ty: &'ast hir::Ty) {
457-
if let hir::TyArray(_, ref length) = ty.node {
458-
self.visit_hir_const_integer(length);
459-
}
460-
if let hir::TyImplTrait(..) = ty.node {
461-
self.create_def(ty.id, DefPathData::ImplTrait);
462-
}
463-
intravisit::walk_ty(self, ty);
464-
}
465-
466-
fn visit_lifetime_def(&mut self, def: &'ast hir::LifetimeDef) {
467-
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
468-
}
469-
470-
fn visit_macro_def(&mut self, macro_def: &'ast hir::MacroDef) {
471-
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name.as_str()));
472-
}
473-
}

src/librustc/hir/map/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,9 @@ pub struct Map<'ast> {
226226
/// All NodeIds that are numerically greater or equal to this value come
227227
/// from inlined items.
228228
local_node_id_watermark: NodeId,
229-
230-
/// All def-indices that are numerically greater or equal to this value come
231-
/// from inlined items.
232-
local_def_id_watermark: usize,
233229
}
234230

235231
impl<'ast> Map<'ast> {
236-
pub fn is_inlined_def_id(&self, id: DefId) -> bool {
237-
id.is_local() && id.index.as_usize() >= self.local_def_id_watermark
238-
}
239-
240232
pub fn is_inlined_node_id(&self, id: NodeId) -> bool {
241233
id >= self.local_node_id_watermark
242234
}
@@ -262,7 +254,6 @@ impl<'ast> Map<'ast> {
262254
EntryItem(_, item) => {
263255
assert_eq!(id, item.id);
264256
let def_id = self.local_def_id(id);
265-
assert!(!self.is_inlined_def_id(def_id));
266257

267258
if let Some(last_id) = last_expr {
268259
// The body of the item may have a separate dep node
@@ -278,7 +269,6 @@ impl<'ast> Map<'ast> {
278269

279270
EntryImplItem(_, item) => {
280271
let def_id = self.local_def_id(id);
281-
assert!(!self.is_inlined_def_id(def_id));
282272

283273
if let Some(last_id) = last_expr {
284274
// The body of the item may have a separate dep node
@@ -934,15 +924,13 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest,
934924
}
935925

936926
let local_node_id_watermark = NodeId::new(map.len());
937-
let local_def_id_watermark = definitions.len();
938927

939928
Map {
940929
forest: forest,
941930
dep_graph: forest.dep_graph.clone(),
942931
map: RefCell::new(map),
943932
definitions: definitions,
944933
local_node_id_watermark: local_node_id_watermark,
945-
local_def_id_watermark: local_def_id_watermark,
946934
}
947935
}
948936

src/librustc_incremental/persist/hash.rs

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
6666
def_id,
6767
self.tcx.item_path_str(def_id));
6868

69-
assert!(!self.tcx.map.is_inlined_def_id(def_id),
70-
"cannot hash HIR for inlined def-id {:?} => {:?}",
71-
def_id,
72-
self.tcx.item_path_str(def_id));
73-
7469
Some(self.incremental_hashes_map[dep_node])
7570
}
7671

0 commit comments

Comments
 (0)