Generate internal dispatch only for functions that might actually get called via pointers

- This also adds support for internal library calls as a side-effect since they'll now be pulled into the internal dispatch automatically.
This commit is contained in:
Kamil Śliwak
2020-05-26 17:01:50 +02:00
parent b7aa6cb1f7
commit 1a2e441bc5
11 changed files with 283 additions and 63 deletions
@@ -0,0 +1,31 @@
contract Test {
bytes6 name;
constructor() public {
function (bytes6 _name) internal setter = setName;
setter("abcdef");
applyShift(leftByteShift, 3);
}
function getName() public returns (bytes6 ret) {
return name;
}
function setName(bytes6 _name) private {
name = _name;
}
function leftByteShift(bytes6 _value, uint _shift) public returns (bytes6) {
return _value << _shift * 8;
}
function applyShift(function (bytes6 _value, uint _shift) internal returns (bytes6) _shiftOperator, uint _bytes) internal {
name = _shiftOperator(name, _bytes);
}
}
// ====
// compileViaYul: also
// ----
// getName() -> "def\x00\x00\x00"
@@ -22,5 +22,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f(uint256[]): 0x20, 0x3, 0x1, 0x7, 0x3 -> 11
@@ -0,0 +1,21 @@
contract A {
function f() internal virtual returns (uint256) {
return 1;
}
}
contract B is A {
function f() internal override returns (uint256) {
return 2;
}
function g() public returns (uint256) {
function() internal returns (uint256) ptr = A.f;
return ptr();
}
}
// ====
// compileViaYul: also
// ----
// g() -> 1
@@ -0,0 +1,17 @@
library L {
function f() internal returns (uint) {
return 66;
}
}
contract C {
function g() public returns (uint) {
function() internal returns(uint) ptr;
ptr = L.f;
return ptr();
}
}
// ====
// compileViaYul: also
// ----
// g() -> 66
@@ -0,0 +1,26 @@
contract Base {
function f() internal returns (uint256 i) {
function() internal returns (uint256) ptr = g;
return ptr();
}
function g() internal virtual returns (uint256 i) {
return 1;
}
}
contract Derived is Base {
function g() internal override returns (uint256 i) {
return 2;
}
function h() public returns (uint256 i) {
return f();
}
}
// ====
// compileViaYul: also
// ----
// h() -> 2