rustc: remove ownership of tcx from trans' context.

This commit is contained in:
Eduard Burtescu 2015-06-14 01:49:28 +03:00
parent ff8fee180b
commit 2e997ef2d4
10 changed files with 161 additions and 196 deletions

View file

@ -119,26 +119,26 @@ pub fn compile_input(sess: Session,
&ast_map.krate(),
&id[..]));
let analysis = phase_3_run_analysis_passes(sess,
ast_map,
&arenas,
id,
control.make_glob_map);
let (tcx, analysis) = phase_3_run_analysis_passes(sess,
ast_map,
&arenas,
id,
control.make_glob_map);
controller_entry_point!(after_analysis,
analysis.ty_cx.sess,
tcx.sess,
CompileState::state_after_analysis(input,
&analysis.ty_cx.sess,
&tcx.sess,
outdir,
analysis.ty_cx.map.krate(),
tcx.map.krate(),
&analysis,
&analysis.ty_cx));
&tcx));
if log_enabled!(::log::INFO) {
println!("Pre-trans");
analysis.ty_cx.print_debug_stats();
tcx.print_debug_stats();
}
let (tcx, trans) = phase_4_translate_to_llvm(analysis);
let trans = phase_4_translate_to_llvm(&tcx, analysis);
if log_enabled!(::log::INFO) {
println!("Post-trans");
@ -240,7 +240,7 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
pub out_dir: Option<&'a Path>,
pub expanded_crate: Option<&'a ast::Crate>,
pub ast_map: Option<&'a ast_map::Map<'ast>>,
pub analysis: Option<&'a ty::CrateAnalysis<'tcx>>,
pub analysis: Option<&'a ty::CrateAnalysis>,
pub tcx: Option<&'a ty::ctxt<'tcx>>,
pub trans: Option<&'a trans::CrateTranslation>,
}
@ -309,7 +309,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
session: &'a Session,
out_dir: &'a Option<PathBuf>,
expanded_crate: &'a ast::Crate,
analysis: &'a ty::CrateAnalysis<'tcx>,
analysis: &'a ty::CrateAnalysis,
tcx: &'a ty::ctxt<'tcx>)
-> CompileState<'a, 'ast, 'tcx> {
CompileState {
@ -583,7 +583,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
arenas: &'tcx ty::CtxtArenas<'tcx>,
name: String,
make_glob_map: resolve::MakeGlobMap)
-> ty::CrateAnalysis<'tcx> {
-> (ty::ctxt<'tcx>, ty::CrateAnalysis) {
let time_passes = sess.time_passes();
let krate = ast_map.krate();
@ -704,29 +704,28 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
// The above three passes generate errors w/o aborting
ty_cx.sess.abort_if_errors();
ty::CrateAnalysis {
(ty_cx, ty::CrateAnalysis {
export_map: export_map,
ty_cx: ty_cx,
exported_items: exported_items,
public_items: public_items,
reachable: reachable_map,
name: name,
glob_map: glob_map,
}
})
}
/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
pub fn phase_4_translate_to_llvm<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
-> (ty::ctxt<'tcx>, trans::CrateTranslation) {
let time_passes = analysis.ty_cx.sess.time_passes();
pub fn phase_4_translate_to_llvm(tcx: &ty::ctxt, analysis: ty::CrateAnalysis)
-> trans::CrateTranslation {
let time_passes = tcx.sess.time_passes();
time(time_passes, "resolving dependency formats", (), |_|
dependency_format::calculate(&analysis.ty_cx));
dependency_format::calculate(tcx));
// Option dance to work around the lack of stack once closures.
time(time_passes, "translation", analysis, |analysis|
trans::trans_crate(analysis))
trans::trans_crate(tcx, analysis))
}
/// Run LLVM itself, producing a bitcode file, assembly file or object file

View file

@ -377,12 +377,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
if sess.opts.debugging_opts.save_analysis {
control.after_analysis.callback = box |state| {
time(state.session.time_passes(),
"save analysis",
state.expanded_crate.unwrap(),
|krate| save::process_crate(state.session,
krate,
state.analysis.unwrap(),
state.out_dir));
"save analysis", (),
|_| save::process_crate(state.tcx.unwrap(),
state.analysis.unwrap(),
state.out_dir));
};
control.make_glob_map = resolve::MakeGlobMap::Yes;
}

View file

@ -148,12 +148,12 @@ impl PpSourceMode {
}
PpmTyped => {
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
let analysis = driver::phase_3_run_analysis_passes(sess,
let (tcx, _) = driver::phase_3_run_analysis_passes(sess,
ast_map,
arenas,
id,
resolve::MakeGlobMap::No);
let annotation = TypedAnnotation { analysis: analysis };
let annotation = TypedAnnotation { tcx: tcx };
f(&annotation, payload)
}
}
@ -285,14 +285,14 @@ impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> {
struct TypedAnnotation<'tcx> {
analysis: ty::CrateAnalysis<'tcx>,
tcx: ty::ctxt<'tcx>,
}
impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> {
fn sess<'a>(&'a self) -> &'a Session { &self.analysis.ty_cx.sess }
fn sess<'a>(&'a self) -> &'a Session { &self.tcx.sess }
fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'tcx>> {
Some(&self.analysis.ty_cx.map)
Some(&self.tcx.map)
}
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self }
@ -310,7 +310,6 @@ impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> {
fn post(&self,
s: &mut pprust::State,
node: pprust::AnnNode) -> io::Result<()> {
let tcx = &self.analysis.ty_cx;
match node {
pprust::NodeExpr(expr) => {
try!(pp::space(&mut s.s));
@ -318,8 +317,8 @@ impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> {
try!(pp::space(&mut s.s));
try!(pp::word(&mut s.s,
&ppaux::ty_to_string(
tcx,
ty::expr_ty(tcx, expr))));
&self.tcx,
ty::expr_ty(&self.tcx, expr))));
s.pclose()
}
_ => Ok(())
@ -646,12 +645,12 @@ 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,
let (tcx, _) = driver::phase_3_run_analysis_passes(sess,
ast_map,
&arenas,
id,
resolve::MakeGlobMap::No);
print_flowgraph(variants, analysis, code, mode, out)
print_flowgraph(variants, &tcx, code, mode, out)
}
None => {
let message = format!("--pretty=flowgraph needs \
@ -682,18 +681,17 @@ pub fn pretty_print_input(sess: Session,
}
fn print_flowgraph<W: Write>(variants: Vec<borrowck_dot::Variant>,
analysis: ty::CrateAnalysis,
tcx: &ty::ctxt,
code: blocks::Code,
mode: PpFlowGraphMode,
mut out: W) -> io::Result<()> {
let ty_cx = &analysis.ty_cx;
let cfg = match code {
blocks::BlockCode(block) => cfg::CFG::new(ty_cx, &*block),
blocks::FnLikeCode(fn_like) => cfg::CFG::new(ty_cx, &*fn_like.body()),
blocks::BlockCode(block) => cfg::CFG::new(tcx, &*block),
blocks::FnLikeCode(fn_like) => cfg::CFG::new(tcx, &*fn_like.body()),
};
let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges;
let lcfg = LabelledCFG {
ast_map: &ty_cx.map,
ast_map: &tcx.map,
cfg: &cfg,
name: format!("node_{}", code.id()),
labelled_edges: labelled_edges,
@ -705,14 +703,14 @@ fn print_flowgraph<W: Write>(variants: Vec<borrowck_dot::Variant>,
return expand_err_details(r);
}
blocks::BlockCode(_) => {
ty_cx.sess.err("--pretty flowgraph with -Z flowgraph-print \
annotations requires fn-like node id.");
tcx.sess.err("--pretty flowgraph with -Z flowgraph-print \
annotations requires fn-like node id.");
return Ok(())
}
blocks::FnLikeCode(fn_like) => {
let fn_parts = borrowck::FnPartsWithCFG::from_fn_like(&fn_like, &cfg);
let (bccx, analysis_data) =
borrowck::build_borrowck_dataflow_data_for_fn(ty_cx, fn_parts);
borrowck::build_borrowck_dataflow_data_for_fn(tcx, fn_parts);
let lcfg = borrowck_dot::DataflowLabeller {
inner: lcfg,