@@ -51,7 +51,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
51
51
StableVec } ;
52
52
use arena:: { TypedArena , SyncDroplessArena } ;
53
53
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
54
- use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal , AtomicOnce , OneThread } ;
54
+ use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal , AtomicOnce , Once , OneThread } ;
55
55
use std:: any:: Any ;
56
56
use std:: borrow:: Borrow ;
57
57
use std:: cmp:: Ordering ;
@@ -1019,15 +1019,20 @@ pub struct GlobalCtxt<'tcx> {
1019
1019
1020
1020
pub io : InputsAndOutputs ,
1021
1021
1022
- pub ast_crate : Steal < ast:: Crate > ,
1022
+ /// This stores a `Lrc<CStore>`, but that type depends on
1023
+ /// rustc_metadata, so it cannot be used here.
1024
+ pub cstore_rc : OneThread < Steal < Box < dyn Any > > > ,
1023
1025
1024
- /// This stores a `Lrc<Option<Lock<BoxedResolver>>>)>`, but that type depends on
1025
- /// librustc_resolve, so it cannot be used here.
1026
- pub boxed_resolver : Steal < OneThread < Box < dyn Any > > > ,
1026
+ pub sess_rc : Lrc < Session > ,
1027
+
1028
+ /// The AST after registering plugins.
1029
+ pub ast_crate : Steal < ( ast:: Crate , ty:: PluginInfo ) > ,
1027
1030
1028
1031
lowered_hir : AtomicOnce < & ' tcx hir:: LoweredHir > ,
1029
1032
hir_map : AtomicOnce < & ' tcx hir_map:: Map < ' tcx > > ,
1030
1033
1034
+ metadata_dep_nodes : Once < ( ) > ,
1035
+
1031
1036
pub queries : query:: Queries < ' tcx > ,
1032
1037
1033
1038
// Internal cache for metadata decoding. No need to track deps on this.
@@ -1087,10 +1092,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1087
1092
self . lowered_hir . get_or_init ( || {
1088
1093
// FIXME: The ignore here is only sound because all queries
1089
1094
// used to compute LoweredHir are eval_always
1090
- self . dep_graph . with_ignore ( || self . lower_ast_to_hir ( LocalCrate ) . unwrap ( ) )
1095
+ self . dep_graph . with_ignore ( || {
1096
+ let map = self . lower_ast_to_hir ( LocalCrate ) . unwrap ( ) ;
1097
+ self . lowered_hir . init ( map) ;
1098
+ self . allocate_metadata_dep_nodes ( ) ;
1099
+ map
1100
+ } )
1091
1101
} )
1092
1102
}
1093
1103
1104
+ pub fn is_hir_lowered ( self ) -> bool {
1105
+ self . lowered_hir . is_initalized ( )
1106
+ }
1107
+
1094
1108
#[ inline( always) ]
1095
1109
pub fn hir ( self ) -> & ' gcx hir_map:: Map < ' gcx > {
1096
1110
self . hir_map . get_or_init ( || {
@@ -1194,14 +1208,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1194
1208
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
1195
1209
/// reference to the context, to allow formatting values that need it.
1196
1210
pub fn create_global_ctxt (
1197
- s : & ' tcx Session ,
1211
+ s : & ' tcx Lrc < Session > ,
1198
1212
cstore : & ' tcx CrateStoreDyn ,
1213
+ cstore_rc : Box < dyn Any > ,
1199
1214
local_providers : ty:: query:: Providers < ' tcx > ,
1200
1215
extern_providers : ty:: query:: Providers < ' tcx > ,
1201
1216
arenas : & ' tcx AllArenas < ' tcx > ,
1202
1217
dep_graph : DepGraph ,
1203
1218
ast_crate : ast:: Crate ,
1204
- boxed_resolver : Box < dyn Any > ,
1219
+ plugin_info : ty :: PluginInfo ,
1205
1220
on_disk_query_result_cache : query:: OnDiskCache < ' tcx > ,
1206
1221
crate_name : & str ,
1207
1222
tx : mpsc:: Sender < Box < dyn Any + Send > > ,
@@ -1217,16 +1232,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1217
1232
providers[ LOCAL_CRATE ] = local_providers;
1218
1233
1219
1234
GlobalCtxt {
1220
- sess : s,
1235
+ sess : & * * s,
1221
1236
cstore,
1237
+ cstore_rc : OneThread :: new ( Steal :: new ( cstore_rc) ) ,
1238
+ sess_rc : s. clone ( ) ,
1222
1239
global_arenas : & arenas. global ,
1223
1240
global_interners : interners,
1224
1241
dep_graph,
1225
1242
types : common_types,
1226
- ast_crate : Steal :: new ( ast_crate) ,
1227
- boxed_resolver : Steal :: new ( OneThread :: new ( boxed_resolver) ) ,
1243
+ ast_crate : Steal :: new ( ( ast_crate, plugin_info) ) ,
1228
1244
lowered_hir : AtomicOnce :: new ( ) ,
1229
1245
hir_map : AtomicOnce :: new ( ) ,
1246
+ metadata_dep_nodes : Once :: new ( ) ,
1230
1247
queries : query:: Queries :: new (
1231
1248
providers,
1232
1249
extern_providers,
@@ -1391,18 +1408,24 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1391
1408
// With full-fledged red/green, the method will probably become unnecessary
1392
1409
// as this will be done on-demand.
1393
1410
pub fn allocate_metadata_dep_nodes ( self ) {
1394
- // We cannot use the query versions of crates() and crate_hash(), since
1395
- // those would need the DepNodes that we are allocating here.
1396
- for cnum in self . cstore . crates_untracked ( ) {
1397
- let dep_node = DepNode :: new ( self , DepConstructor :: CrateMetadata ( cnum) ) ;
1398
- let crate_hash = self . cstore . crate_hash_untracked ( cnum) ;
1399
- self . dep_graph . with_task ( dep_node,
1400
- self ,
1401
- crate_hash,
1402
- |_, x| x, // No transformation needed
1403
- Some ( dep_graph:: hash_result) ,
1404
- ) ;
1405
- }
1411
+ if !self . dep_graph . is_fully_enabled ( ) {
1412
+ return
1413
+ }
1414
+
1415
+ self . metadata_dep_nodes . init_locking ( || {
1416
+ // We cannot use the query versions of crates() and crate_hash(), since
1417
+ // those would need the DepNodes that we are allocating here.
1418
+ for cnum in self . cstore . crates_untracked ( ) {
1419
+ let dep_node = DepNode :: new ( self , DepConstructor :: CrateMetadata ( cnum) ) ;
1420
+ let crate_hash = self . cstore . crate_hash_untracked ( cnum) ;
1421
+ self . dep_graph . with_task ( dep_node,
1422
+ self ,
1423
+ crate_hash,
1424
+ |_, x| x, // No transformation needed
1425
+ Some ( dep_graph:: hash_result) ,
1426
+ ) ;
1427
+ }
1428
+ } ) ;
1406
1429
}
1407
1430
1408
1431
pub fn serialize_query_result_cache < E > ( self ,
0 commit comments