@@ -27,7 +27,7 @@ use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
27
27
use rustc_ast:: { AngleBracketedArg , Crate , Expr , ExprKind , GenericArg , GenericArgs , LitKind , Path } ;
28
28
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet } ;
29
29
use rustc_data_structures:: intern:: Interned ;
30
- use rustc_data_structures:: sync:: { Lrc , MappedReadGuard , ReadGuard } ;
30
+ use rustc_data_structures:: sync:: { Lrc , MappedReadGuard } ;
31
31
use rustc_errors:: { Applicability , DiagnosticBuilder , ErrorGuaranteed } ;
32
32
use rustc_expand:: base:: { DeriveResolutions , SyntaxExtension , SyntaxExtensionKind } ;
33
33
use rustc_hir:: def:: Namespace :: { self , * } ;
@@ -41,12 +41,11 @@ use rustc_metadata::creader::{CStore, CrateLoader};
41
41
use rustc_middle:: metadata:: ModChild ;
42
42
use rustc_middle:: middle:: privacy:: EffectiveVisibilities ;
43
43
use rustc_middle:: span_bug;
44
- use rustc_middle:: ty:: { self , DefIdTree , MainDefinition , RegisteredTools } ;
44
+ use rustc_middle:: ty:: { self , DefIdTree , MainDefinition , RegisteredTools , TyCtxt } ;
45
45
use rustc_middle:: ty:: { ResolverGlobalCtxt , ResolverOutputs } ;
46
46
use rustc_query_system:: ich:: StableHashingContext ;
47
47
use rustc_session:: cstore:: { CrateStore , MetadataLoaderDyn , Untracked } ;
48
48
use rustc_session:: lint:: LintBuffer ;
49
- use rustc_session:: Session ;
50
49
use rustc_span:: hygiene:: { ExpnId , LocalExpnId , MacroKind , SyntaxContext , Transparency } ;
51
50
use rustc_span:: source_map:: Spanned ;
52
51
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -861,10 +860,6 @@ struct MacroData {
861
860
macro_rules : bool ,
862
861
}
863
862
864
- struct TyCtxt < ' tcx > {
865
- sess : & ' tcx Session ,
866
- }
867
-
868
863
/// The main resolver class.
869
864
///
870
865
/// This is the visitor that walks the whole crate.
@@ -962,7 +957,6 @@ pub struct Resolver<'a, 'tcx> {
962
957
963
958
local_crate_name : Symbol ,
964
959
metadata_loader : Box < MetadataLoaderDyn > ,
965
- untracked : & ' tcx Untracked ,
966
960
used_extern_options : FxHashSet < Symbol > ,
967
961
macro_names : FxHashSet < Ident > ,
968
962
builtin_macros : FxHashMap < Symbol , BuiltinMacroState > ,
@@ -1141,7 +1135,7 @@ impl DefIdTree for ResolverTree<'_> {
1141
1135
impl < ' a , ' b , ' tcx > DefIdTree for & ' a Resolver < ' b , ' tcx > {
1142
1136
#[ inline]
1143
1137
fn opt_parent ( self , id : DefId ) -> Option < DefId > {
1144
- ResolverTree ( & self . untracked ) . opt_parent ( id)
1138
+ ResolverTree ( & self . tcx . untracked ( ) ) . opt_parent ( id)
1145
1139
}
1146
1140
}
1147
1141
@@ -1168,10 +1162,11 @@ impl<'tcx> Resolver<'_, 'tcx> {
1168
1162
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}" ,
1169
1163
node_id,
1170
1164
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] ) ,
1172
1166
) ;
1173
1167
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) ;
1175
1170
1176
1171
// Create the definition.
1177
1172
if expn_id != ExpnId :: root ( ) {
@@ -1180,7 +1175,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
1180
1175
1181
1176
// A relative span's parent must be an absolute span.
1182
1177
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) ;
1184
1179
debug_assert_eq ! ( _id, def_id) ;
1185
1180
1186
1181
// Some things for which we allocate `LocalDefId`s don't correspond to
@@ -1206,23 +1201,20 @@ impl<'tcx> Resolver<'_, 'tcx> {
1206
1201
1207
1202
impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
1208
1203
pub fn new (
1209
- session : & ' tcx Session ,
1204
+ tcx : TyCtxt < ' tcx > ,
1210
1205
krate : & Crate ,
1211
1206
crate_name : Symbol ,
1212
1207
metadata_loader : Box < MetadataLoaderDyn > ,
1213
1208
arenas : & ' a ResolverArenas < ' a > ,
1214
- untracked : & ' tcx Untracked ,
1215
1209
) -> Resolver < ' a , ' tcx > {
1216
- let tcx = TyCtxt { sess : session } ;
1217
-
1218
1210
let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
1219
1211
let mut module_map = FxHashMap :: default ( ) ;
1220
1212
let graph_root = arenas. new_module (
1221
1213
None ,
1222
1214
ModuleKind :: Def ( DefKind :: Mod , root_def_id, kw:: Empty ) ,
1223
1215
ExpnId :: root ( ) ,
1224
1216
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) ,
1226
1218
& mut module_map,
1227
1219
) ;
1228
1220
let empty_module = arenas. new_module (
@@ -1245,24 +1237,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1245
1237
let mut invocation_parents = FxHashMap :: default ( ) ;
1246
1238
invocation_parents. insert ( LocalExpnId :: ROOT , ( CRATE_DEF_ID , ImplTraitContext :: Existential ) ) ;
1247
1239
1248
- let mut extern_prelude: FxHashMap < Ident , ExternPreludeEntry < ' _ > > = session
1240
+ let mut extern_prelude: FxHashMap < Ident , ExternPreludeEntry < ' _ > > = tcx
1241
+ . sess
1249
1242
. opts
1250
1243
. externs
1251
1244
. iter ( )
1252
1245
. filter ( |( _, entry) | entry. add_prelude )
1253
1246
. map ( |( name, _) | ( Ident :: from_str ( name) , Default :: default ( ) ) )
1254
1247
. collect ( ) ;
1255
1248
1256
- if !session . contains_name ( & krate. attrs , sym:: no_core) {
1249
+ if !tcx . sess . contains_name ( & krate. attrs , sym:: no_core) {
1257
1250
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) {
1259
1252
extern_prelude. insert ( Ident :: with_dummy_span ( sym:: std) , Default :: default ( ) ) ;
1260
1253
}
1261
1254
}
1262
1255
1263
- let registered_tools = macros:: registered_tools ( session , & krate. attrs ) ;
1256
+ let registered_tools = macros:: registered_tools ( tcx . sess , & krate. attrs ) ;
1264
1257
1265
- let features = session . features_untracked ( ) ;
1258
+ let features = tcx . sess . features_untracked ( ) ;
1266
1259
1267
1260
let mut resolver = Resolver {
1268
1261
tcx,
@@ -1322,16 +1315,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1322
1315
metadata_loader,
1323
1316
local_crate_name : crate_name,
1324
1317
used_extern_options : Default :: default ( ) ,
1325
- untracked,
1326
1318
macro_names : FxHashSet :: default ( ) ,
1327
1319
builtin_macros : Default :: default ( ) ,
1328
1320
builtin_macro_kinds : Default :: default ( ) ,
1329
1321
registered_tools,
1330
1322
macro_use_prelude : FxHashMap :: default ( ) ,
1331
1323
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 ( ) ) ) ,
1335
1327
invocation_parent_scopes : Default :: default ( ) ,
1336
1328
output_macro_rules_scopes : Default :: default ( ) ,
1337
1329
macro_rules_scopes : Default :: default ( ) ,
@@ -1469,22 +1461,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1469
1461
}
1470
1462
1471
1463
fn create_stable_hashing_context ( & self ) -> StableHashingContext < ' _ > {
1472
- StableHashingContext :: new ( self . tcx . sess , self . untracked )
1464
+ StableHashingContext :: new ( self . tcx . sess , self . tcx . untracked ( ) )
1473
1465
}
1474
1466
1475
1467
fn crate_loader < T > ( & mut self , f : impl FnOnce ( & mut CrateLoader < ' _ > ) -> T ) -> T {
1476
1468
f ( & mut CrateLoader :: new (
1477
1469
& self . tcx . sess ,
1478
1470
& * self . metadata_loader ,
1479
1471
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 ( ) ,
1482
1474
& mut self . used_extern_options ,
1483
1475
) )
1484
1476
}
1485
1477
1486
1478
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 )
1488
1480
}
1489
1481
1490
1482
fn dummy_ext ( & self , macro_kind : MacroKind ) -> Lrc < SyntaxExtension > {
@@ -1535,7 +1527,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1535
1527
} ) ;
1536
1528
1537
1529
// Make sure we don't mutate the cstore from here on.
1538
- self . untracked . cstore . leak ( ) ;
1530
+ self . tcx . untracked ( ) . cstore . leak ( ) ;
1539
1531
}
1540
1532
1541
1533
fn traits_in_scope (
@@ -1925,14 +1917,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1925
1917
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
1926
1918
#[ inline]
1927
1919
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) )
1929
1921
}
1930
1922
1931
1923
/// Retrieves the name of the given `DefId`.
1932
1924
#[ inline]
1933
1925
fn opt_name ( & self , def_id : DefId ) -> Option < Symbol > {
1934
1926
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) ,
1936
1928
None => self . cstore ( ) . def_key ( def_id) ,
1937
1929
} ;
1938
1930
def_key. get_opt_name ( )
0 commit comments