Skip to content

Commit 1d9d381

Browse files
committed
Add a workaround for the TailDuplicator compile time overhead
1 parent 239dfe9 commit 1d9d381

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,18 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
118118
unreachable_targets.push(index);
119119
}
120120
}
121-
122-
let replace_otherwise_to_unreachable = allowed_variants.len() <= 1
123-
&& !body.basic_blocks[targets.otherwise()].is_empty_unreachable();
121+
let otherwise_is_empty_unreachable =
122+
body.basic_blocks[targets.otherwise()].is_empty_unreachable();
123+
// After resolving https://github.com/llvm/llvm-project/issues/78578,
124+
// we can remove the limit on the number of successors.
125+
let otherwise_is_last_variant = !otherwise_is_empty_unreachable
126+
&& allowed_variants.len() == 1
127+
&& !body.basic_blocks[targets.otherwise()]
128+
.terminator()
129+
.successors()
130+
.any(|bb| body.basic_blocks[bb].terminator().successors().count() >= 8);
131+
let replace_otherwise_to_unreachable = otherwise_is_last_variant
132+
|| !otherwise_is_empty_unreachable && allowed_variants.is_empty();
124133

125134
if unreachable_targets.is_empty() && !replace_otherwise_to_unreachable {
126135
continue;
@@ -129,7 +138,6 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
129138
let unreachable_block = patch.unreachable_no_cleanup_block();
130139
let mut targets = targets.clone();
131140
if replace_otherwise_to_unreachable {
132-
let otherwise_is_last_variant = !allowed_variants.is_empty();
133141
if otherwise_is_last_variant {
134142
#[allow(rustc::potential_query_instability)]
135143
let last_variant = *allowed_variants.iter().next().unwrap();

0 commit comments

Comments
 (0)