Skip to content

Commit e349452

Browse files
committed
Queryify more metadata
1 parent 50b9858 commit e349452

File tree

10 files changed

+40
-50
lines changed

10 files changed

+40
-50
lines changed

src/librustc/middle/cstore.rs

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

199199
// flags
200-
fn is_const_fn(&self, did: DefId) -> bool;
201-
fn is_default_impl(&self, impl_did: DefId) -> bool;
202200
fn is_foreign_item(&self, did: DefId) -> bool;
203-
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
204201
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
205202
fn is_exported_symbol(&self, def_id: DefId) -> bool;
206203

@@ -325,10 +322,7 @@ impl CrateStore for DummyCrateStore {
325322
{ bug!("associated_item_cloned") }
326323

327324
// flags
328-
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
329-
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
330325
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
331-
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
332326
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
333327
fn is_exported_symbol(&self, def_id: DefId) -> bool { false }
334328

src/librustc/ty/maps.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,25 @@ impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'t
347347
}
348348
}
349349

350-
impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
351-
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
352-
format!("checking if item is mir available: `{}`",
353-
tcx.item_path_str(def_id))
350+
macro_rules! simple_query_description {
351+
($($fn_name:ident, $desc:expr),*,) => {
352+
$(
353+
impl<'tcx> QueryDescription for queries::$fn_name<'tcx> {
354+
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
355+
format!(concat!($desc, "`: {}`"),
356+
tcx.item_path_str(def_id))
357+
}
358+
}
359+
)*
354360
}
355361
}
356362

363+
simple_query_description! {
364+
is_mir_available, "checking if item is mir available",
365+
is_const_fn, "checking if item is const fn",
366+
is_dllimport_foreign_item, "checking if item is dll import foreign item",
367+
}
368+
357369
macro_rules! define_maps {
358370
(<$tcx:tt>
359371
$($(#[$attr:meta])*
@@ -786,6 +798,10 @@ define_maps! { <'tcx>
786798
[] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
787799
[] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool,
788800
[] is_mir_available: metadata_dep_node(DefId) -> bool,
801+
802+
[] is_const_fn: metadata_dep_node(DefId) -> bool,
803+
[] is_default_impl: metadata_dep_node(DefId) -> bool,
804+
[] is_dllimport_foreign_item: metadata_dep_node(DefId) -> bool,
789805
}
790806

791807
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-21
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;
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
}
@@ -219,14 +218,6 @@ impl CrateStore for cstore::CStore {
219218
self.get_crate_data(def_id.krate).exported_symbols.contains(&def_id.index)
220219
}
221220

222-
fn is_dllimport_foreign_item(&self, def_id: DefId) -> bool {
223-
if def_id.krate == LOCAL_CRATE {
224-
self.dllimport_foreign_items.borrow().contains(&def_id.index)
225-
} else {
226-
self.get_crate_data(def_id.krate).is_dllimport_foreign_item(def_id.index)
227-
}
228-
}
229-
230221
fn dylib_dependency_formats(&self, cnum: CrateNum)
231222
-> Vec<(CrateNum, LinkagePreference)>
232223
{

src/librustc_metadata/decoder.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1018,17 +1018,6 @@ impl<'a, 'tcx> CrateMetadata {
10181018
}
10191019
}
10201020

1021-
pub fn is_dllimport_foreign_item(&self, id: DefIndex) -> bool {
1022-
self.dllimport_foreign_items.contains(&id)
1023-
}
1024-
1025-
pub fn is_default_impl(&self, impl_id: DefIndex) -> bool {
1026-
match self.entry(impl_id).kind {
1027-
EntryKind::DefaultImpl(_) => true,
1028-
_ => false,
1029-
}
1030-
}
1031-
10321021
pub fn closure_kind(&self, closure_id: DefIndex) -> ty::ClosureKind {
10331022
match self.entry(closure_id).kind {
10341023
EntryKind::Closure(data) => data.decode(self).kind,

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)