Skip to content

Commit 9ef5b88

Browse files
committed
bless diff
Just output the current bless'd MIR diff The tests are still fairly broken rn
1 parent f51422b commit 9ef5b88

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

src/librustc_mir/transform/match_branches.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
5252
if let Some(f_c) = f_c.literal.try_eval_bool(tcx, param_env) {
5353
// This should also be a bool because it's writing to the same place
5454
let s_c = s_c.literal.try_eval_bool(tcx, param_env).unwrap();
55-
assert_ne!(f_c, s_c, "Unexpected match would've compared eq earlier");
56-
continue;
55+
if f_c != s_c {
56+
// have to check this here because f_c & s_c might have
57+
// different spans.
58+
continue;
59+
}
5760
}
5861
continue 'outer;
5962
}
@@ -63,9 +66,9 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
6366
}
6467
// Take owenership of items now that we know we can optimize.
6568
let discr = discr.clone();
69+
let (from, first) = bbs.pick2_mut(bb_idx, first);
6670

67-
bbs[bb_idx].terminator_mut().kind = TerminatorKind::Goto { target: first };
68-
for s in bbs[first].statements.iter_mut() {
71+
let new_stmts = first.statements.iter().cloned().map(|mut s| {
6972
if let StatementKind::Assign(box (_, ref mut rhs)) = s.kind {
7073
if let Rvalue::Use(Operand::Constant(c)) = rhs {
7174
let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size;
@@ -81,7 +84,10 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
8184
}
8285
}
8386
}
84-
}
87+
s
88+
});
89+
from.statements.extend(new_stmts);
90+
from.terminator_mut().kind = first.terminator().kind.clone();
8591
}
8692
}
8793
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
- // MIR for `foo` before MatchBranchSimplification
2+
+ // MIR for `foo` after MatchBranchSimplification
3+
4+
fn foo(_1: std::option::Option<()>) -> () {
5+
debug bar => _1; // in scope 0 at $DIR/matches_reduce_branches.rs:3:8: 3:11
6+
let mut _0: (); // return place in scope 0 at $DIR/matches_reduce_branches.rs:3:25: 3:25
7+
let mut _2: bool; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
8+
let mut _3: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:4:22: 4:26
9+
10+
bb0: {
11+
StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
12+
_3 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:4:22: 4:26
13+
- switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:4:22: 4:26
14+
+ goto -> bb2; // scope 0 at $DIR/matches_reduce_branches.rs:4:22: 4:26
15+
}
16+
17+
bb1: {
18+
_2 = const false; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
19+
// ty::Const
20+
// + ty: bool
21+
// + val: Value(Scalar(0x00))
22+
// mir::Constant
23+
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
24+
// + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
25+
goto -> bb3; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
26+
}
27+
28+
bb2: {
29+
- _2 = const true; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
30+
+ _2 = Eq(move _3, const 0_isize); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
31+
// ty::Const
32+
- // + ty: bool
33+
- // + val: Value(Scalar(0x01))
34+
+ // + ty: isize
35+
+ // + val: Value(Scalar(0x0000000000000000))
36+
// mir::Constant
37+
- // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
38+
- // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
39+
+ // + span: $DIR/matches_reduce_branches.rs:1:1: 1:1
40+
+ // + literal: Const { ty: isize, val: Value(Scalar(0x0000000000000000)) }
41+
goto -> bb3; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
42+
}
43+
44+
bb3: {
45+
switchInt(_2) -> [false: bb4, otherwise: bb5]; // scope 0 at $DIR/matches_reduce_branches.rs:4:5: 6:6
46+
}
47+
48+
bb4: {
49+
_0 = const (); // scope 0 at $DIR/matches_reduce_branches.rs:4:5: 6:6
50+
// ty::Const
51+
// + ty: ()
52+
// + val: Value(Scalar(<ZST>))
53+
// mir::Constant
54+
// + span: $DIR/matches_reduce_branches.rs:4:5: 6:6
55+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
56+
goto -> bb5; // scope 0 at $DIR/matches_reduce_branches.rs:4:5: 6:6
57+
}
58+
59+
bb5: {
60+
StorageDead(_2); // scope 0 at $DIR/matches_reduce_branches.rs:7:1: 7:2
61+
return; // scope 0 at $DIR/matches_reduce_branches.rs:7:2: 7:2
62+
}
63+
}
64+

0 commit comments

Comments
 (0)