Skip to content

Commit c139d39

Browse files
authored
Merge pull request #12589 from ethereum/emit-immutable-references
Emit immutable references for pure yul code
2 parents d744c0d + b9fe628 commit c139d39

File tree

6 files changed

+88
-12
lines changed

6 files changed

+88
-12
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Language Features:
77

88
Compiler Features:
99
* Yul Optimizer: Remove ``mstore`` and ``sstore`` operations if the slot already contains the same value.
10+
* Yul: Emit immutable references for pure yul code when requested.
1011

1112

1213

libsolidity/interface/StandardCompiler.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,36 +1461,36 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
14611461
stack.optimize();
14621462

14631463
MachineAssemblyObject object;
1464-
MachineAssemblyObject runtimeObject;
1465-
tie(object, runtimeObject) = stack.assembleWithDeployed();
1464+
MachineAssemblyObject deployedObject;
1465+
tie(object, deployedObject) = stack.assembleWithDeployed();
14661466

14671467
if (object.bytecode)
14681468
object.bytecode->link(_inputsAndSettings.libraries);
1469-
if (runtimeObject.bytecode)
1470-
runtimeObject.bytecode->link(_inputsAndSettings.libraries);
1469+
if (deployedObject.bytecode)
1470+
deployedObject.bytecode->link(_inputsAndSettings.libraries);
14711471

1472-
for (string const& objectKind: vector<string>{"bytecode", "deployedBytecode"})
1472+
for (auto&& [kind, isDeployed]: {make_pair("bytecode"s, false), make_pair("deployedBytecode"s, true)})
14731473
if (isArtifactRequested(
14741474
_inputsAndSettings.outputSelection,
14751475
sourceName,
14761476
contractName,
1477-
evmObjectComponents(objectKind),
1477+
evmObjectComponents(kind),
14781478
wildcardMatchesExperimental
14791479
))
14801480
{
1481-
MachineAssemblyObject const& o = objectKind == "bytecode" ? object : runtimeObject;
1481+
MachineAssemblyObject const& o = isDeployed ? deployedObject : object;
14821482
if (o.bytecode)
1483-
output["contracts"][sourceName][contractName]["evm"][objectKind] =
1483+
output["contracts"][sourceName][contractName]["evm"][kind] =
14841484
collectEVMObject(
14851485
*o.bytecode,
14861486
o.sourceMappings.get(),
14871487
Json::arrayValue,
1488-
false,
1489-
[&](string const& _element) { return isArtifactRequested(
1488+
isDeployed,
1489+
[&, kind = kind](string const& _element) { return isArtifactRequested(
14901490
_inputsAndSettings.outputSelection,
14911491
sourceName,
14921492
contractName,
1493-
"evm." + objectKind + "." + _element,
1493+
"evm." + kind + "." + _element,
14941494
wildcardMatchesExperimental
14951495
); }
14961496
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--pretty-json
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"language": "Yul",
3+
"sources":
4+
{
5+
"A":
6+
{
7+
"content": "object \"YulTest\" { code { let size := datasize(\"runtime\") datacopy(0, dataoffset(\"runtime\"), size) setimmutable(0, \"test\", 1) return(0, size) } object \"runtime\" { code { mstore(0, loadimmutable(\"test\")) return(0, 0x20) } }}"
8+
}
9+
},
10+
"settings":
11+
{
12+
"outputSelection": {
13+
"A": {
14+
"*": [
15+
"evm.deployedBytecode.immutableReferences",
16+
"evm.bytecode",
17+
"evm.deployedBytecode"
18+
]
19+
}
20+
}
21+
}
22+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"YulTest":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"functionDebugData": {},
13+
"generatedSources": [],
14+
"linkReferences": {},
15+
"object": "60298060156000396001600060010152806000f3fe7f000000000000000000000000000000000000000000000000000000000000000060005260206000f3",
16+
"opcodes": "PUSH1 0x29 DUP1 PUSH1 0x15 PUSH1 0x0 CODECOPY PUSH1 0x1 PUSH1 0x0 PUSH1 0x1 ADD MSTORE DUP1 PUSH1 0x0 RETURN INVALID PUSH32 0x0 PUSH1 0x0 MSTORE PUSH1 0x20 PUSH1 0x0 RETURN ",
17+
"sourceMap": "42:19:0:-:0;100:4;77:21;74:1;65:40;133:1;122;109:26;;;149:4;146:1;139:15"
18+
},
19+
"deployedBytecode":
20+
{
21+
"functionDebugData": {},
22+
"generatedSources": [],
23+
"immutableReferences":
24+
{
25+
"test":
26+
[
27+
{
28+
"length": 32,
29+
"start": 1
30+
}
31+
]
32+
},
33+
"linkReferences": {},
34+
"object": "7f000000000000000000000000000000000000000000000000000000000000000060005260206000f3",
35+
"opcodes": "PUSH32 0x0 PUSH1 0x0 MSTORE PUSH1 0x20 PUSH1 0x0 RETURN ",
36+
"sourceMap": "203:21:0:-:0;200:1;193:32;241:4;238:1;231:15"
37+
}
38+
}
39+
}
40+
}
41+
},
42+
"errors":
43+
[
44+
{
45+
"component": "general",
46+
"formattedMessage": "Yul is still experimental. Please use the output with care.",
47+
"message": "Yul is still experimental. Please use the output with care.",
48+
"severity": "warning",
49+
"type": "Warning"
50+
}
51+
]
52+
}

test/cmdlineTests/standard_yul_object_name/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sub_0: assembly {
2323
/* \"A\":137:149 */
2424
revert
2525
}
26-
","bytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"},"deployedBytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}},"ir":"object \"NamedObject\" {
26+
","bytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"},"deployedBytecode":{"functionDebugData":{},"generatedSources":[],"immutableReferences":{},"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}},"ir":"object \"NamedObject\" {
2727
code {
2828
let x := dataoffset(\"DataName\")
2929
sstore(add(x, 0), 0)

0 commit comments

Comments
 (0)