1
Fork 0

Make untracked.cstore lockable so that resolution can still write to it when using TyCtxt

This commit is contained in:
Oli Scherer 2022-12-08 10:53:20 +00:00
parent e8e227aec8
commit ade3dceb38
9 changed files with 50 additions and 36 deletions

View file

@ -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::ReadGuard;
use rustc_data_structures::sync::{MappedReadGuard, ReadGuard};
use rustc_expand::base::SyntaxExtension;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
use rustc_hir::definitions::Definitions;
@ -127,11 +127,10 @@ impl<'a> std::fmt::Debug for CrateDump<'a> {
}
impl CStore {
pub fn from_tcx(tcx: TyCtxt<'_>) -> &CStore {
tcx.cstore_untracked()
.as_any()
.downcast_ref::<CStore>()
.expect("`tcx.cstore` is not a `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`")
})
}
fn alloc_new_crate_num(&mut self) -> CrateNum {

View file

@ -130,7 +130,13 @@ macro_rules! provide_one {
$tcx.ensure().crate_hash($def_id.krate);
}
let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
let cdata = rustc_data_structures::sync::MappedReadGuard::map(CStore::from_tcx($tcx), |c| {
c.get_crate_data($def_id.krate).cdata
});
let $cdata = crate::creader::CrateMetadataRef {
cdata: &cdata,
cstore: &CStore::from_tcx($tcx),
};
$compute
}