Skip to content

Commit 4953d70

Browse files
committed
Stuff a TyCtxt into the Resolver
1 parent 9fb91b8 commit 4953d70

File tree

5 files changed

+32
-41
lines changed

5 files changed

+32
-41
lines changed

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ impl<'tcx> Queries<'tcx> {
221221

222222
let arenas = Resolver::arenas();
223223
let mut resolver = Resolver::new(
224-
sess,
224+
tcx,
225225
&krate,
226226
crate_name,
227227
self.codegen_backend().metadata_loader(),
228228
&arenas,
229-
tcx.untracked(),
230229
);
231230
let krate = passes::configure_and_expand(
232231
sess,

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
155155
if !candidates.is_empty() {
156156
show_candidates(
157157
&self.tcx.sess,
158-
&self.untracked.source_span.read(),
158+
&self.tcx.untracked().source_span.read(),
159159
&mut err,
160160
span,
161161
&candidates,
@@ -688,7 +688,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
688688
}
689689
show_candidates(
690690
&self.tcx.sess,
691-
&self.untracked.source_span.read(),
691+
&self.tcx.untracked().source_span.read(),
692692
&mut err,
693693
Some(span),
694694
&import_suggestions,
@@ -1353,7 +1353,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13531353
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
13541354
show_candidates(
13551355
&self.tcx.sess,
1356-
&self.untracked.source_span.read(),
1356+
&self.tcx.untracked().source_span.read(),
13571357
err,
13581358
None,
13591359
&import_suggestions,

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
110110
r.effective_visibilities.update_eff_vis(
111111
r.local_def_id(node_id),
112112
eff_vis,
113-
ResolverTree(&r.untracked),
113+
ResolverTree(&r.tcx.untracked()),
114114
)
115115
}
116116
}

compiler/rustc_resolve/src/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
549549
match &import.kind {
550550
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
551551
self.r.tcx.sess,
552-
&self.r.untracked.source_span.read(),
552+
&self.r.tcx.untracked().source_span.read(),
553553
&mut diag,
554554
Some(err.span),
555555
&candidates,
@@ -562,7 +562,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
562562
ImportKind::Single { nested: true, source, target, .. } => {
563563
import_candidates(
564564
self.r.tcx.sess,
565-
&self.r.untracked.source_span.read(),
565+
&self.r.tcx.untracked().source_span.read(),
566566
&mut diag,
567567
None,
568568
&candidates,

compiler/rustc_resolve/src/lib.rs

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
2727
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
2828
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
2929
use rustc_data_structures::intern::Interned;
30-
use rustc_data_structures::sync::{Lrc, MappedReadGuard, ReadGuard};
30+
use rustc_data_structures::sync::{Lrc, MappedReadGuard};
3131
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
3232
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
3333
use rustc_hir::def::Namespace::{self, *};
@@ -41,12 +41,11 @@ use rustc_metadata::creader::{CStore, CrateLoader};
4141
use rustc_middle::metadata::ModChild;
4242
use rustc_middle::middle::privacy::EffectiveVisibilities;
4343
use rustc_middle::span_bug;
44-
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools};
44+
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, TyCtxt};
4545
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
4646
use rustc_query_system::ich::StableHashingContext;
4747
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn, Untracked};
4848
use rustc_session::lint::LintBuffer;
49-
use rustc_session::Session;
5049
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
5150
use rustc_span::source_map::Spanned;
5251
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -861,10 +860,6 @@ struct MacroData {
861860
macro_rules: bool,
862861
}
863862

864-
struct TyCtxt<'tcx> {
865-
sess: &'tcx Session,
866-
}
867-
868863
/// The main resolver class.
869864
///
870865
/// This is the visitor that walks the whole crate.
@@ -962,7 +957,6 @@ pub struct Resolver<'a, 'tcx> {
962957

963958
local_crate_name: Symbol,
964959
metadata_loader: Box<MetadataLoaderDyn>,
965-
untracked: &'tcx Untracked,
966960
used_extern_options: FxHashSet<Symbol>,
967961
macro_names: FxHashSet<Ident>,
968962
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
@@ -1141,7 +1135,7 @@ impl DefIdTree for ResolverTree<'_> {
11411135
impl<'a, 'b, 'tcx> DefIdTree for &'a Resolver<'b, 'tcx> {
11421136
#[inline]
11431137
fn opt_parent(self, id: DefId) -> Option<DefId> {
1144-
ResolverTree(&self.untracked).opt_parent(id)
1138+
ResolverTree(&self.tcx.untracked()).opt_parent(id)
11451139
}
11461140
}
11471141

@@ -1168,10 +1162,11 @@ impl<'tcx> Resolver<'_, 'tcx> {
11681162
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
11691163
node_id,
11701164
data,
1171-
self.untracked.definitions.read().def_key(self.node_id_to_def_id[&node_id]),
1165+
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id]),
11721166
);
11731167

1174-
let def_id = self.untracked.definitions.write().create_def(parent, data);
1168+
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
1169+
let def_id = self.tcx.untracked().definitions.write().create_def(parent, data);
11751170

11761171
// Create the definition.
11771172
if expn_id != ExpnId::root() {
@@ -1180,7 +1175,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
11801175

11811176
// A relative span's parent must be an absolute span.
11821177
debug_assert_eq!(span.data_untracked().parent, None);
1183-
let _id = self.untracked.source_span.write().push(span);
1178+
let _id = self.tcx.untracked().source_span.write().push(span);
11841179
debug_assert_eq!(_id, def_id);
11851180

11861181
// Some things for which we allocate `LocalDefId`s don't correspond to
@@ -1206,23 +1201,20 @@ impl<'tcx> Resolver<'_, 'tcx> {
12061201

12071202
impl<'a, 'tcx> Resolver<'a, 'tcx> {
12081203
pub fn new(
1209-
session: &'tcx Session,
1204+
tcx: TyCtxt<'tcx>,
12101205
krate: &Crate,
12111206
crate_name: Symbol,
12121207
metadata_loader: Box<MetadataLoaderDyn>,
12131208
arenas: &'a ResolverArenas<'a>,
1214-
untracked: &'tcx Untracked,
12151209
) -> Resolver<'a, 'tcx> {
1216-
let tcx = TyCtxt { sess: session };
1217-
12181210
let root_def_id = CRATE_DEF_ID.to_def_id();
12191211
let mut module_map = FxHashMap::default();
12201212
let graph_root = arenas.new_module(
12211213
None,
12221214
ModuleKind::Def(DefKind::Mod, root_def_id, kw::Empty),
12231215
ExpnId::root(),
12241216
krate.spans.inner_span,
1225-
session.contains_name(&krate.attrs, sym::no_implicit_prelude),
1217+
tcx.sess.contains_name(&krate.attrs, sym::no_implicit_prelude),
12261218
&mut module_map,
12271219
);
12281220
let empty_module = arenas.new_module(
@@ -1245,24 +1237,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12451237
let mut invocation_parents = FxHashMap::default();
12461238
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
12471239

1248-
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session
1240+
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = tcx
1241+
.sess
12491242
.opts
12501243
.externs
12511244
.iter()
12521245
.filter(|(_, entry)| entry.add_prelude)
12531246
.map(|(name, _)| (Ident::from_str(name), Default::default()))
12541247
.collect();
12551248

1256-
if !session.contains_name(&krate.attrs, sym::no_core) {
1249+
if !tcx.sess.contains_name(&krate.attrs, sym::no_core) {
12571250
extern_prelude.insert(Ident::with_dummy_span(sym::core), Default::default());
1258-
if !session.contains_name(&krate.attrs, sym::no_std) {
1251+
if !tcx.sess.contains_name(&krate.attrs, sym::no_std) {
12591252
extern_prelude.insert(Ident::with_dummy_span(sym::std), Default::default());
12601253
}
12611254
}
12621255

1263-
let registered_tools = macros::registered_tools(session, &krate.attrs);
1256+
let registered_tools = macros::registered_tools(tcx.sess, &krate.attrs);
12641257

1265-
let features = session.features_untracked();
1258+
let features = tcx.sess.features_untracked();
12661259

12671260
let mut resolver = Resolver {
12681261
tcx,
@@ -1322,16 +1315,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13221315
metadata_loader,
13231316
local_crate_name: crate_name,
13241317
used_extern_options: Default::default(),
1325-
untracked,
13261318
macro_names: FxHashSet::default(),
13271319
builtin_macros: Default::default(),
13281320
builtin_macro_kinds: Default::default(),
13291321
registered_tools,
13301322
macro_use_prelude: FxHashMap::default(),
13311323
macro_map: FxHashMap::default(),
1332-
dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(session.edition())),
1333-
dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(session.edition())),
1334-
non_macro_attr: Lrc::new(SyntaxExtension::non_macro_attr(session.edition())),
1324+
dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(tcx.sess.edition())),
1325+
dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(tcx.sess.edition())),
1326+
non_macro_attr: Lrc::new(SyntaxExtension::non_macro_attr(tcx.sess.edition())),
13351327
invocation_parent_scopes: Default::default(),
13361328
output_macro_rules_scopes: Default::default(),
13371329
macro_rules_scopes: Default::default(),
@@ -1469,22 +1461,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14691461
}
14701462

14711463
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
1472-
StableHashingContext::new(self.tcx.sess, self.untracked)
1464+
StableHashingContext::new(self.tcx.sess, self.tcx.untracked())
14731465
}
14741466

14751467
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_>) -> T) -> T {
14761468
f(&mut CrateLoader::new(
14771469
&self.tcx.sess,
14781470
&*self.metadata_loader,
14791471
self.local_crate_name,
1480-
&mut *self.untracked.cstore.write().untracked_as_any().downcast_mut().unwrap(),
1481-
self.untracked.definitions.read(),
1472+
&mut *self.tcx.untracked().cstore.write().untracked_as_any().downcast_mut().unwrap(),
1473+
self.tcx.definitions_untracked(),
14821474
&mut self.used_extern_options,
14831475
))
14841476
}
14851477

14861478
fn cstore(&self) -> MappedReadGuard<'_, CStore> {
1487-
ReadGuard::map(self.untracked.cstore.read(), |r| r.as_any().downcast_ref().unwrap())
1479+
CStore::from_tcx(self.tcx)
14881480
}
14891481

14901482
fn dummy_ext(&self, macro_kind: MacroKind) -> Lrc<SyntaxExtension> {
@@ -1535,7 +1527,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15351527
});
15361528

15371529
// Make sure we don't mutate the cstore from here on.
1538-
self.untracked.cstore.leak();
1530+
self.tcx.untracked().cstore.leak();
15391531
}
15401532

15411533
fn traits_in_scope(
@@ -1925,14 +1917,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19251917
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
19261918
#[inline]
19271919
fn opt_span(&self, def_id: DefId) -> Option<Span> {
1928-
def_id.as_local().map(|def_id| self.untracked.source_span.read()[def_id])
1920+
def_id.as_local().map(|def_id| self.tcx.source_span(def_id))
19291921
}
19301922

19311923
/// Retrieves the name of the given `DefId`.
19321924
#[inline]
19331925
fn opt_name(&self, def_id: DefId) -> Option<Symbol> {
19341926
let def_key = match def_id.as_local() {
1935-
Some(def_id) => self.untracked.definitions.read().def_key(def_id),
1927+
Some(def_id) => self.tcx.definitions_untracked().def_key(def_id),
19361928
None => self.cstore().def_key(def_id),
19371929
};
19381930
def_key.get_opt_name()

0 commit comments

Comments
 (0)