Skip to content

Commit 378338b

Browse files
author
zhangyue
committed
chore(lint): add .clang-tidy for Google-style naming enforcement
`clang-format` only enforces whitespace/braces/include order — naming violations (`BUFFER_NUM`, `dimLength`, `inQueueX1`, missing private-member trailing `_`, etc.) pass silently. This PR adds `clang-tidy` with `readability-identifier-naming.*` wired to the Google C++ Style Guide so the `code-lint` skill can catch them. - `.clang-tidy` at repo root: types `PascalCase`, functions `PascalCase`, variables / parameters `snake_case`, private members `snake_case_`, constants `kPascalCase`, macros `UPPER_CASE`, namespaces `lower_case`. Only `readability-identifier-naming.*` is `WarningsAsErrors`; the `google-*` / `modernize-*` checks are advisory. - `src/ascend/custom/.clang-tidy`: relaxes `FunctionCase` to `lower_case` because `ascendc_add_operator(OP_NAME …)` dictates snake_case kernel entry symbol names that cannot be `PascalCase`d. - `src/ascend/custom/rms_norm/op_kernel/.clang-tidy`: disables all checks for device code compiled by `ccec` (absent from `compile_commands.json`, `__aicore__` macro parses incorrectly without `kernel_operator.h`). - `pyproject.toml`: turns on `CMAKE_EXPORT_COMPILE_COMMANDS` so every editable `pip install` emits `compile_commands.json` for `clang-tidy`. - `src/device.h`: adds missing `<string>` / `<string_view>` includes — pre-existing transitive-include bug surfaced by `clang-tidy`'s stricter parsing.
1 parent 123fddc commit 378338b

5 files changed

Lines changed: 109 additions & 0 deletions

File tree

.clang-tidy

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
# Google C++ Style Guide enforcement.
3+
#
4+
# `clang-format` (via `.clang-format`) handles formatting; this file handles
5+
# everything `clang-format` cannot see — primarily identifier naming.
6+
#
7+
# Usage:
8+
# clang-tidy -p build/ --quiet <file> (needs `compile_commands.json`)
9+
#
10+
# The project's scikit-build config sets `CMAKE_EXPORT_COMPILE_COMMANDS=ON`,
11+
# so `pip install -e .[dev]` produces `build*/compile_commands.json`.
12+
#
13+
# Subdirectories may ship their own `.clang-tidy` with
14+
# `InheritParentConfig: true` to override specific rules (e.g.
15+
# `src/ascend/custom/.clang-tidy` relaxes `FunctionCase` for `extern "C"`
16+
# `AscendC` kernel entries whose symbol names are dictated by
17+
# `ascendc_add_operator(OP_NAME …)`).
18+
19+
Checks: >
20+
readability-identifier-naming,
21+
google-explicit-constructor,
22+
google-readability-braces-around-statements,
23+
google-readability-casting,
24+
modernize-use-nullptr,
25+
modernize-use-override
26+
27+
# Only naming violations fail the lint — the rest are advisory while the
28+
# project ramps up on `clang-tidy`.
29+
WarningsAsErrors: 'readability-identifier-naming.*'
30+
31+
HeaderFilterRegex: '^(src|tests)/.*\.(h|hpp|cuh)$'
32+
33+
CheckOptions:
34+
# ---------- Types ----------
35+
- {key: readability-identifier-naming.ClassCase, value: CamelCase}
36+
- {key: readability-identifier-naming.StructCase, value: CamelCase}
37+
- {key: readability-identifier-naming.UnionCase, value: CamelCase}
38+
- {key: readability-identifier-naming.EnumCase, value: CamelCase}
39+
- {key: readability-identifier-naming.TypeAliasCase, value: CamelCase}
40+
- {key: readability-identifier-naming.TypedefCase, value: CamelCase}
41+
- {key: readability-identifier-naming.TypeTemplateParameterCase, value: CamelCase}
42+
43+
# ---------- Enumerators / constants: `k` + PascalCase ----------
44+
- {key: readability-identifier-naming.EnumConstantCase, value: CamelCase}
45+
- {key: readability-identifier-naming.EnumConstantPrefix, value: 'k'}
46+
- {key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase}
47+
- {key: readability-identifier-naming.ConstexprVariablePrefix, value: 'k'}
48+
- {key: readability-identifier-naming.GlobalConstantCase, value: CamelCase}
49+
- {key: readability-identifier-naming.GlobalConstantPrefix, value: 'k'}
50+
- {key: readability-identifier-naming.StaticConstantCase, value: CamelCase}
51+
- {key: readability-identifier-naming.StaticConstantPrefix, value: 'k'}
52+
53+
# ---------- Functions / methods: PascalCase ----------
54+
- {key: readability-identifier-naming.FunctionCase, value: CamelCase}
55+
- {key: readability-identifier-naming.MethodCase, value: CamelCase}
56+
57+
# ---------- Variables / parameters: snake_case ----------
58+
- {key: readability-identifier-naming.VariableCase, value: lower_case}
59+
- {key: readability-identifier-naming.ParameterCase, value: lower_case}
60+
- {key: readability-identifier-naming.LocalVariableCase, value: lower_case}
61+
62+
# ---------- Class data members: snake_case with trailing `_` ----------
63+
- {key: readability-identifier-naming.PrivateMemberCase, value: lower_case}
64+
- {key: readability-identifier-naming.PrivateMemberSuffix, value: '_'}
65+
- {key: readability-identifier-naming.ProtectedMemberCase, value: lower_case}
66+
- {key: readability-identifier-naming.ProtectedMemberSuffix, value: '_'}
67+
- {key: readability-identifier-naming.PublicMemberCase, value: lower_case}
68+
69+
# ---------- Macros: UPPER_CASE ----------
70+
- {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}
71+
# Include guards end in a trailing `_` (e.g. `INFINI_OPS_FOO_H_`), which
72+
# the default `UPPER_CASE` style rejects — skip them by regex.
73+
- {key: readability-identifier-naming.MacroDefinitionIgnoredRegexp, value: '^INFINI_OPS_.*_H_$'}
74+
75+
# ---------- Namespaces: lower_case ----------
76+
- {key: readability-identifier-naming.NamespaceCase, value: lower_case}
77+
78+
# ---------- Exemptions ----------
79+
# Type-trait variables (`IsFP16`, `IsBFloat16`, `HasKey`, …) mirror
80+
# `std::is_*_v<>` naming — `PascalCase` without `k` prefix.
81+
- {key: readability-identifier-naming.ConstexprVariableIgnoredRegexp, value: '^(Is|Has|Can)[A-Z].*'}

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ install-dir = "infini"
1616
AUTO_DETECT_DEVICES = "ON"
1717
AUTO_DETECT_BACKENDS = "ON"
1818
GENERATE_PYTHON_BINDINGS = "ON"
19+
# Enables `compile_commands.json` under `SKBUILD_BUILD_DIR` (or the default
20+
# scikit-build build dir) for `clang-tidy -p <build-dir> <file>` used by
21+
# the `code-lint` skill.
22+
CMAKE_EXPORT_COMPILE_COMMANDS = "ON"
1923

2024
[tool.pytest.ini_options]
2125
testpaths = ["tests"]

src/ascend/custom/.clang-tidy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
# `CANN`'s `ascendc_add_operator(OP_NAME <lower_snake>)` dictates the
3+
# symbol name of the `extern "C" __global__ __aicore__ void <op>(…)`
4+
# kernel entry. The `aclrtlaunch_<op>` wrapper and `op_host/` call site
5+
# must match, so these entries cannot follow Google's `PascalCase`
6+
# convention. Relax `FunctionCase` to `lower_case` within this subtree;
7+
# class and method names still inherit `CamelCase` from the root config.
8+
9+
InheritParentConfig: true
10+
11+
CheckOptions:
12+
- {key: readability-identifier-naming.FunctionCase, value: lower_case}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# `op_kernel/*.cpp` is `AscendC` device code compiled by `ccec`, not by
3+
# the host toolchain, so it has no entry in `compile_commands.json` and
4+
# `clang-tidy` cannot parse it correctly (the `__aicore__` macro expands
5+
# unexpectedly when `kernel_operator.h` is absent). Disable all checks
6+
# here — the `op_host/` side and the `kernel_custom.h` launcher still
7+
# enforce the full ruleset.
8+
9+
Checks: '-*'

src/device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef INFINI_OPS_DEVICE_H_
22
#define INFINI_OPS_DEVICE_H_
33

4+
#include <string>
5+
#include <string_view>
6+
47
#include "common/constexpr_map.h"
58
#include "common/traits.h"
69
#include "hash.h"

0 commit comments

Comments
 (0)