@@ -410,7 +410,7 @@ pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Opti
410410 } ,
411411 & AutoPtr ( r, m, Some ( box ref autoref) ) => {
412412 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} ) ) ,
414414 None => None
415415 }
416416 }
@@ -609,6 +609,7 @@ pub struct CtxtArenas<'tcx> {
609609 type_ : TypedArena < TyS < ' tcx > > ,
610610 substs : TypedArena < Substs < ' tcx > > ,
611611 bare_fn : TypedArena < BareFnTy < ' tcx > > ,
612+ region : TypedArena < Region > ,
612613}
613614
614615impl < ' tcx > CtxtArenas < ' tcx > {
@@ -617,6 +618,7 @@ impl<'tcx> CtxtArenas<'tcx> {
617618 type_ : TypedArena :: new ( ) ,
618619 substs : TypedArena :: new ( ) ,
619620 bare_fn : TypedArena :: new ( ) ,
621+ region : TypedArena :: new ( ) ,
620622 }
621623 }
622624}
@@ -636,6 +638,7 @@ pub struct ctxt<'tcx> {
636638 // FIXME as above, use a hashset if equivalent elements can be queried.
637639 substs_interner : RefCell < FnvHashMap < & ' tcx Substs < ' tcx > , & ' tcx Substs < ' tcx > > > ,
638640 bare_fn_interner : RefCell < FnvHashMap < & ' tcx BareFnTy < ' tcx > , & ' tcx BareFnTy < ' tcx > > > ,
641+ region_interner : RefCell < FnvHashMap < & ' tcx Region , & ' tcx Region > > ,
639642
640643 pub sess : Session ,
641644 pub def_map : DefMap ,
@@ -1340,7 +1343,7 @@ pub enum sty<'tcx> {
13401343 ty_str,
13411344 ty_vec( Ty < ' tcx > , Option < uint > ) , // Second field is length.
13421345 ty_ptr( mt < ' tcx > ) ,
1343- ty_rptr( Region , mt < ' tcx > ) ,
1346+ ty_rptr( & ' tcx Region , mt < ' tcx > ) ,
13441347
13451348 // If the def-id is Some(_), then this is the type of a specific
13461349 // fn item. Otherwise, if None(_), it a fn pointer type.
@@ -1350,7 +1353,7 @@ pub enum sty<'tcx> {
13501353 ty_trait( Box < TyTrait < ' tcx > > ) ,
13511354 ty_struct( DefId , & ' tcx Substs < ' tcx > ) ,
13521355
1353- ty_unboxed_closure( DefId , Region , & ' tcx Substs < ' tcx > ) ,
1356+ ty_unboxed_closure( DefId , & ' tcx Region , & ' tcx Substs < ' tcx > ) ,
13541357
13551358 ty_tup( Vec < Ty < ' tcx > > ) ,
13561359
@@ -2085,6 +2088,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
20852088 interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
20862089 substs_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
20872090 bare_fn_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
2091+ region_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
20882092 named_region_map : named_region_map,
20892093 item_variance_map : RefCell :: new ( DefIdMap :: new ( ) ) ,
20902094 variance_computed : Cell :: new ( false ) ,
@@ -2164,6 +2168,16 @@ impl<'tcx> ctxt<'tcx> {
21642168 self . bare_fn_interner . borrow_mut ( ) . insert ( bare_fn, bare_fn) ;
21652169 bare_fn
21662170 }
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+ }
21672181}
21682182
21692183// Interns a type/name combination, stores the resulting box in cx.interner,
@@ -2269,7 +2283,7 @@ impl FlagComputation {
22692283 }
22702284 }
22712285
2272- & ty_unboxed_closure( _, ref region, substs) => {
2286+ & ty_unboxed_closure( _, region, substs) => {
22732287 self . add_region ( * region) ;
22742288 self . add_substs ( substs) ;
22752289 }
@@ -2299,7 +2313,7 @@ impl FlagComputation {
22992313 }
23002314
23012315 & ty_rptr( r, ref m) => {
2302- self . add_region ( r) ;
2316+ self . add_region ( * r) ;
23032317 self . add_ty ( m. ty ) ;
23042318 }
23052319
@@ -2404,7 +2418,7 @@ pub fn mk_str<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> {
24042418 mk_t ( cx, ty_str)
24052419}
24062420
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 > {
24082422 mk_rptr ( cx, r,
24092423 mt {
24102424 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
24212435
24222436pub fn mk_ptr < ' tcx > ( cx : & ctxt < ' tcx > , tm : mt < ' tcx > ) -> Ty < ' tcx > { mk_t ( cx, ty_ptr ( tm) ) }
24232437
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 > {
24252439 mk_t ( cx, ty_rptr ( r, tm) )
24262440}
24272441
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 > {
24292443 mk_rptr ( cx, r, mt { ty : ty, mutbl : ast:: MutMutable } )
24302444}
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 > {
24322446 mk_rptr ( cx, r, mt { ty : ty, mutbl : ast:: MutImmutable } )
24332447}
24342448
@@ -2448,7 +2462,7 @@ pub fn mk_vec<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, sz: Option<uint>) -> Ty<'tcx>
24482462 mk_t ( cx, ty_vec ( ty, sz) )
24492463}
24502464
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 > {
24522466 mk_rptr ( cx, r,
24532467 mt {
24542468 ty : mk_vec ( cx, tm. ty , None ) ,
@@ -2512,7 +2526,7 @@ pub fn mk_struct<'tcx>(cx: &ctxt<'tcx>, struct_id: ast::DefId,
25122526}
25132527
25142528pub 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 > )
25162530 -> Ty < ' tcx > {
25172531 mk_t ( cx, ty_unboxed_closure ( closure_id, region, substs) )
25182532}
@@ -3087,9 +3101,10 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
30873101
30883102 ty_rptr( r, ref mt) => {
30893103 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 ) ) ,
30933108 }
30943109 }
30953110
@@ -3124,7 +3139,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
31243139 let upvars = unboxed_closure_upvars ( cx, did, substs) ;
31253140 TypeContents :: union ( upvars. as_slice ( ) ,
31263141 |f| tc_ty ( cx, f. ty , cache) )
3127- | borrowed_contents ( r, MutMutable )
3142+ | borrowed_contents ( * r, MutMutable )
31283143 }
31293144
31303145 ty_tup( ref tys) => {
@@ -3796,7 +3811,7 @@ pub fn deref<'tcx>(ty: Ty<'tcx>, explicit: bool) -> Option<mt<'tcx>> {
37963811
37973812pub fn close_type < ' tcx > ( cx : & ctxt < ' tcx > , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
37983813 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 } ) ,
38003815 _ => cx. sess . bug ( format ! ( "Trying to close a non-open type {}" ,
38013816 ty_to_string( cx, ty) ) [ ] )
38023817 }
@@ -4000,7 +4015,7 @@ pub fn ty_region(tcx: &ctxt,
40004015 span : Span ,
40014016 ty : Ty ) -> Region {
40024017 match ty. sty {
4003- ty_rptr( r, _) => r,
4018+ ty_rptr( r, _) => * r,
40044019 ref s => {
40054020 tcx. sess . span_bug (
40064021 span,
@@ -4206,7 +4221,7 @@ pub fn adjust_ty_for_autoref<'tcx>(cx: &ctxt<'tcx>,
42064221 & Some ( box ref a) => adjust_ty_for_autoref ( cx, span, ty, Some ( a) ) ,
42074222 & None => ty
42084223 } ;
4209- mk_rptr ( cx, r , mt {
4224+ mk_rptr ( cx, cx . mk_region ( r ) , mt {
42104225 ty : adjusted_ty,
42114226 mutbl : m
42124227 } )
@@ -5494,7 +5509,7 @@ pub fn unboxed_closure_upvars<'tcx>(tcx: &ctxt<'tcx>, closure_id: ast::DefId, su
54945509 var_id : freevar_def_id. node ,
54955510 closure_expr_id : closure_id. node
54965511 } ] . clone ( ) ;
5497- freevar_ty = mk_rptr ( tcx, borrow. region , ty:: mt {
5512+ freevar_ty = mk_rptr ( tcx, tcx . mk_region ( borrow. region ) , ty:: mt {
54985513 ty : freevar_ty,
54995514 mutbl : borrow. kind . to_mutbl_lossy ( )
55005515 } ) ;
@@ -6348,7 +6363,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
63486363 walk_ty ( ty, |ty| {
63496364 match ty. sty {
63506365 ty_rptr( region, _) => {
6351- accumulator. push ( region)
6366+ accumulator. push ( * region)
63526367 }
63536368 ty_trait( ref t) => {
63546369 accumulator. push_all ( t. principal . substs ( ) . regions ( ) . as_slice ( ) ) ;
@@ -6363,7 +6378,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
63636378 UniqTraitStore => { }
63646379 }
63656380 }
6366- ty_unboxed_closure( _, ref region, substs) => {
6381+ ty_unboxed_closure( _, region, substs) => {
63676382 accumulator. push ( * region) ;
63686383 accum_substs ( accumulator, substs) ;
63696384 }
0 commit comments