Stop passing in values that one can also get from the tcx lazily
This commit is contained in:
parent
c3522d0637
commit
acbcfaaf7b
3 changed files with 23 additions and 34 deletions
|
@ -571,13 +571,7 @@ fn resolver_for_lowering<'tcx>(
|
|||
) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
|
||||
let arenas = Resolver::arenas();
|
||||
let krate = tcx.crate_for_resolver(()).steal();
|
||||
let mut resolver = Resolver::new(
|
||||
tcx,
|
||||
&krate,
|
||||
tcx.crate_name(LOCAL_CRATE),
|
||||
tcx.metadata_loader(()).steal(),
|
||||
&arenas,
|
||||
);
|
||||
let mut resolver = Resolver::new(tcx, &krate, &arenas);
|
||||
let krate = configure_and_expand(tcx, krate, &mut resolver);
|
||||
|
||||
// Make sure we don't mutate the cstore from here on.
|
||||
|
|
|
@ -15,8 +15,8 @@ use rustc_hir::definitions::Definitions;
|
|||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::{self, CrateType, ExternLocation};
|
||||
use rustc_session::cstore::ExternCrateSource;
|
||||
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate};
|
||||
use rustc_session::cstore::{ExternCrateSource, MetadataLoaderDyn};
|
||||
use rustc_session::lint;
|
||||
use rustc_session::output::validate_crate_name;
|
||||
use rustc_session::search_paths::PathKind;
|
||||
|
@ -60,16 +60,22 @@ impl std::fmt::Debug for CStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CrateLoader<'a> {
|
||||
pub struct CrateLoader<'a, 'tcx: 'a> {
|
||||
// Immutable configuration.
|
||||
sess: &'a Session,
|
||||
metadata_loader: &'a MetadataLoaderDyn,
|
||||
local_crate_name: Symbol,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
// Mutable output.
|
||||
cstore: &'a mut CStore,
|
||||
used_extern_options: &'a mut FxHashSet<Symbol>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> std::ops::Deref for CrateLoader<'a, 'tcx> {
|
||||
type Target = TyCtxt<'tcx>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.tcx
|
||||
}
|
||||
}
|
||||
|
||||
pub enum LoadedMacro {
|
||||
MacroDef(ast::Item, Edition),
|
||||
ProcMacro(SyntaxExtension),
|
||||
|
@ -254,15 +260,13 @@ impl CStore {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> CrateLoader<'a> {
|
||||
impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
|
||||
pub fn new(
|
||||
sess: &'a Session,
|
||||
metadata_loader: &'a MetadataLoaderDyn,
|
||||
local_crate_name: Symbol,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cstore: &'a mut CStore,
|
||||
used_extern_options: &'a mut FxHashSet<Symbol>,
|
||||
) -> Self {
|
||||
CrateLoader { sess, metadata_loader, local_crate_name, cstore, used_extern_options }
|
||||
CrateLoader { tcx, cstore, used_extern_options }
|
||||
}
|
||||
pub fn cstore(&self) -> &CStore {
|
||||
&self.cstore
|
||||
|
@ -553,9 +557,10 @@ impl<'a> CrateLoader<'a> {
|
|||
(LoadResult::Previous(cnum), None)
|
||||
} else {
|
||||
info!("falling back to a load");
|
||||
let metadata_loader = self.tcx.metadata_loader(()).borrow();
|
||||
let mut locator = CrateLocator::new(
|
||||
self.sess,
|
||||
&*self.metadata_loader,
|
||||
&**metadata_loader,
|
||||
name,
|
||||
hash,
|
||||
extra_filename,
|
||||
|
@ -960,7 +965,7 @@ impl<'a> CrateLoader<'a> {
|
|||
&format!(
|
||||
"external crate `{}` unused in `{}`: remove the dependency or add `use {} as _;`",
|
||||
name,
|
||||
self.local_crate_name,
|
||||
self.tcx.crate_name(LOCAL_CRATE),
|
||||
name),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ use rustc_middle::span_bug;
|
|||
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, TyCtxt};
|
||||
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn, Untracked};
|
||||
use rustc_session::cstore::{CrateStore, Untracked};
|
||||
use rustc_session::lint::LintBuffer;
|
||||
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
|
||||
use rustc_span::source_map::Spanned;
|
||||
|
@ -955,8 +955,6 @@ pub struct Resolver<'a, 'tcx> {
|
|||
arenas: &'a ResolverArenas<'a>,
|
||||
dummy_binding: &'a NameBinding<'a>,
|
||||
|
||||
local_crate_name: Symbol,
|
||||
metadata_loader: Box<MetadataLoaderDyn>,
|
||||
used_extern_options: FxHashSet<Symbol>,
|
||||
macro_names: FxHashSet<Ident>,
|
||||
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
|
||||
|
@ -1203,8 +1201,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
krate: &Crate,
|
||||
crate_name: Symbol,
|
||||
metadata_loader: Box<MetadataLoaderDyn>,
|
||||
arenas: &'a ResolverArenas<'a>,
|
||||
) -> Resolver<'a, 'tcx> {
|
||||
let root_def_id = CRATE_DEF_ID.to_def_id();
|
||||
|
@ -1312,8 +1308,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
vis: ty::Visibility::Public,
|
||||
}),
|
||||
|
||||
metadata_loader,
|
||||
local_crate_name: crate_name,
|
||||
used_extern_options: Default::default(),
|
||||
macro_names: FxHashSet::default(),
|
||||
builtin_macros: Default::default(),
|
||||
|
@ -1464,14 +1458,10 @@ impl<'a, 'tcx> Resolver<'a, '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.sess,
|
||||
&*self.metadata_loader,
|
||||
self.local_crate_name,
|
||||
&mut *self.tcx.untracked().cstore.write().untracked_as_any().downcast_mut().unwrap(),
|
||||
&mut self.used_extern_options,
|
||||
))
|
||||
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
|
||||
let mut cstore = self.tcx.untracked().cstore.write();
|
||||
let cstore = cstore.untracked_as_any().downcast_mut().unwrap();
|
||||
f(&mut CrateLoader::new(self.tcx, &mut *cstore, &mut self.used_extern_options))
|
||||
}
|
||||
|
||||
fn cstore(&self) -> MappedReadGuard<'_, CStore> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue