-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Emit a warning if a match
is too complex
#122685
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in exhaustiveness checking cc @Nadrieril |
b44b29e
to
48b4105
Compare
Some changes occurred in match checking cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
48b4105
to
99e670f
Compare
99e670f
to
adbb719
Compare
This comment has been minimized.
This comment has been minimized.
adbb719
to
117a4d2
Compare
This comment has been minimized.
This comment has been minimized.
117a4d2
to
079530a
Compare
// Default value to emit the warning for "too complex" match. We picked it based on | ||
// this crater run: <https://github.com/rust-lang/rust/pull/121979>. | ||
.or(Some(10_000_000)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Default value to emit the warning for "too complex" match. We picked it based on | |
// this crater run: <https://github.com/rust-lang/rust/pull/121979>. | |
.or(Some(10_000_000)); | |
// Default value to emit the warning for "too complex" match. We picked it to warn after a second or two. | |
.or(Some(10_000_000)); |
I don't think the crater matters much to future readers of this code, but the timing intent does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you said that limit took more like 20s on your machine? I'd be curious to crater a lower limit then, because I'm afraid people won't wait 20s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me!
Beautiful :D One last remark |
Dear T-lang, this PR adds a warning that cannot be silenced, triggered when a match takes a really long time to analyze (in the order of seconds). This is to help users figure out what's taking so long and fix it. We could make the limit configurable or the warning We're still figuring out the exact limit, but does the team approve in principle? |
079530a
to
2826060
Compare
2826060
to
d1c20e2
Compare
Updated! |
…r when complexity reaches 10_000_000
d1c20e2
to
045f417
Compare
Fixed typo. |
Those interested in pushing the limits of exhaustiveness checking may be interested in: |
☔ The latest upstream changes (presumably #128034) made this pull request unmergeable. Please resolve the merge conflicts. |
Any update here? |
No, we're still working to get to this one on our nominations list. Looking at this myself, though, one thought. I think I'd prefer it to be possible to |
This is not just a lint, it's more accurately compared to overflow in the trait system (IIUC): it's a failure condition where the compiler says "this is too hard for me" to avoid looping for unbounded time |
I don't know. It still feels lint-like to me. It's just an arbitrary limit1. When it fires, it's not saying that "this is too hard for me"2 it's saying "this might take longer to compute than an arbitrarily-decided number of cycles". So it's "linting" against code that would require more than that number of cycles. Footnotes
|
Except that if we reached the limit it's quite likely that we're hitting an exponential case, in which case the computation may need days to complete. If we can't |
Based on the results of crater run from #121979, we can safely set this limit without introducing regressions in the current rust ecosystem.
Follow-up of #121917.
r? @Nadrieril