diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 986ff29636e7..f11ef866fa09 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -69,7 +69,7 @@ #include #include #include -#include +#include #include #include @@ -1676,8 +1676,8 @@ std::string CompilerStack::createMetadata(Contract const& _contract, bool _forIR } else if ( - OptimiserSuite::isEmptyOptimizerSequence(m_optimiserSettings.yulOptimiserSteps) && - OptimiserSuite::isEmptyOptimizerSequence(m_optimiserSettings.yulOptimiserCleanupSteps) + isEmptyOptimizerSequence(m_optimiserSettings.yulOptimiserSteps) && + isEmptyOptimizerSequence(m_optimiserSettings.yulOptimiserCleanupSteps) ) { details["yulDetails"] = Json::objectValue; diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index b74f764c5592..76da19948a48 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -463,7 +464,7 @@ std::optional checkOptimizerDetailSteps(Json::Value const& _details if (_details[_name].isString()) { std::string const fullSequence = _details[_name].asString(); - if (!_runYulOptimizer && !OptimiserSuite::isEmptyOptimizerSequence(fullSequence)) + if (!_runYulOptimizer && !isEmptyOptimizerSequence(fullSequence)) return formatFatalError(Error::Type::JSONError, "If Yul optimizer is disabled, only an empty optimizerSteps sequence is accepted."); try diff --git a/libyul/YulStack.cpp b/libyul/YulStack.cpp index 6c89cadbdfd9..87a132200be4 100644 --- a/libyul/YulStack.cpp +++ b/libyul/YulStack.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -171,7 +172,7 @@ void YulStack::optimize(Object& _object, bool _isCreation) if (!m_optimiserSettings.runYulOptimiser) { // Yul optimizer disabled, but empty sequence (:) explicitly provided - if (OptimiserSuite::isEmptyOptimizerSequence(m_optimiserSettings.yulOptimiserSteps + ":" + m_optimiserSettings.yulOptimiserCleanupSteps)) + if (isEmptyOptimizerSequence(m_optimiserSettings.yulOptimiserSteps + ":" + m_optimiserSettings.yulOptimiserCleanupSteps)) return std::make_tuple(true, "", ""); // Yul optimizer disabled, and no sequence explicitly provided (assumes default sequence) else diff --git a/libyul/optimiser/OptimizerUtilities.cpp b/libyul/optimiser/OptimizerUtilities.cpp index 17f912762b38..d4033a9f5e98 100644 --- a/libyul/optimiser/OptimizerUtilities.cpp +++ b/libyul/optimiser/OptimizerUtilities.cpp @@ -78,3 +78,22 @@ void StatementRemover::operator()(Block& _block) ); ASTModifier::operator()(_block); } + +bool yul::isEmptyOptimizerSequence(std::string const& _sequence) +{ + size_t delimiterCount{0}; + for (char const step: _sequence) + switch (step) + { + case ':': + if (++delimiterCount > 1) + return false; + break; + case ' ': + case '\n': + break; + default: + return false; + } + return true; +} \ No newline at end of file diff --git a/libyul/optimiser/OptimizerUtilities.h b/libyul/optimiser/OptimizerUtilities.h index cb07f7a53006..f3e84af21b46 100644 --- a/libyul/optimiser/OptimizerUtilities.h +++ b/libyul/optimiser/OptimizerUtilities.h @@ -54,6 +54,10 @@ std::optional toEVMInstruction(Dialect const& _dialect, Yul /// It returns the default EVM version if dialect is not an EVMDialect. langutil::EVMVersion const evmVersionFromDialect(Dialect const& _dialect); +/// Check whether the provided sequence is empty provided that the allowed characters are +/// whitespace, newline and : +bool isEmptyOptimizerSequence(std::string const& _sequence); + class StatementRemover: public ASTModifier { public: diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 545ae4de06d7..58561ee10a15 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -383,25 +383,6 @@ void OptimiserSuite::validateSequence(std::string_view _stepAbbreviations) assertThrow(nestingLevel == 0, OptimizerException, "Unbalanced brackets"); } -bool OptimiserSuite::isEmptyOptimizerSequence(std::string const& _sequence) -{ - size_t delimiterCount{0}; - for (char const step: _sequence) - switch (step) - { - case ':': - if (++delimiterCount > 1) - return false; - break; - case ' ': - case '\n': - break; - default: - return false; - } - return true; -} - void OptimiserSuite::runSequence(std::string_view _stepAbbreviations, Block& _ast, bool _repeatUntilStable) { validateSequence(_stepAbbreviations); diff --git a/libyul/optimiser/Suite.h b/libyul/optimiser/Suite.h index 6e3886da3b2d..abed2720e2a5 100644 --- a/libyul/optimiser/Suite.h +++ b/libyul/optimiser/Suite.h @@ -76,10 +76,6 @@ class OptimiserSuite /// Ensures that specified sequence of step abbreviations is well-formed and can be executed. /// @throw OptimizerException if the sequence is invalid static void validateSequence(std::string_view _stepAbbreviations); - /// Check whether the provided sequence is empty provided that the allowed characters are - /// whitespace, newline and : - static bool isEmptyOptimizerSequence(std::string const& _sequence); - void runSequence(std::vector const& _steps, Block& _ast); void runSequence(std::string_view _stepAbbreviations, Block& _ast, bool _repeatUntilStable = false); diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 3ed1b7b634ca..ba0c540a15b2 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -20,6 +20,7 @@ #include +#include #include #include @@ -1229,7 +1230,7 @@ void CommandLineParser::processArgs() if (m_args.count(g_strYulOptimizations)) { OptimiserSettings optimiserSettings = m_options.optimiserSettings(); - if (!optimiserSettings.runYulOptimiser && !OptimiserSuite::isEmptyOptimizerSequence(m_args[g_strYulOptimizations].as())) + if (!optimiserSettings.runYulOptimiser && !isEmptyOptimizerSequence(m_args[g_strYulOptimizations].as())) solThrow(CommandLineValidationError, "--" + g_strYulOptimizations + " is invalid with a non-empty sequence if Yul optimizer is disabled."); try