Skip to content

Commit d473c26

Browse files
committed
Have thread-local GlobalArenas
1 parent 296695b commit d473c26

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/librustc/ty/context.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,19 @@ use syntax::attr;
7373
use syntax::codemap::MultiSpan;
7474
use syntax::symbol::{Symbol, keywords};
7575
use syntax_pos::Span;
76+
use util::common::ThreadLocal;
7677

7778
use hir;
7879

7980
pub struct AllArenas<'tcx> {
80-
pub global: GlobalArenas<'tcx>,
81+
pub global: ThreadLocal<GlobalArenas<'tcx>>,
8182
pub interner: DroplessArena,
8283
}
8384

8485
impl<'tcx> AllArenas<'tcx> {
8586
pub fn new() -> Self {
8687
AllArenas {
87-
global: GlobalArenas::new(),
88+
global: ThreadLocal::new(|| GlobalArenas::new()),
8889
interner: DroplessArena::new(),
8990
}
9091
}
@@ -796,7 +797,7 @@ impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
796797
}
797798

798799
pub struct GlobalCtxt<'tcx> {
799-
global_arenas: &'tcx GlobalArenas<'tcx>,
800+
global_arenas: &'tcx ThreadLocal<GlobalArenas<'tcx>>,
800801
global_interners: CtxtInterners<'tcx>,
801802

802803
cstore: &'tcx (CrateStore + Sync),
@@ -992,23 +993,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
992993
}
993994

994995
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
995-
self.global_arenas.generics.alloc(generics)
996+
self.global_arenas.current().generics.alloc(generics)
996997
}
997998

998999
pub fn alloc_steal_mir(self, mir: Mir<'gcx>) -> &'gcx Steal<Mir<'gcx>> {
999-
self.global_arenas.steal_mir.alloc(Steal::new(mir))
1000+
self.global_arenas.current().steal_mir.alloc(Steal::new(mir))
10001001
}
10011002

10021003
pub fn alloc_mir(self, mir: Mir<'gcx>) -> &'gcx Mir<'gcx> {
1003-
self.global_arenas.mir.alloc(mir)
1004+
self.global_arenas.current().mir.alloc(mir)
10041005
}
10051006

10061007
pub fn alloc_tables(self, tables: ty::TypeckTables<'gcx>) -> &'gcx ty::TypeckTables<'gcx> {
1007-
self.global_arenas.tables.alloc(tables)
1008+
self.global_arenas.current().tables.alloc(tables)
10081009
}
10091010

10101011
pub fn alloc_trait_def(self, def: ty::TraitDef) -> &'gcx ty::TraitDef {
1011-
self.global_arenas.trait_def.alloc(def)
1012+
self.global_arenas.current().trait_def.alloc(def)
10121013
}
10131014

10141015
pub fn alloc_adt_def(self,
@@ -1018,7 +1019,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10181019
repr: ReprOptions)
10191020
-> &'gcx ty::AdtDef {
10201021
let def = ty::AdtDef::new(self, did, kind, variants, repr);
1021-
self.global_arenas.adt_def.alloc(def)
1022+
self.global_arenas.current().adt_def.alloc(def)
10221023
}
10231024

10241025
pub fn alloc_byte_array(self, bytes: &[u8]) -> &'gcx [u8] {
@@ -1055,7 +1056,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10551056
return alloc;
10561057
}
10571058

1058-
let interned = self.global_arenas.const_allocs.alloc(alloc);
1059+
let interned = self.global_arenas.current().const_allocs.alloc(alloc);
10591060
if let Some(prev) = self.interpret_interner.borrow_mut().allocs.replace(interned) {
10601061
bug!("Tried to overwrite interned Allocation: {:#?}", prev)
10611062
}
@@ -1101,7 +1102,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11011102
return layout;
11021103
}
11031104

1104-
let interned = self.global_arenas.layout.alloc(layout);
1105+
let interned = self.global_arenas.current().layout.alloc(layout);
11051106
if let Some(prev) = layout_interner.replace(interned) {
11061107
bug!("Tried to overwrite interned Layout: {:?}", prev)
11071108
}

0 commit comments

Comments
 (0)