@@ -53,7 +53,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
53
53
StableVec } ;
54
54
use arena:: SyncDroplessArena ;
55
55
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
56
- use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal , AtomicOnce , OneThread } ;
56
+ use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal , AtomicOnce , Once , OneThread } ;
57
57
use std:: any:: Any ;
58
58
use std:: borrow:: Borrow ;
59
59
use std:: cmp:: Ordering ;
@@ -1009,15 +1009,20 @@ pub struct GlobalCtxt<'tcx> {
1009
1009
1010
1010
pub io : InputsAndOutputs ,
1011
1011
1012
- pub ast_crate : Steal < ast:: Crate > ,
1012
+ /// This stores a `Lrc<CStore>`, but that type depends on
1013
+ /// rustc_metadata, so it cannot be used here.
1014
+ pub cstore_rc : OneThread < Steal < Box < dyn Any > > > ,
1013
1015
1014
- /// This stores a `Lrc<Option<Lock<BoxedResolver>>>)>`, but that type depends on
1015
- /// librustc_resolve, so it cannot be used here.
1016
- pub boxed_resolver : Steal < OneThread < Box < dyn Any > > > ,
1016
+ pub sess_rc : Lrc < Session > ,
1017
+
1018
+ /// The AST after registering plugins.
1019
+ pub ast_crate : Steal < ( ast:: Crate , ty:: PluginInfo ) > ,
1017
1020
1018
1021
lowered_hir : AtomicOnce < & ' tcx hir:: LoweredHir > ,
1019
1022
hir_map : AtomicOnce < & ' tcx hir_map:: Map < ' tcx > > ,
1020
1023
1024
+ metadata_dep_nodes : Once < ( ) > ,
1025
+
1021
1026
pub queries : query:: Queries < ' tcx > ,
1022
1027
1023
1028
// Internal cache for metadata decoding. No need to track deps on this.
@@ -1075,10 +1080,19 @@ impl<'tcx> TyCtxt<'tcx> {
1075
1080
self . lowered_hir . get_or_init ( || {
1076
1081
// FIXME: The ignore here is only sound because all queries
1077
1082
// used to compute LoweredHir are eval_always
1078
- self . dep_graph . with_ignore ( || self . lower_ast_to_hir ( ( ) ) . unwrap ( ) )
1083
+ self . dep_graph . with_ignore ( || {
1084
+ let map = self . lower_ast_to_hir ( ( ) ) . unwrap ( ) ;
1085
+ self . lowered_hir . init ( map) ;
1086
+ self . allocate_metadata_dep_nodes ( ) ;
1087
+ map
1088
+ } )
1079
1089
} )
1080
1090
}
1081
1091
1092
+ pub fn is_hir_lowered ( self ) -> bool {
1093
+ self . lowered_hir . is_initalized ( )
1094
+ }
1095
+
1082
1096
#[ inline( always) ]
1083
1097
pub fn hir ( self ) -> & ' tcx hir_map:: Map < ' tcx > {
1084
1098
self . hir_map . get_or_init ( || {
@@ -1163,14 +1177,15 @@ impl<'tcx> TyCtxt<'tcx> {
1163
1177
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
1164
1178
/// reference to the context, to allow formatting values that need it.
1165
1179
pub fn create_global_ctxt (
1166
- s : & ' tcx Session ,
1180
+ s : & ' tcx Lrc < Session > ,
1167
1181
cstore : & ' tcx CrateStoreDyn ,
1182
+ cstore_rc : Box < dyn Any > ,
1168
1183
local_providers : ty:: query:: Providers < ' tcx > ,
1169
1184
extern_providers : ty:: query:: Providers < ' tcx > ,
1170
1185
arenas : & ' tcx AllArenas ,
1171
1186
dep_graph : DepGraph ,
1172
1187
ast_crate : ast:: Crate ,
1173
- boxed_resolver : Box < dyn Any > ,
1188
+ plugin_info : ty :: PluginInfo ,
1174
1189
on_disk_query_result_cache : query:: OnDiskCache < ' tcx > ,
1175
1190
crate_name : & str ,
1176
1191
tx : mpsc:: Sender < Box < dyn Any + Send > > ,
@@ -1194,19 +1209,21 @@ impl<'tcx> TyCtxt<'tcx> {
1194
1209
providers[ LOCAL_CRATE ] = local_providers;
1195
1210
1196
1211
GlobalCtxt {
1197
- sess : s,
1198
- cstore,
1212
+ sess : & * * s,
1199
1213
arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
1214
+ cstore,
1215
+ cstore_rc : OneThread :: new ( Steal :: new ( cstore_rc) ) ,
1216
+ sess_rc : s. clone ( ) ,
1200
1217
interners,
1201
1218
dep_graph,
1202
1219
common,
1203
1220
types : common_types,
1204
1221
lifetimes : common_lifetimes,
1205
1222
consts : common_consts,
1206
- ast_crate : Steal :: new ( ast_crate) ,
1207
- boxed_resolver : Steal :: new ( OneThread :: new ( boxed_resolver) ) ,
1223
+ ast_crate : Steal :: new ( ( ast_crate, plugin_info) ) ,
1208
1224
lowered_hir : AtomicOnce :: new ( ) ,
1209
1225
hir_map : AtomicOnce :: new ( ) ,
1226
+ metadata_dep_nodes : Once :: new ( ) ,
1210
1227
queries : query:: Queries :: new (
1211
1228
providers,
1212
1229
extern_providers,
@@ -1381,18 +1398,24 @@ impl<'tcx> TyCtxt<'tcx> {
1381
1398
// With full-fledged red/green, the method will probably become unnecessary
1382
1399
// as this will be done on-demand.
1383
1400
pub fn allocate_metadata_dep_nodes ( self ) {
1384
- // We cannot use the query versions of crates() and crate_hash(), since
1385
- // those would need the DepNodes that we are allocating here.
1386
- for cnum in self . cstore . crates_untracked ( ) {
1387
- let dep_node = DepNode :: new ( self , DepConstructor :: CrateMetadata ( cnum) ) ;
1388
- let crate_hash = self . cstore . crate_hash_untracked ( cnum) ;
1389
- self . dep_graph . with_task ( dep_node,
1390
- self ,
1391
- crate_hash,
1392
- |_, x| x, // No transformation needed
1393
- Some ( dep_graph:: hash_result) ,
1394
- ) ;
1401
+ if !self . dep_graph . is_fully_enabled ( ) {
1402
+ return
1395
1403
}
1404
+
1405
+ self . metadata_dep_nodes . init_locking ( || {
1406
+ // We cannot use the query versions of crates() and crate_hash(), since
1407
+ // those would need the DepNodes that we are allocating here.
1408
+ for cnum in self . cstore . crates_untracked ( ) {
1409
+ let dep_node = DepNode :: new ( self , DepConstructor :: CrateMetadata ( cnum) ) ;
1410
+ let crate_hash = self . cstore . crate_hash_untracked ( cnum) ;
1411
+ self . dep_graph . with_task ( dep_node,
1412
+ self ,
1413
+ crate_hash,
1414
+ |_, x| x, // No transformation needed
1415
+ Some ( dep_graph:: hash_result) ,
1416
+ ) ;
1417
+ }
1418
+ } ) ;
1396
1419
}
1397
1420
1398
1421
pub fn serialize_query_result_cache < E > ( self ,
0 commit comments