Add linters for C10_UNUSED and C10_NODISCARD (#140302)

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/140302
Approved by: https://github.com/Skylion007
This commit is contained in:
Edward Z. Yang
2024-11-11 14:54:46 -05:00
committed by PyTorch MergeBot
parent 263a5bf95e
commit 4e487eda7a
2 changed files with 47 additions and 1 deletions

View File

@ -444,6 +444,52 @@ command = [
'@{{PATHSFILE}}'
]
[[linter]]
code = 'C10_UNUSED'
include_patterns = [
'**/*.cpp',
'**/*.h',
]
exclude_patterns = [
'c10/macros/Macros.h',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=C10_UNUSED',
'--linter-name=C10_UNUSED',
'--error-name=deprecated C10_UNUSED macro',
'--replace-pattern=s/C10_UNUSED/[[maybe_unused]]/',
"""--error-description=\
Deprecated macro, use [[maybe_unused]] directly\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'C10_NODISCARD'
include_patterns = [
'**/*.cpp',
'**/*.h',
]
exclude_patterns = [
'c10/macros/Macros.h',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=C10_NODISCARD',
'--linter-name=C10_NODISCARD',
'--error-name=deprecated C10_NODISCARD macro',
'--replace-pattern=s/C10_NODISCARD/[[nodiscard]]/',
"""--error-description=\
Deprecated macro, use [[nodiscard]] directly\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'INCLUDE'
include_patterns = [

View File

@ -233,7 +233,7 @@ static void xss_sort_kernel(
}
if (values_dim_stride == 1 && indices_dim_stride == 1){
for (const auto i C10_UNUSED : c10::irange(n)) {
for (const auto i [[maybe_unused]] : c10::irange(n)) {
x86simdsortStatic::keyvalue_qsort<scalar_t, index_t>(
reinterpret_cast<scalar_t*>(values_data_bytes),
reinterpret_cast<index_t*>(indices_data_bytes),