From c63b768fff749bd4bbb7b01a9340f00abf32333f Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 7 Sep 2021 17:37:36 +0200 Subject: [PATCH] Sort yul functions by creation time. --- .../codegen/MultiUseYulFunctionCollector.cpp | 19 +++++++------------ .../codegen/MultiUseYulFunctionCollector.h | 10 +++++----- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libsolidity/codegen/MultiUseYulFunctionCollector.cpp b/libsolidity/codegen/MultiUseYulFunctionCollector.cpp index 57d2a856c..69d30c6c8 100644 --- a/libsolidity/codegen/MultiUseYulFunctionCollector.cpp +++ b/libsolidity/codegen/MultiUseYulFunctionCollector.cpp @@ -33,13 +33,8 @@ using namespace solidity::util; string MultiUseYulFunctionCollector::requestedFunctions() { - string result; - for (auto const& [name, code]: m_requestedFunctions) - { - solAssert(code != "< arguments; vector returnParameters; string body = _creator(arguments, returnParameters); solAssert(!body.empty(), ""); - m_requestedFunctions[_name] = Whiskers(R"( + m_code += Whiskers(R"( function () -> { } @@ -80,7 +75,7 @@ string MultiUseYulFunctionCollector::createFunction( ("args", joinHumanReadable(arguments)) ("retParams", joinHumanReadable(returnParameters)) ("body", body) - .render();; + .render(); } return _name; } diff --git a/libsolidity/codegen/MultiUseYulFunctionCollector.h b/libsolidity/codegen/MultiUseYulFunctionCollector.h index 7883fa668..050b5858f 100644 --- a/libsolidity/codegen/MultiUseYulFunctionCollector.h +++ b/libsolidity/codegen/MultiUseYulFunctionCollector.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace solidity::frontend { @@ -46,9 +47,8 @@ public: std::function&, std::vector&)> const& _creator ); - /// @returns concatenation of all generated functions. - /// Guarantees that the order of functions in the generated code is deterministic and - /// platform-independent. + /// @returns concatenation of all generated functions in the order in which they were + /// generated. /// Clears the internal list, i.e. calling it again will result in an /// empty return value. std::string requestedFunctions(); @@ -57,8 +57,8 @@ public: bool contains(std::string const& _name) const { return m_requestedFunctions.count(_name) > 0; } private: - /// Map from function name to code for a multi-use function. - std::map m_requestedFunctions; + std::set m_requestedFunctions; + std::string m_code; }; }