Merge pull request #7792 from ethereum/enableYulOptimizer

Enable yul optimizer by default.
This commit is contained in:
chriseth 2019-12-03 21:24:22 +01:00 committed by GitHub
commit e3ee67da6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 62 additions and 43 deletions

View File

@ -9,6 +9,7 @@ Breaking changes:
* Command line interface: Switch to the new error reporter by default. ``--old-reporter`` falls back to the deprecated old error reporter.
* Command line interface: Add option to disable or choose hash method between IPFS and Swarm for the bytecode metadata.
* General: Disallow explicit conversions from external function types to ``address`` and add a member called ``address`` to them as replacement.
* General: Enable Yul optimizer as part of standard optimization.
* General: New reserved keywords: ``virtual``.
* General: Split unnamed fallback functions into two cases defined using ``fallback()`` and ``receive()``.
* Standard JSON Interface: Add option to disable or choose hash method between IPFS and Swarm for the bytecode metadata.

View File

@ -230,12 +230,6 @@ bool CompilerStack::parse()
if (SemVerVersion{string(VersionString)}.isPrerelease())
m_errorReporter.warning("This is a pre-release compiler version, please do not use it in production.");
if (m_optimiserSettings.runYulOptimiser)
m_errorReporter.warning(
"The Yul optimiser is still experimental. "
"Do not use it in production unless correctness of generated code is verified with extensive tests."
);
vector<string> sourcesToParse;
for (auto const& s: m_sources)
sourcesToParse.push_back(s.first);

View File

@ -54,19 +54,15 @@ struct OptimiserSettings
s.runDeduplicate = true;
s.runCSE = true;
s.runConstantOptimiser = true;
// The only disabled ones
s.optimizeStackAllocation = false;
s.runYulOptimiser = false;
s.runYulOptimiser = true;
s.optimizeStackAllocation = true;
s.expectedExecutionsPerDeployment = 200;
return s;
}
/// Standard optimisations plus yul and stack optimiser.
/// Full optimisations. Currently an alias for standard optimisations.
static OptimiserSettings full()
{
OptimiserSettings s = standard();
s.optimizeStackAllocation = true;
s.runYulOptimiser = true;
return s;
return standard();
}
bool operator==(OptimiserSettings const& _other) const

View File

@ -481,8 +481,7 @@ boost::variant<OptimiserSettings, Json::Value> parseOptimizerSettings(Json::Valu
return *error;
if (auto error = checkOptimizerDetail(details, "yul", settings.runYulOptimiser))
return *error;
if (settings.runYulOptimiser)
settings.optimizeStackAllocation = true;
settings.optimizeStackAllocation = settings.runYulOptimiser;
if (details.isMember("yulDetails"))
{
if (!settings.runYulOptimiser)

View File

@ -136,6 +136,7 @@ static string const g_strMetadataLiteral = "metadata-literal";
static string const g_strNatspecDev = "devdoc";
static string const g_strNatspecUser = "userdoc";
static string const g_strNone = "none";
static string const g_strNoOptimizeYul = "no-optimize-yul";
static string const g_strOpcodes = "opcodes";
static string const g_strOptimize = "optimize";
static string const g_strOptimizeRuns = "optimize-runs";
@ -688,7 +689,8 @@ Allowed options)",
"Set for how many contract runs to optimize."
"Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage."
)
(g_strOptimizeYul.c_str(), "Enable Yul optimizer in Solidity, mostly for ABIEncoderV2. Still considered experimental.")
(g_strOptimizeYul.c_str(), "Enable Yul optimizer in Solidity. Legacy option: the yul optimizer is enabled as part of the general --optimize option.")
(g_strNoOptimizeYul.c_str(), "Disable Yul optimizer in Solidity.")
(g_argPrettyJson.c_str(), "Output JSON in pretty format. Currently it only works with the combined JSON output.")
(
g_argLibraries.c_str(),
@ -960,7 +962,17 @@ bool CommandLineInterface::processInput()
using Machine = yul::AssemblyStack::Machine;
Input inputLanguage = m_args.count(g_argYul) ? Input::Yul : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly);
Machine targetMachine = Machine::EVM;
bool optimize = m_args.count(g_argOptimize) || m_args.count(g_strOptimizeYul);
bool optimize = m_args.count(g_argOptimize);
if (m_args.count(g_strOptimizeYul))
{
serr() << "--optimize-yul is invalid in assembly mode. Use --optimize instead." << endl;
return false;
}
if (m_args.count(g_strNoOptimizeYul))
{
serr() << "--no-optimize-yul is invalid in assembly mode. Optimization is disabled by default and can be enabled with --optimize." << endl;
return false;
}
if (m_args.count(g_argMachine))
{
string machine = m_args[g_argMachine].as<string>();
@ -1008,7 +1020,7 @@ bool CommandLineInterface::processInput()
return false;
}
serr() <<
"Warning: Yul and its optimizer are still experimental. Please use the output with care." <<
"Warning: Yul is still experimental. Please use the output with care." <<
endl;
return assemble(inputLanguage, targetMachine, optimize);
@ -1065,7 +1077,7 @@ bool CommandLineInterface::processInput()
OptimiserSettings settings = m_args.count(g_argOptimize) ? OptimiserSettings::standard() : OptimiserSettings::minimal();
settings.expectedExecutionsPerDeployment = m_args[g_argOptimizeRuns].as<unsigned>();
settings.runYulOptimiser = m_args.count(g_strOptimizeYul);
settings.runYulOptimiser = !m_args.count(g_strNoOptimizeYul);
settings.optimizeStackAllocation = settings.runYulOptimiser;
m_compiler->setOptimiserSettings(settings);

View File

@ -1 +1 @@
Warning: Yul and its optimizer are still experimental. Please use the output with care.
Warning: Yul is still experimental. Please use the output with care.

View File

@ -60,5 +60,4 @@
)
)
"}}}},"errors":[{"component":"general","formattedMessage":"Warning: The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.
","message":"The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.","severity":"warning","type":"Warning"}],"sources":{"A":{"id":0}}}
"}}}},"sources":{"A":{"id":0}}}

View File

@ -0,0 +1,17 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "pragma solidity >=0.0; contract C { function f() public pure {} }"
}
},
"settings":
{
"optimizer": {
"enabled": true,
"details": { "yul": false }
}
}
}

View File

@ -0,0 +1 @@
{"sources":{"A":{"id":0}}}

View File

@ -10,8 +10,7 @@
"settings":
{
"optimizer": {
"enabled": true,
"details": { "yul": true }
"enabled": true
}
}
}

View File

@ -1,2 +1 @@
{"errors":[{"component":"general","formattedMessage":"Warning: The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.
","message":"The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.","severity":"warning","type":"Warning"}],"sources":{"A":{"id":0}}}
{"sources":{"A":{"id":0}}}

View File

@ -1,2 +1 @@
{"errors":[{"component":"general","formattedMessage":"Warning: The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.
","message":"The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.","severity":"warning","type":"Warning"}],"sources":{"A":{"id":0}}}
{"sources":{"A":{"id":0}}}

View File

@ -1,4 +1,4 @@
Warning: Yul and its optimizer are still experimental. Please use the output with care.
Warning: Yul is still experimental. Please use the output with care.
Error: Function not found.
--> strict_asm_jump/input.sol:1:3:
|

View File

@ -1 +1 @@
Warning: Yul and its optimizer are still experimental. Please use the output with care.
Warning: Yul is still experimental. Please use the output with care.

View File

@ -1,4 +1,4 @@
Warning: Yul and its optimizer are still experimental. Please use the output with care.
Warning: Yul is still experimental. Please use the output with care.
Exception while assembling:
Dynamic exception type:
std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack.

View File

@ -1042,12 +1042,6 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_details_different)
)";
Json::Value result = compile(input);
BOOST_CHECK(containsAtMostWarnings(result));
BOOST_CHECK(containsError(
result,
"Warning",
"The Yul optimiser is still experimental. "
"Do not use it in production unless correctness of generated code is verified with extensive tests."
));
Json::Value contract = getContractResult(result, "fileA", "A");
BOOST_CHECK(contract.isObject());
BOOST_CHECK(contract["metadata"].isString());

View File

@ -63,10 +63,18 @@ SyntaxTest::SyntaxTest(string const& _filename, langutil::EVMVersion _evmVersion
if (m_settings.count("optimize-yul"))
{
m_optimiseYul = true;
if (m_settings["optimize-yul"] == "true")
{
m_validatedSettings["optimize-yul"] = "true";
m_settings.erase("optimize-yul");
}
else if (m_settings["optimize-yul"] == "false")
{
m_validatedSettings["optimize-yul"] = "false";
m_settings.erase("optimize-yul");
m_optimiseYul = false;
}
}
m_expectations = parseExpectations(file);
m_parserErrorRecovery = _parserErrorRecovery;
}

View File

@ -90,7 +90,7 @@ protected:
std::map<std::string, std::string> m_sources;
std::vector<SyntaxTestError> m_expectations;
std::vector<SyntaxTestError> m_errorList;
bool m_optimiseYul = false;
bool m_optimiseYul = true;
langutil::EVMVersion const m_evmVersion;
bool m_parserErrorRecovery = false;
};

View File

@ -8,5 +8,4 @@ contract C {
// ====
// optimize-yul: true
// ----
// Warning: The Yul optimiser is still experimental. Do not use it in production unless correctness of generated code is verified with extensive tests.
// SyntaxError: (52-101): The msize instruction cannot be used when the Yul optimizer is activated because it can change its semantics. Either disable the Yul optimizer or do not use the instruction.

View File

@ -5,4 +5,6 @@ contract C {
}
}
}
// ====
// optimize-yul: false
// ----