1
Fork 0

Rollup merge of #109137 - petrochenkov:qcstore2, r=cjgillot

resolve: Querify most cstore access methods (subset 2)

These changes are less likely to cause perf regressions than the rest of https://github.com/rust-lang/rust/pull/108346.
This commit is contained in:
Matthias Krüger 2023-03-23 08:35:34 +01:00 committed by GitHub
commit 3e33fb9f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 47 deletions

View file

@ -925,10 +925,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
tcx.mk_adt_def(did, adt_kind, variants, repr) tcx.mk_adt_def(did, adt_kind, variants, repr)
} }
fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics {
self.root.tables.generics_of.get(self, item_id).unwrap().decode((self, sess))
}
fn get_visibility(self, id: DefIndex) -> Visibility<DefId> { fn get_visibility(self, id: DefIndex) -> Visibility<DefId> {
self.root self.root
.tables .tables

View file

@ -545,10 +545,6 @@ impl CStore {
self.get_crate_data(def.krate).def_kind(def.index) self.get_crate_data(def.krate).def_kind(def.index)
} }
pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
}
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId { pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess) self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
} }
@ -560,14 +556,6 @@ impl CStore {
self.get_crate_data(cnum).num_def_ids() self.get_crate_data(cnum).num_def_ids()
} }
pub fn item_attrs_untracked<'a>(
&'a self,
def_id: DefId,
sess: &'a Session,
) -> impl Iterator<Item = ast::Attribute> + 'a {
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess)
}
pub fn get_proc_macro_quoted_span_untracked( pub fn get_proc_macro_quoted_span_untracked(
&self, &self,
cnum: CrateNum, cnum: CrateNum,

View file

@ -27,7 +27,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_metadata::creader::LoadedMacro; use rustc_metadata::creader::LoadedMacro;
use rustc_middle::metadata::ModChild; use rustc_middle::metadata::ModChild;
use rustc_middle::{bug, ty}; use rustc_middle::{bug, ty};
use rustc_session::cstore::CrateStore;
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
@ -116,34 +115,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if !def_id.is_local() { if !def_id.is_local() {
let def_kind = self.cstore().def_kind(def_id); let def_kind = self.cstore().def_kind(def_id);
match def_kind { if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind {
DefKind::Mod | DefKind::Enum | DefKind::Trait => { let parent = self
let def_key = self.cstore().def_key(def_id); .tcx
let parent = def_key.parent.map(|index| { .opt_parent(def_id)
self.get_nearest_non_block_module(DefId { index, krate: def_id.krate }) .map(|parent_id| self.get_nearest_non_block_module(parent_id));
});
let name = if let Some(cnum) = def_id.as_crate_root() {
self.cstore().crate_name(cnum)
} else {
def_key.disambiguated_data.data.get_opt_name().expect("module without name")
};
let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess); let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess);
Some(self.new_module( return Some(self.new_module(
parent, parent,
ModuleKind::Def(def_kind, def_id, name), ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)),
expn_id, expn_id,
self.def_span(def_id), self.def_span(def_id),
// FIXME: Account for `#[no_implicit_prelude]` attributes. // FIXME: Account for `#[no_implicit_prelude]` attributes.
parent.map_or(false, |module| module.no_implicit_prelude), parent.map_or(false, |module| module.no_implicit_prelude),
)) ));
} }
_ => None,
} }
} else {
None None
} }
}
pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> { pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {
match expn_id.expn_data().macro_def_id { match expn_id.expn_data().macro_def_id {

View file

@ -1168,7 +1168,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
if let Some(def_id) = def_id.as_local() { if let Some(def_id) = def_id.as_local() {
self.item_generics_num_lifetimes[&def_id] self.item_generics_num_lifetimes[&def_id]
} else { } else {
self.cstore().item_generics_num_lifetimes(def_id, self.tcx.sess) self.tcx.generics_of(def_id).own_counts().lifetimes
} }
} }
@ -1906,10 +1906,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return v.clone(); return v.clone();
} }
let attr = self let attr = self.tcx.get_attr(def_id, sym::rustc_legacy_const_generics)?;
.cstore()
.item_attrs_untracked(def_id, self.tcx.sess)
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
let mut ret = Vec::new(); let mut ret = Vec::new();
for meta in attr.meta_item_list()? { for meta in attr.meta_item_list()? {
match meta.lit()?.kind { match meta.lit()?.kind {