Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed Sep 13, 2023
1 parent aad7bb4 commit 6e99d76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 11 additions & 8 deletions libsolidity/codegen/ir/IRGenerationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <libsolutil/StringUtils.h>

#include <range/v3/view/map.hpp>
#include <range/v3/algorithm/find.hpp>

using namespace solidity;
using namespace solidity::util;
Expand All @@ -41,7 +42,7 @@ std::string IRGenerationContext::enqueueFunctionForCodeGeneration(FunctionDefini
std::string name = IRNames::function(_function);

if (!m_functions.contains(name))
m_functionGenerationQueue.push(&_function);
m_functionGenerationQueue.push_back(&_function);

return name;
}
Expand All @@ -51,7 +52,7 @@ FunctionDefinition const* IRGenerationContext::dequeueFunctionForCodeGeneration(
solAssert(!m_functionGenerationQueue.empty(), "");

FunctionDefinition const* result = m_functionGenerationQueue.front();
m_functionGenerationQueue.pop();
m_functionGenerationQueue.pop_front();
return result;
}

Expand Down Expand Up @@ -132,7 +133,7 @@ void IRGenerationContext::initializeInternalDispatch(InternalDispatchMap _intern
{
solAssert(internalDispatchClean(), "");

for (DispatchSet const& functions: _internalDispatch | ranges::views::values)
for (DispatchQueue const& functions: _internalDispatch | ranges::views::values)
for (auto function: functions)
enqueueFunctionForCodeGeneration(*function);

Expand All @@ -153,11 +154,13 @@ void IRGenerationContext::addToInternalDispatch(FunctionDefinition const& _funct

YulArity arity = YulArity::fromType(*functionType);

if (m_internalDispatchMap.count(arity) != 0 && m_internalDispatchMap[arity].count(&_function) != 0)
// Note that m_internalDispatchMap[arity] is a set with a custom comparator, which looks at function IDs not definitions
solAssert(*m_internalDispatchMap[arity].find(&_function) == &_function, "Different definitions with the same function ID");

m_internalDispatchMap[arity].insert(&_function);
if (m_internalDispatchMap.count(arity) != 0)
{
auto it = ranges::find(m_internalDispatchMap[arity], &_function);
if (it != ranges::end(m_internalDispatchMap[arity]))
solAssert(*it == &_function, "Different definitions with the same function ID");
}
m_internalDispatchMap[arity].push_back(&_function);
enqueueFunctionForCodeGeneration(_function);
}

Expand Down
6 changes: 2 additions & 4 deletions libsolidity/codegen/ir/IRGenerationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@
#include <set>
#include <string>
#include <memory>
#include <queue>

namespace solidity::frontend
{

class YulUtilFunctions;
class ABIFunctions;

using DispatchQueue = std::queue<FunctionDefinition const*>;
using DispatchSet = std::set<FunctionDefinition const*>;
using InternalDispatchMap = std::map<YulArity, DispatchSet>;
using DispatchQueue = std::deque<FunctionDefinition const*>;
using InternalDispatchMap = std::map<YulArity, DispatchQueue>;

/**
* Class that contains contextual information during IR generation.
Expand Down

0 comments on commit 6e99d76

Please sign in to comment.