-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Introduce universal compilation host to execution framework #15960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
821a8dd
e7fdb96
6b6351f
bce7aca
7afa15c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,8 +118,8 @@ SemanticTest::SemanticTest( | |
|
||
if (m_enforceGasCost) | ||
{ | ||
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata); | ||
m_compiler.setMetadataHash(CompilerStack::MetadataHash::None); | ||
m_compilerInput.metadataFormat = MetadataFormat::NoMetadata; | ||
m_compilerInput.metadataHash = MetadataHash::None; | ||
} | ||
} | ||
|
||
|
@@ -196,7 +196,7 @@ std::vector<SideEffectHook> SemanticTest::makeSideEffectHooks() const | |
}; | ||
} | ||
|
||
std::string SemanticTest::formatEventParameter(std::optional<AnnotatedEventSignature> _signature, bool _indexed, size_t _index, bytes const& _data) | ||
std::string SemanticTest::formatEventParameter(EventSignature const* _signature, bool _indexed, size_t _index, bytes const& _data) | ||
{ | ||
auto isPrintableASCII = [](bytes const& s) | ||
{ | ||
|
@@ -217,7 +217,7 @@ std::string SemanticTest::formatEventParameter(std::optional<AnnotatedEventSigna | |
ABIType abiType(ABIType::Type::Hex); | ||
if (isPrintableASCII(_data)) | ||
abiType = ABIType(ABIType::Type::String); | ||
if (_signature.has_value()) | ||
if (_signature) | ||
{ | ||
std::vector<std::string> const& types = _indexed ? _signature->indexedTypes : _signature->nonIndexedTypes; | ||
if (_index < types.size()) | ||
|
@@ -231,17 +231,19 @@ std::string SemanticTest::formatEventParameter(std::optional<AnnotatedEventSigna | |
|
||
std::vector<std::string> SemanticTest::eventSideEffectHook(FunctionCall const&) const | ||
{ | ||
auto const& output = m_compiler.output(); | ||
|
||
std::vector<std::string> sideEffects; | ||
std::vector<LogRecord> recordedLogs = ExecutionFramework::recordedLogs(); | ||
for (LogRecord const& log: recordedLogs) | ||
{ | ||
std::optional<AnnotatedEventSignature> eventSignature; | ||
EventSignature const* eventSignature = nullptr; | ||
if (!log.topics.empty()) | ||
eventSignature = matchEvent(log.topics[0]); | ||
eventSignature = output.matchEvent(log.topics[0]); | ||
std::stringstream sideEffect; | ||
sideEffect << "emit "; | ||
if (eventSignature.has_value()) | ||
sideEffect << eventSignature.value().signature; | ||
if (eventSignature) | ||
sideEffect << eventSignature->signature; | ||
else | ||
sideEffect << "<anonymous>"; | ||
|
||
|
@@ -252,7 +254,7 @@ std::vector<std::string> SemanticTest::eventSideEffectHook(FunctionCall const&) | |
size_t index{0}; | ||
for (h256 const& topic: log.topics) | ||
{ | ||
if (!eventSignature.has_value() || index != 0) | ||
if (!eventSignature || index != 0) | ||
eventStrings.push_back("#" + formatEventParameter(eventSignature, true, index, topic.asBytes())); | ||
++index; | ||
} | ||
|
@@ -273,31 +275,6 @@ std::vector<std::string> SemanticTest::eventSideEffectHook(FunctionCall const&) | |
return sideEffects; | ||
} | ||
|
||
std::optional<AnnotatedEventSignature> SemanticTest::matchEvent(util::h256 const& hash) const | ||
{ | ||
std::optional<AnnotatedEventSignature> result; | ||
for (std::string& contractName: m_compiler.contractNames()) | ||
{ | ||
ContractDefinition const& contract = m_compiler.contractDefinition(contractName); | ||
for (EventDefinition const* event: contract.events() + contract.usedInterfaceEvents()) | ||
{ | ||
FunctionTypePointer eventFunctionType = event->functionType(true); | ||
if (!event->isAnonymous() && keccak256(eventFunctionType->externalSignature()) == hash) | ||
{ | ||
AnnotatedEventSignature eventInfo; | ||
eventInfo.signature = eventFunctionType->externalSignature(); | ||
for (auto const& param: event->parameters()) | ||
if (param->isIndexed()) | ||
eventInfo.indexedTypes.emplace_back(param->type()->toString(true)); | ||
else | ||
eventInfo.nonIndexedTypes.emplace_back(param->type()->toString(true)); | ||
result = eventInfo; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
frontend::OptimiserSettings SemanticTest::optimizerSettingsFor(RequiresYulOptimizer _requiresYulOptimizer) | ||
{ | ||
switch (_requiresYulOptimizer) | ||
|
@@ -364,7 +341,7 @@ TestCase::TestResult SemanticTest::runTest( | |
for (TestFunctionCall& test: m_tests) | ||
test.reset(); | ||
|
||
std::map<std::string, solidity::test::Address> libraries; | ||
std::map<std::string, Address> libraries; | ||
|
||
bool constructed = false; | ||
|
||
|
@@ -383,13 +360,14 @@ TestCase::TestResult SemanticTest::runTest( | |
} | ||
else if (test.call().kind == FunctionCall::Kind::Library) | ||
{ | ||
std::string name = test.call().libraryFile + ":" + test.call().signature; | ||
soltestAssert( | ||
deploy(test.call().signature, 0, {}, libraries) && m_transactionSuccessful, | ||
deploy(name, 0, {}, libraries) && m_transactionSuccessful, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need the library file now? Did something semantically change in that regard? |
||
"Failed to deploy library " + test.call().signature); | ||
// For convenience, in semantic tests we assume that an unqualified name like `L` is equivalent to one | ||
// with an empty source unit name (`:L`). This is fine because the compiler never uses unqualified | ||
// names in the Yul code it produces and does not allow `linkersymbol()` at all in inline assembly. | ||
libraries[test.call().libraryFile + ":" + test.call().signature] = m_contractAddress; | ||
libraries[name] = m_contractAddress; | ||
continue; | ||
} | ||
else | ||
|
@@ -416,7 +394,13 @@ TestCase::TestResult SemanticTest::runTest( | |
} | ||
else | ||
{ | ||
ContractName contractName{m_sources.mainSourceFile, ""}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beware: |
||
|
||
auto const* contract = m_compiler.output().contract(contractName); | ||
soltestAssert(contract); | ||
|
||
bytes output; | ||
|
||
if (test.call().kind == FunctionCall::Kind::LowLevel) | ||
output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value); | ||
else if (test.call().kind == FunctionCall::Kind::Builtin) | ||
|
@@ -432,9 +416,10 @@ TestCase::TestResult SemanticTest::runTest( | |
} | ||
else | ||
{ | ||
soltestAssert(contract->interfaceSymbols.has_value()); | ||
soltestAssert( | ||
m_allowNonExistingFunctions || | ||
m_compiler.interfaceSymbols(m_compiler.lastContractName(m_sources.mainSourceFile))["methods"].contains(test.call().signature), | ||
contract->interfaceSymbols.value()["methods"].contains(test.call().signature), | ||
"The function " + test.call().signature + " is not known to the compiler" | ||
); | ||
|
||
|
@@ -462,7 +447,8 @@ TestCase::TestResult SemanticTest::runTest( | |
test.setFailure(!m_transactionSuccessful); | ||
test.setRawBytes(std::move(output)); | ||
if (test.call().kind != FunctionCall::Kind::LowLevel) | ||
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName(m_sources.mainSourceFile))); | ||
if (contract->contractABI.has_value()) | ||
test.setContractABI(contract->contractABI.value()); | ||
Comment on lines
+450
to
+451
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one of these places with experimental/nonexperimental solidity :) if we skip the experimental stuff, it would just be |
||
} | ||
|
||
std::vector<std::string> effects; | ||
|
Uh oh!
There was an error while loading. Please reload this page.