75 Commits

Author SHA1 Message Date
3a66a1cb99 [clang-tidy] Exclude cppcoreguidelines-avoid-magic-numbers (#57841)
Summary:
Add cppcoreguidelines-avoid-magic-numbers exclusion to clang-tidy
Remove existing nolint warnings using following script:
```
for file in `git ls-files | grep -v \.py`; do gsed '/^ *\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)/d' -i  $file; done
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/57841

Reviewed By: samestep

Differential Revision: D28295045

Pulled By: malfet

fbshipit-source-id: 7c6e8d1213c9593f169ed3df6a916498f1a97163
2021-05-07 20:02:33 -07:00
8d5df95551 Make TensorIterator, SparseTensorMath and UnaryOps clang-tidy clean (#55087)
Summary:
Disable `cppcoreguidelines-macro-usage` as PyTorch codebase uses a lots
of macros that violate this rule.

Disable `bugprone-reserved-identifier` and
`performance-unnecessary-value-param` as those checks are very slow

Add `NOLINT` to DEFINE_DISPATCH as it introduces non-const global variables
Replace `for(auto i = 0; i < lim; ++i)` with `for(auto i: c10::irange(lim))` throughout the modified files

Pull Request resolved: https://github.com/pytorch/pytorch/pull/55087

Reviewed By: samestep

Differential Revision: D27475822

Pulled By: malfet

fbshipit-source-id: 2651a4b3dc062066a15e69380354414a198fb279
2021-04-01 09:04:35 -07:00
ed0489c11a disable concat nested namespace check (#49571)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49571

Disable nested namespace check since OSS standard is
```
set(CMAKE_CXX_STANDARD 14)
```
and its currently causing confusion on clang-tidy internally such as D25214452

Test Plan: clang-tidy

Reviewed By: xuzhao9

Differential Revision: D25626392

fbshipit-source-id: 1fb472c89ebe9b83718ae27f2c1d77b8b2412b5e
2020-12-17 20:45:37 -08:00
ff0e20b384 Config inheritance was added for pytorch project (#46584)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46584

The diff enables clang-tidy config inheritance for pytorch project.

Reviewed By: suo

Differential Revision: D24418191

fbshipit-source-id: 5cc0cf2d564236cedc4333af9324387d6d7a55cc
2020-10-21 14:06:35 -07:00
40828b68e1 Revert D24099167: [HTE @ clang-tidy] Enable clang-tidy configs inheretence for caffe2 project
Test Plan: revert-hammer

Differential Revision:
D24099167 (d93cae00f2)

Original commit changeset: 2e092fe678ad

fbshipit-source-id: bbc73556a1b4d341c2db445fe4ebfb6ee6ba269f
2020-10-08 10:30:50 -07:00
d93cae00f2 [HTE @ clang-tidy] Enable clang-tidy configs inheretence for caffe2 project
Summary:
The primary HTE configuration (for `HTE@clang-tidy` project) is stored at the parent config `~/fbsource/fbcode.clang-tidy`. The diff enables inheretence of that configuration.

Note: `facebook-hte-` checks will not be used until switch to HTE2clang-tidy be made.
Note: `clang-diagnostic-*` will start work. As result clang warning messages can be dublicated: one time from HTE and another time from clang-diagnostic

Test Plan: N/A

Reviewed By: wfarner

Differential Revision: D24099167

fbshipit-source-id: 2e092fe678ad3e53a4cef301ce1cb737cf8401e7
2020-10-08 01:35:55 -07:00
92f750b5c7 disable clang-tidy modernize-trailing-return (#37888)
Summary:
too much noise from this warning
![image](https://user-images.githubusercontent.com/5086322/81123764-b6e15900-8ee8-11ea-8f2f-49d69ddde25d.png)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37888

Differential Revision: D21415338

Pulled By: Krovatkin

fbshipit-source-id: 8d6f1be11d8419fa54a18e167929100401da439a
2020-05-05 17:40:22 -07:00
0c7537c409 Fix obviously-broken .clang-tidy files (#28547)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28547

Pull Request resolved: https://github.com/pytorch/glow/pull/3672

See D18090864 for more background.  The issue i addressed there is more widespread, so i'm fixing all the other `.clang-tidy` files clearly not working as intended.

Perhaps this means it's time to lint the linter config :-)

Test Plan:
Here's the resulting output for `~/fbsource/fbcode/third-party-buck/platform007/build/llvm-fb/bin/clang-tidy` related to each file touched:

`fbcode/admarket/intent/.clang-tidy`: P119723794
`fbcode/caffe2/.clang-tidy`: P119723978
`fbcode/glow/glow/.clang-tidy`: P119724081
`fbcode/ice_palace/.clang-tidy`: P119724774
`fbcode/unified_graph/aggregator/.clang-tidy`: P119724375
`xplat/caffe2/.clang-tidy`: P119724464
`xplat/mcfcpp/.clang-tidy`:
```
[billfarner@devvm2187.ftw3 ~/fbsource/xplat/mcfcpp]  ~/fbsource/fbcode/third-party-buck/platform007/build/llvm-fb/bin/clang-tidy -explain-config
'readability-identifier-naming' is enabled in the /home/billfarner/fbsource/xplat/mcfcpp/.clang-tidy.
```

`xplat/wa-msys/mcfcpp/.clang-tidy`:
```
[billfarner@devvm2187.ftw3 ~/fbsource/xplat/wa-msys/mcfcpp]  ~/fbsource/fbcode/third-party-buck/platform007/build/llvm-fb/bin/clang-tidy -explain-config
'readability-identifier-naming' is enabled in the /home/billfarner/fbsource/xplat/wa-msys/mcfcpp/.clang-tidy.
```

Reviewed By: soumith

Differential Revision: D18092684

fbshipit-source-id: 951307d125c0346322cb2c636c0300004a48d7a9
2019-10-28 09:54:34 -07:00
640b486339 add clang-tidy to github actions (#27755)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27755

This gives us nice annotations. See
https://github.com/suo/pytorch/pull/22/files for an approximation of
what it will look like (ignore the warnings on the lint.yml file).

I deleted the old azure pipelines one since making the code work for
both was annoying, and unlike flake8 this one does not affect master

Test Plan: Imported from OSS

Differential Revision: D17888974

Pulled By: suo

fbshipit-source-id: d8928a1451b6ef500dc1889284cab2845ecdeeea
2019-10-11 17:01:50 -07:00
06c09a266b Ignore bugprone-lambda-function-name in clang-tidy. (#24190)
Summary:
Fixes: https://github.com/pytorch/pytorch/issues/23947.

In https://github.com/pytorch/pytorch/pull/23970, I ignored these in dispatch macros, but I think it's more maintainable to just block this globally.  And it's a pretty minor issue if it happens anyway.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24190

Differential Revision: D16766329

Pulled By: gchanan

fbshipit-source-id: 7ae7b7781562a8974d974f7eefa8ec7551eb09fc
2019-08-12 14:21:29 -07:00
7a61306031 Enable all clang-tidy performance checks (#15198)
Summary:
This PR adds the final set of clang-tidy checks we should add for our codebase: a last set of performance-related checks. Most fixes here are around changing `auto` to `const auto&` in a few places where unnecessary copies were made, and adding `reserve()` calls before loops doing repeated `push_back()`. Also a few cases of calling `std::string::find` with a single-character string literal instead of a single char, which uses a less efficient string search algorithm meant for searching larger substrings.

![image](https://user-images.githubusercontent.com/6429851/49978940-adc1a780-ff01-11e8-99da-a4e431361f07.png)

ezyang apaszke
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15198

Differential Revision: D13468797

Pulled By: goldsborough

fbshipit-source-id: 2bed1ea1c7c162b7f3e0e1026f17125e88c4d5b2
2018-12-14 13:32:47 -08:00
1e9c384afb Enable performance-unnecessary-value-param in .clang-tidy (#15026)
Summary:
This PR fixes around 250 places in the codebase where we were making unnecessary copies of objects (some large, some small).

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15026

Differential Revision: D13458784

Pulled By: goldsborough

fbshipit-source-id: be5148b2ce09493588d70952e6f6d6ff5ec5199b
2018-12-13 16:15:35 -08:00
d6c53328f9 Large scale fix of python-related files in torch/csrc/
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/14515

Differential Revision: D13247966

Pulled By: goldsborough

fbshipit-source-id: 7a127c508fc576a7a92626dd6b729f660162d628
2018-12-07 13:04:46 -08:00
220ce8046e Binding for prctl(PR_SET_PDEATHSIG) (#14491)
Summary:
If torch.multiprocessing.spawn is used to launch non-daemonic
processes (the default since #14391), the spawned children won't be
automatically terminated when the parent terminates.

On Linux, we can address this by setting PR_SET_PDEATHSIG, which
delivers a configurable signal to child processes when their parent
terminates.

Fixes #14394.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14491

Differential Revision: D13270374

Pulled By: pietern

fbshipit-source-id: 092c9d3c3cea2622c3766b467957bc27a1bd500c
2018-11-29 20:09:19 -08:00
0479517325 Add modernize-* checks to clang-tidy (#13196)
Summary:
Enables almost all `modernize-*` checks in clang-tidy. This warns against things such as:

- Use of `const std::string&` instead of new-style `std::string` + move,
- Using old-style loops instead of range-for loops,
- Use of raw `new`
- Use of `push_back` instead of `emplace_back`
- Use of `virtual` together with `override` (`override` is sufficient)

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/13196

Differential Revision: D12891837

Pulled By: goldsborough

fbshipit-source-id: 4d0f782a09eb391ee718d3d66f74c095ee121c09
2018-11-02 20:30:40 -07:00
27002e3fd5 Enable a few hicpp (#13189)
Summary:
Enabling three checks from ["High Integrity C++"](https://www.perforce.com/blog/qac/high-integrity-cpp-hicpp)

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/13189

Differential Revision: D12859779

Pulled By: goldsborough

fbshipit-source-id: 8ec22370dcf88618dae749a8dae0e82678e68b0e
2018-11-01 15:19:17 -07:00
6071389a90 Enable cppcoreguidelines checks in clang-tidy (#12959)
Summary:
Enables most of `cppcoreguidelines-*` checks for clang-tidy. Major fixes included:

- Uninitialized members,
- Use of `const_cast`,
- Use of raw `new`

ezyang apaszke
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12959

Differential Revision: D11349285

Pulled By: goldsborough

fbshipit-source-id: 9e24d643787dfe7ede69f96223c8c0179bd1b2d6
2018-10-29 18:23:35 -07:00
033e95765c Diff against master and enable bugprone-* checks (#12378)
Summary:
This PR:

1. Makes clang-tidy diff against `master` instead of `HEAD~1` in CI, which makes much more sense
2. Enables all checks in the `bugprone-*` category (see https://clang.llvm.org/extra/clang-tidy/checks/list.html) except one about parantheses in macros, because it doesn't always apply too well for us.

Fixed some nice code smells.

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12378

Differential Revision: D10247972

Pulled By: goldsborough

fbshipit-source-id: 97dc9e262effa6874d2854584bf41a86684eb8bd
2018-10-10 07:23:57 -07:00
bcc2a0599b Enable clang-tidy in CI (#12213)
Summary:
At long last, we will have clang-tidy enabled in CI. For a while I thought I could clean up the project enough to enable clang-tidy with all checks enabled, but I figure it's smarter to set up the minimal checks and at least have those in CI. We can fix more going forward.

ezyang apaszke
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12213

Differential Revision: D10183069

Pulled By: goldsborough

fbshipit-source-id: 7ecd2d368258f46efe23a2449c0a206d10f3a769
2018-10-03 17:25:06 -07:00
dccd0f2de6 Bag of clang tidy fixes for torch/csrc/ and torch/csrc/autograd (#11050)
Summary:
Linting `torch/csrc/` (non-recursive) and `torch/csrc/autograd` (non-recursive).

Fixed things like:
- `typedef` vs `using`
- Use `.empty()` instead of comparing with empty string/using `.size() == 0`
- Use range for loops instead of old style loops (`modernize-`)
- Remove some `virtual` + `override`
- Replace `stdint.h` with `cstdint`
- Replace `return Type(x, y)` with `return {x, y}`
- Use boolean values (`true`/`false`)  instead of numbers (1/0)
- More ...

ezyang apaszke cpuhrsch
Pull Request resolved: https://github.com/pytorch/pytorch/pull/11050

Differential Revision: D9597505

Pulled By: goldsborough

fbshipit-source-id: cb0fb4793ade885a8dbf4b10484487b84c64c7f2
2018-09-05 19:55:50 -07:00
7ddc6f84c4 NULL -> nullptr (#11047)
Summary:
How did we get so many uses of `NULL` again?

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/11047

Differential Revision: D9566799

Pulled By: goldsborough

fbshipit-source-id: 83469f352ac69aa65bdaf1a1a21f922d892e0db3
2018-08-30 16:25:42 -07:00
04939a4745 Match parameter names and = default (#9737)
Summary:
More clang tidy cleanups in `torch/csrc`. This time:

1. `hicpp-use-equals-default` recommends `= default` instead of `{}` for constructors/destructors. This is better practice because it expresses the intent better (https://stackoverflow.com/questions/6502828/what-does-default-mean-after-a-class-function-declaration)
2. `readability-inconsistent-declaration-parameter-name` enforces that parameter names in the declaration match parameter names in the definition. This is just generally useful and can prevent confusion and bugs.

Also updated my script a little bit.

apaszke ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/9737

Differential Revision: D9069069

Pulled By: goldsborough

fbshipit-source-id: f7b3f3a4eb4c9fadc30425a153566d3b613a41ae
2018-07-30 14:10:00 -07:00
18a975210d Add explicit to conversions (#9336)
Summary:
Another code-mod for clang-tidy: Conversion operators should be marked explicit so that they don't cause unwanted implicit conversions. This is especially important for `operator bool()`, see https://stackoverflow.com/questions/39995573/when-can-i-use-explicit-operator-bool-without-a-cast

ezyang apaszke
Pull Request resolved: https://github.com/pytorch/pytorch/pull/9336

Reviewed By: apaszke

Differential Revision: D8807065

Pulled By: goldsborough

fbshipit-source-id: 0e9f4ebd0048a2a510c0d05fa410695d7e977eb1
2018-07-11 12:10:30 -07:00
b12164005f [C++ API] Remove virtual forward and implement Sequential based on Any(Module) (#7508)
* Remove virtual forward

* Rebase
2018-05-24 12:46:51 -07:00
23be4ac3a2 Add clang tidy tooling (#7412) 2018-05-09 13:08:53 -04:00