Fix inlining order to correspond to source order.

This commit is contained in:
chriseth
2020-08-26 10:20:18 +02:00
parent 29b6c17246
commit e72afcba47
5 changed files with 59 additions and 71 deletions
+13 -3
View File
@@ -80,10 +80,20 @@ void FullInliner::run()
// TODO it might be good to determine a visiting order:
// first handle functions that are called from many places.
for (auto const& fun: m_functions)
// Note that the order of inlining can result in very different code.
// Since AST IDs and thus function names depend on whether or not a contract
// is compiled together with other source files, a change in AST IDs
// should have as little an impact as possible. This is the case
// if we handle inlining in source (and thus, for the IR generator,
// function name) order.
for (auto& statement: m_ast.statements)
{
handleBlock(fun.second->name, fun.second->body);
updateCodeSize(*fun.second);
if (!holds_alternative<FunctionDefinition>(statement))
continue;
FunctionDefinition& fun = std::get<FunctionDefinition>(statement);
handleBlock(fun.name, fun.body);
updateCodeSize(fun);
}
}