Skip to content

Commit

Permalink
Queryify is_item_mir_available
Browse files Browse the repository at this point in the history
  • Loading branch information
cramertj committed May 1, 2017
1 parent fb4380b commit daa0094
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
6 changes: 0 additions & 6 deletions src/librustc/middle/cstore.rs
Expand Up @@ -250,8 +250,6 @@ pub trait CrateStore {
fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-> &'tcx hir::Body;

fn is_item_mir_available(&self, def: DefId) -> bool;

// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.
fn crates(&self) -> Vec<CrateNum>;
Expand Down Expand Up @@ -399,10 +397,6 @@ impl CrateStore for DummyCrateStore {
bug!("item_body")
}

fn is_item_mir_available(&self, def: DefId) -> bool {
bug!("is_item_mir_available")
}

// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.
fn crates(&self) -> Vec<CrateNum> { vec![] }
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ty/maps.rs
Expand Up @@ -305,6 +305,13 @@ impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'t
}
}

impl<'tcx> QueryDescription for queries::is_item_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! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
Expand Down Expand Up @@ -595,6 +602,7 @@ 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_item_mir_available: 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/ty/mod.rs
Expand Up @@ -2332,7 +2332,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
return None;
}

if !did.is_local() && !self.sess.cstore.is_item_mir_available(did) {
if !did.is_local() && !self.is_item_mir_available(did) {
return None;
}

Expand Down
9 changes: 4 additions & 5 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -126,6 +126,10 @@ provide! { <'tcx> tcx, def_id, cdata
cdata.entry(def_id.index).ast.expect("const item missing `ast`")
.decode(cdata).rvalue_promotable_to_static
}
is_item_mir_available => {
!cdata.is_proc_macro(def_id.index) &&
cdata.maybe_entry(def_id.index).and_then(|item| item.decode(cdata).mir).is_some()
}
}

impl CrateStore for cstore::CStore {
Expand Down Expand Up @@ -443,11 +447,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
}

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

fn crates(&self) -> Vec<CrateNum>
{
let mut result = vec![];
Expand Down
9 changes: 2 additions & 7 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -441,11 +441,11 @@ impl<'tcx> EntryKind<'tcx> {
}

impl<'a, 'tcx> CrateMetadata {
fn is_proc_macro(&self, id: DefIndex) -> bool {
pub fn is_proc_macro(&self, id: DefIndex) -> bool {
self.proc_macros.is_some() && id != CRATE_DEF_INDEX
}

fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
pub fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
assert!(!self.is_proc_macro(item_id));
self.root.index.lookup(self.blob.raw_bytes(), item_id)
}
Expand Down Expand Up @@ -772,11 +772,6 @@ impl<'a, 'tcx> CrateMetadata {
tcx.alloc_tables(ast.tables.decode((self, tcx)))
}

pub fn is_item_mir_available(&self, id: DefIndex) -> bool {
!self.is_proc_macro(id) &&
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
}

pub fn maybe_get_item_mir(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: DefIndex)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/collector.rs
Expand Up @@ -659,7 +659,7 @@ fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: &Instan
// in this crate
false
} else {
if !tcx.sess.cstore.is_item_mir_available(def_id) {
if !tcx.is_item_mir_available(def_id) {
bug!("Cannot create local trans-item for {:?}", def_id)
}
true
Expand Down

0 comments on commit daa0094

Please sign in to comment.