// they are treated specially by the `def_path` function.
/// The crate root (marker)
CrateRoot,
-
+
// Catch-all for random DefId things like DUMMY_NODE_ID
Misc,
}
}
+ pub fn def_path_table(&self) -> &DefPathTable {
+ &self.table
+ }
+
/// Get the number of definitions.
pub fn len(&self) -> usize {
self.def_index_to_node.len()
use hir::print as pprust;
use arena::TypedArena;
-use std::cell::RefCell;
+use std::cell::{RefCell, Ref};
use std::io;
use std::mem;
self.definitions.borrow().len()
}
+ pub fn definitions(&self) -> Ref<Definitions> {
+ self.definitions.borrow()
+ }
+
pub fn def_key(&self, def_id: DefId) -> DefKey {
assert!(def_id.is_local());
self.definitions.borrow().def_key(def_id.index)
let mut cmeta = cstore::CrateMetadata {
name: name,
extern_crate: Cell::new(None),
- key_map: metadata.load_key_map(crate_root.index),
+ def_path_table: crate_root.def_path_table.decode(&metadata),
proc_macros: crate_root.macro_derive_registrar.map(|_| {
self.load_derive_macros(&crate_root, dylib.clone().map(|p| p.0), span)
}),
use rustc::dep_graph::DepGraph;
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefIndex, DefId};
-use rustc::hir::map::DefKey;
+use rustc::hir::map::definitions::DefPathTable;
use rustc::hir::svh::Svh;
use rustc::middle::cstore::{DepKind, ExternCrate};
use rustc_back::PanicStrategy;
/// hashmap, which gives the reverse mapping. This allows us to
/// quickly retrace a `DefPath`, which is needed for incremental
/// compilation support.
- pub key_map: FxHashMap<DefKey, DefIndex>,
+ pub def_path_table: DefPathTable,
pub dep_kind: Cell<DepKind>,
pub source: CrateSource,
def: DefKey)
-> Option<DefIndex> {
let cdata = self.get_crate_data(cnum);
- cdata.key_map.get(&def).cloned()
+ cdata.def_path_table.def_index_for_def_key(&def)
}
/// Returns the `DefKey` for a given `DefId`. This indicates the
use astencode::decode_inlined_item;
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
-use index::Index;
use schema::*;
use rustc::hir::map as hir_map;
use rustc::hir::map::{DefKey, DefPathData};
-use rustc::util::nodemap::FxHashMap;
use rustc::hir;
use rustc::hir::intravisit::IdRange;
Lazy::with_position(pos).decode(self)
}
- /// Go through each item in the metadata and create a map from that
- /// item's def-key to the item's DefIndex.
- pub fn load_key_map(&self, index: LazySeq<Index>) -> FxHashMap<DefKey, DefIndex> {
- index.iter_enumerated(self.raw_bytes())
- .map(|(index, item)| (item.decode(self).def_key.decode(self), index))
- .collect()
- }
-
pub fn list_crate_metadata(&self, out: &mut io::Write) -> io::Result<()> {
write!(out, "=External Dependencies=\n")?;
let root = self.get_root();
}
}
- fn item_name(&self, item: &Entry<'tcx>) -> ast::Name {
- item.def_key
- .decode(self)
+ fn item_name(&self, item_index: DefIndex) -> ast::Name {
+ self.def_key(item_index)
.disambiguated_data
.data
.get_opt_name()
(ty::VariantDef {
did: self.local_def_id(data.struct_ctor.unwrap_or(index)),
- name: self.item_name(item),
+ name: self.item_name(index),
fields: item.children.decode(self).map(|index| {
let f = self.entry(index);
ty::FieldDef {
did: self.local_def_id(index),
- name: self.item_name(&f),
+ name: self.item_name(index),
vis: f.visibility
}
}).collect(),
if let Some(def) = self.get_def(child_index) {
callback(def::Export {
def: def,
- name: self.item_name(&self.entry(child_index)),
+ name: self.item_name(child_index),
});
}
}
_ => {}
}
- let def_key = child.def_key.decode(self);
+ let def_key = self.def_key(child_index);
if let (Some(def), Some(name)) =
(self.get_def(child_index), def_key.disambiguated_data.data.get_opt_name()) {
callback(def::Export {
pub fn get_associated_item(&self, id: DefIndex) -> Option<ty::AssociatedItem> {
let item = self.entry(id);
let parent_and_name = || {
- let def_key = item.def_key.decode(self);
+ let def_key = self.def_key(id);
(self.local_def_id(def_key.parent.unwrap()),
def_key.disambiguated_data.data.get_opt_name().unwrap())
};
// we assume that someone passing in a tuple struct ctor is actually wanting to
// look at the definition
let mut item = self.entry(node_id);
- let def_key = item.def_key.decode(self);
+ let def_key = self.def_key(node_id);
if def_key.disambiguated_data.data == DefPathData::StructCtor {
item = self.entry(def_key.parent.unwrap());
}
self.entry(id)
.children
.decode(self)
- .map(|index| self.item_name(&self.entry(index)))
+ .map(|index| self.item_name(index))
.collect()
}
}
pub fn get_trait_of_item(&self, id: DefIndex) -> Option<DefId> {
- self.entry(id).def_key.decode(self).parent.and_then(|parent_index| {
+ self.def_key(id).parent.and_then(|parent_index| {
match self.entry(parent_index).kind {
EntryKind::Trait(_) => Some(self.local_def_id(parent_index)),
_ => None,
pub fn get_macro(&self, id: DefIndex) -> (ast::Name, MacroDef) {
let entry = self.entry(id);
match entry.kind {
- EntryKind::MacroDef(macro_def) => (self.item_name(&entry), macro_def.decode(self)),
+ EntryKind::MacroDef(macro_def) => (self.item_name(id), macro_def.decode(self)),
_ => bug!(),
}
}
}
}
- pub fn def_key(&self, id: DefIndex) -> hir_map::DefKey {
- debug!("def_key: id={:?}", id);
- if self.is_proc_macro(id) {
- let name = self.proc_macros.as_ref().unwrap()[id.as_usize() - 1].0;
- hir_map::DefKey {
- parent: Some(CRATE_DEF_INDEX),
- disambiguated_data: hir_map::DisambiguatedDefPathData {
- data: hir_map::DefPathData::MacroDef(name.as_str()),
- disambiguator: 0,
- },
- }
- } else {
- self.entry(id).def_key.decode(self)
- }
+ pub fn def_key(&self, index: DefIndex) -> DefKey {
+ self.def_path_table.def_key(index)
}
// Returns the path leading to the thing with this `id`. Note that
use rustc::middle::cstore::{LinkagePreference, NativeLibrary};
use rustc::hir::def;
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId};
+use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::dependency_format::Linkage;
use rustc::middle::lang_items;
use rustc::mir;
Ok(())
}
- /// For every DefId that we create a metadata item for, we include a
- /// serialized copy of its DefKey, which allows us to recreate a path.
- fn encode_def_key(&mut self, def_id: DefId) -> Lazy<hir::map::DefKey> {
- let tcx = self.tcx;
- self.lazy(&tcx.map.def_key(def_id))
- }
-
fn encode_item_variances(&mut self, def_id: DefId) -> LazySeq<ty::Variance> {
let tcx = self.tcx;
self.lazy_seq(tcx.item_variances(def_id).iter().cloned())
kind: EntryKind::Variant(self.lazy(&data)),
visibility: enum_vis.simplify(),
span: self.lazy(&tcx.def_span(def_id)),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&tcx.get_attrs(def_id)),
children: self.lazy_seq(variant.fields.iter().map(|f| {
assert!(f.did.is_local());
kind: EntryKind::Mod(self.lazy(&data)),
visibility: vis.simplify(),
span: self.lazy(&md.inner),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(attrs),
children: self.lazy_seq(md.item_ids.iter().map(|item_id| {
tcx.map.local_def_id(item_id.id).index
kind: EntryKind::Field,
visibility: field.vis.simplify(),
span: self.lazy(&tcx.def_span(def_id)),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&variant_data.fields()[field_index].attrs),
children: LazySeq::empty(),
stability: self.encode_stability(def_id),
kind: EntryKind::Struct(self.lazy(&data)),
visibility: struct_vis.simplify(),
span: self.lazy(&tcx.def_span(def_id)),
- def_key: self.encode_def_key(def_id),
attributes: LazySeq::empty(),
children: LazySeq::empty(),
stability: self.encode_stability(def_id),
kind: kind,
visibility: trait_item.vis.simplify(),
span: self.lazy(&ast_item.span),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&ast_item.attrs),
children: LazySeq::empty(),
stability: self.encode_stability(def_id),
kind: kind,
visibility: impl_item.vis.simplify(),
span: self.lazy(&ast_item.span),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&ast_item.attrs),
children: LazySeq::empty(),
stability: self.encode_stability(def_id),
kind: kind,
visibility: item.vis.simplify(),
span: self.lazy(&item.span),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&item.attrs),
children: match item.node {
hir::ItemForeignMod(ref fm) => {
/// Serialize the text of exported macros
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) -> Entry<'tcx> {
- let def_id = self.tcx.map.local_def_id(macro_def.id);
Entry {
kind: EntryKind::MacroDef(self.lazy(&MacroDef {
body: ::syntax::print::pprust::tts_to_string(¯o_def.body)
})),
visibility: ty::Visibility::Public,
span: self.lazy(¯o_def.span),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(¯o_def.attrs),
children: LazySeq::empty(),
kind: kind,
visibility: nitem.vis.simplify(),
span: self.lazy(&nitem.span),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&nitem.attrs),
children: LazySeq::empty(),
stability: self.encode_stability(def_id),
kind: EntryKind::Type,
visibility: ty::Visibility::Public,
span: self.lazy(&tcx.def_span(def_id)),
- def_key: self.encode_def_key(def_id),
attributes: LazySeq::empty(),
children: LazySeq::empty(),
stability: None,
kind: EntryKind::Closure(self.lazy(&data)),
visibility: ty::Visibility::Public,
span: self.lazy(&tcx.def_span(def_id)),
- def_key: self.encode_def_key(def_id),
attributes: self.encode_attributes(&tcx.get_attrs(def_id)),
children: LazySeq::empty(),
stability: None,
})
.map(|filemap| &**filemap))
}
+
+ fn encode_def_path_table(&mut self) -> Lazy<DefPathTable> {
+ let definitions = self.tcx.map.definitions();
+ self.lazy(definitions.def_path_table())
+ }
}
struct ImplVisitor<'a, 'tcx: 'a> {
let codemap = self.encode_codemap();
let codemap_bytes = self.position() - i;
+ // Encode DefPathTable
+ i = self.position();
+ let def_path_table = self.encode_def_path_table();
+ let def_path_table_bytes = self.position() - i;
+
// Encode the def IDs of impls, for coherence checking.
i = self.position();
let impls = self.encode_impls();
lang_items_missing: lang_items_missing,
native_libraries: native_libraries,
codemap: codemap,
+ def_path_table: def_path_table,
impls: impls,
exported_symbols: exported_symbols,
index: index,
println!(" codemap bytes: {}", codemap_bytes);
println!(" impl bytes: {}", impl_bytes);
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
+ println!(" def-path table bytes: {}", def_path_table_bytes);
println!(" item bytes: {}", item_bytes);
println!(" index bytes: {}", index_bytes);
println!(" zero bytes: {}", zero_bytes);
pub lang_items_missing: LazySeq<lang_items::LangItem>,
pub native_libraries: LazySeq<NativeLibrary>,
pub codemap: LazySeq<syntax_pos::FileMap>,
+ pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
pub impls: LazySeq<TraitImpls>,
pub exported_symbols: LazySeq<DefIndex>,
pub index: LazySeq<index::Index>,
pub kind: EntryKind<'tcx>,
pub visibility: ty::Visibility,
pub span: Lazy<Span>,
- pub def_key: Lazy<hir::map::DefKey>,
pub attributes: LazySeq<ast::Attribute>,
pub children: LazySeq<DefIndex>,
pub stability: Option<Lazy<attr::Stability>>,