Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: UninhabitedEnumBranching avoid n^2 #77597

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A pass that eliminates branches on uninhabited enum variants.

use crate::transform::MirPass;
use rustc_data_structures::stable_set::FxHashSet;
use rustc_middle::mir::{
BasicBlock, BasicBlockData, Body, Local, Operand, Rvalue, StatementKind, TerminatorKind,
};
Expand Down Expand Up @@ -52,9 +53,13 @@ fn variant_discriminants<'tcx>(
layout: &TyAndLayout<'tcx>,
ty: Ty<'tcx>,
tcx: TyCtxt<'tcx>,
) -> Vec<u128> {
) -> FxHashSet<u128> {
match &layout.variants {
Variants::Single { index } => vec![index.as_u32() as u128],
Variants::Single { index } => {
let mut res = FxHashSet::default();
res.insert(index.as_u32() as u128);
res
}
Variants::Multiple { variants, .. } => variants
.iter_enumerated()
.filter_map(|(idx, layout)| {
Expand Down