From 18c0e70ccf2678cd2472dcd6935f106485f0bf41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 13 Jan 2021 13:57:09 +0100 Subject: [PATCH 1/3] [yulopti] Print options in column-wise rather than row-wise --- test/tools/yulopti.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index 4a14e18e4..eb6b09a89 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -43,14 +43,20 @@ #include +#include #include +#include +#include +#include + #include #include #include #include using namespace std; +using namespace ranges; using namespace solidity; using namespace solidity::util; using namespace solidity::langutil; @@ -102,24 +108,14 @@ public: size_t _columns ) { - auto hasShorterString = [](auto const& a, auto const& b){ return a.second.size() < b.second.size(); }; - size_t longestDescriptionLength = max( + yulAssert(_columns > 0, ""); + + auto hasShorterString = [](auto const& a, auto const& b) { return a.second.size() < b.second.size(); }; + size_t longestDescriptionLength = std::max( max_element(_optimizationSteps.begin(), _optimizationSteps.end(), hasShorterString)->second.size(), max_element(_extraOptions.begin(), _extraOptions.end(), hasShorterString)->second.size() ); - size_t index = 0; - auto printPair = [&](auto const& optionAndDescription) - { - cout << optionAndDescription.first << ": "; - cout << setw(static_cast(longestDescriptionLength)) << setiosflags(ios::left); - cout << optionAndDescription.second << " "; - - ++index; - if (index % _columns == 0) - cout << endl; - }; - for (auto const& optionAndDescription: _extraOptions) { yulAssert( @@ -131,11 +127,19 @@ public: "OptimiserSuite::stepNameToAbbreviationMap() and not realizing that it's used by yulopti.\n" "Please update the code to use a different character and recompile yulopti." ); - printPair(optionAndDescription); } - for (auto const& abbreviationAndName: _optimizationSteps) - printPair(abbreviationAndName); + vector> sortedOptions = views::concat(_optimizationSteps, _extraOptions); + + yulAssert(sortedOptions.size() > 0, ""); + size_t rows = (sortedOptions.size() - 1) / _columns + 1; + for (size_t row = 0; row < rows; ++row) + { + for (auto const& [key, name]: sortedOptions | views::drop(row) | views::stride(rows)) + cout << key << ": " << setw(static_cast(longestDescriptionLength)) << setiosflags(ios::left) << name << " "; + + cout << endl; + } } void runInteractive(string source) From 88a7dddfbd45d6679c671fb6d01d62ff7c804bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 14 Jan 2021 17:09:04 +0100 Subject: [PATCH 2/3] [yulopti] Sort options by step name, with special options on top of the list --- test/tools/yulopti.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index eb6b09a89..b30c439ca 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -46,10 +46,13 @@ #include #include +#include +#include #include #include #include +#include #include #include #include @@ -129,7 +132,16 @@ public: ); } - vector> sortedOptions = views::concat(_optimizationSteps, _extraOptions); + vector> sortedOptions = + views::concat(_optimizationSteps, _extraOptions) | + to>>() | + actions::sort([](tuple const& _a, tuple const& _b) { + return ( + !boost::algorithm::iequals(get<1>(_a), get<1>(_b)) ? + boost::algorithm::lexicographical_compare(get<1>(_a), get<1>(_b), boost::algorithm::is_iless()) : + tolower(get<0>(_a)) < tolower(get<0>(_b)) + ); + }); yulAssert(sortedOptions.size() > 0, ""); size_t rows = (sortedOptions.size() - 1) / _columns + 1; @@ -161,7 +173,8 @@ public: } map const& abbreviationMap = OptimiserSuite::stepAbbreviationToNameMap(); map const& extraOptions = { - {'#', "quit"}, + // QUIT starts with a non-letter character on purpose to get it to show up on top of the list + {'#', ">>> QUIT <<<"}, {',', "VarNameCleaner"}, {';', "StackCompressor"} }; From 0f75582e128ca980afec9dfb6714419325ec9277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 14 Jan 2021 17:11:37 +0100 Subject: [PATCH 3/3] [yulopti] Rewrite the check against overlapping abbreviations using ranges-v3 --- test/tools/yulopti.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index b30c439ca..469d7964a 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -44,13 +44,17 @@ #include #include +#include #include #include #include #include #include +#include +#include #include +#include #include #include @@ -119,18 +123,19 @@ public: max_element(_extraOptions.begin(), _extraOptions.end(), hasShorterString)->second.size() ); - for (auto const& optionAndDescription: _extraOptions) - { - yulAssert( - _optimizationSteps.count(optionAndDescription.first) == 0, - "ERROR: Conflict between yulopti controls and Yul optimizer step abbreviations.\n" - "Character '" + string(1, optionAndDescription.first) + "' is assigned to both " + - optionAndDescription.second + " and " + _optimizationSteps.at(optionAndDescription.first) + " step.\n" - "This is most likely caused by someone adding a new step abbreviation to " - "OptimiserSuite::stepNameToAbbreviationMap() and not realizing that it's used by yulopti.\n" - "Please update the code to use a different character and recompile yulopti." - ); - } + vector overlappingAbbreviations = + ranges::views::set_intersection(_extraOptions | views::keys, _optimizationSteps | views::keys) | + views::transform([](char _abbreviation){ return string(1, _abbreviation); }) | + to(); + + yulAssert( + overlappingAbbreviations.empty(), + "ERROR: Conflict between yulopti controls and the following Yul optimizer step abbreviations: " + + boost::join(overlappingAbbreviations, ", ") + ".\n" + "This is most likely caused by someone adding a new step abbreviation to " + "OptimiserSuite::stepNameToAbbreviationMap() and not realizing that it's used by yulopti.\n" + "Please update the code to use a different character and recompile yulopti." + ); vector> sortedOptions = views::concat(_optimizationSteps, _extraOptions) |