Skip to content

Commit

Permalink
Merge pull request #15316 from ethereum/remove_yul_cli_arg
Browse files Browse the repository at this point in the history
CLI: remove --yul flag
  • Loading branch information
r0qs committed Aug 8, 2024
2 parents c92b32f + ea85a78 commit f99c239
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 39 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Compiler Features:
* SMTChecker: Replace CVC4 as a possible BMC backend with cvc5.
* Standard JSON Interface: Do not perform IR optimization when only unoptimized IR is requested.
* Standard JSON Interface: Add ``transientStorageLayout`` output.
* Yul: Drop the deprecated typed Yul dialect that was only accessible via ``--yul`` in the CLI.
* Yul Optimizer: The optimizer now treats some previously unrecognized identical literals as identical.
* Commandline Interface: Allow the use of ``--asm-json`` output option in assembler mode to export EVM assembly of the contracts in JSON format.

Expand Down
19 changes: 12 additions & 7 deletions solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ General Information)").c_str(),
"Select desired EOF version. Currently the only valid value is 1. "
"If not specified, legacy non-EOF bytecode will be generated."
)
(
g_strYul.c_str(), "The typed Yul dialect is no longer supported. For regular Yul compilation use --strict-assembly instead."
)
;
outputOptions.add_options()
(
Expand Down Expand Up @@ -664,10 +667,6 @@ General Information)").c_str(),
g_strAssemble.c_str(),
"Switch to assembly mode and assume input is assembly."
)
(
g_strYul.c_str(),
"Switch to Yul mode and assume input is Yul."
)
(
g_strStrictAssembly.c_str(),
"Switch to strict assembly mode and assume input is strict assembly."
Expand Down Expand Up @@ -956,7 +955,6 @@ void CommandLineParser::processArgs()
g_strLink,
g_strAssemble,
g_strStrictAssembly,
g_strYul,
g_strImportAst,
g_strLSP,
g_strImportEvmAssemblerJson,
Expand All @@ -972,7 +970,7 @@ void CommandLineParser::processArgs()
m_options.input.mode = InputMode::StandardJson;
else if (m_args.count(g_strLSP))
m_options.input.mode = InputMode::LanguageServer;
else if (m_args.count(g_strAssemble) > 0 || m_args.count(g_strStrictAssembly) > 0 || m_args.count(g_strYul) > 0)
else if (m_args.count(g_strAssemble) > 0 || m_args.count(g_strStrictAssembly) > 0)
m_options.input.mode = InputMode::Assembler;
else if (m_args.count(g_strLink) > 0)
m_options.input.mode = InputMode::Linker;
Expand All @@ -990,6 +988,13 @@ void CommandLineParser::processArgs()
)
return;

if (m_args.count(g_strYul) > 0)
solThrow(
CommandLineValidationError,
"The typed Yul dialect formerly accessible via --yul is no longer supported, "
"please use --strict-assembly instead."
);

std::map<std::string, std::set<InputMode>> validOptionInputModeCombinations = {
// TODO: This should eventually contain all options.
{g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
Expand Down Expand Up @@ -1276,7 +1281,7 @@ void CommandLineParser::processArgs()
// switch to assembly mode
using Input = yul::YulStack::Language;
using Machine = yul::YulStack::Machine;
m_options.assembly.inputLanguage = m_args.count(g_strYul) ? Input::Yul : (m_args.count(g_strStrictAssembly) ? Input::StrictAssembly : Input::Assembly);
m_options.assembly.inputLanguage = m_args.count(g_strStrictAssembly) ? Input::StrictAssembly : Input::Assembly;

if (m_args.count(g_strMachine))
{
Expand Down
2 changes: 1 addition & 1 deletion test/cmdlineTests/yul_optimize_runs/args
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--yul --yul-dialect evm --optimize --optimize-runs 10000
--strict-assembly --yul-dialect evm --optimize --optimize-runs 10000
21 changes: 13 additions & 8 deletions test/cmdlineTests/~assembler_modes/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@ function test_solc_assembly_output
}

echo '{}' | msg_on_error --silent "$SOLC" - --assemble
echo '{}' | msg_on_error --silent "$SOLC" - --yul
echo '{}' | msg_on_error --silent "$SOLC" - --strict-assembly

# Test options above in conjunction with --optimize.
# Using both, --assemble and --optimize should fail.
# Test in conjunction with --optimize. Using both, --assemble and --optimize should fail.
echo '{}' | "$SOLC" - --assemble --optimize &>/dev/null && fail "solc --assemble --optimize did not fail as expected."
echo '{}' | "$SOLC" - --yul --optimize &>/dev/null && fail "solc --yul --optimize did not fail as expected."

# Test yul and strict assembly output
# Test strict assembly output
# Non-empty code results in non-empty binary representation with optimizations turned off,
# while it results in empty binary representation with optimizations turned on.
test_solc_assembly_output "{ let x:u256 := 0:u256 mstore(0, x) }" "{ { let x := 0 mstore(0, x) } }" "--yul"
test_solc_assembly_output "{ let x:u256 := bitnot(7:u256) mstore(0, x) }" "{ { let x := bitnot(7) mstore(0, x) } }" "--yul"
test_solc_assembly_output "{ let t:bool := not(true) if t { mstore(0, 1) } }" "{ { let t:bool := not(true) if t { mstore(0, 1) } } }" "--yul"
test_solc_assembly_output "{ let x := 0 mstore(0, x) }" "{ { let x := 0 mstore(0, x) } }" "--strict-assembly"
test_solc_assembly_output "{ let x := 0 mstore(0, x) }" "{ { } }" "--strict-assembly --optimize"

# Test that --yul triggers an error
set +e
output=$(echo '{}' | "$SOLC" - --yul 2>&1)
failed=$?
expected="Error: The typed Yul dialect formerly accessible via --yul is no longer supported, please use --strict-assembly instead."
set -e
if [[ $output != "${expected}" ]] || (( failed == 0 ))
then
fail "Incorrect error response to --yul flag: $output"
fi
9 changes: 4 additions & 5 deletions test/solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,24 @@ BOOST_AUTO_TEST_CASE(version)

BOOST_AUTO_TEST_CASE(multiple_input_modes)
{
std::array<std::string, 10> inputModeOptions = {
std::array inputModeOptions {
"--help",
"--license",
"--version",
"--standard-json",
"--link",
"--assemble",
"--strict-assembly",
"--yul",
"--import-ast",
"--import-asm-json",
};
std::string expectedMessage =
"The following options are mutually exclusive: "
"--help, --license, --version, --standard-json, --link, --assemble, --strict-assembly, --yul, --import-ast, --lsp, --import-asm-json. "
"--help, --license, --version, --standard-json, --link, --assemble, --strict-assembly, --import-ast, --lsp, --import-asm-json. "
"Select at most one.";

for (std::string const& mode1: inputModeOptions)
for (std::string const& mode2: inputModeOptions)
for (auto const& mode1: inputModeOptions)
for (auto const& mode2: inputModeOptions)
if (mode1 != mode2)
BOOST_CHECK_EXCEPTION(
parseCommandLineAndReadInputFiles({"solc", mode1, mode2}),
Expand Down
32 changes: 14 additions & 18 deletions test/solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ BOOST_AUTO_TEST_CASE(no_import_callback)
{"solc", "--strict-assembly", "--no-import-callback", "input.yul"},
{"solc", "--import-ast", "--no-import-callback", "ast.json"},
{"solc", "--link", "--no-import-callback", "input.bin"},
{"solc", "--yul", "--no-import-callback", "input.yul"},
};

for (auto const& commandLine: commandLinePerInputMode)
Expand All @@ -271,13 +270,10 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
{
static std::vector<std::tuple<std::vector<std::string>, YulStack::Machine, YulStack::Language>> const allowedCombinations = {
{{"--machine=evm", "--yul-dialect=evm", "--assemble"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
{{"--machine=evm", "--yul-dialect=evm", "--yul"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
{{"--machine=evm", "--yul-dialect=evm", "--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
{{"--machine=evm", "--assemble"}, YulStack::Machine::EVM, YulStack::Language::Assembly},
{{"--machine=evm", "--yul"}, YulStack::Machine::EVM, YulStack::Language::Yul},
{{"--machine=evm", "--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
{{"--assemble"}, YulStack::Machine::EVM, YulStack::Language::Assembly},
{{"--yul"}, YulStack::Machine::EVM, YulStack::Language::Yul},
{{"--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
};

Expand Down Expand Up @@ -424,20 +420,20 @@ BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
{
std::map<std::string, std::vector<std::string>> invalidOptionInputModeCombinations = {
// TODO: This should eventually contain all options.
{"--experimental-via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--metadata-literal", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--metadata-hash=swarm", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-show-proved-safe", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-show-unproved", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-show-unsupported", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-div-mod-no-slacks", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-engine=bmc", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-invariants=contract,reentrancy", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-solvers=z3,smtlib2", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-timeout=5", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-contracts=contract1.yul:A,contract2.yul:B", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-targets=underflow,divByZero", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}
{"--experimental-via-ir", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--via-ir", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--metadata-literal", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--metadata-hash=swarm", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-show-proved-safe", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-show-unproved", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-show-unsupported", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-div-mod-no-slacks", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-engine=bmc", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-invariants=contract,reentrancy", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-solvers=z3,smtlib2", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-timeout=5", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-contracts=contract1.yul:A,contract2.yul:B", {"--assemble", "--strict-assembly", "--standard-json", "--link"}},
{"--model-checker-targets=underflow,divByZero", {"--assemble", "--strict-assembly", "--standard-json", "--link"}}
};

for (auto const& [optionName, inputModes]: invalidOptionInputModeCombinations)
Expand Down

0 comments on commit f99c239

Please sign in to comment.