Skip to content

Commit

Permalink
Refactor hir::lowering API
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed May 10, 2016
1 parent 3927ff4 commit 33978b0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
35 changes: 19 additions & 16 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,33 @@ impl Resolver for DummyResolver {
}
}

impl<'a> LoweringContext<'a> {
pub fn new(id_assigner: &'a NodeIdAssigner,
c: Option<&Crate>,
resolver: &'a mut Resolver)
-> 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")
}
});
pub fn lower_crate(krate: &Crate, id_assigner: &NodeIdAssigner, resolver: &mut Resolver)
-> hir::Crate {
LoweringContext {
crate_root: if std_inject::no_core(krate) {
None
} else if std_inject::no_std(krate) {
Some("core")
} else {
Some("std")
},
id_assigner: id_assigner,
parent_def: None,
resolver: resolver,
}.lower_crate(krate)
}

impl<'a> LoweringContext<'a> {
pub fn testing_context(id_assigner: &'a NodeIdAssigner, resolver: &'a mut Resolver) -> Self {
LoweringContext {
crate_root: crate_root,
crate_root: None,
id_assigner: id_assigner,
parent_def: None,
resolver: resolver,
}
}

pub fn lower_crate(&mut self, c: &Crate) -> hir::Crate {
fn lower_crate(&mut self, c: &Crate) -> hir::Crate {
struct ItemLowerer<'lcx, 'interner: 'lcx> {
items: BTreeMap<NodeId, hir::Item>,
lctx: &'lcx mut LoweringContext<'interner>,
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::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;
Expand Down Expand Up @@ -787,8 +787,7 @@ pub fn lower_and_resolve<'a>(sess: &Session,

// Lower ast -> hir.
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {
let krate = LoweringContext::new(sess, Some(krate), &mut resolver).lower_crate(krate);
hir_map::Forest::new(krate, dep_graph)
hir_map::Forest::new(lower_crate(krate, sess, &mut resolver), dep_graph)
});

(ty::CrateAnalysis {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ fn mk_ctxt() -> parse::ParseSess {
fn with_testing_context<T, F: FnOnce(&mut LoweringContext) -> T>(f: F) -> T {
let assigner = FakeNodeIdAssigner;
let mut resolver = DummyResolver;
let mut lcx = LoweringContext::new(&assigner, None, &mut resolver);
let mut lcx = LoweringContext::testing_context(&assigner, &mut resolver);
f(&mut lcx)
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{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};
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn run(input: &str,
let defs = &RefCell::new(hir_map::collect_definitions(&krate));

let mut dummy_resolver = DummyResolver;
let krate = LoweringContext::new(&sess, Some(&krate), &mut dummy_resolver).lower_crate(&krate);
let krate = lower_crate(&krate, &sess, &mut dummy_resolver);

let opts = scrape_test_config(&krate);

Expand Down

0 comments on commit 33978b0

Please sign in to comment.