Skip to content

Commit 592f863

Browse files
committed
Introduce experimental flag/option
1 parent 34754a5 commit 592f863

File tree

52 files changed

+206
-77
lines changed

Some content is hidden

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

52 files changed

+206
-77
lines changed

libsolidity/interface/CompilerStack.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ void CompilerStack::setViaIR(bool _viaIR)
229229
m_viaIR = _viaIR;
230230
}
231231

232+
void CompilerStack::setExperimental(bool _experimental)
233+
{
234+
solAssert(m_stackState < ParsedAndImported, "Must set experimental before parsing.");
235+
m_experimental = _experimental;
236+
}
237+
232238
void CompilerStack::setEVMVersion(langutil::EVMVersion _version)
233239
{
234240
solAssert(m_stackState < ParsedAndImported, "Must set EVM version before parsing.");

libsolidity/interface/CompilerStack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
223223
/// Must be set before parsing.
224224
void setViaIR(bool _viaIR);
225225

226+
/// Sets the experimental toggle to allow usage of experimental features.
227+
void setExperimental(bool _experimental);
228+
226229
/// Set the EVM version used before running compile.
227230
/// When called without an argument it will revert to the default version.
228231
/// Must be set before parsing.
@@ -607,6 +610,7 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
607610
RevertStrings m_revertStrings = RevertStrings::Default;
608611
State m_stopAfter = State::CompilationSuccessful;
609612
bool m_viaIR = false;
613+
bool m_experimental = false;
610614
langutil::EVMVersion m_evmVersion;
611615
std::optional<uint8_t> m_eofVersion;
612616
ModelCheckerSettings m_modelCheckerSettings;

scripts/ASTImportTest.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function test_ast_import_export_equivalence
117117
local input_files=( "${@:2}" )
118118

119119
local export_command=("$SOLC" --combined-json ast --pretty-json --json-indent 4 "${input_files[@]}")
120-
local import_command=("$SOLC" --import-ast --combined-json ast --pretty-json --json-indent 4 expected.json)
120+
local import_command=("$SOLC" --experimental --import-ast --combined-json ast --pretty-json --json-indent 4 expected.json)
121121
local import_via_standard_json_command=("$SOLC" --combined-json ast --pretty-json --json-indent 4 --standard-json standard_json_input.json)
122122

123123
# export ast - save ast json as expected result (silently)
@@ -228,7 +228,7 @@ function test_evmjson_import_export_equivalence
228228
local bin_file_from_asm_import
229229
bin_file_from_asm_import="import/$(basename "${asm_json_file}" .json).bin"
230230

231-
local import_options=(--bin --import-asm-json "${asm_json_file}")
231+
local import_options=(--experimental --bin --import-asm-json "${asm_json_file}")
232232
run_solc_store_stdout "${bin_file_from_asm_import}" "${import_options[@]}"
233233

234234
stripCLIDecorations < "$bin_file_from_asm_import" > tmpfile

solc/CommandLineInterface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ void CommandLineInterface::compile()
927927

928928
try
929929
{
930+
m_compiler->setExperimental(m_options.experimental);
930931
if (m_options.metadata.literalSources)
931932
m_compiler->useMetadataLiteralSources(true);
932933
m_compiler->setMetadataFormat(m_options.metadata.format);

solc/CommandLineParser.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static std::string const g_strEVMVersion = "evm-version";
5050
static std::string const g_strEOFVersion = "experimental-eof-version";
5151
static std::string const g_strViaIR = "via-ir";
5252
static std::string const g_strExperimentalViaIR = "experimental-via-ir";
53+
static std::string const g_strExperimental = "experimental";
5354
static std::string const g_strGas = "gas";
5455
static std::string const g_strHelp = "help";
5556
static std::string const g_strImportAst = "import-ast";
@@ -157,6 +158,18 @@ void CommandLineParser::checkMutuallyExclusive(std::vector<std::string> const& _
157158
}
158159
}
159160

161+
void CommandLineParser::checkExperimental(std::vector<std::string> const& _optionNames)
162+
{
163+
if (!m_args.contains(g_strExperimental) && countEnabledOptions(_optionNames) > 0)
164+
{
165+
solThrow(
166+
CommandLineValidationError,
167+
"The following options are only available in experimental mode: " + joinOptionNames(_optionNames) + ". " +
168+
"To toggle experimental mode, use the --experimental flag."
169+
);
170+
}
171+
}
172+
160173
bool CompilerOutputs::operator==(CompilerOutputs const& _other) const noexcept
161174
{
162175
for (bool CompilerOutputs::* member: componentMap() | ranges::views::values)
@@ -936,6 +949,17 @@ General Information)").c_str(),
936949
;
937950
desc.add(smtCheckerOptions);
938951

952+
po::options_description experimentalOptions("Experimental options");
953+
experimentalOptions.add_options()
954+
(
955+
g_strExperimental.c_str(),
956+
"Toggle experimental mode. Note that toggling experimental mode by itself will not "
957+
"enable any experimental features, but will simply allow for such features to be enabled in the "
958+
"usual manner, whether by using specific flags or pragmas."
959+
)
960+
;
961+
desc.add(experimentalOptions);
962+
939963
desc.add_options()(g_strInputFile.c_str(), po::value<std::vector<std::string>>(), "input file");
940964
return desc;
941965
}
@@ -979,6 +1003,9 @@ void CommandLineParser::processArgs()
9791003
else if (m_args.count(g_strColor) > 0)
9801004
m_options.formatting.coloredOutput = true;
9811005

1006+
if (m_args.contains(g_strExperimental))
1007+
m_options.experimental = true;
1008+
9821009
checkMutuallyExclusive({
9831010
g_strHelp,
9841011
g_strLicense,
@@ -992,6 +1019,18 @@ void CommandLineParser::processArgs()
9921019
g_strImportEvmAssemblerJson,
9931020
});
9941021

1022+
checkExperimental({
1023+
g_strLSP,
1024+
g_strImportAst,
1025+
g_strImportEvmAssemblerJson,
1026+
"ir-ast-json",
1027+
"ir-optimized-ast-json",
1028+
"yul-cfg-json",
1029+
"ethdebug",
1030+
"ethdebug-runtime",
1031+
g_strEOFVersion,
1032+
});
1033+
9951034
if (m_args.count(g_strHelp) > 0)
9961035
m_options.input.mode = InputMode::Help;
9971036
else if (m_args.count(g_strLicense) > 0)
@@ -1092,6 +1131,7 @@ void CommandLineParser::processArgs()
10921131
g_strPrettyJson,
10931132
"srcmap",
10941133
"srcmap-runtime",
1134+
g_strExperimental,
10951135
};
10961136

10971137
for (auto const& [optionName, optionValue]: m_args)
@@ -1159,6 +1199,12 @@ void CommandLineParser::processArgs()
11591199
if (!m_options.output.debugInfoSelection.has_value())
11601200
solThrow(CommandLineValidationError, "Invalid value for --" + g_strDebugInfo + " option: " + optionValue);
11611201

1202+
if (!m_options.experimental && m_options.output.debugInfoSelection->ethdebug)
1203+
solThrow(
1204+
CommandLineValidationError,
1205+
"--" + g_strDebugInfo + " ethdebug can only be used by toggling the --" + g_strExperimental + " flag."
1206+
);
1207+
11621208
if (m_options.output.debugInfoSelection->snippet && !m_options.output.debugInfoSelection->location)
11631209
solThrow(CommandLineValidationError, "To use 'snippet' with --" + g_strDebugInfo + " you must select also 'location'.");
11641210
}

solc/CommandLineParser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ struct CommandLineOptions
245245
bool initialize = false;
246246
ModelCheckerSettings settings;
247247
} modelChecker;
248+
249+
bool experimental = false;
248250
};
249251

250252
/// Parses the command-line arguments and produces a filled-out CommandLineOptions structure.
@@ -296,6 +298,7 @@ class CommandLineParser
296298
void parseOutputSelection();
297299

298300
void checkMutuallyExclusive(std::vector<std::string> const& _optionNames);
301+
void checkExperimental(std::vector<std::string> const& _optionNames);
299302
size_t countEnabledOptions(std::vector<std::string> const& _optionNames) const;
300303
static std::string joinOptionNames(std::vector<std::string> const& _optionNames, std::string _separator = ", ");
301304

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--pretty-json --json-indent 4 --import-asm-json -
1+
--pretty-json --json-indent 4 --experimental --import-asm-json -
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--import-asm-json - --opcodes --asm --bin --asm-json --pretty-json --json-indent 4
1+
--experimental --import-asm-json - --opcodes --asm --bin --asm-json --pretty-json --json-indent 4

test/cmdlineTests/ast_ir/args

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--ir-ast-json --ir-optimized-ast-json --optimize --pretty-json --json-indent 4
1+
--experimental --ir-ast-json --ir-optimized-ast-json --optimize --pretty-json --json-indent 4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--evm-version=homestead --import-ast --combined-json ast --pretty-json
1+
--experimental --evm-version=homestead --import-ast --combined-json ast --pretty-json

0 commit comments

Comments
 (0)