1
Fork 0

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().
This commit is contained in:
Huon Wilson 2014-12-04 16:25:29 -08:00
parent ce3c949115
commit add6bb2f2d
5 changed files with 42 additions and 60 deletions

View file

@ -604,14 +604,29 @@ pub struct TransmuteRestriction<'tcx> {
pub id: ast::NodeId,
}
/// Internal storage
pub struct CtxtArenas<'tcx> {
type_: TypedArena<TyS<'tcx>>,
substs: TypedArena<Substs<'tcx>>,
bare_fn: TypedArena<BareFnTy<'tcx>>,
}
impl<'tcx> CtxtArenas<'tcx> {
pub fn new() -> CtxtArenas<'tcx> {
CtxtArenas {
type_: TypedArena::new(),
substs: TypedArena::new(),
bare_fn: TypedArena::new(),
}
}
}
/// The data structure to keep track of all the information that typechecker
/// generates so that so that it can be reused and doesn't have to be redone
/// later on.
pub struct ctxt<'tcx> {
/// The arena that types are allocated from.
type_arena: &'tcx TypedArena<TyS<'tcx>>,
substs_arena: &'tcx TypedArena<Substs<'tcx>>,
bare_fn_arena: &'tcx TypedArena<BareFnTy<'tcx>>,
/// The arenas that types etc are allocated from.
arenas: &'tcx CtxtArenas<'tcx>,
/// Specifically use a speedy hash algorithm for this hash map, it's used
/// quite often.
@ -2056,9 +2071,7 @@ impl UnboxedClosureKind {
}
pub fn mk_ctxt<'tcx>(s: Session,
type_arena: &'tcx TypedArena<TyS<'tcx>>,
substs_arena: &'tcx TypedArena<Substs<'tcx>>,
bare_fn_arena: &'tcx TypedArena<BareFnTy<'tcx>>,
arenas: &'tcx CtxtArenas<'tcx>,
dm: DefMap,
named_region_map: resolve_lifetime::NamedRegionMap,
map: ast_map::Map<'tcx>,
@ -2068,9 +2081,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
lang_items: middle::lang_items::LanguageItems,
stability: stability::Index) -> ctxt<'tcx> {
ctxt {
type_arena: type_arena,
substs_arena: substs_arena,
bare_fn_arena: bare_fn_arena,
arenas: arenas,
interner: RefCell::new(FnvHashMap::new()),
substs_interner: RefCell::new(FnvHashMap::new()),
bare_fn_interner: RefCell::new(FnvHashMap::new()),
@ -2139,7 +2150,7 @@ impl<'tcx> ctxt<'tcx> {
return *substs;
}
let substs = self.substs_arena.alloc(substs);
let substs = self.arenas.substs.alloc(substs);
self.substs_interner.borrow_mut().insert(substs, substs);
substs
}
@ -2149,7 +2160,7 @@ impl<'tcx> ctxt<'tcx> {
return *bare_fn;
}
let bare_fn = self.bare_fn_arena.alloc(bare_fn);
let bare_fn = self.arenas.bare_fn.alloc(bare_fn);
self.bare_fn_interner.borrow_mut().insert(bare_fn, bare_fn);
bare_fn
}
@ -2176,7 +2187,7 @@ pub fn mk_t<'tcx>(cx: &ctxt<'tcx>, st: sty<'tcx>) -> Ty<'tcx> {
let flags = FlagComputation::for_sty(&st);
let ty = cx.type_arena.alloc(TyS {
let ty = cx.arenas.type_.alloc(TyS {
sty: st,
flags: flags.flags,
region_depth: flags.depth,

View file

@ -12,7 +12,7 @@ use rustc::session::Session;
use rustc::session::config::{mod, Input, OutputFilenames};
use rustc::lint;
use rustc::metadata::creader;
use rustc::middle::{stability, ty, reachable, subst};
use rustc::middle::{stability, ty, reachable};
use rustc::middle::dependency_format;
use rustc::middle;
use rustc::plugin::load::Plugins;
@ -32,7 +32,7 @@ use serialize::{json, Encodable};
use std::io;
use std::io::fs;
use std::os;
use arena::TypedArena;
use save;
use syntax::ast;
use syntax::ast_map;
use syntax::attr;
@ -79,12 +79,8 @@ pub fn compile_input(sess: Session,
if stop_after_phase_2(&sess) { return; }
let type_arena = TypedArena::new();
let substs_arena = TypedArena::new();
let bare_fn_arena = TypedArena::new();
let analysis = phase_3_run_analysis_passes(sess, ast_map,
&type_arena, &substs_arena, &bare_fn_arena,
id);
let arenas = ty::CtxtArenas::new();
let analysis = phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir);
if log_enabled!(::log::INFO) {
@ -346,9 +342,7 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session,
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
ast_map: ast_map::Map<'tcx>,
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
substs_arena: &'tcx TypedArena<subst::Substs<'tcx>>,
bare_fn_arena: &'tcx TypedArena<ty::BareFnTy<'tcx>>,
arenas: &'tcx ty::CtxtArenas<'tcx>,
name: String) -> ty::CrateAnalysis<'tcx> {
let time_passes = sess.time_passes();
let krate = ast_map.krate();
@ -408,9 +402,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
middle::check_static_recursion::check_crate(&sess, krate, &def_map, &ast_map));
let ty_cx = ty::mk_ctxt(sess,
type_arena,
substs_arena,
bare_fn_arena,
arenas,
def_map,
named_region_map,
ast_map,

View file

@ -19,7 +19,7 @@ use rustc_trans::back::link;
use driver;
use rustc::middle::{ty, subst};
use rustc::middle::ty;
use rustc::middle::cfg;
use rustc::middle::cfg::graphviz::LabelledCFG;
use rustc::session::Session;
@ -40,7 +40,6 @@ use graphviz as dot;
use std::io::{mod, MemReader};
use std::option;
use std::str::FromStr;
use arena::TypedArena;
#[deriving(Copy, PartialEq, Show)]
pub enum PpSourceMode {
@ -112,9 +111,7 @@ impl PpSourceMode {
fn call_with_pp_support<'tcx, A, B, F>(&self,
sess: Session,
ast_map: Option<ast_map::Map<'tcx>>,
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
substs_arena: &'tcx TypedArena<subst::Substs<'tcx>>,
bare_fn_arena: &'tcx TypedArena<ty::BareFnTy<'tcx>>,
arenas: &'tcx ty::CtxtArenas<'tcx>,
id: String,
payload: B,
f: F) -> A where
@ -136,10 +133,7 @@ impl PpSourceMode {
}
PpmTyped => {
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map,
type_arena, substs_arena,
bare_fn_arena,
id);
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, arenas, id);
let annotation = TypedAnnotation { analysis: analysis };
f(&annotation, payload)
}
@ -514,9 +508,7 @@ pub fn pretty_print_input(sess: Session,
};
let mut forest = ast_map::Forest::new(krate);
let type_arena = TypedArena::new();
let substs_arena = TypedArena::new();
let bare_fn_arena = TypedArena::new();
let arenas = ty::CtxtArenas::new();
let (krate, ast_map) = if compute_ast_map {
let map = driver::assign_node_ids_and_map(&sess, &mut forest);
@ -545,8 +537,7 @@ pub fn pretty_print_input(sess: Session,
match (ppm, opt_uii) {
(PpmSource(s), None) =>
s.call_with_pp_support(
sess, ast_map, &type_arena, &substs_arena, &bare_fn_arena,
id, out, |annotation, out| {
sess, ast_map, &arenas, id, out, |annotation, out| {
debug!("pretty printing source code {}", s);
let sess = annotation.sess();
pprust::print_crate(sess.codemap(),
@ -561,8 +552,7 @@ pub fn pretty_print_input(sess: Session,
(PpmSource(s), Some(uii)) =>
s.call_with_pp_support(
sess, ast_map, &type_arena, &substs_arena, &bare_fn_arena,
id, (out,uii), |annotation, (out,uii)| {
sess, ast_map, &arenas, id, (out,uii), |annotation, (out,uii)| {
debug!("pretty printing source code {}", s);
let sess = annotation.sess();
let ast_map = annotation.ast_map()
@ -604,10 +594,7 @@ pub fn pretty_print_input(sess: Session,
match code {
Some(code) => {
let variants = gather_flowgraph_variants(&sess);
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map,
&type_arena, &substs_arena,
&bare_fn_arena,
id);
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
print_flowgraph(variants, analysis, code, out)
}
None => {

View file

@ -127,13 +127,9 @@ fn test_env<F>(source_string: &str,
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
let region_map = region::resolve_crate(&sess, krate);
let stability_index = stability::Index::build(krate);
let type_arena = TypedArena::new();
let substs_arena = TypedArena::new();
let bare_fn_arena = TypedArena::new();
let arenas = ty::CtxtArenas::new();
let tcx = ty::mk_ctxt(sess,
&type_arena,
&substs_arena,
&bare_fn_arena,
&arenas,
def_map,
named_region_map,
ast_map,

View file

@ -19,7 +19,6 @@ use syntax::{ast, ast_map, codemap, diagnostic};
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use arena::TypedArena;
use visit_ast::RustdocVisitor;
use clean;
@ -121,14 +120,11 @@ pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
let mut forest = ast_map::Forest::new(krate);
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
let type_arena = TypedArena::new();
let substs_arena = TypedArena::new();
let bare_fn_arena = TypedArena::new();
let arenas = ty::CtxtArenas::new();
let ty::CrateAnalysis {
let driver::CrateAnalysis {
exported_items, public_items, ty_cx, ..
} = driver::phase_3_run_analysis_passes(sess, ast_map,
&type_arena, &substs_arena, &bare_fn_arena,
name);
} = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, name);
let ctxt = DocContext {
krate: ty_cx.map.krate(),