From c975db4092728095e65ad9474f4b02798381c270 Mon Sep 17 00:00:00 2001 From: x-mass <36629999+x-mass@users.noreply.github.com> Date: Thu, 22 Feb 2024 06:33:22 +0000 Subject: [PATCH] Style adjustments --- .clang-format | 4 ++- .../nil/proof-generator/arg_parser.hpp | 14 +++++----- .../arithmetization_params.hpp | 6 ++--- .../non_type_arithmetization_params.hpp | 20 +++++++------- bin/proof-generator/src/arg_parser.cpp | 26 +++++++++---------- bin/proof-generator/src/main.cpp | 16 ++++++------ 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.clang-format b/.clang-format index ae2281eb..fea2832e 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,6 @@ --- -BasedOnStyle: WebKit +BasedOnStyle: Google +AccessModifierOffset: -4 # To keep them at the same column as `class` AlignAfterOpenBracket: BlockIndent AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false @@ -68,6 +69,7 @@ IncludeCategories: Priority: 4 - Regex: '.*' Priority: 5 +IndentAccessModifiers: false IndentCaseLabels: true IndentPPDirectives: None IndentWidth: 4 diff --git a/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp b/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp index 44b703eb..c95903a5 100644 --- a/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp +++ b/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp @@ -33,7 +33,7 @@ namespace nil { using HashesVariant = typename tuple_to_variant::type>::type; - struct prover_options { + struct ProverOptions { boost::filesystem::path proof_file_path = "proof.bin"; boost::filesystem::path preprocessed_common_data_path = "preprocessed_common_data.dat"; boost::filesystem::path circuit_file_path; @@ -41,15 +41,15 @@ namespace nil { boost::log::trivial::severity_level log_level = boost::log::trivial::severity_level::info; bool skip_verification = false; bool verification_only = false; - CurvesVariant elliptic_curve_type = type_identity {}; - HashesVariant hash_type = type_identity> {}; - columns_params columns = all_columns_params[0]; - lambda_param lambda = all_lambda_params[0]; - grind_param grind = all_grind_params[0]; + CurvesVariant elliptic_curve_type = type_identity{}; + HashesVariant hash_type = type_identity>{}; + ColumnsParams columns = all_columns_params[0]; + LambdaParam lambda = all_lambda_params[0]; + GrindParam grind = all_grind_params[0]; std::size_t expand_factor = 2; }; - std::optional parse_args(int argc, char* argv[]); + std::optional parse_args(int argc, char* argv[]); } // namespace proof_generator } // namespace nil diff --git a/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp b/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp index 2ae8b059..93f48536 100644 --- a/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp +++ b/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp @@ -31,7 +31,7 @@ namespace nil { // Available in runtime columns params. Order is: // witness | public_input | component_constant | component_selector | // lookup_constant | lookup_selector - constexpr std::array all_columns_params = {{ + constexpr std::array all_columns_params = {{ {15, 1, 5, 50, 30, 6}, {15, 1, 5, 60, 0, 0}, {15, 1, 2, 50, 14, 6}, @@ -39,12 +39,12 @@ namespace nil { // Add more params as needed. }}; - constexpr std::array all_lambda_params = { + constexpr std::array all_lambda_params = { 9 // Add more params as needed. }; - constexpr std::array all_grind_params = { + constexpr std::array all_grind_params = { 69 // Add more params as needed. }; diff --git a/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp b/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp index cc798551..a0c938e6 100644 --- a/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp +++ b/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp @@ -22,7 +22,7 @@ namespace nil { namespace proof_generator { - struct columns_params { + struct ColumnsParams { std::size_t witness_columns; std::size_t public_input_columns; std::size_t component_constant_columns; @@ -30,7 +30,7 @@ namespace nil { std::size_t lookup_constant_columns; std::size_t lookup_selector_columns; - bool operator==(const columns_params& other) const { + bool operator==(const ColumnsParams& other) const { return witness_columns == other.witness_columns && public_input_columns == other.public_input_columns && component_constant_columns == other.component_constant_columns && component_selector_columns == other.component_selector_columns @@ -41,10 +41,10 @@ namespace nil { // Need this class to be derived into actual params, so we could overload // read/write operators for parsing. - class size_t_param { + class SizeTParam { public: - size_t_param() = default; // lexical_cast wants it - constexpr size_t_param(std::size_t value) + SizeTParam() = default; // lexical_cast wants it + constexpr SizeTParam(std::size_t value) : value_(value) { } @@ -52,7 +52,7 @@ namespace nil { return value_; } - bool operator==(const size_t_param& other) const { + bool operator==(const SizeTParam& other) const { return value_ == other.value_; } @@ -60,13 +60,13 @@ namespace nil { std::size_t value_; }; - class lambda_param : public size_t_param { + class LambdaParam : public SizeTParam { public: - using size_t_param::size_t_param; + using SizeTParam::SizeTParam; }; - class grind_param : public size_t_param { + class GrindParam : public SizeTParam { public: - using size_t_param::size_t_param; + using SizeTParam::SizeTParam; }; } // namespace proof_generator diff --git a/bin/proof-generator/src/arg_parser.cpp b/bin/proof-generator/src/arg_parser.cpp index 785e2d9f..270b933e 100644 --- a/bin/proof-generator/src/arg_parser.cpp +++ b/bin/proof-generator/src/arg_parser.cpp @@ -55,7 +55,7 @@ namespace nil { } } - std::optional parse_args(int argc, char* argv[]) { + std::optional parse_args(int argc, char* argv[]) { po::options_description options("Nil; Proof Generator Options"); // Declare a group of options that will be // allowed only on command line @@ -68,7 +68,7 @@ namespace nil { ("list-columns-params", "Print available columns params"); // clang-format on - prover_options prover_options; + ProverOptions prover_options; // Declare a group of options that will be // allowed both on command line and in @@ -163,13 +163,13 @@ namespace nil { // >> and << operators are needed for Boost porgram_options to read values and // to print default values to help message: The rest of the file contains them: - std::ostream& operator<<(std::ostream& strm, const columns_params& columns) { + std::ostream& operator<<(std::ostream& strm, const ColumnsParams& columns) { auto it = std::find(all_columns_params.cbegin(), all_columns_params.cend(), columns); strm << std::distance(all_columns_params.cbegin(), it); return strm; } - std::istream& operator>>(std::istream& strm, columns_params& columns) { + std::istream& operator>>(std::istream& strm, ColumnsParams& columns) { std::string str; strm >> str; std::size_t pos; @@ -182,12 +182,12 @@ namespace nil { return strm; } - std::ostream& operator<<(std::ostream& strm, const lambda_param& lambda) { + std::ostream& operator<<(std::ostream& strm, const LambdaParam& lambda) { strm << static_cast(lambda); return strm; } - std::istream& operator>>(std::istream& strm, lambda_param& lambda) { + std::istream& operator>>(std::istream& strm, LambdaParam& lambda) { std::string str; strm >> str; std::size_t pos; @@ -196,7 +196,7 @@ namespace nil { strm.setstate(std::ios_base::failbit); } else { auto it = - std::find(all_lambda_params.cbegin(), all_lambda_params.cend(), static_cast(val)); + std::find(all_lambda_params.cbegin(), all_lambda_params.cend(), static_cast(val)); if (it != all_lambda_params.cend()) { lambda = val; } else { @@ -206,12 +206,12 @@ namespace nil { return strm; } - std::ostream& operator<<(std::ostream& strm, const grind_param& grind) { + std::ostream& operator<<(std::ostream& strm, const GrindParam& grind) { strm << static_cast(grind); return strm; } - std::istream& operator>>(std::istream& strm, grind_param& grind) { + std::istream& operator>>(std::istream& strm, GrindParam& grind) { std::string str; strm >> str; std::size_t pos; @@ -219,7 +219,7 @@ namespace nil { if (pos < str.size() || val < 0) { strm.setstate(std::ios_base::failbit); } else { - auto it = std::find(all_grind_params.cbegin(), all_grind_params.cend(), static_cast(val)); + auto it = std::find(all_grind_params.cbegin(), all_grind_params.cend(), static_cast(val)); if (it != all_grind_params.cend()) { grind = val; } else { @@ -253,17 +253,17 @@ namespace nil { std::istream& operator>>(std::istream& strm, VARIANT_TYPE& variant) { \ std::string str; \ strm >> str; \ - auto l = [&str, &strm]() { \ + auto l = [&str, &strm]() -> VARIANT_TYPE { \ STRING_TO_TYPE_LINES \ strm.setstate(std::ios_base::failbit); \ - return std::variant_alternative_t<0, VARIANT_TYPE>(); \ + return VARIANT_TYPE(); \ }; \ variant = l(); \ return strm; \ } #define STRING_TO_TYPE(TYPE, NAME) \ if (NAME == str) \ - return type_identity {}; + return type_identity{}; #define CURVE_TYPES X(nil::crypto3::algebra::curves::pallas, "pallas") #define X(type, name) TYPE_TO_STRING(type, name) diff --git a/bin/proof-generator/src/main.cpp b/bin/proof-generator/src/main.cpp index f4c2925a..1a9515b3 100644 --- a/bin/proof-generator/src/main.cpp +++ b/bin/proof-generator/src/main.cpp @@ -36,7 +36,7 @@ template< std::size_t LambdaParamIdx, typename HashType, std::size_t GridParamIdx> -int run_prover(const nil::proof_generator::prover_options& prover_options) { +int run_prover(const nil::proof_generator::ProverOptions& prover_options) { auto prover_task = [&] { auto prover = nil::proof_generator::Prover( prover_options.circuit_file_path, @@ -63,7 +63,7 @@ int run_prover(const nil::proof_generator::prover_options& prover_options) { // but this would lead to callback hell. Instead, we declare extra function for // each factor. Last declared function starts the chain. template -int grind_param_wrapper(const prover_options& prover_options) { +int grind_param_wrapper(const ProverOptions& prover_options) { int ret; auto run_prover_void = [&prover_options, &ret]() { ret = run_prover(prover_options); @@ -73,7 +73,7 @@ int grind_param_wrapper(const prover_options& prover_options) { } template -int hash_wrapper(const prover_options& prover_options) { +int hash_wrapper(const ProverOptions& prover_options) { int ret; auto run_prover_wrapper = [&prover_options, &ret]() { using HashType = typename HashTypeIdentity::type; @@ -84,7 +84,7 @@ int hash_wrapper(const prover_options& prover_options) { } template -int lambda_param_wrapper(const prover_options& prover_options) { +int lambda_param_wrapper(const ProverOptions& prover_options) { int ret; auto hash_wrapper_void = [&prover_options, &ret]() { ret = hash_wrapper(prover_options); @@ -94,7 +94,7 @@ int lambda_param_wrapper(const prover_options& prover_options) { } template -int columns_params_wrapper(const prover_options& prover_options) { +int columns_params_wrapper(const ProverOptions& prover_options) { int ret; auto columns_params_wrapper_void = [&prover_options, &ret]() { ret = lambda_param_wrapper(prover_options); @@ -106,7 +106,7 @@ int columns_params_wrapper(const prover_options& prover_options) { return ret; } -int curve_wrapper(const prover_options& prover_options) { +int curve_wrapper(const ProverOptions& prover_options) { int ret; auto curves_wrapper_void = [&prover_options, &ret]() { using CurveType = typename CurveTypeIdentity::type; @@ -116,12 +116,12 @@ int curve_wrapper(const prover_options& prover_options) { return ret; } -int initial_wrapper(const prover_options& prover_options) { +int initial_wrapper(const ProverOptions& prover_options) { return curve_wrapper(prover_options); } int main(int argc, char* argv[]) { - std::optional prover_options = nil::proof_generator::parse_args(argc, argv); + std::optional prover_options = nil::proof_generator::parse_args(argc, argv); if (!prover_options) { // Action has already taken a place (help, version, etc.) return 0;