Misc fixups

This commit is contained in:
Nick Cameron 2015-10-06 15:31:43 +13:00
parent 3d81f78544
commit 2b4f28e531
9 changed files with 54 additions and 26 deletions

View File

@ -54,8 +54,9 @@ use serialize::EncoderHelpers;
#[cfg(test)] use std::io::Cursor;
#[cfg(test)] use syntax::parse;
#[cfg(test)] use syntax::ast::NodeId;
#[cfg(test)] use rustc_front::print::pprust;
#[cfg(test)] use rustc_front::lowering::lower_item;
#[cfg(test)] use rustc_front::lowering::{lower_item, LoweringContext};
struct DecodeContext<'a, 'b, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
@ -1374,6 +1375,22 @@ impl FakeExtCtxt for parse::ParseSess {
fn parse_sess(&self) -> &parse::ParseSess { self }
}
#[cfg(test)]
struct FakeNodeIdAssigner;
#[cfg(test)]
// It should go without sayingt that this may give unexpected results. Avoid
// lowering anything which needs new nodes.
impl NodeIdAssigner for FakeNodeIdAssigner {
fn next_node_id(&self) -> NodeId {
0
}
fn peek_node_id(&self) -> NodeId {
0
}
}
#[cfg(test)]
fn mk_ctxt() -> parse::ParseSess {
parse::ParseSess::new()
@ -1392,7 +1409,9 @@ fn roundtrip(in_item: P<hir::Item>) {
#[test]
fn test_basic() {
let cx = mk_ctxt();
roundtrip(lower_item(&quote_item!(&cx,
let fnia = FakeNodeIdAssigner;
let lcx = LoweringContext::new(&fnia, None);
roundtrip(lower_item(&lcx, &quote_item!(&cx,
fn foo() {}
).unwrap()));
}
@ -1400,7 +1419,9 @@ fn test_basic() {
#[test]
fn test_smalltalk() {
let cx = mk_ctxt();
roundtrip(lower_item(&quote_item!(&cx,
let fnia = FakeNodeIdAssigner;
let lcx = LoweringContext::new(&fnia, None);
roundtrip(lower_item(&lcx, &quote_item!(&cx,
fn foo() -> isize { 3 + 4 } // first smalltalk program ever executed.
).unwrap()));
}
@ -1408,7 +1429,9 @@ fn test_smalltalk() {
#[test]
fn test_more() {
let cx = mk_ctxt();
roundtrip(lower_item(&quote_item!(&cx,
let fnia = FakeNodeIdAssigner;
let lcx = LoweringContext::new(&fnia, None);
roundtrip(lower_item(&lcx, &quote_item!(&cx,
fn foo(x: usize, y: usize) -> usize {
let z = x + y;
return z;
@ -1425,10 +1448,12 @@ fn test_simplification() {
return alist {eq_fn: eq_int, data: Vec::new()};
}
).unwrap();
let hir_item = lower_item(&item);
let fnia = FakeNodeIdAssigner;
let lcx = LoweringContext::new(&fnia, None);
let hir_item = lower_item(&lcx, &item);
let item_in = InlinedItemRef::Item(&hir_item);
let item_out = simplify_ast(item_in);
let item_exp = InlinedItem::Item(lower_item(&quote_item!(&cx,
let item_exp = InlinedItem::Item(lower_item(&lcx, &quote_item!(&cx,
fn new_int_alist<B>() -> alist<isize, B> {
return alist {eq_fn: eq_int, data: Vec::new()};
}

View File

@ -112,7 +112,7 @@ pub fn compile_input(sess: Session,
let expanded_crate = assign_node_ids(&sess, expanded_crate);
// Lower ast -> hir.
let lcx = LoweringContext::new(&sess, &expanded_crate);
let lcx = LoweringContext::new(&sess, Some(&expanded_crate));
let mut hir_forest = time(sess.time_passes(),
"lowering ast -> hir",
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));

View File

@ -670,7 +670,7 @@ 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, &krate);
let lcx = LoweringContext::new(&sess, Some(&krate));
let arenas = ty::CtxtArenas::new();
let ast_map = if compute_ast_map {
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));

View File

@ -38,7 +38,7 @@ use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note, He
use syntax::parse::token;
use syntax::feature_gate::UnstableFeatures;
use rustc_front::lowering::lower_crate;
use rustc_front::lowering::{lower_crate, LoweringContext};
use rustc_front::hir;
struct Env<'a, 'tcx: 'a> {
@ -124,7 +124,8 @@ fn test_env<F>(source_string: &str,
.expect("phase 2 aborted");
let krate = driver::assign_node_ids(&sess, krate);
let mut hir_forest = hir_map::Forest::new(lower_crate(&krate));
let lcx = LoweringContext::new(&sess, Some(&krate));
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
let arenas = ty::CtxtArenas::new();
let ast_map = driver::make_map(&sess, &mut hir_forest);
let krate = ast_map.krate();
@ -135,7 +136,7 @@ fn test_env<F>(source_string: &str,
resolve::resolve_crate(&sess, &ast_map, resolve::MakeGlobMap::No);
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
let region_map = region::resolve_crate(&sess, krate);
ty::ctxt::create_and_enter(sess,
ty::ctxt::create_and_enter(&sess,
&arenas,
def_map,
named_region_map,

View File

@ -80,14 +80,16 @@ pub struct LoweringContext<'a> {
}
impl<'a, 'hir> LoweringContext<'a> {
pub fn new(id_assigner: &'a NodeIdAssigner, c: &Crate) -> LoweringContext<'a> {
let crate_root = if std_inject::no_core(c) {
None
} else if std_inject::no_std(c) {
Some("core")
} else {
Some("std")
};
pub fn new(id_assigner: &'a NodeIdAssigner, c: Option<&Crate>) -> LoweringContext<'a> {
let crate_root = c.and_then(|c| {
if std_inject::no_core(c) {
None
} else if std_inject::no_std(c) {
Some("core")
} else {
Some("std")
}
});
LoweringContext {
crate_root: crate_root,

View File

@ -38,7 +38,6 @@ use std::cell::RefCell;
use std::rc::Rc;
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::ast::NodeIdAssigner;
use util::nodemap::{DefIdMap, FnvHashMap};
use rustc::front::map as hir_map;
use rustc::front::map::NodeItem;

View File

@ -135,7 +135,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
let krate = driver::assign_node_ids(&sess, krate);
// Lower ast -> hir.
let lcx = LoweringContext::new(&sess, &krate);
let lcx = LoweringContext::new(&sess, Some(&krate));
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
let arenas = ty::CtxtArenas::new();
let hir_map = driver::make_map(&sess, &mut hir_forest);

View File

@ -83,7 +83,7 @@ pub fn run(input: &str,
"rustdoc-test", None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
let krate = driver::assign_node_ids(&sess, krate);
let lcx = LoweringContext::new(&sess, &krate);
let lcx = LoweringContext::new(&sess, Some(&krate));
let krate = lower_crate(&lcx, &krate);
let opts = scrape_test_config(&krate);

View File

@ -31,7 +31,7 @@ use rustc::middle::ty;
use rustc::session::config::{self, basic_options, build_configuration, Input, Options};
use rustc::session::build_session;
use rustc_driver::driver;
use rustc_front::lowering::lower_crate;
use rustc_front::lowering::{lower_crate, LoweringContext};
use rustc_resolve::MakeGlobMap;
use libc::c_void;
@ -223,12 +223,13 @@ fn compile_program(input: &str, sysroot: PathBuf)
.expect("phase_2 returned `None`");
let krate = driver::assign_node_ids(&sess, krate);
let mut hir_forest = ast_map::Forest::new(lower_crate(&krate));
let lcx = LoweringContext::new(&sess, Some(&krate));
let mut hir_forest = ast_map::Forest::new(lower_crate(&lcx, &krate));
let arenas = ty::CtxtArenas::new();
let ast_map = driver::make_map(&sess, &mut hir_forest);
driver::phase_3_run_analysis_passes(
sess, ast_map, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
&sess, ast_map, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
let trans = driver::phase_4_translate_to_llvm(tcx, analysis);
@ -246,7 +247,7 @@ fn compile_program(input: &str, sysroot: PathBuf)
let modp = llmod as usize;
(modp, deps)
}).1
})
}).unwrap();
match handle.join() {