@@ -57,12 +57,11 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
5757use rustc_data_structures:: stable_hasher:: { HashStable , hash_stable_hashmap,
5858 StableHasher , StableHasherResult ,
5959 StableVec } ;
60- use arena:: { TypedArena , DroplessArena } ;
60+ use arena:: { TypedArena , SyncDroplessArena } ;
6161use rustc_data_structures:: indexed_vec:: IndexVec ;
6262use rustc_data_structures:: sync:: { Lrc , Lock } ;
6363use std:: any:: Any ;
6464use std:: borrow:: Borrow ;
65- use std:: cell:: Cell ;
6665use std:: cmp:: Ordering ;
6766use std:: collections:: hash_map:: { self , Entry } ;
6867use std:: hash:: { Hash , Hasher } ;
@@ -83,14 +82,14 @@ use hir;
8382
8483pub struct AllArenas < ' tcx > {
8584 pub global : GlobalArenas < ' tcx > ,
86- pub interner : DroplessArena ,
85+ pub interner : SyncDroplessArena ,
8786}
8887
8988impl < ' tcx > AllArenas < ' tcx > {
9089 pub fn new ( ) -> Self {
9190 AllArenas {
9291 global : GlobalArenas :: new ( ) ,
93- interner : DroplessArena :: new ( ) ,
92+ interner : SyncDroplessArena :: new ( ) ,
9493 }
9594 }
9695}
@@ -130,7 +129,7 @@ type InternedSet<'tcx, T> = Lock<FxHashSet<Interned<'tcx, T>>>;
130129
131130pub struct CtxtInterners < ' tcx > {
132131 /// The arena that types, regions, etc are allocated from
133- arena : & ' tcx DroplessArena ,
132+ arena : & ' tcx SyncDroplessArena ,
134133
135134 /// Specifically use a speedy hash algorithm for these hash sets,
136135 /// they're accessed quite often.
@@ -147,7 +146,7 @@ pub struct CtxtInterners<'tcx> {
147146}
148147
149148impl < ' gcx : ' tcx , ' tcx > CtxtInterners < ' tcx > {
150- fn new ( arena : & ' tcx DroplessArena ) -> CtxtInterners < ' tcx > {
149+ fn new ( arena : & ' tcx SyncDroplessArena ) -> CtxtInterners < ' tcx > {
151150 CtxtInterners {
152151 arena,
153152 type_ : Default :: default ( ) ,
@@ -174,10 +173,10 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
174173 return ty;
175174 }
176175 let global_interner = global_interners. map ( |interners| {
177- interners. type_ . borrow_mut ( )
176+ ( interners. type_ . borrow_mut ( ) , & interners . arena )
178177 } ) ;
179- if let Some ( ref interner ) = global_interner {
180- if let Some ( & Interned ( ty) ) = interner . get ( & st) {
178+ if let Some ( ( ref type_ , _ ) ) = global_interner {
179+ if let Some ( & Interned ( ty) ) = type_ . get ( & st) {
181180 return ty;
182181 }
183182 }
@@ -193,18 +192,18 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
193192 // determine that all contents are in the global tcx.
194193 // See comments on Lift for why we can't use that.
195194 if !flags. flags . intersects ( ty:: TypeFlags :: KEEP_IN_LOCAL_TCX ) {
196- if let Some ( interner ) = global_interners {
195+ if let Some ( ( mut type_ , arena ) ) = global_interner {
197196 let ty_struct: TyS < ' gcx > = unsafe {
198197 mem:: transmute ( ty_struct)
199198 } ;
200- let ty: Ty < ' gcx > = interner . arena . alloc ( ty_struct) ;
201- global_interner . unwrap ( ) . insert ( Interned ( ty) ) ;
199+ let ty: Ty < ' gcx > = arena. alloc ( ty_struct) ;
200+ type_ . insert ( Interned ( ty) ) ;
202201 return ty;
203202 }
204203 } else {
205204 // Make sure we don't end up with inference
206205 // types/regions in the global tcx.
207- if global_interners . is_none ( ) {
206+ if global_interner . is_none ( ) {
208207 drop ( interner) ;
209208 bug ! ( "Attempted to intern `{:?}` which contains \
210209 inference types/regions in the global type context",
@@ -915,9 +914,6 @@ pub struct GlobalCtxt<'tcx> {
915914 /// Data layout specification for the current target.
916915 pub data_layout : TargetDataLayout ,
917916
918- /// Used to prevent layout from recursing too deeply.
919- pub layout_depth : Cell < usize > ,
920-
921917 stability_interner : Lock < FxHashSet < & ' tcx attr:: Stability > > ,
922918
923919 pub interpret_interner : InterpretInterner < ' tcx > ,
@@ -1292,7 +1288,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12921288 crate_name : Symbol :: intern ( crate_name) ,
12931289 data_layout,
12941290 layout_interner : Lock :: new ( FxHashSet ( ) ) ,
1295- layout_depth : Cell :: new ( 0 ) ,
12961291 stability_interner : Lock :: new ( FxHashSet ( ) ) ,
12971292 interpret_interner : Default :: default ( ) ,
12981293 tx_to_llvm_workers : Lock :: new ( tx) ,
@@ -1559,7 +1554,7 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
15591554 /// Call the closure with a local `TyCtxt` using the given arena.
15601555 pub fn enter_local < F , R > (
15611556 & self ,
1562- arena : & ' tcx DroplessArena ,
1557+ arena : & ' tcx SyncDroplessArena ,
15631558 f : F
15641559 ) -> R
15651560 where
@@ -1574,6 +1569,7 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
15741569 let new_icx = ty:: tls:: ImplicitCtxt {
15751570 tcx,
15761571 query : icx. query . clone ( ) ,
1572+ layout_depth : icx. layout_depth ,
15771573 } ;
15781574 ty:: tls:: enter_context ( & new_icx, |new_icx| {
15791575 f ( new_icx. tcx )
@@ -1768,6 +1764,9 @@ pub mod tls {
17681764 /// The current query job, if any. This is updated by start_job in
17691765 /// ty::maps::plumbing when executing a query
17701766 pub query : Option < Lrc < maps:: QueryJob < ' gcx > > > ,
1767+
1768+ /// Used to prevent layout from recursing too deeply.
1769+ pub layout_depth : usize ,
17711770 }
17721771
17731772 // A thread local value which stores a pointer to the current ImplicitCtxt
@@ -1853,6 +1852,7 @@ pub mod tls {
18531852 let icx = ImplicitCtxt {
18541853 tcx,
18551854 query : None ,
1855+ layout_depth : 0 ,
18561856 } ;
18571857 enter_context ( & icx, |_| {
18581858 f ( tcx)
0 commit comments