Skip to content

Commit aed0cdb

Browse files
definitions: Don't allocate DefIds for inlined HIR
1 parent 8e34a8e commit aed0cdb

File tree

7 files changed

+6
-109
lines changed

7 files changed

+6
-109
lines changed

src/librustc/hir/map/collector.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use super::*;
1212

1313
use hir::intravisit::{Visitor, NestedVisitorMap};
14-
use hir::def_id::DefId;
1514
use middle::cstore::InlinedItem;
1615
use std::iter::repeat;
1716
use syntax::ast::{NodeId, CRATE_NODE_ID};
@@ -47,8 +46,6 @@ impl<'ast> NodeCollector<'ast> {
4746
pub fn extend(krate: &'ast Crate,
4847
parent: &'ast InlinedItem,
4948
parent_node: NodeId,
50-
parent_def_path: DefPath,
51-
parent_def_id: DefId,
5249
map: Vec<MapEntry<'ast>>)
5350
-> NodeCollector<'ast> {
5451
let mut collector = NodeCollector {
@@ -58,7 +55,6 @@ impl<'ast> NodeCollector<'ast> {
5855
ignore_nested_items: true
5956
};
6057

61-
assert_eq!(parent_def_path.krate, parent_def_id.krate);
6258
collector.insert_entry(parent_node, RootInlinedParent(parent));
6359

6460
collector

src/librustc/hir/map/def_collector.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hir::map::definitions::*;
1212

1313
use hir;
1414
use hir::intravisit::{self, Visitor, NestedVisitorMap};
15-
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
15+
use hir::def_id::{CRATE_DEF_INDEX, DefIndex};
1616

1717
use middle::cstore::InlinedItem;
1818

@@ -47,25 +47,6 @@ impl<'a> DefCollector<'a> {
4747
}
4848
}
4949

50-
pub fn extend(parent_node: NodeId,
51-
parent_def_path: DefPath,
52-
parent_def_id: DefId,
53-
definitions: &'a mut Definitions)
54-
-> Self {
55-
let mut collector = DefCollector::new(definitions);
56-
57-
assert_eq!(parent_def_path.krate, parent_def_id.krate);
58-
let root_path = Box::new(InlinedRootPath {
59-
data: parent_def_path.data,
60-
def_id: parent_def_id,
61-
});
62-
63-
let def = collector.create_def(parent_node, DefPathData::InlinedRoot(root_path));
64-
collector.parent_def = Some(def);
65-
66-
collector
67-
}
68-
6950
pub fn collect_root(&mut self) {
7051
let root = self.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
7152
assert_eq!(root, CRATE_DEF_INDEX);

src/librustc/hir/map/definitions.rs

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ impl DefPathTable {
5757
pub fn contains_key(&self, key: &DefKey) -> bool {
5858
self.key_to_index.contains_key(key)
5959
}
60-
61-
/// Returns the path from the crate root to `index`. The root
62-
/// nodes are not included in the path (i.e., this will be an
63-
/// empty vector for the crate root). For an inlined item, this
64-
/// will be the path of the item in the external crate (but the
65-
/// path will begin with the path to the external crate).
66-
pub fn def_path(&self, index: DefIndex) -> DefPath {
67-
DefPath::make(LOCAL_CRATE, index, |p| self.def_key(p))
68-
}
6960
}
7061

7162

@@ -136,12 +127,11 @@ impl DefPath {
136127
self.krate == LOCAL_CRATE
137128
}
138129

139-
pub fn make<FN>(start_krate: CrateNum,
130+
pub fn make<FN>(krate: CrateNum,
140131
start_index: DefIndex,
141132
mut get_key: FN) -> DefPath
142133
where FN: FnMut(DefIndex) -> DefKey
143134
{
144-
let mut krate = start_krate;
145135
let mut data = vec![];
146136
let mut index = Some(start_index);
147137
loop {
@@ -154,13 +144,6 @@ impl DefPath {
154144
assert!(key.parent.is_none());
155145
break;
156146
}
157-
DefPathData::InlinedRoot(ref p) => {
158-
assert!(key.parent.is_none());
159-
assert!(!p.def_id.is_local());
160-
data.extend(p.data.iter().cloned().rev());
161-
krate = p.def_id.krate;
162-
break;
163-
}
164147
_ => {
165148
data.push(key.disambiguated_data);
166149
index = key.parent;
@@ -203,41 +186,14 @@ impl DefPath {
203186
}
204187
}
205188

206-
/// Root of an inlined item. We track the `DefPath` of the item within
207-
/// the original crate but also its def-id. This is kind of an
208-
/// augmented version of a `DefPath` that includes a `DefId`. This is
209-
/// all sort of ugly but the hope is that inlined items will be going
210-
/// away soon anyway.
211-
///
212-
/// Some of the constraints that led to the current approach:
213-
///
214-
/// - I don't want to have a `DefId` in the main `DefPath` because
215-
/// that gets serialized for incr. comp., and when reloaded the
216-
/// `DefId` is no longer valid. I'd rather maintain the invariant
217-
/// that every `DefId` is valid, and a potentially outdated `DefId` is
218-
/// represented as a `DefPath`.
219-
/// - (We don't serialize def-paths from inlined items, so it's ok to have one here.)
220-
/// - We need to be able to extract the def-id from inline items to
221-
/// make the symbol name. In theory we could retrace it from the
222-
/// data, but the metadata doesn't have the required indices, and I
223-
/// don't want to write the code to create one just for this.
224-
/// - It may be that we don't actually need `data` at all. We'll have
225-
/// to see about that.
226-
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
227-
pub struct InlinedRootPath {
228-
pub data: Vec<DisambiguatedDefPathData>,
229-
pub def_id: DefId,
230-
}
231189

232190
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
233191
pub enum DefPathData {
234192
// Root: these should only be used for the root nodes, because
235193
// they are treated specially by the `def_path` function.
236194
/// The crate root (marker)
237195
CrateRoot,
238-
/// An inlined root
239-
InlinedRoot(Box<InlinedRootPath>),
240-
196+
241197
// Catch-all for random DefId things like DUMMY_NODE_ID
242198
Misc,
243199

@@ -345,10 +301,7 @@ impl Definitions {
345301
data,
346302
self.table.def_key(self.node_to_def_index[&node_id]));
347303

348-
assert!(parent.is_some() ^ match data {
349-
DefPathData::CrateRoot | DefPathData::InlinedRoot(_) => true,
350-
_ => false,
351-
});
304+
assert!(parent.is_some() ^ (data == DefPathData::CrateRoot));
352305

353306
// Find a unique DefKey. This basically means incrementing the disambiguator
354307
// until we get no match.
@@ -393,7 +346,6 @@ impl DefPathData {
393346

394347
Impl |
395348
CrateRoot |
396-
InlinedRoot(_) |
397349
Misc |
398350
ClosureExpr |
399351
StructCtor |
@@ -420,9 +372,6 @@ impl DefPathData {
420372
// note that this does not show up in user printouts
421373
CrateRoot => "{{root}}",
422374

423-
// note that this does not show up in user printouts
424-
InlinedRoot(_) => "{{inlined-root}}",
425-
426375
Impl => "{{impl}}",
427376
Misc => "{{?}}",
428377
ClosureExpr => "{{closure}}",

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use self::MapEntry::*;
1313
use self::collector::NodeCollector;
1414
pub use self::def_collector::{DefCollector, MacroInvocationData};
1515
pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData,
16-
DisambiguatedDefPathData, InlinedRootPath};
16+
DisambiguatedDefPathData};
1717

1818
use dep_graph::{DepGraph, DepNode};
1919

@@ -945,27 +945,16 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest,
945945
/// Used for items loaded from external crate that are being inlined into this
946946
/// crate.
947947
pub fn map_decoded_item<'ast>(map: &Map<'ast>,
948-
parent_def_path: DefPath,
949-
parent_def_id: DefId,
950948
ii: InlinedItem,
951949
ii_parent_id: NodeId)
952950
-> &'ast InlinedItem {
953951
let _ignore = map.forest.dep_graph.in_ignore();
954952

955953
let ii = map.forest.inlined_items.alloc(ii);
956954

957-
let defs = &mut *map.definitions.borrow_mut();
958-
let mut def_collector = DefCollector::extend(ii_parent_id,
959-
parent_def_path.clone(),
960-
parent_def_id,
961-
defs);
962-
def_collector.walk_item(ii, map.krate());
963-
964955
let mut collector = NodeCollector::extend(map.krate(),
965956
ii,
966957
ii_parent_id,
967-
parent_def_path,
968-
parent_def_id,
969958
mem::replace(&mut *map.map.borrow_mut(), vec![]));
970959
ii.visit(&mut collector);
971960
*map.map.borrow_mut() = collector.map;

src/librustc/ty/item_path.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
160160
self.push_krate_path(buffer, def_id.krate);
161161
}
162162

163-
DefPathData::InlinedRoot(ref root_path) => {
164-
assert!(key.parent.is_none());
165-
self.push_item_path(buffer, root_path.def_id);
166-
}
167-
168163
DefPathData::Impl => {
169164
self.push_impl_path(buffer, def_id);
170165
}

src/librustc_metadata/astencode.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for SideTableEncodingIdVisitor<'a, 'b, 'tcx> {
102102
/// ast-map.
103103
pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
104104
tcx: TyCtxt<'a, 'tcx, 'tcx>,
105-
parent_def_path: ast_map::DefPath,
106-
parent_did: DefId,
107105
ast: Ast<'tcx>,
108106
orig_did: DefId)
109107
-> &'tcx InlinedItem {
@@ -120,17 +118,9 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
120118
let ii = ast.item.decode((cdata, tcx, id_ranges));
121119
let item_node_id = tcx.sess.next_node_id();
122120
let ii = ast_map::map_decoded_item(&tcx.map,
123-
parent_def_path,
124-
parent_did,
125121
ii,
126122
item_node_id);
127123

128-
let inlined_did = tcx.map.local_def_id(item_node_id);
129-
let ty = tcx.item_type(orig_did);
130-
let generics = tcx.item_generics(orig_did);
131-
tcx.item_types.borrow_mut().insert(inlined_did, ty);
132-
tcx.generics.borrow_mut().insert(inlined_did, generics);
133-
134124
for (id, entry) in ast.side_tables.decode((cdata, tcx, id_ranges)) {
135125
match entry {
136126
TableEntry::TypeRelativeDef(def) => {

src/librustc_metadata/decoder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,9 @@ impl<'a, 'tcx> CrateMetadata {
839839
if self.is_proc_macro(id) { return None; }
840840
let item_doc = self.entry(id);
841841
let item_did = self.local_def_id(id);
842-
let parent_def_id = self.local_def_id(self.def_key(id).parent.unwrap());
843-
let mut parent_def_path = self.def_path(id).unwrap();
844-
parent_def_path.data.pop();
845842
item_doc.ast.map(|ast| {
846843
let ast = ast.decode(self);
847-
decode_inlined_item(self, tcx, parent_def_path, parent_def_id, ast, item_did)
844+
decode_inlined_item(self, tcx, ast, item_did)
848845
})
849846
}
850847

0 commit comments

Comments
 (0)