mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Extract recursive function detection from Semantics into the CallGraph.
This commit is contained in:
committed by
chriseth
parent
bd6cd027a3
commit
99d831d7d1
@@ -102,33 +102,13 @@ map<YulString, SideEffects> SideEffectsPropagator::sideEffects(
|
||||
// is actually a bit different from "not movable".
|
||||
|
||||
map<YulString, SideEffects> ret;
|
||||
for (auto const& function: _directCallGraph.functionsWithLoops)
|
||||
for (auto const& function: _directCallGraph.functionsWithLoops + _directCallGraph.recursiveFunctions())
|
||||
{
|
||||
ret[function].movable = false;
|
||||
ret[function].sideEffectFree = false;
|
||||
ret[function].sideEffectFreeIfNoMSize = false;
|
||||
}
|
||||
|
||||
// Detect recursive functions.
|
||||
for (auto const& call: _directCallGraph.functionCalls)
|
||||
{
|
||||
// TODO we could shortcut the search as soon as we find a
|
||||
// function that has as bad side-effects as we can
|
||||
// ever achieve via recursion.
|
||||
auto search = [&](YulString const& _functionName, util::CycleDetector<YulString>& _cycleDetector, size_t) {
|
||||
for (auto const& callee: _directCallGraph.functionCalls.at(_functionName))
|
||||
if (!_dialect.builtin(callee))
|
||||
if (_cycleDetector.run(callee))
|
||||
return;
|
||||
};
|
||||
if (util::CycleDetector<YulString>(search).run(call.first))
|
||||
{
|
||||
ret[call.first].movable = false;
|
||||
ret[call.first].sideEffectFree = false;
|
||||
ret[call.first].sideEffectFreeIfNoMSize = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& call: _directCallGraph.functionCalls)
|
||||
{
|
||||
YulString funName = call.first;
|
||||
|
||||
Reference in New Issue
Block a user