Merge pull request #9354 from ethereum/improveTestSpeed

Improve testing speed by only enabling the Yul optimizer if needed.
This commit is contained in:
chriseth 2020-07-08 19:54:32 +02:00 committed by GitHub
commit ecc4bf2464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,18 +61,40 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
evmasm::LinkerObject obj; evmasm::LinkerObject obj;
if (m_compileViaYul) if (m_compileViaYul)
{ {
yul::AssemblyStack asmStack( // Try compiling twice: If the first run fails due to stack errors, forcefully enable
m_evmVersion, // the optimizer.
yul::AssemblyStack::Language::StrictAssembly, for (bool forceEnableOptimizer: {false, true})
// Ignore optimiser settings here because we need Yul optimisation to {
// get code that does not exhaust the stack. OptimiserSettings optimiserSettings = m_optimiserSettings;
OptimiserSettings::full() if (!forceEnableOptimizer && !optimiserSettings.runYulOptimiser)
); {
bool analysisSuccessful = asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(contractName)); // Enable some optimizations on the first run
solAssert(analysisSuccessful, "Code that passed analysis in CompilerStack can't have errors"); optimiserSettings.runYulOptimiser = true;
optimiserSettings.yulOptimiserSteps = "uljmul jmul";
}
else if (forceEnableOptimizer)
optimiserSettings = OptimiserSettings::full();
asmStack.optimize(); yul::AssemblyStack asmStack(
obj = std::move(*asmStack.assemble(yul::AssemblyStack::Machine::EVM).bytecode); m_evmVersion,
yul::AssemblyStack::Language::StrictAssembly,
optimiserSettings
);
bool analysisSuccessful = asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(contractName));
solAssert(analysisSuccessful, "Code that passed analysis in CompilerStack can't have errors");
try
{
asmStack.optimize();
obj = std::move(*asmStack.assemble(yul::AssemblyStack::Machine::EVM).bytecode);
break;
}
catch (...)
{
if (forceEnableOptimizer || optimiserSettings == OptimiserSettings::full())
throw;
}
}
} }
else else
obj = m_compiler.object(contractName); obj = m_compiler.object(contractName);