diff options
| author | bors <bors@rust-lang.org> | 2018-05-23 09:50:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-23 09:50:54 +0000 |
| commit | c3733a770edb1eb0f8b8943e7a0a962f4e1e91a8 (patch) | |
| tree | dc8ba9d188e17a846d71843998fe12d6f5c6b5d0 /src/librustc_metadata/decoder.rs | |
| parent | 531e4ab7bc1a9064ae0b77ba16a9cd46832194e6 (diff) | |
| parent | d95ba305b474a724e041df6d7ffd74bf3199d296 (diff) | |
Auto merge of #50528 - whitfin:issue-50508, r=michaelwoerister
Remove attribute_cache from CrateMetadata This PR will fix #50508 by removing the `attribute_cache` from the `CrateMetadata` struct. Seeing as performance was referenced in the original issue, I also cleaned up a `self.entry(node_id);` call which might have occasionally happened redundantly. r? @michaelwoerister
Diffstat (limited to 'src/librustc_metadata/decoder.rs')
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 53d1ff15627..8af4649ed5f 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -557,12 +557,14 @@ impl<'a, 'tcx> CrateMetadata { -> &'tcx ty::AdtDef { let item = self.entry(item_id); let did = self.local_def_id(item_id); - let kind = match item.kind { - EntryKind::Enum(_) => ty::AdtKind::Enum, - EntryKind::Struct(_, _) => ty::AdtKind::Struct, - EntryKind::Union(_, _) => ty::AdtKind::Union, + + let (kind, repr) = match item.kind { + EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr), + EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr), + EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr), _ => bug!("get_adt_def called on a non-ADT {:?}", did), }; + let variants = if let ty::AdtKind::Enum = kind { item.children .decode(self) @@ -573,12 +575,6 @@ impl<'a, 'tcx> CrateMetadata { } else { vec![self.get_variant(&item, item_id)] }; - let (kind, repr) = match item.kind { - EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr), - EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr), - EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr), - _ => bug!("get_adt_def called on a non-ADT {:?}", did), - }; tcx.alloc_adt_def(did, kind, variants, repr) } @@ -880,34 +876,22 @@ impl<'a, 'tcx> CrateMetadata { } pub fn get_item_attrs(&self, node_id: DefIndex, sess: &Session) -> Lrc<[ast::Attribute]> { - let (node_as, node_index) = - (node_id.address_space().index(), node_id.as_array_index()); if self.is_proc_macro(node_id) { return Lrc::new([]); } - if let Some(&Some(ref val)) = - self.attribute_cache.borrow()[node_as].get(node_index) { - return val.clone(); - } - // The attributes for a tuple struct are attached to the definition, not the ctor; // we assume that someone passing in a tuple struct ctor is actually wanting to // look at the definition - let mut item = self.entry(node_id); let def_key = self.def_key(node_id); - if def_key.disambiguated_data.data == DefPathData::StructCtor { - item = self.entry(def_key.parent.unwrap()); - } - let result: Lrc<[ast::Attribute]> = Lrc::from(self.get_attributes(&item, sess)); - let vec_ = &mut self.attribute_cache.borrow_mut()[node_as]; - if vec_.len() < node_index + 1 { - vec_.resize(node_index + 1, None); - } - // This can overwrite the result produced by another thread, but the value - // written should be the same - vec_[node_index] = Some(result.clone()); - result + let item_id = if def_key.disambiguated_data.data == DefPathData::StructCtor { + def_key.parent.unwrap() + } else { + node_id + }; + + let item = self.entry(item_id); + Lrc::from(self.get_attributes(&item, sess)) } pub fn get_struct_field_names(&self, id: DefIndex) -> Vec<ast::Name> { |
