PyTorch expands clang-tidy linting to cover ATen & autograd generated C++
PyTorch now lints 100% of generated C++ code, adding include paths and removing exclusions.
PyTorch's latest infrastructure commit (PR #184951) tightens code quality by bringing generated C++ code under clang-tidy's umbrella. Previously, header-only lints lacked proper include paths, causing false positives when analyzing ATen headers. The fix adds `-I` paths for `aten/src` and the build directory’s `aten/src`, ensuring `<ATen/...>` includes resolve correctly. At the same time, the patch removes the blanket exclusion of `**/generated/**` and a stale `LineFilter` that was silently suppressing warnings. The result is that all autograd and serialization-generated source files now receive the same lint scrutiny as hand-written code.
On the generation side, the codegen templates have been updated to produce cleaner, more idiomatic C++. Changes include merging multiple namespaces into single concatenated forms, initializing primitive fields with value initialization (e.g., `int x{}`), and dropping unnecessary `= {}` on non-primitive types. Move operations for `ForwardRef` are now explicitly marked `noexcept`, and setter signatures are selected based on whether the input type is movable. These steps reduce lint noise and produce code that is safer, more readable, and easier to maintain—critical for a project like PyTorch with hundreds of contributors and heavy reliance on generated code.
- Added `aten/src` and `{build_dir}/aten/src` include paths so header-only clang-tidy lints resolve `<ATen/...>` headers.
- Removed the `**/generated/**` exclusion pattern and a stale `LineFilter` from `.clang-tidy`, enabling full coverage of autograd/serde generated C++.
- Codegen templates now emit concatenated namespaces, value-initialized primitive fields, `noexcept` on ForwardRef moves, and movability-aware setter signatures.
Why It Matters
Improves code consistency and safety across PyTorch's generated C++, reducing bugs and maintenance overhead for contributors.