Skip to content

Commit 8ae0de2

Browse files
committed
Experiment: remove hack
1 parent 9a05cf2 commit 8ae0de2

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

compiler/rustc_mir_build/src/build/matches/test.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
216216

217217
target_blocks
218218
};
219+
let target_blocks = make_target_blocks(self);
219220

220221
let place = place_builder.to_place(self);
221222
let place_ty = place.ty(&self.local_decls, self.tcx);
@@ -224,7 +225,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
224225
let source_info = self.source_info(test.span);
225226
match test.kind {
226227
TestKind::Switch { adt_def, ref variants } => {
227-
let target_blocks = make_target_blocks(self);
228228
// Variants is a BitVec of indexes into adt_def.variants.
229229
let num_enum_variants = adt_def.variants().len();
230230
debug_assert_eq!(target_blocks.len(), num_enum_variants + 1);
@@ -270,7 +270,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
270270
}
271271

272272
TestKind::SwitchInt { switch_ty, ref options } => {
273-
let target_blocks = make_target_blocks(self);
274273
let terminator = if *switch_ty.kind() == ty::Bool {
275274
assert!(!options.is_empty() && options.len() <= 2);
276275
let [first_bb, second_bb] = *target_blocks else {
@@ -340,7 +339,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
340339
);
341340
self.non_scalar_compare(
342341
eq_block,
343-
make_target_blocks,
342+
target_blocks,
344343
source_info,
345344
value,
346345
ref_str,
@@ -351,15 +350,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
351350
if !ty.is_scalar() {
352351
// Use `PartialEq::eq` instead of `BinOp::Eq`
353352
// (the binop can only handle primitives)
354-
self.non_scalar_compare(
355-
block,
356-
make_target_blocks,
357-
source_info,
358-
value,
359-
place,
360-
ty,
361-
);
362-
} else if let [success, fail] = *make_target_blocks(self) {
353+
self.non_scalar_compare(block, target_blocks, source_info, value, place, ty);
354+
} else if let [success, fail] = *target_blocks {
363355
assert_eq!(value.ty(), ty);
364356
let expect = self.literal_operand(test.span, value);
365357
let val = Operand::Copy(place);
@@ -371,7 +363,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
371363

372364
TestKind::Range(ref range) => {
373365
let lower_bound_success = self.cfg.start_new_block();
374-
let target_blocks = make_target_blocks(self);
375366

376367
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
377368
// FIXME: skip useless comparison when the range is half-open.
@@ -401,8 +392,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
401392
}
402393

403394
TestKind::Len { len, op } => {
404-
let target_blocks = make_target_blocks(self);
405-
406395
let usize_ty = self.tcx.types.usize;
407396
let actual = self.temp(usize_ty, test.span);
408397

@@ -466,7 +455,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
466455
fn non_scalar_compare(
467456
&mut self,
468457
block: BasicBlock,
469-
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
458+
target_blocks: Vec<BasicBlock>,
470459
source_info: SourceInfo,
471460
value: Const<'tcx>,
472461
mut val: Place<'tcx>,
@@ -591,7 +580,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
591580
);
592581
self.diverge_from(block);
593582

594-
let [success_block, fail_block] = *make_target_blocks(self) else {
583+
let [success_block, fail_block] = *target_blocks else {
595584
bug!("`TestKind::Eq` should have two target blocks")
596585
};
597586
// check the result

tests/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ fn match_tuple(_1: (u32, bool, Option<i32>, u32)) -> u32 {
3838

3939
bb4: {
4040
_5 = Le(const 6_u32, (_1.3: u32));
41-
switchInt(move _5) -> [0: bb6, otherwise: bb5];
41+
switchInt(move _5) -> [0: bb5, otherwise: bb7];
4242
}
4343

4444
bb5: {
45-
_6 = Le((_1.3: u32), const 9_u32);
46-
switchInt(move _6) -> [0: bb6, otherwise: bb8];
45+
_3 = Le(const 13_u32, (_1.3: u32));
46+
switchInt(move _3) -> [0: bb1, otherwise: bb6];
4747
}
4848

4949
bb6: {
50-
_3 = Le(const 13_u32, (_1.3: u32));
51-
switchInt(move _3) -> [0: bb1, otherwise: bb7];
50+
_4 = Le((_1.3: u32), const 16_u32);
51+
switchInt(move _4) -> [0: bb1, otherwise: bb8];
5252
}
5353

5454
bb7: {
55-
_4 = Le((_1.3: u32), const 16_u32);
56-
switchInt(move _4) -> [0: bb1, otherwise: bb8];
55+
_6 = Le((_1.3: u32), const 9_u32);
56+
switchInt(move _6) -> [0: bb5, otherwise: bb8];
5757
}
5858

5959
bb8: {

tests/mir-opt/match_test.main.SimplifyCfg-initial.after.mir

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,43 @@ fn main() -> () {
2828
StorageLive(_3);
2929
PlaceMention(_1);
3030
_6 = Le(const 0_i32, _1);
31-
switchInt(move _6) -> [0: bb4, otherwise: bb1];
31+
switchInt(move _6) -> [0: bb3, otherwise: bb8];
3232
}
3333

3434
bb1: {
35-
_7 = Lt(_1, const 10_i32);
36-
switchInt(move _7) -> [0: bb4, otherwise: bb2];
35+
falseEdge -> [real: bb9, imaginary: bb4];
3736
}
3837

3938
bb2: {
40-
falseEdge -> [real: bb9, imaginary: bb6];
39+
_3 = const 3_i32;
40+
goto -> bb14;
4141
}
4242

4343
bb3: {
44-
_3 = const 3_i32;
45-
goto -> bb14;
44+
_4 = Le(const 10_i32, _1);
45+
switchInt(move _4) -> [0: bb5, otherwise: bb7];
4646
}
4747

4848
bb4: {
49-
_4 = Le(const 10_i32, _1);
50-
switchInt(move _4) -> [0: bb7, otherwise: bb5];
49+
falseEdge -> [real: bb12, imaginary: bb6];
5150
}
5251

5352
bb5: {
54-
_5 = Le(_1, const 20_i32);
55-
switchInt(move _5) -> [0: bb7, otherwise: bb6];
53+
switchInt(_1) -> [4294967295: bb6, otherwise: bb2];
5654
}
5755

5856
bb6: {
59-
falseEdge -> [real: bb12, imaginary: bb8];
57+
falseEdge -> [real: bb13, imaginary: bb2];
6058
}
6159

6260
bb7: {
63-
switchInt(_1) -> [4294967295: bb8, otherwise: bb3];
61+
_5 = Le(_1, const 20_i32);
62+
switchInt(move _5) -> [0: bb5, otherwise: bb4];
6463
}
6564

6665
bb8: {
67-
falseEdge -> [real: bb13, imaginary: bb3];
66+
_7 = Lt(_1, const 10_i32);
67+
switchInt(move _7) -> [0: bb3, otherwise: bb1];
6868
}
6969

7070
bb9: {
@@ -83,7 +83,7 @@ fn main() -> () {
8383

8484
bb11: {
8585
StorageDead(_9);
86-
falseEdge -> [real: bb3, imaginary: bb6];
86+
falseEdge -> [real: bb2, imaginary: bb4];
8787
}
8888

8989
bb12: {

0 commit comments

Comments
 (0)