Skip to content

Commit cc3f4c0

Browse files
authored
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 #108346.
2 parents 7f2eea3 + 18b59f5 commit cc3f4c0

File tree

4 files changed

+18
-47
lines changed

4 files changed

+18
-47
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

-4
Original file line numberDiff line numberDiff line change
@@ -925,10 +925,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
925925
tcx.mk_adt_def(did, adt_kind, variants, repr)
926926
}
927927

928-
fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics {
929-
self.root.tables.generics_of.get(self, item_id).unwrap().decode((self, sess))
930-
}
931-
932928
fn get_visibility(self, id: DefIndex) -> Visibility<DefId> {
933929
self.root
934930
.tables

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-12
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,6 @@ impl CStore {
557557
self.get_crate_data(def.krate).def_kind(def.index)
558558
}
559559

560-
pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
561-
self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
562-
}
563-
564560
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
565561
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
566562
}
@@ -572,14 +568,6 @@ impl CStore {
572568
self.get_crate_data(cnum).num_def_ids()
573569
}
574570

575-
pub fn item_attrs_untracked<'a>(
576-
&'a self,
577-
def_id: DefId,
578-
sess: &'a Session,
579-
) -> impl Iterator<Item = ast::Attribute> + 'a {
580-
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess)
581-
}
582-
583571
pub fn get_proc_macro_quoted_span_untracked(
584572
&self,
585573
cnum: CrateNum,

compiler/rustc_resolve/src/build_reduced_graph.rs

+16-26
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
2727
use rustc_metadata::creader::LoadedMacro;
2828
use rustc_middle::metadata::ModChild;
2929
use rustc_middle::{bug, ty};
30-
use rustc_session::cstore::CrateStore;
3130
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
3231
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3332
use rustc_span::Span;
@@ -116,33 +115,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
116115

117116
if !def_id.is_local() {
118117
let def_kind = self.cstore().def_kind(def_id);
119-
match def_kind {
120-
DefKind::Mod | DefKind::Enum | DefKind::Trait => {
121-
let def_key = self.cstore().def_key(def_id);
122-
let parent = def_key.parent.map(|index| {
123-
self.get_nearest_non_block_module(DefId { index, krate: def_id.krate })
124-
});
125-
let name = if let Some(cnum) = def_id.as_crate_root() {
126-
self.cstore().crate_name(cnum)
127-
} else {
128-
def_key.disambiguated_data.data.get_opt_name().expect("module without name")
129-
};
130-
131-
let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess);
132-
Some(self.new_module(
133-
parent,
134-
ModuleKind::Def(def_kind, def_id, name),
135-
expn_id,
136-
self.def_span(def_id),
137-
// FIXME: Account for `#[no_implicit_prelude]` attributes.
138-
parent.map_or(false, |module| module.no_implicit_prelude),
139-
))
140-
}
141-
_ => None,
118+
if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind {
119+
let parent = self
120+
.tcx
121+
.opt_parent(def_id)
122+
.map(|parent_id| self.get_nearest_non_block_module(parent_id));
123+
let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess);
124+
return Some(self.new_module(
125+
parent,
126+
ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)),
127+
expn_id,
128+
self.def_span(def_id),
129+
// FIXME: Account for `#[no_implicit_prelude]` attributes.
130+
parent.map_or(false, |module| module.no_implicit_prelude),
131+
));
142132
}
143-
} else {
144-
None
145133
}
134+
135+
None
146136
}
147137

148138
pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {

compiler/rustc_resolve/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
11681168
if let Some(def_id) = def_id.as_local() {
11691169
self.item_generics_num_lifetimes[&def_id]
11701170
} else {
1171-
self.cstore().item_generics_num_lifetimes(def_id, self.tcx.sess)
1171+
self.tcx.generics_of(def_id).own_counts().lifetimes
11721172
}
11731173
}
11741174

@@ -1910,10 +1910,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19101910
return v.clone();
19111911
}
19121912

1913-
let attr = self
1914-
.cstore()
1915-
.item_attrs_untracked(def_id, self.tcx.sess)
1916-
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
1913+
let attr = self.tcx.get_attr(def_id, sym::rustc_legacy_const_generics)?;
19171914
let mut ret = Vec::new();
19181915
for meta in attr.meta_item_list()? {
19191916
match meta.lit()?.kind {

0 commit comments

Comments
 (0)