diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index b6003c3f8..4a0779ef7 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -124,7 +126,7 @@ public: langutil::EVMVersion evmVersion; /// This specifies an estimate on how often each opcode in this assembly will be executed, /// i.e. use a small value to optimise for size and a large value to optimise for runtime gas usage. - size_t expectedExecutionsPerDeployment = 200; + size_t expectedExecutionsPerDeployment = frontend::OptimiserSettings{}.expectedExecutionsPerDeployment; }; /// Modify and return the current assembly such that creation and execution gas usage diff --git a/libevmasm/Inliner.h b/libevmasm/Inliner.h index ed68dc4ce..874472351 100644 --- a/libevmasm/Inliner.h +++ b/libevmasm/Inliner.h @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include @@ -75,7 +76,7 @@ private: AssemblyItems& m_items; std::set const& m_tagsReferencedFromOutside; - size_t const m_runs = 200; + size_t const m_runs = Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment; bool const m_isCreation = false; langutil::EVMVersion const m_evmVersion; }; diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 11c7da805..44daa6381 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -146,7 +146,7 @@ public: /// Changes the optimiser settings. /// Must be set before parsing. - void setOptimiserSettings(bool _optimize, size_t _runs = 200); + void setOptimiserSettings(bool _optimize, size_t _runs = OptimiserSettings{}.expectedExecutionsPerDeployment); /// Changes the optimiser settings. /// Must be set before parsing. diff --git a/libsolidity/interface/OptimiserSettings.h b/libsolidity/interface/OptimiserSettings.h index 0dea6c3d5..578a5519a 100644 --- a/libsolidity/interface/OptimiserSettings.h +++ b/libsolidity/interface/OptimiserSettings.h @@ -85,7 +85,6 @@ struct OptimiserSettings s.runConstantOptimiser = true; s.runYulOptimiser = true; s.optimizeStackAllocation = true; - s.expectedExecutionsPerDeployment = 200; return s; } /// Full optimisations. Currently an alias for standard optimisations. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 40fd3649d..4b19b730c 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1037,7 +1037,9 @@ General Information)").c_str(), ) ( g_argOptimizeRuns.c_str(), - po::value()->value_name("n")->default_value(200), + // TODO: The type in OptimiserSettings is size_t but we only accept values up to 2**32-1 + // on the CLI and in Standard JSON. We should just switch to uint32_t everywhere. + po::value()->value_name("n")->default_value(static_cast(OptimiserSettings{}.expectedExecutionsPerDeployment)), "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." ) diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index 8903cc331..c8bb93c41 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -1286,7 +1286,8 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies) settings.runCSE = true; settings.runConstantOptimiser = true; settings.evmVersion = solidity::test::CommonOptions::get().evmVersion(); - settings.expectedExecutionsPerDeployment = 200; + settings.expectedExecutionsPerDeployment = OptimiserSettings{}.expectedExecutionsPerDeployment; +; main.optimise(settings); AssemblyItems expectationMain{ @@ -1679,7 +1680,7 @@ BOOST_AUTO_TEST_CASE(inliner) Instruction::SWAP1, jumpOutOf, }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1701,7 +1702,7 @@ BOOST_AUTO_TEST_CASE(inliner_no_inline_type) Instruction::SWAP1, Instruction::JUMP, }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), items.begin(), items.end() @@ -1726,7 +1727,7 @@ BOOST_AUTO_TEST_CASE(inliner_no_inline) Instruction::JUMPI, Instruction::JUMP, }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1757,7 +1758,7 @@ BOOST_AUTO_TEST_CASE(inliner_single_jump) AssemblyItem(Tag, 2), jumpOutOf, }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1777,7 +1778,7 @@ BOOST_AUTO_TEST_CASE(inliner_end_of_bytecode) Instruction::STOP, AssemblyItem(Tag, 2), }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), items.begin(), items.end() @@ -1802,7 +1803,7 @@ BOOST_AUTO_TEST_CASE(inliner_cse_break) Instruction::STOP, // CSE breaking instruction jumpOutOf }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), items.begin(), items.end() @@ -1822,7 +1823,7 @@ BOOST_AUTO_TEST_CASE(inliner_stop) AssemblyItem(Tag, 1), Instruction::STOP }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1840,7 +1841,7 @@ BOOST_AUTO_TEST_CASE(inliner_stop_jumpi) Instruction::STOP }; AssemblyItems expectation = items; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1867,7 +1868,7 @@ BOOST_AUTO_TEST_CASE(inliner_revert) Instruction::REVERT }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1887,7 +1888,7 @@ BOOST_AUTO_TEST_CASE(inliner_revert_increased_datagas) }; AssemblyItems expectation = items; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() @@ -1908,7 +1909,7 @@ BOOST_AUTO_TEST_CASE(inliner_invalid) AssemblyItem(Tag, 1), Instruction::INVALID }; - Inliner{items, {}, 200, false, {}}.optimise(); + Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise(); BOOST_CHECK_EQUAL_COLLECTIONS( items.begin(), items.end(), expectation.begin(), expectation.end() diff --git a/test/libsolidity/GasTest.cpp b/test/libsolidity/GasTest.cpp index 540fb0a75..36910647c 100644 --- a/test/libsolidity/GasTest.cpp +++ b/test/libsolidity/GasTest.cpp @@ -34,7 +34,6 @@ using namespace solidity::frontend; using namespace solidity::frontend::test; using namespace solidity; using namespace std; -namespace fs = boost::filesystem; using namespace boost::unit_test; GasTest::GasTest(string const& _filename): @@ -43,7 +42,7 @@ GasTest::GasTest(string const& _filename): m_source = m_reader.source(); m_optimise = m_reader.boolSetting("optimize", false); m_optimiseYul = m_reader.boolSetting("optimize-yul", false); - m_optimiseRuns = m_reader.sizetSetting("optimize-runs", 200); + m_optimiseRuns = m_reader.sizetSetting("optimize-runs", OptimiserSettings{}.expectedExecutionsPerDeployment); parseExpectations(m_reader.stream()); } diff --git a/test/libsolidity/GasTest.h b/test/libsolidity/GasTest.h index da14e5292..46619c471 100644 --- a/test/libsolidity/GasTest.h +++ b/test/libsolidity/GasTest.h @@ -22,6 +22,8 @@ #include #include +#include + #include #include #include @@ -47,7 +49,7 @@ private: bool m_optimise = false; bool m_optimiseYul = false; - size_t m_optimiseRuns = 200; + size_t m_optimiseRuns = OptimiserSettings{}.expectedExecutionsPerDeployment; std::map> m_expectations; }; diff --git a/test/tools/fuzzer_common.cpp b/test/tools/fuzzer_common.cpp index 81f3e2c73..99a3775e1 100644 --- a/test/tools/fuzzer_common.cpp +++ b/test/tools/fuzzer_common.cpp @@ -19,6 +19,7 @@ #include "libsolidity/formal/ModelCheckerSettings.h" #include +#include #include #include @@ -34,9 +35,10 @@ using namespace std; using namespace solidity; -using namespace solidity::util; using namespace solidity::evmasm; +using namespace solidity::frontend; using namespace solidity::langutil; +using namespace solidity::util; static vector s_evmVersions = { EVMVersion::homestead(), @@ -62,7 +64,7 @@ void FuzzerUtil::testCompilerJsonInterface(string const& _input, bool _optimize, config["settings"] = Json::objectValue; config["settings"]["optimizer"] = Json::objectValue; config["settings"]["optimizer"]["enabled"] = _optimize; - config["settings"]["optimizer"]["runs"] = 200; + config["settings"]["optimizer"]["runs"] = static_cast(OptimiserSettings{}.expectedExecutionsPerDeployment); config["settings"]["evmVersion"] = "berlin"; // Enable all SourceUnit-level outputs.