Skip to content

Commit abed56d

Browse files
committed
Auto merge of #50528 - whitfin:issue-50508, r=<try>
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
2 parents 295d980 + 1307f7b commit abed56d

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

src/librustc_metadata/creader.rs

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ impl<'a> CrateLoader<'a> {
242242
cnum_map: Lock::new(cnum_map),
243243
cnum,
244244
codemap_import_info: RwLock::new(vec![]),
245-
attribute_cache: Lock::new([Vec::new(), Vec::new()]),
246245
dep_kind: Lock::new(dep_kind),
247246
source: cstore::CrateSource {
248247
dylib,

src/librustc_metadata/cstore.rs

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ pub struct CrateMetadata {
6767
pub cnum_map: Lock<CrateNumMap>,
6868
pub cnum: CrateNum,
6969
pub codemap_import_info: RwLock<Vec<ImportedFileMap>>,
70-
pub attribute_cache: Lock<[Vec<Option<Lrc<[ast::Attribute]>>>; 2]>,
7170

7271
pub root: schema::CrateRoot,
7372

src/librustc_metadata/decoder.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -880,34 +880,22 @@ impl<'a, 'tcx> CrateMetadata {
880880
}
881881

882882
pub fn get_item_attrs(&self, node_id: DefIndex, sess: &Session) -> Lrc<[ast::Attribute]> {
883-
let (node_as, node_index) =
884-
(node_id.address_space().index(), node_id.as_array_index());
885883
if self.is_proc_macro(node_id) {
886884
return Lrc::new([]);
887885
}
888886

889-
if let Some(&Some(ref val)) =
890-
self.attribute_cache.borrow()[node_as].get(node_index) {
891-
return val.clone();
892-
}
893-
894887
// The attributes for a tuple struct are attached to the definition, not the ctor;
895888
// we assume that someone passing in a tuple struct ctor is actually wanting to
896889
// look at the definition
897-
let mut item = self.entry(node_id);
898890
let def_key = self.def_key(node_id);
899-
if def_key.disambiguated_data.data == DefPathData::StructCtor {
900-
item = self.entry(def_key.parent.unwrap());
901-
}
902-
let result: Lrc<[ast::Attribute]> = Lrc::from(self.get_attributes(&item, sess));
903-
let vec_ = &mut self.attribute_cache.borrow_mut()[node_as];
904-
if vec_.len() < node_index + 1 {
905-
vec_.resize(node_index + 1, None);
906-
}
907-
// This can overwrite the result produced by another thread, but the value
908-
// written should be the same
909-
vec_[node_index] = Some(result.clone());
910-
result
891+
let item_id = if def_key.disambiguated_data.data == DefPathData::StructCtor {
892+
def_key.parent.unwrap()
893+
} else {
894+
node_id
895+
};
896+
897+
let item = self.entry(item_id);
898+
Lrc::from(self.get_attributes(&item, sess))
911899
}
912900

913901
pub fn get_struct_field_names(&self, id: DefIndex) -> Vec<ast::Name> {

0 commit comments

Comments
 (0)