Skip to content

Commit add6bb2

Browse files
committed
Collect tcx arenas into a single struct.
This allows expanding how many arenas exist without users having to care, since they are all created with CtxtArena::new().
1 parent ce3c949 commit add6bb2

File tree

5 files changed

+42
-60
lines changed

5 files changed

+42
-60
lines changed

src/librustc/middle/ty.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,29 @@ pub struct TransmuteRestriction<'tcx> {
604604
pub id: ast::NodeId,
605605
}
606606

607+
/// Internal storage
608+
pub struct CtxtArenas<'tcx> {
609+
type_: TypedArena<TyS<'tcx>>,
610+
substs: TypedArena<Substs<'tcx>>,
611+
bare_fn: TypedArena<BareFnTy<'tcx>>,
612+
}
613+
614+
impl<'tcx> CtxtArenas<'tcx> {
615+
pub fn new() -> CtxtArenas<'tcx> {
616+
CtxtArenas {
617+
type_: TypedArena::new(),
618+
substs: TypedArena::new(),
619+
bare_fn: TypedArena::new(),
620+
}
621+
}
622+
}
623+
607624
/// The data structure to keep track of all the information that typechecker
608625
/// generates so that so that it can be reused and doesn't have to be redone
609626
/// later on.
610627
pub struct ctxt<'tcx> {
611-
/// The arena that types are allocated from.
612-
type_arena: &'tcx TypedArena<TyS<'tcx>>,
613-
substs_arena: &'tcx TypedArena<Substs<'tcx>>,
614-
bare_fn_arena: &'tcx TypedArena<BareFnTy<'tcx>>,
628+
/// The arenas that types etc are allocated from.
629+
arenas: &'tcx CtxtArenas<'tcx>,
615630

616631
/// Specifically use a speedy hash algorithm for this hash map, it's used
617632
/// quite often.
@@ -2056,9 +2071,7 @@ impl UnboxedClosureKind {
20562071
}
20572072

20582073
pub fn mk_ctxt<'tcx>(s: Session,
2059-
type_arena: &'tcx TypedArena<TyS<'tcx>>,
2060-
substs_arena: &'tcx TypedArena<Substs<'tcx>>,
2061-
bare_fn_arena: &'tcx TypedArena<BareFnTy<'tcx>>,
2074+
arenas: &'tcx CtxtArenas<'tcx>,
20622075
dm: DefMap,
20632076
named_region_map: resolve_lifetime::NamedRegionMap,
20642077
map: ast_map::Map<'tcx>,
@@ -2068,9 +2081,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
20682081
lang_items: middle::lang_items::LanguageItems,
20692082
stability: stability::Index) -> ctxt<'tcx> {
20702083
ctxt {
2071-
type_arena: type_arena,
2072-
substs_arena: substs_arena,
2073-
bare_fn_arena: bare_fn_arena,
2084+
arenas: arenas,
20742085
interner: RefCell::new(FnvHashMap::new()),
20752086
substs_interner: RefCell::new(FnvHashMap::new()),
20762087
bare_fn_interner: RefCell::new(FnvHashMap::new()),
@@ -2139,7 +2150,7 @@ impl<'tcx> ctxt<'tcx> {
21392150
return *substs;
21402151
}
21412152

2142-
let substs = self.substs_arena.alloc(substs);
2153+
let substs = self.arenas.substs.alloc(substs);
21432154
self.substs_interner.borrow_mut().insert(substs, substs);
21442155
substs
21452156
}
@@ -2149,7 +2160,7 @@ impl<'tcx> ctxt<'tcx> {
21492160
return *bare_fn;
21502161
}
21512162

2152-
let bare_fn = self.bare_fn_arena.alloc(bare_fn);
2163+
let bare_fn = self.arenas.bare_fn.alloc(bare_fn);
21532164
self.bare_fn_interner.borrow_mut().insert(bare_fn, bare_fn);
21542165
bare_fn
21552166
}
@@ -2176,7 +2187,7 @@ pub fn mk_t<'tcx>(cx: &ctxt<'tcx>, st: sty<'tcx>) -> Ty<'tcx> {
21762187

21772188
let flags = FlagComputation::for_sty(&st);
21782189

2179-
let ty = cx.type_arena.alloc(TyS {
2190+
let ty = cx.arenas.type_.alloc(TyS {
21802191
sty: st,
21812192
flags: flags.flags,
21822193
region_depth: flags.depth,

src/librustc_driver/driver.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::session::Session;
1212
use rustc::session::config::{mod, Input, OutputFilenames};
1313
use rustc::lint;
1414
use rustc::metadata::creader;
15-
use rustc::middle::{stability, ty, reachable, subst};
15+
use rustc::middle::{stability, ty, reachable};
1616
use rustc::middle::dependency_format;
1717
use rustc::middle;
1818
use rustc::plugin::load::Plugins;
@@ -32,7 +32,7 @@ use serialize::{json, Encodable};
3232
use std::io;
3333
use std::io::fs;
3434
use std::os;
35-
use arena::TypedArena;
35+
use save;
3636
use syntax::ast;
3737
use syntax::ast_map;
3838
use syntax::attr;
@@ -79,12 +79,8 @@ pub fn compile_input(sess: Session,
7979

8080
if stop_after_phase_2(&sess) { return; }
8181

82-
let type_arena = TypedArena::new();
83-
let substs_arena = TypedArena::new();
84-
let bare_fn_arena = TypedArena::new();
85-
let analysis = phase_3_run_analysis_passes(sess, ast_map,
86-
&type_arena, &substs_arena, &bare_fn_arena,
87-
id);
82+
let arenas = ty::CtxtArenas::new();
83+
let analysis = phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
8884
phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir);
8985

9086
if log_enabled!(::log::INFO) {
@@ -346,9 +342,7 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session,
346342
/// structures carrying the results of the analysis.
347343
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
348344
ast_map: ast_map::Map<'tcx>,
349-
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
350-
substs_arena: &'tcx TypedArena<subst::Substs<'tcx>>,
351-
bare_fn_arena: &'tcx TypedArena<ty::BareFnTy<'tcx>>,
345+
arenas: &'tcx ty::CtxtArenas<'tcx>,
352346
name: String) -> ty::CrateAnalysis<'tcx> {
353347
let time_passes = sess.time_passes();
354348
let krate = ast_map.krate();
@@ -408,9 +402,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
408402
middle::check_static_recursion::check_crate(&sess, krate, &def_map, &ast_map));
409403

410404
let ty_cx = ty::mk_ctxt(sess,
411-
type_arena,
412-
substs_arena,
413-
bare_fn_arena,
405+
arenas,
414406
def_map,
415407
named_region_map,
416408
ast_map,

src/librustc_driver/pretty.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_trans::back::link;
1919

2020
use driver;
2121

22-
use rustc::middle::{ty, subst};
22+
use rustc::middle::ty;
2323
use rustc::middle::cfg;
2424
use rustc::middle::cfg::graphviz::LabelledCFG;
2525
use rustc::session::Session;
@@ -40,7 +40,6 @@ use graphviz as dot;
4040
use std::io::{mod, MemReader};
4141
use std::option;
4242
use std::str::FromStr;
43-
use arena::TypedArena;
4443

4544
#[deriving(Copy, PartialEq, Show)]
4645
pub enum PpSourceMode {
@@ -112,9 +111,7 @@ impl PpSourceMode {
112111
fn call_with_pp_support<'tcx, A, B, F>(&self,
113112
sess: Session,
114113
ast_map: Option<ast_map::Map<'tcx>>,
115-
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
116-
substs_arena: &'tcx TypedArena<subst::Substs<'tcx>>,
117-
bare_fn_arena: &'tcx TypedArena<ty::BareFnTy<'tcx>>,
114+
arenas: &'tcx ty::CtxtArenas<'tcx>,
118115
id: String,
119116
payload: B,
120117
f: F) -> A where
@@ -136,10 +133,7 @@ impl PpSourceMode {
136133
}
137134
PpmTyped => {
138135
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
139-
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map,
140-
type_arena, substs_arena,
141-
bare_fn_arena,
142-
id);
136+
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, arenas, id);
143137
let annotation = TypedAnnotation { analysis: analysis };
144138
f(&annotation, payload)
145139
}
@@ -514,9 +508,7 @@ pub fn pretty_print_input(sess: Session,
514508
};
515509

516510
let mut forest = ast_map::Forest::new(krate);
517-
let type_arena = TypedArena::new();
518-
let substs_arena = TypedArena::new();
519-
let bare_fn_arena = TypedArena::new();
511+
let arenas = ty::CtxtArenas::new();
520512

521513
let (krate, ast_map) = if compute_ast_map {
522514
let map = driver::assign_node_ids_and_map(&sess, &mut forest);
@@ -545,8 +537,7 @@ pub fn pretty_print_input(sess: Session,
545537
match (ppm, opt_uii) {
546538
(PpmSource(s), None) =>
547539
s.call_with_pp_support(
548-
sess, ast_map, &type_arena, &substs_arena, &bare_fn_arena,
549-
id, out, |annotation, out| {
540+
sess, ast_map, &arenas, id, out, |annotation, out| {
550541
debug!("pretty printing source code {}", s);
551542
let sess = annotation.sess();
552543
pprust::print_crate(sess.codemap(),
@@ -561,8 +552,7 @@ pub fn pretty_print_input(sess: Session,
561552

562553
(PpmSource(s), Some(uii)) =>
563554
s.call_with_pp_support(
564-
sess, ast_map, &type_arena, &substs_arena, &bare_fn_arena,
565-
id, (out,uii), |annotation, (out,uii)| {
555+
sess, ast_map, &arenas, id, (out,uii), |annotation, (out,uii)| {
566556
debug!("pretty printing source code {}", s);
567557
let sess = annotation.sess();
568558
let ast_map = annotation.ast_map()
@@ -604,10 +594,7 @@ pub fn pretty_print_input(sess: Session,
604594
match code {
605595
Some(code) => {
606596
let variants = gather_flowgraph_variants(&sess);
607-
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map,
608-
&type_arena, &substs_arena,
609-
&bare_fn_arena,
610-
id);
597+
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
611598
print_flowgraph(variants, analysis, code, out)
612599
}
613600
None => {

src/librustc_driver/test.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,9 @@ fn test_env<F>(source_string: &str,
127127
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
128128
let region_map = region::resolve_crate(&sess, krate);
129129
let stability_index = stability::Index::build(krate);
130-
let type_arena = TypedArena::new();
131-
let substs_arena = TypedArena::new();
132-
let bare_fn_arena = TypedArena::new();
130+
let arenas = ty::CtxtArenas::new();
133131
let tcx = ty::mk_ctxt(sess,
134-
&type_arena,
135-
&substs_arena,
136-
&bare_fn_arena,
132+
&arenas,
137133
def_map,
138134
named_region_map,
139135
ast_map,

src/librustdoc/core.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use syntax::{ast, ast_map, codemap, diagnostic};
1919

2020
use std::cell::RefCell;
2121
use std::collections::{HashMap, HashSet};
22-
use arena::TypedArena;
2322

2423
use visit_ast::RustdocVisitor;
2524
use clean;
@@ -121,14 +120,11 @@ pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
121120
let mut forest = ast_map::Forest::new(krate);
122121
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
123122

124-
let type_arena = TypedArena::new();
125-
let substs_arena = TypedArena::new();
126-
let bare_fn_arena = TypedArena::new();
123+
let arenas = ty::CtxtArenas::new();
127124
let ty::CrateAnalysis {
125+
let driver::CrateAnalysis {
128126
exported_items, public_items, ty_cx, ..
129-
} = driver::phase_3_run_analysis_passes(sess, ast_map,
130-
&type_arena, &substs_arena, &bare_fn_arena,
131-
name);
127+
} = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, name);
132128

133129
let ctxt = DocContext {
134130
krate: ty_cx.map.krate(),

0 commit comments

Comments
 (0)