Keep the data and its obligations visible
The source’s docs/STYLE.md is authoritative. Its base is Linux-kernel-style C++:
plain structs and free functions, with C++ facilities where they help MLIR
integration or the underlying calculations. Follow the surrounding file rather
than introducing an object hierarchy or a new registration framework.
- Use four spaces, K&R braces, and
snake_casenames. - Keep file-local functions and variables
static. - Put file-scope types, constants, and state before function definitions. Preserve initialization order for objects with runtime initializers.
- Declare function locals first, then trivial early exits, complex initialization, and the work. Declare loop-body locals before its statements.
- Use plain structs with public members and default initializers; document
members with trailing
//!<comments. Operations live in free functions. - Headers retain their license block, include guard, and declarations.
The repository also contains .clang-format; formatting does not check semantic
contracts.
Separate checks from effects
Pass dependencies explicitly. Separate calculations from CUDA, file, and process operations when that clarifies the data flow. A reusable contract checker takes explicit inputs and returns evidence or refusal; it does not mutate IR or publish an image while deciding whether that mutation is legal.
Document non-obvious contracts above the function. Keep call-site comments short
and focused on units or constraints. Reverse-engineering history, experiments,
and implementation handoffs belong under docs/.
Readability changes must preserve ABI layouts and scheduling semantics. See Compiler contracts & lessons for the obligations that survive every refactor and optimization.