mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into HEAD
This commit is contained in:
+1
-1
@@ -188,7 +188,7 @@ add_executable(soltest ${sources}
|
||||
${libsolidity_util_sources}
|
||||
${yul_phaser_sources}
|
||||
)
|
||||
target_link_libraries(soltest PRIVATE libsolc yul solidity yulInterpreter evmasm solutil Boost::boost Boost::filesystem Boost::program_options Boost::unit_test_framework evmc)
|
||||
target_link_libraries(soltest PRIVATE libsolc yul solidity smtutil solutil Boost::boost yulInterpreter evmasm Boost::filesystem Boost::program_options Boost::unit_test_framework evmc)
|
||||
|
||||
|
||||
# Special compilation flag for Visual Studio (version 2019 at least affected)
|
||||
|
||||
+4
-1
@@ -89,7 +89,10 @@ int registerTests(
|
||||
}
|
||||
else
|
||||
{
|
||||
static vector<unique_ptr<string>> filenames;
|
||||
// This must be a vector of unique_ptrs because Boost.Test keeps the equivalent of a string_view to the filename
|
||||
// that is passed in. If the strings were stored directly in the vector, pointers/references to them would be
|
||||
// invalidated on reallocation.
|
||||
static vector<unique_ptr<string const>> filenames;
|
||||
|
||||
filenames.emplace_back(make_unique<string>(_path.string()));
|
||||
_suite.add(make_test_case(
|
||||
|
||||
@@ -154,7 +154,7 @@ object "object" {
|
||||
|
||||
|
||||
Binary representation:
|
||||
0061736d0100000001480a60000060017e017e60027e7e017e60037e7e7e017e60047e7e7e7e017e60057e7e7e7e7e0060087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60027f7f0060037f7f7f0002310208657468657265756d0c73746f7261676553746f7265000808657468657265756d0c63616c6c44617461436f70790009030e0d0003070407020704010101050605030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00020a80090dee02011f7e4200210002402000200020002000100921012300210223012103230221040b2001210520022106200321072004210842012109200020008420002009848450ada745ada745ad210a02400340200aa745ad500d01024002402005200620072008200020002000420a1008210b2300210c2301210d2302210e0b0240200b200c200d200e1005210f2300211023012111230221120b200f20108420112012848450ada745ad42005204400c030b024020052006200720082000200020004202100621132300211423012115230221160b201320148420152016848450ada745ad42005204400c030b0240200520062007200820002000200042041006211723002118230121192302211a0b20172018842019201a848450ada745ad42005204400c010b0b0240200520062007200820002000200020091004211b2300211c2301211d2302211e0b201b2105201c2106201d2107201e21080b0b20002000200020002005200620072008100e0b2c01037e200020017c2105200520027c21032005200054ada72003200554ada772ada7ad21042004240020030b6f010b7e200320077c210c200c42007c210b024020022006200c200354ada7200b200c54ada772ada7ad1003210d2300210e0b200d210a024020012005200e1003210f230021100b200f2109024020002004201010032111230021120b2011210820092400200a2401200b240220080b2301047e200020018420022003848450ada7ad210720052400200624012007240220040b4601047e2000200451ad42005204402001200551ad42005204402002200651ad42005204402003200751ad42005204404201210b0b0b0b0b20092400200a2401200b240220080b2a01027e02402000200154ad21032003420151044042ffffffff0f2102052000200152ad21020b0b20020b930101087e4200210c0240200020041007210d200d42005104400240200120051007210e200e42005104400240200220061007210f200f42005104402003200754ad210c05200f42015104404200210c054201210c0b0b0b05200e42015104404200210c054201210c0b0b0b05200d42015104404200210c054201210c0b0b0b200ca7ad210b20092400200a2401200b240220080b8c0101087e4200200020018420028452ad4200520440000b4200200342208852ad4200520440000b4200a72003a7ada74220a710014200a7290300100c21084200a74208a76aada7290300100c21094200a74210a76aada7290300100c210a4200a74218a76aada7290300100c210b2008210420092105200a2106200b210720052400200624012007240220040b1c01017e20004208864280fe0383200042088842ff018384210120010b1b01027e2000100a421086210220022000421088100a84210120010b1b01027e2000100b422086210220022000422088100b84210120010b3e01007e2000a72001100c3703002000a74208a76aada72002100c3703002000a74210a76aada72003100c3703002000a74218a76aada72004100c3703000b2401007e42002000200120022003100d42202004200520062007100d4200a74220a710000b
|
||||
0061736d0100000001480a60000060017e017e60027e7e017e60037e7e7e017e60047e7e7e7e017e60057e7e7e7e7e0060087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60027f7f0060037f7f7f0002310208657468657265756d0c73746f7261676553746f7265000808657468657265756d0c63616c6c44617461436f70790009030e0d0003070407020704010101050605030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00020a82090df002011f7e4200210002402000200020002000100921012300210223012103230221040b2001210520022106200321072004210842012109200020008420002009848450ada745ada745ad210a02400340200aa745ad500d01024002402005200620072008200020002000420a1008210b2300210c2301210d2302210e0b0240200b200c200d200e1005210f2300211023012111230221120b200f20108420112012848450ada745ad42005204400c030b024020052006200720082000200020004202100621132300211423012115230221160b201320148420152016848450ada745ad42005204400c030b0240200520062007200820002000200042041006211723002118230121192302211a0b20172018842019201a848450ada745ad42005204400c010b0b0240200520062007200820002000200020091004211b2300211c2301211d2302211e0b201b2105201c2106201d2107201e21080c000b0b20002000200020002005200620072008100e0b2c01037e200020017c2105200520027c21032005200054ada72003200554ada772ada7ad21042004240020030b6f010b7e200320077c210c200c42007c210b024020022006200c200354ada7200b200c54ada772ada7ad1003210d2300210e0b200d210a024020012005200e1003210f230021100b200f2109024020002004201010032111230021120b2011210820092400200a2401200b240220080b2301047e200020018420022003848450ada7ad210720052400200624012007240220040b4601047e2000200451ad42005204402001200551ad42005204402002200651ad42005204402003200751ad42005204404201210b0b0b0b0b20092400200a2401200b240220080b2a01027e02402000200154ad21032003420151044042ffffffff0f2102052000200152ad21020b0b20020b930101087e4200210c0240200020041007210d200d42005104400240200120051007210e200e42005104400240200220061007210f200f42005104402003200754ad210c05200f42015104404200210c054201210c0b0b0b05200e42015104404200210c054201210c0b0b0b05200d42015104404200210c054201210c0b0b0b200ca7ad210b20092400200a2401200b240220080b8c0101087e4200200020018420028452ad4200520440000b4200200342208852ad4200520440000b4200a72003a7ada74220a710014200a7290300100c21084200a74208a76aada7290300100c21094200a74210a76aada7290300100c210a4200a74218a76aada7290300100c210b2008210420092105200a2106200b210720052400200624012007240220040b1c01017e20004208864280fe0383200042088842ff018384210120010b1b01027e2000100a421086210220022000421088100a84210120010b1b01027e2000100b422086210220022000422088100b84210120010b3e01007e2000a72001100c3703002000a74208a76aada72002100c3703002000a74210a76aada72003100c3703002000a74218a76aada72004100c3703000b2401007e42002000200120022003100d42202004200520062007100d4200a74220a710000b
|
||||
|
||||
Text representation:
|
||||
(module
|
||||
@@ -213,7 +213,7 @@ Text representation:
|
||||
(local.set $_2 (i64.const 1))
|
||||
(local.set $_3 (i64.extend_i32_u (i32.eqz (i32.wrap_i64 (i64.extend_i32_u (i32.eqz (i32.wrap_i64 (i64.extend_i32_u (i64.eqz (i64.or (i64.or (local.get $_1) (local.get $_1)) (i64.or (local.get $_1) (local.get $_2))))))))))))
|
||||
(block $label_
|
||||
(loop
|
||||
(loop $label__4
|
||||
(br_if $label_ (i64.eqz (i64.extend_i32_u (i32.eqz (i32.wrap_i64 (local.get $_3))))))
|
||||
(block $label__3
|
||||
(block
|
||||
@@ -266,6 +266,7 @@ Text representation:
|
||||
(local.set $x_5 (local.get $x_9))
|
||||
(local.set $x_6 (local.get $x_10))
|
||||
(local.set $x_7 (local.get $x_11))
|
||||
(br $label__4)
|
||||
)
|
||||
|
||||
)
|
||||
@@ -413,22 +414,22 @@ Text representation:
|
||||
(local $z3 i64)
|
||||
(local $z4 i64)
|
||||
(local $z i64)
|
||||
(local $condition_4 i64)
|
||||
(local $condition_5 i64)
|
||||
(local $condition_6 i64)
|
||||
(local $condition_7 i64)
|
||||
(local.set $z (i64.const 0))
|
||||
(block
|
||||
(local.set $condition_4 (call $cmp (local.get $x1) (local.get $y1)))
|
||||
(if (i64.eq (local.get $condition_4) (i64.const 0)) (then
|
||||
(local.set $condition_5 (call $cmp (local.get $x1) (local.get $y1)))
|
||||
(if (i64.eq (local.get $condition_5) (i64.const 0)) (then
|
||||
(block
|
||||
(local.set $condition_5 (call $cmp (local.get $x2) (local.get $y2)))
|
||||
(if (i64.eq (local.get $condition_5) (i64.const 0)) (then
|
||||
(local.set $condition_6 (call $cmp (local.get $x2) (local.get $y2)))
|
||||
(if (i64.eq (local.get $condition_6) (i64.const 0)) (then
|
||||
(block
|
||||
(local.set $condition_6 (call $cmp (local.get $x3) (local.get $y3)))
|
||||
(if (i64.eq (local.get $condition_6) (i64.const 0)) (then
|
||||
(local.set $condition_7 (call $cmp (local.get $x3) (local.get $y3)))
|
||||
(if (i64.eq (local.get $condition_7) (i64.const 0)) (then
|
||||
(local.set $z (i64.extend_i32_u (i64.lt_u (local.get $x4) (local.get $y4))))
|
||||
)(else
|
||||
(if (i64.eq (local.get $condition_6) (i64.const 1)) (then
|
||||
(if (i64.eq (local.get $condition_7) (i64.const 1)) (then
|
||||
(local.set $z (i64.const 0))
|
||||
)(else
|
||||
(local.set $z (i64.const 1))
|
||||
@@ -437,7 +438,7 @@ Text representation:
|
||||
|
||||
)
|
||||
)(else
|
||||
(if (i64.eq (local.get $condition_5) (i64.const 1)) (then
|
||||
(if (i64.eq (local.get $condition_6) (i64.const 1)) (then
|
||||
(local.set $z (i64.const 0))
|
||||
)(else
|
||||
(local.set $z (i64.const 1))
|
||||
@@ -446,7 +447,7 @@ Text representation:
|
||||
|
||||
)
|
||||
)(else
|
||||
(if (i64.eq (local.get $condition_4) (i64.const 1)) (then
|
||||
(if (i64.eq (local.get $condition_5) (i64.const 1)) (then
|
||||
(local.set $z (i64.const 0))
|
||||
)(else
|
||||
(local.set $z (i64.const 1))
|
||||
|
||||
@@ -85,10 +85,10 @@
|
||||
{
|
||||
"C":
|
||||
[
|
||||
20
|
||||
23
|
||||
]
|
||||
},
|
||||
"id": 21,
|
||||
"id": 24,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
@@ -98,89 +98,126 @@
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"fullyImplemented": true,
|
||||
"id": 20,
|
||||
"id": 23,
|
||||
"linearizedBaseContracts":
|
||||
[
|
||||
20
|
||||
23
|
||||
],
|
||||
"name": "C",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"anonymous": false,
|
||||
"constant": false,
|
||||
"documentation":
|
||||
{
|
||||
"id": 7,
|
||||
"nodeType": "StructuredDocumentation",
|
||||
"src": "15:26:3",
|
||||
"text": "Some comment on Evt."
|
||||
"src": "15:32:3",
|
||||
"text": "Some comment on state var."
|
||||
},
|
||||
"functionSelector": "c19d93fb",
|
||||
"id": 9,
|
||||
"name": "Evt",
|
||||
"nodeType": "EventDefinition",
|
||||
"parameters":
|
||||
"mutability": "mutable",
|
||||
"name": "state",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 23,
|
||||
"src": "48:17:3",
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 8,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "51:2:3"
|
||||
"name": "uint",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "48:4:3",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
}
|
||||
},
|
||||
"src": "42:12:3"
|
||||
"visibility": "public"
|
||||
},
|
||||
{
|
||||
"body":
|
||||
{
|
||||
"id": 13,
|
||||
"nodeType": "Block",
|
||||
"src": "99:6:3",
|
||||
"statements":
|
||||
[
|
||||
{
|
||||
"id": 12,
|
||||
"nodeType": "PlaceholderStatement",
|
||||
"src": "101:1:3"
|
||||
}
|
||||
]
|
||||
},
|
||||
"anonymous": false,
|
||||
"documentation":
|
||||
{
|
||||
"id": 10,
|
||||
"nodeType": "StructuredDocumentation",
|
||||
"src": "57:26:3",
|
||||
"text": "Some comment on mod."
|
||||
"src": "69:26:3",
|
||||
"text": "Some comment on Evt."
|
||||
},
|
||||
"id": 14,
|
||||
"name": "mod",
|
||||
"nodeType": "ModifierDefinition",
|
||||
"id": 12,
|
||||
"name": "Evt",
|
||||
"nodeType": "EventDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 11,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "96:2:3"
|
||||
"src": "105:2:3"
|
||||
},
|
||||
"src": "84:21:3",
|
||||
"src": "96:12:3"
|
||||
},
|
||||
{
|
||||
"body":
|
||||
{
|
||||
"id": 16,
|
||||
"nodeType": "Block",
|
||||
"src": "153:6:3",
|
||||
"statements":
|
||||
[
|
||||
{
|
||||
"id": 15,
|
||||
"nodeType": "PlaceholderStatement",
|
||||
"src": "155:1:3"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation":
|
||||
{
|
||||
"id": 13,
|
||||
"nodeType": "StructuredDocumentation",
|
||||
"src": "111:26:3",
|
||||
"text": "Some comment on mod."
|
||||
},
|
||||
"id": 17,
|
||||
"name": "mod",
|
||||
"nodeType": "ModifierDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 14,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "150:2:3"
|
||||
},
|
||||
"src": "138:21:3",
|
||||
"virtual": false,
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"body":
|
||||
{
|
||||
"id": 18,
|
||||
"id": 21,
|
||||
"nodeType": "Block",
|
||||
"src": "155:2:3",
|
||||
"src": "209:2:3",
|
||||
"statements": []
|
||||
},
|
||||
"documentation":
|
||||
{
|
||||
"id": 15,
|
||||
"id": 18,
|
||||
"nodeType": "StructuredDocumentation",
|
||||
"src": "108:25:3",
|
||||
"src": "162:25:3",
|
||||
"text": "Some comment on fn."
|
||||
},
|
||||
"functionSelector": "a4a2c40b",
|
||||
"id": 19,
|
||||
"id": 22,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
"modifiers": [],
|
||||
@@ -188,29 +225,29 @@
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 16,
|
||||
"id": 19,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "145:2:3"
|
||||
"src": "199:2:3"
|
||||
},
|
||||
"returnParameters":
|
||||
{
|
||||
"id": 17,
|
||||
"id": 20,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "155:0:3"
|
||||
"src": "209:0:3"
|
||||
},
|
||||
"scope": 20,
|
||||
"src": "134:23:3",
|
||||
"scope": 23,
|
||||
"src": "188:23:3",
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 21,
|
||||
"src": "0:159:3"
|
||||
"scope": 24,
|
||||
"src": "0:213:3"
|
||||
}
|
||||
],
|
||||
"src": "0:160:3"
|
||||
"src": "0:214:3"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -11,6 +11,7 @@ contract C {}
|
||||
// ---- SOURCE: c
|
||||
|
||||
contract C {
|
||||
/** Some comment on state var.*/ uint public state;
|
||||
/** Some comment on Evt.*/ event Evt();
|
||||
/** Some comment on mod.*/ modifier mod() { _; }
|
||||
/** Some comment on fn.*/ function fn() public {}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{
|
||||
"C":
|
||||
[
|
||||
20
|
||||
23
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -28,13 +28,52 @@
|
||||
"fullyImplemented": true,
|
||||
"linearizedBaseContracts":
|
||||
[
|
||||
20
|
||||
23
|
||||
],
|
||||
"name": "C",
|
||||
"scope": 21
|
||||
"scope": 24
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"constant": false,
|
||||
"functionSelector": "c19d93fb",
|
||||
"mutability": "mutable",
|
||||
"name": "state",
|
||||
"scope": 23,
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"type": "uint256",
|
||||
"visibility": "public"
|
||||
},
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"name": "uint",
|
||||
"type": "uint256"
|
||||
},
|
||||
"id": 8,
|
||||
"name": "ElementaryTypeName",
|
||||
"src": "48:4:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"text": "Some comment on state var."
|
||||
},
|
||||
"id": 7,
|
||||
"name": "StructuredDocumentation",
|
||||
"src": "15:32:3"
|
||||
}
|
||||
],
|
||||
"id": 9,
|
||||
"name": "VariableDeclaration",
|
||||
"src": "48:17:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
@@ -48,9 +87,9 @@
|
||||
{
|
||||
"text": "Some comment on Evt."
|
||||
},
|
||||
"id": 7,
|
||||
"id": 10,
|
||||
"name": "StructuredDocumentation",
|
||||
"src": "15:26:3"
|
||||
"src": "69:26:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -61,14 +100,14 @@
|
||||
]
|
||||
},
|
||||
"children": [],
|
||||
"id": 8,
|
||||
"id": 11,
|
||||
"name": "ParameterList",
|
||||
"src": "51:2:3"
|
||||
"src": "105:2:3"
|
||||
}
|
||||
],
|
||||
"id": 9,
|
||||
"id": 12,
|
||||
"name": "EventDefinition",
|
||||
"src": "42:12:3"
|
||||
"src": "96:12:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -84,9 +123,9 @@
|
||||
{
|
||||
"text": "Some comment on mod."
|
||||
},
|
||||
"id": 10,
|
||||
"id": 13,
|
||||
"name": "StructuredDocumentation",
|
||||
"src": "57:26:3"
|
||||
"src": "111:26:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -97,27 +136,27 @@
|
||||
]
|
||||
},
|
||||
"children": [],
|
||||
"id": 11,
|
||||
"id": 14,
|
||||
"name": "ParameterList",
|
||||
"src": "96:2:3"
|
||||
"src": "150:2:3"
|
||||
},
|
||||
{
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"id": 12,
|
||||
"id": 15,
|
||||
"name": "PlaceholderStatement",
|
||||
"src": "101:1:3"
|
||||
"src": "155:1:3"
|
||||
}
|
||||
],
|
||||
"id": 13,
|
||||
"id": 16,
|
||||
"name": "Block",
|
||||
"src": "99:6:3"
|
||||
"src": "153:6:3"
|
||||
}
|
||||
],
|
||||
"id": 14,
|
||||
"id": 17,
|
||||
"name": "ModifierDefinition",
|
||||
"src": "84:21:3"
|
||||
"src": "138:21:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -131,7 +170,7 @@
|
||||
null
|
||||
],
|
||||
"name": "fn",
|
||||
"scope": 20,
|
||||
"scope": 23,
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false,
|
||||
"visibility": "public"
|
||||
@@ -143,9 +182,9 @@
|
||||
{
|
||||
"text": "Some comment on fn."
|
||||
},
|
||||
"id": 15,
|
||||
"id": 18,
|
||||
"name": "StructuredDocumentation",
|
||||
"src": "108:25:3"
|
||||
"src": "162:25:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -156,9 +195,9 @@
|
||||
]
|
||||
},
|
||||
"children": [],
|
||||
"id": 16,
|
||||
"id": 19,
|
||||
"name": "ParameterList",
|
||||
"src": "145:2:3"
|
||||
"src": "199:2:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -169,9 +208,9 @@
|
||||
]
|
||||
},
|
||||
"children": [],
|
||||
"id": 17,
|
||||
"id": 20,
|
||||
"name": "ParameterList",
|
||||
"src": "155:0:3"
|
||||
"src": "209:0:3"
|
||||
},
|
||||
{
|
||||
"attributes":
|
||||
@@ -182,22 +221,22 @@
|
||||
]
|
||||
},
|
||||
"children": [],
|
||||
"id": 18,
|
||||
"id": 21,
|
||||
"name": "Block",
|
||||
"src": "155:2:3"
|
||||
"src": "209:2:3"
|
||||
}
|
||||
],
|
||||
"id": 19,
|
||||
"id": 22,
|
||||
"name": "FunctionDefinition",
|
||||
"src": "134:23:3"
|
||||
"src": "188:23:3"
|
||||
}
|
||||
],
|
||||
"id": 20,
|
||||
"id": 23,
|
||||
"name": "ContractDefinition",
|
||||
"src": "0:159:3"
|
||||
"src": "0:213:3"
|
||||
}
|
||||
],
|
||||
"id": 21,
|
||||
"id": 24,
|
||||
"name": "SourceUnit",
|
||||
"src": "0:160:3"
|
||||
"src": "0:214:3"
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _ev
|
||||
{
|
||||
auto const& choice = m_reader.stringSetting("SMTSolvers", "any");
|
||||
if (choice == "any")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::All();
|
||||
m_enabledSolvers = smtutil::SMTSolverChoice::All();
|
||||
else if (choice == "z3")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::Z3();
|
||||
m_enabledSolvers = smtutil::SMTSolverChoice::Z3();
|
||||
else if (choice == "cvc4")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::CVC4();
|
||||
m_enabledSolvers = smtutil::SMTSolverChoice::CVC4();
|
||||
else if (choice == "none")
|
||||
m_enabledSolvers = smt::SMTSolverChoice::None();
|
||||
m_enabledSolvers = smtutil::SMTSolverChoice::None();
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT solver choice."));
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <test/libsolidity/SyntaxTest.h>
|
||||
|
||||
#include <libsolidity/formal/SolverInterface.h>
|
||||
#include <libsmtutil/SolverInterface.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -41,7 +41,7 @@ protected:
|
||||
/// This is set via option SMTSolvers in the test.
|
||||
/// The possible options are `all`, `z3`, `cvc4`, `none`,
|
||||
/// where if none is given the default used option is `all`.
|
||||
smt::SMTSolverChoice m_enabledSolvers;
|
||||
smtutil::SMTSolverChoice m_enabledSolvers;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -204,6 +204,77 @@ BOOST_AUTO_TEST_CASE(dev_and_user_no_doc)
|
||||
checkNatspec(sourceCode, "test", userNatspec, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(public_state_variable)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
/// @return returns state
|
||||
uint public state;
|
||||
}
|
||||
)";
|
||||
|
||||
char const* devDoc = R"R(
|
||||
{
|
||||
"methods" : {},
|
||||
"stateVariables" :
|
||||
{
|
||||
"state" :
|
||||
{
|
||||
"details" : "example of dev",
|
||||
"return" : "returns state"
|
||||
}
|
||||
}
|
||||
}
|
||||
)R";
|
||||
checkNatspec(sourceCode, "test", devDoc, false);
|
||||
|
||||
char const* userDoc = R"R(
|
||||
{
|
||||
"methods" :
|
||||
{
|
||||
"state()" :
|
||||
{
|
||||
"notice": "example of notice"
|
||||
}
|
||||
}
|
||||
}
|
||||
)R";
|
||||
checkNatspec(sourceCode, "test", userDoc, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(private_state_variable)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
/// @dev example of dev
|
||||
uint private state;
|
||||
}
|
||||
)";
|
||||
|
||||
char const* devDoc = R"(
|
||||
{
|
||||
"methods" : {},
|
||||
"stateVariables" :
|
||||
{
|
||||
"state" :
|
||||
{
|
||||
"details" : "example of dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
checkNatspec(sourceCode, "test", devDoc, false);
|
||||
|
||||
char const* userDoc = R"(
|
||||
{
|
||||
"methods":{}
|
||||
}
|
||||
)";
|
||||
checkNatspec(sourceCode, "test", userDoc, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(dev_desc_after_nl)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
contract C {
|
||||
function m(
|
||||
function() external returns (uint) a,
|
||||
function() external returns (uint) b
|
||||
) internal returns (function() external returns (uint)) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function s(uint a, uint b) internal returns (uint) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function foo() external returns (uint) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
function test() public returns (uint) {
|
||||
function(uint, uint) internal returns (uint) single_slot_function = s;
|
||||
|
||||
function(
|
||||
function() external returns (uint),
|
||||
function() external returns (uint)
|
||||
) internal returns (function() external returns (uint)) multi_slot_function = m;
|
||||
|
||||
return multi_slot_function(this.foo, this.foo)() + single_slot_function(5, 1);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 12
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public returns (uint[5] memory) {
|
||||
uint[5] memory a = [4, 11, 0x111, uint(3355443), 2222222222222222222];
|
||||
return a;
|
||||
}
|
||||
function g() public returns (uint[5] memory) {
|
||||
uint[5] memory a = [16, 256, 257, uint(0x333333), 0x1ed6eb565788e38e];
|
||||
return a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> 4, 11, 0x0111, 0x333333, 2222222222222222222
|
||||
// g() -> 0x10, 0x0100, 0x0101, 0x333333, 2222222222222222222
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
/// @title title
|
||||
/// @author author
|
||||
uint private state;
|
||||
}
|
||||
// ----
|
||||
// Warning: (17-56): Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0.
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
contract test {
|
||||
/// @return returns something
|
||||
uint private state;
|
||||
}
|
||||
// ----
|
||||
// DocstringParsingError: (18-47): Documentation tag "@return" is only allowed on public state-variables.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
uint private state;
|
||||
}
|
||||
// ----
|
||||
// Warning: (17-74): Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly.
|
||||
@@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
uint public state;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
contract test {
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
/// @return returns something
|
||||
/// @return returns something
|
||||
uint public state;
|
||||
}
|
||||
// ----
|
||||
// DocstringParsingError: (18-137): Documentation tag "@return" is only allowed once on state-variables.
|
||||
@@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
function f() public pure returns (uint) {
|
||||
/// @title example of title
|
||||
/// @author example of author
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
/// @param example of param
|
||||
/// @return example of return
|
||||
uint state = 42;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (290-295): Only state variables can have a docstring. This will be disallowed in 0.7.0.
|
||||
@@ -252,7 +252,35 @@ string BytesUtils::formatBytes(
|
||||
if (*_bytes.begin() & 0x80)
|
||||
os << formatSigned(_bytes);
|
||||
else
|
||||
os << formatUnsigned(_bytes);
|
||||
{
|
||||
std::string decimal(formatUnsigned(_bytes));
|
||||
std::string hexadecimal(formatHex(_bytes));
|
||||
unsigned int value = u256(_bytes).convert_to<unsigned int>();
|
||||
if (value < 0x10)
|
||||
os << decimal;
|
||||
else if (value >= 0x10 && value <= 0xff) {
|
||||
os << hexadecimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto entropy = [](std::string const& str) -> double {
|
||||
double result = 0;
|
||||
map<char, int> frequencies;
|
||||
for (char c: str)
|
||||
frequencies[c]++;
|
||||
for (auto p: frequencies)
|
||||
{
|
||||
double freq = static_cast<double>(p.second) / str.length();
|
||||
result -= freq * (log(freq) / log(2));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
if (entropy(decimal) < entropy(hexadecimal.substr(2, hexadecimal.length())))
|
||||
os << decimal;
|
||||
else
|
||||
os << hexadecimal;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ABIType::SignedDec:
|
||||
os << formatSigned(_bytes);
|
||||
|
||||
+207
-2
@@ -36,15 +36,38 @@ namespace solidity::yul::test
|
||||
namespace
|
||||
{
|
||||
|
||||
size_t codeSize(string const& _source)
|
||||
size_t codeSize(string const& _source, CodeWeights const _weights = {})
|
||||
{
|
||||
shared_ptr<Block> ast = parse(_source, false).first;
|
||||
BOOST_REQUIRE(ast);
|
||||
return CodeSize::codeSize(*ast);
|
||||
return CodeSize::codeSize(*ast, _weights);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CustomWeightFixture
|
||||
{
|
||||
protected:
|
||||
CodeWeights m_weights{
|
||||
/* expressionStatementCost = */ 1,
|
||||
/* assignmentCost = */ 2,
|
||||
/* variableDeclarationCost = */ 3,
|
||||
/* functionDefinitionCost = */ 4,
|
||||
/* ifCost = */ 5,
|
||||
/* switchCost = */ 6,
|
||||
/* caseCost = */ 7,
|
||||
/* forLoopCost = */ 8,
|
||||
/* breakCost = */ 9,
|
||||
/* continueCost = */ 10,
|
||||
/* leaveCost = */ 11,
|
||||
/* blockCost = */ 12,
|
||||
|
||||
/* functionCallCost = */ 13,
|
||||
/* identifierCost = */ 14,
|
||||
/* literalCost = */ 15,
|
||||
};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(YulCodeSize)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_code)
|
||||
@@ -52,41 +75,103 @@ BOOST_AUTO_TEST_CASE(empty_code)
|
||||
BOOST_CHECK_EQUAL(codeSize("{}"), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(empty_code_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{}", m_weights), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(nested_blocks)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ {} {} {{ }} }"), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(nested_blocks_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ {} {} {{ }} }", m_weights), 4 * m_weights.blockCost);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(instruction)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ pop(calldatasize()) }"), 2);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(instruction_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ pop(calldatasize()) }", m_weights),
|
||||
2 * m_weights.functionCallCost +
|
||||
1 * m_weights.expressionStatementCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(variables_are_free)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ let x let y let a, b, c }"), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(variables_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ let x let y let a, b, c }", m_weights),
|
||||
3 * m_weights.variableDeclarationCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(constants_cost_one)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ let x := 3 }"), 1);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(constants_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ let x := 3 }", m_weights),
|
||||
1 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.literalCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(functions_are_skipped)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ function f(x) -> r { r := mload(x) } }"), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(functions_are_skipped_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ function f(x) -> r { r := mload(x) } }", m_weights), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_with_arguments)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ function f(x) { sstore(x, 2) } f(2) }"), 2);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(function_with_arguments_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ function f(x) { sstore(x, 2) } f(2) }", m_weights),
|
||||
1 * m_weights.expressionStatementCost +
|
||||
1 * m_weights.functionCallCost +
|
||||
1 * m_weights.literalCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_with_variables_as_arguments)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ function f(x) { sstore(x, 2) } let y f(y) }"), 1);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(function_with_variables_as_arguments_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ function f(x) { sstore(x, 2) } let y f(y) }", m_weights),
|
||||
1 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.expressionStatementCost +
|
||||
1 * m_weights.functionCallCost +
|
||||
1 * m_weights.identifierCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_with_variables_and_constants_as_arguments)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -94,21 +179,69 @@ BOOST_AUTO_TEST_CASE(function_with_variables_and_constants_as_arguments)
|
||||
), 2);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
function_with_variables_and_constants_as_arguments_custom_weights,
|
||||
CustomWeightFixture
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize(
|
||||
"{ function f(x, r) -> z { sstore(x, r) z := r } let y let t := f(y, 2) }",
|
||||
m_weights
|
||||
),
|
||||
2 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.functionCallCost +
|
||||
1 * m_weights.identifierCost +
|
||||
1 * m_weights.literalCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignment)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ let a a := 3 }"), 1);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(assignment_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ let a a := 3 }", m_weights),
|
||||
1 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.assignmentCost +
|
||||
1 * m_weights.literalCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignments_between_vars_are_free)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ let a let b := a a := b }"), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(assignments_between_vars_are_free_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ let a let b := a a := b }", m_weights),
|
||||
2 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.assignmentCost +
|
||||
2 * m_weights.identifierCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignment_complex)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize("{ let a let x := mload(a) a := sload(x) }"), 2);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(assignment_complex_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ let a let x := mload(a) a := sload(x) }", m_weights),
|
||||
2 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.assignmentCost +
|
||||
2 * m_weights.identifierCost +
|
||||
2 * m_weights.functionCallCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_for_loop)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -116,6 +249,15 @@ BOOST_AUTO_TEST_CASE(empty_for_loop)
|
||||
), 4);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(empty_for_loop_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ for {} 1 {} {} }", m_weights),
|
||||
1 * m_weights.forLoopCost +
|
||||
1 * m_weights.literalCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(break_statement)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -123,6 +265,16 @@ BOOST_AUTO_TEST_CASE(break_statement)
|
||||
), 6);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(break_statement_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ for {} 1 {} { break } }", m_weights),
|
||||
1 * m_weights.forLoopCost +
|
||||
1 * m_weights.literalCost +
|
||||
1 * m_weights.breakCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(continue_statement)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -130,6 +282,16 @@ BOOST_AUTO_TEST_CASE(continue_statement)
|
||||
), 6);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(continue_statement_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ for {} 1 {} { continue } }", m_weights),
|
||||
1 * m_weights.forLoopCost +
|
||||
1 * m_weights.literalCost +
|
||||
1 * m_weights.continueCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(regular_for_loop)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -137,6 +299,20 @@ BOOST_AUTO_TEST_CASE(regular_for_loop)
|
||||
), 10);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(regular_for_loop_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ for { let x := 0 } lt(x, 10) { x := add(x, 1) } { mstore(x, 1) } }", m_weights),
|
||||
1 * m_weights.forLoopCost +
|
||||
1 * m_weights.variableDeclarationCost +
|
||||
1 * m_weights.assignmentCost +
|
||||
3 * m_weights.functionCallCost +
|
||||
4 * m_weights.literalCost +
|
||||
3 * m_weights.identifierCost +
|
||||
1 * m_weights.expressionStatementCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(if_statement)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -144,6 +320,15 @@ BOOST_AUTO_TEST_CASE(if_statement)
|
||||
), 3);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(if_statement_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ if 1 {} }", m_weights),
|
||||
1 * m_weights.ifCost +
|
||||
1 * m_weights.literalCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_statement_tiny)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -158,6 +343,16 @@ BOOST_AUTO_TEST_CASE(switch_statement_small)
|
||||
), 6);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(switch_statement_small_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ switch calldatasize() case 0 {} default {} }", m_weights),
|
||||
1 * m_weights.functionCallCost +
|
||||
1 * m_weights.switchCost +
|
||||
2 * m_weights.caseCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_statement_medium)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(codeSize(
|
||||
@@ -172,6 +367,16 @@ BOOST_AUTO_TEST_CASE(switch_statement_large)
|
||||
), 10);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(switch_statement_large_custom_weights, CustomWeightFixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
codeSize("{ switch calldatasize() case 0 {} case 1 {} case 2 {} default {} }", m_weights),
|
||||
1 * m_weights.functionCallCost +
|
||||
1 * m_weights.switchCost +
|
||||
4 * m_weights.caseCost
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ using namespace boost::unit_test::framework;
|
||||
using namespace boost::test_tools;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::yul;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
@@ -299,8 +300,8 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_cache_stats_if_requested, AlgorithmRunn
|
||||
make_shared<ProgramCache>(programs[1]),
|
||||
};
|
||||
shared_ptr<FitnessMetric> fitnessMetric = make_shared<FitnessMetricAverage>(vector<shared_ptr<FitnessMetric>>{
|
||||
make_shared<ProgramSize>(nullopt, caches[0]),
|
||||
make_shared<ProgramSize>(nullopt, caches[1]),
|
||||
make_shared<ProgramSize>(nullopt, caches[0], CodeWeights{}),
|
||||
make_shared<ProgramSize>(nullopt, caches[1], CodeWeights{}),
|
||||
});
|
||||
Population population = Population::makeRandom(fitnessMetric, 2, 0, 5);
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ protected:
|
||||
|
||||
Program optimisedProgram(Program _program) const
|
||||
{
|
||||
[[maybe_unused]] size_t originalSize = _program.codeSize();
|
||||
[[maybe_unused]] size_t originalSize = _program.codeSize(m_weights);
|
||||
Program result = move(_program);
|
||||
result.optimise(m_chromosome.optimisationSteps());
|
||||
|
||||
// Make sure that the program and the chromosome we have chosen are suitable for the test
|
||||
assert(result.codeSize() != originalSize);
|
||||
assert(result.codeSize(m_weights) != originalSize);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -77,15 +77,16 @@ protected:
|
||||
Program m_program = get<Program>(Program::load(m_sourceStream));
|
||||
Program m_optimisedProgram = optimisedProgram(m_program);
|
||||
shared_ptr<ProgramCache> m_programCache = make_shared<ProgramCache>(m_program);
|
||||
static constexpr CodeWeights m_weights{};
|
||||
};
|
||||
|
||||
class FitnessMetricCombinationFixture: public ProgramBasedMetricFixture
|
||||
{
|
||||
protected:
|
||||
vector<shared_ptr<FitnessMetric>> m_simpleMetrics = {
|
||||
make_shared<ProgramSize>(m_program, nullptr, 1),
|
||||
make_shared<ProgramSize>(m_program, nullptr, 2),
|
||||
make_shared<ProgramSize>(m_program, nullptr, 3),
|
||||
make_shared<ProgramSize>(m_program, nullptr, m_weights, 1),
|
||||
make_shared<ProgramSize>(m_program, nullptr, m_weights, 2),
|
||||
make_shared<ProgramSize>(m_program, nullptr, m_weights, 3),
|
||||
};
|
||||
vector<size_t> m_fitness = {
|
||||
m_simpleMetrics[0]->evaluate(m_chromosome),
|
||||
@@ -100,7 +101,7 @@ BOOST_AUTO_TEST_SUITE(ProgramBasedMetricTest)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_return_optimised_program_even_if_cache_not_available, ProgramBasedMetricFixture)
|
||||
{
|
||||
string code = toString(DummyProgramBasedMetric(m_program, nullptr).optimisedProgram(m_chromosome));
|
||||
string code = toString(DummyProgramBasedMetric(m_program, nullptr, m_weights).optimisedProgram(m_chromosome));
|
||||
|
||||
BOOST_TEST(code != toString(m_program));
|
||||
BOOST_TEST(code == toString(m_optimisedProgram));
|
||||
@@ -108,7 +109,7 @@ BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_return_optimised_program_even_if
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_use_cache_if_available, ProgramBasedMetricFixture)
|
||||
{
|
||||
string code = toString(DummyProgramBasedMetric(nullopt, m_programCache).optimisedProgram(m_chromosome));
|
||||
string code = toString(DummyProgramBasedMetric(nullopt, m_programCache, m_weights).optimisedProgram(m_chromosome));
|
||||
|
||||
BOOST_TEST(code != toString(m_program));
|
||||
BOOST_TEST(code == toString(m_optimisedProgram));
|
||||
@@ -117,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_use_cache_if_available, ProgramB
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(optimisedProgramNoCache_should_return_optimised_program_even_if_cache_not_available, ProgramBasedMetricFixture)
|
||||
{
|
||||
string code = toString(DummyProgramBasedMetric(m_program, nullptr).optimisedProgramNoCache(m_chromosome));
|
||||
string code = toString(DummyProgramBasedMetric(m_program, nullptr, m_weights).optimisedProgramNoCache(m_chromosome));
|
||||
|
||||
BOOST_TEST(code != toString(m_program));
|
||||
BOOST_TEST(code == toString(m_optimisedProgram));
|
||||
@@ -125,7 +126,7 @@ BOOST_FIXTURE_TEST_CASE(optimisedProgramNoCache_should_return_optimised_program_
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(optimisedProgramNoCache_should_not_use_cache_even_if_available, ProgramBasedMetricFixture)
|
||||
{
|
||||
string code = toString(DummyProgramBasedMetric(nullopt, m_programCache).optimisedProgramNoCache(m_chromosome));
|
||||
string code = toString(DummyProgramBasedMetric(nullopt, m_programCache, m_weights).optimisedProgramNoCache(m_chromosome));
|
||||
|
||||
BOOST_TEST(code != toString(m_program));
|
||||
BOOST_TEST(code == toString(m_optimisedProgram));
|
||||
@@ -137,18 +138,18 @@ BOOST_AUTO_TEST_SUITE(ProgramSizeTest)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_compute_size_of_the_optimised_program, ProgramBasedMetricFixture)
|
||||
{
|
||||
size_t fitness = ProgramSize(m_program, nullptr).evaluate(m_chromosome);
|
||||
size_t fitness = ProgramSize(m_program, nullptr, m_weights).evaluate(m_chromosome);
|
||||
|
||||
BOOST_TEST(fitness != m_program.codeSize());
|
||||
BOOST_TEST(fitness == m_optimisedProgram.codeSize());
|
||||
BOOST_TEST(fitness != m_program.codeSize(m_weights));
|
||||
BOOST_TEST(fitness == m_optimisedProgram.codeSize(m_weights));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_be_able_to_use_program_cache_if_available, ProgramBasedMetricFixture)
|
||||
{
|
||||
size_t fitness = ProgramSize(nullopt, m_programCache).evaluate(m_chromosome);
|
||||
size_t fitness = ProgramSize(nullopt, m_programCache, m_weights).evaluate(m_chromosome);
|
||||
|
||||
BOOST_TEST(fitness != m_program.codeSize());
|
||||
BOOST_TEST(fitness == m_optimisedProgram.codeSize());
|
||||
BOOST_TEST(fitness != m_program.codeSize(m_weights));
|
||||
BOOST_TEST(fitness == m_optimisedProgram.codeSize(m_weights));
|
||||
BOOST_TEST(m_programCache->size() == m_chromosome.length());
|
||||
}
|
||||
|
||||
@@ -157,21 +158,21 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_repeat_the_optimisation_specified_number
|
||||
Program const& programOptimisedOnce = m_optimisedProgram;
|
||||
Program programOptimisedTwice = optimisedProgram(programOptimisedOnce);
|
||||
|
||||
ProgramSize metric(m_program, nullptr, 2);
|
||||
ProgramSize metric(m_program, nullptr, m_weights, 2);
|
||||
size_t fitness = metric.evaluate(m_chromosome);
|
||||
|
||||
BOOST_TEST(fitness != m_program.codeSize());
|
||||
BOOST_TEST(fitness != programOptimisedOnce.codeSize());
|
||||
BOOST_TEST(fitness == programOptimisedTwice.codeSize());
|
||||
BOOST_TEST(fitness != m_program.codeSize(m_weights));
|
||||
BOOST_TEST(fitness != programOptimisedOnce.codeSize(m_weights));
|
||||
BOOST_TEST(fitness == programOptimisedTwice.codeSize(m_weights));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_not_optimise_if_number_of_repetitions_is_zero, ProgramBasedMetricFixture)
|
||||
{
|
||||
ProgramSize metric(m_program, nullptr, 0);
|
||||
ProgramSize metric(m_program, nullptr, m_weights, 0);
|
||||
size_t fitness = metric.evaluate(m_chromosome);
|
||||
|
||||
BOOST_TEST(fitness == m_program.codeSize());
|
||||
BOOST_TEST(fitness != m_optimisedProgram.codeSize());
|
||||
BOOST_TEST(fitness == m_program.codeSize(m_weights));
|
||||
BOOST_TEST(fitness != m_optimisedProgram.codeSize(m_weights));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -179,12 +180,18 @@ BOOST_AUTO_TEST_SUITE(RelativeProgramSizeTest)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_compute_the_size_ratio_between_optimised_program_and_original_program, ProgramBasedMetricFixture)
|
||||
{
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 3).evaluate(m_chromosome) == round(1000.0 * m_optimisedProgram.codeSize() / m_program.codeSize()));
|
||||
BOOST_TEST(
|
||||
RelativeProgramSize(m_program, nullptr, 3, m_weights).evaluate(m_chromosome) ==
|
||||
round(1000.0 * m_optimisedProgram.codeSize(m_weights) / m_program.codeSize(m_weights))
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_be_able_to_use_program_cache_if_available, ProgramBasedMetricFixture)
|
||||
{
|
||||
BOOST_TEST(RelativeProgramSize(nullopt, m_programCache, 3).evaluate(m_chromosome) == round(1000.0 * m_optimisedProgram.codeSize() / m_program.codeSize()));
|
||||
BOOST_TEST(
|
||||
RelativeProgramSize(nullopt, m_programCache, 3, m_weights).evaluate(m_chromosome) ==
|
||||
round(1000.0 * m_optimisedProgram.codeSize(m_weights) / m_program.codeSize(m_weights))
|
||||
);
|
||||
BOOST_TEST(m_programCache->size() == m_chromosome.length());
|
||||
}
|
||||
|
||||
@@ -193,17 +200,17 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_repeat_the_optimisation_specified_number
|
||||
Program const& programOptimisedOnce = m_optimisedProgram;
|
||||
Program programOptimisedTwice = optimisedProgram(programOptimisedOnce);
|
||||
|
||||
RelativeProgramSize metric(m_program, nullptr, 3, 2);
|
||||
RelativeProgramSize metric(m_program, nullptr, 3, m_weights, 2);
|
||||
size_t fitness = metric.evaluate(m_chromosome);
|
||||
|
||||
BOOST_TEST(fitness != 1000);
|
||||
BOOST_TEST(fitness != RelativeProgramSize(programOptimisedTwice, nullptr, 3, 1).evaluate(m_chromosome));
|
||||
BOOST_TEST(fitness == round(1000.0 * programOptimisedTwice.codeSize() / m_program.codeSize()));
|
||||
BOOST_TEST(fitness != RelativeProgramSize(programOptimisedTwice, nullptr, 3, m_weights, 1).evaluate(m_chromosome));
|
||||
BOOST_TEST(fitness == round(1000.0 * programOptimisedTwice.codeSize(m_weights) / m_program.codeSize(m_weights)));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_number_of_repetitions_is_zero, ProgramBasedMetricFixture)
|
||||
{
|
||||
RelativeProgramSize metric(m_program, nullptr, 3, 0);
|
||||
RelativeProgramSize metric(m_program, nullptr, 3, m_weights, 0);
|
||||
|
||||
BOOST_TEST(metric.evaluate(m_chromosome) == 1000);
|
||||
}
|
||||
@@ -213,7 +220,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_the_original_program_size_
|
||||
CharStream sourceStream = CharStream("{}", "");
|
||||
Program program = get<Program>(Program::load(sourceStream));
|
||||
|
||||
RelativeProgramSize metric(program, nullptr, 3);
|
||||
RelativeProgramSize metric(program, nullptr, 3, m_weights);
|
||||
|
||||
BOOST_TEST(metric.evaluate(m_chromosome) == 1000);
|
||||
BOOST_TEST(metric.evaluate(Chromosome("")) == 1000);
|
||||
@@ -222,12 +229,12 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_the_original_program_size_
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_multiply_the_result_by_scaling_factor, ProgramBasedMetricFixture)
|
||||
{
|
||||
double sizeRatio = static_cast<double>(m_optimisedProgram.codeSize()) / m_program.codeSize();
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 0).evaluate(m_chromosome) == round(1.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 1).evaluate(m_chromosome) == round(10.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 2).evaluate(m_chromosome) == round(100.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 3).evaluate(m_chromosome) == round(1000.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 4).evaluate(m_chromosome) == round(10000.0 * sizeRatio));
|
||||
double sizeRatio = static_cast<double>(m_optimisedProgram.codeSize(m_weights)) / m_program.codeSize(m_weights);
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 0, m_weights).evaluate(m_chromosome) == round(1.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 1, m_weights).evaluate(m_chromosome) == round(10.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 2, m_weights).evaluate(m_chromosome) == round(100.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 3, m_weights).evaluate(m_chromosome) == round(1000.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 4, m_weights).evaluate(m_chromosome) == round(10000.0 * sizeRatio));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
using namespace std;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::yul;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
@@ -86,6 +87,7 @@ protected:
|
||||
/* relativeMetricScale = */ 5,
|
||||
/* chromosomeRepetitions = */ 1,
|
||||
};
|
||||
CodeWeights const m_weights{};
|
||||
};
|
||||
|
||||
class PoulationFactoryFixture
|
||||
@@ -183,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_create_metric_of_the_right_type, FitnessMet
|
||||
{
|
||||
m_options.metric = MetricChoice::RelativeCodeSize;
|
||||
m_options.metricAggregator = MetricAggregatorChoice::Sum;
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr});
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights);
|
||||
BOOST_REQUIRE(metric != nullptr);
|
||||
|
||||
auto sumMetric = dynamic_cast<FitnessMetricSum*>(metric.get());
|
||||
@@ -201,7 +203,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_respect_chromosome_repetitions_option, Fitn
|
||||
m_options.metric = MetricChoice::CodeSize;
|
||||
m_options.metricAggregator = MetricAggregatorChoice::Average;
|
||||
m_options.chromosomeRepetitions = 5;
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr});
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights);
|
||||
BOOST_REQUIRE(metric != nullptr);
|
||||
|
||||
auto averageMetric = dynamic_cast<FitnessMetricAverage*>(metric.get());
|
||||
@@ -219,7 +221,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_set_relative_metric_scale, FitnessMetricFac
|
||||
m_options.metric = MetricChoice::RelativeCodeSize;
|
||||
m_options.metricAggregator = MetricAggregatorChoice::Average;
|
||||
m_options.relativeMetricScale = 10;
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr});
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights);
|
||||
BOOST_REQUIRE(metric != nullptr);
|
||||
|
||||
auto averageMetric = dynamic_cast<FitnessMetricAverage*>(metric.get());
|
||||
@@ -237,7 +239,8 @@ BOOST_FIXTURE_TEST_CASE(build_should_create_metric_for_each_input_program, Fitne
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(
|
||||
m_options,
|
||||
m_programs,
|
||||
vector<shared_ptr<ProgramCache>>(m_programs.size(), nullptr)
|
||||
vector<shared_ptr<ProgramCache>>(m_programs.size(), nullptr),
|
||||
m_weights
|
||||
);
|
||||
BOOST_REQUIRE(metric != nullptr);
|
||||
|
||||
@@ -256,7 +259,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_pass_program_caches_to_metrics, FitnessMetr
|
||||
};
|
||||
|
||||
m_options.metric = MetricChoice::RelativeCodeSize;
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, m_programs, caches);
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, m_programs, caches, m_weights);
|
||||
BOOST_REQUIRE(metric != nullptr);
|
||||
|
||||
auto combinedMetric = dynamic_cast<FitnessMetricCombination*>(metric.get());
|
||||
|
||||
@@ -398,7 +398,7 @@ BOOST_AUTO_TEST_CASE(codeSize)
|
||||
CharStream sourceStream(sourceCode, current_test_case().p_name);
|
||||
Program program = get<Program>(Program::load(sourceStream));
|
||||
|
||||
BOOST_TEST(program.codeSize() == CodeSize::codeSizeIncludingFunctions(program.ast()));
|
||||
BOOST_TEST(program.codeSize(CodeWeights{}) == CodeSize::codeSizeIncludingFunctions(program.ast()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <tools/yulPhaser/ProgramCache.h>
|
||||
#include <tools/yulPhaser/Chromosome.h>
|
||||
|
||||
#include <libyul/optimiser/Metrics.h>
|
||||
|
||||
#include <liblangutil/CharStream.h>
|
||||
|
||||
#include <libsolutil/CommonIO.h>
|
||||
@@ -212,11 +214,11 @@ BOOST_FIXTURE_TEST_CASE(startRound_should_remove_entries_older_than_two_rounds,
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(gatherStats_should_return_cache_statistics, ProgramCacheFixture)
|
||||
{
|
||||
size_t sizeI = optimisedProgram(m_program, "I").codeSize();
|
||||
size_t sizeIu = optimisedProgram(m_program, "Iu").codeSize();
|
||||
size_t sizeIuO = optimisedProgram(m_program, "IuO").codeSize();
|
||||
size_t sizeL = optimisedProgram(m_program, "L").codeSize();
|
||||
size_t sizeLT = optimisedProgram(m_program, "LT").codeSize();
|
||||
size_t sizeI = optimisedProgram(m_program, "I").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeIu = optimisedProgram(m_program, "Iu").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeIuO = optimisedProgram(m_program, "IuO").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeL = optimisedProgram(m_program, "L").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeLT = optimisedProgram(m_program, "LT").codeSize(CacheStats::StorageWeights);
|
||||
|
||||
m_programCache.optimiseProgram("L");
|
||||
m_programCache.optimiseProgram("Iu");
|
||||
|
||||
Reference in New Issue
Block a user