Make untracked.cstore lockable so that resolution can still write to it when using TyCtxt
This commit is contained in:
parent
e8e227aec8
commit
ade3dceb38
9 changed files with 50 additions and 36 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::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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue