Skip to content

Commit 56713a1

Browse files
committed
Add a lowering context
1 parent 11eda66 commit 56713a1

File tree

6 files changed

+487
-463
lines changed

6 files changed

+487
-463
lines changed

src/librustc_driver/driver.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_trans::trans;
3131
use rustc_typeck as typeck;
3232
use rustc_privacy;
3333
use rustc_front::hir;
34-
use rustc_front::lowering::lower_crate;
34+
use rustc_front::lowering::{lower_crate, LoweringContext};
3535
use super::Compilation;
3636

3737
use serialize::json;
@@ -112,9 +112,11 @@ pub fn compile_input(sess: Session,
112112

113113
let expanded_crate = assign_node_ids(&sess, expanded_crate);
114114
// Lower ast -> hir.
115+
let foo = &42;
116+
let lcx = LoweringContext::new(foo);
115117
let mut hir_forest = time(sess.time_passes(),
116118
"lowering ast -> hir",
117-
|| hir_map::Forest::new(lower_crate(&expanded_crate)));
119+
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));
118120
let arenas = ty::CtxtArenas::new();
119121
let ast_map = make_map(&sess, &mut hir_forest);
120122

@@ -128,7 +130,8 @@ pub fn compile_input(sess: Session,
128130
&ast_map,
129131
&expanded_crate,
130132
&ast_map.krate(),
131-
&id[..]));
133+
&id[..],
134+
&lcx));
132135

133136
time(sess.time_passes(), "attribute checking", || {
134137
front::check_attr::check_crate(&sess, &expanded_crate);
@@ -152,7 +155,8 @@ pub fn compile_input(sess: Session,
152155
&expanded_crate,
153156
tcx.map.krate(),
154157
&analysis,
155-
tcx);
158+
tcx,
159+
&lcx);
156160
(control.after_analysis.callback)(state);
157161

158162
tcx.sess.abort_if_errors();
@@ -278,6 +282,7 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
278282
pub ast_map: Option<&'a hir_map::Map<'ast>>,
279283
pub analysis: Option<&'a ty::CrateAnalysis>,
280284
pub tcx: Option<&'a ty::ctxt<'tcx>>,
285+
pub lcx: Option<&'a LoweringContext<'tcx>>,
281286
pub trans: Option<&'a trans::CrateTranslation>,
282287
}
283288

@@ -299,6 +304,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
299304
ast_map: None,
300305
analysis: None,
301306
tcx: None,
307+
lcx: None,
302308
trans: None,
303309
}
304310
}
@@ -333,13 +339,15 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
333339
ast_map: &'a hir_map::Map<'ast>,
334340
krate: &'a ast::Crate,
335341
hir_crate: &'a hir::Crate,
336-
crate_name: &'a str)
342+
crate_name: &'a str,
343+
lcx: &'a LoweringContext<'tcx>)
337344
-> CompileState<'a, 'ast, 'tcx> {
338345
CompileState {
339346
crate_name: Some(crate_name),
340347
ast_map: Some(ast_map),
341348
krate: Some(krate),
342349
hir_crate: Some(hir_crate),
350+
lcx: Some(lcx),
343351
.. CompileState::empty(input, session, out_dir)
344352
}
345353
}
@@ -350,13 +358,15 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
350358
krate: &'a ast::Crate,
351359
hir_crate: &'a hir::Crate,
352360
analysis: &'a ty::CrateAnalysis,
353-
tcx: &'a ty::ctxt<'tcx>)
361+
tcx: &'a ty::ctxt<'tcx>,
362+
lcx: &'a LoweringContext<'tcx>)
354363
-> CompileState<'a, 'ast, 'tcx> {
355364
CompileState {
356365
analysis: Some(analysis),
357366
tcx: Some(tcx),
358367
krate: Some(krate),
359368
hir_crate: Some(hir_crate),
369+
lcx: Some(lcx),
360370
.. CompileState::empty(input, session, out_dir)
361371
}
362372
}

src/librustc_driver/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
396396
time(state.session.time_passes(),
397397
"save analysis",
398398
|| save::process_crate(state.tcx.unwrap(),
399+
state.lcx.unwrap(),
399400
state.krate.unwrap(),
400401
state.analysis.unwrap(),
401402
state.out_dir));

src/librustc_driver/pretty.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::str::FromStr;
4747
use rustc::front::map as hir_map;
4848
use rustc::front::map::{blocks, NodePrinter};
4949
use rustc_front::hir;
50-
use rustc_front::lowering::lower_crate;
50+
use rustc_front::lowering::{lower_crate, LoweringContext};
5151
use rustc_front::print::pprust as pprust_hir;
5252

5353
#[derive(Copy, Clone, PartialEq, Debug)]
@@ -670,9 +670,11 @@ pub fn pretty_print_input(sess: Session,
670670
// There is some twisted, god-forsaken tangle of lifetimes here which makes
671671
// the ordering of stuff super-finicky.
672672
let mut hir_forest;
673+
let foo = &42;
674+
let lcx = LoweringContext::new(foo);
673675
let arenas = ty::CtxtArenas::new();
674676
let ast_map = if compute_ast_map {
675-
hir_forest = hir_map::Forest::new(lower_crate(&krate));
677+
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
676678
let map = driver::make_map(&sess, &mut hir_forest);
677679
Some(map)
678680
} else {

0 commit comments

Comments
 (0)