Skip to content

Commit 20083c1

Browse files
committed
Move for loop desugaring to lowering
1 parent 56713a1 commit 20083c1

File tree

12 files changed

+420
-214
lines changed

12 files changed

+420
-214
lines changed

mk/crates.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ DEPS_rustc_typeck := rustc syntax rustc_front rustc_platform_intrinsics
8080
DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax
8181
DEPS_rustc_resolve := rustc rustc_front log syntax
8282
DEPS_rustc_privacy := rustc rustc_front log syntax
83+
DEPS_rustc_front := std syntax log serialize
8384
DEPS_rustc_lint := rustc log syntax
84-
DEPS_rustc := syntax flate arena serialize getopts rbml \
85+
DEPS_rustc := syntax flate arena serialize getopts rbml rustc_front\
8586
log graphviz rustc_llvm rustc_back rustc_data_structures
8687
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
8788
DEPS_rustc_platform_intrinsics := rustc rustc_llvm
8889
DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc
89-
DEPS_rustc_front := std syntax log serialize
9090
DEPS_rustc_data_structures := std log serialize
9191
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
9292
test rustc_lint rustc_front

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use middle::subst;
3636
use middle::ty::{self, Ty};
3737

3838
use syntax::{ast, ast_util, codemap};
39+
use syntax::ast::NodeIdAssigner;
3940
use syntax::codemap::Span;
4041
use syntax::ptr::P;
4142

src/librustc/middle/ty/context.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub struct ctxt<'tcx> {
219219
/// Common types, pre-interned for your convenience.
220220
pub types: CommonTypes<'tcx>,
221221

222-
pub sess: Session,
222+
pub sess: &'tcx Session,
223223
pub def_map: DefMap,
224224

225225
pub named_region_map: resolve_lifetime::NamedRegionMap,
@@ -443,7 +443,7 @@ impl<'tcx> ctxt<'tcx> {
443443
/// to the context. The closure enforces that the type context and any interned
444444
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
445445
/// reference to the context, to allow formatting values that need it.
446-
pub fn create_and_enter<F, R>(s: Session,
446+
pub fn create_and_enter<F, R>(s: &'tcx Session,
447447
arenas: &'tcx CtxtArenas<'tcx>,
448448
def_map: DefMap,
449449
named_region_map: resolve_lifetime::NamedRegionMap,
@@ -452,7 +452,7 @@ impl<'tcx> ctxt<'tcx> {
452452
region_maps: RegionMaps,
453453
lang_items: middle::lang_items::LanguageItems,
454454
stability: stability::Index<'tcx>,
455-
f: F) -> (Session, R)
455+
f: F) -> R
456456
where F: FnOnce(&ctxt<'tcx>) -> R
457457
{
458458
let interner = RefCell::new(FnvHashMap());
@@ -556,7 +556,6 @@ impl<'a, 'tcx> Lift<'tcx> for &'a Substs<'a> {
556556

557557
pub mod tls {
558558
use middle::ty;
559-
use session::Session;
560559

561560
use std::fmt;
562561
use syntax::codemap;
@@ -574,17 +573,15 @@ pub mod tls {
574573
})
575574
}
576575

577-
pub fn enter<'tcx, F: FnOnce(&ty::ctxt<'tcx>) -> R, R>(tcx: ty::ctxt<'tcx>, f: F)
578-
-> (Session, R) {
579-
let result = codemap::SPAN_DEBUG.with(|span_dbg| {
576+
pub fn enter<'tcx, F: FnOnce(&ty::ctxt<'tcx>) -> R, R>(tcx: ty::ctxt<'tcx>, f: F) -> R {
577+
codemap::SPAN_DEBUG.with(|span_dbg| {
580578
let original_span_debug = span_dbg.get();
581579
span_dbg.set(span_debug);
582580
let tls_ptr = &tcx as *const _ as *const ThreadLocalTyCx;
583581
let result = TLS_TCX.set(unsafe { &*tls_ptr }, || f(&tcx));
584582
span_dbg.set(original_span_debug);
585583
result
586-
});
587-
(tcx.sess, result)
584+
})
588585
}
589586

590587
pub fn with<F: FnOnce(&ty::ctxt) -> R, R>(f: F) -> R {

src/librustc/session/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use middle::dependency_format;
1515
use session::search_paths::PathKind;
1616
use util::nodemap::{NodeMap, FnvHashMap};
1717

18-
use syntax::ast::NodeId;
18+
use syntax::ast::{NodeId, NodeIdAssigner};
1919
use syntax::codemap::Span;
2020
use syntax::diagnostic::{self, Emitter};
2121
use syntax::diagnostics;
@@ -236,9 +236,6 @@ impl Session {
236236
}
237237
lints.insert(id, vec!((lint_id, sp, msg)));
238238
}
239-
pub fn next_node_id(&self) -> ast::NodeId {
240-
self.reserve_node_ids(1)
241-
}
242239
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
243240
let id = self.next_node_id.get();
244241

@@ -317,6 +314,12 @@ impl Session {
317314
}
318315
}
319316

317+
impl NodeIdAssigner for Session {
318+
fn next_node_id(&self) -> NodeId {
319+
self.reserve_node_ids(1)
320+
}
321+
}
322+
320323
fn split_msg_into_multilines(msg: &str) -> Option<String> {
321324
// Conditions for enabling multi-line errors:
322325
if !msg.contains("mismatched types") &&

src/librustc_driver/driver.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::ffi::{OsString, OsStr};
4242
use std::fs;
4343
use std::io::{self, Write};
4444
use std::path::{Path, PathBuf};
45-
use syntax::ast;
45+
use syntax::ast::{self, NodeIdAssigner};
4646
use syntax::attr;
4747
use syntax::attr::AttrMetaMethods;
4848
use syntax::diagnostics;
@@ -71,7 +71,7 @@ pub fn compile_input(sess: Session,
7171
// We need nested scopes here, because the intermediate results can keep
7272
// large chunks of memory alive and we want to free them as soon as
7373
// possible to keep the peak memory usage low
74-
let (sess, result) = {
74+
let result = {
7575
let (outputs, expanded_crate, id) = {
7676
let krate = phase_1_parse_input(&sess, cfg, input);
7777

@@ -113,7 +113,7 @@ pub fn compile_input(sess: Session,
113113
let expanded_crate = assign_node_ids(&sess, expanded_crate);
114114
// Lower ast -> hir.
115115
let foo = &42;
116-
let lcx = LoweringContext::new(foo);
116+
let lcx = LoweringContext::new(foo, &sess, &expanded_crate);
117117
let mut hir_forest = time(sess.time_passes(),
118118
"lowering ast -> hir",
119119
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));
@@ -141,7 +141,7 @@ pub fn compile_input(sess: Session,
141141
lint::check_ast_crate(&sess, &expanded_crate)
142142
});
143143

144-
phase_3_run_analysis_passes(sess,
144+
phase_3_run_analysis_passes(&sess,
145145
ast_map,
146146
&arenas,
147147
id,
@@ -282,7 +282,7 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
282282
pub ast_map: Option<&'a hir_map::Map<'ast>>,
283283
pub analysis: Option<&'a ty::CrateAnalysis>,
284284
pub tcx: Option<&'a ty::ctxt<'tcx>>,
285-
pub lcx: Option<&'a LoweringContext<'tcx>>,
285+
pub lcx: Option<&'a LoweringContext<'a, 'tcx>>,
286286
pub trans: Option<&'a trans::CrateTranslation>,
287287
}
288288

@@ -340,7 +340,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
340340
krate: &'a ast::Crate,
341341
hir_crate: &'a hir::Crate,
342342
crate_name: &'a str,
343-
lcx: &'a LoweringContext<'tcx>)
343+
lcx: &'a LoweringContext<'a, 'tcx>)
344344
-> CompileState<'a, 'ast, 'tcx> {
345345
CompileState {
346346
crate_name: Some(crate_name),
@@ -359,7 +359,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
359359
hir_crate: &'a hir::Crate,
360360
analysis: &'a ty::CrateAnalysis,
361361
tcx: &'a ty::ctxt<'tcx>,
362-
lcx: &'a LoweringContext<'tcx>)
362+
lcx: &'a LoweringContext<'a, 'tcx>)
363363
-> CompileState<'a, 'ast, 'tcx> {
364364
CompileState {
365365
analysis: Some(analysis),
@@ -659,21 +659,21 @@ pub fn make_map<'ast>(sess: &Session,
659659
/// Run the resolution, typechecking, region checking and other
660660
/// miscellaneous analysis passes on the crate. Return various
661661
/// structures carrying the results of the analysis.
662-
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
662+
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
663663
ast_map: front::map::Map<'tcx>,
664664
arenas: &'tcx ty::CtxtArenas<'tcx>,
665665
name: String,
666666
make_glob_map: resolve::MakeGlobMap,
667667
f: F)
668-
-> (Session, R)
668+
-> R
669669
where F: for<'a> FnOnce(&'a ty::ctxt<'tcx>,
670670
ty::CrateAnalysis) -> R
671671
{
672672
let time_passes = sess.time_passes();
673673
let krate = ast_map.krate();
674674

675675
time(time_passes, "external crate/lib resolution", ||
676-
LocalCrateReader::new(&sess, &ast_map).read_crates(krate));
676+
LocalCrateReader::new(sess, &ast_map).read_crates(krate));
677677

678678
let lang_items = time(time_passes, "language item collection", ||
679679
middle::lang_items::collect_language_items(&sess, &ast_map));
@@ -687,32 +687,32 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
687687
glob_map,
688688
} =
689689
time(time_passes, "resolution",
690-
|| resolve::resolve_crate(&sess, &ast_map, make_glob_map));
690+
|| resolve::resolve_crate(sess, &ast_map, make_glob_map));
691691

692692
// Discard MTWT tables that aren't required past resolution.
693693
if !sess.opts.debugging_opts.keep_mtwt_tables {
694694
syntax::ext::mtwt::clear_tables();
695695
}
696696

697697
let named_region_map = time(time_passes, "lifetime resolution",
698-
|| middle::resolve_lifetime::krate(&sess, krate, &def_map));
698+
|| middle::resolve_lifetime::krate(sess, krate, &def_map));
699699

700700
time(time_passes, "looking for entry point",
701-
|| middle::entry::find_entry_point(&sess, &ast_map));
701+
|| middle::entry::find_entry_point(sess, &ast_map));
702702

703703
sess.plugin_registrar_fn.set(
704704
time(time_passes, "looking for plugin registrar", ||
705705
plugin::build::find_plugin_registrar(
706706
sess.diagnostic(), krate)));
707707

708708
let region_map = time(time_passes, "region resolution", ||
709-
middle::region::resolve_crate(&sess, krate));
709+
middle::region::resolve_crate(sess, krate));
710710

711711
time(time_passes, "loop checking", ||
712-
middle::check_loop::check_crate(&sess, krate));
712+
middle::check_loop::check_crate(sess, krate));
713713

714714
time(time_passes, "static item recursion checking", ||
715-
middle::check_static_recursion::check_crate(&sess, krate, &def_map, &ast_map));
715+
middle::check_static_recursion::check_crate(sess, krate, &def_map, &ast_map));
716716

717717
ty::ctxt::create_and_enter(sess,
718718
arenas,

0 commit comments

Comments
 (0)