-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike: decide on standardization rules for circuits C++ #216
Comments
The actual standardization tickets: |
Current plan for linting is to use clang-tidy and clang-format. We will also use the clangd plugin for vscode to enable format-on-save, and to give yellow-squiggles for clang-tidy suggestions. It will not however auto-refactor according to clang-tidy suggestions on save. We will need to decide whether CI should fully enforce clang-tidy suggestions or not. And should compiler error/warn when tidy has warnings/errors? |
Draft
Draft
|
Once clang-format/clang-tidy is finalized, each standardization rule should be flagged as covered in the automatic tooling or not. |
Closing because moved to 'Done' |
Draft of C++ Standards for Aztec Circuits
/cppguide.html)
public
/protected
/private
) which can use 2snake_case
for files, namespaces and local variables/membersCamelCase
for classes, structs, enums, typesuint
orfield_ct
ALL_CAPS
forconstexpr
s, global constants, and macrosauto
*
,&
, and/orconst
even when usingauto
const
andconstexpr
const
whenever possible to express immutabilityconstexpr
whenever aconst
can be computed at compile-timeconst
/constexpr
BEFORE the core type as is done in bberg stdlibnamespace
andusing
using namespace my_namespace;
which causes namespace pollution and reduces readabilityaztec3/circuits/abis/private_kernel
:init.hpp
only for core/critical renames likeNT/CT
and for toggling core types likeComposer
namespace { ...\n } // namespace
at the very top of the file directly after#include
susing Rename = old::namespace::prefix::Name;
to import and shorten names from external namespacesusing A = A<NT>;
)std::
prefixNT::
orCT::
prefixtest.cpp
tests must always explicitly import every single name they intend to usecircuit_types
andnative_types
using
statements should be sorted case according to theLexicographicNumeric
rulesSortUsingDeclarations
section of the LLVM Clang Format Style Options document#pragma once
index.hpp
should include common headers that will be referenced by most cpp/hpp files in the current directoryinit.hpp
should inject ONLY critical renames (likeNT
/CT
) and type toggles (like Composer)using NT = aztec3::utils::types::NativeTypes;
../../other_dir
) unless they are a subdir (subdir/header.hpp
)aztec3/circuits/hash.hpp
"index.hpp"
"init.hpp"
/
)"private/private_kernel_inputs.hpp"
)/
first, relative paths second)"aztec3/constants.hpp"
)<gtest>
or other third party headers specified in.clang-format
public
,protected
,private
MyStruct my_inst{};
NT::fr my_fr = 0;
std::array<T, 8> my_arr{};
fr
are different! Usezero_array
helper function for initializationstd::array<fr, VK_TREE_HEIGHT> vk_path = zero_array<fr, VK_TREE_HEIGHT>();
fr
does have a default constructor that intentionally does not intialize its members to 0malloc/free
std::array/vector
instead ofint[]
std::unique_ptr/shared_ptr
) instead of raw pointersstatic_cast
orreinterpret_cast
)const
when they will not be modified[[nodiscard]]
if it makes no sense to call this function and discard return value_myparam
uintN_t
instead of a primitive type (e.g.size_t
) when a specific type width must be guaranteedint
,long
,char
etc) unless signedness is requirednullptr
explicit
to prevent unwanted conversionsA() = default;
instead ofA(){}
(explanation here)A(){};
(with semicolon) which can't even be auto-fixed byclang-tidy
override
when overriding a parent class' member (explanation here)std::vector::emplace_back
instead ofpush_back
std::make_pair
when usingemplace_back
(unnecessary as explained here)References
.clangd
.clang-format
TODO
More examplesCome up with a preliminary plan for using a linter/formatter for enforcing [subset of] standardsDiscuss enforcement of preconditions in wasm in lieu ofcreated ticket: Spike: Barretenbergthrow
ASSERT
should not be ignored in wasm, or workaround aztec-packages#308 (and can useDummyComposer
in circuits repo generally)Dig intocreated ticket: Renamebarretenberg_module
(to be renamedcircuits_module
or something similar) and agree on standard for where/when/how modules should be createdbarretenberg_module
aztec-packages#364Solicit feedback and refine proposed standardsDecide where this standard should livedecision:circuits/cpp/CODING_STANDARD.md
The text was updated successfully, but these errors were encountered: