Skip to content

Commit 0a785cd

Browse files
committed
Add some more sanity tests and add a debug log message for it
1 parent de434d8 commit 0a785cd

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

src/librustc_mir/transform/const_prop.rs

+5
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,11 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
893893
// ```
894894
// FIXME: we overzealously erase the entire local, because that's easier to
895895
// implement.
896+
trace!(
897+
"propagation into {:?} failed.
898+
Nuking the entire site from orbit, it's the only way to be sure",
899+
place,
900+
);
896901
Self::remove_const(&mut self.ecx, place.local);
897902
}
898903
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -O
2+
3+
// EMIT_MIR rustc.main.ConstProp.diff
4+
fn main() {
5+
let a = foo();
6+
let mut x: (i32, i32) = (1, 2);
7+
x.1 = a;
8+
let y = x.1;
9+
let z = x.0; // this could theoretically be allowed, but we can't handle it right now
10+
}
11+
12+
#[inline(never)]
13+
fn foo() -> i32 {
14+
unimplemented!()
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
- // MIR for `main` before ConstProp
2+
+ // MIR for `main` after ConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/mutable_variable_unprop_assign.rs:4:11: 4:11
6+
let _1: i32; // in scope 0 at $DIR/mutable_variable_unprop_assign.rs:5:9: 5:10
7+
let mut _3: i32; // in scope 0 at $DIR/mutable_variable_unprop_assign.rs:7:11: 7:12
8+
scope 1 {
9+
debug a => _1; // in scope 1 at $DIR/mutable_variable_unprop_assign.rs:5:9: 5:10
10+
let mut _2: (i32, i32) as UserTypeProjection { base: UserType(0), projs: [] }; // in scope 1 at $DIR/mutable_variable_unprop_assign.rs:6:9: 6:14
11+
scope 2 {
12+
debug x => _2; // in scope 2 at $DIR/mutable_variable_unprop_assign.rs:6:9: 6:14
13+
let _4: i32; // in scope 2 at $DIR/mutable_variable_unprop_assign.rs:8:9: 8:10
14+
scope 3 {
15+
debug y => _4; // in scope 3 at $DIR/mutable_variable_unprop_assign.rs:8:9: 8:10
16+
let _5: i32; // in scope 3 at $DIR/mutable_variable_unprop_assign.rs:9:9: 9:10
17+
scope 4 {
18+
debug z => _5; // in scope 4 at $DIR/mutable_variable_unprop_assign.rs:9:9: 9:10
19+
}
20+
}
21+
}
22+
}
23+
24+
bb0: {
25+
StorageLive(_1); // scope 0 at $DIR/mutable_variable_unprop_assign.rs:5:9: 5:10
26+
_1 = const foo() -> bb1; // scope 0 at $DIR/mutable_variable_unprop_assign.rs:5:13: 5:18
27+
// ty::Const
28+
// + ty: fn() -> i32 {foo}
29+
// + val: Value(Scalar(<ZST>))
30+
// mir::Constant
31+
// + span: $DIR/mutable_variable_unprop_assign.rs:5:13: 5:16
32+
// + literal: Const { ty: fn() -> i32 {foo}, val: Value(Scalar(<ZST>)) }
33+
}
34+
35+
bb1: {
36+
StorageLive(_2); // scope 1 at $DIR/mutable_variable_unprop_assign.rs:6:9: 6:14
37+
_2 = (const 1i32, const 2i32); // scope 1 at $DIR/mutable_variable_unprop_assign.rs:6:29: 6:35
38+
// ty::Const
39+
// + ty: i32
40+
// + val: Value(Scalar(0x00000001))
41+
// mir::Constant
42+
- // + span: $DIR/mutable_variable_unprop_assign.rs:6:30: 6:31
43+
+ // + span: $DIR/mutable_variable_unprop_assign.rs:6:29: 6:35
44+
// + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) }
45+
// ty::Const
46+
// + ty: i32
47+
// + val: Value(Scalar(0x00000002))
48+
// mir::Constant
49+
- // + span: $DIR/mutable_variable_unprop_assign.rs:6:33: 6:34
50+
+ // + span: $DIR/mutable_variable_unprop_assign.rs:6:29: 6:35
51+
// + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) }
52+
StorageLive(_3); // scope 2 at $DIR/mutable_variable_unprop_assign.rs:7:11: 7:12
53+
_3 = _1; // scope 2 at $DIR/mutable_variable_unprop_assign.rs:7:11: 7:12
54+
(_2.1: i32) = move _3; // scope 2 at $DIR/mutable_variable_unprop_assign.rs:7:5: 7:12
55+
StorageDead(_3); // scope 2 at $DIR/mutable_variable_unprop_assign.rs:7:11: 7:12
56+
StorageLive(_4); // scope 2 at $DIR/mutable_variable_unprop_assign.rs:8:9: 8:10
57+
_4 = (_2.1: i32); // scope 2 at $DIR/mutable_variable_unprop_assign.rs:8:13: 8:16
58+
StorageLive(_5); // scope 3 at $DIR/mutable_variable_unprop_assign.rs:9:9: 9:10
59+
_5 = (_2.0: i32); // scope 3 at $DIR/mutable_variable_unprop_assign.rs:9:13: 9:16
60+
_0 = const (); // scope 0 at $DIR/mutable_variable_unprop_assign.rs:4:11: 10:2
61+
// ty::Const
62+
// + ty: ()
63+
// + val: Value(Scalar(<ZST>))
64+
// mir::Constant
65+
// + span: $DIR/mutable_variable_unprop_assign.rs:4:11: 10:2
66+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
67+
StorageDead(_5); // scope 3 at $DIR/mutable_variable_unprop_assign.rs:10:1: 10:2
68+
StorageDead(_4); // scope 2 at $DIR/mutable_variable_unprop_assign.rs:10:1: 10:2
69+
StorageDead(_2); // scope 1 at $DIR/mutable_variable_unprop_assign.rs:10:1: 10:2
70+
StorageDead(_1); // scope 0 at $DIR/mutable_variable_unprop_assign.rs:10:1: 10:2
71+
return; // scope 0 at $DIR/mutable_variable_unprop_assign.rs:10:2: 10:2
72+
}
73+
}
74+

0 commit comments

Comments
 (0)