Skip to content

Commit d84658e

Browse files
committed
address review comments
1 parent 881249a commit d84658e

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

src/librustc/mir/mir_map.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use dep_graph::DepNode;
1112
use util::nodemap::NodeMap;
1213
use mir::repr::Mir;
1314
use mir::transform::MirPass;
@@ -23,6 +24,9 @@ impl<'tcx> MirMap<'tcx> {
2324
if passes.is_empty() { return; }
2425

2526
for (&id, mir) in &mut self.map {
27+
let did = tcx.map.local_def_id(id);
28+
let _task = tcx.dep_graph.in_task(DepNode::MirMapConstruction(did));
29+
2630
let param_env = ty::ParameterEnvironment::for_item(tcx, id);
2731
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env));
2832

src/librustc_mir/build/expr/as_rvalue.rs

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
153153

154154
let fields = if let Some(FruInfo { base, field_types }) = base {
155155
let base = unpack!(block = this.as_lvalue(block, base));
156+
157+
// MIR does not natively support FRU, so for each
158+
// base-supplied field, generate an operand that
159+
// reads it from the base.
156160
field_names.into_iter()
157161
.zip(field_types.into_iter())
158162
.map(|(n, ty)| match fields_map.get(&n) {

src/librustc_mir/transform/clear_dead_blocks.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,29 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! A pass that erases the contents of dead blocks. This is required
12-
//! because rustc allows for ill-typed block terminators in dead
13-
//! blocks.
11+
//! A pass that erases the contents of dead blocks. This pass must
12+
//! run before any analysis passes because some of the dead blocks
13+
//! can be ill-typed.
1414
//!
15-
//! This pass does not renumber or remove the blocks, to have the
16-
//! MIR better match the source.
15+
//! The main problem is that typeck lets most blocks whose end is not
16+
//! reachable have an arbitrary return type, rather than having the
17+
//! usual () return type (as a note, typeck's notion of reachability
18+
//! is in fact slightly weaker than MIR CFG reachability - see #31617).
19+
//!
20+
//! A standard example of the situation is:
21+
//! ```rust
22+
//! fn example() {
23+
//! let _a: char = { return; };
24+
//! }
25+
//! ```
26+
//!
27+
//! Here the block (`{ return; }`) has the return type `char`,
28+
//! rather than `()`, but the MIR we naively generate still contains
29+
//! the `_a = ()` write in the unreachable block "after" the return.
30+
//!
31+
//! As we have to run this pass even when we want to debug the MIR,
32+
//! this pass just replaces the blocks with empty "return" blocks
33+
//! and does not renumber anything.
1734
1835
use rustc::middle::infer;
1936
use rustc::mir::repr::*;
@@ -43,8 +60,9 @@ impl ClearDeadBlocks {
4360
}
4461
}
4562

46-
for (block, seen) in mir.basic_blocks.iter_mut().zip(seen) {
63+
for (n, (block, seen)) in mir.basic_blocks.iter_mut().zip(seen).enumerate() {
4764
if !seen {
65+
info!("clearing block #{}: {:?}", n, block);
4866
*block = BasicBlockData {
4967
statements: vec![],
5068
terminator: Some(Terminator::Return),

src/librustc_mir/transform/type_check.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ enum FieldAccessError {
4848
OutOfRange { field_count: usize }
4949
}
5050

51-
/// Verifies that MIR types are sane to not crash further
52-
/// checks.
51+
/// Verifies that MIR types are sane to not crash further checks.
52+
///
53+
/// The sanitize_XYZ methods here take an MIR object and compute its
54+
/// type, calling `span_mirbug` and returning an error type if there
55+
/// is a problem.
5356
struct TypeVerifier<'a, 'b: 'a, 'tcx: 'b> {
5457
cx: &'a mut TypeChecker<'b, 'tcx>,
5558
mir: &'a Mir<'tcx>,
@@ -119,11 +122,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
119122
}
120123

121124
fn sanitize_type(&mut self, parent: &fmt::Debug, ty: Ty<'tcx>) -> Ty<'tcx> {
122-
if !(ty.needs_infer() || ty.has_escaping_regions() ||
123-
ty.references_error()) {
124-
return ty;
125+
if ty.needs_infer() || ty.has_escaping_regions() || ty.references_error() {
126+
span_mirbug_and_err!(self, parent, "bad type {:?}", ty)
127+
} else {
128+
ty
125129
}
126-
span_mirbug_and_err!(self, parent, "bad type {:?}", ty)
127130
}
128131

129132
fn sanitize_lvalue(&mut self, lvalue: &Lvalue<'tcx>) -> LvalueTy<'tcx> {
@@ -225,7 +228,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
225228
}
226229
_ => LvalueTy::Ty {
227230
ty: span_mirbug_and_err!(
228-
self, lvalue, "can't downcast {:?}", base_ty)
231+
self, lvalue, "can't downcast {:?} as {:?}",
232+
base_ty, adt_def1)
229233
}
230234
},
231235
ProjectionElem::Field(field, fty) => {
@@ -467,8 +471,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
467471
args: &[Operand<'tcx>])
468472
{
469473
debug!("check_call_inputs({:?}, {:?})", sig, args);
470-
if sig.inputs.len() > args.len() ||
471-
(sig.inputs.len() < args.len() && !sig.variadic) {
474+
if args.len() < sig.inputs.len() ||
475+
(args.len() > sig.inputs.len() && !sig.variadic) {
472476
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
473477
}
474478
for (n, (fn_arg, op_arg)) in sig.inputs.iter().zip(args).enumerate() {

src/test/run-pass/mir_augmented_assignments.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ fn main_mir() {
7777
assert_eq!(x, Int(0));
7878

7979
// indexed LHS
80-
let mut v = vec![Int(1), Int(2)];
80+
// FIXME(mir-drop): use the vec![..] macro
81+
let mut v = Vec::new();
82+
v.push(Int(1));
83+
v.push(Int(2));
8184
v[0] += Int(2);
8285
assert_eq!(v[0], Int(3));
8386

@@ -87,6 +90,7 @@ fn main_mir() {
8790
assert_eq!(array[0], 1);
8891
assert_eq!(array[1], 2);
8992
assert_eq!(array[2], 3);
93+
9094
}
9195

9296
impl AddAssign for Int {

0 commit comments

Comments
 (0)