提交 fa6b2d4c 编写于 作者: B bors

auto merge of #17647 : pcwalton/rust/stop-looking-in-metadata-in-tc, r=cmr

I don't know exactly what made this regress so badly…maybe it was all the lifetimes that @EddyB landed. According to `git blame` this is all somewhat old code. Regardless this is an enormous improvement in compile times.

r? @brson 
......@@ -593,6 +593,7 @@ fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
"static_assert",
"thread_local",
"no_debug",
"unsafe_no_drop_flag",
// used in resolve
"prelude_import",
......
......@@ -214,6 +214,8 @@ pub fn from_uint(value : uint) -> Option<astencode_tag> {
pub static tag_items_data_item_stability: uint = 0x92;
pub static tag_items_data_item_repr: uint = 0x93;
#[deriving(Clone, Show)]
pub struct LinkMeta {
pub crate_name: String,
......
......@@ -350,6 +350,12 @@ pub fn get_stability(cstore: &cstore::CStore,
decoder::get_stability(&*cdata, def.node)
}
pub fn get_repr_attrs(cstore: &cstore::CStore, def: ast::DefId)
-> Vec<attr::ReprAttr> {
let cdata = cstore.get_crate_data(def.krate);
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)
......
......@@ -384,6 +384,17 @@ pub fn get_stability(cdata: Cmd, id: ast::NodeId) -> Option<attr::Stability> {
})
}
pub fn get_repr_attrs(cdata: Cmd, id: ast::NodeId) -> Vec<attr::ReprAttr> {
let item = lookup_item(id, cdata.data());
match reader::maybe_get_doc(item, tag_items_data_item_repr).map(|doc| {
let mut decoder = reader::Decoder::new(doc);
Decodable::decode(&mut decoder).unwrap()
}) {
Some(attrs) => attrs,
None => Vec::new(),
}
}
pub fn get_impl_trait(cdata: Cmd,
id: ast::NodeId,
tcx: &ty::ctxt) -> Option<Rc<ty::TraitRef>>
......
......@@ -332,6 +332,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
encode_parent_item(rbml_w, local_def(id));
encode_visibility(rbml_w, variant.node.vis);
encode_attributes(rbml_w, variant.node.attrs.as_slice());
encode_repr_attrs(rbml_w, ecx, variant.node.attrs.as_slice());
let stab = stability::lookup(ecx.tcx, ast_util::local_def(variant.node.id));
encode_stability(rbml_w, stab);
......@@ -948,6 +949,19 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
rbml_w.end_tag();
}
fn encode_repr_attrs(rbml_w: &mut Encoder,
ecx: &EncodeContext,
attrs: &[Attribute]) {
let mut repr_attrs = Vec::new();
for attr in attrs.iter() {
repr_attrs.extend(attr::find_repr_attrs(ecx.tcx.sess.diagnostic(),
attr).into_iter());
}
rbml_w.start_tag(tag_items_data_item_repr);
repr_attrs.encode(rbml_w);
rbml_w.end_tag();
}
fn encode_inlined_item(ecx: &EncodeContext,
rbml_w: &mut Encoder,
ii: InlinedItemRef) {
......@@ -1137,6 +1151,7 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(rbml_w, item.ident.name);
encode_attributes(rbml_w, item.attrs.as_slice());
encode_repr_attrs(rbml_w, ecx, item.attrs.as_slice());
for v in (*enum_definition).variants.iter() {
encode_variant_id(rbml_w, local_def(v.node.id));
}
......@@ -1183,6 +1198,7 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
encode_path(rbml_w, path.clone());
encode_stability(rbml_w, stab);
encode_visibility(rbml_w, vis);
encode_repr_attrs(rbml_w, ecx, item.attrs.as_slice());
/* Encode def_ids for each field and method
for methods, write all the stuff get_trait_method
......
......@@ -583,6 +583,9 @@ pub struct ctxt<'tcx> {
/// Caches the results of trait selection. This cache is used
/// for things that do not have to do with the parameters in scope.
pub selection_cache: traits::SelectionCache,
/// Caches the representation hints for struct definitions.
pub repr_hint_cache: RefCell<DefIdMap<Rc<Vec<attr::ReprAttr>>>>,
}
pub enum tbox_flag {
......@@ -1533,6 +1536,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
associated_types: RefCell::new(DefIdMap::new()),
trait_associated_types: RefCell::new(DefIdMap::new()),
selection_cache: traits::SelectionCache::new(),
repr_hint_cache: RefCell::new(DefIdMap::new()),
}
}
......@@ -4326,7 +4330,7 @@ pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
}
pub fn has_dtor(cx: &ctxt, struct_id: DefId) -> bool {
ty_dtor(cx, struct_id).is_present()
cx.destructor_for_type.borrow().contains_key(&struct_id)
}
pub fn with_path<T>(cx: &ctxt, id: ast::DefId, f: |ast_map::PathElems| -> T) -> T {
......@@ -4513,14 +4517,26 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
}
/// Obtain the representation annotation for a struct definition.
pub fn lookup_repr_hints(tcx: &ctxt, did: DefId) -> Vec<attr::ReprAttr> {
let mut acc = Vec::new();
pub fn lookup_repr_hints(tcx: &ctxt, did: DefId) -> Rc<Vec<attr::ReprAttr>> {
match tcx.repr_hint_cache.borrow().find(&did) {
None => {}
Some(ref hints) => return (*hints).clone(),
}
ty::each_attr(tcx, did, |meta| {
acc.extend(attr::find_repr_attrs(tcx.sess.diagnostic(), meta).into_iter());
true
});
let acc = if did.krate == LOCAL_CRATE {
let mut acc = Vec::new();
ty::each_attr(tcx, did, |meta| {
acc.extend(attr::find_repr_attrs(tcx.sess.diagnostic(),
meta).into_iter());
true
});
acc
} else {
csearch::get_repr_attrs(&tcx.sess.cstore, did)
};
let acc = Rc::new(acc);
tcx.repr_hint_cache.borrow_mut().insert(did, acc.clone());
acc
}
......
......@@ -508,7 +508,7 @@ fn int_type_of_word(s: &str) -> Option<IntType> {
}
}
#[deriving(PartialEq, Show)]
#[deriving(PartialEq, Show, Encodable, Decodable)]
pub enum ReprAttr {
ReprAny,
ReprInt(Span, IntType),
......@@ -527,7 +527,7 @@ pub fn is_ffi_safe(&self) -> bool {
}
}
#[deriving(Eq, Hash, PartialEq, Show)]
#[deriving(Eq, Hash, PartialEq, Show, Encodable, Decodable)]
pub enum IntType {
SignedInt(ast::IntTy),
UnsignedInt(ast::UintTy)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册