inline CrateLoader inside of CStore
This commit is contained in:
@@ -45,7 +45,7 @@ use rustc_attr_data_structures::StrippedCfgItem;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::sync::FreezeReadGuard;
|
||||
use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard};
|
||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||
use rustc_errors::{Applicability, Diag, ErrCode, ErrorGuaranteed};
|
||||
use rustc_expand::base::{DeriveResolution, SyntaxExtension, SyntaxExtensionKind};
|
||||
@@ -58,7 +58,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId,
|
||||
use rustc_hir::definitions::DisambiguatorState;
|
||||
use rustc_hir::{PrimTy, TraitCandidate};
|
||||
use rustc_index::bit_set::DenseBitSet;
|
||||
use rustc_metadata::creader::{CStore, CrateLoader};
|
||||
use rustc_metadata::creader::CStore;
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
||||
use rustc_middle::query::Providers;
|
||||
@@ -1110,7 +1110,6 @@ pub struct Resolver<'ra, 'tcx> {
|
||||
builtin_types_bindings: FxHashMap<Symbol, NameBinding<'ra>>,
|
||||
builtin_attrs_bindings: FxHashMap<Symbol, NameBinding<'ra>>,
|
||||
registered_tool_bindings: FxHashMap<Ident, NameBinding<'ra>>,
|
||||
used_extern_options: FxHashSet<Symbol>,
|
||||
macro_names: FxHashSet<Ident>,
|
||||
builtin_macros: FxHashMap<Symbol, SyntaxExtensionKind>,
|
||||
registered_tools: &'tcx RegisteredTools,
|
||||
@@ -1546,7 +1545,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
(*ident, binding)
|
||||
})
|
||||
.collect(),
|
||||
used_extern_options: Default::default(),
|
||||
macro_names: FxHashSet::default(),
|
||||
builtin_macros: Default::default(),
|
||||
registered_tools,
|
||||
@@ -1733,18 +1731,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
StableHashingContext::new(self.tcx.sess, self.tcx.untracked())
|
||||
}
|
||||
|
||||
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
|
||||
f(&mut CrateLoader::new(
|
||||
self.tcx,
|
||||
&mut CStore::from_tcx_mut(self.tcx),
|
||||
&mut self.used_extern_options,
|
||||
))
|
||||
}
|
||||
|
||||
fn cstore(&self) -> FreezeReadGuard<'_, CStore> {
|
||||
CStore::from_tcx(self.tcx)
|
||||
}
|
||||
|
||||
fn cstore_mut(&self) -> FreezeWriteGuard<'_, CStore> {
|
||||
CStore::from_tcx_mut(self.tcx)
|
||||
}
|
||||
|
||||
fn dummy_ext(&self, macro_kind: MacroKind) -> Arc<SyntaxExtension> {
|
||||
match macro_kind {
|
||||
MacroKind::Bang => Arc::clone(&self.dummy_ext_bang),
|
||||
@@ -1790,7 +1784,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
self.tcx.sess.time("resolve_report_errors", || self.report_errors(krate));
|
||||
self.tcx
|
||||
.sess
|
||||
.time("resolve_postprocess", || self.crate_loader(|c| c.postprocess(krate)));
|
||||
.time("resolve_postprocess", || self.cstore_mut().postprocess(self.tcx, krate));
|
||||
});
|
||||
|
||||
// Make sure we don't mutate the cstore from here on.
|
||||
@@ -2156,7 +2150,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
Some(if let Some(binding) = entry.binding {
|
||||
if finalize {
|
||||
if !entry.is_import() {
|
||||
self.crate_loader(|c| c.process_path_extern(ident.name, ident.span));
|
||||
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span);
|
||||
} else if entry.introduced_by_item {
|
||||
self.record_use(ident, binding, Used::Other);
|
||||
}
|
||||
@@ -2165,13 +2159,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
} else {
|
||||
let crate_id = if finalize {
|
||||
let Some(crate_id) =
|
||||
self.crate_loader(|c| c.process_path_extern(ident.name, ident.span))
|
||||
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span)
|
||||
else {
|
||||
return Some(self.dummy_binding);
|
||||
};
|
||||
crate_id
|
||||
} else {
|
||||
self.crate_loader(|c| c.maybe_process_path_extern(ident.name))?
|
||||
self.cstore_mut().maybe_process_path_extern(self.tcx, ident.name)?
|
||||
};
|
||||
let res = Res::Def(DefKind::Mod, crate_id.as_def_id());
|
||||
self.arenas.new_pub_res_binding(res, DUMMY_SP, LocalExpnId::ROOT)
|
||||
|
||||
Reference in New Issue
Block a user