Skip to content

Commit fa91eeb

Browse files
Remove unused DefTable::retrace_path().
1 parent 1edbc3d commit fa91eeb

File tree

6 files changed

+27
-113
lines changed

6 files changed

+27
-113
lines changed

src/librustc/hir/def_id.rs

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ impl DefIndex {
136136
pub fn as_array_index(&self) -> usize {
137137
(self.0 & !DEF_INDEX_HI_START.0) as usize
138138
}
139+
140+
pub fn from_array_index(i: usize, address_space: DefIndexAddressSpace) -> DefIndex {
141+
DefIndex::new(address_space.start() + i)
142+
}
139143
}
140144

141145
/// The start of the "high" range of DefIndexes.

src/librustc/hir/map/definitions.rs

+19-66
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hir;
1818
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace,
1919
CRATE_DEF_INDEX};
2020
use ich::Fingerprint;
21-
use rustc_data_structures::fx::FxHashMap;
21+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2222
use rustc_data_structures::indexed_vec::IndexVec;
2323
use rustc_data_structures::stable_hasher::StableHasher;
2424
use serialize::{Encodable, Decodable, Encoder, Decoder};
@@ -36,7 +36,6 @@ use util::nodemap::NodeMap;
3636
/// There is one DefPathTable for each crate.
3737
pub struct DefPathTable {
3838
index_to_key: [Vec<DefKey>; 2],
39-
key_to_index: FxHashMap<DefKey, DefIndex>,
4039
def_path_hashes: [Vec<DefPathHash>; 2],
4140
}
4241

@@ -47,7 +46,6 @@ impl Clone for DefPathTable {
4746
DefPathTable {
4847
index_to_key: [self.index_to_key[0].clone(),
4948
self.index_to_key[1].clone()],
50-
key_to_index: self.key_to_index.clone(),
5149
def_path_hashes: [self.def_path_hashes[0].clone(),
5250
self.def_path_hashes[1].clone()],
5351
}
@@ -65,10 +63,9 @@ impl DefPathTable {
6563
let index_to_key = &mut self.index_to_key[address_space.index()];
6664
let index = DefIndex::new(index_to_key.len() + address_space.start());
6765
debug!("DefPathTable::insert() - {:?} <-> {:?}", key, index);
68-
index_to_key.push(key.clone());
66+
index_to_key.push(key);
6967
index
7068
};
71-
self.key_to_index.insert(key, index);
7269
self.def_path_hashes[address_space.index()].push(def_path_hash);
7370
debug_assert!(self.def_path_hashes[address_space.index()].len() ==
7471
self.index_to_key[address_space.index()].len());
@@ -87,47 +84,6 @@ impl DefPathTable {
8784
[index.as_array_index()]
8885
}
8986

90-
#[inline(always)]
91-
pub fn def_index_for_def_key(&self, key: &DefKey) -> Option<DefIndex> {
92-
self.key_to_index.get(key).cloned()
93-
}
94-
95-
#[inline(always)]
96-
pub fn contains_key(&self, key: &DefKey) -> bool {
97-
self.key_to_index.contains_key(key)
98-
}
99-
100-
pub fn retrace_path(&self,
101-
path_data: &[DisambiguatedDefPathData])
102-
-> Option<DefIndex> {
103-
let root_key = DefKey {
104-
parent: None,
105-
disambiguated_data: DisambiguatedDefPathData {
106-
data: DefPathData::CrateRoot,
107-
disambiguator: 0,
108-
},
109-
};
110-
111-
let root_index = self.key_to_index
112-
.get(&root_key)
113-
.expect("no root key?")
114-
.clone();
115-
116-
debug!("retrace_path: root_index={:?}", root_index);
117-
118-
let mut index = root_index;
119-
for data in path_data {
120-
let key = DefKey { parent: Some(index), disambiguated_data: data.clone() };
121-
debug!("retrace_path: key={:?}", key);
122-
match self.key_to_index.get(&key) {
123-
Some(&i) => index = i,
124-
None => return None,
125-
}
126-
}
127-
128-
Some(index)
129-
}
130-
13187
pub fn add_def_path_hashes_to(&self,
13288
cnum: CrateNum,
13389
out: &mut FxHashMap<DefPathHash, DefId>) {
@@ -149,7 +105,7 @@ impl DefPathTable {
149105
}
150106

151107
pub fn size(&self) -> usize {
152-
self.key_to_index.len()
108+
self.index_to_key.iter().map(|v| v.len()).sum()
153109
}
154110
}
155111

@@ -179,19 +135,8 @@ impl Decodable for DefPathTable {
179135
let index_to_key = [index_to_key_lo, index_to_key_hi];
180136
let def_path_hashes = [def_path_hashes_lo, def_path_hashes_hi];
181137

182-
let mut key_to_index = FxHashMap();
183-
184-
for space in &[DefIndexAddressSpace::Low, DefIndexAddressSpace::High] {
185-
key_to_index.extend(index_to_key[space.index()]
186-
.iter()
187-
.enumerate()
188-
.map(|(index, key)| (key.clone(),
189-
DefIndex::new(index + space.start()))))
190-
}
191-
192138
Ok(DefPathTable {
193139
index_to_key,
194-
key_to_index,
195140
def_path_hashes,
196141
})
197142
}
@@ -208,6 +153,7 @@ pub struct Definitions {
208153
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
209154
macro_def_scopes: FxHashMap<Mark, DefId>,
210155
expansions: FxHashMap<DefIndex, Mark>,
156+
keys_created: FxHashSet<DefKey>,
211157
}
212158

213159
// Unfortunately we have to provide a manual impl of Clone because of the
@@ -224,6 +170,7 @@ impl Clone for Definitions {
224170
node_to_hir_id: self.node_to_hir_id.clone(),
225171
macro_def_scopes: self.macro_def_scopes.clone(),
226172
expansions: self.expansions.clone(),
173+
keys_created: self.keys_created.clone(),
227174
}
228175
}
229176
}
@@ -448,14 +395,14 @@ impl Definitions {
448395
Definitions {
449396
table: DefPathTable {
450397
index_to_key: [vec![], vec![]],
451-
key_to_index: FxHashMap(),
452398
def_path_hashes: [vec![], vec![]],
453399
},
454400
node_to_def_index: NodeMap(),
455401
def_index_to_node: [vec![], vec![]],
456402
node_to_hir_id: IndexVec::new(),
457403
macro_def_scopes: FxHashMap(),
458404
expansions: FxHashMap(),
405+
keys_created: FxHashSet(),
459406
}
460407
}
461408

@@ -478,10 +425,6 @@ impl Definitions {
478425
self.table.def_path_hash(index)
479426
}
480427

481-
pub fn def_index_for_def_key(&self, key: DefKey) -> Option<DefIndex> {
482-
self.table.def_index_for_def_key(&key)
483-
}
484-
485428
/// Returns the path from the crate root to `index`. The root
486429
/// nodes are not included in the path (i.e., this will be an
487430
/// empty vector for the crate root). For an inlined item, this
@@ -583,9 +526,10 @@ impl Definitions {
583526
}
584527
};
585528

586-
while self.table.contains_key(&key) {
529+
while self.keys_created.contains(&key) {
587530
key.disambiguated_data.disambiguator += 1;
588531
}
532+
self.keys_created.insert(key.clone());
589533

590534
let parent_hash = self.table.def_path_hash(parent);
591535
let def_path_hash = key.compute_stable_hash(parent_hash);
@@ -710,6 +654,8 @@ macro_rules! define_global_metadata_kind {
710654
$($variant),*
711655
}
712656

657+
const GLOBAL_MD_ADDRESS_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;
658+
713659
impl GlobalMetaDataKind {
714660
fn allocate_def_indices(definitions: &mut Definitions) {
715661
$({
@@ -718,7 +664,7 @@ macro_rules! define_global_metadata_kind {
718664
CRATE_DEF_INDEX,
719665
ast::DUMMY_NODE_ID,
720666
DefPathData::GlobalMetaData(instance.name()),
721-
DefIndexAddressSpace::High,
667+
GLOBAL_MD_ADDRESS_SPACE,
722668
Mark::root()
723669
);
724670

@@ -736,7 +682,14 @@ macro_rules! define_global_metadata_kind {
736682
}
737683
};
738684

739-
def_path_table.key_to_index[&def_key]
685+
// These DefKeys are all right after the root,
686+
// so a linear search is fine.
687+
let index = def_path_table.index_to_key[GLOBAL_MD_ADDRESS_SPACE.index()]
688+
.iter()
689+
.position(|k| *k == def_key)
690+
.unwrap();
691+
692+
DefIndex::from_array_index(index, GLOBAL_MD_ADDRESS_SPACE)
740693
}
741694

742695
fn name(&self) -> Symbol {

src/librustc/hir/map/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData,
1717

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

20-
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex, DefIndexAddressSpace};
20+
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndexAddressSpace};
2121

2222
use syntax::abi::Abi;
2323
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
@@ -377,10 +377,6 @@ impl<'hir> Map<'hir> {
377377
self.definitions.def_path(def_id.index)
378378
}
379379

380-
pub fn def_index_for_def_key(&self, def_key: DefKey) -> Option<DefIndex> {
381-
self.definitions.def_index_for_def_key(def_key)
382-
}
383-
384380
pub fn local_def_id(&self, node: NodeId) -> DefId {
385381
self.opt_local_def_id(node).unwrap_or_else(|| {
386382
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",

src/librustc/middle/cstore.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
use hir::def;
2626
use hir::def_id::{CrateNum, DefId, DefIndex};
2727
use hir::map as hir_map;
28-
use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData,
29-
DefPathTable};
28+
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
3029
use hir::svh::Svh;
3130
use ich;
3231
use middle::lang_items;
@@ -269,10 +268,6 @@ pub trait CrateStore {
269268
fn is_no_builtins(&self, cnum: CrateNum) -> bool;
270269

271270
// resolve
272-
fn retrace_path(&self,
273-
cnum: CrateNum,
274-
path_data: &[DisambiguatedDefPathData])
275-
-> Option<DefId>;
276271
fn def_key(&self, def: DefId) -> DefKey;
277272
fn def_path(&self, def: DefId) -> hir_map::DefPath;
278273
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
@@ -392,13 +387,6 @@ impl CrateStore for DummyCrateStore {
392387
fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }
393388

394389
// resolve
395-
fn retrace_path(&self,
396-
cnum: CrateNum,
397-
path_data: &[DisambiguatedDefPathData])
398-
-> Option<DefId> {
399-
None
400-
}
401-
402390
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
403391
fn def_path(&self, def: DefId) -> hir_map::DefPath {
404392
bug!("relative_def_path")

src/librustc/ty/context.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hir::TraitMap;
1818
use hir::def::{Def, ExportMap};
1919
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
2020
use hir::map as hir_map;
21-
use hir::map::{DisambiguatedDefPathData, DefPathHash};
21+
use hir::map::DefPathHash;
2222
use middle::free_region::FreeRegionMap;
2323
use middle::lang_items;
2424
use middle::resolve_lifetime;
@@ -570,23 +570,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
570570
}
571571
}
572572

573-
pub fn retrace_path(self,
574-
krate: CrateNum,
575-
path_data: &[DisambiguatedDefPathData])
576-
-> Option<DefId> {
577-
debug!("retrace_path(path={:?}, krate={:?})", path_data, self.crate_name(krate));
578-
579-
if krate == LOCAL_CRATE {
580-
self.hir
581-
.definitions()
582-
.def_path_table()
583-
.retrace_path(path_data)
584-
.map(|def_index| DefId { krate: krate, index: def_index })
585-
} else {
586-
self.sess.cstore.retrace_path(krate, path_data)
587-
}
588-
}
589-
590573
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
591574
self.global_arenas.generics.alloc(generics)
592575
}

src/librustc_metadata/cstore_impl.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::session::Session;
2222
use rustc::ty::{self, TyCtxt};
2323
use rustc::ty::maps::Providers;
2424
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
25-
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData, DefPathHash};
25+
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
2626
use rustc::hir::map::blocks::FnLikeNode;
2727
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
2828
use rustc::util::nodemap::{NodeSet, DefIdMap};
@@ -307,16 +307,6 @@ impl CrateStore for cstore::CStore {
307307
self.get_crate_data(cnum).is_no_builtins(&self.dep_graph)
308308
}
309309

310-
fn retrace_path(&self,
311-
cnum: CrateNum,
312-
path: &[DisambiguatedDefPathData])
313-
-> Option<DefId> {
314-
let cdata = self.get_crate_data(cnum);
315-
cdata.def_path_table
316-
.retrace_path(&path)
317-
.map(|index| DefId { krate: cnum, index: index })
318-
}
319-
320310
/// Returns the `DefKey` for a given `DefId`. This indicates the
321311
/// parent `DefId` as well as some idea of what kind of data the
322312
/// `DefId` refers to.

0 commit comments

Comments
 (0)