mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13687 from ethereum/hashNumberLiterals
Hash number literals according to their value instead of their string representation.
This commit is contained in:
commit
9db2da0385
@ -13,6 +13,7 @@ Compiler Features:
|
|||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
* Yul Optimizer: Hash hex and decimal literals according to their value instead of their representation, improving the detection of equivalent functions.
|
||||||
* Solidity Upgrade Tool ``solidity-upgrade``: Fix the tool returning success code on uncaught exceptions.
|
* Solidity Upgrade Tool ``solidity-upgrade``: Fix the tool returning success code on uncaught exceptions.
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,6 +54,9 @@ std::map<Block const*, uint64_t> BlockHasher::run(Block const& _block)
|
|||||||
void BlockHasher::operator()(Literal const& _literal)
|
void BlockHasher::operator()(Literal const& _literal)
|
||||||
{
|
{
|
||||||
hash64(compileTimeLiteralHash("Literal"));
|
hash64(compileTimeLiteralHash("Literal"));
|
||||||
|
if (_literal.kind == LiteralKind::Number)
|
||||||
|
hash64(std::hash<u256>{}(valueOfNumberLiteral(_literal)));
|
||||||
|
else
|
||||||
hash64(_literal.value.hash());
|
hash64(_literal.value.hash());
|
||||||
hash64(_literal.type.hash());
|
hash64(_literal.type.hash());
|
||||||
hash8(static_cast<uint8_t>(_literal.kind));
|
hash8(static_cast<uint8_t>(_literal.kind));
|
||||||
|
@ -33,8 +33,8 @@ contract C {
|
|||||||
// compileViaYul: true
|
// compileViaYul: true
|
||||||
// ----
|
// ----
|
||||||
// test1((uint8[],uint8[2])[][][]): 0x20, 1, 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29 -> 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29
|
// test1((uint8[],uint8[2])[][][]): 0x20, 1, 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29 -> 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29
|
||||||
// gas irOptimized: 332334
|
// gas irOptimized: 332586
|
||||||
// test2((uint8[],uint8[2])[][1][]): 0x20, 2, 0x40, 0x0160, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13, 0x20, 1, 0x20, 0x60, 31, 37, 2, 23, 29 -> 0x20, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13
|
// test2((uint8[],uint8[2])[][1][]): 0x20, 2, 0x40, 0x0160, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13, 0x20, 1, 0x20, 0x60, 31, 37, 2, 23, 29 -> 0x20, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13
|
||||||
// gas irOptimized: 145029
|
// gas irOptimized: 145182
|
||||||
// test3((uint8[],uint8[2])[1][][2]): 0x20, 0x40, 0x60, 0, 2, 0x40, 288, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13 -> 0x20, 2, 0x40, 288, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13
|
// test3((uint8[],uint8[2])[1][][2]): 0x20, 0x40, 0x60, 0, 2, 0x40, 288, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13 -> 0x20, 2, 0x40, 288, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13
|
||||||
// gas irOptimized: 192344
|
// gas irOptimized: 192512
|
||||||
|
@ -31,8 +31,8 @@ contract C {
|
|||||||
// compileViaYul: true
|
// compileViaYul: true
|
||||||
// ----
|
// ----
|
||||||
// test1((uint8[],uint8[2])[][]): 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29 -> 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29
|
// test1((uint8[],uint8[2])[][]): 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29 -> 0x20, 2, 0x40, 0x0140, 1, 0x20, 0x60, 3, 7, 2, 1, 2, 2, 0x40, 0x0100, 0x60, 17, 19, 2, 11, 13, 0x60, 31, 37, 2, 23, 29
|
||||||
// gas irOptimized: 308790
|
// gas irOptimized: 309123
|
||||||
// test2((uint8[],uint8[2])[][1]): 0x20, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13 -> 0x20, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13
|
// test2((uint8[],uint8[2])[][1]): 0x20, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13 -> 0x20, 0x20, 1, 0x20, 0x60, 17, 19, 2, 11, 13
|
||||||
// gas irOptimized: 118077
|
// gas irOptimized: 118188
|
||||||
// test3((uint8[],uint8[2])[1][]): 0x20, 2, 0x40, 0x0120, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13 -> 0x20, 2, 0x40, 0x0120, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13
|
// test3((uint8[],uint8[2])[1][]): 0x20, 2, 0x40, 0x0120, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13 -> 0x20, 2, 0x40, 0x0120, 0x20, 0x60, 3, 7, 2, 1, 2, 0x20, 0x60, 17, 19, 2, 11, 13
|
||||||
// gas irOptimized: 190775
|
// gas irOptimized: 190997
|
||||||
|
@ -28,7 +28,7 @@ contract C {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// constructor() ->
|
// constructor() ->
|
||||||
// gas irOptimized: 518935
|
// gas irOptimized: 464753
|
||||||
// gas legacy: 729908
|
// gas legacy: 729908
|
||||||
// gas legacyOptimized: 493347
|
// gas legacyOptimized: 493347
|
||||||
// h() -> 0x20, 0x40, 0x00, 0
|
// h() -> 0x20, 0x40, 0x00, 0
|
||||||
|
@ -299,6 +299,6 @@ contract Test {
|
|||||||
// gas legacyOptimized: 267239
|
// gas legacyOptimized: 267239
|
||||||
// verifyTx() -> true
|
// verifyTx() -> true
|
||||||
// ~ emit Verified(string): 0x20, 0x16, "Successfully verified."
|
// ~ emit Verified(string): 0x20, 0x16, "Successfully verified."
|
||||||
// gas irOptimized: 783949
|
// gas irOptimized: 784027
|
||||||
// gas legacy: 805423
|
// gas legacy: 805423
|
||||||
// gas legacyOptimized: 772571
|
// gas legacyOptimized: 772571
|
||||||
|
@ -49,11 +49,11 @@ contract C {
|
|||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// test_f() -> true
|
// test_f() -> true
|
||||||
// gas irOptimized: 122053
|
// gas irOptimized: 122510
|
||||||
// gas legacy: 126150
|
// gas legacy: 126150
|
||||||
// gas legacyOptimized: 123163
|
// gas legacyOptimized: 123163
|
||||||
// test_g() -> true
|
// test_g() -> true
|
||||||
// gas irOptimized: 106138
|
// gas irOptimized: 106903
|
||||||
// gas legacy: 112481
|
// gas legacy: 112481
|
||||||
// gas legacyOptimized: 107706
|
// gas legacyOptimized: 107706
|
||||||
// addresses(uint256): 0 -> 0x18
|
// addresses(uint256): 0 -> 0x18
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
f()
|
||||||
|
g()
|
||||||
|
function f() { mstore(0x01, mload(0x00)) }
|
||||||
|
function g() { mstore(1, mload(0)) }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// step: equivalentFunctionCombiner
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// f()
|
||||||
|
// f()
|
||||||
|
// function f()
|
||||||
|
// { mstore(0x01, mload(0x00)) }
|
||||||
|
// function g()
|
||||||
|
// { mstore(1, mload(0)) }
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user