@@ -82,13 +82,15 @@ use crate::hir;
8282pub struct AllArenas < ' tcx > {
8383 pub global : WorkerLocal < GlobalArenas < ' tcx > > ,
8484 pub interner : SyncDroplessArena ,
85+ pub local_interner : SyncDroplessArena ,
8586}
8687
8788impl < ' tcx > AllArenas < ' tcx > {
8889 pub fn new ( ) -> Self {
8990 AllArenas {
9091 global : WorkerLocal :: new ( |_| GlobalArenas :: default ( ) ) ,
9192 interner : SyncDroplessArena :: default ( ) ,
93+ local_interner : SyncDroplessArena :: default ( ) ,
9294 }
9395 }
9496}
@@ -154,7 +156,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
154156 /// Intern a type
155157 #[ inline( never) ]
156158 fn intern_ty (
157- local : & CtxtInterners < ' tcx > ,
159+ local : & CtxtInterners < ' gcx > ,
158160 global : & CtxtInterners < ' gcx > ,
159161 st : TyKind < ' tcx >
160162 ) -> Ty < ' tcx > {
@@ -179,6 +181,12 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
179181 & ty_struct) ;
180182 }
181183
184+ // This is safe because all the types the ty_struct can point to
185+ // already is in the local arena or the global arena
186+ let ty_struct: TyS < ' gcx > = unsafe {
187+ mem:: transmute ( ty_struct)
188+ } ;
189+
182190 Interned ( local. arena . alloc ( ty_struct) )
183191 } ) . 0
184192 } else {
@@ -1029,8 +1037,8 @@ pub struct FreeRegionInfo {
10291037#[ derive( Copy , Clone ) ]
10301038pub struct TyCtxt < ' a , ' gcx : ' tcx , ' tcx : ' a > {
10311039 gcx : & ' gcx GlobalCtxt < ' gcx > ,
1032- interners : & ' tcx CtxtInterners < ' tcx > ,
1033- dummy : PhantomData < & ' a ( ) > ,
1040+ interners : & ' gcx CtxtInterners < ' gcx > ,
1041+ dummy : PhantomData < ( & ' a ( ) , & ' tcx ( ) ) > ,
10341042}
10351043
10361044impl < ' gcx > Deref for TyCtxt < ' _ , ' gcx , ' _ > {
@@ -1045,6 +1053,7 @@ pub struct GlobalCtxt<'tcx> {
10451053 pub arena : WorkerLocal < Arena < ' tcx > > ,
10461054 global_arenas : & ' tcx WorkerLocal < GlobalArenas < ' tcx > > ,
10471055 global_interners : CtxtInterners < ' tcx > ,
1056+ local_interners : CtxtInterners < ' tcx > ,
10481057
10491058 cstore : & ' tcx CrateStoreDyn ,
10501059
@@ -1262,6 +1271,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12621271 s. fatal ( & err) ;
12631272 } ) ;
12641273 let interners = CtxtInterners :: new ( & arenas. interner ) ;
1274+ let local_interners = CtxtInterners :: new ( & arenas. local_interner ) ;
12651275 let common = Common {
12661276 empty_predicates : ty:: GenericPredicates {
12671277 parent : None ,
@@ -1321,6 +1331,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13211331 arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
13221332 global_arenas : & arenas. global ,
13231333 global_interners : interners,
1334+ local_interners : local_interners,
13241335 dep_graph,
13251336 common,
13261337 types : common_types,
@@ -1716,18 +1727,15 @@ impl<'gcx> GlobalCtxt<'gcx> {
17161727 /// with the same lifetime as `arena`.
17171728 pub fn enter_local < ' tcx , F , R > (
17181729 & ' gcx self ,
1719- arena : & ' tcx SyncDroplessArena ,
1720- interners : & ' tcx mut Option < CtxtInterners < ' tcx > > ,
17211730 f : F
17221731 ) -> R
17231732 where
17241733 F : FnOnce ( TyCtxt < ' tcx , ' gcx , ' tcx > ) -> R ,
17251734 ' gcx : ' tcx ,
17261735 {
1727- * interners = Some ( CtxtInterners :: new ( & arena) ) ;
17281736 let tcx = TyCtxt {
17291737 gcx : self ,
1730- interners : interners . as_ref ( ) . unwrap ( ) ,
1738+ interners : & self . local_interners ,
17311739 dummy : PhantomData ,
17321740 } ;
17331741 ty:: tls:: with_related_context ( tcx. global_tcx ( ) , |icx| {
@@ -2333,6 +2341,17 @@ macro_rules! intern_method {
23332341 pub fn $method( self , v: $alloc) -> & $lt_tcx $ty {
23342342 let key = ( $alloc_to_key) ( & v) ;
23352343
2344+ let alloc = |v, interners: & ' gcx CtxtInterners <' gcx>| {
2345+ // This transmutes $alloc<'tcx> to $alloc<'gcx>
2346+ let v = unsafe {
2347+ mem:: transmute( v)
2348+ } ;
2349+ let i: & $lt_tcx $ty = $alloc_method( & interners. arena, v) ;
2350+ // Cast to 'gcx
2351+ let i = unsafe { mem:: transmute( i) } ;
2352+ Interned ( i)
2353+ } ;
2354+
23362355 // HACK(eddyb) Depend on flags being accurate to
23372356 // determine that all contents are in the global tcx.
23382357 // See comments on Lift for why we can't use that.
@@ -2346,18 +2365,11 @@ macro_rules! intern_method {
23462365 v) ;
23472366 }
23482367
2349- Interned ( $alloc_method ( & self . interners. arena , v ) )
2368+ alloc ( v , & self . interners)
23502369 } ) . 0
23512370 } else {
23522371 self . global_interners. $name. borrow_mut( ) . intern_ref( key, || {
2353- // This transmutes $alloc<'tcx> to $alloc<'gcx>
2354- let v = unsafe {
2355- mem:: transmute( v)
2356- } ;
2357- let i: & $lt_tcx $ty = $alloc_method( & self . global_interners. arena, v) ;
2358- // Cast to 'gcx
2359- let i = unsafe { mem:: transmute( i) } ;
2360- Interned ( i)
2372+ alloc( v, & self . global_interners)
23612373 } ) . 0
23622374 }
23632375 }
0 commit comments