Skip to content

Commit

Permalink
rustc: fix fallout from using ptr::P.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 14, 2014
1 parent d379ad1 commit b062128
Show file tree
Hide file tree
Showing 64 changed files with 1,956 additions and 2,070 deletions.
94 changes: 57 additions & 37 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::io::fs;
use std::os;
use arena::TypedArena;
use syntax::ast;
use syntax::ast_map;
use syntax::attr;
use syntax::attr::{AttrMetaMethods};
use syntax::diagnostics;
Expand Down Expand Up @@ -65,7 +66,7 @@ pub fn compile_input(sess: Session,
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
let (outputs, trans, sess) = {
let (outputs, expanded_crate, ast_map, id) = {
let (outputs, expanded_crate, id) = {
let krate = phase_1_parse_input(&sess, cfg, input);
if stop_after_phase_1(&sess) { return; }
let outputs = build_output_filenames(input,
Expand All @@ -75,25 +76,28 @@ pub fn compile_input(sess: Session,
&sess);
let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
input);
let (expanded_crate, ast_map)
let expanded_crate
= match phase_2_configure_and_expand(&sess, krate, id.as_slice(),
addl_plugins) {
None => return,
Some(p) => p,
Some(k) => k
};

(outputs, expanded_crate, ast_map, id)
(outputs, expanded_crate, id)
};

let mut forest = ast_map::Forest::new(expanded_crate);
let ast_map = assign_node_ids_and_map(&sess, &mut forest);

write_out_deps(&sess, input, &outputs, id.as_slice());

if stop_after_phase_2(&sess) { return; }

let type_arena = TypedArena::new();
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate,
ast_map, &type_arena, id);
phase_save_analysis(&analysis.ty_cx.sess, &expanded_crate, &analysis, outdir);
let analysis = phase_3_run_analysis_passes(sess, ast_map, &type_arena, id);
phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir);
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate, analysis);
let (tcx, trans) = phase_4_translate_to_llvm(analysis);

// Discard interned strings as they are no longer required.
token::get_ident_interner().clear();
Expand Down Expand Up @@ -182,7 +186,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
mut krate: ast::Crate,
crate_name: &str,
addl_plugins: Option<Plugins>)
-> Option<(ast::Crate, syntax::ast_map::Map)> {
-> Option<ast::Crate> {
let time_passes = sess.time_passes();

*sess.crate_types.borrow_mut() =
Expand Down Expand Up @@ -294,20 +298,37 @@ pub fn phase_2_configure_and_expand(sess: &Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

let (krate, map) = time(time_passes, "assigning node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));

Some(krate)
}

pub fn assign_node_ids_and_map<'ast>(sess: &Session,
forest: &'ast mut ast_map::Forest)
-> ast_map::Map<'ast> {
struct NodeIdAssigner<'a> {
sess: &'a Session
}

impl<'a> ast_map::FoldOps for NodeIdAssigner<'a> {
fn new_id(&self, old_id: ast::NodeId) -> ast::NodeId {
assert_eq!(old_id, ast::DUMMY_NODE_ID);
self.sess.next_node_id()
}
}

let map = time(sess.time_passes(), "assigning node ids and indexing ast", forest, |forest|
ast_map::map_crate(forest, NodeIdAssigner { sess: sess }));

if sess.opts.debugging_opts & config::AST_JSON != 0 {
let mut stdout = io::BufferedWriter::new(io::stdout());
let mut json = json::PrettyEncoder::new(&mut stdout);
// unwrapping so IoError isn't ignored
krate.encode(&mut json).unwrap();
map.krate().encode(&mut json).unwrap();
}

time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));

Some((krate, map))
map
}

pub struct CrateAnalysis<'tcx> {
Expand All @@ -324,11 +345,11 @@ pub struct CrateAnalysis<'tcx> {
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
krate: &ast::Crate,
ast_map: syntax::ast_map::Map,
ast_map: ast_map::Map<'tcx>,
type_arena: &'tcx TypedArena<ty::t_box_>,
name: String) -> CrateAnalysis<'tcx> {
let time_passes = sess.time_passes();
let krate = ast_map.krate();

time(time_passes, "external crate/lib resolution", (), |_|
creader::read_crates(&sess, krate));
Expand All @@ -353,7 +374,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
|_| middle::resolve_lifetime::krate(&sess, krate));

time(time_passes, "looking for entry point", (),
|_| middle::entry::find_entry_point(&sess, krate, &ast_map));
|_| middle::entry::find_entry_point(&sess, &ast_map));

sess.plugin_registrar_fn.set(
time(time_passes, "looking for plugin registrar", (), |_|
Expand Down Expand Up @@ -385,43 +406,43 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
stability_index);

// passes are timed inside typeck
typeck::check_crate(&ty_cx, trait_map, krate);
typeck::check_crate(&ty_cx, trait_map);

time(time_passes, "check static items", (), |_|
middle::check_static::check_crate(&ty_cx, krate));
middle::check_static::check_crate(&ty_cx));

// These next two const passes can probably be merged
time(time_passes, "const marking", (), |_|
middle::const_eval::process_crate(krate, &ty_cx));
middle::const_eval::process_crate(&ty_cx));

time(time_passes, "const checking", (), |_|
middle::check_const::check_crate(krate, &ty_cx));
middle::check_const::check_crate(&ty_cx));

let maps = (external_exports, last_private_map);
let (exported_items, public_items) =
time(time_passes, "privacy checking", maps, |(a, b)|
middle::privacy::check_crate(&ty_cx, &exp_map2, a, b, krate));
middle::privacy::check_crate(&ty_cx, &exp_map2, a, b));

time(time_passes, "intrinsic checking", (), |_|
middle::intrinsicck::check_crate(&ty_cx, krate));
middle::intrinsicck::check_crate(&ty_cx));

time(time_passes, "effect checking", (), |_|
middle::effect::check_crate(&ty_cx, krate));
middle::effect::check_crate(&ty_cx));

time(time_passes, "match checking", (), |_|
middle::check_match::check_crate(&ty_cx, krate));
middle::check_match::check_crate(&ty_cx));

time(time_passes, "liveness checking", (), |_|
middle::liveness::check_crate(&ty_cx, krate));
middle::liveness::check_crate(&ty_cx));

time(time_passes, "borrow checking", (), |_|
middle::borrowck::check_crate(&ty_cx, krate));
middle::borrowck::check_crate(&ty_cx));

time(time_passes, "rvalue checking", (), |_|
middle::check_rvalues::check_crate(&ty_cx, krate));

time(time_passes, "kind checking", (), |_|
kind::check_crate(&ty_cx, krate));
kind::check_crate(&ty_cx));

let reachable_map =
time(time_passes, "reachability checking", (), |_|
Expand All @@ -430,12 +451,11 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
time(time_passes, "death checking", (), |_| {
middle::dead::check_crate(&ty_cx,
&exported_items,
&reachable_map,
krate)
&reachable_map)
});

time(time_passes, "lint checking", (), |_|
lint::check_crate(&ty_cx, krate, &exported_items));
lint::check_crate(&ty_cx, &exported_items));

CrateAnalysis {
exp_map2: exp_map2,
Expand Down Expand Up @@ -475,16 +495,16 @@ pub struct CrateTranslation {

/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
pub fn phase_4_translate_to_llvm(krate: ast::Crate,
analysis: CrateAnalysis) -> (ty::ctxt, CrateTranslation) {
pub fn phase_4_translate_to_llvm<'tcx>(analysis: CrateAnalysis<'tcx>)
-> (ty::ctxt<'tcx>, CrateTranslation) {
let time_passes = analysis.ty_cx.sess.time_passes();

time(time_passes, "resolving dependency formats", (), |_|
dependency_format::calculate(&analysis.ty_cx));

// Option dance to work around the lack of stack once closures.
time(time_passes, "translation", (krate, analysis), |(krate, analysis)|
trans::base::trans_crate(krate, analysis))
time(time_passes, "translation", analysis, |analysis|
trans::base::trans_crate(analysis))
}

/// Run LLVM itself, producing a bitcode file, assembly file or object file
Expand Down
Loading

0 comments on commit b062128

Please sign in to comment.