mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Make --optimize-yul work again
This commit is contained in:
		
							parent
							
								
									42a068b449
								
							
						
					
					
						commit
						2769bb52f6
					
				| @ -6,6 +6,7 @@ Language Features: | ||||
| Compiler Features: | ||||
|  * Commandline Interface: Add ``--ast-compact-json`` output in assembler mode. | ||||
|  * Commandline Interface: Add ``--ir-ast-json`` and ``--ir-optimized-ast-json`` outputs for Solidity input, providing AST in compact JSON format for IR and optimized IR. | ||||
|  * Commandline Interface: Respect ``--optimize-yul`` and ``--no-optimize-yul`` in compiler mode and accept them in assembler mode as well. ``--optimize --no-optimize-yul`` combination now allows enabling EVM assembly optimizer without enabling Yul optimizer. | ||||
|  * EWasm: Remove EWasm backend. | ||||
|  * Parser: Introduce ``pragma experimental solidity``, which will enable an experimental language mode that in particular has no stability guarantees between non-breaking releases and is not suited for production use. | ||||
|  * Standard JSON Interface: Add ``ast`` file-level output for Yul input. | ||||
|  | ||||
| @ -259,13 +259,16 @@ OptimiserSettings CommandLineOptions::optimiserSettings() const | ||||
| { | ||||
| 	OptimiserSettings settings; | ||||
| 
 | ||||
| 	if (optimizer.optimizeEvmasm || optimizer.optimizeYul) | ||||
| 	if (optimizer.optimizeEvmasm) | ||||
| 		settings = OptimiserSettings::standard(); | ||||
| 	else | ||||
| 		settings = OptimiserSettings::minimal(); | ||||
| 
 | ||||
| 	if (!optimizer.optimizeYul) | ||||
| 		settings.runYulOptimiser = false; | ||||
| 	settings.runYulOptimiser = optimizer.optimizeYul; | ||||
| 	if (optimizer.optimizeYul) | ||||
| 		// NOTE: Standard JSON disables optimizeStackAllocation by default when yul optimizer is disabled.
 | ||||
| 		// --optimize --no-optimize-yul on the CLI does not have that effect.
 | ||||
| 		settings.optimizeStackAllocation = true; | ||||
| 
 | ||||
| 	if (optimizer.expectedExecutionsPerDeployment.has_value()) | ||||
| 		settings.expectedExecutionsPerDeployment = optimizer.expectedExecutionsPerDeployment.value(); | ||||
| @ -644,21 +647,15 @@ General Information)").c_str(), | ||||
| 		) | ||||
| 		( | ||||
| 			g_strAssemble.c_str(), | ||||
| 			("Switch to assembly mode, ignoring all options except " | ||||
| 			"--" + g_strMachine + ", --" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " " | ||||
| 			"and assumes input is assembly.").c_str() | ||||
| 			"Switch to assembly mode and assume input is assembly." | ||||
| 		) | ||||
| 		( | ||||
| 			g_strYul.c_str(), | ||||
| 			("Switch to Yul mode, ignoring all options except " | ||||
| 			"--" + g_strMachine + ", --" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " " | ||||
| 			"and assumes input is Yul.").c_str() | ||||
| 			"Switch to Yul mode and assume input is Yul." | ||||
| 		) | ||||
| 		( | ||||
| 			g_strStrictAssembly.c_str(), | ||||
| 			("Switch to strict assembly mode, ignoring all options except " | ||||
| 			"--" + g_strMachine + ", --" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " " | ||||
| 			"and assumes input is strict assembly.").c_str() | ||||
| 			"Switch to strict assembly mode and assume input is strict assembly." | ||||
| 		) | ||||
| 		( | ||||
| 			g_strImportAst.c_str(), | ||||
| @ -784,7 +781,7 @@ General Information)").c_str(), | ||||
| 	optimizerOptions.add_options() | ||||
| 		( | ||||
| 			g_strOptimize.c_str(), | ||||
| 			"Enable bytecode optimizer." | ||||
| 			"Enable optimizer." | ||||
| 		) | ||||
| 		( | ||||
| 			g_strOptimizeRuns.c_str(), | ||||
| @ -796,16 +793,18 @@ General Information)").c_str(), | ||||
| 		) | ||||
| 		( | ||||
| 			g_strOptimizeYul.c_str(), | ||||
| 			("Legacy option, ignored. Use the general --" + g_strOptimize + " to enable Yul optimizer.").c_str() | ||||
| 			("Enable Yul optimizer (independently of the EVM assembly optimizer). " | ||||
| 			"The general --" + g_strOptimize + " option automatically enables this unless --" + | ||||
| 			g_strNoOptimizeYul + " is specified.").c_str() | ||||
| 		) | ||||
| 		( | ||||
| 			g_strNoOptimizeYul.c_str(), | ||||
| 			"Disable Yul optimizer in Solidity." | ||||
| 			"Disable Yul optimizer (independently of the EVM assembly optimizer)." | ||||
| 		) | ||||
| 		( | ||||
| 			g_strYulOptimizations.c_str(), | ||||
| 			po::value<string>()->value_name("steps"), | ||||
| 			"Forces yul optimizer to use the specified sequence of optimization steps instead of the built-in one." | ||||
| 			"Forces Yul optimizer to use the specified sequence of optimization steps instead of the built-in one." | ||||
| 		) | ||||
| 	; | ||||
| 	desc.add(optimizerOptions); | ||||
| @ -1165,10 +1164,10 @@ void CommandLineParser::processArgs() | ||||
| 			"Options --" + g_strOptimizeYul + " and --" + g_strNoOptimizeYul + " cannot be used together." | ||||
| 		); | ||||
| 
 | ||||
| 	// We deliberately ignore --optimize-yul
 | ||||
| 	m_options.optimizer.optimizeEvmasm = (m_args.count(g_strOptimize) > 0); | ||||
| 	m_options.optimizer.optimizeYul = ( | ||||
| 		m_args.count(g_strOptimize) > 0 && m_args.count(g_strNoOptimizeYul) == 0 | ||||
| 		(m_args.count(g_strOptimize) > 0 && m_args.count(g_strNoOptimizeYul) == 0) || | ||||
| 		m_args.count(g_strOptimizeYul) > 0 | ||||
| 	); | ||||
| 	if (!m_args[g_strOptimizeRuns].defaulted()) | ||||
| 		m_options.optimizer.expectedExecutionsPerDeployment = m_args.at(g_strOptimizeRuns).as<unsigned>(); | ||||
| @ -1201,8 +1200,6 @@ void CommandLineParser::processArgs() | ||||
| 			g_strOutputDir, | ||||
| 			g_strGas, | ||||
| 			g_strCombinedJson, | ||||
| 			g_strOptimizeYul, | ||||
| 			g_strNoOptimizeYul, | ||||
| 		}; | ||||
| 		if (countEnabledOptions(nonAssemblyModeOptions) >= 1) | ||||
| 		{ | ||||
| @ -1210,9 +1207,6 @@ void CommandLineParser::processArgs() | ||||
| 			auto enabledOptions = nonAssemblyModeOptions | ranges::views::filter(optionEnabled) | ranges::to_vector; | ||||
| 
 | ||||
| 			string message = "The following options are invalid in assembly mode: " + joinOptionNames(enabledOptions) + "."; | ||||
| 			if (m_args.count(g_strOptimizeYul) || m_args.count(g_strNoOptimizeYul)) | ||||
| 				message += " Optimization is disabled by default and can be enabled with --" + g_strOptimize + "."; | ||||
| 
 | ||||
| 			solThrow(CommandLineValidationError, message); | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
| @ -1 +0,0 @@ | ||||
| --strict-assembly --optimize-yul | ||||
| @ -1 +0,0 @@ | ||||
| The following options are invalid in assembly mode: --optimize-yul. Optimization is disabled by default and can be enabled with --optimize. | ||||
| @ -1 +0,0 @@ | ||||
| 1 | ||||
| @ -1,3 +0,0 @@ | ||||
| { | ||||
|     sstore(0, 1) | ||||
| } | ||||
| @ -440,6 +440,10 @@ BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations) | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(optimizer_flags) | ||||
| { | ||||
| 	OptimiserSettings yulOnly = OptimiserSettings::minimal(); | ||||
| 	yulOnly.runYulOptimiser = true; | ||||
| 	yulOnly.optimizeStackAllocation = true; | ||||
| 
 | ||||
| 	OptimiserSettings evmasmOnly = OptimiserSettings::standard(); | ||||
| 	evmasmOnly.runYulOptimiser = false; | ||||
| 
 | ||||
| @ -447,7 +451,7 @@ BOOST_AUTO_TEST_CASE(optimizer_flags) | ||||
| 		{{}, OptimiserSettings::minimal()}, | ||||
| 		{{"--optimize"}, OptimiserSettings::standard()}, | ||||
| 		{{"--no-optimize-yul"}, OptimiserSettings::minimal()}, | ||||
| 		{{"--optimize-yul"}, OptimiserSettings::minimal()}, | ||||
| 		{{"--optimize-yul"}, yulOnly}, | ||||
| 		{{"--optimize", "--no-optimize-yul"}, evmasmOnly}, | ||||
| 		{{"--optimize", "--optimize-yul"}, OptimiserSettings::standard()}, | ||||
| 	}; | ||||
| @ -455,6 +459,7 @@ BOOST_AUTO_TEST_CASE(optimizer_flags) | ||||
| 	map<InputMode, string> inputModeFlagMap = { | ||||
| 		{InputMode::Compiler, ""}, | ||||
| 		{InputMode::CompilerWithASTImport, "--import-ast"}, | ||||
| 		{InputMode::Assembler, "--strict-assembly"}, | ||||
| 	}; | ||||
| 
 | ||||
| 	for (auto const& [inputMode, inputModeFlag]: inputModeFlagMap) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user