Merge pull request #8183 from ethereum/functionOptionsYulIR

[YulIR] Function call options for Yul IR
This commit is contained in:
Daniel Kirchner 2020-03-12 10:49:51 +01:00 committed by GitHub
commit bdd8045db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 1 deletions

View File

@ -2954,7 +2954,7 @@ vector<tuple<string, TypePointer>> FunctionType::makeStackItems() const
if (m_valueSet)
slots.emplace_back("value", TypeProvider::uint256());
if (m_saltSet)
slots.emplace_back("salt", TypeProvider::uint256());
slots.emplace_back("salt", TypeProvider::fixedBytes(32));
if (bound())
for (auto const& [boundName, boundType]: m_parameterTypes.front()->stackItems())
slots.emplace_back("self_" + boundName, boundType);

View File

@ -739,6 +739,25 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
}
}
void IRGeneratorForStatements::endVisit(FunctionCallOptions const& _options)
{
FunctionType const& previousType = dynamic_cast<FunctionType const&>(*_options.expression().annotation().type);
solUnimplementedAssert(!previousType.bound(), "");
// Copy over existing values.
for (auto const& item: previousType.stackItems())
define(IRVariable(_options).part(get<0>(item)), IRVariable(_options.expression()).part(get<0>(item)));
for (size_t i = 0; i < _options.names().size(); ++i)
{
string const& name = *_options.names()[i];
solAssert(name == "salt" || name == "gas" || name == "value", "");
define(IRVariable(_options).part(name), *_options.options()[i]);
}
}
void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
{
ASTString const& member = _memberAccess.memberName();

View File

@ -60,6 +60,7 @@ public:
void endVisit(UnaryOperation const& _unaryOperation) override;
bool visit(BinaryOperation const& _binOp) override;
void endVisit(FunctionCall const& _funCall) override;
void endVisit(FunctionCallOptions const& _funCallOptions) override;
void endVisit(MemberAccess const& _memberAccess) override;
bool visit(InlineAssembly const& _inlineAsm) override;
void endVisit(IndexAccess const& _indexAccess) override;

View File

@ -0,0 +1,17 @@
pragma solidity >= 0.6.0;
contract C {
function g(uint n) external payable returns (uint, uint) {
return (msg.value * 1000, n);
}
function f(uint n) public payable returns (uint, uint) {
return this.g{value: 10}(n);
}
}
// ====
// compileViaYul: also
// ----
// g(uint256), 1 ether: 4 -> 1000000000000000000000, 4
// f(uint256), 11 ether: 2 -> 10000, 2