-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Clang-tidy check to combine locals into points #41238
Clang-tidy check to combine locals into points #41238
Conversation
98ea6e7
to
328fdda
Compare
This is an initial implementation of the idea.
Add a test for this case, which happens to occur in the CDDA code.
When naming the new point variable, remove leading or trailing underscores from the root name, so that e.g. win_x, win_y become win.x and win.y (rather than win_.x and win_.y).
When naming the new point variable, try to avoid existing names. This check won't avoid all existing names, but it's a start.
The name derivation rules could lead to naming a variable e.g. '1', which is illegal.
The new check is quite likely to conflict with itself if making multiple edits to a single function, so prevent it from doing so.
When merging some ints into a point, if the ints were static or constexpr then the point must be also.
Doing this one separately because it required a little manual intervention.
Doing headers separately to avoid edit collisions.
3d0b65b
to
6d1d88f
Compare
6d1d88f
to
9fc62e1
Compare
OK, looks like the clang-3.8 issues are now resolved. |
Is the I think you need to write it like (I get map corruption around that line...) edit: The aforementioned change makes the load corruption go away. edit: nm fixed |
Thanks for catching that. Indeed it was a bad change. Did you see other similar changes? |
Didn't notice any on a cursory grepping. I'll keep my eyes open for further crashes. :) |
Summary
SUMMARY: Infrastructure "Enforce use of points as local variables"
Purpose of change
For better type safety and code clarity.
Working towards #32017.
Describe the solution
Add a new clang-tidy check that looks for pairs (or triples) of local variables that should be merged into
point
s (ortripoint
s), and automate that conversion.On average, I think these changes are a substantial improvement; lots of cases where points were being unnecessarily decomposed and recomposed are now performed as point arithmetic directly.
Describe alternatives you've considered
Doing some subset of the changes by hand.
Testing
Most of the changes are automated, so should be low-risk.
Ran the unit tests.
Additional context
I'm expecting some compiler errors from the old clang we support (3.8), so don't merge until that looks good (it's the first Travis CI job).