@@ -410,7 +410,7 @@ pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Opti
410
410
} ,
411
411
& AutoPtr ( r, m, Some ( box ref autoref) ) => {
412
412
match type_of_autoref ( cx, autoref) {
413
- Some ( ty) => Some ( mk_rptr ( cx, r , mt { mutbl : m, ty : ty} ) ) ,
413
+ Some ( ty) => Some ( mk_rptr ( cx, cx . mk_region ( r ) , mt { mutbl : m, ty : ty} ) ) ,
414
414
None => None
415
415
}
416
416
}
@@ -609,6 +609,7 @@ pub struct CtxtArenas<'tcx> {
609
609
type_ : TypedArena < TyS < ' tcx > > ,
610
610
substs : TypedArena < Substs < ' tcx > > ,
611
611
bare_fn : TypedArena < BareFnTy < ' tcx > > ,
612
+ region : TypedArena < Region > ,
612
613
}
613
614
614
615
impl < ' tcx > CtxtArenas < ' tcx > {
@@ -617,6 +618,7 @@ impl<'tcx> CtxtArenas<'tcx> {
617
618
type_ : TypedArena :: new ( ) ,
618
619
substs : TypedArena :: new ( ) ,
619
620
bare_fn : TypedArena :: new ( ) ,
621
+ region : TypedArena :: new ( ) ,
620
622
}
621
623
}
622
624
}
@@ -636,6 +638,7 @@ pub struct ctxt<'tcx> {
636
638
// FIXME as above, use a hashset if equivalent elements can be queried.
637
639
substs_interner : RefCell < FnvHashMap < & ' tcx Substs < ' tcx > , & ' tcx Substs < ' tcx > > > ,
638
640
bare_fn_interner : RefCell < FnvHashMap < & ' tcx BareFnTy < ' tcx > , & ' tcx BareFnTy < ' tcx > > > ,
641
+ region_interner : RefCell < FnvHashMap < & ' tcx Region , & ' tcx Region > > ,
639
642
640
643
pub sess : Session ,
641
644
pub def_map : DefMap ,
@@ -1340,7 +1343,7 @@ pub enum sty<'tcx> {
1340
1343
ty_str,
1341
1344
ty_vec( Ty < ' tcx > , Option < uint > ) , // Second field is length.
1342
1345
ty_ptr( mt < ' tcx > ) ,
1343
- ty_rptr( Region , mt < ' tcx > ) ,
1346
+ ty_rptr( & ' tcx Region , mt < ' tcx > ) ,
1344
1347
1345
1348
// If the def-id is Some(_), then this is the type of a specific
1346
1349
// fn item. Otherwise, if None(_), it a fn pointer type.
@@ -1350,7 +1353,7 @@ pub enum sty<'tcx> {
1350
1353
ty_trait( Box < TyTrait < ' tcx > > ) ,
1351
1354
ty_struct( DefId , & ' tcx Substs < ' tcx > ) ,
1352
1355
1353
- ty_unboxed_closure( DefId , Region , & ' tcx Substs < ' tcx > ) ,
1356
+ ty_unboxed_closure( DefId , & ' tcx Region , & ' tcx Substs < ' tcx > ) ,
1354
1357
1355
1358
ty_tup( Vec < Ty < ' tcx > > ) ,
1356
1359
@@ -2085,6 +2088,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
2085
2088
interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
2086
2089
substs_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
2087
2090
bare_fn_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
2091
+ region_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
2088
2092
named_region_map : named_region_map,
2089
2093
item_variance_map : RefCell :: new ( DefIdMap :: new ( ) ) ,
2090
2094
variance_computed : Cell :: new ( false ) ,
@@ -2164,6 +2168,16 @@ impl<'tcx> ctxt<'tcx> {
2164
2168
self . bare_fn_interner . borrow_mut ( ) . insert ( bare_fn, bare_fn) ;
2165
2169
bare_fn
2166
2170
}
2171
+
2172
+ pub fn mk_region ( & self , region : Region ) -> & ' tcx Region {
2173
+ if let Some ( region) = self . region_interner . borrow ( ) . get ( & region) {
2174
+ return * region;
2175
+ }
2176
+
2177
+ let region = self . arenas . region . alloc ( region) ;
2178
+ self . region_interner . borrow_mut ( ) . insert ( region, region) ;
2179
+ region
2180
+ }
2167
2181
}
2168
2182
2169
2183
// Interns a type/name combination, stores the resulting box in cx.interner,
@@ -2269,7 +2283,7 @@ impl FlagComputation {
2269
2283
}
2270
2284
}
2271
2285
2272
- & ty_unboxed_closure( _, ref region, substs) => {
2286
+ & ty_unboxed_closure( _, region, substs) => {
2273
2287
self . add_region ( * region) ;
2274
2288
self . add_substs ( substs) ;
2275
2289
}
@@ -2299,7 +2313,7 @@ impl FlagComputation {
2299
2313
}
2300
2314
2301
2315
& ty_rptr( r, ref m) => {
2302
- self . add_region ( r) ;
2316
+ self . add_region ( * r) ;
2303
2317
self . add_ty ( m. ty ) ;
2304
2318
}
2305
2319
@@ -2404,7 +2418,7 @@ pub fn mk_str<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> {
2404
2418
mk_t ( cx, ty_str)
2405
2419
}
2406
2420
2407
- pub fn mk_str_slice < ' tcx > ( cx : & ctxt < ' tcx > , r : Region , m : ast:: Mutability ) -> Ty < ' tcx > {
2421
+ pub fn mk_str_slice < ' tcx > ( cx : & ctxt < ' tcx > , r : & ' tcx Region , m : ast:: Mutability ) -> Ty < ' tcx > {
2408
2422
mk_rptr ( cx, r,
2409
2423
mt {
2410
2424
ty : mk_t ( cx, ty_str) ,
@@ -2421,14 +2435,14 @@ pub fn mk_uniq<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_un
2421
2435
2422
2436
pub fn mk_ptr < ' tcx > ( cx : & ctxt < ' tcx > , tm : mt < ' tcx > ) -> Ty < ' tcx > { mk_t ( cx, ty_ptr ( tm) ) }
2423
2437
2424
- pub fn mk_rptr < ' tcx > ( cx : & ctxt < ' tcx > , r : Region , tm : mt < ' tcx > ) -> Ty < ' tcx > {
2438
+ pub fn mk_rptr < ' tcx > ( cx : & ctxt < ' tcx > , r : & ' tcx Region , tm : mt < ' tcx > ) -> Ty < ' tcx > {
2425
2439
mk_t ( cx, ty_rptr ( r, tm) )
2426
2440
}
2427
2441
2428
- pub fn mk_mut_rptr < ' tcx > ( cx : & ctxt < ' tcx > , r : Region , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
2442
+ pub fn mk_mut_rptr < ' tcx > ( cx : & ctxt < ' tcx > , r : & ' tcx Region , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
2429
2443
mk_rptr ( cx, r, mt { ty : ty, mutbl : ast:: MutMutable } )
2430
2444
}
2431
- pub fn mk_imm_rptr < ' tcx > ( cx : & ctxt < ' tcx > , r : Region , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
2445
+ pub fn mk_imm_rptr < ' tcx > ( cx : & ctxt < ' tcx > , r : & ' tcx Region , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
2432
2446
mk_rptr ( cx, r, mt { ty : ty, mutbl : ast:: MutImmutable } )
2433
2447
}
2434
2448
@@ -2448,7 +2462,7 @@ pub fn mk_vec<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, sz: Option<uint>) -> Ty<'tcx>
2448
2462
mk_t ( cx, ty_vec ( ty, sz) )
2449
2463
}
2450
2464
2451
- pub fn mk_slice < ' tcx > ( cx : & ctxt < ' tcx > , r : Region , tm : mt < ' tcx > ) -> Ty < ' tcx > {
2465
+ pub fn mk_slice < ' tcx > ( cx : & ctxt < ' tcx > , r : & ' tcx Region , tm : mt < ' tcx > ) -> Ty < ' tcx > {
2452
2466
mk_rptr ( cx, r,
2453
2467
mt {
2454
2468
ty : mk_vec ( cx, tm. ty , None ) ,
@@ -2512,7 +2526,7 @@ pub fn mk_struct<'tcx>(cx: &ctxt<'tcx>, struct_id: ast::DefId,
2512
2526
}
2513
2527
2514
2528
pub fn mk_unboxed_closure < ' tcx > ( cx : & ctxt < ' tcx > , closure_id : ast:: DefId ,
2515
- region : Region , substs : & ' tcx Substs < ' tcx > )
2529
+ region : & ' tcx Region , substs : & ' tcx Substs < ' tcx > )
2516
2530
-> Ty < ' tcx > {
2517
2531
mk_t ( cx, ty_unboxed_closure ( closure_id, region, substs) )
2518
2532
}
@@ -3087,9 +3101,10 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
3087
3101
3088
3102
ty_rptr( r, ref mt) => {
3089
3103
TC :: ReachesFfiUnsafe | match mt. ty . sty {
3090
- ty_str => borrowed_contents ( r, ast:: MutImmutable ) ,
3091
- ty_vec( ..) => tc_ty ( cx, mt. ty , cache) . reference ( borrowed_contents ( r, mt. mutbl ) ) ,
3092
- _ => tc_ty ( cx, mt. ty , cache) . reference ( borrowed_contents ( r, mt. mutbl ) ) ,
3104
+ ty_str => borrowed_contents ( * r, ast:: MutImmutable ) ,
3105
+ ty_vec( ..) => tc_ty ( cx, mt. ty , cache) . reference ( borrowed_contents ( * r,
3106
+ mt. mutbl ) ) ,
3107
+ _ => tc_ty ( cx, mt. ty , cache) . reference ( borrowed_contents ( * r, mt. mutbl ) ) ,
3093
3108
}
3094
3109
}
3095
3110
@@ -3124,7 +3139,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
3124
3139
let upvars = unboxed_closure_upvars ( cx, did, substs) ;
3125
3140
TypeContents :: union ( upvars. as_slice ( ) ,
3126
3141
|f| tc_ty ( cx, f. ty , cache) )
3127
- | borrowed_contents ( r, MutMutable )
3142
+ | borrowed_contents ( * r, MutMutable )
3128
3143
}
3129
3144
3130
3145
ty_tup( ref tys) => {
@@ -3796,7 +3811,7 @@ pub fn deref<'tcx>(ty: Ty<'tcx>, explicit: bool) -> Option<mt<'tcx>> {
3796
3811
3797
3812
pub fn close_type < ' tcx > ( cx : & ctxt < ' tcx > , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
3798
3813
match ty. sty {
3799
- ty_open( ty) => mk_rptr ( cx, ReStatic , mt { ty : ty, mutbl : ast:: MutImmutable } ) ,
3814
+ ty_open( ty) => mk_rptr ( cx, cx . mk_region ( ReStatic ) , mt { ty : ty, mutbl : ast:: MutImmutable } ) ,
3800
3815
_ => cx. sess . bug ( format ! ( "Trying to close a non-open type {}" ,
3801
3816
ty_to_string( cx, ty) ) [ ] )
3802
3817
}
@@ -4000,7 +4015,7 @@ pub fn ty_region(tcx: &ctxt,
4000
4015
span : Span ,
4001
4016
ty : Ty ) -> Region {
4002
4017
match ty. sty {
4003
- ty_rptr( r, _) => r,
4018
+ ty_rptr( r, _) => * r,
4004
4019
ref s => {
4005
4020
tcx. sess . span_bug (
4006
4021
span,
@@ -4206,7 +4221,7 @@ pub fn adjust_ty_for_autoref<'tcx>(cx: &ctxt<'tcx>,
4206
4221
& Some ( box ref a) => adjust_ty_for_autoref ( cx, span, ty, Some ( a) ) ,
4207
4222
& None => ty
4208
4223
} ;
4209
- mk_rptr ( cx, r , mt {
4224
+ mk_rptr ( cx, cx . mk_region ( r ) , mt {
4210
4225
ty : adjusted_ty,
4211
4226
mutbl : m
4212
4227
} )
@@ -5494,7 +5509,7 @@ pub fn unboxed_closure_upvars<'tcx>(tcx: &ctxt<'tcx>, closure_id: ast::DefId, su
5494
5509
var_id : freevar_def_id. node ,
5495
5510
closure_expr_id : closure_id. node
5496
5511
} ] . clone ( ) ;
5497
- freevar_ty = mk_rptr ( tcx, borrow. region , ty:: mt {
5512
+ freevar_ty = mk_rptr ( tcx, tcx . mk_region ( borrow. region ) , ty:: mt {
5498
5513
ty : freevar_ty,
5499
5514
mutbl : borrow. kind . to_mutbl_lossy ( )
5500
5515
} ) ;
@@ -6348,7 +6363,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
6348
6363
walk_ty ( ty, |ty| {
6349
6364
match ty. sty {
6350
6365
ty_rptr( region, _) => {
6351
- accumulator. push ( region)
6366
+ accumulator. push ( * region)
6352
6367
}
6353
6368
ty_trait( ref t) => {
6354
6369
accumulator. push_all ( t. principal . substs ( ) . regions ( ) . as_slice ( ) ) ;
@@ -6363,7 +6378,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
6363
6378
UniqTraitStore => { }
6364
6379
}
6365
6380
}
6366
- ty_unboxed_closure( _, ref region, substs) => {
6381
+ ty_unboxed_closure( _, region, substs) => {
6367
6382
accumulator. push ( * region) ;
6368
6383
accum_substs ( accumulator, substs) ;
6369
6384
}
0 commit comments