Skip to content

Commit 0e43b37

Browse files
Split CtxtArenas into GlobalArenas and CtxtInterners.
CtxtInterners contains a single DroplessArena, while GlobalArenas contains the TypedArenas still required for the remaining Drop-containing types.
1 parent bb1959f commit 0e43b37

File tree

8 files changed

+87
-74
lines changed

8 files changed

+87
-74
lines changed

src/librustc/infer/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use syntax::ast;
4141
use errors::DiagnosticBuilder;
4242
use syntax_pos::{self, Span, DUMMY_SP};
4343
use util::nodemap::{FxHashMap, FxHashSet, NodeMap};
44+
use arena::DroplessArena;
4445

4546
use self::combine::CombineFields;
4647
use self::higher_ranked::HrMatchResult;
@@ -374,7 +375,7 @@ impl fmt::Display for FixupError {
374375
/// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(InferCtxt<'b, 'gcx, 'tcx>).
375376
pub struct InferCtxtBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
376377
global_tcx: TyCtxt<'a, 'gcx, 'gcx>,
377-
arenas: ty::CtxtArenas<'tcx>,
378+
arena: DroplessArena,
378379
tables: Option<RefCell<ty::Tables<'tcx>>>,
379380
param_env: Option<ty::ParameterEnvironment<'gcx>>,
380381
projection_mode: Reveal,
@@ -388,7 +389,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
388389
-> InferCtxtBuilder<'a, 'gcx, 'tcx> {
389390
InferCtxtBuilder {
390391
global_tcx: self,
391-
arenas: ty::CtxtArenas::new(),
392+
arena: DroplessArena::new(),
392393
tables: tables.map(RefCell::new),
393394
param_env: param_env,
394395
projection_mode: projection_mode,
@@ -426,7 +427,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
426427
{
427428
let InferCtxtBuilder {
428429
global_tcx,
429-
ref arenas,
430+
ref arena,
430431
ref tables,
431432
ref mut param_env,
432433
projection_mode,
@@ -439,7 +440,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
439440
let param_env = param_env.take().unwrap_or_else(|| {
440441
global_tcx.empty_parameter_environment()
441442
});
442-
global_tcx.enter_local(arenas, |tcx| f(InferCtxt {
443+
global_tcx.enter_local(arena, |tcx| f(InferCtxt {
443444
tcx: tcx,
444445
tables: tables,
445446
projection_cache: RefCell::new(traits::ProjectionCache::new()),

src/librustc/ty/context.rs

+41-56
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
3939
use util::nodemap::{FxHashMap, FxHashSet};
4040
use rustc_data_structures::accumulate_vec::AccumulateVec;
4141

42-
use arena::TypedArena;
42+
use arena::{TypedArena, DroplessArena};
4343
use std::borrow::Borrow;
4444
use std::cell::{Cell, RefCell};
4545
use std::hash::{Hash, Hasher};
@@ -55,16 +55,9 @@ use syntax::symbol::{Symbol, keywords};
5555
use hir;
5656

5757
/// Internal storage
58-
pub struct CtxtArenas<'tcx> {
58+
pub struct GlobalArenas<'tcx> {
5959
// 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>,
6660
layout: TypedArena<Layout>,
67-
existential_predicates: TypedArena<ExistentialPredicate<'tcx>>,
6861

6962
// references
7063
generics: TypedArena<ty::Generics<'tcx>>,
@@ -73,29 +66,21 @@ pub struct CtxtArenas<'tcx> {
7366
mir: TypedArena<RefCell<Mir<'tcx>>>,
7467
}
7568

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 {
8572
layout: TypedArena::new(),
86-
existential_predicates: TypedArena::new(),
87-
8873
generics: TypedArena::new(),
8974
trait_def: TypedArena::new(),
9075
adt_def: TypedArena::new(),
91-
mir: TypedArena::new()
76+
mir: TypedArena::new(),
9277
}
9378
}
9479
}
9580

9681
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,
9984

10085
/// Specifically use a speedy hash algorithm for these hash sets,
10186
/// they're accessed quite often.
@@ -104,22 +89,18 @@ pub struct CtxtInterners<'tcx> {
10489
substs: RefCell<FxHashSet<Interned<'tcx, Substs<'tcx>>>>,
10590
bare_fn: RefCell<FxHashSet<Interned<'tcx, BareFnTy<'tcx>>>>,
10691
region: RefCell<FxHashSet<Interned<'tcx, Region>>>,
107-
stability: RefCell<FxHashSet<&'tcx attr::Stability>>,
108-
layout: RefCell<FxHashSet<&'tcx Layout>>,
10992
existential_predicates: RefCell<FxHashSet<Interned<'tcx, Slice<ExistentialPredicate<'tcx>>>>>,
11093
}
11194

11295
impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
113-
fn new(arenas: &'tcx CtxtArenas<'tcx>) -> CtxtInterners<'tcx> {
96+
fn new(arena: &'tcx DroplessArena) -> CtxtInterners<'tcx> {
11497
CtxtInterners {
115-
arenas: arenas,
98+
arena: arena,
11699
type_: RefCell::new(FxHashSet()),
117100
type_list: RefCell::new(FxHashSet()),
118101
substs: RefCell::new(FxHashSet()),
119102
bare_fn: RefCell::new(FxHashSet()),
120103
region: RefCell::new(FxHashSet()),
121-
stability: RefCell::new(FxHashSet()),
122-
layout: RefCell::new(FxHashSet()),
123104
existential_predicates: RefCell::new(FxHashSet()),
124105
}
125106
}
@@ -158,7 +139,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
158139
let ty_struct: TyS<'gcx> = unsafe {
159140
mem::transmute(ty_struct)
160141
};
161-
let ty: Ty<'gcx> = interner.arenas.type_.alloc(ty_struct);
142+
let ty: Ty<'gcx> = interner.arena.alloc(ty_struct);
162143
global_interner.unwrap().insert(Interned(ty));
163144
return ty;
164145
}
@@ -174,7 +155,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
174155
}
175156

176157
// 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);
178159
interner.insert(Interned(ty));
179160
ty
180161
};
@@ -387,6 +368,7 @@ impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
387368
}
388369

389370
pub struct GlobalCtxt<'tcx> {
371+
global_arenas: &'tcx GlobalArenas<'tcx>,
390372
global_interners: CtxtInterners<'tcx>,
391373

392374
pub specializes_cache: RefCell<traits::SpecializesCache>,
@@ -582,6 +564,10 @@ pub struct GlobalCtxt<'tcx> {
582564
/// Map from function to the `#[derive]` mode that it's defining. Only used
583565
/// by `proc-macro` crates.
584566
pub derive_macros: RefCell<NodeMap<Symbol>>,
567+
568+
stability_interner: RefCell<FxHashSet<&'tcx attr::Stability>>,
569+
570+
layout_interner: RefCell<FxHashSet<&'tcx Layout>>,
585571
}
586572

587573
impl<'tcx> GlobalCtxt<'tcx> {
@@ -645,15 +631,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
645631

646632
pub fn alloc_generics(self, generics: ty::Generics<'gcx>)
647633
-> &'gcx ty::Generics<'gcx> {
648-
self.global_interners.arenas.generics.alloc(generics)
634+
self.global_arenas.generics.alloc(generics)
649635
}
650636

651637
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))
653639
}
654640

655641
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)
657643
}
658644

659645
pub fn alloc_adt_def(self,
@@ -662,32 +648,28 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
662648
variants: Vec<ty::VariantDef>)
663649
-> &'gcx ty::AdtDef {
664650
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)
666652
}
667653

668654
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) {
670656
return st;
671657
}
672658

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) {
677661
bug!("Tried to overwrite interned Stability: {:?}", prev)
678662
}
679663
interned
680664
}
681665

682666
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) {
684668
return layout;
685669
}
686670

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) {
691673
bug!("Tried to overwrite interned Layout: {:?}", prev)
692674
}
693675
interned
@@ -724,24 +706,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
724706
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
725707
/// reference to the context, to allow formatting values that need it.
726708
pub fn create_and_enter<F, R>(s: &'tcx Session,
727-
arenas: &'tcx CtxtArenas<'tcx>,
709+
arenas: &'tcx GlobalArenas<'tcx>,
710+
arena: &'tcx DroplessArena,
728711
resolutions: ty::Resolutions,
729712
named_region_map: resolve_lifetime::NamedRegionMap,
730713
map: ast_map::Map<'tcx>,
731714
region_maps: RegionMaps,
732715
lang_items: middle::lang_items::LanguageItems,
733716
stability: stability::Index<'tcx>,
734-
crate_name: &str,
717+
crate_name: &str,
735718
f: F) -> R
736719
where F: for<'b> FnOnce(TyCtxt<'b, 'tcx, 'tcx>) -> R
737720
{
738721
let data_layout = TargetDataLayout::parse(s);
739-
let interners = CtxtInterners::new(arenas);
722+
let interners = CtxtInterners::new(arena);
740723
let common_types = CommonTypes::new(&interners);
741724
let dep_graph = map.dep_graph.clone();
742725
let fulfilled_predicates = traits::GlobalFulfilledPredicates::new(dep_graph.clone());
743726
tls::enter_global(GlobalCtxt {
744727
specializes_cache: RefCell::new(traits::SpecializesCache::new()),
728+
global_arenas: arenas,
745729
global_interners: interners,
746730
dep_graph: dep_graph.clone(),
747731
types: common_types,
@@ -790,18 +774,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
790774
crate_name: Symbol::intern(crate_name),
791775
data_layout: data_layout,
792776
layout_cache: RefCell::new(FxHashMap()),
777+
layout_interner: RefCell::new(FxHashSet()),
793778
layout_depth: Cell::new(0),
794779
derive_macros: RefCell::new(NodeMap()),
780+
stability_interner: RefCell::new(FxHashSet()),
795781
}, f)
796782
}
797783
}
798784

799785
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
802788
where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
803789
{
804-
let interners = CtxtInterners::new(arenas);
790+
let interners = CtxtInterners::new(arena);
805791
tls::enter(self, &interners, f)
806792
}
807793
}
@@ -1097,8 +1083,8 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
10971083
println!("Substs interner: #{}", self.interners.substs.borrow().len());
10981084
println!("BareFnTy interner: #{}", self.interners.bare_fn.borrow().len());
10991085
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());
11021088
}
11031089
}
11041090

@@ -1201,8 +1187,7 @@ macro_rules! intern_method {
12011187
let v = unsafe {
12021188
mem::transmute(v)
12031189
};
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));
12061191
self.global_interners.$name.borrow_mut().insert(Interned(i));
12071192
return i;
12081193
}
@@ -1216,7 +1201,7 @@ macro_rules! intern_method {
12161201
}
12171202
}
12181203

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));
12201205
self.interners.$name.borrow_mut().insert(Interned(i));
12211206
i
12221207
}

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub use self::sty::Region::*;
6868
pub use self::sty::TypeVariants::*;
6969

7070
pub use self::contents::TypeContents;
71-
pub use self::context::{TyCtxt, tls};
72-
pub use self::context::{CtxtArenas, Lift, Tables};
71+
pub use self::context::{TyCtxt, GlobalArenas, tls};
72+
pub use self::context::{Lift, Tables};
7373

7474
pub use self::trait_def::{TraitDef, TraitFlags};
7575

0 commit comments

Comments
 (0)