Skip to content

Commit acbcfaa

Browse files
committed
Stop passing in values that one can also get from the tcx lazily
1 parent c3522d0 commit acbcfaa

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,7 @@ fn resolver_for_lowering<'tcx>(
571571
) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
572572
let arenas = Resolver::arenas();
573573
let krate = tcx.crate_for_resolver(()).steal();
574-
let mut resolver = Resolver::new(
575-
tcx,
576-
&krate,
577-
tcx.crate_name(LOCAL_CRATE),
578-
tcx.metadata_loader(()).steal(),
579-
&arenas,
580-
);
574+
let mut resolver = Resolver::new(tcx, &krate, &arenas);
581575
let krate = configure_and_expand(tcx, krate, &mut resolver);
582576

583577
// Make sure we don't mutate the cstore from here on.

compiler/rustc_metadata/src/creader.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_hir::definitions::Definitions;
1515
use rustc_index::vec::IndexVec;
1616
use rustc_middle::ty::TyCtxt;
1717
use rustc_session::config::{self, CrateType, ExternLocation};
18+
use rustc_session::cstore::ExternCrateSource;
1819
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate};
19-
use rustc_session::cstore::{ExternCrateSource, MetadataLoaderDyn};
2020
use rustc_session::lint;
2121
use rustc_session::output::validate_crate_name;
2222
use rustc_session::search_paths::PathKind;
@@ -60,16 +60,22 @@ impl std::fmt::Debug for CStore {
6060
}
6161
}
6262

63-
pub struct CrateLoader<'a> {
63+
pub struct CrateLoader<'a, 'tcx: 'a> {
6464
// Immutable configuration.
65-
sess: &'a Session,
66-
metadata_loader: &'a MetadataLoaderDyn,
67-
local_crate_name: Symbol,
65+
tcx: TyCtxt<'tcx>,
6866
// Mutable output.
6967
cstore: &'a mut CStore,
7068
used_extern_options: &'a mut FxHashSet<Symbol>,
7169
}
7270

71+
impl<'a, 'tcx> std::ops::Deref for CrateLoader<'a, 'tcx> {
72+
type Target = TyCtxt<'tcx>;
73+
74+
fn deref(&self) -> &Self::Target {
75+
&self.tcx
76+
}
77+
}
78+
7379
pub enum LoadedMacro {
7480
MacroDef(ast::Item, Edition),
7581
ProcMacro(SyntaxExtension),
@@ -254,15 +260,13 @@ impl CStore {
254260
}
255261
}
256262

257-
impl<'a> CrateLoader<'a> {
263+
impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
258264
pub fn new(
259-
sess: &'a Session,
260-
metadata_loader: &'a MetadataLoaderDyn,
261-
local_crate_name: Symbol,
265+
tcx: TyCtxt<'tcx>,
262266
cstore: &'a mut CStore,
263267
used_extern_options: &'a mut FxHashSet<Symbol>,
264268
) -> Self {
265-
CrateLoader { sess, metadata_loader, local_crate_name, cstore, used_extern_options }
269+
CrateLoader { tcx, cstore, used_extern_options }
266270
}
267271
pub fn cstore(&self) -> &CStore {
268272
&self.cstore
@@ -553,9 +557,10 @@ impl<'a> CrateLoader<'a> {
553557
(LoadResult::Previous(cnum), None)
554558
} else {
555559
info!("falling back to a load");
560+
let metadata_loader = self.tcx.metadata_loader(()).borrow();
556561
let mut locator = CrateLocator::new(
557562
self.sess,
558-
&*self.metadata_loader,
563+
&**metadata_loader,
559564
name,
560565
hash,
561566
extra_filename,
@@ -960,7 +965,7 @@ impl<'a> CrateLoader<'a> {
960965
&format!(
961966
"external crate `{}` unused in `{}`: remove the dependency or add `use {} as _;`",
962967
name,
963-
self.local_crate_name,
968+
self.tcx.crate_name(LOCAL_CRATE),
964969
name),
965970
);
966971
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_middle::span_bug;
4444
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, TyCtxt};
4545
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
4646
use rustc_query_system::ich::StableHashingContext;
47-
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn, Untracked};
47+
use rustc_session::cstore::{CrateStore, Untracked};
4848
use rustc_session::lint::LintBuffer;
4949
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
5050
use rustc_span::source_map::Spanned;
@@ -955,8 +955,6 @@ pub struct Resolver<'a, 'tcx> {
955955
arenas: &'a ResolverArenas<'a>,
956956
dummy_binding: &'a NameBinding<'a>,
957957

958-
local_crate_name: Symbol,
959-
metadata_loader: Box<MetadataLoaderDyn>,
960958
used_extern_options: FxHashSet<Symbol>,
961959
macro_names: FxHashSet<Ident>,
962960
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
@@ -1203,8 +1201,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12031201
pub fn new(
12041202
tcx: TyCtxt<'tcx>,
12051203
krate: &Crate,
1206-
crate_name: Symbol,
1207-
metadata_loader: Box<MetadataLoaderDyn>,
12081204
arenas: &'a ResolverArenas<'a>,
12091205
) -> Resolver<'a, 'tcx> {
12101206
let root_def_id = CRATE_DEF_ID.to_def_id();
@@ -1312,8 +1308,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13121308
vis: ty::Visibility::Public,
13131309
}),
13141310

1315-
metadata_loader,
1316-
local_crate_name: crate_name,
13171311
used_extern_options: Default::default(),
13181312
macro_names: FxHashSet::default(),
13191313
builtin_macros: Default::default(),
@@ -1464,14 +1458,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14641458
StableHashingContext::new(self.tcx.sess, self.tcx.untracked())
14651459
}
14661460

1467-
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_>) -> T) -> T {
1468-
f(&mut CrateLoader::new(
1469-
&self.tcx.sess,
1470-
&*self.metadata_loader,
1471-
self.local_crate_name,
1472-
&mut *self.tcx.untracked().cstore.write().untracked_as_any().downcast_mut().unwrap(),
1473-
&mut self.used_extern_options,
1474-
))
1461+
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
1462+
let mut cstore = self.tcx.untracked().cstore.write();
1463+
let cstore = cstore.untracked_as_any().downcast_mut().unwrap();
1464+
f(&mut CrateLoader::new(self.tcx, &mut *cstore, &mut self.used_extern_options))
14751465
}
14761466

14771467
fn cstore(&self) -> MappedReadGuard<'_, CStore> {

0 commit comments

Comments
 (0)