-
Notifications
You must be signed in to change notification settings - Fork 27
Incremental clang-tidy fixes #213
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
Changes from all commits
5df197d
ec37233
71e04fa
1d0b5c9
1ac96c9
eea0e03
9c20b2d
324b7d7
9036c08
8407e41
338c024
f29d08e
e918805
487cb9f
733f89d
d9a0bbc
0df760a
28e8075
28b89ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
--- | ||
|
||
# | ||
# Clang-tidy configuration for Zeth | ||
# This file follows the YAML syntax, see: https://yaml.org/spec/ | ||
|
@@ -27,7 +25,43 @@ | |
# flexible. We consider this negligible compared to the benefits of | ||
# manipulating variables that are explicitly typed. | ||
# | ||
Checks: > | ||
# -modernize-use-trailing-return-type, | ||
# -modernize-return-braced-init-list, | ||
# These are removed since they conflict with the current code style. | ||
# | ||
# -modernize-pass-by-value | ||
# -modernize-deprecated-headers | ||
# -modernize-use-default-member-init | ||
# -readability-redundant-member-init | ||
# -bugprone-exception-escape | ||
# These conflict with the current code style, or would require larger | ||
# changes. May wish to review in the future. | ||
# | ||
# -readability-magic-numbers | ||
# Disabled for now as it picks up some constants which don't necessarily need | ||
# their own variables (for some trivial multiplication and masking) and some | ||
# test data. May wish to review in the future. | ||
# | ||
# -readability-implicit-bool-conversion | ||
# We use implicit bool conversion for specifying many constants in terms of | ||
# `0` and `1`. (TODO: it may be a good idea to enable this to fix implicit | ||
# conversion in conditions). | ||
# | ||
# -readability-named-parameter, | ||
# We occasionally omit the name of a parameter in a function definition if the | ||
# parameter is unused, and avoid a compiler warning. This check complains | ||
# in these cases. | ||
# | ||
# -readability-identifier-naming | ||
# TODO: Retry this (attempts to customize this to our standards failed under | ||
# clang-tidy-10 - see CheckOptions below). | ||
# | ||
# -misc-non-private-member-variables-in-classes, | ||
# TODO: Public member variables are often used in our code, and in | ||
# dependencies. There is a good argument for not exposing these. Decide on a | ||
# policy and update this comment. | ||
|
||
Checks: | ||
-*, | ||
bugprone-*, | ||
llvm-*, | ||
|
@@ -38,30 +72,45 @@ Checks: > | |
readability-*, | ||
-modernize-avoid-c-arrays, | ||
-modernize-use-bool-literals, | ||
-modernize-use-auto | ||
-modernize-use-auto, | ||
-modernize-use-trailing-return-type, | ||
-readability-magic-numbers, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use "magic numbers" in many places? I like this check actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general it's pretty good, but picks up a few bits of test data and some numbers in expressions (masking expressions, etc) which don't really warrant a whole separate constant. It would be nice if it was a tiny bit less sensitive, so we may want to revisit in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks |
||
-readability-implicit-bool-conversion, | ||
-modernize-return-braced-init-list, | ||
-readability-named-parameter, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use functions with unnamed arguments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in the case of unused parameters we remove the name to stop the compiler complaining. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes right... |
||
-modernize-pass-by-value, | ||
-modernize-use-default-member-init, | ||
-bugprone-exception-escape, | ||
-misc-non-private-member-variables-in-classes, | ||
-readability-redundant-member-init, | ||
-modernize-deprecated-headers, | ||
-readability-identifier-naming, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see that you have disabled many checks here, which is fine (if we can't do otherwise for now). I think it would be nice to add a few lines about why each check has been disabled (as I started to do above) in order to make it crystal clear that we have a reason to remove the checks. Eg. If we have a lot of magic numbers (in the tests for eg) we can add a line to say "-readability-magic-numbers is removed because we have a lot of magic numbers in the tests [...]". Likewise, I imagine that you removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some comments about the disabled checks. |
||
|
||
WarningsAsErrors: | ||
'*' | ||
|
||
HeaderFilterRegex: 'libzeth/*.(h|hpp|cpp)' | ||
|
||
CheckOptions: | ||
- key: readability-identifier-naming.MacroDefinitionCase | ||
value: UPPER_CASE | ||
- key: readability-identifier-naming.StaticConstantCase | ||
value: UPPER_CASE | ||
- key: readability-identifier-naming.ConstantParameterCase | ||
value: lower_case | ||
- key: readability-identifier-naming.FunctionCase | ||
value: lower_case | ||
- key: readability-identifier-naming.VariableCase | ||
value: lower_case | ||
- key: readability-identifier-naming.ClassCase | ||
value: lower_case | ||
- key: readability-identifier-naming.ClassMemberCase | ||
value: lower_case | ||
- key: readability-identifier-naming.NamespaceCase | ||
value: lower_case | ||
- key: readability-identifier-naming.TemplateParameterCase | ||
value: CamelCase | ||
- key: readability-identifier-naming.TemplateParameterSuffix | ||
value: T | ||
- key: readability-implicit-bool-conversion.AllowIntegerConditions | ||
value: '1' | ||
# CheckOptions: | ||
# - key: readability-identifier-naming.MacroDefinitionCase | ||
# value: UPPER_CASE | ||
# - key: readability-identifier-naming.StaticConstantCase | ||
# value: UPPER_CASE | ||
# - key: readability-identifier-naming.ConstantParameterCase | ||
# value: lower_case | ||
# - key: readability-identifier-naming.FunctionCase | ||
# value: lower_case | ||
# - key: readability-identifier-naming.VariableCase | ||
# value: lower_case | ||
# - key: readability-identifier-naming.ClassCase | ||
# value: lower_case | ||
# - key: readability-identifier-naming.ClassMemberCase | ||
# value: lower_case | ||
# - key: readability-identifier-naming.NamespaceCase | ||
# value: lower_case | ||
# - key: readability-identifier-naming.TemplateParameterCase | ||
# value: CamelCase | ||
# - key: readability-identifier-naming.TemplateParameterSuffix | ||
# value: T | ||
# - key: readability-implicit-bool-conversion.AllowIntegerConditions | ||
# value: '1' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Errors and Warnings to Suppress CEB7 span> | ||
useStlAlgorithm:* | ||
|
||
// This raises some false positives, and inline suppressions seem not to work | ||
unusedFunction:* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Disable all checks. | ||
# (Dummy check here prevents error from clang-tidy) | ||
Checks: '-*,misc-definitions-in-headers' | ||
CheckOptions: | ||
- { key: HeaderFileExtensions, value: "x" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,66 +25,67 @@ template<typename FieldT> class BLAKE2s_256 : public libsnark::gadget<FieldT> | |
{ | ||
private: | ||
// Parameter block, size set to 32 bytes, fanout and depth set to serial | ||
// mode. See: Section 2.8 https://blake2.net/blake2.pdf Table 2 | ||
std::array<std::array<bool, BLAKE2s_word_size>, 8> parameter_block = { | ||
// mode. See: Section 2.8 https://blake2.net/blake2.pdf Table 2. Note, byte | ||
// endianness has been swapped to avoid doing this repeatedly at runtime. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by "to avoid doing this repeatedly at runtime"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, these constants were endian-swappd before being used (see the .tcc file), and this swap was happening for every invocation of
It refers to the byte swapping. After this change, it's swapped in the static data, so it doesn't have to be done many times when running the proof gen. (I also put the comment for anyone looking at the reference above, in case they see a discrepency in the order). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, I see. The parameter block structure was taken from Table 2. https://blake2.net/blake2.pdf and since blake processed byte strings as little endian the endianness needed to be switched. |
||
const std::array<const bits<BLAKE2s_word_size>, 8> parameter_block = { | ||
{{ | ||
// Digest byte length, Key byte length, Fanout, Depth | ||
0, 0, 1, 0, 0, 0, 0, 0, // 0x20 (32 bytes) | ||
0, 0, 0, 0, 0, 0, 0, 0, // 0x00 (key length) | ||
0, 0, 0, 0, 0, 0, 0, 1, // 0x01 (depth 1) | ||
0, 0, 0, 0, 0, 0, 0, 1, // 0x01 (fanout 1) | ||
0, 0, 0, 0, 0, 0, 0, 1 // 0x01 (depth 1) | ||
0, 0, 0, 0, 0, 0, 0, 0, // 0x00 (key length) | ||
0, 0, 1, 0, 0, 0, 0, 0, // 0x20 (32 bytes) | ||
}, | ||
{ | ||
// Leaf length | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
}, | ||
{ | ||
// Node offset | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
}, | ||
{ | ||
// Node offset (cont.), Node depth, Inner length | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 (inner length) | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 (node depth) | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 (node depth) | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 (inner length) | ||
}, | ||
{ | ||
// Salt | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
}, | ||
{ | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
}, | ||
{ | ||
// Personalization | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
}, | ||
{ | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0 // 00 | ||
0, 0, 0, 0, 0, 0, 0, 0, // 00 | ||
}}}; | ||
|
||
// See: Appendix A.2 of https://blake2.net/blake2.pdf for the specification | ||
// of the IV used in BLAKE2s | ||
std::array<std::array<bool, BLAKE2s_word_size>, 8> BLAKE2s_IV = { | ||
std::array<bits<BLAKE2s_word_size>, 8> BLAKE2s_IV = { | ||
{{ | ||
0, 1, 1, 0, 1, 0, 1, 0, // 6A | ||
0, 0, 0, 0, 1, 0, 0, 1, // 09 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can enable this check bu we will need to add a lot of
NOLINT
comments to disable the checks when we use pb_variable_arrays of booleans (like in blake/sha). This is what I did on #212