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 suggestion for mul_add #4602

Merged
merged 1 commit into from
Oct 8, 2019
Merged

Conversation

EthanTheMaster
Copy link
Contributor

@EthanTheMaster EthanTheMaster commented Sep 30, 2019

Issue #4001: Whenever a*b+c is found where a,b, and c are floats, a lint is suggested saying to use a.mul_add(b, c). Using mul_add may give a performance boost depending on the target architecture and also has higher numerical accuracy as there is no round off when doing a*b.

changelog: New lint: manual_mul_add

@flip1995 flip1995 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 1, 2019
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Thanks for contributing and welcome to Clippy! 🎉

LGTM overall, only some small changes and this should be good to go

clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
@EthanTheMaster
Copy link
Contributor Author

When trying to build, I got an error for a non-existent CVarArgs in rustc::hir::TyKind so I just commented it out. Did CVarArgs get removed in a new update of rustc?

@tesuji
Copy link
Contributor

tesuji commented Oct 1, 2019

Yes, you need to rebase this PR on top of master.

clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
clippy_lints/src/mul_add.rs Outdated Show resolved Hide resolved
clippy_lints/src/utils/hir_utils.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,29 @@
#![warn(clippy::manual_mul_add)]
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
#![warn(clippy::manual_mul_add)]
// run-rustfix
#![warn(clippy::manual_mul_add)]

I'm not sure if this will work, because some of the suggestions have to be applied one after another. If that's the case, just split up the test in a run-rustfix file and a non-run-rustfix file.

@EthanTheMaster
Copy link
Contributor Author

When testing whether a direct substitution of the suggestion would work, I noticed that I would sometimes get compilation errors because the type of a float (f32 or f64) could not be determined. See this demo.. Would using rustfix and MachineApplicable be fine in this scenario as substituting in the solution might give a cryptic error?

@flip1995
Copy link
Member

flip1995 commented Oct 1, 2019

Would using rustfix and MachineApplicable be fine in this scenario as substituting in the solution might give a cryptic error?

No that would be bad. You can just make it MaybeIncorrect (but split up the test cases in fixable and non-fixable). Another possibility is to only provide a suggestion if it is auto applicable (by checking for this case), but that is more work.

@EthanTheMaster
Copy link
Contributor Author

What would splitting the test cases look like? Is that something I change in the uitest file with a macro or comment?

@flip1995
Copy link
Member

flip1995 commented Oct 1, 2019

No, it's simply to make a test file for auto fixable tests and one test file for non-autofixable tests. 😉

@EthanTheMaster
Copy link
Contributor Author

So I need to make a ‘.fixed’ file containing ‘//run-rustfix’ at the top and code where the suggestions can be substituted without error?

@flip1995
Copy link
Member

flip1995 commented Oct 2, 2019

No, the *.fixed file is a auto generated file. What you need to do is

  1. Create a file tests/ui/manual_mul_add_fixable.rs and add // run-rustfix to the top (In this file are the auto fixable tests)
  2. Create a file tests/ui/manual_mul_add.rs without // run-rustfix (in this file are the tests that are not auto fixable)
  3. Run sh tests/ui/update-all-references.sh (This should create 3 files: 2 *.stderr files and one *.fixed file)

@EthanTheMaster
Copy link
Contributor Author

Thanks for the clarification. I‘ll give that a try later today. I remember, however, trying to run the update script which created the .stderr file but not the .fixed file. Is there some command I run before the update script like running rustfix or cargo test?

@flip1995
Copy link
Member

flip1995 commented Oct 2, 2019

The *.fixed file is only created if you add // run-rustfix to the top of the test (*.rs) file. So once you added that to the fixable test file, this should be created (after running cargo +master uitest+sh tests/ui/update-all-references.sh)

@phansch
Copy link
Member

phansch commented Oct 8, 2019

@bors r=flip1995

@bors
Copy link
Collaborator

bors commented Oct 8, 2019

📌 Commit 048a5f9 has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Oct 8, 2019

⌛ Testing commit 048a5f9 with merge 13b423c...

bors added a commit that referenced this pull request Oct 8, 2019
Add suggestion for mul_add

Issue #4001: Whenever `a*b+c` is found where `a`,`b`, and `c` are floats, a lint is suggested saying to use `a.mul_add(b, c)`. Using `mul_add` may give a performance boost depending on the target architecture and also has higher numerical accuracy as there is no round off when doing `a*b`.

changelog: New lint: `manual_mul_add`
@bors
Copy link
Collaborator

bors commented Oct 8, 2019

💔 Test failed - status-appveyor

@phansch
Copy link
Member

phansch commented Oct 8, 2019

@EthanTheMaster This will need a rebase as the lint count recently changed

@tesuji
Copy link
Contributor

tesuji commented Oct 8, 2019

And squashing the commits I think.

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 8, 2019
@EthanTheMaster EthanTheMaster force-pushed the issue-4001 branch 2 times, most recently from 25a4576 to f94cbac Compare October 8, 2019 13:31
@tesuji
Copy link
Contributor

tesuji commented Oct 8, 2019

You need to run ./util/dev update_lints to update the lint count.

Fixed typo

Fixes lint name and uses appropriate linting suggestion

changed lint help message

Added autofixable test

Added Autofixable Test

Removed Broken Autofixable File

updated lints

Generated Autofixable/Nonfixable Test Cases

Changed Suggestion Applicability

Updated Lint Count
@phansch
Copy link
Member

phansch commented Oct 8, 2019

@bors retry

@phansch
Copy link
Member

phansch commented Oct 8, 2019

@bors r=flip1995

@bors
Copy link
Collaborator

bors commented Oct 8, 2019

📌 Commit 327c91f has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Oct 8, 2019

⌛ Testing commit 327c91f with merge 1dc7f5c...

bors added a commit that referenced this pull request Oct 8, 2019
Add suggestion for mul_add

Issue #4001: Whenever `a*b+c` is found where `a`,`b`, and `c` are floats, a lint is suggested saying to use `a.mul_add(b, c)`. Using `mul_add` may give a performance boost depending on the target architecture and also has higher numerical accuracy as there is no round off when doing `a*b`.

changelog: New lint: `manual_mul_add`
@bors
Copy link
Collaborator

bors commented Oct 8, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: flip1995
Pushing 1dc7f5c to master...

@bors bors merged commit 327c91f into rust-lang:master Oct 8, 2019
@rye rye mentioned this pull request Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants