rustc_metadata: Make attribute decoding slightly faster and stricter
Rename `CStore::item_attrs` -> `CStore::item_attrs_untracked` top follow conventions
This commit is contained in:
parent
636fd495c8
commit
4c6120c386
4 changed files with 24 additions and 22 deletions
|
@ -1309,24 +1309,26 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
|
|
||||||
fn get_item_attrs(
|
fn get_item_attrs(
|
||||||
&'a self,
|
&'a self,
|
||||||
node_id: DefIndex,
|
id: DefIndex,
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
) -> impl Iterator<Item = ast::Attribute> + 'a {
|
) -> impl Iterator<Item = ast::Attribute> + 'a {
|
||||||
// The attributes for a tuple struct/variant 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 def_key = self.def_key(node_id);
|
|
||||||
let item_id = if def_key.disambiguated_data.data == DefPathData::Ctor {
|
|
||||||
def_key.parent.unwrap()
|
|
||||||
} else {
|
|
||||||
node_id
|
|
||||||
};
|
|
||||||
|
|
||||||
self.root
|
self.root
|
||||||
.tables
|
.tables
|
||||||
.attributes
|
.attributes
|
||||||
.get(self, item_id)
|
.get(self, id)
|
||||||
.unwrap_or_else(Lazy::empty)
|
.unwrap_or_else(|| {
|
||||||
|
// Structure and variant constructors don't have any attributes encoded for them,
|
||||||
|
// but we assume that someone passing a constructor ID actually wants to look at
|
||||||
|
// the attributes on the corresponding struct or variant.
|
||||||
|
let def_key = self.def_key(id);
|
||||||
|
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
|
||||||
|
let parent_id = def_key.parent.expect("no parent for a constructor");
|
||||||
|
self.root
|
||||||
|
.tables
|
||||||
|
.attributes
|
||||||
|
.get(self, parent_id)
|
||||||
|
.expect("no encoded attributes for a structure or variant")
|
||||||
|
})
|
||||||
.decode((self, sess))
|
.decode((self, sess))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
lookup_deprecation_entry => {
|
lookup_deprecation_entry => {
|
||||||
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
||||||
}
|
}
|
||||||
item_attrs => { tcx.arena.alloc_from_iter(
|
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
|
||||||
cdata.get_item_attrs(def_id.index, tcx.sess)
|
|
||||||
) }
|
|
||||||
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
|
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
|
||||||
rendered_const => { cdata.get_rendered_const(def_id.index) }
|
rendered_const => { cdata.get_rendered_const(def_id.index) }
|
||||||
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
||||||
|
@ -470,7 +468,7 @@ impl CStore {
|
||||||
self.get_crate_data(cnum).num_def_ids()
|
self.get_crate_data(cnum).num_def_ids()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
|
pub fn item_attrs_untracked(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
|
||||||
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
|
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -895,8 +895,11 @@ impl<'a> Resolver<'a> {
|
||||||
// a note about editions
|
// a note about editions
|
||||||
let note = if let Some(did) = did {
|
let note = if let Some(did) = did {
|
||||||
let requires_note = !did.is_local()
|
let requires_note = !did.is_local()
|
||||||
&& this.cstore().item_attrs(did, this.session).iter().any(
|
&& this
|
||||||
|attr| {
|
.cstore()
|
||||||
|
.item_attrs_untracked(did, this.session)
|
||||||
|
.iter()
|
||||||
|
.any(|attr| {
|
||||||
if attr.has_name(sym::rustc_diagnostic_item) {
|
if attr.has_name(sym::rustc_diagnostic_item) {
|
||||||
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
||||||
.map(|x| Some(x))
|
.map(|x| Some(x))
|
||||||
|
@ -904,8 +907,7 @@ impl<'a> Resolver<'a> {
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
requires_note.then(|| {
|
requires_note.then(|| {
|
||||||
format!(
|
format!(
|
||||||
|
|
|
@ -3420,7 +3420,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
let attr = self
|
let attr = self
|
||||||
.cstore()
|
.cstore()
|
||||||
.item_attrs(def_id, self.session)
|
.item_attrs_untracked(def_id, self.session)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
|
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue