query for describe_def

This commit is contained in:
achernyak 2017-04-27 13:27:16 -05:00
parent 4961d724f8
commit e24003fb3c
6 changed files with 20 additions and 13 deletions

View File

@ -22,7 +22,7 @@
// are *mostly* used as a part of that interface, but these should // are *mostly* used as a part of that interface, but these should
// probably get a better home if someone can find one. // probably get a better home if someone can find one.
use hir::def::{self, Def}; use hir::def;
use hir::def_id::{CrateNum, DefId, DefIndex}; use hir::def_id::{CrateNum, DefId, DefIndex};
use hir::map as hir_map; use hir::map as hir_map;
use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData}; use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData};
@ -181,7 +181,6 @@ pub trait CrateStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>; fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>;
// item info // item info
fn describe_def(&self, def: DefId) -> Option<Def>;
fn def_span(&self, sess: &Session, def: DefId) -> Span; fn def_span(&self, sess: &Session, def: DefId) -> Span;
fn stability(&self, def: DefId) -> Option<attr::Stability>; fn stability(&self, def: DefId) -> Option<attr::Stability>;
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>; fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
@ -313,7 +312,6 @@ impl CrateStore for DummyCrateStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any> fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
{ bug!("crate_data_as_rc_any") } { bug!("crate_data_as_rc_any") }
// item info // item info
fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") } fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") } fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") } fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }

View File

@ -432,7 +432,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// (See issue #38412) // (See issue #38412)
fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool { fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
// Check if `def_id` is a trait method. // Check if `def_id` is a trait method.
match self.sess.cstore.describe_def(def_id) { match self.describe_def(def_id) {
Some(Def::Method(_)) | Some(Def::Method(_)) |
Some(Def::AssociatedTy(_)) | Some(Def::AssociatedTy(_)) |
Some(Def::AssociatedConst(_)) => { Some(Def::AssociatedConst(_)) => {

View File

@ -10,6 +10,7 @@
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig}; use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::def::Def;
use hir; use hir;
use middle::const_val; use middle::const_val;
use middle::privacy::AccessLevels; use middle::privacy::AccessLevels;
@ -264,6 +265,12 @@ fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
} }
} }
impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
fn describe(_: TyCtxt, _: DefId) -> String {
bug!("describe_def")
}
}
macro_rules! define_maps { macro_rules! define_maps {
(<$tcx:tt> (<$tcx:tt>
$($(#[$attr:meta])* $($(#[$attr:meta])*
@ -538,7 +545,9 @@ fn default() -> Self {
pub mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx RefCell<mir::Mir<'tcx>>, pub mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx RefCell<mir::Mir<'tcx>>,
pub def_symbol_name: SymbolName(DefId) -> ty::SymbolName, pub def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
pub symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName pub symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
pub describe_def: meta_data_node(DefId) -> Option<Def>
} }
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> { fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
@ -570,3 +579,7 @@ fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> { fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
DepNode::ConstEval(def_id) DepNode::ConstEval(def_id)
} }
fn meta_data_node(def_id: DefId) -> DepNode<DefId> {
DepNode::MetaData(def_id)
}

View File

@ -2385,7 +2385,7 @@ pub fn trait_id_of_impl(self, def_id: DefId) -> Option<DefId> {
/// ID of the impl that the method belongs to. Otherwise, return `None`. /// ID of the impl that the method belongs to. Otherwise, return `None`.
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> { pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
let item = if def_id.krate != LOCAL_CRATE { let item = if def_id.krate != LOCAL_CRATE {
if let Some(Def::Method(_)) = self.sess.cstore.describe_def(def_id) { if let Some(Def::Method(_)) = self.describe_def(def_id) {
Some(self.associated_item(def_id)) Some(self.associated_item(def_id))
} else { } else {
None None

View File

@ -68,7 +68,7 @@ pub fn lookup_const_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_ => Some((def_id, substs)) _ => Some((def_id, substs))
} }
} else { } else {
match tcx.sess.cstore.describe_def(def_id) { match tcx.describe_def(def_id) {
Some(Def::AssociatedConst(_)) => { Some(Def::AssociatedConst(_)) => {
// As mentioned in the comments above for in-crate // As mentioned in the comments above for in-crate
// constants, we only try to find the expression for a // constants, we only try to find the expression for a

View File

@ -17,7 +17,7 @@
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind, use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
ExternCrate, NativeLibrary, LinkMeta, ExternCrate, NativeLibrary, LinkMeta,
LinkagePreference, LoadedMacro, EncodedMetadata}; LinkagePreference, LoadedMacro, EncodedMetadata};
use rustc::hir::def::{self, Def}; use rustc::hir::def;
use rustc::middle::lang_items; use rustc::middle::lang_items;
use rustc::session::Session; use rustc::session::Session;
use rustc::ty::{self, TyCtxt}; use rustc::ty::{self, TyCtxt};
@ -113,6 +113,7 @@ pub fn provide<$lt>(providers: &mut Providers<$lt>) {
closure_type => { cdata.closure_ty(def_id.index, tcx) } closure_type => { cdata.closure_ty(def_id.index, tcx) }
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) } inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) } is_foreign_item => { cdata.is_foreign_item(def_id.index) }
describe_def => { cdata.get_def(def_id.index) }
} }
impl CrateStore for cstore::CStore { impl CrateStore for cstore::CStore {
@ -120,11 +121,6 @@ fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any> {
self.get_crate_data(krate) self.get_crate_data(krate)
} }
fn describe_def(&self, def: DefId) -> Option<Def> {
self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).get_def(def.index)
}
fn def_span(&self, sess: &Session, def: DefId) -> Span { fn def_span(&self, sess: &Session, def: DefId) -> Span {
self.dep_graph.read(DepNode::MetaData(def)); self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).get_span(def.index, sess) self.get_crate_data(def.krate).get_span(def.index, sess)