Skip to content

Commit

Permalink
Queryify more metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
cramertj committed May 5, 2017
1 parent 50b9858 commit e349452
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 50 deletions.
6 changes: 0 additions & 6 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ pub trait CrateStore {
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;

// flags
fn is_const_fn(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_foreign_item(&self, did: DefId) -> bool;
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
fn is_exported_symbol(&self, def_id: DefId) -> bool;

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

// flags
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
fn is_exported_symbol(&self, def_id: DefId) -> bool { false }

Expand Down
24 changes: 20 additions & 4 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,25 @@ impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'t
}
}

impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
format!("checking if item is mir available: `{}`",
tcx.item_path_str(def_id))
macro_rules! simple_query_description {
($($fn_name:ident, $desc:expr),*,) => {
$(
impl<'tcx> QueryDescription for queries::$fn_name<'tcx> {
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
format!(concat!($desc, "`: {}`"),
tcx.item_path_str(def_id))
}
}
)*
}
}

simple_query_description! {
is_mir_available, "checking if item is mir available",
is_const_fn, "checking if item is const fn",
is_dllimport_foreign_item, "checking if item is dll import foreign item",
}

macro_rules! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
Expand Down Expand Up @@ -786,6 +798,10 @@ define_maps! { <'tcx>
[] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
[] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool,
[] is_mir_available: metadata_dep_node(DefId) -> bool,

[] is_const_fn: metadata_dep_node(DefId) -> bool,
[] is_default_impl: metadata_dep_node(DefId) -> bool,
[] is_dllimport_foreign_item: metadata_dep_node(DefId) -> bool,
}

fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
signal!(e, TypeckError)
}
} else {
if tcx.sess.cstore.is_const_fn(def_id) {
if tcx.is_const_fn(def_id) {
tcx.sess.cstore.item_body(tcx, def_id)
} else {
signal!(e, TypeckError)
Expand Down
33 changes: 12 additions & 21 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use cstore;
use encoder;
use locator;
use schema;
use schema::{self, EntryKind};

use rustc::dep_graph::DepTrackingMapConfig;
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
Expand All @@ -22,7 +22,7 @@ use rustc::middle::lang_items;
use rustc::session::Session;
use rustc::ty::{self, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};

use rustc::dep_graph::DepNode;
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData};
Expand Down Expand Up @@ -128,6 +128,16 @@ provide! { <'tcx> tcx, def_id, cdata
!cdata.is_proc_macro(def_id.index) &&
cdata.maybe_entry(def_id.index).and_then(|item| item.decode(cdata).mir).is_some()
}
is_const_fn => { cdata.is_const_fn(def_id.index) }
is_default_impl => {
match cdata.entry(def_id.index).kind {
EntryKind::DefaultImpl(_) => true,
_ => false,
}
}
is_dllimport_foreign_item => {
cdata.dllimport_foreign_items.contains(&def_id.index)
}
}

impl CrateStore for cstore::CStore {
Expand Down Expand Up @@ -195,17 +205,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(def.krate).get_associated_item(def.index)
}

fn is_const_fn(&self, did: DefId) -> bool
{
self.dep_graph.read(DepNode::MetaData(did));
self.get_crate_data(did.krate).is_const_fn(did.index)
}

fn is_default_impl(&self, impl_did: DefId) -> bool {
self.dep_graph.read(DepNode::MetaData(impl_did));
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
}

fn is_foreign_item(&self, did: DefId) -> bool {
self.get_crate_data(did.krate).is_foreign_item(did.index)
}
Expand All @@ -219,14 +218,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(def_id.krate).exported_symbols.contains(&def_id.index)
}

fn is_dllimport_foreign_item(&self, def_id: DefId) -> bool {
if def_id.krate == LOCAL_CRATE {
self.dllimport_foreign_items.borrow().contains(&def_id.index)
} else {
self.get_crate_data(def_id.krate).is_dllimport_foreign_item(def_id.index)
}
}

fn dylib_dependency_formats(&self, cnum: CrateNum)
-> Vec<(CrateNum, LinkagePreference)>
{
Expand Down
11 changes: 0 additions & 11 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,17 +1018,6 @@ impl<'a, 'tcx> CrateMetadata {
}
}

pub fn is_dllimport_foreign_item(&self, id: DefIndex) -> bool {
self.dllimport_foreign_items.contains(&id)
}

pub fn is_default_impl(&self, impl_id: DefIndex) -> bool {
match self.entry(impl_id).kind {
EntryKind::DefaultImpl(_) => true,
_ => false,
}
}

pub fn closure_kind(&self, closure_id: DefIndex) -> ty::ClosureKind {
match self.entry(closure_id).kind {
EntryKind::Closure(data) => data.decode(self).kind,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn is_const_fn(tcx: TyCtxt, def_id: DefId) -> bool {
false
}
} else {
tcx.sess.cstore.is_const_fn(def_id)
tcx.is_const_fn(def_id)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
fn_like.constness() == hir::Constness::Const
})
} else {
self.tcx.sess.cstore.is_const_fn(def_id)
self.tcx.is_const_fn(def_id)
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
}

if ccx.use_dll_storage_attrs() &&
ccx.sess().cstore.is_dllimport_foreign_item(instance.def_id())
ccx.tcx().is_dllimport_foreign_item(instance.def_id())
{
unsafe {
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
g
};

if ccx.use_dll_storage_attrs() && ccx.sess().cstore.is_dllimport_foreign_item(def_id) {
if ccx.use_dll_storage_attrs() && ccx.tcx().is_dllimport_foreign_item(def_id) {
// For foreign (native) libs we know the exact storage type to use.
unsafe {
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait {
fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function {
let sig = cx.tcx.type_of(did).fn_sig();

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

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

0 comments on commit e349452

Please sign in to comment.