debugging, misc fixes

This commit is contained in:
Nick Cameron 2016-04-18 10:30:55 +12:00
parent 744be0b5aa
commit 1d5a29cf0e
17 changed files with 260 additions and 162 deletions

View file

@ -43,6 +43,7 @@ use super::Compilation;
use serialize::json;
use std::cell::RefCell;
use std::collections::HashMap;
use std::env;
use std::ffi::{OsString, OsStr};
@ -123,9 +124,9 @@ pub fn compile_input(sess: &Session,
let dep_graph = DepGraph::new(sess.opts.build_dep_graph);
// Collect defintions for def ids.
let defs = time(sess.time_passes(),
"collecting defs",
|| hir_map::collect_definitions(&expanded_crate));
let defs = &RefCell::new(time(sess.time_passes(),
"collecting defs",
|| hir_map::collect_definitions(&expanded_crate)));
time(sess.time_passes(),
"external crate/lib resolution",
@ -133,7 +134,7 @@ pub fn compile_input(sess: &Session,
.read_crates(&dep_graph));
// Lower ast -> hir.
let lcx = LoweringContext::new(sess, Some(&expanded_crate));
let lcx = LoweringContext::new(sess, Some(&expanded_crate), defs);
let hir_forest = &mut time(sess.time_passes(),
"lowering ast -> hir",
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate),

View file

@ -199,14 +199,9 @@ pub fn run_compiler<'a>(args: &[String],
// It is somewhat unfortunate that this is hardwired in - this is forced by
// the fact that pretty_print_input requires the session by value.
let pretty = callbacks.parse_pretty(&sess, &matches);
match pretty {
Some((ppm, opt_uii)) => {
pretty::pretty_print_input(sess, &cstore, cfg, &input, ppm, opt_uii, ofile);
return (Ok(()), None);
}
None => {
// continue
}
if let Some((ppm, opt_uii)) = pretty {
pretty::pretty_print_input(sess, &cstore, cfg, &input, ppm, opt_uii, ofile);
return (Ok(()), None);
}
let plugins = sess.opts.debugging_opts.extra_plugins.clone();

View file

@ -29,6 +29,7 @@ use rustc_borrowck as borrowck;
use rustc_borrowck::graphviz as borrowck_dot;
use rustc_resolve as resolve;
use rustc_metadata::cstore::CStore;
use rustc_metadata::creader::LocalCrateReader;
use rustc_mir::pretty::write_mir_pretty;
use rustc_mir::graphviz::write_mir_graphviz;
@ -43,6 +44,7 @@ use syntax::util::small_vector::SmallVector;
use graphviz as dot;
use std::cell::RefCell;
use std::fs::File;
use std::io::{self, Write};
use std::iter;
@ -719,7 +721,7 @@ pub fn pretty_print_input(sess: Session,
let is_expanded = needs_expansion(&ppm);
let compute_ast_map = needs_ast_map(&ppm, &opt_uii);
let krate = if compute_ast_map {
match driver::phase_2_configure_and_expand(&sess, &cstore, krate, &id[..], None) {
match driver::phase_2_configure_and_expand(&sess, &cstore, krate, &id, None) {
Err(_) => return,
Ok(k) => driver::assign_node_ids(&sess, k),
}
@ -730,15 +732,18 @@ pub fn pretty_print_input(sess: Session,
// There is some twisted, god-forsaken tangle of lifetimes here which makes
// the ordering of stuff super-finicky.
let mut hir_forest;
let lcx = LoweringContext::new(&sess, Some(&krate));
let arenas = ty::CtxtArenas::new();
let mut _defs = None;
let dep_graph = DepGraph::new(false);
let arenas = ty::CtxtArenas::new();
let _ignore = dep_graph.in_ignore();
let ast_map = if compute_ast_map {
let defs = hir_map::collect_definitions(&krate);
_defs = Some(RefCell::new(hir_map::collect_definitions(&krate)));
let defs = _defs.as_ref().unwrap();
LocalCrateReader::new(&sess, &cstore, defs, &krate, &id).read_crates(&dep_graph);
let lcx = LoweringContext::new(&sess, Some(&krate), defs);
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
let map = hir_map::map_crate(&mut hir_forest, defs);
Some(map)
Some(hir_map::map_crate(&mut hir_forest, defs))
} else {
None
};
@ -751,7 +756,7 @@ pub fn pretty_print_input(sess: Session,
.unwrap()
.as_bytes()
.to_vec();
let mut rdr = &src[..];
let mut rdr = &*src;
let mut out = Vec::new();

View file

@ -27,8 +27,10 @@ use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc::ty::relate::TypeRelation;
use rustc::infer::{self, InferOk, InferResult, TypeOrigin};
use rustc_metadata::cstore::CStore;
use rustc_metadata::creader::LocalCrateReader;
use rustc::hir::map as hir_map;
use rustc::session::{self, config};
use std::cell::RefCell;
use std::rc::Rc;
use syntax::ast;
use syntax::abi::Abi;
@ -119,13 +121,15 @@ fn test_env<F>(source_string: &str,
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, "test", None)
.expect("phase 2 aborted");
let krate = driver::assign_node_ids(&sess, krate);
let lcx = LoweringContext::new(&sess, Some(&krate));
let dep_graph = DepGraph::new(false);
let krate = driver::assign_node_ids(&sess, krate);
let defs = &RefCell::new(hir_map::collect_definitions(&krate));
LocalCrateReader::new(&sess, &cstore, defs, &krate, "test_crate").read_crates(&dep_graph);
let lcx = LoweringContext::new(&sess, Some(&krate), defs);
let _ignore = dep_graph.in_ignore();
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
let mut hir_forest = &mut hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
let arenas = ty::CtxtArenas::new();
let ast_map = driver::make_map(&sess, &mut hir_forest);
let ast_map = hir_map::map_crate(hir_forest, defs);
// run just enough stuff to build a tcx:
let lang_items = lang_items::collect_language_items(&sess, &ast_map);