Annotate function ID of functions that may be called via the internal dispatch.

Co-authored-by: Daniel <daniel@ekpyron.org>
This commit is contained in:
Rodrigo Q. Saramago
2023-03-20 20:14:41 +01:00
co-authored by Daniel
parent e7ec40b1af
commit a0e62bbd3d
11 changed files with 1631 additions and 27 deletions
+29
View File
@@ -526,6 +526,7 @@ bool CompilerStack::analyze()
if (noErrors)
{
createAndAssignCallGraphs();
annotateInternalFunctionIDs();
findAndReportCyclicContractDependencies();
}
@@ -1245,6 +1246,34 @@ void CompilerStack::storeContractDefinitions()
}
}
void CompilerStack::annotateInternalFunctionIDs()
{
uint64_t internalFunctionID = 1;
for (Source const* source: m_sourceOrder)
{
if (!source->ast)
continue;
for (ContractDefinition const* contract: ASTNode::filteredNodes<ContractDefinition>(source->ast->nodes()))
{
ContractDefinitionAnnotation& annotation = contract->annotation();
if (auto const* deployTimeInternalDispatch = util::valueOrNullptr((*annotation.deployedCallGraph)->edges, CallGraph::SpecialNode::InternalDispatch))
for (auto const& node: *deployTimeInternalDispatch)
if (auto const* callable = get_if<CallableDeclaration const*>(&node))
if (auto const* function = dynamic_cast<FunctionDefinition const*>(*callable))
if (!function->annotation().internalFunctionID.set())
function->annotation().internalFunctionID = internalFunctionID++;
if (auto const* creationTimeInternalDispatch = util::valueOrNullptr((*annotation.creationCallGraph)->edges, CallGraph::SpecialNode::InternalDispatch))
for (auto const& node: *creationTimeInternalDispatch)
if (auto const* callable = get_if<CallableDeclaration const*>(&node))
if (auto const* function = dynamic_cast<FunctionDefinition const*>(*callable))
// Make sure the function already got an ID since it also occurs in the deploy-time internal dispatch.
solAssert(function->annotation().internalFunctionID.set());
}
}
}
namespace
{
bool onlySafeExperimentalFeaturesActivated(set<ExperimentalFeature> const& features)
+3
View File
@@ -415,6 +415,9 @@ private:
/// Store the contract definitions in m_contracts.
void storeContractDefinitions();
/// Annotate internal dispatch function Ids
void annotateInternalFunctionIDs();
/// @returns true if the source is requested to be compiled.
bool isRequestedSource(std::string const& _sourceName) const;