@@ -39,7 +39,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
39
39
use util:: nodemap:: { FxHashMap , FxHashSet } ;
40
40
use rustc_data_structures:: accumulate_vec:: AccumulateVec ;
41
41
42
- use arena:: TypedArena ;
42
+ use arena:: { TypedArena , DroplessArena } ;
43
43
use std:: borrow:: Borrow ;
44
44
use std:: cell:: { Cell , RefCell } ;
45
45
use std:: hash:: { Hash , Hasher } ;
@@ -55,16 +55,9 @@ use syntax::symbol::{Symbol, keywords};
55
55
use hir;
56
56
57
57
/// Internal storage
58
- pub struct CtxtArenas < ' tcx > {
58
+ pub struct GlobalArenas < ' tcx > {
59
59
// internings
60
- type_ : TypedArena < TyS < ' tcx > > ,
61
- type_list : TypedArena < Ty < ' tcx > > ,
62
- substs : TypedArena < Kind < ' tcx > > ,
63
- bare_fn : TypedArena < BareFnTy < ' tcx > > ,
64
- region : TypedArena < Region > ,
65
- stability : TypedArena < attr:: Stability > ,
66
60
layout : TypedArena < Layout > ,
67
- existential_predicates : TypedArena < ExistentialPredicate < ' tcx > > ,
68
61
69
62
// references
70
63
generics : TypedArena < ty:: Generics < ' tcx > > ,
@@ -73,29 +66,21 @@ pub struct CtxtArenas<'tcx> {
73
66
mir : TypedArena < RefCell < Mir < ' tcx > > > ,
74
67
}
75
68
76
- impl < ' tcx > CtxtArenas < ' tcx > {
77
- pub fn new ( ) -> CtxtArenas < ' tcx > {
78
- CtxtArenas {
79
- type_ : TypedArena :: new ( ) ,
80
- type_list : TypedArena :: new ( ) ,
81
- substs : TypedArena :: new ( ) ,
82
- bare_fn : TypedArena :: new ( ) ,
83
- region : TypedArena :: new ( ) ,
84
- stability : TypedArena :: new ( ) ,
69
+ impl < ' tcx > GlobalArenas < ' tcx > {
70
+ pub fn new ( ) -> GlobalArenas < ' tcx > {
71
+ GlobalArenas {
85
72
layout : TypedArena :: new ( ) ,
86
- existential_predicates : TypedArena :: new ( ) ,
87
-
88
73
generics : TypedArena :: new ( ) ,
89
74
trait_def : TypedArena :: new ( ) ,
90
75
adt_def : TypedArena :: new ( ) ,
91
- mir : TypedArena :: new ( )
76
+ mir : TypedArena :: new ( ) ,
92
77
}
93
78
}
94
79
}
95
80
96
81
pub struct CtxtInterners < ' tcx > {
97
- /// The arenas that types etc are allocated from.
98
- arenas : & ' tcx CtxtArenas < ' tcx > ,
82
+ /// The arena that types, regions, etc are allocated from
83
+ arena : & ' tcx DroplessArena ,
99
84
100
85
/// Specifically use a speedy hash algorithm for these hash sets,
101
86
/// they're accessed quite often.
@@ -104,22 +89,18 @@ pub struct CtxtInterners<'tcx> {
104
89
substs : RefCell < FxHashSet < Interned < ' tcx , Substs < ' tcx > > > > ,
105
90
bare_fn : RefCell < FxHashSet < Interned < ' tcx , BareFnTy < ' tcx > > > > ,
106
91
region : RefCell < FxHashSet < Interned < ' tcx , Region > > > ,
107
- stability : RefCell < FxHashSet < & ' tcx attr:: Stability > > ,
108
- layout : RefCell < FxHashSet < & ' tcx Layout > > ,
109
92
existential_predicates : RefCell < FxHashSet < Interned < ' tcx , Slice < ExistentialPredicate < ' tcx > > > > > ,
110
93
}
111
94
112
95
impl < ' gcx : ' tcx , ' tcx > CtxtInterners < ' tcx > {
113
- fn new ( arenas : & ' tcx CtxtArenas < ' tcx > ) -> CtxtInterners < ' tcx > {
96
+ fn new ( arena : & ' tcx DroplessArena ) -> CtxtInterners < ' tcx > {
114
97
CtxtInterners {
115
- arenas : arenas ,
98
+ arena : arena ,
116
99
type_ : RefCell :: new ( FxHashSet ( ) ) ,
117
100
type_list : RefCell :: new ( FxHashSet ( ) ) ,
118
101
substs : RefCell :: new ( FxHashSet ( ) ) ,
119
102
bare_fn : RefCell :: new ( FxHashSet ( ) ) ,
120
103
region : RefCell :: new ( FxHashSet ( ) ) ,
121
- stability : RefCell :: new ( FxHashSet ( ) ) ,
122
- layout : RefCell :: new ( FxHashSet ( ) ) ,
123
104
existential_predicates : RefCell :: new ( FxHashSet ( ) ) ,
124
105
}
125
106
}
@@ -158,7 +139,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
158
139
let ty_struct: TyS < ' gcx > = unsafe {
159
140
mem:: transmute ( ty_struct)
160
141
} ;
161
- let ty: Ty < ' gcx > = interner. arenas . type_ . alloc ( ty_struct) ;
142
+ let ty: Ty < ' gcx > = interner. arena . alloc ( ty_struct) ;
162
143
global_interner. unwrap ( ) . insert ( Interned ( ty) ) ;
163
144
return ty;
164
145
}
@@ -174,7 +155,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
174
155
}
175
156
176
157
// Don't be &mut TyS.
177
- let ty: Ty < ' tcx > = self . arenas . type_ . alloc ( ty_struct) ;
158
+ let ty: Ty < ' tcx > = self . arena . alloc ( ty_struct) ;
178
159
interner. insert ( Interned ( ty) ) ;
179
160
ty
180
161
} ;
@@ -387,6 +368,7 @@ impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
387
368
}
388
369
389
370
pub struct GlobalCtxt < ' tcx > {
371
+ global_arenas : & ' tcx GlobalArenas < ' tcx > ,
390
372
global_interners : CtxtInterners < ' tcx > ,
391
373
392
374
pub specializes_cache : RefCell < traits:: SpecializesCache > ,
@@ -582,6 +564,10 @@ pub struct GlobalCtxt<'tcx> {
582
564
/// Map from function to the `#[derive]` mode that it's defining. Only used
583
565
/// by `proc-macro` crates.
584
566
pub derive_macros : RefCell < NodeMap < Symbol > > ,
567
+
568
+ stability_interner : RefCell < FxHashSet < & ' tcx attr:: Stability > > ,
569
+
570
+ layout_interner : RefCell < FxHashSet < & ' tcx Layout > > ,
585
571
}
586
572
587
573
impl < ' tcx > GlobalCtxt < ' tcx > {
@@ -645,15 +631,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
645
631
646
632
pub fn alloc_generics ( self , generics : ty:: Generics < ' gcx > )
647
633
-> & ' gcx ty:: Generics < ' gcx > {
648
- self . global_interners . arenas . generics . alloc ( generics)
634
+ self . global_arenas . generics . alloc ( generics)
649
635
}
650
636
651
637
pub fn alloc_mir ( self , mir : Mir < ' gcx > ) -> & ' gcx RefCell < Mir < ' gcx > > {
652
- self . global_interners . arenas . mir . alloc ( RefCell :: new ( mir) )
638
+ self . global_arenas . mir . alloc ( RefCell :: new ( mir) )
653
639
}
654
640
655
641
pub fn alloc_trait_def ( self , def : ty:: TraitDef ) -> & ' gcx ty:: TraitDef {
656
- self . global_interners . arenas . trait_def . alloc ( def)
642
+ self . global_arenas . trait_def . alloc ( def)
657
643
}
658
644
659
645
pub fn alloc_adt_def ( self ,
@@ -662,32 +648,28 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
662
648
variants : Vec < ty:: VariantDef > )
663
649
-> & ' gcx ty:: AdtDef {
664
650
let def = ty:: AdtDef :: new ( self , did, kind, variants) ;
665
- self . global_interners . arenas . adt_def . alloc ( def)
651
+ self . global_arenas . adt_def . alloc ( def)
666
652
}
667
653
668
654
pub fn intern_stability ( self , stab : attr:: Stability ) -> & ' gcx attr:: Stability {
669
- if let Some ( st) = self . global_interners . stability . borrow ( ) . get ( & stab) {
655
+ if let Some ( st) = self . stability_interner . borrow ( ) . get ( & stab) {
670
656
return st;
671
657
}
672
658
673
- let interned = self . global_interners . arenas . stability . alloc ( stab) ;
674
- if let Some ( prev) = self . global_interners . stability
675
- . borrow_mut ( )
676
- . replace ( interned) {
659
+ let interned = self . global_interners . arena . alloc ( stab) ;
660
+ if let Some ( prev) = self . stability_interner . borrow_mut ( ) . replace ( interned) {
677
661
bug ! ( "Tried to overwrite interned Stability: {:?}" , prev)
678
662
}
679
663
interned
680
664
}
681
665
682
666
pub fn intern_layout ( self , layout : Layout ) -> & ' gcx Layout {
683
- if let Some ( layout) = self . global_interners . layout . borrow ( ) . get ( & layout) {
667
+ if let Some ( layout) = self . layout_interner . borrow ( ) . get ( & layout) {
684
668
return layout;
685
669
}
686
670
687
- let interned = self . global_interners . arenas . layout . alloc ( layout) ;
688
- if let Some ( prev) = self . global_interners . layout
689
- . borrow_mut ( )
690
- . replace ( interned) {
671
+ let interned = self . global_arenas . layout . alloc ( layout) ;
672
+ if let Some ( prev) = self . layout_interner . borrow_mut ( ) . replace ( interned) {
691
673
bug ! ( "Tried to overwrite interned Layout: {:?}" , prev)
692
674
}
693
675
interned
@@ -724,24 +706,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
724
706
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
725
707
/// reference to the context, to allow formatting values that need it.
726
708
pub fn create_and_enter < F , R > ( s : & ' tcx Session ,
727
- arenas : & ' tcx CtxtArenas < ' tcx > ,
709
+ arenas : & ' tcx GlobalArenas < ' tcx > ,
710
+ arena : & ' tcx DroplessArena ,
728
711
resolutions : ty:: Resolutions ,
729
712
named_region_map : resolve_lifetime:: NamedRegionMap ,
730
713
map : ast_map:: Map < ' tcx > ,
731
714
region_maps : RegionMaps ,
732
715
lang_items : middle:: lang_items:: LanguageItems ,
733
716
stability : stability:: Index < ' tcx > ,
734
- crate_name : & str ,
717
+ crate_name : & str ,
735
718
f : F ) -> R
736
719
where F : for < ' b > FnOnce ( TyCtxt < ' b , ' tcx , ' tcx > ) -> R
737
720
{
738
721
let data_layout = TargetDataLayout :: parse ( s) ;
739
- let interners = CtxtInterners :: new ( arenas ) ;
722
+ let interners = CtxtInterners :: new ( arena ) ;
740
723
let common_types = CommonTypes :: new ( & interners) ;
741
724
let dep_graph = map. dep_graph . clone ( ) ;
742
725
let fulfilled_predicates = traits:: GlobalFulfilledPredicates :: new ( dep_graph. clone ( ) ) ;
743
726
tls:: enter_global ( GlobalCtxt {
744
727
specializes_cache : RefCell :: new ( traits:: SpecializesCache :: new ( ) ) ,
728
+ global_arenas : arenas,
745
729
global_interners : interners,
746
730
dep_graph : dep_graph. clone ( ) ,
747
731
types : common_types,
@@ -790,18 +774,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
790
774
crate_name : Symbol :: intern ( crate_name) ,
791
775
data_layout : data_layout,
792
776
layout_cache : RefCell :: new ( FxHashMap ( ) ) ,
777
+ layout_interner : RefCell :: new ( FxHashSet ( ) ) ,
793
778
layout_depth : Cell :: new ( 0 ) ,
794
779
derive_macros : RefCell :: new ( NodeMap ( ) ) ,
780
+ stability_interner : RefCell :: new ( FxHashSet ( ) ) ,
795
781
} , f)
796
782
}
797
783
}
798
784
799
785
impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
800
- /// Call the closure with a local `TyCtxt` using the given arenas .
801
- pub fn enter_local < F , R > ( & self , arenas : & ' tcx CtxtArenas < ' tcx > , f : F ) -> R
786
+ /// Call the closure with a local `TyCtxt` using the given arena .
787
+ pub fn enter_local < F , R > ( & self , arena : & ' tcx DroplessArena , f : F ) -> R
802
788
where F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
803
789
{
804
- let interners = CtxtInterners :: new ( arenas ) ;
790
+ let interners = CtxtInterners :: new ( arena ) ;
805
791
tls:: enter ( self , & interners, f)
806
792
}
807
793
}
@@ -1097,8 +1083,8 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
1097
1083
println ! ( "Substs interner: #{}" , self . interners. substs. borrow( ) . len( ) ) ;
1098
1084
println ! ( "BareFnTy interner: #{}" , self . interners. bare_fn. borrow( ) . len( ) ) ;
1099
1085
println ! ( "Region interner: #{}" , self . interners. region. borrow( ) . len( ) ) ;
1100
- println ! ( "Stability interner: #{}" , self . interners . stability . borrow( ) . len( ) ) ;
1101
- println ! ( "Layout interner: #{}" , self . interners . layout . borrow( ) . len( ) ) ;
1086
+ println ! ( "Stability interner: #{}" , self . stability_interner . borrow( ) . len( ) ) ;
1087
+ println ! ( "Layout interner: #{}" , self . layout_interner . borrow( ) . len( ) ) ;
1102
1088
}
1103
1089
}
1104
1090
@@ -1201,8 +1187,7 @@ macro_rules! intern_method {
1201
1187
let v = unsafe {
1202
1188
mem:: transmute( v)
1203
1189
} ;
1204
- let i = ( $alloc_to_ret) ( self . global_interners. arenas. $name
1205
- . $alloc_method( v) ) ;
1190
+ let i = ( $alloc_to_ret) ( self . global_interners. arena. $alloc_method( v) ) ;
1206
1191
self . global_interners. $name. borrow_mut( ) . insert( Interned ( i) ) ;
1207
1192
return i;
1208
1193
}
@@ -1216,7 +1201,7 @@ macro_rules! intern_method {
1216
1201
}
1217
1202
}
1218
1203
1219
- let i = ( $alloc_to_ret) ( self . interners . arenas . $name . $alloc_method( v) ) ;
1204
+ let i = ( $alloc_to_ret) ( self . global_interners . arena . $alloc_method( v) ) ;
1220
1205
self . interners. $name. borrow_mut( ) . insert( Interned ( i) ) ;
1221
1206
i
1222
1207
}
0 commit comments