1
- // ignore-tidy-filelength
2
-
3
1
//! Type context book-keeping.
4
2
5
3
use crate :: arena:: Arena ;
@@ -67,7 +65,6 @@ use std::ops::{Deref, Bound};
67
65
use std:: iter;
68
66
use std:: sync:: mpsc;
69
67
use std:: sync:: Arc ;
70
- use std:: marker:: PhantomData ;
71
68
use rustc_target:: spec:: abi;
72
69
use rustc_macros:: HashStable ;
73
70
use syntax:: ast;
@@ -81,14 +78,12 @@ use crate::hir;
81
78
82
79
pub struct AllArenas {
83
80
pub interner : SyncDroplessArena ,
84
- pub local_interner : SyncDroplessArena ,
85
81
}
86
82
87
83
impl AllArenas {
88
84
pub fn new ( ) -> Self {
89
85
AllArenas {
90
86
interner : SyncDroplessArena :: default ( ) ,
91
- local_interner : SyncDroplessArena :: default ( ) ,
92
87
}
93
88
}
94
89
}
@@ -136,57 +131,21 @@ impl<'tcx> CtxtInterners<'tcx> {
136
131
137
132
/// Intern a type
138
133
#[ inline( never) ]
139
- fn intern_ty (
140
- local : & CtxtInterners < ' tcx > ,
141
- global : & CtxtInterners < ' tcx > ,
142
- st : TyKind < ' tcx > ,
134
+ fn intern_ty ( & self ,
135
+ st : TyKind < ' tcx >
143
136
) -> Ty < ' tcx > {
144
- let flags = super :: flags:: FlagComputation :: for_sty ( & st) ;
145
-
146
- // HACK(eddyb) Depend on flags being accurate to
147
- // determine that all contents are in the global tcx.
148
- // See comments on Lift for why we can't use that.
149
- if flags. flags . intersects ( ty:: TypeFlags :: KEEP_IN_LOCAL_TCX ) {
150
- local. type_ . borrow_mut ( ) . intern ( st, |st| {
151
- let ty_struct = TyS {
152
- sty : st,
153
- flags : flags. flags ,
154
- outer_exclusive_binder : flags. outer_exclusive_binder ,
155
- } ;
137
+ self . type_ . borrow_mut ( ) . intern ( st, |st| {
138
+ let flags = super :: flags:: FlagComputation :: for_sty ( & st) ;
156
139
157
- // Make sure we don't end up with inference
158
- // types/regions in the global interner
159
- if ptr_eq ( local, global) {
160
- bug ! ( "Attempted to intern `{:?}` which contains \
161
- inference types/regions in the global type context",
162
- & ty_struct) ;
163
- }
164
-
165
- // This is safe because all the types the ty_struct can point to
166
- // already is in the local arena or the global arena
167
- let ty_struct: TyS < ' tcx > = unsafe {
168
- mem:: transmute ( ty_struct)
169
- } ;
170
-
171
- Interned ( local. arena . alloc ( ty_struct) )
172
- } ) . 0
173
- } else {
174
- global. type_ . borrow_mut ( ) . intern ( st, |st| {
175
- let ty_struct = TyS {
176
- sty : st,
177
- flags : flags. flags ,
178
- outer_exclusive_binder : flags. outer_exclusive_binder ,
179
- } ;
140
+ let ty_struct = TyS {
141
+ sty : st,
142
+ flags : flags. flags ,
143
+ outer_exclusive_binder : flags. outer_exclusive_binder ,
144
+ } ;
180
145
181
- // This is safe because all the types the ty_struct can point to
182
- // already is in the global arena
183
- let ty_struct: TyS < ' tcx > = unsafe {
184
- mem:: transmute ( ty_struct)
185
- } ;
186
146
187
- Interned ( global. arena . alloc ( ty_struct) )
188
- } ) . 0
189
- }
147
+ Interned ( self . arena . alloc ( ty_struct) )
148
+ } ) . 0
190
149
}
191
150
}
192
151
@@ -933,7 +892,7 @@ EnumLiftImpl! {
933
892
934
893
impl < ' tcx > CommonTypes < ' tcx > {
935
894
fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonTypes < ' tcx > {
936
- let mk = |sty| CtxtInterners :: intern_ty ( interners , interners , sty) ;
895
+ let mk = |sty| interners . intern_ty ( sty) ;
937
896
938
897
CommonTypes {
939
898
unit : mk ( Tuple ( List :: empty ( ) ) ) ,
@@ -1015,8 +974,6 @@ pub struct FreeRegionInfo {
1015
974
#[ derive( Copy , Clone ) ]
1016
975
pub struct TyCtxt < ' tcx > {
1017
976
gcx : & ' tcx GlobalCtxt < ' tcx > ,
1018
- interners : & ' tcx CtxtInterners < ' tcx > ,
1019
- dummy : PhantomData < & ' tcx ( ) > ,
1020
977
}
1021
978
1022
979
impl < ' tcx > Deref for TyCtxt < ' tcx > {
@@ -1030,8 +987,7 @@ impl<'tcx> Deref for TyCtxt<'tcx> {
1030
987
pub struct GlobalCtxt < ' tcx > {
1031
988
pub arena : WorkerLocal < Arena < ' tcx > > ,
1032
989
1033
- global_interners : CtxtInterners < ' tcx > ,
1034
- local_interners : CtxtInterners < ' tcx > ,
990
+ interners : CtxtInterners < ' tcx > ,
1035
991
1036
992
cstore : & ' tcx CrateStoreDyn ,
1037
993
@@ -1122,8 +1078,6 @@ impl<'tcx> TyCtxt<'tcx> {
1122
1078
pub fn global_tcx ( self ) -> TyCtxt < ' tcx > {
1123
1079
TyCtxt {
1124
1080
gcx : self . gcx ,
1125
- interners : & self . gcx . global_interners ,
1126
- dummy : PhantomData ,
1127
1081
}
1128
1082
}
1129
1083
@@ -1203,11 +1157,6 @@ impl<'tcx> TyCtxt<'tcx> {
1203
1157
value. lift_to_tcx ( self . global_tcx ( ) )
1204
1158
}
1205
1159
1206
- /// Returns `true` if self is the same as self.global_tcx().
1207
- fn is_global ( self ) -> bool {
1208
- ptr_eq ( self . interners , & self . global_interners )
1209
- }
1210
-
1211
1160
/// Creates a type context and call the closure with a `TyCtxt` reference
1212
1161
/// to the context. The closure enforces that the type context and any interned
1213
1162
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
@@ -1229,7 +1178,6 @@ impl<'tcx> TyCtxt<'tcx> {
1229
1178
s. fatal ( & err) ;
1230
1179
} ) ;
1231
1180
let interners = CtxtInterners :: new ( & arenas. interner ) ;
1232
- let local_interners = CtxtInterners :: new ( & arenas. local_interner ) ;
1233
1181
let common = Common {
1234
1182
empty_predicates : ty:: GenericPredicates {
1235
1183
parent : None ,
@@ -1287,8 +1235,7 @@ impl<'tcx> TyCtxt<'tcx> {
1287
1235
sess : s,
1288
1236
cstore,
1289
1237
arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
1290
- global_interners : interners,
1291
- local_interners : local_interners,
1238
+ interners,
1292
1239
dep_graph,
1293
1240
common,
1294
1241
types : common_types,
@@ -1682,8 +1629,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
1682
1629
{
1683
1630
let tcx = TyCtxt {
1684
1631
gcx : self ,
1685
- interners : & self . local_interners ,
1686
- dummy : PhantomData ,
1687
1632
} ;
1688
1633
ty:: tls:: with_related_context ( tcx. global_tcx ( ) , |icx| {
1689
1634
let new_icx = ty:: tls:: ImplicitCtxt {
@@ -1729,11 +1674,7 @@ macro_rules! nop_lift {
1729
1674
type Lifted = $lifted;
1730
1675
fn lift_to_tcx( & self , tcx: TyCtxt <' tcx>) -> Option <Self :: Lifted > {
1731
1676
if tcx. interners. arena. in_arena( * self as * const _) {
1732
- return Some ( unsafe { mem:: transmute( * self ) } ) ;
1733
- }
1734
- // Also try in the global tcx if we're not that.
1735
- if !tcx. is_global( ) {
1736
- self . lift_to_tcx( tcx. global_tcx( ) )
1677
+ Some ( unsafe { mem:: transmute( * self ) } )
1737
1678
} else {
1738
1679
None
1739
1680
}
@@ -1751,11 +1692,7 @@ macro_rules! nop_list_lift {
1751
1692
return Some ( List :: empty( ) ) ;
1752
1693
}
1753
1694
if tcx. interners. arena. in_arena( * self as * const _) {
1754
- return Some ( unsafe { mem:: transmute( * self ) } ) ;
1755
- }
1756
- // Also try in the global tcx if we're not that.
1757
- if !tcx. is_global( ) {
1758
- self . lift_to_tcx( tcx. global_tcx( ) )
1695
+ Some ( unsafe { mem:: transmute( * self ) } )
1759
1696
} else {
1760
1697
None
1761
1698
}
@@ -1785,7 +1722,6 @@ pub mod tls {
1785
1722
1786
1723
use std:: fmt;
1787
1724
use std:: mem;
1788
- use std:: marker:: PhantomData ;
1789
1725
use syntax_pos;
1790
1726
use crate :: ty:: query;
1791
1727
use errors:: { Diagnostic , TRACK_DIAGNOSTICS } ;
@@ -1949,8 +1885,6 @@ pub mod tls {
1949
1885
1950
1886
let tcx = TyCtxt {
1951
1887
gcx,
1952
- interners : & gcx. global_interners ,
1953
- dummy : PhantomData ,
1954
1888
} ;
1955
1889
let icx = ImplicitCtxt {
1956
1890
tcx,
@@ -1981,8 +1915,6 @@ pub mod tls {
1981
1915
let gcx = & * ( gcx as * const GlobalCtxt < ' _ > ) ;
1982
1916
let tcx = TyCtxt {
1983
1917
gcx,
1984
- interners : & gcx. global_interners ,
1985
- dummy : PhantomData ,
1986
1918
} ;
1987
1919
let icx = ImplicitCtxt {
1988
1920
query : None ,
@@ -2041,26 +1973,6 @@ pub mod tls {
2041
1973
} )
2042
1974
}
2043
1975
2044
- /// Allows access to the current ImplicitCtxt whose tcx field has the same global
2045
- /// interner and local interner as the tcx argument passed in. This means the closure
2046
- /// is given an ImplicitCtxt with the same 'tcx and 'tcx lifetimes as the TyCtxt passed in.
2047
- /// This will panic if you pass it a TyCtxt which has a different global interner or
2048
- /// a different local interner from the current ImplicitCtxt's tcx field.
2049
- #[ inline]
2050
- pub fn with_fully_related_context < ' tcx , F , R > ( tcx : TyCtxt < ' tcx > , f : F ) -> R
2051
- where
2052
- F : for < ' b > FnOnce ( & ImplicitCtxt < ' b , ' tcx > ) -> R ,
2053
- {
2054
- with_context ( |context| {
2055
- unsafe {
2056
- assert ! ( ptr_eq( context. tcx. gcx, tcx. gcx) ) ;
2057
- assert ! ( ptr_eq( context. tcx. interners, tcx. interners) ) ;
2058
- let context: & ImplicitCtxt < ' _ , ' _ > = mem:: transmute ( context) ;
2059
- f ( context)
2060
- }
2061
- } )
2062
- }
2063
-
2064
1976
/// Allows access to the TyCtxt in the current ImplicitCtxt.
2065
1977
/// Panics if there is no ImplicitCtxt available
2066
1978
#[ inline]
@@ -2288,39 +2200,22 @@ impl<'tcx> Borrow<[Goal<'tcx>]> for Interned<'tcx, List<Goal<'tcx>>> {
2288
2200
macro_rules! intern_method {
2289
2201
( $lt_tcx: tt, $name: ident: $method: ident( $alloc: ty,
2290
2202
$alloc_method: expr,
2291
- $alloc_to_key: expr,
2292
- $keep_in_local_tcx: expr) -> $ty: ty) => {
2203
+ $alloc_to_key: expr) -> $ty: ty) => {
2293
2204
impl <$lt_tcx> TyCtxt <$lt_tcx> {
2294
2205
pub fn $method( self , v: $alloc) -> & $lt_tcx $ty {
2295
2206
let key = ( $alloc_to_key) ( & v) ;
2296
2207
2297
- // HACK(eddyb) Depend on flags being accurate to
2298
- // determine that all contents are in the global tcx.
2299
- // See comments on Lift for why we can't use that.
2300
- if ( $keep_in_local_tcx) ( & v) {
2301
- self . interners. $name. borrow_mut( ) . intern_ref( key, || {
2302
- // Make sure we don't end up with inference
2303
- // types/regions in the global tcx.
2304
- if self . is_global( ) {
2305
- bug!( "Attempted to intern `{:?}` which contains \
2306
- inference types/regions in the global type context",
2307
- v) ;
2308
- }
2208
+ self . interners. $name. borrow_mut( ) . intern_ref( key, || {
2209
+ Interned ( $alloc_method( & self . interners. arena, v) )
2309
2210
2310
- Interned ( $alloc_method( & self . interners. arena, v) )
2311
- } ) . 0
2312
- } else {
2313
- self . global_interners. $name. borrow_mut( ) . intern_ref( key, || {
2314
- Interned ( $alloc_method( & self . global_interners. arena, v) )
2315
- } ) . 0
2316
- }
2211
+ } ) . 0
2317
2212
}
2318
2213
}
2319
2214
}
2320
2215
}
2321
2216
2322
2217
macro_rules! direct_interners {
2323
- ( $lt_tcx: tt, $( $name: ident: $method: ident( $keep_in_local_tcx : expr ) -> $ ty: ty) ,+) => {
2218
+ ( $lt_tcx: tt, $( $name: ident: $method: ident( $ty: ty) ) ,+) => {
2324
2219
$( impl <$lt_tcx> PartialEq for Interned <$lt_tcx, $ty> {
2325
2220
fn eq( & self , other: & Self ) -> bool {
2326
2221
self . 0 == other. 0
@@ -2339,8 +2234,7 @@ macro_rules! direct_interners {
2339
2234
$lt_tcx,
2340
2235
$name: $method( $ty,
2341
2236
|a: & $lt_tcx SyncDroplessArena , v| -> & $lt_tcx $ty { a. alloc( v) } ,
2342
- |x| x,
2343
- $keep_in_local_tcx) -> $ty) ; ) +
2237
+ |x| x) -> $ty) ; ) +
2344
2238
}
2345
2239
}
2346
2240
@@ -2349,18 +2243,17 @@ pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
2349
2243
}
2350
2244
2351
2245
direct_interners ! ( ' tcx,
2352
- region: mk_region( |r : & RegionKind | r . keep_in_local_tcx ( ) ) -> RegionKind ,
2353
- goal: mk_goal( |c : & GoalKind <' _>| keep_local ( c ) ) -> GoalKind < ' tcx>,
2354
- const_: mk_const( |c : & Const <' _>| keep_local ( & c ) ) -> Const < ' tcx>
2246
+ region: mk_region( RegionKind ) ,
2247
+ goal: mk_goal( GoalKind <' tcx>) ,
2248
+ const_: mk_const( Const <' tcx>)
2355
2249
) ;
2356
2250
2357
2251
macro_rules! slice_interners {
2358
2252
( $( $field: ident: $method: ident( $ty: ty) ) ,+) => (
2359
2253
$( intern_method!( ' tcx, $field: $method(
2360
2254
& [ $ty] ,
2361
2255
|a, v| List :: from_arena( a, v) ,
2362
- Deref :: deref,
2363
- |xs: & [ $ty] | xs. iter( ) . any( keep_local) ) -> List <$ty>) ; ) +
2256
+ Deref :: deref) -> List <$ty>) ; ) +
2364
2257
) ;
2365
2258
}
2366
2259
@@ -2384,8 +2277,7 @@ intern_method! {
2384
2277
canonical_var_infos: _intern_canonical_var_infos(
2385
2278
& [ CanonicalVarInfo ] ,
2386
2279
|a, v| List :: from_arena( a, v) ,
2387
- Deref :: deref,
2388
- |_xs: & [ CanonicalVarInfo ] | -> bool { false }
2280
+ Deref :: deref
2389
2281
) -> List <CanonicalVarInfo >
2390
2282
}
2391
2283
@@ -2431,7 +2323,7 @@ impl<'tcx> TyCtxt<'tcx> {
2431
2323
2432
2324
#[ inline]
2433
2325
pub fn mk_ty ( & self , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
2434
- CtxtInterners :: intern_ty ( & self . interners , & self . global_interners , st)
2326
+ self . interners . intern_ty ( st)
2435
2327
}
2436
2328
2437
2329
pub fn mk_mach_int ( self , tm : ast:: IntTy ) -> Ty < ' tcx > {
0 commit comments