Naming
- Classes / structs / enums:
CamelCase (MyClass, RenderPipeline)
- Functions & public vars:
snake_case (get_value, process_data)
- Private/protected members & functions:
_snake_case (_private_var, _internal_helper())
- Constants:
kCamelCase or UPPER_SNAKE_CASE for macros
- Template params:
CamelCase
- Namespaces:
luisa, luisa::compute, vstd, etc. Keep compact.
Syntax Check
Use the project C++ syntax checker:
python scripts/check_cpp_syntax.py <file>.cpp
It runs clangd with the project's compile_commands.json and .clang-tidy. Skip files not in compile_commands.json.
Formatting
Format with the project .clang-format (bundled in this skill; the project root copy is authoritative).
Base: LLVM style. Key overrides:
- Indent: 4 spaces, no tabs. Continuation indent 4. Case labels indented. Preprocessor indent 2.
- Braces: K&R (attach). No break before braces. Indent braces off.
- Line width: unlimited (
ColumnLimit: 0).
- Pointers/refs: right-aligned (
int *p, int &r).
- Access modifiers: indent offset
-4 (flush with class). Empty lines before/after left as-is.
- Short constructs: allow single-line for short blocks, functions, ifs, loops, lambdas, enums, case labels.
- Constructor init: not forced one-per-line; no break before comma.
- Templates / concepts: break declarations only when multiline; indent requires clause.
- Spaces: before
=, ctor-initializer :, inheritance :, range-for :. No space after C-style casts, !, template keyword, before braced lists. No space in empty parens or before trailing comments.
- Alignment: after open brackets & operands; don't align consecutive assignments.
- Includes/using: never auto-sort.
- Namespaces: compact single-line when short; no indentation inside (
ShortNamespaceLines: 0).
- Strings/comments: break string literals; don't reflow comments.
- Macros: control-flow-like (
$if, $elif, $else, $for, $while, $loop, $switch, $case, $default) get space before (. Function-like macros don't. Special lists:
ForEachMacros: LUISA_STRUCT, LUISA_BINDING_GROUP, LUISA_BINDING_GROUP_TEMPLATE
IfMacros: $if, $elif, $else, $for, $while, $loop, $switch, $case, $default
StatementMacros: LUISA_MAP
Static Analysis
Run .clang-tidy (bundled in this skill; the project root copy is authoritative).
All checks disabled (-*), then enabled by category:
- bugprone-*
- cert-*
- cppcoreguidelines-*
- google-* (default-arguments, explicit-constructor, runtime-operator)
- hicpp-*
- misc-*
- modernize-*
- mpi-, openmp-
- performance-*
- portability-*
- readability-*
See the bundled .clang-tidy for the exact check list.
No RTTI
RTTI is disabled for project code. Do not use:
dynamic_cast — use static_cast when type is known
typeid
std::type_info
Prefer virtual dispatch or explicit type tags for type-safe downcasting. Third-party code under src/ext is exempt.
Integer Types
Prefer fixed-width integer types:
- Use:
int32_t, uint32_t, int64_t, uint64_t, int16_t, uint16_t, int8_t, uint8_t
size_t is acceptable for sizes/indices per STL convention.
- Prefer
std::byte for raw byte data.
- Avoid
unsigned int, long long, unsigned long, short, and char for arithmetic. Some platform/system headers may define aliases such as uint; avoid introducing new uses in project code.
Verification
After editing C++ files:
# Check syntax / tidy diagnostics
python scripts/check_cpp_syntax.py src/foo.cpp
# Check formatting (dry run; replace --dry-run with -i to apply)
clang-format --dry-run --Werror src/foo.cpp
# Run clang-tidy on a specific file
clang-tidy -p build src/foo.cpp
When changing build-affecting files, configure and build a relevant target:
xmake f -m debug -c
xmake build <target>
Resources
.clang-format — bundled copy of the project formatter config.
.clang-tidy — bundled copy of the project static-analysis config.
.clangd — project root configuration for clangd diagnostics (not bundled; see project root).
1---2name: cpp-style3description: C++ naming, formatting, static analysis, and RTTI rules for LuisaCompute.4---56## Naming78- **Classes / structs / enums**: `CamelCase` (`MyClass`, `RenderPipeline`)9- **Functions & public vars**: `snake_case` (`get_value`, `process_data`)10- **Private/protected members & functions**: `_snake_case` (`_private_var`, `_internal_helper()`)11- **Constants**: `kCamelCase` or `UPPER_SNAKE_CASE` for macros12- **Template params**: `CamelCase`13- **Namespaces**: `luisa`, `luisa::compute`, `vstd`, etc. Keep compact.1415## Syntax Check1617Use the project C++ syntax checker:1819```bash20python scripts/check_cpp_syntax.py <file>.cpp21```2223It runs `clangd` with the project's `compile_commands.json` and `.clang-tidy`. Skip files not in `compile_commands.json`.2425## Formatting2627Format with the project `.clang-format` (bundled in this skill; the project root copy is authoritative).2829Base: **LLVM style**. Key overrides:3031- **Indent**: 4 spaces, no tabs. Continuation indent 4. Case labels indented. Preprocessor indent 2.32- **Braces**: K&R (attach). No break before braces. Indent braces off.33- **Line width**: unlimited (`ColumnLimit: 0`).34- **Pointers/refs**: right-aligned (`int *p`, `int &r`).35- **Access modifiers**: indent offset `-4` (flush with `class`). Empty lines before/after left as-is.36- **Short constructs**: allow single-line for short blocks, functions, ifs, loops, lambdas, enums, case labels.37- **Constructor init**: not forced one-per-line; no break before comma.38- **Templates / concepts**: break declarations only when multiline; indent requires clause.39- **Spaces**: before `=`, ctor-initializer `:`, inheritance `:`, range-for `:`. No space after C-style casts, `!`, `template` keyword, before braced lists. No space in empty parens or before trailing comments.40- **Alignment**: after open brackets & operands; don't align consecutive assignments.41- **Includes/using**: never auto-sort.42- **Namespaces**: compact single-line when short; no indentation inside (`ShortNamespaceLines: 0`).43- **Strings/comments**: break string literals; don't reflow comments.44- **Macros**: control-flow-like (`$if`, `$elif`, `$else`, `$for`, `$while`, `$loop`, `$switch`, `$case`, `$default`) get space before `(`. Function-like macros don't. Special lists:45 - `ForEachMacros`: `LUISA_STRUCT`, `LUISA_BINDING_GROUP`, `LUISA_BINDING_GROUP_TEMPLATE`46 - `IfMacros`: `$if`, `$elif`, `$else`, `$for`, `$while`, `$loop`, `$switch`, `$case`, `$default`47 - `StatementMacros`: `LUISA_MAP`4849## Static Analysis5051Run `.clang-tidy` (bundled in this skill; the project root copy is authoritative).5253All checks disabled (`-*`), then enabled by category:5455- **bugprone-***56- **cert-***57- **cppcoreguidelines-***58- **google-*** (default-arguments, explicit-constructor, runtime-operator)59- **hicpp-***60- **misc-***61- **modernize-***62- **mpi-***, **openmp-***63- **performance-***64- **portability-***65- **readability-***6667See the bundled `.clang-tidy` for the exact check list.6869## No RTTI7071RTTI is disabled for project code. Do **not** use:7273- `dynamic_cast` — use `static_cast` when type is known74- `typeid`75- `std::type_info`7677Prefer virtual dispatch or explicit type tags for type-safe downcasting. Third-party code under `src/ext` is exempt.7879## Integer Types8081Prefer fixed-width integer types:8283- Use: `int32_t`, `uint32_t`, `int64_t`, `uint64_t`, `int16_t`, `uint16_t`, `int8_t`, `uint8_t`84- `size_t` is acceptable for sizes/indices per STL convention.85- Prefer `std::byte` for raw byte data.86- Avoid `unsigned int`, `long long`, `unsigned long`, `short`, and `char` for arithmetic. Some platform/system headers may define aliases such as `uint`; avoid introducing new uses in project code.8788## Verification8990After editing C++ files:9192```bash93# Check syntax / tidy diagnostics94python scripts/check_cpp_syntax.py src/foo.cpp9596# Check formatting (dry run; replace --dry-run with -i to apply)97clang-format --dry-run --Werror src/foo.cpp9899# Run clang-tidy on a specific file100clang-tidy -p build src/foo.cpp101```102103When changing build-affecting files, configure and build a relevant target:104105```bash106xmake f -m debug -c107xmake build <target>108```109110## Resources111112- `.clang-format` — bundled copy of the project formatter config.113- `.clang-tidy` — bundled copy of the project static-analysis config.114- `.clangd` — project root configuration for clangd diagnostics (not bundled; see project root).