Skip to content

Commit 2518378

Browse files
committed
Introduce experimental option in standard JSON
1 parent 524bdf6 commit 2518378

File tree

50 files changed

+428
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+428
-48
lines changed

libsolidity/interface/StandardCompiler.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ bool isEthdebugRequested(Json const& _outputSelection)
307307
return false;
308308
}
309309

310+
bool isExperimentalArtifactRequested(Json const& _outputSelection)
311+
{
312+
std::set<std::string> experimentalArtifacts{"irAst", "irOptimizedAst", "yulCFGJson"};
313+
if (!_outputSelection.is_object())
314+
return false;
315+
316+
for (auto const& fileRequests: _outputSelection)
317+
for (auto const& requests: fileRequests)
318+
for (auto const& request: requests)
319+
if (experimentalArtifacts.contains(request))
320+
return true;
321+
322+
return false;
323+
}
324+
310325
/// @returns The set of selected contracts, along with their compiler pipeline configuration, based
311326
/// on outputs requested in the JSON. Translates wildcards to the ones understood by CompilerStack.
312327
/// Note that as an exception, '*' does not yet match "ir", "irAst", "irOptimized" or "irOptimizedAst".
@@ -430,7 +445,7 @@ std::optional<Json> checkAuxiliaryInputKeys(Json const& _input)
430445

431446
std::optional<Json> checkSettingsKeys(Json const& _input)
432447
{
433-
static std::set<std::string> keys{"debug", "evmVersion", "eofVersion", "libraries", "metadata", "modelChecker", "optimizer", "outputSelection", "remappings", "stopAfter", "viaIR"};
448+
static std::set<std::string> keys{"debug", "evmVersion", "experimental", "eofVersion", "libraries", "metadata", "modelChecker", "optimizer", "outputSelection", "remappings", "stopAfter", "viaIR"};
434449
return checkKeys(_input, keys, "settings");
435450
}
436451

@@ -803,6 +818,13 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
803818
if (auto result = checkSettingsKeys(settings))
804819
return *result;
805820

821+
if (settings.contains("experimental"))
822+
{
823+
if (!settings["experimental"].is_boolean())
824+
return formatFatalError(Error::Type::JSONError, "\"settings.experimental\" must be a Boolean.");
825+
ret.experimental = settings["experimental"].get<bool>();
826+
}
827+
806828
if (settings.contains("stopAfter"))
807829
{
808830
if (!settings["stopAfter"].is_string())
@@ -1213,6 +1235,21 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
12131235
if (ret.optimiserSettings.runYulOptimiser)
12141236
solUnimplemented("Optimization is not yet supported with ethdebug.");
12151237

1238+
if (!ret.experimental)
1239+
{
1240+
if (ret.language == "SolidityAST" || ret.language == "EVMAssembly")
1241+
return formatFatalError(Error::Type::FatalError, "'SolidityAST' and 'EVMAssembly' inputs are experimental, and can only be used by toggling the 'settings.experimental' option.");
1242+
1243+
if (isExperimentalArtifactRequested(ret.outputSelection))
1244+
return formatFatalError(Error::Type::FatalError, "'irAst', 'irOptimizedAst' and 'yulCFGJson' outputs are experimental, and can only be used by toggling the 'settings.experimental' option.");
1245+
1246+
if (isEthdebugRequested(ret.outputSelection))
1247+
return formatFatalError(Error::Type::FatalError, "'settings.debug.debugInfo.ethdebug' is experimental, and can only be used by toggling the 'settings.experimental' option.");
1248+
1249+
if (ret.eofVersion)
1250+
return formatFatalError(Error::Type::FatalError, "'eofVersion' is experimental, and can only be used by toggling the 'settings.experimental' option.");
1251+
}
1252+
12161253
return {std::move(ret)};
12171254
}
12181255

@@ -1373,6 +1410,7 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
13731410
compilerStack.setMetadataHash(_inputsAndSettings.metadataHash);
13741411
compilerStack.selectContracts(pipelineConfig(_inputsAndSettings.outputSelection));
13751412
compilerStack.setModelCheckerSettings(_inputsAndSettings.modelCheckerSettings);
1413+
compilerStack.setExperimental(_inputsAndSettings.experimental);
13761414

13771415
Json errors = std::move(_inputsAndSettings.errors);
13781416

libsolidity/interface/StandardCompiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class StandardCompiler
8989
Json outputSelection;
9090
ModelCheckerSettings modelCheckerSettings = ModelCheckerSettings{};
9191
bool viaIR = false;
92+
bool experimental = false;
9293
};
9394

9495
/// Parses the input json (and potentially invokes the read callback) and either returns

scripts/ASTImportTest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function test_ast_import_export_equivalence
139139
echo ". += {\"sources\":" > _ast_json.json
140140
jq .sources expected.json >> _ast_json.json
141141
echo "}" >> _ast_json.json
142-
echo "{\"language\": \"SolidityAST\", \"settings\": {\"outputSelection\": {\"*\": {\"\": [\"ast\"]}}}}" > standard_json.json
142+
echo "{\"language\": \"SolidityAST\", \"settings\": {\"experimental\": true, \"outputSelection\": {\"*\": {\"\": [\"ast\"]}}}}" > standard_json.json
143143
jq --from-file _ast_json.json standard_json.json > standard_json_input.json
144144

145145
# (re)import ast via standard json - and export it again as obtained result (silently)

test/cmdlineTests/import_asm_json_standard_json_no_optimize/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
}
2929
},
3030
"settings": {
31+
"experimental": true,
3132
"outputSelection": {
3233
"*": {
3334
"": ["evm.assembly"]

test/cmdlineTests/import_asm_json_standard_json_optimize/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
}
2929
},
3030
"settings": {
31+
"experimental": true,
3132
"outputSelection": {
3233
"*": {
3334
"": ["evm.assembly"]

test/cmdlineTests/standard_import_asm_json/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020
},
2121
"settings": {
22+
"experimental": true,
2223
"outputSelection": {
2324
"*": {
2425
"": ["*"]

test/cmdlineTests/standard_import_asm_json_immutable_references/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
}
3535
},
3636
"settings": {
37+
"experimental": true,
3738
"outputSelection": {
3839
"*": {
3940
"": [

test/cmdlineTests/standard_import_asm_json_invalid_opcode/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020
},
2121
"settings": {
22+
"experimental": true,
2223
"outputSelection": {
2324
"*": {
2425
"": ["evm.bytecode"]

test/cmdlineTests/standard_import_asm_json_link_references/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}
2727
},
2828
"settings": {
29+
"experimental": true,
2930
"outputSelection": {
3031
"*": {
3132
"": [

test/cmdlineTests/standard_import_asm_json_no_output_selection/input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020
},
2121
"settings": {
22+
"experimental": true,
2223
"outputSelection": {
2324
"*": {
2425
"": [

0 commit comments

Comments
 (0)