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

Add new pattern_complexity attribute to add possibility to limit and check recursion in pattern matching #121917

Merged
merged 3 commits into from
Mar 3, 2024

Conversation

GuillaumeGomez
Copy link
Member

Needed for rust-lang/rust-analyzer#9528.

This PR adds a new attribute only available when running rust testsuite called pattern_complexity which allows to set the maximum recursion for the pattern matching. It is quite useful to ensure the complexity doesn't grow, like in tests/ui/pattern/usefulness/issue-118437-exponential-time-on-diagonal-match.rs.

r? @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 2, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 2, 2024

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred in exhaustiveness checking

cc @Nadrieril

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Nadrieril
Copy link
Member

Could you add a test that ensures the new attribute is internal-only? Like we do for feature gates:

#![pattern_complexity = "60"]
//~^ ERROR: internal attribute
fn main() {}

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the pattern-complexity_limit.rs branch 2 times, most recently from c962905 to dd1c55b Compare March 2, 2024 22:17
@GuillaumeGomez
Copy link
Member Author

Could you add a test that ensures the new attribute is internal-only? Like we do for feature gates:

#![pattern_complexity = "60"]
//~^ ERROR: internal attribute
fn main() {}

CI caught this one but good catch! ;)

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the pattern-complexity_limit.rs branch 2 times, most recently from c151ec2 to 0216123 Compare March 3, 2024 10:27
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the pattern-complexity_limit.rs branch 2 times, most recently from 9ef241b to 1e10212 Compare March 3, 2024 10:48
Comment on lines 746 to 747
.map(|complexity_limit| complexity_limit < self.complexity_level)
.unwrap_or(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map(|complexity_limit| complexity_limit < self.complexity_level)
.unwrap_or(false)
.is_some_and(|complexity_limit| complexity_limit < self.complexity_level)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a new clippy lint for this if it doesn't exist. :o

@Nadrieril
Copy link
Member

Amazing, thank you! r=me with or without the last suggestion

@GuillaumeGomez
Copy link
Member Author

@bors r=Nadrieril rollup

@bors
Copy link
Contributor

bors commented Mar 3, 2024

📌 Commit f04c5c5 has been approved by Nadrieril

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 3, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2024
…llaumeGomez

Rollup of 3 pull requests

Successful merges:

 - rust-lang#121917 (Add new `pattern_complexity` attribute to add possibility to limit and check recursion in pattern matching)
 - rust-lang#121933 (Add missing get_name for wasm::thread.)
 - rust-lang#121934 (rustc_log: expose tracing-tree "wraparound" in an env var)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7d8f74f into rust-lang:master Mar 3, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2024
Rollup merge of rust-lang#121917 - GuillaumeGomez:pattern-complexity_limit.rs, r=Nadrieril

Add new `pattern_complexity` attribute to add possibility to limit and check recursion in pattern matching

Needed for rust-lang/rust-analyzer#9528.

This PR adds a new attribute only available when running rust testsuite called `pattern_complexity` which allows to set the maximum recursion for the pattern matching. It is quite useful to ensure the complexity doesn't grow, like in `tests/ui/pattern/usefulness/issue-118437-exponential-time-on-diagonal-match.rs`.

r? `@Nadrieril`
@GuillaumeGomez GuillaumeGomez deleted the pattern-complexity_limit.rs branch March 3, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants