@@ -53,7 +53,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5353 StableVec } ;
5454use arena:: SyncDroplessArena ;
5555use 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 } ;
5757use std:: any:: Any ;
5858use std:: borrow:: Borrow ;
5959use std:: cmp:: Ordering ;
@@ -1009,15 +1009,20 @@ pub struct GlobalCtxt<'tcx> {
10091009
10101010 pub io : InputsAndOutputs ,
10111011
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 > > > ,
10131015
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 ) > ,
10171020
10181021 lowered_hir : AtomicOnce < & ' tcx hir:: LoweredHir > ,
10191022 hir_map : AtomicOnce < & ' tcx hir_map:: Map < ' tcx > > ,
10201023
1024+ metadata_dep_nodes : Once < ( ) > ,
1025+
10211026 pub queries : query:: Queries < ' tcx > ,
10221027
10231028 // Internal cache for metadata decoding. No need to track deps on this.
@@ -1075,10 +1080,19 @@ impl<'tcx> TyCtxt<'tcx> {
10751080 self . lowered_hir . get_or_init ( || {
10761081 // FIXME: The ignore here is only sound because all queries
10771082 // 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+ } )
10791089 } )
10801090 }
10811091
1092+ pub fn is_hir_lowered ( self ) -> bool {
1093+ self . lowered_hir . is_initalized ( )
1094+ }
1095+
10821096 #[ inline( always) ]
10831097 pub fn hir ( self ) -> & ' tcx hir_map:: Map < ' tcx > {
10841098 self . hir_map . get_or_init ( || {
@@ -1163,14 +1177,15 @@ impl<'tcx> TyCtxt<'tcx> {
11631177 /// value (types, substs, etc.) can only be used while `ty::tls` has a valid
11641178 /// reference to the context, to allow formatting values that need it.
11651179 pub fn create_global_ctxt (
1166- s : & ' tcx Session ,
1180+ s : & ' tcx Lrc < Session > ,
11671181 cstore : & ' tcx CrateStoreDyn ,
1182+ cstore_rc : Box < dyn Any > ,
11681183 local_providers : ty:: query:: Providers < ' tcx > ,
11691184 extern_providers : ty:: query:: Providers < ' tcx > ,
11701185 arenas : & ' tcx AllArenas ,
11711186 dep_graph : DepGraph ,
11721187 ast_crate : ast:: Crate ,
1173- boxed_resolver : Box < dyn Any > ,
1188+ plugin_info : ty :: PluginInfo ,
11741189 on_disk_query_result_cache : query:: OnDiskCache < ' tcx > ,
11751190 crate_name : & str ,
11761191 tx : mpsc:: Sender < Box < dyn Any + Send > > ,
@@ -1194,19 +1209,21 @@ impl<'tcx> TyCtxt<'tcx> {
11941209 providers[ LOCAL_CRATE ] = local_providers;
11951210
11961211 GlobalCtxt {
1197- sess : s,
1198- cstore,
1212+ sess : & * * s,
11991213 arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
1214+ cstore,
1215+ cstore_rc : OneThread :: new ( Steal :: new ( cstore_rc) ) ,
1216+ sess_rc : s. clone ( ) ,
12001217 interners,
12011218 dep_graph,
12021219 common,
12031220 types : common_types,
12041221 lifetimes : common_lifetimes,
12051222 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) ) ,
12081224 lowered_hir : AtomicOnce :: new ( ) ,
12091225 hir_map : AtomicOnce :: new ( ) ,
1226+ metadata_dep_nodes : Once :: new ( ) ,
12101227 queries : query:: Queries :: new (
12111228 providers,
12121229 extern_providers,
@@ -1381,18 +1398,24 @@ impl<'tcx> TyCtxt<'tcx> {
13811398 // With full-fledged red/green, the method will probably become unnecessary
13821399 // as this will be done on-demand.
13831400 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
13951403 }
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+ } ) ;
13961419 }
13971420
13981421 pub fn serialize_query_result_cache < E > ( self ,
0 commit comments