Skip to content

Commit 6d38746

Browse files
committed
Remove GlobalArenas and use Arena instead
1 parent 3ade426 commit 6d38746

File tree

10 files changed

+33
-61
lines changed

10 files changed

+33
-61
lines changed

src/librustc/arena.rs

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ use smallvec::SmallVec;
1919
macro_rules! arena_types {
2020
($macro:path, $args:tt, $tcx:lifetime) => (
2121
$macro!($args, [
22+
[] layouts: rustc::ty::layout::LayoutDetails,
23+
[] generics: rustc::ty::Generics,
24+
[] trait_def: rustc::ty::TraitDef,
25+
[] adt_def: rustc::ty::AdtDef,
26+
[] steal_mir: rustc::ty::steal::Steal<rustc::mir::Body<$tcx>>,
27+
[] mir: rustc::mir::Body<$tcx>,
28+
[] tables: rustc::ty::TypeckTables<$tcx>,
29+
[] const_allocs: rustc::mir::interpret::Allocation,
2230
[] vtable_method: Option<(
2331
rustc::hir::def_id::DefId,
2432
rustc::ty::subst::SubstsRef<$tcx>

src/librustc/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ rustc_queries! {
4242
load_cached(tcx, id) {
4343
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
4444
.try_load_query_result(tcx, id);
45-
generics.map(|x| tcx.alloc_generics(x))
45+
generics.map(|x| &*tcx.arena.alloc(x))
4646
}
4747
}
4848

@@ -118,7 +118,7 @@ rustc_queries! {
118118
load_cached(tcx, id) {
119119
let mir: Option<crate::mir::Body<'tcx>> = tcx.queries.on_disk_cache
120120
.try_load_query_result(tcx, id);
121-
mir.map(|x| tcx.alloc_mir(x))
121+
mir.map(|x| &*tcx.arena.alloc(x))
122122
}
123123
}
124124
}
@@ -353,7 +353,7 @@ rustc_queries! {
353353
.queries.on_disk_cache
354354
.try_load_query_result(tcx, id);
355355

356-
typeck_tables.map(|tables| tcx.alloc_tables(tables))
356+
typeck_tables.map(|tables| &*tcx.arena.alloc(tables))
357357
}
358358
}
359359
}

src/librustc/ty/context.rs

+10-46
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use smallvec::SmallVec;
5353
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5454
StableHasher, StableHasherResult,
5555
StableVec};
56-
use arena::{TypedArena, SyncDroplessArena};
56+
use arena::SyncDroplessArena;
5757
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
5858
use rustc_data_structures::sync::{Lrc, Lock, WorkerLocal};
5959
use std::any::Any;
@@ -79,37 +79,18 @@ use syntax_pos::Span;
7979

8080
use crate::hir;
8181

82-
pub struct AllArenas<'tcx> {
83-
pub global: WorkerLocal<GlobalArenas<'tcx>>,
82+
pub struct AllArenas {
8483
pub interner: SyncDroplessArena,
8584
}
8685

87-
impl<'tcx> AllArenas<'tcx> {
86+
impl AllArenas {
8887
pub fn new() -> Self {
8988
AllArenas {
90-
global: WorkerLocal::new(|_| GlobalArenas::default()),
9189
interner: SyncDroplessArena::default(),
9290
}
9391
}
9492
}
9593

96-
/// Internal storage
97-
#[derive(Default)]
98-
pub struct GlobalArenas<'tcx> {
99-
// internings
100-
layout: TypedArena<LayoutDetails>,
101-
102-
// references
103-
generics: TypedArena<ty::Generics>,
104-
trait_def: TypedArena<ty::TraitDef>,
105-
adt_def: TypedArena<ty::AdtDef>,
106-
steal_mir: TypedArena<Steal<Body<'tcx>>>,
107-
mir: TypedArena<Body<'tcx>>,
108-
tables: TypedArena<ty::TypeckTables<'tcx>>,
109-
/// miri allocations
110-
const_allocs: TypedArena<interpret::Allocation>,
111-
}
112-
11394
type InternedSet<'tcx, T> = Lock<FxHashMap<Interned<'tcx, T>, ()>>;
11495

11596
pub struct CtxtInterners<'tcx> {
@@ -1043,7 +1024,7 @@ impl<'gcx> Deref for TyCtxt<'_, 'gcx, '_> {
10431024

10441025
pub struct GlobalCtxt<'tcx> {
10451026
pub arena: WorkerLocal<Arena<'tcx>>,
1046-
global_arenas: &'tcx WorkerLocal<GlobalArenas<'tcx>>,
1027+
10471028
global_interners: CtxtInterners<'tcx>,
10481029

10491030
cstore: &'tcx CrateStoreDyn,
@@ -1150,24 +1131,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11501131
&self.hir_map
11511132
}
11521133

1153-
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
1154-
self.global_arenas.generics.alloc(generics)
1155-
}
1156-
11571134
pub fn alloc_steal_mir(self, mir: Body<'gcx>) -> &'gcx Steal<Body<'gcx>> {
1158-
self.global_arenas.steal_mir.alloc(Steal::new(mir))
1159-
}
1160-
1161-
pub fn alloc_mir(self, mir: Body<'gcx>) -> &'gcx Body<'gcx> {
1162-
self.global_arenas.mir.alloc(mir)
1163-
}
1164-
1165-
pub fn alloc_tables(self, tables: ty::TypeckTables<'gcx>) -> &'gcx ty::TypeckTables<'gcx> {
1166-
self.global_arenas.tables.alloc(tables)
1167-
}
1168-
1169-
pub fn alloc_trait_def(self, def: ty::TraitDef) -> &'gcx ty::TraitDef {
1170-
self.global_arenas.trait_def.alloc(def)
1135+
self.arena.alloc(Steal::new(mir))
11711136
}
11721137

11731138
pub fn alloc_adt_def(self,
@@ -1177,12 +1142,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11771142
repr: ReprOptions)
11781143
-> &'gcx ty::AdtDef {
11791144
let def = ty::AdtDef::new(self, did, kind, variants, repr);
1180-
self.global_arenas.adt_def.alloc(def)
1145+
self.arena.alloc(def)
11811146
}
11821147

11831148
pub fn intern_const_alloc(self, alloc: Allocation) -> &'gcx Allocation {
11841149
self.allocation_interner.borrow_mut().intern(alloc, |alloc| {
1185-
self.global_arenas.const_allocs.alloc(alloc)
1150+
self.arena.alloc(alloc)
11861151
})
11871152
}
11881153

@@ -1196,13 +1161,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11961161

11971162
pub fn intern_stability(self, stab: attr::Stability) -> &'gcx attr::Stability {
11981163
self.stability_interner.borrow_mut().intern(stab, |stab| {
1199-
self.global_interners.arena.alloc(stab)
1164+
self.arena.alloc(stab)
12001165
})
12011166
}
12021167

12031168
pub fn intern_layout(self, layout: LayoutDetails) -> &'gcx LayoutDetails {
12041169
self.layout_interner.borrow_mut().intern(layout, |layout| {
1205-
self.global_arenas.layout.alloc(layout)
1170+
self.arena.alloc(layout)
12061171
})
12071172
}
12081173

@@ -1250,7 +1215,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12501215
cstore: &'tcx CrateStoreDyn,
12511216
local_providers: ty::query::Providers<'tcx>,
12521217
extern_providers: ty::query::Providers<'tcx>,
1253-
arenas: &'tcx AllArenas<'tcx>,
1218+
arenas: &'tcx AllArenas,
12541219
resolutions: ty::Resolutions,
12551220
hir: hir_map::Map<'tcx>,
12561221
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
@@ -1319,7 +1284,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13191284
sess: s,
13201285
cstore,
13211286
arena: WorkerLocal::new(|_| Arena::default()),
1322-
global_arenas: &arenas.global,
13231287
global_interners: interners,
13241288
dep_graph,
13251289
common,

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub use self::sty::TyKind::*;
7575
pub use self::binding::BindingMode;
7676
pub use self::binding::BindingMode::*;
7777

78-
pub use self::context::{TyCtxt, FreeRegionInfo, GlobalArenas, AllArenas, tls, keep_local};
78+
pub use self::context::{TyCtxt, FreeRegionInfo, AllArenas, tls, keep_local};
7979
pub use self::context::{Lift, TypeckTables, CtxtInterners, GlobalCtxt};
8080
pub use self::context::{
8181
UserTypeAnnotationIndex, UserType, CanonicalUserType,

src/librustc_metadata/cstore_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ impl IntoArgs for (CrateNum, DefId) {
9494
provide! { <'tcx> tcx, def_id, other, cdata,
9595
type_of => { cdata.get_type(def_id.index, tcx) }
9696
generics_of => {
97-
tcx.alloc_generics(cdata.get_generics(def_id.index, tcx.sess))
97+
tcx.arena.alloc(cdata.get_generics(def_id.index, tcx.sess))
9898
}
9999
predicates_of => { tcx.arena.alloc(cdata.get_predicates(def_id.index, tcx)) }
100100
predicates_defined_on => {
101101
tcx.arena.alloc(cdata.get_predicates_defined_on(def_id.index, tcx))
102102
}
103103
super_predicates_of => { tcx.arena.alloc(cdata.get_super_predicates(def_id.index, tcx)) }
104104
trait_def => {
105-
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index, tcx.sess))
105+
tcx.arena.alloc(cdata.get_trait_def(def_id.index, tcx.sess))
106106
}
107107
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
108108
adt_destructor => {
@@ -129,7 +129,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
129129
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
130130
});
131131

132-
let mir = tcx.alloc_mir(mir);
132+
let mir = tcx.arena.alloc(mir);
133133

134134
mir
135135
}

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
125125

126126
debug!("make_shim({:?}) = {:?}", instance, result);
127127

128-
tcx.alloc_mir(result)
128+
tcx.arena.alloc(result)
129129
}
130130

131131
#[derive(Copy, Clone, Debug, PartialEq)]

src/librustc_mir/transform/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,5 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
290290
&add_call_guards::CriticalCallEdges,
291291
&dump_mir::Marker("PreCodegen"),
292292
]);
293-
tcx.alloc_mir(mir)
293+
tcx.arena.alloc(mir)
294294
}

src/librustc_typeck/check/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
8181
item_def_id, wbcx.tables
8282
);
8383

84-
self.tcx.alloc_tables(wbcx.tables)
84+
self.tcx.arena.alloc(wbcx.tables)
8585
}
8686
}
8787

src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::
763763
let is_marker = tcx.has_attr(def_id, sym::marker);
764764
let def_path_hash = tcx.def_path_hash(def_id);
765765
let def = ty::TraitDef::new(def_id, unsafety, paren_sugar, is_auto, is_marker, def_path_hash);
766-
tcx.alloc_trait_def(def)
766+
tcx.arena.alloc(def)
767767
}
768768

769769
fn has_late_bound_regions<'a, 'tcx>(
@@ -1110,7 +1110,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
11101110
.map(|param| (param.def_id, param.index))
11111111
.collect();
11121112

1113-
tcx.alloc_generics(ty::Generics {
1113+
tcx.arena.alloc(ty::Generics {
11141114
parent: parent_def_id,
11151115
parent_count,
11161116
params,

src/libsyntax/attr/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
111111
}
112112

113113
/// Represents the #[stable], #[unstable], #[rustc_{deprecated,const_unstable}] attributes.
114-
#[derive(RustcEncodable, RustcDecodable, Clone, Debug, PartialEq, Eq, Hash)]
114+
#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
115115
pub struct Stability {
116116
pub level: StabilityLevel,
117117
pub feature: Symbol,
@@ -127,7 +127,7 @@ pub struct Stability {
127127
}
128128

129129
/// The available stability levels.
130-
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
130+
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)]
131131
pub enum StabilityLevel {
132132
// Reason for the current stability level and the relevant rust-lang issue
133133
Unstable { reason: Option<Symbol>, issue: u32 },
@@ -151,7 +151,7 @@ impl StabilityLevel {
151151
}
152152
}
153153

154-
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
154+
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)]
155155
pub struct RustcDeprecation {
156156
pub since: Symbol,
157157
pub reason: Symbol,

0 commit comments

Comments
 (0)