Auto merge of #41593 - achernyak:def_span, r=eddyb
query for def_span Resolves `fn def_span(&self, sess: &Session, def: DefId) -> Span;` of #41417. I had to change the query name to `def_sess_span` since `ty::TyCtxt` already has a method `def_span` implemented. This also will probably have merge conflicts with #41534 but I will resolves those once it's merged and wanted to start a code review on this one now. r? @eddyb
This commit is contained in:
commit
ba5b911340
|
@ -148,6 +148,9 @@ pub enum DepNode<D: Clone + Debug> {
|
||||||
// For proj. cache, we just keep a list of all def-ids, since it is
|
// For proj. cache, we just keep a list of all def-ids, since it is
|
||||||
// not a hotspot.
|
// not a hotspot.
|
||||||
ProjectionCache { def_ids: Vec<D> },
|
ProjectionCache { def_ids: Vec<D> },
|
||||||
|
|
||||||
|
DescribeDef(D),
|
||||||
|
DefSpan(D),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Clone + Debug> DepNode<D> {
|
impl<D: Clone + Debug> DepNode<D> {
|
||||||
|
@ -253,6 +256,8 @@ impl<D: Clone + Debug> DepNode<D> {
|
||||||
let def_ids: Option<Vec<E>> = def_ids.iter().map(op).collect();
|
let def_ids: Option<Vec<E>> = def_ids.iter().map(op).collect();
|
||||||
def_ids.map(|d| ProjectionCache { def_ids: d })
|
def_ids.map(|d| ProjectionCache { def_ids: d })
|
||||||
}
|
}
|
||||||
|
DescribeDef(ref d) => op(d).map(DescribeDef),
|
||||||
|
DefSpan(ref d) => op(d).map(DefSpan),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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>;
|
||||||
fn visibility(&self, def: DefId) -> ty::Visibility;
|
fn visibility(&self, def: DefId) -> ty::Visibility;
|
||||||
|
@ -312,7 +311,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 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") }
|
||||||
fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
|
fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
|
||||||
|
|
|
@ -285,6 +285,12 @@ impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> QueryDescription for queries::def_span<'tcx> {
|
||||||
|
fn describe(_: TyCtxt, _: DefId) -> String {
|
||||||
|
bug!("def_span")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! define_maps {
|
macro_rules! define_maps {
|
||||||
(<$tcx:tt>
|
(<$tcx:tt>
|
||||||
$($(#[$attr:meta])*
|
$($(#[$attr:meta])*
|
||||||
|
@ -359,8 +365,10 @@ macro_rules! define_maps {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) Get more valid Span's on queries.
|
// FIXME(eddyb) Get more valid Span's on queries.
|
||||||
if span == DUMMY_SP {
|
// def_span guard is necesary to prevent a recursive loop,
|
||||||
span = key.default_span(tcx);
|
// default_span calls def_span query internally.
|
||||||
|
if span == DUMMY_SP && stringify!($name) != "def_span" {
|
||||||
|
span = key.default_span(tcx)
|
||||||
}
|
}
|
||||||
|
|
||||||
let _task = tcx.dep_graph.in_task(Self::to_dep_node(&key));
|
let _task = tcx.dep_graph.in_task(Self::to_dep_node(&key));
|
||||||
|
@ -568,7 +576,8 @@ define_maps! { <'tcx>
|
||||||
[] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
|
[] def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
|
||||||
[] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
|
[] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
|
||||||
|
|
||||||
[] describe_def: meta_data_node(DefId) -> Option<Def>
|
[] describe_def: DescribeDef(DefId) -> Option<Def>,
|
||||||
|
[] def_span: DefSpan(DefId) -> Span
|
||||||
}
|
}
|
||||||
|
|
||||||
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
|
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
|
||||||
|
@ -600,7 +609,3 @@ 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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -2285,14 +2285,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_span(self, def_id: DefId) -> Span {
|
|
||||||
if let Some(id) = self.hir.as_local_node_id(def_id) {
|
|
||||||
self.hir.span(id)
|
|
||||||
} else {
|
|
||||||
self.sess.cstore.def_span(&self.sess, def_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn vis_is_accessible_from(self, vis: Visibility, block: NodeId) -> bool {
|
pub fn vis_is_accessible_from(self, vis: Visibility, block: NodeId) -> bool {
|
||||||
vis.is_accessible_from(self.hir.local_def_id(self.hir.get_module_parent(block)), self)
|
vis.is_accessible_from(self.hir.local_def_id(self.hir.get_module_parent(block)), self)
|
||||||
}
|
}
|
||||||
|
@ -2694,12 +2686,17 @@ fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
Rc::new(vec)
|
Rc::new(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span {
|
||||||
|
tcx.hir.span_if_local(def_id).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut ty::maps::Providers) {
|
pub fn provide(providers: &mut ty::maps::Providers) {
|
||||||
*providers = ty::maps::Providers {
|
*providers = ty::maps::Providers {
|
||||||
associated_item,
|
associated_item,
|
||||||
associated_item_def_ids,
|
associated_item_def_ids,
|
||||||
adt_sized_constraint,
|
adt_sized_constraint,
|
||||||
adt_dtorck_constraint,
|
adt_dtorck_constraint,
|
||||||
|
def_span,
|
||||||
..*providers
|
..*providers
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ provide! { <'tcx> tcx, def_id, cdata
|
||||||
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) }
|
describe_def => { cdata.get_def(def_id.index) }
|
||||||
|
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CrateStore for cstore::CStore {
|
impl CrateStore for cstore::CStore {
|
||||||
|
@ -121,11 +122,6 @@ impl CrateStore for cstore::CStore {
|
||||||
self.get_crate_data(krate)
|
self.get_crate_data(krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn def_span(&self, sess: &Session, def: DefId) -> Span {
|
|
||||||
self.dep_graph.read(DepNode::MetaData(def));
|
|
||||||
self.get_crate_data(def.krate).get_span(def.index, sess)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stability(&self, def: DefId) -> Option<attr::Stability> {
|
fn stability(&self, def: DefId) -> Option<attr::Stability> {
|
||||||
self.dep_graph.read(DepNode::MetaData(def));
|
self.dep_graph.read(DepNode::MetaData(def));
|
||||||
self.get_crate_data(def.krate).get_stability(def.index)
|
self.get_crate_data(def.krate).get_stability(def.index)
|
||||||
|
|
Loading…
Reference in New Issue