Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queryify more metadata #41766

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/nomicon
6 changes: 0 additions & 6 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,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 @@ -353,10 +350,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 @@ -353,13 +353,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 @@ -784,6 +796,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
3 changes: 2 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
reachable::provide(&mut local_providers);
rustc_const_eval::provide(&mut local_providers);
middle::region::provide(&mut local_providers);
cstore::provide_local(&mut local_providers);

let mut extern_providers = ty::maps::Providers::default();
cstore::provide(&mut extern_providers);
cstore::provide_extern(&mut extern_providers);
trans::provide(&mut extern_providers);
ty::provide_extern(&mut extern_providers);
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
Expand Down
52 changes: 29 additions & 23 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, GlobalMetaDataKind};
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData};
Expand All @@ -45,7 +45,7 @@ use std::collections::BTreeMap;

macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => {
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
pub fn provide_extern<$lt>(providers: &mut Providers<$lt>) {
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
-> <ty::queries::$name<$lt> as
DepTrackingMapConfig>::Value {
Expand Down Expand Up @@ -128,6 +128,32 @@ 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 => {
// extern case
cdata.dllimport_foreign_items.contains(&def_id.index)
}
}

pub fn provide_local(providers: &mut ty::maps::Providers) {
providers.is_dllimport_foreign_item = is_dllimport_foreign_item;
}

fn is_dllimport_foreign_item_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
tcx.dep_graph.read(DepNode::MetaData(def_id));

let cdata = tcx.sess.cstore.crate_data_as_rc_any(def_id.krate);
let cdata = cdata.downcast_ref::<cstore::CrateMetadata>()
.expect("CrateStore crated ata is not a CrateMetadata");

cdata.get_crate_data(def_id.krate)
.is_dllimport_foreign_item(def_id.index, &cdata.dep_graph)
}

impl CrateStore for cstore::CStore {
Expand Down Expand Up @@ -195,17 +221,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 @@ -223,15 +238,6 @@ impl CrateStore for cstore::CStore {
.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, &self.dep_graph)
}
}

fn dylib_dependency_formats(&self, cnum: CrateNum)
-> Vec<(CrateNum, LinkagePreference)>
{
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
2 changes: 1 addition & 1 deletion src/rust-installer