Skip to content

Commit

Permalink
Remove attribute_cache from CrateMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfin committed May 18, 2018
1 parent df40e61 commit f418f1d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ impl<'a> CrateLoader<'a> {
cnum,
dependencies: Lock::new(dependencies),
codemap_import_info: RwLock::new(vec![]),
attribute_cache: Lock::new([Vec::new(), Vec::new()]),
dep_kind: Lock::new(dep_kind),
source: cstore::CrateSource {
dylib,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub struct CrateMetadata {
pub cnum: CrateNum,
pub dependencies: Lock<Vec<CrateNum>>,
pub codemap_import_info: RwLock<Vec<ImportedFileMap>>,
pub attribute_cache: Lock<[Vec<Option<Lrc<[ast::Attribute]>>>; 2]>,

pub root: schema::CrateRoot,

Expand Down
28 changes: 8 additions & 20 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,34 +880,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> {
Expand Down

0 comments on commit f418f1d

Please sign in to comment.