@@ -51,7 +51,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5151 StableVec } ;
5252use arena:: { TypedArena , SyncDroplessArena } ;
5353use 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 } ;
5555use std:: any:: Any ;
5656use std:: borrow:: Borrow ;
5757use std:: cmp:: Ordering ;
@@ -1019,15 +1019,20 @@ pub struct GlobalCtxt<'tcx> {
10191019
10201020 pub io : InputsAndOutputs ,
10211021
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 > > > ,
10231025
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 ) > ,
10271030
10281031 lowered_hir : AtomicOnce < & ' tcx hir:: LoweredHir > ,
10291032 hir_map : AtomicOnce < & ' tcx hir_map:: Map < ' tcx > > ,
10301033
1034+ metadata_dep_nodes : Once < ( ) > ,
1035+
10311036 pub queries : query:: Queries < ' tcx > ,
10321037
10331038 // Internal cache for metadata decoding. No need to track deps on this.
@@ -1087,10 +1092,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10871092 self . lowered_hir . get_or_init ( || {
10881093 // FIXME: The ignore here is only sound because all queries
10891094 // 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+ } )
10911101 } )
10921102 }
10931103
1104+ pub fn is_hir_lowered ( self ) -> bool {
1105+ self . lowered_hir . is_initalized ( )
1106+ }
1107+
10941108 #[ inline( always) ]
10951109 pub fn hir ( self ) -> & ' gcx hir_map:: Map < ' gcx > {
10961110 self . hir_map . get_or_init ( || {
@@ -1194,14 +1208,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11941208 /// value (types, substs, etc.) can only be used while `ty::tls` has a valid
11951209 /// reference to the context, to allow formatting values that need it.
11961210 pub fn create_global_ctxt (
1197- s : & ' tcx Session ,
1211+ s : & ' tcx Lrc < Session > ,
11981212 cstore : & ' tcx CrateStoreDyn ,
1213+ cstore_rc : Box < dyn Any > ,
11991214 local_providers : ty:: query:: Providers < ' tcx > ,
12001215 extern_providers : ty:: query:: Providers < ' tcx > ,
12011216 arenas : & ' tcx AllArenas < ' tcx > ,
12021217 dep_graph : DepGraph ,
12031218 ast_crate : ast:: Crate ,
1204- boxed_resolver : Box < dyn Any > ,
1219+ plugin_info : ty :: PluginInfo ,
12051220 on_disk_query_result_cache : query:: OnDiskCache < ' tcx > ,
12061221 crate_name : & str ,
12071222 tx : mpsc:: Sender < Box < dyn Any + Send > > ,
@@ -1217,16 +1232,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12171232 providers[ LOCAL_CRATE ] = local_providers;
12181233
12191234 GlobalCtxt {
1220- sess : s,
1235+ sess : & * * s,
12211236 cstore,
1237+ cstore_rc : OneThread :: new ( Steal :: new ( cstore_rc) ) ,
1238+ sess_rc : s. clone ( ) ,
12221239 global_arenas : & arenas. global ,
12231240 global_interners : interners,
12241241 dep_graph,
12251242 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) ) ,
12281244 lowered_hir : AtomicOnce :: new ( ) ,
12291245 hir_map : AtomicOnce :: new ( ) ,
1246+ metadata_dep_nodes : Once :: new ( ) ,
12301247 queries : query:: Queries :: new (
12311248 providers,
12321249 extern_providers,
@@ -1391,18 +1408,24 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13911408 // With full-fledged red/green, the method will probably become unnecessary
13921409 // as this will be done on-demand.
13931410 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+ } ) ;
14061429 }
14071430
14081431 pub fn serialize_query_result_cache < E > ( self ,
0 commit comments