Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a TypedArena in ty::ctxt. #12809

Merged
merged 4 commits into from
Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use serialize::{json, Encodable};

use std::io;
use std::io::fs;
use arena::TypedArena;
use syntax::ast;
use syntax::attr;
use syntax::attr::{AttrMetaMethods};
Expand Down Expand Up @@ -86,8 +87,9 @@ pub fn compile_input(sess: Session,

if stop_after_phase_2(&sess) { return; }

let type_arena = TypedArena::new();
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate,
ast_map, id);
ast_map, &type_arena, id);
phase_save_analysis(&analysis.ty_cx.sess, &expanded_crate, &analysis, outdir);
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate, analysis);
Expand Down Expand Up @@ -299,11 +301,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
Some((krate, map))
}

pub struct CrateAnalysis {
pub struct CrateAnalysis<'tcx> {
pub exp_map2: middle::resolve::ExportMap2,
pub exported_items: middle::privacy::ExportedItems,
pub public_items: middle::privacy::PublicItems,
pub ty_cx: ty::ctxt,
pub ty_cx: ty::ctxt<'tcx>,
pub reachable: NodeSet,
pub name: String,
}
Expand All @@ -312,10 +314,11 @@ pub struct CrateAnalysis {
/// Run the resolution, typechecking, region checking and other
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes(sess: Session,
krate: &ast::Crate,
ast_map: syntax::ast_map::Map,
name: String) -> CrateAnalysis {
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
krate: &ast::Crate,
ast_map: syntax::ast_map::Map,
type_arena: &'tcx TypedArena<ty::t_box_>,
name: String) -> CrateAnalysis<'tcx> {
let time_passes = sess.time_passes();

time(time_passes, "external crate/lib resolution", (), |_|
Expand Down Expand Up @@ -362,6 +365,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
stability::Index::build(krate));

let ty_cx = ty::mk_ctxt(sess,
type_arena,
def_map,
named_region_map,
ast_map,
Expand Down
21 changes: 12 additions & 9 deletions src/librustc/driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use graphviz as dot;
use std::io::{mod, MemReader};
use std::from_str::FromStr;
use std::option;

use arena::TypedArena;

#[deriving(PartialEq, Show)]
pub enum PpSourceMode {
Expand Down Expand Up @@ -114,7 +114,9 @@ impl PpSourceMode {
}
PpmTyped => {
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
let analysis = driver::phase_3_run_analysis_passes(sess, krate, ast_map, id);
let type_arena = TypedArena::new();
let analysis = driver::phase_3_run_analysis_passes(sess, krate, ast_map,
&type_arena, id);
let annotation = TypedAnnotation { analysis: analysis };
f(&annotation, payload)
}
Expand Down Expand Up @@ -260,25 +262,25 @@ impl pprust::PpAnn for HygieneAnnotation {
}


struct TypedAnnotation {
analysis: CrateAnalysis,
struct TypedAnnotation<'tcx> {
analysis: CrateAnalysis<'tcx>,
}

impl PrinterSupport for TypedAnnotation {
impl<'tcx> PrinterSupport for TypedAnnotation<'tcx> {
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self as &pprust::PpAnn }
}

impl SessionCarrier for TypedAnnotation {
impl<'tcx> SessionCarrier for TypedAnnotation<'tcx> {
fn sess<'a>(&'a self) -> &'a Session { &self.analysis.ty_cx.sess }
}

impl AstMapCarrier for TypedAnnotation {
impl<'tcx> AstMapCarrier for TypedAnnotation<'tcx> {
fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map> {
Some(&self.analysis.ty_cx.map)
}
}

impl pprust::PpAnn for TypedAnnotation {
impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> {
fn pre(&self,
s: &mut pprust::State,
node: pprust::AnnNode) -> io::IoResult<()> {
Expand Down Expand Up @@ -531,8 +533,9 @@ pub fn pretty_print_input(sess: Session,
match code {
Some(code) => {
let variants = gather_flowgraph_variants(&sess);
let type_arena = TypedArena::new();
let analysis = driver::phase_3_run_analysis_passes(sess, &krate,
ast_map, id);
ast_map, &type_arena, id);
print_flowgraph(variants, analysis, code, out)
}
None => {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ impl LintPass for TypeLimits {
declare_lint!(CTYPES, Warn,
"proper use of libc types in foreign modules")

struct CTypesVisitor<'a> {
cx: &'a Context<'a>
struct CTypesVisitor<'a, 'tcx: 'a> {
cx: &'a Context<'a, 'tcx>
}

impl<'a> CTypesVisitor<'a> {
impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> {
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
match self.cx.tcx.def_map.borrow().get_copy(&path_id) {
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<'a> CTypesVisitor<'a> {
}
}

impl<'a> Visitor<()> for CTypesVisitor<'a> {
impl<'a, 'tcx> Visitor<()> for CTypesVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
match ty.node {
ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id),
Expand Down Expand Up @@ -505,11 +505,11 @@ impl LintPass for HeapMemory {
declare_lint!(RAW_POINTER_DERIVING, Warn,
"uses of #[deriving] with raw pointers are rarely correct")

struct RawPtrDerivingVisitor<'a> {
cx: &'a Context<'a>
struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
cx: &'a Context<'a, 'tcx>
}

impl<'a> Visitor<()> for RawPtrDerivingVisitor<'a> {
impl<'a, 'tcx> Visitor<()> for RawPtrDerivingVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
match ty.node {
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ impl LintStore {
}

/// Context for lint checking.
pub struct Context<'a> {
pub struct Context<'a, 'tcx: 'a> {
/// Type context we're checking in.
pub tcx: &'a ty::ctxt,
pub tcx: &'a ty::ctxt<'tcx>,

/// The crate being checked.
pub krate: &'a ast::Crate,
Expand Down Expand Up @@ -345,10 +345,10 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
}
}

impl<'a> Context<'a> {
fn new(tcx: &'a ty::ctxt,
impl<'a, 'tcx> Context<'a, 'tcx> {
fn new(tcx: &'a ty::ctxt<'tcx>,
krate: &'a ast::Crate,
exported_items: &'a ExportedItems) -> Context<'a> {
exported_items: &'a ExportedItems) -> Context<'a, 'tcx> {
// We want to own the lint store, so move it out of the session.
let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(),
LintStore::new());
Expand Down Expand Up @@ -476,8 +476,8 @@ impl<'a> Context<'a> {
}
}

impl<'a> AstConv for Context<'a>{
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx }
impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx }

fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype {
ty::lookup_item_type(self.tcx, id)
Expand All @@ -492,7 +492,7 @@ impl<'a> AstConv for Context<'a>{
}
}

impl<'a> Visitor<()> for Context<'a> {
impl<'a, 'tcx> Visitor<()> for Context<'a, 'tcx> {
fn visit_item(&mut self, it: &ast::Item, _: ()) {
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
run_lints!(cx, check_item, it);
Expand Down Expand Up @@ -663,7 +663,7 @@ impl<'a> Visitor<()> for Context<'a> {
}

// Output any lints that were previously added to the session.
impl<'a> IdVisitingOperation for Context<'a> {
impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> {
fn visit_id(&self, id: ast::NodeId) {
match self.tcx.sess.lints.borrow_mut().pop(&id) {
None => {}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ pub type EncodeInlinedItem<'a> = |ecx: &EncodeContext,
rbml_w: &mut Encoder,
ii: InlinedItemRef|: 'a;

pub struct EncodeParams<'a> {
pub struct EncodeParams<'a, 'tcx: 'a> {
pub diag: &'a SpanHandler,
pub tcx: &'a ty::ctxt,
pub tcx: &'a ty::ctxt<'tcx>,
pub reexports2: &'a middle::resolve::ExportMap2,
pub item_symbols: &'a RefCell<NodeMap<String>>,
pub non_inlineable_statics: &'a RefCell<NodeSet>,
Expand All @@ -83,9 +83,9 @@ pub struct EncodeParams<'a> {
pub reachable: &'a NodeSet,
}

pub struct EncodeContext<'a> {
pub struct EncodeContext<'a, 'tcx: 'a> {
pub diag: &'a SpanHandler,
pub tcx: &'a ty::ctxt,
pub tcx: &'a ty::ctxt<'tcx>,
pub reexports2: &'a middle::resolve::ExportMap2,
pub item_symbols: &'a RefCell<NodeMap<String>>,
pub non_inlineable_statics: &'a RefCell<NodeSet>,
Expand Down Expand Up @@ -1793,12 +1793,12 @@ fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &Crate) {



struct ImplVisitor<'a,'b:'a,'c:'a> {
ecx: &'a EncodeContext<'b>,
struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
ecx: &'a EncodeContext<'b, 'tcx>,
rbml_w: &'a mut Encoder<'c>,
}

impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> {
impl<'a, 'b, 'c, 'tcx> Visitor<()> for ImplVisitor<'a, 'b, 'c, 'tcx> {
fn visit_item(&mut self, item: &Item, _: ()) {
match item.node {
ItemImpl(_, Some(ref trait_ref), _, _) => {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ pub enum DefIdSource {
pub type conv_did<'a> =
|source: DefIdSource, ast::DefId|: 'a -> ast::DefId;

pub struct PState<'a> {
pub struct PState<'a, 'tcx: 'a> {
data: &'a [u8],
krate: ast::CrateNum,
pos: uint,
tcx: &'a ty::ctxt
tcx: &'a ty::ctxt<'tcx>
}

fn peek(st: &PState) -> char {
Expand Down Expand Up @@ -105,8 +105,9 @@ fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
})
}

pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum,
pos: uint, tcx: &'a ty::ctxt) -> PState<'a> {
pub fn parse_state_from_data<'a, 'tcx>(data: &'a [u8], crate_num: ast::CrateNum,
pos: uint, tcx: &'a ty::ctxt<'tcx>)
-> PState<'a, 'tcx> {
PState {
data: data,
krate: crate_num,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ use rbml::io::SeekableMemWriter;

macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) )

pub struct ctxt<'a> {
pub struct ctxt<'a, 'tcx: 'a> {
pub diag: &'a SpanHandler,
// Def -> str Callback:
pub ds: fn(DefId) -> String,
// The type context.
pub tcx: &'a ty::ctxt,
pub tcx: &'a ty::ctxt<'tcx>,
pub abbrevs: &'a abbrev_map
}

Expand Down
24 changes: 12 additions & 12 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ use serialize::{EncoderHelpers};
#[cfg(test)] use syntax::print::pprust;
#[cfg(test)] use std::gc::Gc;

struct DecodeContext<'a> {
struct DecodeContext<'a, 'tcx: 'a> {
cdata: &'a cstore::crate_metadata,
tcx: &'a ty::ctxt,
tcx: &'a ty::ctxt<'tcx>,
}

struct ExtendedDecodeContext<'a> {
dcx: &'a DecodeContext<'a>,
struct ExtendedDecodeContext<'a, 'tcx: 'a> {
dcx: &'a DecodeContext<'a, 'tcx>,
from_id_range: ast_util::IdRange,
to_id_range: ast_util::IdRange
}
Expand Down Expand Up @@ -176,7 +176,7 @@ fn reserve_id_range(sess: &Session,
ast_util::IdRange { min: to_id_min, max: to_id_max }
}

impl<'a> ExtendedDecodeContext<'a> {
impl<'a, 'tcx> ExtendedDecodeContext<'a, 'tcx> {
pub fn tr_id(&self, id: ast::NodeId) -> ast::NodeId {
/*!
* Translates an internal id, meaning a node id that is known
Expand Down Expand Up @@ -382,11 +382,11 @@ fn decode_ast(par_doc: rbml::Doc) -> ast::InlinedItem {
Decodable::decode(&mut d).unwrap()
}

struct AstRenumberer<'a> {
xcx: &'a ExtendedDecodeContext<'a>,
struct AstRenumberer<'a, 'tcx: 'a> {
xcx: &'a ExtendedDecodeContext<'a, 'tcx>,
}

impl<'a> ast_map::FoldOps for AstRenumberer<'a> {
impl<'a, 'tcx> ast_map::FoldOps for AstRenumberer<'a, 'tcx> {
fn new_id(&self, id: ast::NodeId) -> ast::NodeId {
if id == ast::DUMMY_NODE_ID {
// Used by ast_map to map the NodeInlinedParent.
Expand Down Expand Up @@ -914,12 +914,12 @@ fn encode_vec_per_param_space<T>(rbml_w: &mut Encoder,
// ______________________________________________________________________
// Encoding and decoding the side tables

trait get_ty_str_ctxt {
fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a>;
trait get_ty_str_ctxt<'tcx> {
fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a, 'tcx>;
}

impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> {
fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a> {
impl<'a, 'tcx> get_ty_str_ctxt<'tcx> for e::EncodeContext<'a, 'tcx> {
fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a, 'tcx> {
tyencode::ctxt {
diag: self.tcx.sess.diagnostic(),
ds: e::def_to_string,
Expand Down
Loading