rustc_metadata: move opt_item_name to TyCtxt::item_name.
This commit is contained in:
parent
dc26a23301
commit
dadbaa48ac
7 changed files with 51 additions and 55 deletions
|
@ -14,7 +14,7 @@ use rustc_data_structures::fnv::FnvHashMap;
|
|||
use std::fmt::Write;
|
||||
use std::hash::{Hash, Hasher, SipHasher};
|
||||
use syntax::{ast, visit};
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::parse::token::{self, InternedString};
|
||||
use ty::TyCtxt;
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
|
@ -326,6 +326,30 @@ impl Definitions {
|
|||
}
|
||||
|
||||
impl DefPathData {
|
||||
pub fn get_opt_name(&self) -> Option<ast::Name> {
|
||||
use self::DefPathData::*;
|
||||
match *self {
|
||||
TypeNs(ref name) |
|
||||
ValueNs(ref name) |
|
||||
Module(ref name) |
|
||||
MacroDef(ref name) |
|
||||
TypeParam(ref name) |
|
||||
LifetimeDef(ref name) |
|
||||
EnumVariant(ref name) |
|
||||
Binding(ref name) |
|
||||
Field(ref name) => Some(token::intern(name)),
|
||||
|
||||
Impl |
|
||||
CrateRoot |
|
||||
InlinedRoot(_) |
|
||||
Misc |
|
||||
ClosureExpr |
|
||||
StructCtor |
|
||||
Initializer |
|
||||
ImplTrait => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_interned_str(&self) -> InternedString {
|
||||
use self::DefPathData::*;
|
||||
match *self {
|
||||
|
|
|
@ -132,7 +132,6 @@ pub trait CrateStore<'tcx> {
|
|||
fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Ty<'tcx>;
|
||||
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
|
||||
fn opt_item_name(&self, def: DefId) -> Option<ast::Name>;
|
||||
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> ty::GenericPredicates<'tcx>;
|
||||
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
|
@ -293,7 +292,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
|
||||
bug!("visible_parent_map")
|
||||
}
|
||||
fn opt_item_name(&self, def: DefId) -> Option<ast::Name> { bug!("opt_item_name") }
|
||||
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
|
||||
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
|
@ -424,4 +422,4 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
|
||||
pub trait MacroLoader {
|
||||
fn load_crate(&mut self, extern_crate: &ast::Item, allows_macros: bool) -> Vec<LoadedMacro>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,7 +138,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
cur_path.push(self.sess.cstore.opt_item_name(cur_def).unwrap_or_else(||
|
||||
cur_path.push(self.sess.cstore.def_key(cur_def)
|
||||
.disambiguated_data.data.get_opt_name().unwrap_or_else(||
|
||||
token::intern("<unnamed>")));
|
||||
match visible_parent_map.get(&cur_def) {
|
||||
Some(&def) => cur_def = def,
|
||||
|
|
|
@ -21,7 +21,7 @@ use dep_graph::{self, DepNode};
|
|||
use hir::map as ast_map;
|
||||
use middle;
|
||||
use hir::def::{Def, PathResolution, ExportMap};
|
||||
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
|
||||
use middle::region::{CodeExtent, ROOT_CODE_EXTENT};
|
||||
use traits;
|
||||
|
@ -43,7 +43,7 @@ use std::slice;
|
|||
use std::vec::IntoIter;
|
||||
use syntax::ast::{self, Name, NodeId};
|
||||
use syntax::attr;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::parse::token::{self, InternedString};
|
||||
use syntax_pos::{DUMMY_SP, Span};
|
||||
|
||||
use rustc_const_math::ConstInt;
|
||||
|
@ -2390,10 +2390,21 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
pub fn item_name(self, id: DefId) -> ast::Name {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
self.map.name(id)
|
||||
} else if id.index == CRATE_DEF_INDEX {
|
||||
token::intern(&self.sess.cstore.original_crate_name(id.krate))
|
||||
} else {
|
||||
self.sess.cstore.opt_item_name(id).unwrap_or_else(|| {
|
||||
bug!("item_name: no name for {:?}", self.def_path(id));
|
||||
})
|
||||
let def_key = self.sess.cstore.def_key(id);
|
||||
// The name of a StructCtor is that of its struct parent.
|
||||
if let ast_map::DefPathData::StructCtor = def_key.disambiguated_data.data {
|
||||
self.item_name(DefId {
|
||||
krate: id.krate,
|
||||
index: def_key.parent.unwrap()
|
||||
})
|
||||
} else {
|
||||
def_key.disambiguated_data.data.get_opt_name().unwrap_or_else(|| {
|
||||
bug!("item_name: no name for {:?}", self.def_path(id));
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,16 +127,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
self.get_crate_data(did.krate).get_fn_arg_names(did.index)
|
||||
}
|
||||
|
||||
fn opt_item_name(&self, def: DefId) -> Option<ast::Name> {
|
||||
self.dep_graph.read(DepNode::MetaData(def));
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
if def.index == CRATE_DEF_INDEX {
|
||||
Some(token::intern(&cdata.name()))
|
||||
} else {
|
||||
cdata.maybe_get_item_name(def.index)
|
||||
}
|
||||
}
|
||||
|
||||
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(def_id));
|
||||
|
|
|
@ -43,7 +43,6 @@ use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
|
|||
use syntax::attr;
|
||||
use syntax::ast::{self, NodeId};
|
||||
use syntax::codemap;
|
||||
use syntax::parse::token;
|
||||
use syntax_pos::{self, Span, BytePos, Pos};
|
||||
|
||||
pub struct DecodeContext<'a, 'tcx: 'a> {
|
||||
|
@ -469,32 +468,6 @@ impl<'tcx> EntryKind<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn def_key_name(def_key: &hir_map::DefKey) -> Option<ast::Name> {
|
||||
match def_key.disambiguated_data.data {
|
||||
DefPathData::TypeNs(ref name) |
|
||||
DefPathData::ValueNs(ref name) |
|
||||
DefPathData::Module(ref name) |
|
||||
DefPathData::MacroDef(ref name) |
|
||||
DefPathData::TypeParam(ref name) |
|
||||
DefPathData::LifetimeDef(ref name) |
|
||||
DefPathData::EnumVariant(ref name) |
|
||||
DefPathData::Field(ref name) |
|
||||
DefPathData::Binding(ref name) => {
|
||||
Some(token::intern(name))
|
||||
}
|
||||
|
||||
DefPathData::InlinedRoot(_) => bug!("unexpected DefPathData"),
|
||||
|
||||
DefPathData::CrateRoot |
|
||||
DefPathData::Misc |
|
||||
DefPathData::Impl |
|
||||
DefPathData::ClosureExpr |
|
||||
DefPathData::StructCtor |
|
||||
DefPathData::Initializer |
|
||||
DefPathData::ImplTrait => None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> CrateMetadata {
|
||||
fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
|
||||
self.root.index.lookup(self.blob.raw_bytes(), item_id)
|
||||
|
@ -518,7 +491,8 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
}
|
||||
|
||||
fn item_name(&self, item: &Entry<'tcx>) -> ast::Name {
|
||||
def_key_name(&item.def_key.decode(self)).expect("no name in item_name")
|
||||
item.def_key.decode(self).disambiguated_data.data.get_opt_name()
|
||||
.expect("no name in item_name")
|
||||
}
|
||||
|
||||
pub fn get_def(&self, index: DefIndex) -> Option<Def> {
|
||||
|
@ -708,7 +682,8 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
if let Some(name) = def_key_name(&child.def_key.decode(self)) {
|
||||
let def_key = child.def_key.decode(self);
|
||||
if let Some(name) = def_key.disambiguated_data.data.get_opt_name() {
|
||||
callback(def::Export {
|
||||
def_id: self.local_def_id(child_index),
|
||||
name: name
|
||||
|
@ -724,10 +699,6 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn maybe_get_item_name(&self, id: DefIndex) -> Option<ast::Name> {
|
||||
def_key_name(&self.entry(id).def_key.decode(self))
|
||||
}
|
||||
|
||||
pub fn maybe_get_item_ast(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefIndex)
|
||||
-> Option<&'tcx InlinedItem> {
|
||||
debug!("Looking up item: {:?}", id);
|
||||
|
@ -757,7 +728,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
let parent_and_name = || {
|
||||
let def_key = item.def_key.decode(self);
|
||||
(self.local_def_id(def_key.parent.unwrap()),
|
||||
def_key_name(&def_key).unwrap())
|
||||
def_key.disambiguated_data.data.get_opt_name().unwrap())
|
||||
};
|
||||
|
||||
Some(match item.kind {
|
||||
|
|
|
@ -436,7 +436,8 @@ impl<'b> Resolver<'b> {
|
|||
let trait_item_def_ids = self.session.cstore.impl_or_trait_items(def_id);
|
||||
for &trait_item_def in &trait_item_def_ids {
|
||||
let trait_item_name =
|
||||
self.session.cstore.opt_item_name(trait_item_def)
|
||||
self.session.cstore.def_key(trait_item_def)
|
||||
.disambiguated_data.data.get_opt_name()
|
||||
.expect("opt_item_name returned None for trait");
|
||||
|
||||
debug!("(building reduced graph for external crate) ... adding trait item \
|
||||
|
|
Loading…
Reference in a new issue