Skip to content

Commit

Permalink
Add a workaround for the TailDuplicator compile time overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
DianQK committed Feb 29, 2024
1 parent 239dfe9 commit 1d9d381
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,18 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
unreachable_targets.push(index);
}
}

let replace_otherwise_to_unreachable = allowed_variants.len() <= 1
&& !body.basic_blocks[targets.otherwise()].is_empty_unreachable();
let otherwise_is_empty_unreachable =
body.basic_blocks[targets.otherwise()].is_empty_unreachable();
// After resolving https://github.com/llvm/llvm-project/issues/78578,
// we can remove the limit on the number of successors.
let otherwise_is_last_variant = !otherwise_is_empty_unreachable
&& allowed_variants.len() == 1
&& !body.basic_blocks[targets.otherwise()]
.terminator()
.successors()
.any(|bb| body.basic_blocks[bb].terminator().successors().count() >= 8);
let replace_otherwise_to_unreachable = otherwise_is_last_variant
|| !otherwise_is_empty_unreachable && allowed_variants.is_empty();

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

0 comments on commit 1d9d381

Please sign in to comment.