Rollup merge of #43361 - michaelwoerister:remove-retrace-path, r=nikomatsakis

Remove unused DefPathTable::retrace_path()

`DefPathTable::retrace_path()` is not used anymore for a while now and removing it also removes the need to build the costly `DefPathTable::key_to_index` map for every upstream crate.

cc #43300

r? @eddyb
This commit is contained in:
Mark Simulacrum 2017-07-24 09:16:32 -06:00 committed by GitHub
commit 7e72b41d0c
6 changed files with 27 additions and 113 deletions

View file

@ -136,6 +136,10 @@ pub fn address_space(&self) -> DefIndexAddressSpace {
pub fn as_array_index(&self) -> usize {
(self.0 & !DEF_INDEX_HI_START.0) as usize
}
pub fn from_array_index(i: usize, address_space: DefIndexAddressSpace) -> DefIndex {
DefIndex::new(address_space.start() + i)
}
}
/// The start of the "high" range of DefIndexes.

View file

@ -18,7 +18,7 @@
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace,
CRATE_DEF_INDEX};
use ich::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::stable_hasher::StableHasher;
use serialize::{Encodable, Decodable, Encoder, Decoder};
@ -36,7 +36,6 @@
/// There is one DefPathTable for each crate.
pub struct DefPathTable {
index_to_key: [Vec<DefKey>; 2],
key_to_index: FxHashMap<DefKey, DefIndex>,
def_path_hashes: [Vec<DefPathHash>; 2],
}
@ -47,7 +46,6 @@ fn clone(&self) -> Self {
DefPathTable {
index_to_key: [self.index_to_key[0].clone(),
self.index_to_key[1].clone()],
key_to_index: self.key_to_index.clone(),
def_path_hashes: [self.def_path_hashes[0].clone(),
self.def_path_hashes[1].clone()],
}
@ -65,10 +63,9 @@ fn allocate(&mut self,
let index_to_key = &mut self.index_to_key[address_space.index()];
let index = DefIndex::new(index_to_key.len() + address_space.start());
debug!("DefPathTable::insert() - {:?} <-> {:?}", key, index);
index_to_key.push(key.clone());
index_to_key.push(key);
index
};
self.key_to_index.insert(key, index);
self.def_path_hashes[address_space.index()].push(def_path_hash);
debug_assert!(self.def_path_hashes[address_space.index()].len() ==
self.index_to_key[address_space.index()].len());
@ -87,47 +84,6 @@ pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
[index.as_array_index()]
}
#[inline(always)]
pub fn def_index_for_def_key(&self, key: &DefKey) -> Option<DefIndex> {
self.key_to_index.get(key).cloned()
}
#[inline(always)]
pub fn contains_key(&self, key: &DefKey) -> bool {
self.key_to_index.contains_key(key)
}
pub fn retrace_path(&self,
path_data: &[DisambiguatedDefPathData])
-> Option<DefIndex> {
let root_key = DefKey {
parent: None,
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::CrateRoot,
disambiguator: 0,
},
};
let root_index = self.key_to_index
.get(&root_key)
.expect("no root key?")
.clone();
debug!("retrace_path: root_index={:?}", root_index);
let mut index = root_index;
for data in path_data {
let key = DefKey { parent: Some(index), disambiguated_data: data.clone() };
debug!("retrace_path: key={:?}", key);
match self.key_to_index.get(&key) {
Some(&i) => index = i,
None => return None,
}
}
Some(index)
}
pub fn add_def_path_hashes_to(&self,
cnum: CrateNum,
out: &mut FxHashMap<DefPathHash, DefId>) {
@ -149,7 +105,7 @@ pub fn add_def_path_hashes_to(&self,
}
pub fn size(&self) -> usize {
self.key_to_index.len()
self.index_to_key.iter().map(|v| v.len()).sum()
}
}
@ -179,19 +135,8 @@ fn decode<D: Decoder>(d: &mut D) -> Result<DefPathTable, D::Error> {
let index_to_key = [index_to_key_lo, index_to_key_hi];
let def_path_hashes = [def_path_hashes_lo, def_path_hashes_hi];
let mut key_to_index = FxHashMap();
for space in &[DefIndexAddressSpace::Low, DefIndexAddressSpace::High] {
key_to_index.extend(index_to_key[space.index()]
.iter()
.enumerate()
.map(|(index, key)| (key.clone(),
DefIndex::new(index + space.start()))))
}
Ok(DefPathTable {
index_to_key,
key_to_index,
def_path_hashes,
})
}
@ -208,6 +153,7 @@ pub struct Definitions {
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
macro_def_scopes: FxHashMap<Mark, DefId>,
expansions: FxHashMap<DefIndex, Mark>,
keys_created: FxHashSet<DefKey>,
}
// Unfortunately we have to provide a manual impl of Clone because of the
@ -224,6 +170,7 @@ fn clone(&self) -> Self {
node_to_hir_id: self.node_to_hir_id.clone(),
macro_def_scopes: self.macro_def_scopes.clone(),
expansions: self.expansions.clone(),
keys_created: self.keys_created.clone(),
}
}
}
@ -448,7 +395,6 @@ pub fn new() -> Definitions {
Definitions {
table: DefPathTable {
index_to_key: [vec![], vec![]],
key_to_index: FxHashMap(),
def_path_hashes: [vec![], vec![]],
},
node_to_def_index: NodeMap(),
@ -456,6 +402,7 @@ pub fn new() -> Definitions {
node_to_hir_id: IndexVec::new(),
macro_def_scopes: FxHashMap(),
expansions: FxHashMap(),
keys_created: FxHashSet(),
}
}
@ -478,10 +425,6 @@ pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
self.table.def_path_hash(index)
}
pub fn def_index_for_def_key(&self, key: DefKey) -> Option<DefIndex> {
self.table.def_index_for_def_key(&key)
}
/// Returns the path from the crate root to `index`. The root
/// nodes are not included in the path (i.e., this will be an
/// empty vector for the crate root). For an inlined item, this
@ -583,9 +526,10 @@ pub fn create_def_with_parent(&mut self,
}
};
while self.table.contains_key(&key) {
while self.keys_created.contains(&key) {
key.disambiguated_data.disambiguator += 1;
}
self.keys_created.insert(key.clone());
let parent_hash = self.table.def_path_hash(parent);
let def_path_hash = key.compute_stable_hash(parent_hash);
@ -710,6 +654,8 @@ pub enum GlobalMetaDataKind {
$($variant),*
}
const GLOBAL_MD_ADDRESS_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;
impl GlobalMetaDataKind {
fn allocate_def_indices(definitions: &mut Definitions) {
$({
@ -718,7 +664,7 @@ fn allocate_def_indices(definitions: &mut Definitions) {
CRATE_DEF_INDEX,
ast::DUMMY_NODE_ID,
DefPathData::GlobalMetaData(instance.name()),
DefIndexAddressSpace::High,
GLOBAL_MD_ADDRESS_SPACE,
Mark::root()
);
@ -736,7 +682,14 @@ pub fn def_index(&self, def_path_table: &DefPathTable) -> DefIndex {
}
};
def_path_table.key_to_index[&def_key]
// These DefKeys are all right after the root,
// so a linear search is fine.
let index = def_path_table.index_to_key[GLOBAL_MD_ADDRESS_SPACE.index()]
.iter()
.position(|k| *k == def_key)
.unwrap();
DefIndex::from_array_index(index, GLOBAL_MD_ADDRESS_SPACE)
}
fn name(&self) -> Symbol {

View file

@ -17,7 +17,7 @@
use dep_graph::{DepGraph, DepNode, DepKind};
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex, DefIndexAddressSpace};
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndexAddressSpace};
use syntax::abi::Abi;
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
@ -377,10 +377,6 @@ pub fn def_path(&self, def_id: DefId) -> DefPath {
self.definitions.def_path(def_id.index)
}
pub fn def_index_for_def_key(&self, def_key: DefKey) -> Option<DefIndex> {
self.definitions.def_index_for_def_key(def_key)
}
pub fn local_def_id(&self, node: NodeId) -> DefId {
self.opt_local_def_id(node).unwrap_or_else(|| {
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",

View file

@ -25,8 +25,7 @@
use hir::def;
use hir::def_id::{CrateNum, DefId, DefIndex};
use hir::map as hir_map;
use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData,
DefPathTable};
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
use hir::svh::Svh;
use ich;
use middle::lang_items;
@ -269,10 +268,6 @@ pub trait CrateStore {
fn is_no_builtins(&self, cnum: CrateNum) -> bool;
// resolve
fn retrace_path(&self,
cnum: CrateNum,
path_data: &[DisambiguatedDefPathData])
-> Option<DefId>;
fn def_key(&self, def: DefId) -> DefKey;
fn def_path(&self, def: DefId) -> hir_map::DefPath;
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
@ -392,13 +387,6 @@ fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbol
fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }
// resolve
fn retrace_path(&self,
cnum: CrateNum,
path_data: &[DisambiguatedDefPathData])
-> Option<DefId> {
None
}
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
fn def_path(&self, def: DefId) -> hir_map::DefPath {
bug!("relative_def_path")

View file

@ -18,7 +18,7 @@
use hir::def::{Def, ExportMap};
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::map as hir_map;
use hir::map::{DisambiguatedDefPathData, DefPathHash};
use hir::map::DefPathHash;
use middle::free_region::FreeRegionMap;
use middle::lang_items;
use middle::resolve_lifetime;
@ -570,23 +570,6 @@ pub fn crate_disambiguator(self, cnum: CrateNum) -> Symbol {
}
}
pub fn retrace_path(self,
krate: CrateNum,
path_data: &[DisambiguatedDefPathData])
-> Option<DefId> {
debug!("retrace_path(path={:?}, krate={:?})", path_data, self.crate_name(krate));
if krate == LOCAL_CRATE {
self.hir
.definitions()
.def_path_table()
.retrace_path(path_data)
.map(|def_index| DefId { krate: krate, index: def_index })
} else {
self.sess.cstore.retrace_path(krate, path_data)
}
}
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
self.global_arenas.generics.alloc(generics)
}

View file

@ -22,7 +22,7 @@
use rustc::ty::{self, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData, DefPathHash};
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
use rustc::hir::map::blocks::FnLikeNode;
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
use rustc::util::nodemap::{NodeSet, DefIdMap};
@ -307,16 +307,6 @@ fn is_no_builtins(&self, cnum: CrateNum) -> bool {
self.get_crate_data(cnum).is_no_builtins(&self.dep_graph)
}
fn retrace_path(&self,
cnum: CrateNum,
path: &[DisambiguatedDefPathData])
-> Option<DefId> {
let cdata = self.get_crate_data(cnum);
cdata.def_path_table
.retrace_path(&path)
.map(|index| DefId { krate: cnum, index: index })
}
/// Returns the `DefKey` for a given `DefId`. This indicates the
/// parent `DefId` as well as some idea of what kind of data the
/// `DefId` refers to.