diff --git a/tests/unit/ast/test_pre_parser.py b/tests/unit/ast/test_pre_parser.py index 3dcf48e9a4..fd24586a46 100644 --- a/tests/unit/ast/test_pre_parser.py +++ b/tests/unit/ast/test_pre_parser.py @@ -209,6 +209,25 @@ def test_parse_pragmas(code, pre_parse_settings, compiler_data_settings, mock_ve assert compiler_data.settings == compiler_data_settings +pragma_venom = [ + """ + #pragma venom + """, + """ + #pragma experimental-codegen + """, +] + + +@pytest.mark.parametrize("code", pragma_venom) +def test_parse_venom_pragma(code): + pre_parse_result = pre_parse(code) + assert pre_parse_result.settings.experimental_codegen is True + + compiler_data = CompilerData(code) + assert compiler_data.settings.experimental_codegen is True + + invalid_pragmas = [ # evm-versionnn """ @@ -236,6 +255,15 @@ def test_parse_pragmas(code, pre_parse_settings, compiler_data_settings, mock_ve # pragma evm-version cancun # pragma evm-version shanghai """, + # duplicate setting of venom + """ + #pragma venom + #pragma experimental-codegen + """, + """ + #pragma venom + #pragma venom + """, ] diff --git a/tests/unit/cli/vyper_json/test_compile_json.py b/tests/unit/cli/vyper_json/test_compile_json.py index 55fdc4a6b3..d3386b567c 100644 --- a/tests/unit/cli/vyper_json/test_compile_json.py +++ b/tests/unit/cli/vyper_json/test_compile_json.py @@ -9,6 +9,7 @@ compile_json, exc_handler_to_dict, get_inputs, + get_settings, ) from vyper.compiler import OUTPUT_FORMATS, compile_code, compile_from_file_input from vyper.compiler.input_bundle import JSONInputBundle @@ -319,3 +320,38 @@ def test_compile_json_with_abi_top(make_input_bundle): """ input_bundle = make_input_bundle({"stream.json": stream, "code.vy": code}) vyper.compiler.compile_code(code, input_bundle=input_bundle) + + +def test_compile_json_with_experimental_codegen(): + code = { + "language": "Vyper", + "sources": {"foo.vy": {"content": "@external\ndef foo() -> bool:\n return True"}}, + "settings": { + "evmVersion": "cancun", + "optimize": "gas", + "venom": True, + "search_paths": [], + "outputSelection": {"*": ["ast"]}, + }, + } + + settings = get_settings(code) + assert settings.experimental_codegen is True + + +def test_compile_json_with_both_venom_aliases(): + code = { + "language": "Vyper", + "sources": {"foo.vy": {"content": ""}}, + "settings": { + "evmVersion": "cancun", + "optimize": "gas", + "experimentalCodegen": False, + "venom": False, + "search_paths": [], + "outputSelection": {"*": ["ast"]}, + }, + } + with pytest.raises(JSONError) as e: + get_settings(code) + assert e.value.args[0] == "both experimentalCodegen and venom cannot be set" diff --git a/vyper/ast/pre_parser.py b/vyper/ast/pre_parser.py index 07ba1d2d0d..5d2abcf645 100644 --- a/vyper/ast/pre_parser.py +++ b/vyper/ast/pre_parser.py @@ -265,10 +265,10 @@ def pre_parse(code: str) -> PreParseResult: if evm_version not in EVM_VERSIONS: raise StructureException(f"Invalid evm version: `{evm_version}`", start) settings.evm_version = evm_version - elif pragma.startswith("experimental-codegen"): + elif pragma.startswith("experimental-codegen") or pragma.startswith("venom"): if settings.experimental_codegen is not None: raise StructureException( - "pragma experimental-codegen specified twice!", start + "pragma experimental-codegen/venom specified twice!", start ) settings.experimental_codegen = True elif pragma.startswith("enable-decimals"): diff --git a/vyper/cli/vyper_compile.py b/vyper/cli/vyper_compile.py index 5999aed178..fde35f781e 100755 --- a/vyper/cli/vyper_compile.py +++ b/vyper/cli/vyper_compile.py @@ -176,6 +176,7 @@ def _parse_args(argv): parser.add_argument("-o", help="Set the output path", dest="output_path") parser.add_argument( "--experimental-codegen", + "--venom", help="The compiler use the new IR codegen. This is an experimental feature.", action="store_true", dest="experimental_codegen", diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 7d0e6064af..9fcdf27baf 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -253,7 +253,13 @@ def get_settings(input_dict: dict) -> Settings: evm_version = get_evm_version(input_dict) optimize = input_dict["settings"].get("optimize") + experimental_codegen = input_dict["settings"].get("experimentalCodegen") + if experimental_codegen is None: + experimental_codegen = input_dict["settings"].get("venom") + elif input_dict["settings"].get("venom") is not None: + raise JSONError("both experimentalCodegen and venom cannot be set") + if isinstance(optimize, bool): # bool optimization level for backwards compatibility warnings.warn( diff --git a/vyper/compiler/settings.py b/vyper/compiler/settings.py index 7c20e03906..a8e28c1ed1 100644 --- a/vyper/compiler/settings.py +++ b/vyper/compiler/settings.py @@ -77,7 +77,7 @@ def as_cli(self): if self.optimize is not None: ret.append(" --optimize " + str(self.optimize)) if self.experimental_codegen is True: - ret.append(" --experimental-codegen") + ret.append(" --venom") if self.evm_version is not None: ret.append(" --evm-version " + self.evm_version) if self.debug is True: