Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enables clang-tidy as a lint check in the preci-lint-check CI job. It removes the dependency on a build directory (compile_commands.json), clones PyTorch headers for include paths, bumps the clang-tidy binary version to 19.1.4, and suppresses known issues in the .clang-tidy config. Several source files also have duplicate/unnecessary includes removed.
Changes:
- Removed build-dir dependency from clang-tidy linter, using
PYTORCH_ROOTenv var and SYCL include discovery instead - Updated
.clang-tidyconfig to disable many additional checks (known issues) and bumped the clang-tidy S3 binary to version 19.1.4 (Linux only, Darwin entries removed) - Cleaned up duplicate
#includedirectives across multiple source files
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.clang-tidy |
Expanded list of disabled checks; removed Darwin-specific LineFilter |
tools/linter/adapters/clangtidy_linter.py |
Replaced scm_root() with PYTORCH_ROOT env var; removed build-dir logic; added SYCL include dir; suppressed clang-diagnostic-error |
tools/linter/adapters/s3_init_config.json |
Bumped clang-tidy to 19.1.4; removed Darwin entries |
.lintrunner.toml |
Removed --build_dir argument |
.github/workflows/pull.yml |
Added PyTorch checkout step for headers; enabled CLANGTIDY in lint |
src/ATen/native/xpu/** (multiple files) |
Removed duplicate/unnecessary #include directives |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR enables the clang-tidy linter job in the preci-lint-check CI workflow. It removes the dependency on a build directory (compile_commands.json), clones PyTorch for headers, updates the clang-tidy binary version, cleans up duplicate/unused includes found by the linter, and expands the .clang-tidy suppression list to skip known issues.
Changes:
- Rewires
clangtidy_linter.pyto use aPYTORCH_ROOTenv variable instead of scanning for SCM root, removes build-dir dependency, adds system include paths, and silently skipsclang-diagnostic-errordiagnostics. - Updates
.clang-tidyconfiguration with many additional check suppressions and bumps the clang-tidy binary ins3_init_config.jsonfrom 17.0.6 to 19.1.4 (Linux only, Darwin entries removed). - Cleans up duplicate/unused
#includedirectives across ~10 source files and enablesCLANGTIDYin the CI workflow alongsideCLANGFORMAT.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.clang-tidy |
Expanded suppression list for known issues, sorted checks, removed LineFilter |
tools/linter/adapters/clangtidy_linter.py |
Replaced SCM root detection with PYTORCH_ROOT env var, removed build-dir dependency, updated include paths |
tools/linter/adapters/s3_init_config.json |
Bumped clang-tidy to 19.1.4, removed Darwin entries |
.lintrunner.toml |
Removed --build_dir argument from clang-tidy linter config |
.github/workflows/pull.yml |
Added PyTorch checkout step, enabled CLANGTIDY in Clang lint step |
src/ATen/native/xpu/sycl/UpSampleNearest1dKernels.cpp |
Removed duplicate include |
src/ATen/native/xpu/sycl/UnaryComplexKernels.cpp |
Removed duplicate includes |
src/ATen/native/xpu/sycl/RepeatKernel.cpp |
Removed duplicate include |
src/ATen/native/xpu/sycl/MultinomialKernel.cpp |
Removed duplicate include |
src/ATen/native/xpu/sycl/LossNLLKernel.cpp |
Removed unused include |
src/ATen/native/xpu/sycl/DistributionTemplates.h |
Removed unused include |
src/ATen/native/xpu/sycl/AveragePool2dKernels.cpp |
Removed duplicate include |
src/ATen/native/xpu/Resize.cpp |
Removed duplicate include |
src/ATen/native/xpu/ForeachOpScalarList.cpp |
Removed unused includes |
src/ATen/native/xpu/Activation.cpp |
Removed duplicate include |
src/ATen/native/sparse/xpu/sycl/SparseSoftmaxKernels.cpp |
Removed unused include |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@guangyey, @chuanqi129 could you please take a look? I wonder if CLANGTIDY should be on-demand workflow or integrated directly in |
|
Hi @Silv3S, let's add it into current lint check job by default, but we need to make the test pass, whatever we skip some failures as post fix or fix them directly. And please rebase the PR to trigger the CI test |
| InheritParentConfig: true | ||
| Checks: ' | ||
| bugprone-*, | ||
| -bugprone-branch-clone, |
There was a problem hiding this comment.
This file seems different from https://github.com/pytorch/pytorch/blob/main/.clang-tidy. Could you help me understand the difference.
There was a problem hiding this comment.
Sure. In upstream config there are groups of checks enabled, for example all checks from bugprone- category, but some are failing, so individual checks can be skipped with - prefix. It totally disables the check. Also, one can use in-line comment with NOLINT(check-name) to skip particular occurrence of failed check.
Some checks are debatable and implementing them is not worth it, so explicit skip allows us to ignore one check while enabling all other checks from this category. One example is modernize-concat-nested-namespaces which enforces squashing namespaces, that is purely formatting that depends mostly on personal preferences.
If we used upstream config without modifications, CI would fail on preci-lint-check as we have more issues in codebase than upstream. That's why I extended config with few explicitly skipped checks. Now it will pass CI and guard from further regressions. I plan to create tasks to enable each check one-by-one to not introduce them in one PR.
| repository: pytorch/pytorch | ||
| path: pytorch-headers | ||
| fetch-depth: 1 | ||
| submodules: false |
There was a problem hiding this comment.
There are some code gen files that are handled in
torch-xpu-ops/.github/scripts/lintrunner.sh
Lines 37 to 38 in e3bd5f9
Please ensure these paths are matched.
There was a problem hiding this comment.
I think it would require extracting clang-tidy to separate CI job that builds PyTorch+XPU and pass compile_commands.json to linter. Currently clang-tidy only clones PyTorch (for headers) and torch-xpu-ops to lint. It doesn't build nor generate any files, and both conditions
if [[ "${CLANG}" == "1" ]]; then
if [[ -e "third_party/torch-xpu-ops/tools/linter/clang_tidy/generate_build_files.py" ]];thenare not met.
This lightweight version lets us quickly fix issues that reproduce without build dependency. It's fast so can guard any regressions in preci-lint-check stage. I agree that it should be extended to cover autogen files, but maybe it could be done in next iteration?
guangyey
left a comment
There was a problem hiding this comment.
Sounds good at this stage!
There was a problem hiding this comment.
Pull request overview
This PR enables clang-tidy as part of the preci-lint-check CI workflow and updates repository/configuration to support running it without a build directory, while also cleaning up several duplicate includes to satisfy readability-duplicate-include.
Changes:
- Enable
CLANGTIDYin the GitHub Actionspreci-lint-checkjob and check out a PyTorch repo for headers. - Update the clang-tidy adapter to remove
-p/build-dir dependency, adjust include args, and ignoreclang-diagnostic-error. - Remove a set of duplicate includes across multiple XPU/SYCL source files and expand
.clang-tidycheck configuration.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/linter/adapters/s3_init_config.json | Bumps clang-tidy binary version and updates S3 download config. |
| tools/linter/adapters/clangtidy_linter.py | Refactors clang-tidy invocation to run without a build directory and adds env-based header root configuration. |
| .lintrunner.toml | Removes the now-unused --build_dir argument from the clang-tidy command. |
| .github/workflows/pull.yml | Runs clang-tidy in CI and checks out PyTorch headers to support parsing. |
| .clang-tidy | Expands the enabled/disabled checks list and updates some options. |
| src/ATen/native/xpu/sycl/UpSampleNearest1dKernels.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/sycl/UnaryComplexKernels.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/sycl/RepeatKernel.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/sycl/MultinomialKernel.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/sycl/LossNLLKernel.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/sycl/DistributionTemplates.h | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/sycl/AveragePool2dKernels.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/Resize.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/ForeachOpScalarList.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/xpu/Activation.cpp | Removes redundant includes to satisfy duplicate-include checks. |
| src/ATen/native/sparse/xpu/sycl/SparseSoftmaxKernels.cpp | Removes redundant includes to satisfy duplicate-include checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@EikanWang any idea? |
This PR enables clang-tidy as one of checks in
preci-lint-check. Some changes were required to make it working:preci-lint-checkto have headers added to include paths,builddir, as inpreci-lint-checknothing is built yet,.clang-tidyfile,This PR also fixes
readability-duplicate-include: