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

Limit number of nonminimal_bool ops #13209

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,12 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
cx: self.cx,
};
if let Ok(expr) = h2q.run(e) {
if h2q.terminals.len() > 8 {
// QMC has exponentially slow behavior as the number of terminals increases
// 8 is reasonable, it takes approximately 0.2 seconds.
// See #825
let stats = terminal_stats(&expr);
if stats.ops > 7 {
// QMC has exponentially slow behavior as the number of ops increases.
// See #825, #13206
return;
}

let stats = terminal_stats(&expr);
let mut simplified = expr.simplify();
for simple in Bool::Not(Box::new(expr)).simplify() {
match simple {
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/nonminimal_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ fn issue_12371(x: usize) -> bool {
// Should not warn!
!x != 0
}

// Not linted because it is slow to do so
// https://github.com/rust-lang/rust-clippy/issues/13206
fn many_ops(a: bool, b: bool, c: bool, d: bool, e: bool, f: bool) -> bool {
(a && c && f) || (!a && b && !d) || (!b && !c && !e) || (d && e && !f)
}