Skip to content

Commit 5b71d76

Browse files
committed
moved metadata provider impls to decoder
1 parent 03fe10d commit 5b71d76

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/librustc_metadata/cstore_impl.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ use rustc::hir::svh::Svh;
4141
use rustc_back::target::Target;
4242
use rustc::hir;
4343

44-
use std::collections::BTreeMap;
45-
4644
macro_rules! provide {
4745
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => {
4846
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
@@ -121,21 +119,11 @@ provide! { <'tcx> tcx, def_id, cdata
121119
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
122120
impl_parent => { cdata.get_parent_impl(def_id.index) }
123121
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
124-
item_body_nested_bodies => {
125-
let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| {
126-
ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body))
127-
}).collect();
128-
129-
Rc::new(map)
130-
}
122+
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
131123
const_is_rvalue_promotable_to_static => {
132-
cdata.entry(def_id.index).ast.expect("const item missing `ast`")
133-
.decode(cdata).rvalue_promotable_to_static
134-
}
135-
is_mir_available => {
136-
!cdata.is_proc_macro(def_id.index) &&
137-
cdata.maybe_entry(def_id.index).and_then(|item| item.decode(cdata).mir).is_some()
124+
cdata.const_is_rvalue_promotable_to_static(def_id.index)
138125
}
126+
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
139127
}
140128

141129
impl CrateStore for cstore::CStore {

src/librustc_metadata/decoder.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc::mir::Mir;
2929

3030
use std::borrow::Cow;
3131
use std::cell::Ref;
32+
use std::collections::BTreeMap;
3233
use std::io;
3334
use std::mem;
3435
use std::rc::Rc;
@@ -448,16 +449,16 @@ impl<'tcx> EntryKind<'tcx> {
448449
}
449450

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

455-
pub fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
456+
fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
456457
assert!(!self.is_proc_macro(item_id));
457458
self.root.index.lookup(self.blob.raw_bytes(), item_id)
458459
}
459460

460-
pub fn entry(&self, item_id: DefIndex) -> Entry<'tcx> {
461+
fn entry(&self, item_id: DefIndex) -> Entry<'tcx> {
461462
match self.maybe_entry(item_id) {
462463
None => {
463464
bug!("entry: id not found: {:?} in crate {:?} with number {}",
@@ -779,6 +780,22 @@ impl<'a, 'tcx> CrateMetadata {
779780
tcx.alloc_tables(ast.tables.decode((self, tcx)))
780781
}
781782

783+
pub fn item_body_nested_bodies(&self, id: DefIndex) -> BTreeMap<hir::BodyId, hir::Body> {
784+
self.entry(id).ast.into_iter().flat_map(|ast| {
785+
ast.decode(self).nested_bodies.decode(self).map(|body| (body.id(), body))
786+
}).collect()
787+
}
788+
789+
pub fn const_is_rvalue_promotable_to_static(&self, id: DefIndex) -> bool {
790+
self.entry(id).ast.expect("const item missing `ast`")
791+
.decode(self).rvalue_promotable_to_static
792+
}
793+
794+
pub fn is_item_mir_available(&self, id: DefIndex) -> bool {
795+
!self.is_proc_macro(id) &&
796+
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
797+
}
798+
782799
pub fn maybe_get_optimized_mir(&self,
783800
tcx: TyCtxt<'a, 'tcx, 'tcx>,
784801
id: DefIndex)

0 commit comments

Comments
 (0)