@@ -57,12 +57,11 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
57
57
use rustc_data_structures:: stable_hasher:: { HashStable , hash_stable_hashmap,
58
58
StableHasher , StableHasherResult ,
59
59
StableVec } ;
60
- use arena:: { TypedArena , DroplessArena } ;
60
+ use arena:: { TypedArena , SyncDroplessArena } ;
61
61
use rustc_data_structures:: indexed_vec:: IndexVec ;
62
62
use rustc_data_structures:: sync:: { Lrc , Lock } ;
63
63
use std:: any:: Any ;
64
64
use std:: borrow:: Borrow ;
65
- use std:: cell:: Cell ;
66
65
use std:: cmp:: Ordering ;
67
66
use std:: collections:: hash_map:: { self , Entry } ;
68
67
use std:: hash:: { Hash , Hasher } ;
@@ -83,14 +82,14 @@ use hir;
83
82
84
83
pub struct AllArenas < ' tcx > {
85
84
pub global : GlobalArenas < ' tcx > ,
86
- pub interner : DroplessArena ,
85
+ pub interner : SyncDroplessArena ,
87
86
}
88
87
89
88
impl < ' tcx > AllArenas < ' tcx > {
90
89
pub fn new ( ) -> Self {
91
90
AllArenas {
92
91
global : GlobalArenas :: new ( ) ,
93
- interner : DroplessArena :: new ( ) ,
92
+ interner : SyncDroplessArena :: new ( ) ,
94
93
}
95
94
}
96
95
}
@@ -130,7 +129,7 @@ type InternedSet<'tcx, T> = Lock<FxHashSet<Interned<'tcx, T>>>;
130
129
131
130
pub struct CtxtInterners < ' tcx > {
132
131
/// The arena that types, regions, etc are allocated from
133
- arena : & ' tcx DroplessArena ,
132
+ arena : & ' tcx SyncDroplessArena ,
134
133
135
134
/// Specifically use a speedy hash algorithm for these hash sets,
136
135
/// they're accessed quite often.
@@ -147,7 +146,7 @@ pub struct CtxtInterners<'tcx> {
147
146
}
148
147
149
148
impl < ' gcx : ' tcx , ' tcx > CtxtInterners < ' tcx > {
150
- fn new ( arena : & ' tcx DroplessArena ) -> CtxtInterners < ' tcx > {
149
+ fn new ( arena : & ' tcx SyncDroplessArena ) -> CtxtInterners < ' tcx > {
151
150
CtxtInterners {
152
151
arena,
153
152
type_ : Default :: default ( ) ,
@@ -174,10 +173,10 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
174
173
return ty;
175
174
}
176
175
let global_interner = global_interners. map ( |interners| {
177
- interners. type_ . borrow_mut ( )
176
+ ( interners. type_ . borrow_mut ( ) , & interners . arena )
178
177
} ) ;
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) {
181
180
return ty;
182
181
}
183
182
}
@@ -193,18 +192,18 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
193
192
// determine that all contents are in the global tcx.
194
193
// See comments on Lift for why we can't use that.
195
194
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 {
197
196
let ty_struct: TyS < ' gcx > = unsafe {
198
197
mem:: transmute ( ty_struct)
199
198
} ;
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) ) ;
202
201
return ty;
203
202
}
204
203
} else {
205
204
// Make sure we don't end up with inference
206
205
// types/regions in the global tcx.
207
- if global_interners . is_none ( ) {
206
+ if global_interner . is_none ( ) {
208
207
drop ( interner) ;
209
208
bug ! ( "Attempted to intern `{:?}` which contains \
210
209
inference types/regions in the global type context",
@@ -915,9 +914,6 @@ pub struct GlobalCtxt<'tcx> {
915
914
/// Data layout specification for the current target.
916
915
pub data_layout : TargetDataLayout ,
917
916
918
- /// Used to prevent layout from recursing too deeply.
919
- pub layout_depth : Cell < usize > ,
920
-
921
917
stability_interner : Lock < FxHashSet < & ' tcx attr:: Stability > > ,
922
918
923
919
pub interpret_interner : InterpretInterner < ' tcx > ,
@@ -1292,7 +1288,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1292
1288
crate_name : Symbol :: intern ( crate_name) ,
1293
1289
data_layout,
1294
1290
layout_interner : Lock :: new ( FxHashSet ( ) ) ,
1295
- layout_depth : Cell :: new ( 0 ) ,
1296
1291
stability_interner : Lock :: new ( FxHashSet ( ) ) ,
1297
1292
interpret_interner : Default :: default ( ) ,
1298
1293
tx_to_llvm_workers : Lock :: new ( tx) ,
@@ -1559,7 +1554,7 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
1559
1554
/// Call the closure with a local `TyCtxt` using the given arena.
1560
1555
pub fn enter_local < F , R > (
1561
1556
& self ,
1562
- arena : & ' tcx DroplessArena ,
1557
+ arena : & ' tcx SyncDroplessArena ,
1563
1558
f : F
1564
1559
) -> R
1565
1560
where
@@ -1574,6 +1569,7 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
1574
1569
let new_icx = ty:: tls:: ImplicitCtxt {
1575
1570
tcx,
1576
1571
query : icx. query . clone ( ) ,
1572
+ layout_depth : icx. layout_depth ,
1577
1573
} ;
1578
1574
ty:: tls:: enter_context ( & new_icx, |new_icx| {
1579
1575
f ( new_icx. tcx )
@@ -1768,6 +1764,9 @@ pub mod tls {
1768
1764
/// The current query job, if any. This is updated by start_job in
1769
1765
/// ty::maps::plumbing when executing a query
1770
1766
pub query : Option < Lrc < maps:: QueryJob < ' gcx > > > ,
1767
+
1768
+ /// Used to prevent layout from recursing too deeply.
1769
+ pub layout_depth : usize ,
1771
1770
}
1772
1771
1773
1772
// A thread local value which stores a pointer to the current ImplicitCtxt
@@ -1853,6 +1852,7 @@ pub mod tls {
1853
1852
let icx = ImplicitCtxt {
1854
1853
tcx,
1855
1854
query : None ,
1855
+ layout_depth : 0 ,
1856
1856
} ;
1857
1857
enter_context ( & icx, |_| {
1858
1858
f ( tcx)
0 commit comments