Skip to content

Commit 02274a8

Browse files
authored
Rollup merge of rust-lang#41653 - achernyak:master, r=nikomatsakis
Queries for Crate Metadata This resolves following parts of rust-lang#41417: * `fn stability(&self, def: DefId) -> Option<attr::Stability>;` * `fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;` r? @nikomatsakis
2 parents 9e621c2 + c1d97c7 commit 02274a8

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub enum DepNode<D: Clone + Debug> {
152152

153153
DescribeDef(D),
154154
DefSpan(D),
155+
Stability(D),
156+
Deprecation(D),
155157
}
156158

157159
impl<D: Clone + Debug> DepNode<D> {
@@ -260,6 +262,8 @@ impl<D: Clone + Debug> DepNode<D> {
260262
}
261263
DescribeDef(ref d) => op(d).map(DescribeDef),
262264
DefSpan(ref d) => op(d).map(DefSpan),
265+
Stability(ref d) => op(d).map(Stability),
266+
Deprecation(ref d) => op(d).map(Deprecation),
263267
}
264268
}
265269
}

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use std::any::Any;
3838
use std::path::PathBuf;
3939
use std::rc::Rc;
4040
use syntax::ast;
41-
use syntax::attr;
4241
use syntax::ext::base::SyntaxExtension;
4342
use syntax::symbol::Symbol;
4443
use syntax_pos::Span;
@@ -180,8 +179,6 @@ pub trait CrateStore {
180179
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>;
181180

182181
// item info
183-
fn stability(&self, def: DefId) -> Option<attr::Stability>;
184-
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
185182
fn visibility(&self, def: DefId) -> ty::Visibility;
186183
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>>;
187184
fn item_generics_cloned(&self, def: DefId) -> ty::Generics;
@@ -306,8 +303,6 @@ impl CrateStore for DummyCrateStore {
306303
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
307304
{ bug!("crate_data_as_rc_any") }
308305
// item info
309-
fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
310-
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
311306
fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
312307
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> {
313308
bug!("visible_parent_map")

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
636636
if id.is_local() {
637637
None // The stability cache is filled partially lazily
638638
} else {
639-
self.sess.cstore.stability(id).map(|st| self.intern_stability(st))
639+
self.stability(id).map(|st| self.intern_stability(st))
640640
}
641641
}
642642

@@ -645,7 +645,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
645645
if id.is_local() {
646646
None // The stability cache is filled partially lazily
647647
} else {
648-
self.sess.cstore.deprecation(id).map(DeprecationEntry::external)
648+
self.deprecation(id).map(DeprecationEntry::external)
649649
}
650650
}
651651
}

src/librustc/ty/maps.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use std::collections::BTreeMap;
3333
use std::ops::Deref;
3434
use std::rc::Rc;
3535
use syntax_pos::{Span, DUMMY_SP};
36+
use syntax::attr;
3637
use syntax::symbol::Symbol;
3738

3839
pub trait Key: Clone + Hash + Eq + Debug {
@@ -320,6 +321,19 @@ impl<'tcx> QueryDescription for queries::def_span<'tcx> {
320321
}
321322
}
322323

324+
325+
impl<'tcx> QueryDescription for queries::stability<'tcx> {
326+
fn describe(_: TyCtxt, _: DefId) -> String {
327+
bug!("stability")
328+
}
329+
}
330+
331+
impl<'tcx> QueryDescription for queries::deprecation<'tcx> {
332+
fn describe(_: TyCtxt, _: DefId) -> String {
333+
bug!("deprecation")
334+
}
335+
}
336+
323337
impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
324338
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
325339
format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
@@ -767,7 +781,8 @@ define_maps! { <'tcx>
767781

768782
[] describe_def: DescribeDef(DefId) -> Option<Def>,
769783
[] def_span: DefSpan(DefId) -> Span,
770-
784+
[] stability: Stability(DefId) -> Option<attr::Stability>,
785+
[] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
771786
[] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
772787
[] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool,
773788
[] is_mir_available: metadata_dep_node(DefId) -> bool,

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ provide! { <'tcx> tcx, def_id, cdata
111111
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
112112
describe_def => { cdata.get_def(def_id.index) }
113113
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
114+
stability => { cdata.get_stability(def_id.index) }
115+
deprecation => { cdata.get_deprecation(def_id.index) }
114116
item_body_nested_bodies => {
115117
let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| {
116118
ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body))
@@ -133,16 +135,6 @@ impl CrateStore for cstore::CStore {
133135
self.get_crate_data(krate)
134136
}
135137

136-
fn stability(&self, def: DefId) -> Option<attr::Stability> {
137-
self.dep_graph.read(DepNode::MetaData(def));
138-
self.get_crate_data(def.krate).get_stability(def.index)
139-
}
140-
141-
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> {
142-
self.dep_graph.read(DepNode::MetaData(def));
143-
self.get_crate_data(def.krate).get_deprecation(def.index)
144-
}
145-
146138
fn visibility(&self, def: DefId) -> ty::Visibility {
147139
self.dep_graph.read(DepNode::MetaData(def));
148140
self.get_crate_data(def.krate).get_visibility(def.index)

0 commit comments

Comments
 (0)