Skip to content

Commit

Permalink
Auto merge of #25785 - arielb1:cleanup-201505, r=eddyb
Browse files Browse the repository at this point in the history
The caching essentially eliminates "stability checking" time (my attempt to clean-up junk got tangled up with stability, so I added the caching while I was at it).

r? @eddyb
  • Loading branch information
bors committed May 26, 2015
2 parents 8a87294 + 0ec3183 commit c654a07
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 490 deletions.
2 changes: 1 addition & 1 deletion src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ enum_from_u32! {
tag_table_closure_kinds = 0x65,
tag_table_upvar_capture_map = 0x66,
tag_table_capture_modes = 0x67,
tag_table_object_cast_map = 0x68,
// GAP 0x68
tag_table_const_qualif = 0x69,
tag_table_cast_kinds = 0x6a,
}
Expand Down
23 changes: 7 additions & 16 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,6 @@ pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>,
decoder::get_impl_trait(&*cdata, def.node, tcx)
}

// Given a def_id for an impl, return information about its vtables
pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>,
def: ast::DefId)
-> ty::vtable_res<'tcx> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_vtables(&*cdata, def.node, tcx)
}

pub fn get_native_libraries(cstore: &cstore::CStore, crate_num: ast::CrateNum)
-> Vec<(cstore::NativeLibraryKind, String)> {
let cdata = cstore.get_crate_data(crate_num);
Expand Down Expand Up @@ -389,15 +380,20 @@ pub fn is_const_fn(cstore: &cstore::CStore, did: ast::DefId) -> bool {
decoder::is_const_fn(&*cdata, did.node)
}

pub fn is_impl(cstore: &cstore::CStore, did: ast::DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_impl(&*cdata, did.node)
}

pub fn get_stability(cstore: &cstore::CStore,
def: ast::DefId)
-> Option<attr::Stability> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_stability(&*cdata, def.node)
}

pub fn is_staged_api(cstore: &cstore::CStore, def: ast::DefId) -> bool {
let cdata = cstore.get_crate_data(def.krate);
pub fn is_staged_api(cstore: &cstore::CStore, krate: ast::CrateNum) -> bool {
let cdata = cstore.get_crate_data(krate);
let attrs = decoder::get_crate_attributes(cdata.data());
for attr in &attrs {
if &attr.name()[..] == "staged_api" {
Expand All @@ -414,11 +410,6 @@ pub fn get_repr_attrs(cstore: &cstore::CStore, def: ast::DefId)
decoder::get_repr_attrs(&*cdata, def.node)
}

pub fn is_associated_type(cstore: &cstore::CStore, def: ast::DefId) -> bool {
let cdata = cstore.get_crate_data(def.krate);
decoder::is_associated_type(&*cdata, def.node)
}

pub fn is_defaulted_trait(cstore: &cstore::CStore, trait_def_id: ast::DefId) -> bool {
let cdata = cstore.get_crate_data(trait_def_id.krate);
decoder::is_defaulted_trait(&*cdata, trait_def_id.node)
Expand Down
29 changes: 8 additions & 21 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use middle::lang_items;
use middle::subst;
use middle::ty::{ImplContainer, TraitContainer};
use middle::ty::{self, Ty};
use middle::astencode::vtable_decoder_helpers;
use util::nodemap::FnvHashMap;

use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -522,18 +521,6 @@ pub fn get_impl_trait<'tcx>(cdata: Cmd,
}
}

pub fn get_impl_vtables<'tcx>(cdata: Cmd,
id: ast::NodeId,
tcx: &ty::ctxt<'tcx>)
-> ty::vtable_res<'tcx>
{
let item_doc = lookup_item(id, cdata.data());
let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables);
let mut decoder = reader::Decoder::new(vtables_doc);
decoder.read_vtable_res(tcx, cdata)
}


pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
return item_symbol(lookup_item(id, data));
}
Expand Down Expand Up @@ -1546,6 +1533,14 @@ pub fn is_const_fn(cdata: Cmd, id: ast::NodeId) -> bool {
}
}

pub fn is_impl(cdata: Cmd, id: ast::NodeId) -> bool {
let item_doc = lookup_item(id, cdata.data());
match item_family(item_doc) {
Impl => true,
_ => false,
}
}

fn doc_generics<'tcx>(base_doc: rbml::Doc,
tcx: &ty::ctxt<'tcx>,
cdata: Cmd,
Expand Down Expand Up @@ -1623,14 +1618,6 @@ fn doc_predicates<'tcx>(base_doc: rbml::Doc,
ty::GenericPredicates { predicates: predicates }
}

pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
match maybe_find_item(id, items) {
None => false,
Some(item) => item_sort(item) == Some('t'),
}
}

pub fn is_defaulted_trait(cdata: Cmd, trait_id: ast::NodeId) -> bool {
let trait_doc = lookup_item(trait_id, cdata.data());
assert!(item_family(trait_doc) == Family::Trait);
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ fn encode_extension_implementations(ecx: &EncodeContext,
});
}

fn encode_stability(rbml_w: &mut Encoder, stab_opt: Option<attr::Stability>) {
fn encode_stability(rbml_w: &mut Encoder, stab_opt: Option<&attr::Stability>) {
stab_opt.map(|stab| {
rbml_w.start_tag(tag_items_data_item_stability);
stab.encode(rbml_w).unwrap();
Expand Down Expand Up @@ -1215,11 +1215,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(rbml_w, item.ident.name);
encode_unsafety(rbml_w, unsafety);

let trait_ref = ty::impl_id_to_trait_ref(tcx, item.id);
let trait_ref = ty::impl_trait_ref(tcx, local_def(item.id)).unwrap();
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
rbml_w.end_tag();
}
ast::ItemImpl(unsafety, polarity, _, ref opt_trait, ref ty, ref ast_items) => {
ast::ItemImpl(unsafety, polarity, _, _, ref ty, ref ast_items) => {
// We need to encode information about the default methods we
// have inherited, so we drive this based on the impl structure.
let impl_items = tcx.impl_items.borrow();
Expand Down Expand Up @@ -1269,8 +1269,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
rbml_w.end_tag();
}
if opt_trait.is_some() {
let trait_ref = ty::impl_id_to_trait_ref(tcx, item.id);
if let Some(trait_ref) = ty::impl_trait_ref(tcx, local_def(item.id)) {
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
}
encode_path(rbml_w, path.clone());
Expand Down
104 changes: 0 additions & 104 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,19 +696,6 @@ pub fn encode_cast_kind(ebml_w: &mut Encoder, kind: cast::CastKind) {
pub trait vtable_decoder_helpers<'tcx> {
fn read_vec_per_param_space<T, F>(&mut self, f: F) -> VecPerParamSpace<T> where
F: FnMut(&mut Self) -> T;
fn read_vtable_res_with_key(&mut self,
tcx: &ty::ctxt<'tcx>,
cdata: &cstore::crate_metadata)
-> (u32, ty::vtable_res<'tcx>);
fn read_vtable_res(&mut self,
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
-> ty::vtable_res<'tcx>;
fn read_vtable_param_res(&mut self,
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
-> ty::vtable_param_res<'tcx>;
fn read_vtable_origin(&mut self,
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
-> ty::vtable_origin<'tcx>;
}

impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
Expand All @@ -720,85 +707,6 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
let fns = self.read_to_vec(|this| Ok(f(this))).unwrap();
VecPerParamSpace::new(types, selfs, fns)
}

fn read_vtable_res_with_key(&mut self,
tcx: &ty::ctxt<'tcx>,
cdata: &cstore::crate_metadata)
-> (u32, ty::vtable_res<'tcx>) {
self.read_struct("VtableWithKey", 2, |this| {
let autoderef = this.read_struct_field("autoderef", 0, |this| {
Decodable::decode(this)
}).unwrap();
Ok((autoderef, this.read_struct_field("vtable_res", 1, |this| {
Ok(this.read_vtable_res(tcx, cdata))
}).unwrap()))
}).unwrap()
}

fn read_vtable_res(&mut self,
tcx: &ty::ctxt<'tcx>,
cdata: &cstore::crate_metadata)
-> ty::vtable_res<'tcx>
{
self.read_vec_per_param_space(
|this| this.read_vtable_param_res(tcx, cdata))
}

fn read_vtable_param_res(&mut self,
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
-> ty::vtable_param_res<'tcx> {
self.read_to_vec(|this| Ok(this.read_vtable_origin(tcx, cdata)))
.unwrap().into_iter().collect()
}

fn read_vtable_origin(&mut self,
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
-> ty::vtable_origin<'tcx> {
self.read_enum("vtable_origin", |this| {
this.read_enum_variant(&["vtable_static",
"vtable_param",
"vtable_error",
"vtable_closure"],
|this, i| {
Ok(match i {
0 => {
ty::vtable_static(
this.read_enum_variant_arg(0, |this| {
Ok(this.read_def_id_nodcx(cdata))
}).unwrap(),
this.read_enum_variant_arg(1, |this| {
Ok(this.read_substs_nodcx(tcx, cdata))
}).unwrap(),
this.read_enum_variant_arg(2, |this| {
Ok(this.read_vtable_res(tcx, cdata))
}).unwrap()
)
}
1 => {
ty::vtable_param(
this.read_enum_variant_arg(0, |this| {
Decodable::decode(this)
}).unwrap(),
this.read_enum_variant_arg(1, |this| {
this.read_uint()
}).unwrap()
)
}
2 => {
ty::vtable_closure(
this.read_enum_variant_arg(0, |this| {
Ok(this.read_def_id_nodcx(cdata))
}).unwrap()
)
}
3 => {
ty::vtable_error
}
_ => panic!("bad enum variant")
})
})
}).unwrap()
}
}

// ___________________________________________________________________________
Expand Down Expand Up @@ -1209,13 +1117,6 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
})
}

if let Some(trait_ref) = tcx.object_cast_map.borrow().get(&id) {
rbml_w.tag(c::tag_table_object_cast_map, |rbml_w| {
rbml_w.id(id);
rbml_w.emit_trait_ref(ecx, &trait_ref.0);
})
}

if let Some(adjustment) = tcx.adjustments.borrow().get(&id) {
match *adjustment {
ty::AdjustDerefRef(ref adj) => {
Expand Down Expand Up @@ -1800,11 +1701,6 @@ fn decode_side_tables(dcx: &DecodeContext,
};
dcx.tcx.method_map.borrow_mut().insert(method_call, method);
}
c::tag_table_object_cast_map => {
let trait_ref = val_dsr.read_poly_trait_ref(dcx);
dcx.tcx.object_cast_map.borrow_mut()
.insert(id, trait_ref);
}
c::tag_table_adjustments => {
let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(dcx);
dcx.tcx.adjustments.borrow_mut().insert(id, adj);
Expand Down
Loading

0 comments on commit c654a07

Please sign in to comment.