Auto merge of #33532 - jseyfried:mutable_lowering_context, r=nrc

Clean up `hir::lowering`

Clean up `hir::lowering`:
 - give lowering functions mutable access to the lowering context
 - refactor the `lower_*` functions and other functions that take a lowering context into methods
 - simplify the API that `hir::lowering` exposes to `driver`
 - other miscellaneous cleanups

r? @nrc
This commit is contained in:
bors 2016-05-13 18:40:08 -07:00
commit dee865a56d
4 changed files with 1745 additions and 1800 deletions

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,7 @@ use rustc_typeck as typeck;
use rustc_privacy;
use rustc_plugin::registry::Registry;
use rustc_plugin as plugin;
use rustc::hir::lowering::{lower_crate, LoweringContext};
use rustc::hir::lowering::lower_crate;
use rustc_passes::{no_asm, loops, consts, rvalues, static_recursion};
use rustc_const_eval::check_match;
use super::Compilation;
@ -816,8 +816,7 @@ pub fn lower_and_resolve<'a>(sess: &Session,
// Lower ast -> hir.
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {
let lcx = LoweringContext::new(sess, Some(krate), &mut resolver);
hir_map::Forest::new(lower_crate(&lcx, krate), dep_graph)
hir_map::Forest::new(lower_crate(krate, sess, &mut resolver), dep_graph)
});
(ty::CrateAnalysis {

View File

@ -57,7 +57,7 @@ use rustc_serialize::{Encodable, EncoderHelpers};
#[cfg(test)] use syntax::parse;
#[cfg(test)] use syntax::ast::NodeId;
#[cfg(test)] use rustc::hir::print as pprust;
#[cfg(test)] use rustc::hir::lowering::{lower_item, LoweringContext, DummyResolver};
#[cfg(test)] use rustc::hir::lowering::{LoweringContext, DummyResolver};
struct DecodeContext<'a, 'b, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@ -1319,11 +1319,11 @@ fn mk_ctxt() -> parse::ParseSess {
}
#[cfg(test)]
fn with_testing_context<T, F: FnOnce(LoweringContext) -> T>(f: F) -> T {
fn with_testing_context<T, F: FnOnce(&mut LoweringContext) -> T>(f: F) -> T {
let assigner = FakeNodeIdAssigner;
let mut resolver = DummyResolver;
let lcx = LoweringContext::new(&assigner, None, &mut resolver);
f(lcx)
let mut lcx = LoweringContext::testing_context(&assigner, &mut resolver);
f(&mut lcx)
}
#[cfg(test)]
@ -1340,7 +1340,7 @@ fn roundtrip(in_item: hir::Item) {
fn test_basic() {
let cx = mk_ctxt();
with_testing_context(|lcx| {
roundtrip(lower_item(&lcx, &quote_item!(&cx,
roundtrip(lcx.lower_item(&quote_item!(&cx,
fn foo() {}
).unwrap()));
});
@ -1350,7 +1350,7 @@ fn test_basic() {
fn test_smalltalk() {
let cx = mk_ctxt();
with_testing_context(|lcx| {
roundtrip(lower_item(&lcx, &quote_item!(&cx,
roundtrip(lcx.lower_item(&quote_item!(&cx,
fn foo() -> isize { 3 + 4 } // first smalltalk program ever executed.
).unwrap()));
});
@ -1360,7 +1360,7 @@ fn test_smalltalk() {
fn test_more() {
let cx = mk_ctxt();
with_testing_context(|lcx| {
roundtrip(lower_item(&lcx, &quote_item!(&cx,
roundtrip(lcx.lower_item(&quote_item!(&cx,
fn foo(x: usize, y: usize) -> usize {
let z = x + y;
return z;
@ -1380,10 +1380,10 @@ fn test_simplification() {
).unwrap();
let cx = mk_ctxt();
with_testing_context(|lcx| {
let hir_item = lower_item(&lcx, &item);
let hir_item = lcx.lower_item(&item);
let item_in = InlinedItemRef::Item(&hir_item);
let item_out = simplify_ast(item_in);
let item_exp = InlinedItem::Item(P(lower_item(&lcx, &quote_item!(&cx,
let item_exp = InlinedItem::Item(P(lcx.lower_item(&quote_item!(&cx,
fn new_int_alist<B>() -> alist<isize, B> {
return alist {eq_fn: eq_int, data: Vec::new()};
}

View File

@ -28,7 +28,7 @@ use rustc::hir::map as hir_map;
use rustc::session::{self, config};
use rustc::session::config::{get_unstable_features_setting, OutputType};
use rustc::session::search_paths::{SearchPaths, PathKind};
use rustc::hir::lowering::{lower_crate, LoweringContext, DummyResolver};
use rustc::hir::lowering::{lower_crate, DummyResolver};
use rustc_back::dynamic_lib::DynamicLibrary;
use rustc_back::tempdir::TempDir;
use rustc_driver::{driver, Compilation};
@ -98,8 +98,7 @@ pub fn run(input: &str,
let defs = &RefCell::new(hir_map::collect_definitions(&krate));
let mut dummy_resolver = DummyResolver;
let lcx = LoweringContext::new(&sess, Some(&krate), &mut dummy_resolver);
let krate = lower_crate(&lcx, &krate);
let krate = lower_crate(&krate, &sess, &mut dummy_resolver);
let opts = scrape_test_config(&krate);