Skip to content

Commit

Permalink
auto merge of #6793 : graydon/rust/drop-ast-before-llvm, r=Aatch
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed May 29, 2013
2 parents 149960e + b4a3fe2 commit e3e55c5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 56 deletions.
105 changes: 54 additions & 51 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,73 +172,75 @@ 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();

*sess.building_library = session::building_library(
sess.opts.crate_type, crate, sess.opts.test);
let (llmod, link_meta) = {

crate = time(time_passes, ~"expansion", ||
syntax::ext::expand::expand_crate(sess.parse_sess, copy cfg,
crate));
let mut crate = curr.unwrap();

crate = time(time_passes, ~"configuration", ||
front::config::strip_unconfigured_items(crate));
*sess.building_library = session::building_library(
sess.opts.crate_type, crate, sess.opts.test);

crate = time(time_passes, ~"maybe building test harness", ||
front::test::modify_for_testing(sess, crate));
crate = time(time_passes, ~"expansion", ||
syntax::ext::expand::expand_crate(sess.parse_sess, copy cfg,
crate));

if upto == cu_expand { return (crate, None); }
crate = time(time_passes, ~"configuration", ||
front::config::strip_unconfigured_items(crate));

crate = time(time_passes, ~"intrinsic injection", ||
front::intrinsic_inject::inject_intrinsic(sess, crate));
crate = time(time_passes, ~"maybe building test harness", ||
front::test::modify_for_testing(sess, crate));

crate = time(time_passes, ~"extra injection", ||
front::std_inject::maybe_inject_libstd_ref(sess, crate));
if upto == cu_expand { return (Some(crate), None); }

let ast_map = time(time_passes, ~"ast indexing", ||
syntax::ast_map::map_crate(sess.diagnostic(), crate));
crate = time(time_passes, ~"intrinsic injection", ||
front::intrinsic_inject::inject_intrinsic(sess, crate));

time(time_passes, ~"external crate/lib resolution", ||
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
sess.filesearch,
session::sess_os_to_meta_os(sess.targ_cfg.os),
sess.opts.is_static,
sess.parse_sess.interner));
crate = time(time_passes, ~"extra injection", ||
front::std_inject::maybe_inject_libstd_ref(sess, crate));

let lang_items = time(time_passes, ~"language item collection", ||
middle::lang_items::collect_language_items(crate, sess));
let ast_map = time(time_passes, ~"ast indexing", ||
syntax::ast_map::map_crate(sess.diagnostic(), crate));

let middle::resolve::CrateMap {
def_map: def_map,
exp_map2: exp_map2,
trait_map: trait_map
} =
time(time_passes, ~"resolution", ||
middle::resolve::resolve_crate(sess, lang_items, crate));
time(time_passes, ~"external crate/lib resolution", ||
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
sess.filesearch,
session::sess_os_to_meta_os(sess.targ_cfg.os),
sess.opts.is_static,
sess.parse_sess.interner));

time(time_passes, ~"looking for entry point",
|| middle::entry::find_entry_point(sess, crate, ast_map));
let lang_items = time(time_passes, ~"language item collection", ||
middle::lang_items::collect_language_items(crate, sess));

let freevars = time(time_passes, ~"freevar finding", ||
freevars::annotate_freevars(def_map, crate));
let middle::resolve::CrateMap {
def_map: def_map,
exp_map2: exp_map2,
trait_map: trait_map
} =
time(time_passes, ~"resolution", ||
middle::resolve::resolve_crate(sess, lang_items, crate));

let region_map = time(time_passes, ~"region resolution", ||
middle::region::resolve_crate(sess, def_map, crate));
time(time_passes, ~"looking for entry point",
|| middle::entry::find_entry_point(sess, crate, ast_map));

let rp_set = time(time_passes, ~"region parameterization inference", ||
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
let freevars = time(time_passes, ~"freevar finding", ||
freevars::annotate_freevars(def_map, crate));

let outputs = outputs.get();
let region_map = time(time_passes, ~"region resolution", ||
middle::region::resolve_crate(sess, def_map, crate));

let (llmod, link_meta) = {
let rp_set = time(time_passes, ~"region parameterization inference", ||
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));

let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
region_map, rp_set, lang_items);
Expand All @@ -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));
Expand Down Expand Up @@ -288,7 +290,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,
Expand All @@ -299,13 +301,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), " "));
Expand Down Expand Up @@ -334,24 +337,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))
}
Expand Down Expand Up @@ -436,7 +439,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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/librusti/rusti.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'self> PkgScript<'self> {
input: input,
sess: sess,
cfg: cfg,
crate: crate,
crate: crate.unwrap(),
build_dir: work_dir
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3e55c5

Please sign in to comment.