From d7d000ff2790bfb30b7acf4d65dd2c1d51d6b0ad Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 28 Oct 2024 11:51:26 +0100 Subject: [PATCH 01/10] test source code pragmas work with both venom and experimental-codegen --- tests/unit/ast/test_pre_parser.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/ast/test_pre_parser.py b/tests/unit/ast/test_pre_parser.py index 4190725f7e..6763895263 100644 --- a/tests/unit/ast/test_pre_parser.py +++ b/tests/unit/ast/test_pre_parser.py @@ -191,6 +191,24 @@ 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 == True + + compiler_data = CompilerData(code) + assert compiler_data.settings.experimental_codegen == True + + invalid_pragmas = [ # evm-versionnn """ From 1743f789a7a21ff7ad0ed9f526d2d637e495b302 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 28 Oct 2024 15:15:32 +0100 Subject: [PATCH 02/10] test venom key works in json input --- .../unit/cli/vyper_json/test_compile_json.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/cli/vyper_json/test_compile_json.py b/tests/unit/cli/vyper_json/test_compile_json.py index 5da98cf20f..9cc7db812a 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,26 @@ 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==True \ No newline at end of file From 61e1ea8e98a35aad7d75832483290d2cce0e2686 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 28 Oct 2024 15:16:59 +0100 Subject: [PATCH 03/10] add venom alias to experimental-codegen --- vyper/ast/pre_parser.py | 4 ++-- vyper/cli/vyper_compile.py | 1 + vyper/cli/vyper_json.py | 2 +- vyper/compiler/settings.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) 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..56d5a9f687 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -253,7 +253,7 @@ 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") + experimental_codegen = input_dict["settings"].get("experimentalCodegen") or input_dict["settings"].get("venom") 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: From 92e101f7348d7f06c1ed682cac6485445b613982 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 28 Oct 2024 15:21:50 +0100 Subject: [PATCH 04/10] lint --- tests/unit/ast/test_pre_parser.py | 1 + tests/unit/cli/vyper_json/test_compile_json.py | 14 ++++---------- vyper/cli/vyper_json.py | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/unit/ast/test_pre_parser.py b/tests/unit/ast/test_pre_parser.py index 6763895263..5633a039eb 100644 --- a/tests/unit/ast/test_pre_parser.py +++ b/tests/unit/ast/test_pre_parser.py @@ -200,6 +200,7 @@ def test_parse_pragmas(code, pre_parse_settings, compiler_data_settings, mock_ve """, ] + @pytest.mark.parametrize("code", pragma_venom) def test_parse_venom_pragma(code): pre_parse_result = pre_parse(code) diff --git a/tests/unit/cli/vyper_json/test_compile_json.py b/tests/unit/cli/vyper_json/test_compile_json.py index 9cc7db812a..775f10d663 100644 --- a/tests/unit/cli/vyper_json/test_compile_json.py +++ b/tests/unit/cli/vyper_json/test_compile_json.py @@ -325,21 +325,15 @@ def test_compile_json_with_abi_top(make_input_bundle): def test_compile_json_with_experimental_codegen(): code = { "language": "Vyper", - "sources": { - "foo.vy": { - "content": "@external\ndef foo() -> bool:\n return True" - } - }, + "sources": {"foo.vy": {"content": "@external\ndef foo() -> bool:\n return True"}}, "settings": { "evmVersion": "cancun", "optimize": "gas", "venom": True, "search_paths": [], - "outputSelection": { - "*": ["ast"], - } - } + "outputSelection": {"*": ["ast"]}, + }, } settings = get_settings(code) - assert settings.experimental_codegen==True \ No newline at end of file + assert settings.experimental_codegen == True diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 56d5a9f687..90aa8199fa 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -253,7 +253,9 @@ 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") or input_dict["settings"].get("venom") + experimental_codegen = input_dict["settings"].get("experimentalCodegen") or input_dict[ + "settings" + ].get("venom") if isinstance(optimize, bool): # bool optimization level for backwards compatibility warnings.warn( From f228f6780cc6a1889f3ea6fea52beda9ccde0992 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 28 Oct 2024 15:35:26 +0100 Subject: [PATCH 05/10] fix false and none mixing up --- vyper/cli/vyper_json.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 90aa8199fa..59d09232b4 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -253,9 +253,9 @@ 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") or input_dict[ - "settings" - ].get("venom") + experimental_codegen = input_dict["settings"].get("experimentalCodegen") + if experimental_codegen is None: + experimental_codegen = input_dict["settings"].get("venom") if isinstance(optimize, bool): # bool optimization level for backwards compatibility warnings.warn( From 2e61f77b4f7a35956a0d25d3892c98103354850d Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 28 Oct 2024 17:43:46 +0100 Subject: [PATCH 06/10] raise error when both experimental codegen and venom are set --- tests/unit/cli/vyper_json/test_compile_json.py | 17 +++++++++++++++++ vyper/cli/vyper_json.py | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/tests/unit/cli/vyper_json/test_compile_json.py b/tests/unit/cli/vyper_json/test_compile_json.py index 775f10d663..b7d6ba4c3a 100644 --- a/tests/unit/cli/vyper_json/test_compile_json.py +++ b/tests/unit/cli/vyper_json/test_compile_json.py @@ -337,3 +337,20 @@ def test_compile_json_with_experimental_codegen(): settings = get_settings(code) assert settings.experimental_codegen == 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): + get_settings(code) diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 59d09232b4..9fcdf27baf 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -253,9 +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( From 70bb05d00c844eb1f29cad350a3bcd67fd1969dc Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Tue, 29 Oct 2024 09:50:53 +0100 Subject: [PATCH 07/10] test dupliciting pragma setting of venom --- tests/unit/ast/test_pre_parser.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/ast/test_pre_parser.py b/tests/unit/ast/test_pre_parser.py index 5633a039eb..e58c63c204 100644 --- a/tests/unit/ast/test_pre_parser.py +++ b/tests/unit/ast/test_pre_parser.py @@ -237,6 +237,15 @@ def test_parse_venom_pragma(code): # pragma evm-version cancun # pragma evm-version shanghai """, + # duplicit setting of venom + """ + #pragma venom + #pragma experimental-codegen + """, + """ + #pragma venom + #pragma venom + """, ] From 5a80cd7582a1bc256e7f7dc96a46c3c2971abf4d Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Tue, 29 Oct 2024 09:53:28 +0100 Subject: [PATCH 08/10] fix flake8 errors --- tests/unit/ast/test_pre_parser.py | 4 ++-- tests/unit/cli/vyper_json/test_compile_json.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/ast/test_pre_parser.py b/tests/unit/ast/test_pre_parser.py index e58c63c204..7b064fcef3 100644 --- a/tests/unit/ast/test_pre_parser.py +++ b/tests/unit/ast/test_pre_parser.py @@ -204,10 +204,10 @@ def test_parse_pragmas(code, pre_parse_settings, compiler_data_settings, mock_ve @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 == True + assert pre_parse_result.settings.experimental_codegen is True compiler_data = CompilerData(code) - assert compiler_data.settings.experimental_codegen == True + assert compiler_data.settings.experimental_codegen is True invalid_pragmas = [ diff --git a/tests/unit/cli/vyper_json/test_compile_json.py b/tests/unit/cli/vyper_json/test_compile_json.py index b7d6ba4c3a..ff49f5d514 100644 --- a/tests/unit/cli/vyper_json/test_compile_json.py +++ b/tests/unit/cli/vyper_json/test_compile_json.py @@ -336,7 +336,7 @@ def test_compile_json_with_experimental_codegen(): } settings = get_settings(code) - assert settings.experimental_codegen == True + assert settings.experimental_codegen is True def test_compile_json_with_both_venom_aliases(): From e18a4e5f367fbbd8bb46c7c2429f01595d63b2ea Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 1 Nov 2024 07:46:37 +0000 Subject: [PATCH 09/10] fix typo --- tests/unit/ast/test_pre_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ast/test_pre_parser.py b/tests/unit/ast/test_pre_parser.py index 7b064fcef3..5d3f30481c 100644 --- a/tests/unit/ast/test_pre_parser.py +++ b/tests/unit/ast/test_pre_parser.py @@ -237,7 +237,7 @@ def test_parse_venom_pragma(code): # pragma evm-version cancun # pragma evm-version shanghai """, - # duplicit setting of venom + # duplicate setting of venom """ #pragma venom #pragma experimental-codegen From d6bba9917f4e168c0005427a110e6d615cf732e4 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Tue, 5 Nov 2024 09:12:53 +0000 Subject: [PATCH 10/10] check the error message --- tests/unit/cli/vyper_json/test_compile_json.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/cli/vyper_json/test_compile_json.py b/tests/unit/cli/vyper_json/test_compile_json.py index ff49f5d514..7802ee7955 100644 --- a/tests/unit/cli/vyper_json/test_compile_json.py +++ b/tests/unit/cli/vyper_json/test_compile_json.py @@ -352,5 +352,6 @@ def test_compile_json_with_both_venom_aliases(): "outputSelection": {"*": ["ast"]}, }, } - with pytest.raises(JSONError): + with pytest.raises(JSONError) as e: get_settings(code) + assert e.value.args[0] == "both experimentalCodegen and venom cannot be set"