Skip to content

Commit 51b4db7

Browse files
committed
Queryify more metadata
1 parent 978d2cf commit 51b4db7

File tree

9 files changed

+40
-31
lines changed

9 files changed

+40
-31
lines changed

src/librustc/middle/cstore.rs

-6
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ pub trait CrateStore {
225225
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;
226226

227227
// flags
228-
fn is_const_fn(&self, did: DefId) -> bool;
229-
fn is_default_impl(&self, impl_did: DefId) -> bool;
230228
fn is_foreign_item(&self, did: DefId) -> bool;
231-
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
232229
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
233230
fn is_exported_symbol(&self, def_id: DefId) -> bool;
234231

@@ -353,10 +350,7 @@ impl CrateStore for DummyCrateStore {
353350
{ bug!("associated_item_cloned") }
354351

355352
// flags
356-
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
357-
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
358353
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
359-
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
360354
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
361355
fn is_exported_symbol(&self, def_id: DefId) -> bool { false }
362356

src/librustc/ty/maps.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,25 @@ impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'t
353353
}
354354
}
355355

356-
impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
357-
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
358-
format!("checking if item is mir available: `{}`",
359-
tcx.item_path_str(def_id))
356+
macro_rules! simple_query_description {
357+
($($fn_name:ident, $desc:expr),*,) => {
358+
$(
359+
impl<'tcx> QueryDescription for queries::$fn_name<'tcx> {
360+
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
361+
format!(concat!($desc, "`: {}`"),
362+
tcx.item_path_str(def_id))
363+
}
364+
}
365+
)*
360366
}
361367
}
362368

369+
simple_query_description! {
370+
is_mir_available, "checking if item is mir available",
371+
is_const_fn, "checking if item is const fn",
372+
is_dllimport_foreign_item, "checking if item is dll import foreign item",
373+
}
374+
363375
macro_rules! define_maps {
364376
(<$tcx:tt>
365377
$($(#[$attr:meta])*
@@ -784,6 +796,10 @@ define_maps! { <'tcx>
784796
[] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
785797
[] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool,
786798
[] is_mir_available: metadata_dep_node(DefId) -> bool,
799+
800+
[] is_const_fn: metadata_dep_node(DefId) -> bool,
801+
[] is_default_impl: metadata_dep_node(DefId) -> bool,
802+
[] is_dllimport_foreign_item: metadata_dep_node(DefId) -> bool,
787803
}
788804

789805
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {

src/librustc_const_eval/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
352352
signal!(e, TypeckError)
353353
}
354354
} else {
355-
if tcx.sess.cstore.is_const_fn(def_id) {
355+
if tcx.is_const_fn(def_id) {
356356
tcx.sess.cstore.item_body(tcx, def_id)
357357
} else {
358358
signal!(e, TypeckError)

src/librustc_metadata/cstore_impl.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use cstore;
1212
use encoder;
1313
use locator;
14-
use schema;
14+
use schema::{self, EntryKind};
1515

1616
use rustc::dep_graph::DepTrackingMapConfig;
1717
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
@@ -22,7 +22,7 @@ use rustc::middle::lang_items;
2222
use rustc::session::Session;
2323
use rustc::ty::{self, TyCtxt};
2424
use rustc::ty::maps::Providers;
25-
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
25+
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
2626

2727
use rustc::dep_graph::{DepNode, GlobalMetaDataKind};
2828
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData};
@@ -128,6 +128,16 @@ provide! { <'tcx> tcx, def_id, cdata
128128
!cdata.is_proc_macro(def_id.index) &&
129129
cdata.maybe_entry(def_id.index).and_then(|item| item.decode(cdata).mir).is_some()
130130
}
131+
is_const_fn => { cdata.is_const_fn(def_id.index) }
132+
is_default_impl => {
133+
match cdata.entry(def_id.index).kind {
134+
EntryKind::DefaultImpl(_) => true,
135+
_ => false,
136+
}
137+
}
138+
is_dllimport_foreign_item => {
139+
cdata.dllimport_foreign_items.contains(&def_id.index)
140+
}
131141
}
132142

133143
impl CrateStore for cstore::CStore {
@@ -195,17 +205,6 @@ impl CrateStore for cstore::CStore {
195205
self.get_crate_data(def.krate).get_associated_item(def.index)
196206
}
197207

198-
fn is_const_fn(&self, did: DefId) -> bool
199-
{
200-
self.dep_graph.read(DepNode::MetaData(did));
201-
self.get_crate_data(did.krate).is_const_fn(did.index)
202-
}
203-
204-
fn is_default_impl(&self, impl_did: DefId) -> bool {
205-
self.dep_graph.read(DepNode::MetaData(impl_did));
206-
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
207-
}
208-
209208
fn is_foreign_item(&self, did: DefId) -> bool {
210209
self.get_crate_data(did.krate).is_foreign_item(did.index)
211210
}

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn is_const_fn(tcx: TyCtxt, def_id: DefId) -> bool {
117117
false
118118
}
119119
} else {
120-
tcx.sess.cstore.is_const_fn(def_id)
120+
tcx.is_const_fn(def_id)
121121
}
122122
}
123123

src/librustc_passes/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
102102
fn_like.constness() == hir::Constness::Const
103103
})
104104
} else {
105-
self.tcx.sess.cstore.is_const_fn(def_id)
105+
self.tcx.is_const_fn(def_id)
106106
};
107107
}
108108
}

src/librustc_trans/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
111111
}
112112

113113
if ccx.use_dll_storage_attrs() &&
114-
ccx.sess().cstore.is_dllimport_foreign_item(instance.def_id())
114+
ccx.tcx().is_dllimport_foreign_item(instance.def_id())
115115
{
116116
unsafe {
117117
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);

src/librustc_trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
199199
g
200200
};
201201

202-
if ccx.use_dll_storage_attrs() && ccx.sess().cstore.is_dllimport_foreign_item(def_id) {
202+
if ccx.use_dll_storage_attrs() && ccx.tcx().is_dllimport_foreign_item(def_id) {
203203
// For foreign (native) libs we know the exact storage type to use.
204204
unsafe {
205205
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);

src/librustdoc/clean/inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait {
167167
fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function {
168168
let sig = cx.tcx.type_of(did).fn_sig();
169169

170-
let constness = if cx.tcx.sess.cstore.is_const_fn(did) {
170+
let constness = if cx.tcx.is_const_fn(did) {
171171
hir::Constness::Const
172172
} else {
173173
hir::Constness::NotConst
@@ -306,7 +306,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
306306
}
307307

308308
// If this is a defaulted impl, then bail out early here
309-
if tcx.sess.cstore.is_default_impl(did) {
309+
if tcx.is_default_impl(did) {
310310
return ret.push(clean::Item {
311311
inner: clean::DefaultImplItem(clean::DefaultImpl {
312312
// FIXME: this should be decoded
@@ -368,7 +368,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
368368
clean::TyMethodItem(clean::TyMethod {
369369
unsafety, decl, generics, abi
370370
}) => {
371-
let constness = if tcx.sess.cstore.is_const_fn(item.def_id) {
371+
let constness = if tcx.is_const_fn(item.def_id) {
372372
hir::Constness::Const
373373
} else {
374374
hir::Constness::NotConst

0 commit comments

Comments
 (0)