Auto merge of #108992 - petrochenkov:qcstore2, r=cjgillot
resolve: Querify most cstore access methods (subset) A subset of https://github.com/rust-lang/rust/pull/108346 that is not on a hot path in any way.
This commit is contained in:
commit
bd43458d4c
11 changed files with 169 additions and 250 deletions
|
@ -8,7 +8,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
|
|||
use rustc_ast::{self as ast, *};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::MappedReadGuard;
|
||||
use rustc_data_structures::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard, WriteGuard};
|
||||
use rustc_expand::base::SyntaxExtension;
|
||||
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::Definitions;
|
||||
|
@ -133,8 +133,14 @@ impl<'a> std::fmt::Debug for CrateDump<'a> {
|
|||
|
||||
impl CStore {
|
||||
pub fn from_tcx(tcx: TyCtxt<'_>) -> MappedReadGuard<'_, CStore> {
|
||||
MappedReadGuard::map(tcx.cstore_untracked(), |c| {
|
||||
c.as_any().downcast_ref::<CStore>().expect("`tcx.cstore` is not a `CStore`")
|
||||
ReadGuard::map(tcx.untracked().cstore.read(), |cstore| {
|
||||
cstore.as_any().downcast_ref::<CStore>().expect("`tcx.cstore` is not a `CStore`")
|
||||
})
|
||||
}
|
||||
|
||||
pub fn from_tcx_mut(tcx: TyCtxt<'_>) -> MappedWriteGuard<'_, CStore> {
|
||||
WriteGuard::map(tcx.untracked().cstore.write(), |cstore| {
|
||||
cstore.untracked_as_any().downcast_mut().expect("`tcx.cstore` is not a `CStore`")
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -268,9 +274,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
|
|||
) -> Self {
|
||||
CrateLoader { tcx, cstore, used_extern_options }
|
||||
}
|
||||
pub fn cstore(&self) -> &CStore {
|
||||
&self.cstore
|
||||
}
|
||||
|
||||
fn existing_match(&self, name: Symbol, hash: Option<Svh>, kind: PathKind) -> Option<CrateNum> {
|
||||
for (cnum, data) in self.cstore.iter_crate_data() {
|
||||
|
|
|
@ -30,7 +30,6 @@ use rustc_session::cstore::{
|
|||
};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::ExpnIndex;
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::{self, BytePos, ExpnId, Pos, Span, SyntaxContext, DUMMY_SP};
|
||||
|
||||
|
@ -930,7 +929,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||
self.root.tables.generics_of.get(self, item_id).unwrap().decode((self, sess))
|
||||
}
|
||||
|
||||
fn get_visibility(self, id: DefIndex) -> ty::Visibility<DefId> {
|
||||
fn get_visibility(self, id: DefIndex) -> Visibility<DefId> {
|
||||
self.root
|
||||
.tables
|
||||
.visibility
|
||||
|
@ -1134,33 +1133,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||
.decode((self, sess))
|
||||
}
|
||||
|
||||
fn get_struct_field_names(
|
||||
self,
|
||||
id: DefIndex,
|
||||
sess: &'a Session,
|
||||
) -> impl Iterator<Item = Spanned<Symbol>> + 'a {
|
||||
self.root
|
||||
.tables
|
||||
.children
|
||||
.get(self, id)
|
||||
.expect("fields not encoded for a struct")
|
||||
.decode(self)
|
||||
.map(move |index| respan(self.get_span(index, sess), self.item_name(index)))
|
||||
}
|
||||
|
||||
fn get_struct_field_visibilities(
|
||||
self,
|
||||
id: DefIndex,
|
||||
) -> impl Iterator<Item = Visibility<DefId>> + 'a {
|
||||
self.root
|
||||
.tables
|
||||
.children
|
||||
.get(self, id)
|
||||
.expect("fields not encoded for a struct")
|
||||
.decode(self)
|
||||
.map(move |field_index| self.get_visibility(field_index))
|
||||
}
|
||||
|
||||
fn get_inherent_implementations_for_type(
|
||||
self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
|
|
@ -15,12 +15,12 @@ use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
|||
use rustc_middle::middle::stability::DeprecationEntry;
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||
use rustc_middle::ty::{self, TyCtxt, Visibility};
|
||||
use rustc_session::cstore::{CrateSource, CrateStore};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::cstore::CrateStore;
|
||||
use rustc_session::{Session, StableCrateId};
|
||||
use rustc_span::hygiene::{ExpnHash, ExpnId};
|
||||
use rustc_span::source_map::{Span, Spanned};
|
||||
use rustc_span::symbol::{kw, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use std::any::Any;
|
||||
|
@ -501,35 +501,18 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
|||
tcx.arena
|
||||
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
|
||||
},
|
||||
crates: |tcx, ()| tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).crates_untracked()),
|
||||
crates: |tcx, ()| {
|
||||
tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum))
|
||||
},
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
||||
impl CStore {
|
||||
pub fn struct_field_names_untracked<'a>(
|
||||
&'a self,
|
||||
def: DefId,
|
||||
sess: &'a Session,
|
||||
) -> impl Iterator<Item = Spanned<Symbol>> + 'a {
|
||||
self.get_crate_data(def.krate).get_struct_field_names(def.index, sess)
|
||||
}
|
||||
|
||||
pub fn struct_field_visibilities_untracked(
|
||||
&self,
|
||||
def: DefId,
|
||||
) -> impl Iterator<Item = Visibility<DefId>> + '_ {
|
||||
self.get_crate_data(def.krate).get_struct_field_visibilities(def.index)
|
||||
}
|
||||
|
||||
pub fn ctor_untracked(&self, def: DefId) -> Option<(CtorKind, DefId)> {
|
||||
self.get_crate_data(def.krate).get_ctor(def.index)
|
||||
}
|
||||
|
||||
pub fn visibility_untracked(&self, def: DefId) -> Visibility<DefId> {
|
||||
self.get_crate_data(def.krate).get_visibility(def.index)
|
||||
}
|
||||
|
||||
pub fn module_children_untracked<'a>(
|
||||
&'a self,
|
||||
def_id: DefId,
|
||||
|
@ -566,14 +549,6 @@ impl CStore {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn fn_has_self_parameter_untracked(&self, def: DefId, sess: &Session) -> bool {
|
||||
self.get_crate_data(def.krate).get_fn_has_self_parameter(def.index, sess)
|
||||
}
|
||||
|
||||
pub fn crate_source_untracked(&self, cnum: CrateNum) -> Lrc<CrateSource> {
|
||||
self.get_crate_data(cnum).source.clone()
|
||||
}
|
||||
|
||||
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
|
||||
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
|
||||
}
|
||||
|
@ -582,10 +557,6 @@ impl CStore {
|
|||
self.get_crate_data(def.krate).def_kind(def.index)
|
||||
}
|
||||
|
||||
pub fn crates_untracked(&self) -> impl Iterator<Item = CrateNum> + '_ {
|
||||
self.iter_crate_data().map(|(cnum, _)| cnum)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue