Cache metadata and allow after analysis in CompilerStack

This commit is contained in:
Alex Beregszaszi 2019-02-03 00:25:36 +00:00 committed by chriseth
parent 5a47f3e005
commit 26ca144647
2 changed files with 23 additions and 8 deletions

View File

@ -631,10 +631,24 @@ Json::Value CompilerStack::methodIdentifiers(string const& _contractName) const
string const& CompilerStack::metadata(string const& _contractName) const
{
if (m_stackState != CompilationSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Compilation was not successful."));
if (m_stackState < AnalysisSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Analysis was not successful."));
return contract(_contractName).metadata;
return metadata(contract(_contractName));
}
string const& CompilerStack::metadata(Contract const& _contract) const
{
if (m_stackState < AnalysisSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Analysis was not successful."));
solAssert(_contract.contract, "");
// cache the result
if (!_contract.metadata)
_contract.metadata.reset(new string(createMetadata(_contract)));
return *_contract.metadata;
}
Scanner const& CompilerStack::scanner(string const& _sourceName) const
@ -848,11 +862,8 @@ void CompilerStack::compileContract(
shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimiserSettings);
compiledContract.compiler = compiler;
string metadata = createMetadata(compiledContract);
compiledContract.metadata = metadata;
bytes cborEncodedMetadata = createCBORMetadata(
metadata,
metadata(compiledContract),
!onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)
);

View File

@ -276,7 +276,7 @@ private:
std::shared_ptr<Compiler> compiler;
eth::LinkerObject object; ///< Deployment object (includes the runtime sub-object).
eth::LinkerObject runtimeObject; ///< Runtime object.
std::string metadata; ///< The metadata json that will be hashed into the chain.
mutable std::unique_ptr<std::string const> metadata; ///< The metadata json that will be hashed into the chain.
mutable std::unique_ptr<Json::Value const> abi;
mutable std::unique_ptr<Json::Value const> userDocumentation;
mutable std::unique_ptr<Json::Value const> devDocumentation;
@ -339,6 +339,10 @@ private:
/// This will generate the JSON object and store it in the Contract object if it is not present yet.
Json::Value const& natspecDev(Contract const&) const;
/// @returns the Contract Metadata
/// This will generate the metadata and store it in the Contract object if it is not present yet.
std::string const& metadata(Contract const&) const;
/// @returns the offset of the entry point of the given function into the list of assembly items
/// or zero if it is not found or does not exist.
size_t functionEntryPoint(