}
impl DefPathTable {
- pub fn new() -> Self {
- DefPathTable {
- index_to_key: [vec![], vec![]],
- key_to_index: FxHashMap(),
- def_path_hashes: [vec![], vec![]],
- }
- }
- pub fn allocate(&mut self,
- key: DefKey,
- def_path_hash: DefPathHash,
- address_space: DefIndexAddressSpace)
- -> DefIndex {
+ fn allocate(&mut self,
+ key: DefKey,
+ def_path_hash: DefPathHash,
+ address_space: DefIndexAddressSpace)
+ -> DefIndex {
let index = {
let index_to_key = &mut self.index_to_key[address_space.index()];
let index = DefIndex::new(index_to_key.len() + address_space.start());
}
impl DefKey {
- pub fn compute_stable_hash(&self, parent_hash: DefPathHash) -> DefPathHash {
+ fn compute_stable_hash(&self, parent_hash: DefPathHash) -> DefPathHash {
let mut hasher = StableHasher::new();
// We hash a 0u8 here to disambiguate between regular DefPath hashes,
DefPathHash(hasher.finish())
}
- pub fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> DefPathHash {
+ fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> DefPathHash {
let mut hasher = StableHasher::new();
// Disambiguate this from a regular DefPath hash,
// see compute_stable_hash() above.
/// Create new empty definition map.
pub fn new() -> Definitions {
Definitions {
- table: DefPathTable::new(),
+ table: DefPathTable {
+ index_to_key: [vec![], vec![]],
+ key_to_index: FxHashMap(),
+ def_path_hashes: [vec![], vec![]],
+ },
node_to_def_index: NodeMap(),
def_index_to_node: [vec![], vec![]],
node_to_hir_id: IndexVec::new(),
use locator::{self, CratePaths};
use schema::{CrateRoot, Tracked};
-use rustc::hir::def_id::{CrateNum, DefIndex, CRATE_DEF_INDEX};
+use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::svh::Svh;
use rustc::middle::cstore::DepKind;
use rustc::session::Session;
use rustc::util::common::record_time;
use rustc::util::nodemap::FxHashSet;
use rustc::middle::cstore::NativeLibrary;
-use rustc::hir::map::{Definitions, DefKey, DefPathData, DisambiguatedDefPathData, ITEM_LIKE_SPACE};
-use rustc::hir::map::definitions::DefPathTable;
+use rustc::hir::map::Definitions;
use std::cell::{RefCell, Cell};
use std::ops::Deref;
let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);
- let proc_macros = crate_root.macro_derive_registrar.map(|_| {
- self.load_derive_macros(&crate_root, dylib.clone().map(|p| p.0), span)
+ let def_path_table = record_time(&self.sess.perf_stats.decode_def_path_tables_time, || {
+ crate_root.def_path_table.decode(&metadata)
});
- let def_path_table = if let Some(ref proc_macros) = proc_macros {
- proc_macro_def_path_table(proc_macros)
- } else {
- record_time(&self.sess.perf_stats.decode_def_path_tables_time, || {
- crate_root.def_path_table.decode(&metadata)
- })
- };
let exported_symbols = crate_root.exported_symbols
.map(|x| x.decode(&metadata).collect());
def_path_table: Rc::new(def_path_table),
exported_symbols: exported_symbols,
trait_impls: trait_impls,
- proc_macros: proc_macros,
+ proc_macros: crate_root.macro_derive_registrar.map(|_| {
+ self.load_derive_macros(&crate_root, dylib.clone().map(|p| p.0), span)
+ }),
root: crate_root,
blob: metadata,
cnum_map: RefCell::new(cnum_map),
}
}
}
-
-fn proc_macro_def_path_table(proc_macros: &[(ast::Name, Rc<SyntaxExtension>)]) -> DefPathTable {
- let mut table = DefPathTable::new();
- let root = DefKey {
- parent: None,
- disambiguated_data: DisambiguatedDefPathData {
- data: DefPathData::CrateRoot,
- disambiguator: 0,
- },
- };
-
- let initial_hash = DefKey::root_parent_stable_hash("", "");
- let root_hash = root.compute_stable_hash(initial_hash);
- let root_id = table.allocate(root, root_hash, ITEM_LIKE_SPACE);
- let root_path_hash = table.def_path_hash(root_id);
- for proc_macro in proc_macros {
- let key = DefKey {
- parent: Some(CRATE_DEF_INDEX),
- disambiguated_data: DisambiguatedDefPathData {
- data: DefPathData::MacroDef(proc_macro.0),
- disambiguator: 0,
- },
- };
- let def_path_hash = key.compute_stable_hash(root_path_hash);
- table.allocate(key, def_path_hash, ITEM_LIKE_SPACE);
- }
- table
-}