-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 lint to improve floating-point expressions #4897
Add lint to improve floating-point expressions #4897
Conversation
@clarfon Hey I wanted to get the ball rolling on this issue but I have a few questions regarding how we would separate the lints. For example, should I create separate lints for The direction I was going in was creating separate lints for each of your suggestions but I am not sure if that's the right approach. |
Ignore me. I can't read. |
No, this would lint calls such as
|
Oh! I did that thing I absolutely shouldn't do which is to assume something without reading the whole thing. -___- Honestly, I feel like one lint should cover all cases for things like this. Things that have explicit specialised versions should go in one lint. (With the exception of things like Things which don't have explicit functions but are more accurate should go in a separate lint, e.g. Herbie's home page example of |
Another potential thing to consider is whether you're optimising for speed or accuracy. I'd maybe separate lints based upon that, e.g. |
5f871f8
to
42b9e14
Compare
known_log_bases
lint
@clarfon Hey I created two lints: one for better accuracy and another for performance. The expression currently linted are:
I will add lints for some of the other suggestions in your issue in a separate PR. Would love to know your thoughts/suggestions. |
Honestly, it may be worth a "always better" lint for some. For example, the log lints are pretty much the same or better for performance and better for accuracy. Ditto for the log plus one and exp minus one lints. However, changing to hypot or fused multiply-add might reduce performance, and thus is better for accuracy only. |
Yeah makes sense. Any suggestion for the lint name? |
How about Thinking about it more, we likely want the best perf and accuracy, but some people will accept perf loss for more accuracy while others will accept suboptimal accuracy for better perf. So we can either make both lints and for suggestions that don't exacerbate perf or accuracy for the respective other we lint the more likely lint unless it's disabled. Or we make a |
@llogiq Any suggestion for lints that are better for both performance and accuracy? Should I use |
Having a
|
I'd put everything that sacrifices accuracy under |
I didn't have to add the |
dca37f5
to
53ee2fb
Compare
☔ The latest upstream changes (presumably #4930) made this pull request unmergeable. Please resolve the merge conflicts. |
I agree with the grouping of the lints, but I don't like the names. E.g., My suggestions:
I'm not happy with the word #[allow(clippy::inaccurate_floating_point)]
let y = x.log(2); So it is obvious, that |
Makes sense. How about: Also having a |
I like As for the suffix, I personally like |
Could always just do flops for floating point operations |
That is more concise but isn't flops supposed to be floating point operations per second? So maybe just
|
16c03a0
to
85670af
Compare
Yes, { |
@flip1995 Hey I changed the name of the lint to suboptimal_flops as we discussed above. The reason you don't see the other lints yet( But, I looked at the implementation of these library functions and some of these are internally calling the Also, I temporarily removed the lints to improve style as there were some bugs in implementation. Ill create a separate PR for those. |
Ah ok, that's fair. As long as it is in nursery, it doesn't matter too much anyway.
I think this is part of the split up, we should do, when we "stabilize" the lint(s)
👍 I'd say with the NITs fixed, I noted above, we can merge this, and everything else can be done in a later PR(s) 👍 |
Add lints to detect floating point computations that are either inaccurate or inefficient and suggest better alternatives.
Merge the accuracy and efficiency lints into a single lint that checks for improvements to accuracy, efficiency and readability of floating-point expressions.
4c90369
to
29c49d6
Compare
Add lint to detect floating point operations that can be computed more accurately at the cost of performance. `cbrt`, `ln_1p` and `exp_m1` library functions call their equivalent cmath implementations which is slower but more accurate so moving checks for these under this new lint.
29c49d6
to
ff0d44e
Compare
@flip1995 Hey I created the |
@bors r+ Thanks! |
📌 Commit ff0d44e has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Update cargo, clippy Closes #69601 ## cargo 16 commits in e57bd02999c9f40d52116e0beca7d1dccb0643de..bda50510d1daf6e9c53ad6ccf603da6e0fa8103f 2020-02-21 20:20:10 +0000 to 2020-03-02 18:05:34 +0000 - Fix rare failure in collision_export test. (rust-lang/cargo#7956) - Ignore broken Cargo.toml in git sources (rust-lang/cargo#7947) - Add more fingerprint mtime debug logging. (rust-lang/cargo#7952) - Fix plugin tests for latest nightly. (rust-lang/cargo#7955) - Simplified usage code of SipHasher (rust-lang/cargo#7945) - Add a special case for git config discovery inside tests (rust-lang/cargo#7944) - Fixes issue rust-lang/cargo#7543 (rust-lang/cargo#7946) - Filter out cfgs which should not be used during build (rust-lang/cargo#7943) - Provide extra context on a query failure. (rust-lang/cargo#7934) - Try to clarify `cargo metadata`'s relationship with the workspace. (rust-lang/cargo#7927) - Update libgit2 dependency (rust-lang/cargo#7939) - Fix link in comment (rust-lang/cargo#7936) - Enable `cargo doc --open` tests on macos. (rust-lang/cargo#7932) - build-std: remove sysroot probe (rust-lang/cargo#7931) - Try to clarify how feature flags work on the "current" package. (rust-lang/cargo#7928) - Add extra details in the new feature resolver doc comment. (rust-lang/cargo#7918) ## clippy 6 commits in fc5d0cc..8b7f7e6 2020-02-24 05:58:17 +0000 to 2020-03-02 20:00:31 +0000 - Rustup to #69469 (rust-lang/rust-clippy#5254) - Some rustups (rust-lang/rust-clippy#5247) - Update git2 to 0.12 (rust-lang/rust-clippy#5232) - Rustup to #61812 (rust-lang/rust-clippy#5231) - Add lint to improve floating-point expressions (rust-lang/rust-clippy#4897) - Do not run deploy action on other repos (rust-lang/rust-clippy#5222)
Looks for floating-point expressions that can be expressed using built-in methods to improve accuracy, performance and/or succinctness.
changelog: Add lint
floating_point_improvements
.Fixes #4726
Partly addresses #2040
Currently linted expressions: