metedata: Remove the unnecessary indirection to astencode.
This commit is contained in:
parent
9723a3bc37
commit
b918e37eb3
@ -8,7 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use astencode;
|
||||
use cstore;
|
||||
use decoder;
|
||||
use encoder;
|
||||
@ -439,8 +438,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
||||
-> FoundAst<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
let decode_inlined_item = Box::new(astencode::decode_inlined_item);
|
||||
decoder::maybe_get_item_ast(&cdata, tcx, def.index, decode_inlined_item)
|
||||
decoder::maybe_get_item_ast(&cdata, tcx, def.index)
|
||||
}
|
||||
|
||||
fn maybe_get_item_mir(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
||||
@ -509,21 +507,18 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
||||
mir_map: &MirMap<'tcx>,
|
||||
krate: &hir::Crate) -> Vec<u8>
|
||||
{
|
||||
let encode_inlined_item: encoder::EncodeInlinedItem =
|
||||
Box::new(|ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii));
|
||||
|
||||
let encode_params = encoder::EncodeParams {
|
||||
let ecx = encoder::EncodeContext {
|
||||
diag: tcx.sess.diagnostic(),
|
||||
tcx: tcx,
|
||||
reexports: reexports,
|
||||
item_symbols: item_symbols,
|
||||
link_meta: link_meta,
|
||||
cstore: self,
|
||||
encode_inlined_item: encode_inlined_item,
|
||||
reachable: reachable,
|
||||
mir_map: mir_map,
|
||||
type_abbrevs: RefCell::new(FnvHashMap()),
|
||||
};
|
||||
encoder::encode_metadata(encode_params, krate)
|
||||
encoder::encode_metadata(ecx, krate)
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
use self::Family::*;
|
||||
|
||||
use astencode::decode_inlined_item;
|
||||
use cstore::{self, crate_metadata};
|
||||
use common::*;
|
||||
use encoder::def_to_u64;
|
||||
@ -797,20 +798,9 @@ pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Nam
|
||||
item_name(intr, cdata.lookup_item(id))
|
||||
}
|
||||
|
||||
pub type DecodeInlinedItem<'a> =
|
||||
Box<for<'tcx> FnMut(Cmd,
|
||||
&TyCtxt<'tcx>,
|
||||
Vec<hir_map::PathElem>, // parent_path
|
||||
hir_map::DefPath, // parent_def_path
|
||||
rbml::Doc,
|
||||
DefId)
|
||||
-> Result<&'tcx InlinedItem, (Vec<hir_map::PathElem>,
|
||||
hir_map::DefPath)> + 'a>;
|
||||
|
||||
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd,
|
||||
tcx: &TyCtxt<'tcx>,
|
||||
id: DefIndex,
|
||||
mut decode_inlined_item: DecodeInlinedItem)
|
||||
-> FoundAst<'tcx> {
|
||||
debug!("Looking up item: {:?}", id);
|
||||
let item_doc = cdata.lookup_item(id);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#![allow(unused_must_use)] // everything is just a MemWriter, can't fail
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
use astencode::encode_inlined_item;
|
||||
use common::*;
|
||||
use cstore;
|
||||
use decoder;
|
||||
@ -55,21 +56,6 @@ use rustc_front::hir::{self, PatKind};
|
||||
use rustc_front::intravisit::Visitor;
|
||||
use rustc_front::intravisit;
|
||||
|
||||
pub type EncodeInlinedItem<'a> =
|
||||
Box<FnMut(&EncodeContext, &mut Encoder, InlinedItemRef) + 'a>;
|
||||
|
||||
pub struct EncodeParams<'a, 'tcx: 'a> {
|
||||
pub diag: &'a Handler,
|
||||
pub tcx: &'a TyCtxt<'tcx>,
|
||||
pub reexports: &'a def::ExportMap,
|
||||
pub item_symbols: &'a RefCell<NodeMap<String>>,
|
||||
pub link_meta: &'a LinkMeta,
|
||||
pub cstore: &'a cstore::CStore,
|
||||
pub encode_inlined_item: EncodeInlinedItem<'a>,
|
||||
pub reachable: &'a NodeSet,
|
||||
pub mir_map: &'a MirMap<'tcx>,
|
||||
}
|
||||
|
||||
pub struct EncodeContext<'a, 'tcx: 'a> {
|
||||
pub diag: &'a Handler,
|
||||
pub tcx: &'a TyCtxt<'tcx>,
|
||||
@ -77,7 +63,6 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
|
||||
pub item_symbols: &'a RefCell<NodeMap<String>>,
|
||||
pub link_meta: &'a LinkMeta,
|
||||
pub cstore: &'a cstore::CStore,
|
||||
pub encode_inlined_item: RefCell<EncodeInlinedItem<'a>>,
|
||||
pub type_abbrevs: tyencode::abbrev_map<'tcx>,
|
||||
pub reachable: &'a NodeSet,
|
||||
pub mir_map: &'a MirMap<'tcx>,
|
||||
@ -688,6 +673,7 @@ fn encode_info_for_associated_const<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
rbml_w,
|
||||
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
|
||||
ii));
|
||||
encode_mir(ecx, rbml_w, ii.id);
|
||||
}
|
||||
|
||||
rbml_w.end_tag();
|
||||
@ -733,6 +719,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
rbml_w,
|
||||
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
|
||||
impl_item));
|
||||
encode_mir(ecx, rbml_w, impl_item.id);
|
||||
}
|
||||
encode_constness(rbml_w, sig.constness);
|
||||
encode_defaultness(rbml_w, impl_item.defaultness);
|
||||
@ -820,23 +807,6 @@ fn encode_repr_attrs(rbml_w: &mut Encoder,
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_inlined_item(ecx: &EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
ii: InlinedItemRef) {
|
||||
let mut eii = ecx.encode_inlined_item.borrow_mut();
|
||||
let eii: &mut EncodeInlinedItem = &mut *eii;
|
||||
eii(ecx, rbml_w, ii);
|
||||
|
||||
let node_id = match ii {
|
||||
InlinedItemRef::Item(item) => item.id,
|
||||
InlinedItemRef::TraitItem(_, trait_item) => trait_item.id,
|
||||
InlinedItemRef::ImplItem(_, impl_item) => impl_item.id,
|
||||
InlinedItemRef::Foreign(foreign_item) => foreign_item.id
|
||||
};
|
||||
|
||||
encode_mir(ecx, rbml_w, node_id);
|
||||
}
|
||||
|
||||
fn encode_mir(ecx: &EncodeContext, rbml_w: &mut Encoder, node_id: NodeId) {
|
||||
if let Some(mir) = ecx.mir_map.map.get(&node_id) {
|
||||
rbml_w.start_tag(tag_mir as usize);
|
||||
@ -958,6 +928,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_path(rbml_w, path);
|
||||
encode_attributes(rbml_w, &item.attrs);
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_mir(ecx, rbml_w, item.id);
|
||||
encode_visibility(rbml_w, vis);
|
||||
encode_stability(rbml_w, stab);
|
||||
encode_deprecation(rbml_w, depr);
|
||||
@ -976,6 +947,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
let needs_inline = tps_len > 0 || attr::requests_inline(&item.attrs);
|
||||
if needs_inline || constness == hir::Constness::Const {
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_mir(ecx, rbml_w, item.id);
|
||||
}
|
||||
if tps_len == 0 {
|
||||
encode_symbol(ecx, rbml_w, item.id);
|
||||
@ -1044,6 +1016,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.data.id()));
|
||||
}
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_mir(ecx, rbml_w, item.id);
|
||||
encode_path(rbml_w, path);
|
||||
|
||||
// Encode inherent implementations for this enumeration.
|
||||
@ -1092,6 +1065,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_struct_fields(rbml_w, variant);
|
||||
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_mir(ecx, rbml_w, item.id);
|
||||
|
||||
// Encode inherent implementations for this structure.
|
||||
encode_inherent_implementations(ecx, rbml_w, def_id);
|
||||
@ -1374,6 +1348,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
|
||||
encode_inlined_item(ecx, rbml_w,
|
||||
InlinedItemRef::TraitItem(def_id, trait_item));
|
||||
encode_mir(ecx, rbml_w, trait_item.id);
|
||||
}
|
||||
hir::MethodTraitItem(ref sig, ref body) => {
|
||||
// If this is a static method, we've already
|
||||
@ -1389,6 +1364,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_item_sort(rbml_w, 'p');
|
||||
encode_inlined_item(ecx, rbml_w,
|
||||
InlinedItemRef::TraitItem(def_id, trait_item));
|
||||
encode_mir(ecx, rbml_w, trait_item.id);
|
||||
} else {
|
||||
encode_item_sort(rbml_w, 'r');
|
||||
}
|
||||
@ -1426,13 +1402,15 @@ fn encode_info_for_foreign_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_name(rbml_w, nitem.name);
|
||||
if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Foreign(nitem));
|
||||
encode_mir(ecx, rbml_w, nitem.id);
|
||||
} else {
|
||||
encode_symbol(ecx, rbml_w, nitem.id);
|
||||
}
|
||||
encode_attributes(rbml_w, &nitem.attrs);
|
||||
let stab = stability::lookup_stability(ecx.tcx, ecx.tcx.map.local_def_id(nitem.id));
|
||||
let depr = stability::lookup_deprecation(ecx.tcx, ecx.tcx.map.local_def_id(nitem.id));
|
||||
encode_stability(rbml_w, stab);
|
||||
encode_deprecation(rbml_w, depr);
|
||||
encode_symbol(ecx, rbml_w, nitem.id);
|
||||
encode_method_argument_names(rbml_w, &fndecl);
|
||||
}
|
||||
hir::ForeignItemStatic(_, mutbl) => {
|
||||
@ -1928,32 +1906,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 2 ];
|
||||
|
||||
pub fn encode_metadata(parms: EncodeParams, krate: &hir::Crate) -> Vec<u8> {
|
||||
let EncodeParams {
|
||||
item_symbols,
|
||||
diag,
|
||||
tcx,
|
||||
reexports,
|
||||
cstore,
|
||||
encode_inlined_item,
|
||||
link_meta,
|
||||
reachable,
|
||||
mir_map,
|
||||
..
|
||||
} = parms;
|
||||
let ecx = EncodeContext {
|
||||
diag: diag,
|
||||
tcx: tcx,
|
||||
reexports: reexports,
|
||||
item_symbols: item_symbols,
|
||||
link_meta: link_meta,
|
||||
cstore: cstore,
|
||||
encode_inlined_item: RefCell::new(encode_inlined_item),
|
||||
type_abbrevs: RefCell::new(FnvHashMap()),
|
||||
reachable: reachable,
|
||||
mir_map: mir_map,
|
||||
};
|
||||
|
||||
pub fn encode_metadata(ecx: EncodeContext, krate: &hir::Crate) -> Vec<u8> {
|
||||
let mut wr = Cursor::new(Vec::new());
|
||||
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user