Skip to content

Commit daa0094

Browse files
committed
Queryify is_item_mir_available
1 parent fb4380b commit daa0094

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

src/librustc/middle/cstore.rs

-6
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ pub trait CrateStore {
250250
fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
251251
-> &'tcx hir::Body;
252252

253-
fn is_item_mir_available(&self, def: DefId) -> bool;
254-
255253
// This is basically a 1-based range of ints, which is a little
256254
// silly - I may fix that.
257255
fn crates(&self) -> Vec<CrateNum>;
@@ -399,10 +397,6 @@ impl CrateStore for DummyCrateStore {
399397
bug!("item_body")
400398
}
401399

402-
fn is_item_mir_available(&self, def: DefId) -> bool {
403-
bug!("is_item_mir_available")
404-
}
405-
406400
// This is basically a 1-based range of ints, which is a little
407401
// silly - I may fix that.
408402
fn crates(&self) -> Vec<CrateNum> { vec![] }

src/librustc/ty/maps.rs

+8
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'t
305305
}
306306
}
307307

308+
impl<'tcx> QueryDescription for queries::is_item_mir_available<'tcx> {
309+
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
310+
format!("checking if item is mir available: `{}`",
311+
tcx.item_path_str(def_id))
312+
}
313+
}
314+
308315
macro_rules! define_maps {
309316
(<$tcx:tt>
310317
$($(#[$attr:meta])*
@@ -595,6 +602,7 @@ define_maps! { <'tcx>
595602

596603
[] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
597604
[] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool,
605+
[] is_item_mir_available: metadata_dep_node(DefId) -> bool,
598606
}
599607

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

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23322332
return None;
23332333
}
23342334

2335-
if !did.is_local() && !self.sess.cstore.is_item_mir_available(did) {
2335+
if !did.is_local() && !self.is_item_mir_available(did) {
23362336
return None;
23372337
}
23382338

src/librustc_metadata/cstore_impl.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ provide! { <'tcx> tcx, def_id, cdata
126126
cdata.entry(def_id.index).ast.expect("const item missing `ast`")
127127
.decode(cdata).rvalue_promotable_to_static
128128
}
129+
is_item_mir_available => {
130+
!cdata.is_proc_macro(def_id.index) &&
131+
cdata.maybe_entry(def_id.index).and_then(|item| item.decode(cdata).mir).is_some()
132+
}
129133
}
130134

131135
impl CrateStore for cstore::CStore {
@@ -443,11 +447,6 @@ impl CrateStore for cstore::CStore {
443447
self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
444448
}
445449

446-
fn is_item_mir_available(&self, def: DefId) -> bool {
447-
self.dep_graph.read(DepNode::MetaData(def));
448-
self.get_crate_data(def.krate).is_item_mir_available(def.index)
449-
}
450-
451450
fn crates(&self) -> Vec<CrateNum>
452451
{
453452
let mut result = vec![];

src/librustc_metadata/decoder.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ impl<'tcx> EntryKind<'tcx> {
441441
}
442442

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

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

775-
pub fn is_item_mir_available(&self, id: DefIndex) -> bool {
776-
!self.is_proc_macro(id) &&
777-
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
778-
}
779-
780775
pub fn maybe_get_item_mir(&self,
781776
tcx: TyCtxt<'a, 'tcx, 'tcx>,
782777
id: DefIndex)

src/librustc_trans/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: &Instan
659659
// in this crate
660660
false
661661
} else {
662-
if !tcx.sess.cstore.is_item_mir_available(def_id) {
662+
if !tcx.is_item_mir_available(def_id) {
663663
bug!("Cannot create local trans-item for {:?}", def_id)
664664
}
665665
true

0 commit comments

Comments
 (0)