Skip to content

Commit c146090

Browse files
committed
Auto merge of #28857 - nrc:lowering, r=nikomatsakis
r? @nikomatsakis
2 parents 7cea9a7 + a62a529 commit c146090

39 files changed

+1602
-888
lines changed

mk/crates.mk

+33-29
Original file line numberDiff line numberDiff line change
@@ -61,51 +61,55 @@ HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros
6161
TOOLS := compiletest rustdoc rustc rustbook error-index-generator
6262

6363
DEPS_core :=
64+
DEPS_alloc := core libc alloc_system
65+
DEPS_alloc_system := core libc
66+
DEPS_collections := core alloc rustc_unicode
6467
DEPS_libc := core
68+
DEPS_rand := core
69+
DEPS_rustc_bitflags := core
6570
DEPS_rustc_unicode := core
66-
DEPS_alloc := core libc alloc_system
71+
6772
DEPS_std := core libc rand alloc collections rustc_unicode \
6873
native:rust_builtin native:backtrace \
6974
alloc_system
75+
DEPS_arena := std
76+
DEPS_glob := std
77+
DEPS_flate := std native:miniz
78+
DEPS_fmt_macros = std
79+
DEPS_getopts := std
7080
DEPS_graphviz := std
81+
DEPS_log := std
82+
DEPS_num := std
83+
DEPS_rbml := std log serialize
84+
DEPS_serialize := std log
85+
DEPS_term := std log
86+
DEPS_test := std getopts serialize rbml term native:rust_test_helpers
87+
7188
DEPS_syntax := std term serialize log fmt_macros arena libc rustc_bitflags
89+
90+
DEPS_rustc := syntax flate arena serialize getopts rbml rustc_front\
91+
log graphviz rustc_llvm rustc_back rustc_data_structures
92+
DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc
93+
DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax
94+
DEPS_rustc_data_structures := std log serialize
7295
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
7396
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
7497
rustc_trans rustc_privacy rustc_lint rustc_front
7598

76-
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
77-
log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics
78-
DEPS_rustc_mir := rustc rustc_front syntax
79-
DEPS_rustc_typeck := rustc syntax rustc_front rustc_platform_intrinsics
80-
DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax
81-
DEPS_rustc_resolve := rustc rustc_front log syntax
82-
DEPS_rustc_privacy := rustc rustc_front log syntax
99+
DEPS_rustc_front := std syntax log serialize
83100
DEPS_rustc_lint := rustc log syntax
84-
DEPS_rustc := syntax flate arena serialize getopts rbml \
85-
log graphviz rustc_llvm rustc_back rustc_data_structures
86101
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
102+
DEPS_rustc_mir := rustc rustc_front syntax
103+
DEPS_rustc_resolve := rustc rustc_front log syntax
87104
DEPS_rustc_platform_intrinsics := rustc rustc_llvm
88-
DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc
89-
DEPS_rustc_front := std syntax log serialize
90-
DEPS_rustc_data_structures := std log serialize
105+
DEPS_rustc_privacy := rustc rustc_front log syntax
106+
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
107+
log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics
108+
DEPS_rustc_typeck := rustc syntax rustc_front rustc_platform_intrinsics
109+
91110
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
92111
test rustc_lint rustc_front
93-
DEPS_rustc_bitflags := core
94-
DEPS_flate := std native:miniz
95-
DEPS_arena := std
96-
DEPS_graphviz := std
97-
DEPS_glob := std
98-
DEPS_serialize := std log
99-
DEPS_rbml := std log serialize
100-
DEPS_term := std log
101-
DEPS_getopts := std
102-
DEPS_collections := core alloc rustc_unicode
103-
DEPS_num := std
104-
DEPS_test := std getopts serialize rbml term native:rust_test_helpers
105-
DEPS_rand := core
106-
DEPS_log := std
107-
DEPS_fmt_macros = std
108-
DEPS_alloc_system := core libc
112+
109113

110114
TOOL_DEPS_compiletest := test getopts
111115
TOOL_DEPS_rustdoc := rustdoc

src/librustc/middle/astencode.rs

+32-6
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

@@ -53,8 +54,9 @@ use serialize::EncoderHelpers;
5354

5455
#[cfg(test)] use std::io::Cursor;
5556
#[cfg(test)] use syntax::parse;
57+
#[cfg(test)] use syntax::ast::NodeId;
5658
#[cfg(test)] use rustc_front::print::pprust;
57-
#[cfg(test)] use rustc_front::lowering::lower_item;
59+
#[cfg(test)] use rustc_front::lowering::{lower_item, LoweringContext};
5860

5961
struct DecodeContext<'a, 'b, 'tcx: 'a> {
6062
tcx: &'a ty::ctxt<'tcx>,
@@ -1376,6 +1378,22 @@ impl FakeExtCtxt for parse::ParseSess {
13761378
fn parse_sess(&self) -> &parse::ParseSess { self }
13771379
}
13781380

1381+
#[cfg(test)]
1382+
struct FakeNodeIdAssigner;
1383+
1384+
#[cfg(test)]
1385+
// It should go without saying that this may give unexpected results. Avoid
1386+
// lowering anything which needs new nodes.
1387+
impl NodeIdAssigner for FakeNodeIdAssigner {
1388+
fn next_node_id(&self) -> NodeId {
1389+
0
1390+
}
1391+
1392+
fn peek_node_id(&self) -> NodeId {
1393+
0
1394+
}
1395+
}
1396+
13791397
#[cfg(test)]
13801398
fn mk_ctxt() -> parse::ParseSess {
13811399
parse::ParseSess::new()
@@ -1394,23 +1412,29 @@ fn roundtrip(in_item: P<hir::Item>) {
13941412
#[test]
13951413
fn test_basic() {
13961414
let cx = mk_ctxt();
1397-
roundtrip(lower_item(&quote_item!(&cx,
1415+
let fnia = FakeNodeIdAssigner;
1416+
let lcx = LoweringContext::new(&fnia, None);
1417+
roundtrip(lower_item(&lcx, &quote_item!(&cx,
13981418
fn foo() {}
13991419
).unwrap()));
14001420
}
14011421

14021422
#[test]
14031423
fn test_smalltalk() {
14041424
let cx = mk_ctxt();
1405-
roundtrip(lower_item(&quote_item!(&cx,
1425+
let fnia = FakeNodeIdAssigner;
1426+
let lcx = LoweringContext::new(&fnia, None);
1427+
roundtrip(lower_item(&lcx, &quote_item!(&cx,
14061428
fn foo() -> isize { 3 + 4 } // first smalltalk program ever executed.
14071429
).unwrap()));
14081430
}
14091431

14101432
#[test]
14111433
fn test_more() {
14121434
let cx = mk_ctxt();
1413-
roundtrip(lower_item(&quote_item!(&cx,
1435+
let fnia = FakeNodeIdAssigner;
1436+
let lcx = LoweringContext::new(&fnia, None);
1437+
roundtrip(lower_item(&lcx, &quote_item!(&cx,
14141438
fn foo(x: usize, y: usize) -> usize {
14151439
let z = x + y;
14161440
return z;
@@ -1427,10 +1451,12 @@ fn test_simplification() {
14271451
return alist {eq_fn: eq_int, data: Vec::new()};
14281452
}
14291453
).unwrap();
1430-
let hir_item = lower_item(&item);
1454+
let fnia = FakeNodeIdAssigner;
1455+
let lcx = LoweringContext::new(&fnia, None);
1456+
let hir_item = lower_item(&lcx, &item);
14311457
let item_in = InlinedItemRef::Item(&hir_item);
14321458
let item_out = simplify_ast(item_in);
1433-
let item_exp = InlinedItem::Item(lower_item(&quote_item!(&cx,
1459+
let item_exp = InlinedItem::Item(lower_item(&lcx, &quote_item!(&cx,
14341460
fn new_int_alist<B>() -> alist<isize, B> {
14351461
return alist {eq_fn: eq_int, data: Vec::new()};
14361462
}

src/librustc/middle/effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
102102
fn visit_block(&mut self, block: &hir::Block) {
103103
let old_unsafe_context = self.unsafe_context;
104104
match block.rules {
105-
hir::DefaultBlock => {}
106105
hir::UnsafeBlock(source) => {
107106
// By default only the outermost `unsafe` block is
108107
// "used" and so nested unsafe blocks are pointless
@@ -131,6 +130,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
131130
self.unsafe_context.push_unsafe_count =
132131
self.unsafe_context.push_unsafe_count.checked_sub(1).unwrap();
133132
}
133+
hir::DefaultBlock | hir::PushUnstableBlock | hir:: PopUnstableBlock => {}
134134
}
135135

136136
visit::walk_block(self, block);

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl RegionMaps {
377377
self.code_extents.borrow()[e.0 as usize]
378378
}
379379
pub fn each_encl_scope<E>(&self, mut e:E) where E: FnMut(&CodeExtent, &CodeExtent) {
380-
for child_id in (1..self.code_extents.borrow().len()) {
380+
for child_id in 1..self.code_extents.borrow().len() {
381381
let child = CodeExtent(child_id as u32);
382382
if let Some(parent) = self.opt_encl_scope(child) {
383383
e(&child, &parent)

src/librustc/middle/stability.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ pub fn check_unstable_api_usage(tcx: &ty::ctxt)
270270
let mut checker = Checker {
271271
tcx: tcx,
272272
active_features: active_features,
273-
used_features: FnvHashMap()
273+
used_features: FnvHashMap(),
274+
in_skip_block: 0,
274275
};
275276

276277
let krate = tcx.map.krate();
@@ -283,14 +284,23 @@ pub fn check_unstable_api_usage(tcx: &ty::ctxt)
283284
struct Checker<'a, 'tcx: 'a> {
284285
tcx: &'a ty::ctxt<'tcx>,
285286
active_features: FnvHashSet<InternedString>,
286-
used_features: FnvHashMap<InternedString, attr::StabilityLevel>
287+
used_features: FnvHashMap<InternedString, attr::StabilityLevel>,
288+
// Within a block where feature gate checking can be skipped.
289+
in_skip_block: u32,
287290
}
288291

289292
impl<'a, 'tcx> Checker<'a, 'tcx> {
290293
fn check(&mut self, id: DefId, span: Span, stab: &Option<&Stability>) {
291294
// Only the cross-crate scenario matters when checking unstable APIs
292295
let cross_crate = !id.is_local();
293-
if !cross_crate { return }
296+
if !cross_crate {
297+
return
298+
}
299+
300+
// We don't need to check for stability - presumably compiler generated code.
301+
if self.in_skip_block > 0 {
302+
return;
303+
}
294304

295305
match *stab {
296306
Some(&Stability { level: attr::Unstable, ref feature, ref reason, issue, .. }) => {
@@ -369,6 +379,21 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
369379
&mut |id, sp, stab| self.check(id, sp, stab));
370380
visit::walk_pat(self, pat)
371381
}
382+
383+
fn visit_block(&mut self, b: &hir::Block) {
384+
let old_skip_count = self.in_skip_block;
385+
match b.rules {
386+
hir::BlockCheckMode::PushUnstableBlock => {
387+
self.in_skip_block += 1;
388+
}
389+
hir::BlockCheckMode::PopUnstableBlock => {
390+
self.in_skip_block = self.in_skip_block.checked_sub(1).unwrap();
391+
}
392+
_ => {}
393+
}
394+
visit::walk_block(self, b);
395+
self.in_skip_block = old_skip_count;
396+
}
372397
}
373398

374399
/// Helper for discovering nodes to check for stability

src/librustc/middle/ty/context.rs

+6-9
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

+11-4
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,16 @@ 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+
fn peek_node_id(&self) -> NodeId {
323+
self.next_node_id.get().checked_add(1).unwrap()
324+
}
325+
}
326+
320327
fn split_msg_into_multilines(msg: &str) -> Option<String> {
321328
// Conditions for enabling multi-line errors:
322329
if !msg.contains("mismatched types") &&

0 commit comments

Comments
 (0)