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:
parent
ce3c949115
commit
add6bb2f2d
5 changed files with 42 additions and 60 deletions
|
@ -604,14 +604,29 @@ pub struct TransmuteRestriction<'tcx> {
|
||||||
pub id: ast::NodeId,
|
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
|
/// 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
|
/// generates so that so that it can be reused and doesn't have to be redone
|
||||||
/// later on.
|
/// later on.
|
||||||
pub struct ctxt<'tcx> {
|
pub struct ctxt<'tcx> {
|
||||||
/// The arena that types are allocated from.
|
/// The arenas that types etc are allocated from.
|
||||||
type_arena: &'tcx TypedArena<TyS<'tcx>>,
|
arenas: &'tcx CtxtArenas<'tcx>,
|
||||||
substs_arena: &'tcx TypedArena<Substs<'tcx>>,
|
|
||||||
bare_fn_arena: &'tcx TypedArena<BareFnTy<'tcx>>,
|
|
||||||
|
|
||||||
/// Specifically use a speedy hash algorithm for this hash map, it's used
|
/// Specifically use a speedy hash algorithm for this hash map, it's used
|
||||||
/// quite often.
|
/// quite often.
|
||||||
|
@ -2056,9 +2071,7 @@ impl UnboxedClosureKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_ctxt<'tcx>(s: Session,
|
pub fn mk_ctxt<'tcx>(s: Session,
|
||||||
type_arena: &'tcx TypedArena<TyS<'tcx>>,
|
arenas: &'tcx CtxtArenas<'tcx>,
|
||||||
substs_arena: &'tcx TypedArena<Substs<'tcx>>,
|
|
||||||
bare_fn_arena: &'tcx TypedArena<BareFnTy<'tcx>>,
|
|
||||||
dm: DefMap,
|
dm: DefMap,
|
||||||
named_region_map: resolve_lifetime::NamedRegionMap,
|
named_region_map: resolve_lifetime::NamedRegionMap,
|
||||||
map: ast_map::Map<'tcx>,
|
map: ast_map::Map<'tcx>,
|
||||||
|
@ -2068,9 +2081,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
|
||||||
lang_items: middle::lang_items::LanguageItems,
|
lang_items: middle::lang_items::LanguageItems,
|
||||||
stability: stability::Index) -> ctxt<'tcx> {
|
stability: stability::Index) -> ctxt<'tcx> {
|
||||||
ctxt {
|
ctxt {
|
||||||
type_arena: type_arena,
|
arenas: arenas,
|
||||||
substs_arena: substs_arena,
|
|
||||||
bare_fn_arena: bare_fn_arena,
|
|
||||||
interner: RefCell::new(FnvHashMap::new()),
|
interner: RefCell::new(FnvHashMap::new()),
|
||||||
substs_interner: RefCell::new(FnvHashMap::new()),
|
substs_interner: RefCell::new(FnvHashMap::new()),
|
||||||
bare_fn_interner: RefCell::new(FnvHashMap::new()),
|
bare_fn_interner: RefCell::new(FnvHashMap::new()),
|
||||||
|
@ -2139,7 +2150,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||||
return *substs;
|
return *substs;
|
||||||
}
|
}
|
||||||
|
|
||||||
let substs = self.substs_arena.alloc(substs);
|
let substs = self.arenas.substs.alloc(substs);
|
||||||
self.substs_interner.borrow_mut().insert(substs, substs);
|
self.substs_interner.borrow_mut().insert(substs, substs);
|
||||||
substs
|
substs
|
||||||
}
|
}
|
||||||
|
@ -2149,7 +2160,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||||
return *bare_fn;
|
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);
|
self.bare_fn_interner.borrow_mut().insert(bare_fn, 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 flags = FlagComputation::for_sty(&st);
|
||||||
|
|
||||||
let ty = cx.type_arena.alloc(TyS {
|
let ty = cx.arenas.type_.alloc(TyS {
|
||||||
sty: st,
|
sty: st,
|
||||||
flags: flags.flags,
|
flags: flags.flags,
|
||||||
region_depth: flags.depth,
|
region_depth: flags.depth,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use rustc::session::Session;
|
||||||
use rustc::session::config::{mod, Input, OutputFilenames};
|
use rustc::session::config::{mod, Input, OutputFilenames};
|
||||||
use rustc::lint;
|
use rustc::lint;
|
||||||
use rustc::metadata::creader;
|
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::dependency_format;
|
||||||
use rustc::middle;
|
use rustc::middle;
|
||||||
use rustc::plugin::load::Plugins;
|
use rustc::plugin::load::Plugins;
|
||||||
|
@ -32,7 +32,7 @@ use serialize::{json, Encodable};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::fs;
|
use std::io::fs;
|
||||||
use std::os;
|
use std::os;
|
||||||
use arena::TypedArena;
|
use save;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast_map;
|
use syntax::ast_map;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
@ -79,12 +79,8 @@ pub fn compile_input(sess: Session,
|
||||||
|
|
||||||
if stop_after_phase_2(&sess) { return; }
|
if stop_after_phase_2(&sess) { return; }
|
||||||
|
|
||||||
let type_arena = TypedArena::new();
|
let arenas = ty::CtxtArenas::new();
|
||||||
let substs_arena = TypedArena::new();
|
let analysis = phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
|
||||||
let bare_fn_arena = TypedArena::new();
|
|
||||||
let analysis = phase_3_run_analysis_passes(sess, ast_map,
|
|
||||||
&type_arena, &substs_arena, &bare_fn_arena,
|
|
||||||
id);
|
|
||||||
phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir);
|
phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir);
|
||||||
|
|
||||||
if log_enabled!(::log::INFO) {
|
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.
|
/// structures carrying the results of the analysis.
|
||||||
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
|
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
|
||||||
ast_map: ast_map::Map<'tcx>,
|
ast_map: ast_map::Map<'tcx>,
|
||||||
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
|
arenas: &'tcx ty::CtxtArenas<'tcx>,
|
||||||
substs_arena: &'tcx TypedArena<subst::Substs<'tcx>>,
|
|
||||||
bare_fn_arena: &'tcx TypedArena<ty::BareFnTy<'tcx>>,
|
|
||||||
name: String) -> ty::CrateAnalysis<'tcx> {
|
name: String) -> ty::CrateAnalysis<'tcx> {
|
||||||
let time_passes = sess.time_passes();
|
let time_passes = sess.time_passes();
|
||||||
let krate = ast_map.krate();
|
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));
|
middle::check_static_recursion::check_crate(&sess, krate, &def_map, &ast_map));
|
||||||
|
|
||||||
let ty_cx = ty::mk_ctxt(sess,
|
let ty_cx = ty::mk_ctxt(sess,
|
||||||
type_arena,
|
arenas,
|
||||||
substs_arena,
|
|
||||||
bare_fn_arena,
|
|
||||||
def_map,
|
def_map,
|
||||||
named_region_map,
|
named_region_map,
|
||||||
ast_map,
|
ast_map,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use rustc_trans::back::link;
|
||||||
|
|
||||||
use driver;
|
use driver;
|
||||||
|
|
||||||
use rustc::middle::{ty, subst};
|
use rustc::middle::ty;
|
||||||
use rustc::middle::cfg;
|
use rustc::middle::cfg;
|
||||||
use rustc::middle::cfg::graphviz::LabelledCFG;
|
use rustc::middle::cfg::graphviz::LabelledCFG;
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
|
@ -40,7 +40,6 @@ use graphviz as dot;
|
||||||
use std::io::{mod, MemReader};
|
use std::io::{mod, MemReader};
|
||||||
use std::option;
|
use std::option;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use arena::TypedArena;
|
|
||||||
|
|
||||||
#[deriving(Copy, PartialEq, Show)]
|
#[deriving(Copy, PartialEq, Show)]
|
||||||
pub enum PpSourceMode {
|
pub enum PpSourceMode {
|
||||||
|
@ -112,9 +111,7 @@ impl PpSourceMode {
|
||||||
fn call_with_pp_support<'tcx, A, B, F>(&self,
|
fn call_with_pp_support<'tcx, A, B, F>(&self,
|
||||||
sess: Session,
|
sess: Session,
|
||||||
ast_map: Option<ast_map::Map<'tcx>>,
|
ast_map: Option<ast_map::Map<'tcx>>,
|
||||||
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
|
arenas: &'tcx ty::CtxtArenas<'tcx>,
|
||||||
substs_arena: &'tcx TypedArena<subst::Substs<'tcx>>,
|
|
||||||
bare_fn_arena: &'tcx TypedArena<ty::BareFnTy<'tcx>>,
|
|
||||||
id: String,
|
id: String,
|
||||||
payload: B,
|
payload: B,
|
||||||
f: F) -> A where
|
f: F) -> A where
|
||||||
|
@ -136,10 +133,7 @@ impl PpSourceMode {
|
||||||
}
|
}
|
||||||
PpmTyped => {
|
PpmTyped => {
|
||||||
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
|
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
|
||||||
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map,
|
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, arenas, id);
|
||||||
type_arena, substs_arena,
|
|
||||||
bare_fn_arena,
|
|
||||||
id);
|
|
||||||
let annotation = TypedAnnotation { analysis: analysis };
|
let annotation = TypedAnnotation { analysis: analysis };
|
||||||
f(&annotation, payload)
|
f(&annotation, payload)
|
||||||
}
|
}
|
||||||
|
@ -514,9 +508,7 @@ pub fn pretty_print_input(sess: Session,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut forest = ast_map::Forest::new(krate);
|
let mut forest = ast_map::Forest::new(krate);
|
||||||
let type_arena = TypedArena::new();
|
let arenas = ty::CtxtArenas::new();
|
||||||
let substs_arena = TypedArena::new();
|
|
||||||
let bare_fn_arena = TypedArena::new();
|
|
||||||
|
|
||||||
let (krate, ast_map) = if compute_ast_map {
|
let (krate, ast_map) = if compute_ast_map {
|
||||||
let map = driver::assign_node_ids_and_map(&sess, &mut forest);
|
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) {
|
match (ppm, opt_uii) {
|
||||||
(PpmSource(s), None) =>
|
(PpmSource(s), None) =>
|
||||||
s.call_with_pp_support(
|
s.call_with_pp_support(
|
||||||
sess, ast_map, &type_arena, &substs_arena, &bare_fn_arena,
|
sess, ast_map, &arenas, id, out, |annotation, out| {
|
||||||
id, out, |annotation, out| {
|
|
||||||
debug!("pretty printing source code {}", s);
|
debug!("pretty printing source code {}", s);
|
||||||
let sess = annotation.sess();
|
let sess = annotation.sess();
|
||||||
pprust::print_crate(sess.codemap(),
|
pprust::print_crate(sess.codemap(),
|
||||||
|
@ -561,8 +552,7 @@ pub fn pretty_print_input(sess: Session,
|
||||||
|
|
||||||
(PpmSource(s), Some(uii)) =>
|
(PpmSource(s), Some(uii)) =>
|
||||||
s.call_with_pp_support(
|
s.call_with_pp_support(
|
||||||
sess, ast_map, &type_arena, &substs_arena, &bare_fn_arena,
|
sess, ast_map, &arenas, id, (out,uii), |annotation, (out,uii)| {
|
||||||
id, (out,uii), |annotation, (out,uii)| {
|
|
||||||
debug!("pretty printing source code {}", s);
|
debug!("pretty printing source code {}", s);
|
||||||
let sess = annotation.sess();
|
let sess = annotation.sess();
|
||||||
let ast_map = annotation.ast_map()
|
let ast_map = annotation.ast_map()
|
||||||
|
@ -604,10 +594,7 @@ pub fn pretty_print_input(sess: Session,
|
||||||
match code {
|
match code {
|
||||||
Some(code) => {
|
Some(code) => {
|
||||||
let variants = gather_flowgraph_variants(&sess);
|
let variants = gather_flowgraph_variants(&sess);
|
||||||
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map,
|
let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
|
||||||
&type_arena, &substs_arena,
|
|
||||||
&bare_fn_arena,
|
|
||||||
id);
|
|
||||||
print_flowgraph(variants, analysis, code, out)
|
print_flowgraph(variants, analysis, code, out)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -127,13 +127,9 @@ fn test_env<F>(source_string: &str,
|
||||||
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
|
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
|
||||||
let region_map = region::resolve_crate(&sess, krate);
|
let region_map = region::resolve_crate(&sess, krate);
|
||||||
let stability_index = stability::Index::build(krate);
|
let stability_index = stability::Index::build(krate);
|
||||||
let type_arena = TypedArena::new();
|
let arenas = ty::CtxtArenas::new();
|
||||||
let substs_arena = TypedArena::new();
|
|
||||||
let bare_fn_arena = TypedArena::new();
|
|
||||||
let tcx = ty::mk_ctxt(sess,
|
let tcx = ty::mk_ctxt(sess,
|
||||||
&type_arena,
|
&arenas,
|
||||||
&substs_arena,
|
|
||||||
&bare_fn_arena,
|
|
||||||
def_map,
|
def_map,
|
||||||
named_region_map,
|
named_region_map,
|
||||||
ast_map,
|
ast_map,
|
||||||
|
|
|
@ -19,7 +19,6 @@ use syntax::{ast, ast_map, codemap, diagnostic};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use arena::TypedArena;
|
|
||||||
|
|
||||||
use visit_ast::RustdocVisitor;
|
use visit_ast::RustdocVisitor;
|
||||||
use clean;
|
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 mut forest = ast_map::Forest::new(krate);
|
||||||
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
|
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
|
||||||
|
|
||||||
let type_arena = TypedArena::new();
|
let arenas = ty::CtxtArenas::new();
|
||||||
let substs_arena = TypedArena::new();
|
|
||||||
let bare_fn_arena = TypedArena::new();
|
|
||||||
let ty::CrateAnalysis {
|
let ty::CrateAnalysis {
|
||||||
|
let driver::CrateAnalysis {
|
||||||
exported_items, public_items, ty_cx, ..
|
exported_items, public_items, ty_cx, ..
|
||||||
} = driver::phase_3_run_analysis_passes(sess, ast_map,
|
} = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, name);
|
||||||
&type_arena, &substs_arena, &bare_fn_arena,
|
|
||||||
name);
|
|
||||||
|
|
||||||
let ctxt = DocContext {
|
let ctxt = DocContext {
|
||||||
krate: ty_cx.map.krate(),
|
krate: ty_cx.map.krate(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue