@@ -72,6 +72,7 @@ use std::ops::{Deref, Bound};
7272use std:: iter;
7373use std:: sync:: mpsc;
7474use std:: sync:: Arc ;
75+ use std:: marker:: PhantomData ;
7576use rustc_target:: spec:: abi;
7677use syntax:: ast:: { self , NodeId } ;
7778use syntax:: attr;
@@ -86,13 +87,15 @@ use hir;
8687pub struct AllArenas < ' tcx > {
8788 pub global : WorkerLocal < GlobalArenas < ' tcx > > ,
8889 pub interner : SyncDroplessArena ,
90+ global_ctxt : Option < GlobalCtxt < ' tcx > > ,
8991}
9092
9193impl < ' tcx > AllArenas < ' tcx > {
9294 pub fn new ( ) -> Self {
9395 AllArenas {
9496 global : WorkerLocal :: new ( |_| GlobalArenas :: default ( ) ) ,
9597 interner : SyncDroplessArena :: default ( ) ,
98+ global_ctxt : None ,
9699 }
97100 }
98101}
@@ -869,12 +872,13 @@ pub struct FreeRegionInfo {
869872/// [rustc guide]: https://rust-lang.github.io/rustc-guide/ty.html
870873#[ derive( Copy , Clone ) ]
871874pub struct TyCtxt < ' a , ' gcx : ' tcx , ' tcx : ' a > {
872- gcx : & ' a GlobalCtxt < ' gcx > ,
873- interners : & ' a CtxtInterners < ' tcx >
875+ gcx : & ' gcx GlobalCtxt < ' gcx > ,
876+ interners : & ' tcx CtxtInterners < ' tcx > ,
877+ dummy : PhantomData < & ' a ( ) > ,
874878}
875879
876- impl < ' a , ' gcx , ' tcx > Deref for TyCtxt < ' a , ' gcx , ' tcx > {
877- type Target = & ' a GlobalCtxt < ' gcx > ;
880+ impl < ' gcx > Deref for TyCtxt < ' _ , ' gcx , ' _ > {
881+ type Target = & ' gcx GlobalCtxt < ' gcx > ;
878882 #[ inline( always) ]
879883 fn deref ( & self ) -> & Self :: Target {
880884 & self . gcx
@@ -964,10 +968,11 @@ pub struct GlobalCtxt<'tcx> {
964968impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
965969 /// Get the global TyCtxt.
966970 #[ inline]
967- pub fn global_tcx ( self ) -> TyCtxt < ' a , ' gcx , ' gcx > {
971+ pub fn global_tcx ( self ) -> TyCtxt < ' gcx , ' gcx , ' gcx > {
968972 TyCtxt {
969973 gcx : self . gcx ,
970974 interners : & self . gcx . global_interners ,
975+ dummy : PhantomData ,
971976 }
972977 }
973978
@@ -1105,7 +1110,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11051110 cstore : & ' tcx CrateStoreDyn ,
11061111 local_providers : ty:: query:: Providers < ' tcx > ,
11071112 extern_providers : ty:: query:: Providers < ' tcx > ,
1108- arenas : & ' tcx AllArenas < ' tcx > ,
1113+ arenas : & ' tcx mut AllArenas < ' tcx > ,
11091114 resolutions : ty:: Resolutions ,
11101115 hir : hir_map:: Map < ' tcx > ,
11111116 on_disk_query_result_cache : query:: OnDiskCache < ' tcx > ,
@@ -1166,7 +1171,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11661171 Lrc :: new ( StableVec :: new ( v) ) ) ;
11671172 }
11681173
1169- let gcx = & GlobalCtxt {
1174+ arenas . global_ctxt = Some ( GlobalCtxt {
11701175 sess : s,
11711176 cstore,
11721177 global_arenas : & arenas. global ,
@@ -1209,7 +1214,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12091214 alloc_map : Lock :: new ( interpret:: AllocMap :: new ( ) ) ,
12101215 tx_to_llvm_workers : Lock :: new ( tx) ,
12111216 output_filenames : Arc :: new ( output_filenames. clone ( ) ) ,
1212- } ;
1217+ } ) ;
1218+
1219+ let gcx = arenas. global_ctxt . as_ref ( ) . unwrap ( ) ;
12131220
12141221 sync:: assert_send_val ( & gcx) ;
12151222
@@ -1609,20 +1616,23 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
16091616 }
16101617}
16111618
1612- impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
1619+ impl < ' gcx > GlobalCtxt < ' gcx > {
16131620 /// Call the closure with a local `TyCtxt` using the given arena.
1614- pub fn enter_local < F , R > (
1615- & self ,
1621+ pub fn enter_local < ' tcx , F , R > (
1622+ & ' gcx self ,
16161623 arena : & ' tcx SyncDroplessArena ,
1624+ interners : & ' tcx mut Option < CtxtInterners < ' tcx > > ,
16171625 f : F
16181626 ) -> R
16191627 where
1620- F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
1628+ F : FnOnce ( TyCtxt < ' tcx , ' gcx , ' tcx > ) -> R ,
1629+ ' gcx : ' tcx ,
16211630 {
1622- let interners = CtxtInterners :: new ( arena) ;
1631+ * interners = Some ( CtxtInterners :: new ( & arena) ) ;
16231632 let tcx = TyCtxt {
16241633 gcx : self ,
1625- interners : & interners,
1634+ interners : interners. as_ref ( ) . unwrap ( ) ,
1635+ dummy : PhantomData ,
16261636 } ;
16271637 ty:: tls:: with_related_context ( tcx. global_tcx ( ) , |icx| {
16281638 let new_icx = ty:: tls:: ImplicitCtxt {
@@ -1631,8 +1641,8 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
16311641 layout_depth : icx. layout_depth ,
16321642 task : icx. task ,
16331643 } ;
1634- ty:: tls:: enter_context ( & new_icx, |new_icx | {
1635- f ( new_icx . tcx )
1644+ ty:: tls:: enter_context ( & new_icx, |_ | {
1645+ f ( tcx)
16361646 } )
16371647 } )
16381648 }
@@ -1872,6 +1882,7 @@ pub mod tls {
18721882
18731883 use std:: fmt;
18741884 use std:: mem;
1885+ use std:: marker:: PhantomData ;
18751886 use syntax_pos;
18761887 use ty:: query;
18771888 use errors:: { Diagnostic , TRACK_DIAGNOSTICS } ;
@@ -1891,10 +1902,10 @@ pub mod tls {
18911902 /// you should also have access to an ImplicitCtxt through the functions
18921903 /// in this module.
18931904 #[ derive( Clone ) ]
1894- pub struct ImplicitCtxt < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
1905+ pub struct ImplicitCtxt < ' a , ' gcx : ' tcx , ' tcx > {
18951906 /// The current TyCtxt. Initially created by `enter_global` and updated
18961907 /// by `enter_local` with a new local interner
1897- pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
1908+ pub tcx : TyCtxt < ' tcx , ' gcx , ' tcx > ,
18981909
18991910 /// The current query job, if any. This is updated by start_job in
19001911 /// ty::query::plumbing when executing a query
@@ -2008,7 +2019,7 @@ pub mod tls {
20082019 /// creating a initial TyCtxt and ImplicitCtxt.
20092020 /// This happens once per rustc session and TyCtxts only exists
20102021 /// inside the `f` function.
2011- pub fn enter_global < ' gcx , F , R > ( gcx : & GlobalCtxt < ' gcx > , f : F ) -> R
2022+ pub fn enter_global < ' gcx , F , R > ( gcx : & ' gcx GlobalCtxt < ' gcx > , f : F ) -> R
20122023 where F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' gcx > ) -> R
20132024 {
20142025 with_thread_locals ( || {
@@ -2024,6 +2035,7 @@ pub mod tls {
20242035 let tcx = TyCtxt {
20252036 gcx,
20262037 interners : & gcx. global_interners ,
2038+ dummy : PhantomData ,
20272039 } ;
20282040 let icx = ImplicitCtxt {
20292041 tcx,
@@ -2053,6 +2065,7 @@ pub mod tls {
20532065 let tcx = TyCtxt {
20542066 gcx,
20552067 interners : & gcx. global_interners ,
2068+ dummy : PhantomData ,
20562069 } ;
20572070 let icx = ImplicitCtxt {
20582071 query : None ,
0 commit comments