From 620ec47efb12e0b2a1ca49e8725a6e8c43e51a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 6 Oct 2021 16:00:16 +0200 Subject: [PATCH] OptimizerSuite: Rewrite runSequence() with support for nested brackets --- Changelog.md | 2 + libyul/optimiser/Suite.cpp | 108 +++-- libyul/optimiser/Suite.h | 7 +- .../args | 0 .../in.sol | 0 .../input.json | 16 + .../output.json | 9 + .../args | 0 .../in.sol | 0 .../input.json | 16 + .../output.json | 4 +- .../args | 1 + .../in.sol | 6 + .../input.json | 4 +- .../output.json | 0 .../args | 1 + .../in.sol | 6 + .../input.json | 2 +- .../output.json | 12 + .../yul_optimizer_steps_invalid_nesting/args | 1 - .../yul_optimizer_steps_invalid_nesting/err | 1 - .../yul_optimizer_steps_nested_brackets/args | 1 + .../input.sol | 0 .../output | 433 ++++++++++++++++++ .../yul_optimizer_steps_nesting_too_deep/args | 1 + .../yul_optimizer_steps_nesting_too_deep/err | 1 + .../exit | 0 .../input.sol | 0 .../args | 1 + .../err | 0 .../exit | 0 .../input.sol | 7 + .../args | 0 .../err | 1 + .../exit | 1 + .../input.sol | 7 + 36 files changed, 602 insertions(+), 47 deletions(-) rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_invalid_nesting => standard_optimizer_yulDetails_optimiserSteps_nested_brackets}/args (100%) rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_invalid_nesting => standard_optimizer_yulDetails_optimiserSteps_nested_brackets}/in.sol (100%) create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/input.json create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/output.json rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket => standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep}/args (100%) rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket => standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep}/in.sol (100%) create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/input.json rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_invalid_nesting => standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep}/output.json (62%) create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/args create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/in.sol rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_invalid_nesting => standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket}/input.json (53%) rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket => standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket}/output.json (100%) create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/args create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/in.sol rename test/cmdlineTests/{standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket => standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket}/input.json (87%) create mode 100644 test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/output.json delete mode 100644 test/cmdlineTests/yul_optimizer_steps_invalid_nesting/args delete mode 100644 test/cmdlineTests/yul_optimizer_steps_invalid_nesting/err create mode 100644 test/cmdlineTests/yul_optimizer_steps_nested_brackets/args rename test/cmdlineTests/{yul_optimizer_steps_invalid_nesting => yul_optimizer_steps_nested_brackets}/input.sol (100%) create mode 100644 test/cmdlineTests/yul_optimizer_steps_nested_brackets/output create mode 100644 test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/args create mode 100644 test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/err rename test/cmdlineTests/{yul_optimizer_steps_invalid_nesting => yul_optimizer_steps_nesting_too_deep}/exit (100%) rename test/cmdlineTests/{yul_optimizer_steps_unbalanced_bracket => yul_optimizer_steps_nesting_too_deep}/input.sol (100%) create mode 100644 test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/args rename test/cmdlineTests/{yul_optimizer_steps_unbalanced_bracket => yul_optimizer_steps_unbalanced_closing_bracket}/err (100%) rename test/cmdlineTests/{yul_optimizer_steps_unbalanced_bracket => yul_optimizer_steps_unbalanced_closing_bracket}/exit (100%) create mode 100644 test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/input.sol rename test/cmdlineTests/{yul_optimizer_steps_unbalanced_bracket => yul_optimizer_steps_unbalanced_opening_bracket}/args (100%) create mode 100644 test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/err create mode 100644 test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/exit create mode 100644 test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/input.sol diff --git a/Changelog.md b/Changelog.md index 74e20d4b8..058ecc2e0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,7 +5,9 @@ Language Features: Compiler Features: + * Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``. * SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions. + * Standard JSON: Accept nested brackets in step sequences passed to ``settings.optimizer.details.yulDetails.optimizerSteps``. Bugfixes: diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index a77fd8ef9..5525e17d2 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -79,6 +79,7 @@ #include #include +#include using namespace std; using namespace solidity; @@ -308,10 +309,50 @@ void OptimiserSuite::validateSequence(string_view _stepAbbreviations) assertThrow(nestingLevel == 0, OptimizerException, "Unbalanced brackets"); } -void OptimiserSuite::runSequence(string_view _stepAbbreviations, Block& _ast) +void OptimiserSuite::runSequence(string_view _stepAbbreviations, Block& _ast, bool _repeatUntilStable) { validateSequence(_stepAbbreviations); + // This splits 'aaa[bbb]ccc...' into 'aaa' and '[bbb]ccc...'. + auto extractNonNestedPrefix = [](string_view _tail) -> tuple + { + for (size_t i = 0; i < _tail.size(); ++i) + { + yulAssert(_tail[i] != ']'); + if (_tail[i] == '[') + return {_tail.substr(0, i), _tail.substr(i)}; + } + return {_tail, {}}; + }; + + // This splits '[bbb]ccc...' into 'bbb' and 'ccc...'. + auto extractBracketContent = [](string_view _tail) -> tuple + { + yulAssert(!_tail.empty() && _tail[0] == '['); + + size_t contentLength = 0; + int8_t nestingLevel = 1; + for (char abbreviation: _tail.substr(1)) + { + if (abbreviation == '[') + { + yulAssert(nestingLevel < numeric_limits::max()); + ++nestingLevel; + } + else if (abbreviation == ']') + { + --nestingLevel; + if (nestingLevel == 0) + break; + } + ++contentLength; + } + yulAssert(nestingLevel == 0); + yulAssert(_tail[contentLength + 1] == ']'); + + return {_tail.substr(1, contentLength), _tail.substr(contentLength + 2)}; + }; + auto abbreviationsToSteps = [](string_view _sequence) -> vector { vector steps; @@ -321,21 +362,41 @@ void OptimiserSuite::runSequence(string_view _stepAbbreviations, Block& _ast) return steps; }; - // The sequence has now been validated and must consist of pairs of segments that look like this: `aaa[bbb]` - // `aaa` or `[bbb]` can be empty. For example we consider a sequence like `fgo[aaf]Oo` to have - // four segments, the last of which is an empty bracket. - size_t currentPairStart = 0; - while (currentPairStart < _stepAbbreviations.size()) + vector> subsequences; + string_view tail = _stepAbbreviations; + while (!tail.empty()) { - size_t openingBracket = _stepAbbreviations.find('[', currentPairStart); - size_t closingBracket = _stepAbbreviations.find(']', openingBracket); - size_t firstCharInside = (openingBracket == string::npos ? _stepAbbreviations.size() : openingBracket + 1); - yulAssert((openingBracket == string::npos) == (closingBracket == string::npos), ""); + string_view subsequence; + tie(subsequence, tail) = extractNonNestedPrefix(tail); + if (subsequence.size() > 0) + subsequences.push_back({subsequence, false}); - runSequence(abbreviationsToSteps(_stepAbbreviations.substr(currentPairStart, openingBracket - currentPairStart)), _ast); - runSequenceUntilStable(abbreviationsToSteps(_stepAbbreviations.substr(firstCharInside, closingBracket - firstCharInside)), _ast); + if (tail.empty()) + break; - currentPairStart = (closingBracket == string::npos ? _stepAbbreviations.size() : closingBracket + 1); + tie(subsequence, tail) = extractBracketContent(tail); + if (subsequence.size() > 0) + subsequences.push_back({subsequence, true}); + } + + size_t codeSize = 0; + for (size_t round = 0; round < MaxRounds; ++round) + { + for (auto const& [subsequence, repeat]: subsequences) + { + if (repeat) + runSequence(subsequence, _ast, true); + else + runSequence(abbreviationsToSteps(subsequence), _ast); + } + + if (!_repeatUntilStable) + break; + + size_t newSize = CodeSize::codeSizeIncludingFunctions(_ast); + if (newSize == codeSize) + break; + codeSize = newSize; } } @@ -363,24 +424,3 @@ void OptimiserSuite::runSequence(std::vector const& _steps, Block& _ast) } } } - -void OptimiserSuite::runSequenceUntilStable( - std::vector const& _steps, - Block& _ast, - size_t maxRounds -) -{ - if (_steps.empty()) - return; - - size_t codeSize = 0; - for (size_t rounds = 0; rounds < maxRounds; ++rounds) - { - size_t newSize = CodeSize::codeSizeIncludingFunctions(_ast); - if (newSize == codeSize) - break; - codeSize = newSize; - - runSequence(_steps, _ast); - } -} diff --git a/libyul/optimiser/Suite.h b/libyul/optimiser/Suite.h index 062d76954..9b38ce542 100644 --- a/libyul/optimiser/Suite.h +++ b/libyul/optimiser/Suite.h @@ -75,12 +75,7 @@ public: static void validateSequence(std::string_view _stepAbbreviations); void runSequence(std::vector const& _steps, Block& _ast); - void runSequence(std::string_view _stepAbbreviations, Block& _ast); - void runSequenceUntilStable( - std::vector const& _steps, - Block& _ast, - size_t maxRounds = MaxRounds - ); + void runSequence(std::string_view _stepAbbreviations, Block& _ast, bool _repeatUntilStable = false); static std::map> const& allSteps(); static std::map const& stepNameToAbbreviationMap(); diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/args b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/args similarity index 100% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/args rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/args diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/in.sol b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/in.sol similarity index 100% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/in.sol rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/in.sol diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/input.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/input.json new file mode 100644 index 000000000..2baf7a723 --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/input.json @@ -0,0 +1,16 @@ +{ + "language": "Solidity", + "sources": { + "A": {"urls": ["standard_optimizer_yulDetails_optimiserSteps_nested_brackets/in.sol"]} + }, + "settings": { + "optimizer": { + "details": { + "yul": true, + "yulDetails": { + "optimizerSteps": "a[[a][[aa]aa[aa]][]]aaa[aa[aa[aa]]]a[a][a][a]a[a]" + } + } + } + } +} diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/output.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/output.json new file mode 100644 index 000000000..acf3b74ef --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nested_brackets/output.json @@ -0,0 +1,9 @@ +{ + "sources": + { + "A": + { + "id": 0 + } + } +} diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/args b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/args similarity index 100% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/args rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/args diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/in.sol b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/in.sol similarity index 100% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/in.sol rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/in.sol diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/input.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/input.json new file mode 100644 index 000000000..1c055d915 --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/input.json @@ -0,0 +1,16 @@ +{ + "language": "Solidity", + "sources": { + "A": {"urls": ["standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/in.sol"]} + }, + "settings": { + "optimizer": { + "details": { + "yul": true, + "yulDetails": { + "optimizerSteps": "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" + } + } + } + } +} diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/output.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/output.json similarity index 62% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/output.json rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/output.json index b2bc6b7d5..e06e14205 100644 --- a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/output.json +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_nesting_too_deep/output.json @@ -3,8 +3,8 @@ [ { "component": "general", - "formattedMessage": "Invalid optimizer step sequence in \"settings.optimizer.details.optimizerSteps\": Nested brackets are not supported", - "message": "Invalid optimizer step sequence in \"settings.optimizer.details.optimizerSteps\": Nested brackets are not supported", + "formattedMessage": "Invalid optimizer step sequence in \"settings.optimizer.details.optimizerSteps\": Brackets nested too deep", + "message": "Invalid optimizer step sequence in \"settings.optimizer.details.optimizerSteps\": Brackets nested too deep", "severity": "error", "type": "JSONError" } diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/args b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/args new file mode 100644 index 000000000..a905f1fe6 --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/args @@ -0,0 +1 @@ +--pretty-json --json-indent 4 diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/in.sol b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/in.sol new file mode 100644 index 000000000..9e5350072 --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/in.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C { + function f() public pure {} +} diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/input.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/input.json similarity index 53% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/input.json rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/input.json index 881470ab5..e3cd50027 100644 --- a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/input.json +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/input.json @@ -1,14 +1,14 @@ { "language": "Solidity", "sources": { - "A": {"urls": ["standard_optimizer_yulDetails_optimiserSteps_invalid_nesting/in.sol"]} + "A": {"urls": ["standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/in.sol"]} }, "settings": { "optimizer": { "details": { "yul": true, "yulDetails": { - "optimizerSteps": "a[a][aa[aa]]a" + "optimizerSteps": "a]a][" } } } diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/output.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/output.json similarity index 100% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/output.json rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_closing_bracket/output.json diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/args b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/args new file mode 100644 index 000000000..a905f1fe6 --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/args @@ -0,0 +1 @@ +--pretty-json --json-indent 4 diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/in.sol b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/in.sol new file mode 100644 index 000000000..9e5350072 --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/in.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C { + function f() public pure {} +} diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/input.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/input.json similarity index 87% rename from test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/input.json rename to test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/input.json index ddfb37678..6cf7a2334 100644 --- a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/input.json +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/input.json @@ -1,7 +1,7 @@ { "language": "Solidity", "sources": { - "A": {"urls": ["standard_optimizer_yulDetails_optimiserSteps_unbalanced_bracket/in.sol"]} + "A": {"urls": ["standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/in.sol"]} }, "settings": { "optimizer": { diff --git a/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/output.json b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/output.json new file mode 100644 index 000000000..316529b0d --- /dev/null +++ b/test/cmdlineTests/standard_optimizer_yulDetails_optimiserSteps_unbalanced_opening_bracket/output.json @@ -0,0 +1,12 @@ +{ + "errors": + [ + { + "component": "general", + "formattedMessage": "Invalid optimizer step sequence in \"settings.optimizer.details.optimizerSteps\": Unbalanced brackets", + "message": "Invalid optimizer step sequence in \"settings.optimizer.details.optimizerSteps\": Unbalanced brackets", + "severity": "error", + "type": "JSONError" + } + ] +} diff --git a/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/args b/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/args deleted file mode 100644 index 724fe4724..000000000 --- a/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/args +++ /dev/null @@ -1 +0,0 @@ ---ir-optimized --optimize --yul-optimizations a[a][aa[aa]]a diff --git a/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/err b/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/err deleted file mode 100644 index 2f6d9ff47..000000000 --- a/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/err +++ /dev/null @@ -1 +0,0 @@ -Invalid optimizer step sequence in --yul-optimizations: Nested brackets are not supported diff --git a/test/cmdlineTests/yul_optimizer_steps_nested_brackets/args b/test/cmdlineTests/yul_optimizer_steps_nested_brackets/args new file mode 100644 index 000000000..4b536761f --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_nested_brackets/args @@ -0,0 +1 @@ +--ir-optimized --optimize --yul-optimizations a[[a][[aa]aa[aa]][]]aaa[aa[aa[aa]]]a[a][a][a]a[a] diff --git a/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/input.sol b/test/cmdlineTests/yul_optimizer_steps_nested_brackets/input.sol similarity index 100% rename from test/cmdlineTests/yul_optimizer_steps_invalid_nesting/input.sol rename to test/cmdlineTests/yul_optimizer_steps_nested_brackets/input.sol diff --git a/test/cmdlineTests/yul_optimizer_steps_nested_brackets/output b/test/cmdlineTests/yul_optimizer_steps_nested_brackets/output new file mode 100644 index 000000000..d4c026105 --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_nested_brackets/output @@ -0,0 +1,433 @@ +Optimized IR: +/*=====================================================* + * WARNING * + * Solidity to Yul compilation is still EXPERIMENTAL * + * It can result in LOSS OF FUNDS or worse * + * !USE AT YOUR OWN RISK! * + *=====================================================*/ + +/// @use-src 0:"yul_optimizer_steps_nested_brackets/input.sol" +object "C_6" { + code { + { + /// @src 0:60:103 "contract C..." + mstore(64, 128) + if callvalue() + { + revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() + } + constructor_C() + let _1 := allocate_unbounded() + codecopy(_1, dataoffset("C_6_deployed"), datasize("C_6_deployed")) + return(_1, datasize("C_6_deployed")) + } + function allocate_unbounded() -> memPtr + { + let memPtr_1 := mload(64) + let memPtr_2 := memPtr_1 + let memPtr_3 := memPtr_1 + let memPtr_4 := memPtr_1 + let memPtr_5 := memPtr_1 + let memPtr_6 := memPtr_1 + let memPtr_7 := memPtr_1 + let memPtr_8 := memPtr_1 + let memPtr_9 := memPtr_1 + let memPtr_10 := memPtr_1 + let memPtr_11 := memPtr_1 + let memPtr_12 := memPtr_1 + let memPtr_13 := memPtr_1 + let memPtr_14 := memPtr_1 + let memPtr_15 := memPtr_1 + let memPtr_16 := memPtr_1 + let memPtr_17 := memPtr_1 + let memPtr_18 := memPtr_1 + let memPtr_19 := memPtr_1 + let memPtr_20 := memPtr_1 + let memPtr_21 := memPtr_1 + let memPtr_22 := memPtr_1 + let memPtr_23 := memPtr_1 + let memPtr_24 := memPtr_1 + let memPtr_25 := memPtr_1 + let memPtr_26 := memPtr_1 + let memPtr_27 := memPtr_1 + let memPtr_28 := memPtr_1 + let memPtr_29 := memPtr_1 + let memPtr_30 := memPtr_1 + let memPtr_31 := memPtr_1 + let memPtr_32 := memPtr_1 + let memPtr_33 := memPtr_1 + let memPtr_34 := memPtr_1 + let memPtr_35 := memPtr_1 + let memPtr_36 := memPtr_1 + let memPtr_37 := memPtr_1 + let memPtr_38 := memPtr_1 + let memPtr_39 := memPtr_1 + let memPtr_40 := memPtr_1 + let memPtr_41 := memPtr_1 + let memPtr_42 := memPtr_1 + let memPtr_43 := memPtr_1 + let memPtr_44 := memPtr_1 + let memPtr_45 := memPtr_1 + let memPtr_46 := memPtr_1 + let memPtr_47 := memPtr_1 + let memPtr_48 := memPtr_1 + let memPtr_49 := memPtr_1 + let memPtr_50 := memPtr_1 + let memPtr_51 := memPtr_1 + let memPtr_52 := memPtr_1 + let memPtr_53 := memPtr_1 + let memPtr_54 := memPtr_1 + let memPtr_55 := memPtr_1 + let memPtr_56 := memPtr_1 + let memPtr_57 := memPtr_1 + let memPtr_58 := memPtr_1 + let memPtr_59 := memPtr_1 + let memPtr_60 := memPtr_1 + let memPtr_61 := memPtr_1 + let memPtr_62 := memPtr_1 + let memPtr_63 := memPtr_1 + let memPtr_64 := memPtr_1 + let memPtr_65 := memPtr_1 + let memPtr_66 := memPtr_1 + let memPtr_67 := memPtr_1 + let memPtr_68 := memPtr_1 + let memPtr_69 := memPtr_1 + let memPtr_70 := memPtr_1 + let memPtr_71 := memPtr_1 + let memPtr_72 := memPtr_1 + let memPtr_73 := memPtr_1 + let memPtr_74 := memPtr_1 + let memPtr_75 := memPtr_1 + let memPtr_76 := memPtr_1 + let memPtr_77 := memPtr_1 + let memPtr_78 := memPtr_1 + let memPtr_79 := memPtr_1 + let memPtr_80 := memPtr_1 + let memPtr_81 := memPtr_1 + let memPtr_82 := memPtr_1 + let memPtr_83 := memPtr_1 + let memPtr_84 := memPtr_1 + let memPtr_85 := memPtr_1 + let memPtr_86 := memPtr_1 + memPtr := memPtr_1 + } + function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() + { revert(0, 0) } + function constructor_C() + { } + } + /// @use-src 0:"yul_optimizer_steps_nested_brackets/input.sol" + object "C_6_deployed" { + code { + { + /// @src 0:60:103 "contract C..." + mstore(64, 128) + if iszero(lt(calldatasize(), 4)) + { + let selector := shift_right_unsigned(calldataload(0)) + if eq(0x26121ff0, selector) + { + if callvalue() + { + revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() + } + abi_decode(4, calldatasize()) + fun_f() + let memPos := allocate_unbounded() + let memEnd := abi_encode_tuple(memPos) + return(memPos, sub(memEnd, memPos)) + } + } + pop(iszero(calldatasize())) + revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() + } + function shift_right_unsigned(value) -> newValue + { + let newValue_1 := shr(224, value) + let newValue_2 := newValue_1 + let newValue_3 := newValue_1 + let newValue_4 := newValue_1 + let newValue_5 := newValue_1 + let newValue_6 := newValue_1 + let newValue_7 := newValue_1 + let newValue_8 := newValue_1 + let newValue_9 := newValue_1 + let newValue_10 := newValue_1 + let newValue_11 := newValue_1 + let newValue_12 := newValue_1 + let newValue_13 := newValue_1 + let newValue_14 := newValue_1 + let newValue_15 := newValue_1 + let newValue_16 := newValue_1 + let newValue_17 := newValue_1 + let newValue_18 := newValue_1 + let newValue_19 := newValue_1 + let newValue_20 := newValue_1 + let newValue_21 := newValue_1 + let newValue_22 := newValue_1 + let newValue_23 := newValue_1 + let newValue_24 := newValue_1 + let newValue_25 := newValue_1 + let newValue_26 := newValue_1 + let newValue_27 := newValue_1 + let newValue_28 := newValue_1 + let newValue_29 := newValue_1 + let newValue_30 := newValue_1 + let newValue_31 := newValue_1 + let newValue_32 := newValue_1 + let newValue_33 := newValue_1 + let newValue_34 := newValue_1 + let newValue_35 := newValue_1 + let newValue_36 := newValue_1 + let newValue_37 := newValue_1 + let newValue_38 := newValue_1 + let newValue_39 := newValue_1 + let newValue_40 := newValue_1 + let newValue_41 := newValue_1 + let newValue_42 := newValue_1 + let newValue_43 := newValue_1 + let newValue_44 := newValue_1 + let newValue_45 := newValue_1 + let newValue_46 := newValue_1 + let newValue_47 := newValue_1 + let newValue_48 := newValue_1 + let newValue_49 := newValue_1 + let newValue_50 := newValue_1 + let newValue_51 := newValue_1 + let newValue_52 := newValue_1 + let newValue_53 := newValue_1 + let newValue_54 := newValue_1 + let newValue_55 := newValue_1 + let newValue_56 := newValue_1 + let newValue_57 := newValue_1 + let newValue_58 := newValue_1 + let newValue_59 := newValue_1 + let newValue_60 := newValue_1 + let newValue_61 := newValue_1 + let newValue_62 := newValue_1 + let newValue_63 := newValue_1 + let newValue_64 := newValue_1 + let newValue_65 := newValue_1 + let newValue_66 := newValue_1 + let newValue_67 := newValue_1 + let newValue_68 := newValue_1 + let newValue_69 := newValue_1 + let newValue_70 := newValue_1 + let newValue_71 := newValue_1 + let newValue_72 := newValue_1 + let newValue_73 := newValue_1 + let newValue_74 := newValue_1 + let newValue_75 := newValue_1 + let newValue_76 := newValue_1 + let newValue_77 := newValue_1 + let newValue_78 := newValue_1 + let newValue_79 := newValue_1 + let newValue_80 := newValue_1 + let newValue_81 := newValue_1 + let newValue_82 := newValue_1 + let newValue_83 := newValue_1 + let newValue_84 := newValue_1 + let newValue_85 := newValue_1 + let newValue_86 := newValue_1 + newValue := newValue_1 + } + function allocate_unbounded() -> memPtr + { + let memPtr_1 := mload(64) + let memPtr_2 := memPtr_1 + let memPtr_3 := memPtr_1 + let memPtr_4 := memPtr_1 + let memPtr_5 := memPtr_1 + let memPtr_6 := memPtr_1 + let memPtr_7 := memPtr_1 + let memPtr_8 := memPtr_1 + let memPtr_9 := memPtr_1 + let memPtr_10 := memPtr_1 + let memPtr_11 := memPtr_1 + let memPtr_12 := memPtr_1 + let memPtr_13 := memPtr_1 + let memPtr_14 := memPtr_1 + let memPtr_15 := memPtr_1 + let memPtr_16 := memPtr_1 + let memPtr_17 := memPtr_1 + let memPtr_18 := memPtr_1 + let memPtr_19 := memPtr_1 + let memPtr_20 := memPtr_1 + let memPtr_21 := memPtr_1 + let memPtr_22 := memPtr_1 + let memPtr_23 := memPtr_1 + let memPtr_24 := memPtr_1 + let memPtr_25 := memPtr_1 + let memPtr_26 := memPtr_1 + let memPtr_27 := memPtr_1 + let memPtr_28 := memPtr_1 + let memPtr_29 := memPtr_1 + let memPtr_30 := memPtr_1 + let memPtr_31 := memPtr_1 + let memPtr_32 := memPtr_1 + let memPtr_33 := memPtr_1 + let memPtr_34 := memPtr_1 + let memPtr_35 := memPtr_1 + let memPtr_36 := memPtr_1 + let memPtr_37 := memPtr_1 + let memPtr_38 := memPtr_1 + let memPtr_39 := memPtr_1 + let memPtr_40 := memPtr_1 + let memPtr_41 := memPtr_1 + let memPtr_42 := memPtr_1 + let memPtr_43 := memPtr_1 + let memPtr_44 := memPtr_1 + let memPtr_45 := memPtr_1 + let memPtr_46 := memPtr_1 + let memPtr_47 := memPtr_1 + let memPtr_48 := memPtr_1 + let memPtr_49 := memPtr_1 + let memPtr_50 := memPtr_1 + let memPtr_51 := memPtr_1 + let memPtr_52 := memPtr_1 + let memPtr_53 := memPtr_1 + let memPtr_54 := memPtr_1 + let memPtr_55 := memPtr_1 + let memPtr_56 := memPtr_1 + let memPtr_57 := memPtr_1 + let memPtr_58 := memPtr_1 + let memPtr_59 := memPtr_1 + let memPtr_60 := memPtr_1 + let memPtr_61 := memPtr_1 + let memPtr_62 := memPtr_1 + let memPtr_63 := memPtr_1 + let memPtr_64 := memPtr_1 + let memPtr_65 := memPtr_1 + let memPtr_66 := memPtr_1 + let memPtr_67 := memPtr_1 + let memPtr_68 := memPtr_1 + let memPtr_69 := memPtr_1 + let memPtr_70 := memPtr_1 + let memPtr_71 := memPtr_1 + let memPtr_72 := memPtr_1 + let memPtr_73 := memPtr_1 + let memPtr_74 := memPtr_1 + let memPtr_75 := memPtr_1 + let memPtr_76 := memPtr_1 + let memPtr_77 := memPtr_1 + let memPtr_78 := memPtr_1 + let memPtr_79 := memPtr_1 + let memPtr_80 := memPtr_1 + let memPtr_81 := memPtr_1 + let memPtr_82 := memPtr_1 + let memPtr_83 := memPtr_1 + let memPtr_84 := memPtr_1 + let memPtr_85 := memPtr_1 + let memPtr_86 := memPtr_1 + memPtr := memPtr_1 + } + function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() + { revert(0, 0) } + function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() + { revert(0, 0) } + function abi_decode(headStart, dataEnd) + { + if slt(sub(dataEnd, headStart), 0) + { + revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() + } + } + function abi_encode_tuple(headStart) -> tail + { + let tail_1 := add(headStart, 0) + let tail_2 := tail_1 + let tail_3 := tail_1 + let tail_4 := tail_1 + let tail_5 := tail_1 + let tail_6 := tail_1 + let tail_7 := tail_1 + let tail_8 := tail_1 + let tail_9 := tail_1 + let tail_10 := tail_1 + let tail_11 := tail_1 + let tail_12 := tail_1 + let tail_13 := tail_1 + let tail_14 := tail_1 + let tail_15 := tail_1 + let tail_16 := tail_1 + let tail_17 := tail_1 + let tail_18 := tail_1 + let tail_19 := tail_1 + let tail_20 := tail_1 + let tail_21 := tail_1 + let tail_22 := tail_1 + let tail_23 := tail_1 + let tail_24 := tail_1 + let tail_25 := tail_1 + let tail_26 := tail_1 + let tail_27 := tail_1 + let tail_28 := tail_1 + let tail_29 := tail_1 + let tail_30 := tail_1 + let tail_31 := tail_1 + let tail_32 := tail_1 + let tail_33 := tail_1 + let tail_34 := tail_1 + let tail_35 := tail_1 + let tail_36 := tail_1 + let tail_37 := tail_1 + let tail_38 := tail_1 + let tail_39 := tail_1 + let tail_40 := tail_1 + let tail_41 := tail_1 + let tail_42 := tail_1 + let tail_43 := tail_1 + let tail_44 := tail_1 + let tail_45 := tail_1 + let tail_46 := tail_1 + let tail_47 := tail_1 + let tail_48 := tail_1 + let tail_49 := tail_1 + let tail_50 := tail_1 + let tail_51 := tail_1 + let tail_52 := tail_1 + let tail_53 := tail_1 + let tail_54 := tail_1 + let tail_55 := tail_1 + let tail_56 := tail_1 + let tail_57 := tail_1 + let tail_58 := tail_1 + let tail_59 := tail_1 + let tail_60 := tail_1 + let tail_61 := tail_1 + let tail_62 := tail_1 + let tail_63 := tail_1 + let tail_64 := tail_1 + let tail_65 := tail_1 + let tail_66 := tail_1 + let tail_67 := tail_1 + let tail_68 := tail_1 + let tail_69 := tail_1 + let tail_70 := tail_1 + let tail_71 := tail_1 + let tail_72 := tail_1 + let tail_73 := tail_1 + let tail_74 := tail_1 + let tail_75 := tail_1 + let tail_76 := tail_1 + let tail_77 := tail_1 + let tail_78 := tail_1 + let tail_79 := tail_1 + let tail_80 := tail_1 + let tail_81 := tail_1 + let tail_82 := tail_1 + let tail_83 := tail_1 + let tail_84 := tail_1 + let tail_85 := tail_1 + let tail_86 := tail_1 + tail := tail_1 + } + function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() + { revert(0, 0) } + /// @ast-id 5 @src 0:74:101 "function f() public pure {}" + function fun_f() + { } + } + data ".metadata" hex"" + } +} diff --git a/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/args b/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/args new file mode 100644 index 000000000..b2ff99d3f --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/args @@ -0,0 +1 @@ +--ir-optimized --optimize --yul-optimizations [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] diff --git a/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/err b/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/err new file mode 100644 index 000000000..c8dc9697e --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/err @@ -0,0 +1 @@ +Invalid optimizer step sequence in --yul-optimizations: Brackets nested too deep diff --git a/test/cmdlineTests/yul_optimizer_steps_invalid_nesting/exit b/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/exit similarity index 100% rename from test/cmdlineTests/yul_optimizer_steps_invalid_nesting/exit rename to test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/exit diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/input.sol b/test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/input.sol similarity index 100% rename from test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/input.sol rename to test/cmdlineTests/yul_optimizer_steps_nesting_too_deep/input.sol diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/args b/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/args new file mode 100644 index 000000000..04933d213 --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/args @@ -0,0 +1 @@ +--ir-optimized --optimize --yul-optimizations a]a][ diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/err b/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/err similarity index 100% rename from test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/err rename to test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/err diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/exit b/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/exit similarity index 100% rename from test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/exit rename to test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/exit diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/input.sol b/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/input.sol new file mode 100644 index 000000000..6923ca702 --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_unbalanced_closing_bracket/input.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C +{ + function f() public pure {} +} diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/args b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/args similarity index 100% rename from test/cmdlineTests/yul_optimizer_steps_unbalanced_bracket/args rename to test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/args diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/err b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/err new file mode 100644 index 000000000..1da42b743 --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/err @@ -0,0 +1 @@ +Invalid optimizer step sequence in --yul-optimizations: Unbalanced brackets diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/exit b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/exit @@ -0,0 +1 @@ +1 diff --git a/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/input.sol b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/input.sol new file mode 100644 index 000000000..6923ca702 --- /dev/null +++ b/test/cmdlineTests/yul_optimizer_steps_unbalanced_opening_bracket/input.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C +{ + function f() public pure {} +}