librustc: drop AST before running LLVM, frees 400mb on a librustc build
This commit is contained in:
parent
6264df5331
commit
b4a3fe25c6
4 changed files with 75 additions and 71 deletions
|
@ -172,15 +172,21 @@ pub enum compile_upto {
|
|||
|
||||
// For continuing compilation after a parsed crate has been
|
||||
// modified
|
||||
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn compile_rest(sess: Session,
|
||||
cfg: ast::crate_cfg,
|
||||
upto: compile_upto,
|
||||
outputs: Option<@OutputFilenames>,
|
||||
curr: Option<@ast::crate>)
|
||||
-> (@ast::crate, Option<ty::ctxt>) {
|
||||
-> (Option<@ast::crate>, Option<ty::ctxt>) {
|
||||
|
||||
let time_passes = sess.time_passes();
|
||||
let mut crate = curr.get();
|
||||
|
||||
let (llmod, link_meta) = {
|
||||
|
||||
let mut crate = curr.unwrap();
|
||||
|
||||
*sess.building_library = session::building_library(
|
||||
sess.opts.crate_type, crate, sess.opts.test);
|
||||
|
@ -195,7 +201,7 @@ pub fn compile_rest(sess: Session,
|
|||
crate = time(time_passes, ~"maybe building test harness", ||
|
||||
front::test::modify_for_testing(sess, crate));
|
||||
|
||||
if upto == cu_expand { return (crate, None); }
|
||||
if upto == cu_expand { return (Some(crate), None); }
|
||||
|
||||
crate = time(time_passes, ~"intrinsic injection", ||
|
||||
front::intrinsic_inject::inject_intrinsic(sess, crate));
|
||||
|
@ -236,10 +242,6 @@ pub fn compile_rest(sess: Session,
|
|||
let rp_set = time(time_passes, ~"region parameterization inference", ||
|
||||
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
|
||||
|
||||
let outputs = outputs.get();
|
||||
|
||||
let (llmod, link_meta) = {
|
||||
|
||||
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
|
||||
region_map, rp_set, lang_items);
|
||||
|
||||
|
@ -255,7 +257,7 @@ pub fn compile_rest(sess: Session,
|
|||
middle::check_const::check_crate(sess, crate, ast_map, def_map,
|
||||
method_map, ty_cx));
|
||||
|
||||
if upto == cu_typeck { return (crate, Some(ty_cx)); }
|
||||
if upto == cu_typeck { return (Some(crate), Some(ty_cx)); }
|
||||
|
||||
time(time_passes, ~"privacy checking", ||
|
||||
middle::privacy::check_crate(ty_cx, &method_map, crate));
|
||||
|
@ -289,7 +291,7 @@ pub fn compile_rest(sess: Session,
|
|||
time(time_passes, ~"lint checking", ||
|
||||
lint::check_crate(ty_cx, crate));
|
||||
|
||||
if upto == cu_no_trans { return (crate, Some(ty_cx)); }
|
||||
if upto == cu_no_trans { return (Some(crate), Some(ty_cx)); }
|
||||
|
||||
let maps = astencode::Maps {
|
||||
root_map: root_map,
|
||||
|
@ -300,13 +302,14 @@ pub fn compile_rest(sess: Session,
|
|||
capture_map: capture_map
|
||||
};
|
||||
|
||||
let outputs = outputs.get_ref();
|
||||
time(time_passes, ~"translation", ||
|
||||
trans::base::trans_crate(sess, crate, ty_cx,
|
||||
&outputs.obj_filename,
|
||||
exp_map2, maps))
|
||||
|
||||
};
|
||||
|
||||
let outputs = outputs.get_ref();
|
||||
if (sess.opts.debugging_opts & session::print_link_args) != 0 {
|
||||
io::println(str::connect(link::link_args(sess,
|
||||
&outputs.obj_filename, &outputs.out_filename, link_meta), " "));
|
||||
|
@ -335,24 +338,24 @@ pub fn compile_rest(sess: Session,
|
|||
(sess.opts.is_static && *sess.building_library) ||
|
||||
sess.opts.jit;
|
||||
|
||||
if stop_after_codegen { return (crate, None); }
|
||||
if stop_after_codegen { return (None, None); }
|
||||
|
||||
time(time_passes, ~"linking", ||
|
||||
link::link_binary(sess,
|
||||
&outputs.obj_filename,
|
||||
&outputs.out_filename, link_meta));
|
||||
|
||||
return (crate, None);
|
||||
return (None, None);
|
||||
}
|
||||
|
||||
pub fn compile_upto(sess: Session, cfg: ast::crate_cfg,
|
||||
input: &input, upto: compile_upto,
|
||||
outputs: Option<@OutputFilenames>)
|
||||
-> (@ast::crate, Option<ty::ctxt>) {
|
||||
-> (Option<@ast::crate>, Option<ty::ctxt>) {
|
||||
let time_passes = sess.time_passes();
|
||||
let crate = time(time_passes, ~"parsing",
|
||||
|| parse_input(sess, copy cfg, input) );
|
||||
if upto == cu_parse { return (crate, None); }
|
||||
if upto == cu_parse { return (Some(crate), None); }
|
||||
|
||||
compile_rest(sess, cfg, upto, outputs, Some(crate))
|
||||
}
|
||||
|
@ -437,7 +440,7 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
|
|||
let src = sess.codemap.get_filemap(source_name(input)).src;
|
||||
do io::with_str_reader(*src) |rdr| {
|
||||
pprust::print_crate(sess.codemap, sess.parse_sess.interner,
|
||||
sess.span_diagnostic, crate,
|
||||
sess.span_diagnostic, crate.unwrap(),
|
||||
source_name(input),
|
||||
rdr, io::stdout(), ann, is_expanded);
|
||||
}
|
||||
|
|
|
@ -144,9 +144,10 @@ fn run(repl: Repl, input: ~str) -> Repl {
|
|||
|
||||
let outputs = driver::build_output_filenames(&wrapped, &None, &None, sess);
|
||||
debug!("calling compile_upto");
|
||||
let (crate, _) = driver::compile_upto(sess, cfg, &wrapped,
|
||||
driver::cu_everything,
|
||||
Some(outputs));
|
||||
|
||||
let crate = driver::parse_input(sess, copy cfg, &wrapped);
|
||||
driver::compile_rest(sess, cfg, driver::cu_everything,
|
||||
Some(outputs), Some(crate));
|
||||
|
||||
let mut opt = None;
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ impl<'self> PkgScript<'self> {
|
|||
input: input,
|
||||
sess: sess,
|
||||
cfg: cfg,
|
||||
crate: crate,
|
||||
crate: crate.unwrap(),
|
||||
build_dir: work_dir
|
||||
}
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ pub fn compile_crate_from_input(input: &driver::input,
|
|||
debug!("Calling compile_upto, outputs = %?", outputs);
|
||||
let (crate, _) = driver::compile_upto(sess, copy cfg, input,
|
||||
driver::cu_parse, Some(outputs));
|
||||
let mut crate = crate;
|
||||
let mut crate = crate.unwrap();
|
||||
|
||||
debug!("About to inject link_meta info...");
|
||||
// Inject the inferred link_meta info if it's not already there
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue