Skip to content

Commit

Permalink
refactor[ux]: add venom as experimental-codegen alias (vyperlang#…
Browse files Browse the repository at this point in the history
…4337)

Make "venom" an alternative alias to the "experimental_codegen" flag.
Add the alias to cli, pre-parser, and json parser.
  • Loading branch information
sandbubbles authored Nov 5, 2024
1 parent fcddb70 commit 471a556
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
28 changes: 28 additions & 0 deletions tests/unit/ast/test_pre_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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
"""
Expand Down Expand Up @@ -218,6 +237,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
""",
]


Expand Down
36 changes: 36 additions & 0 deletions tests/unit/cli/vyper_json/test_compile_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
4 changes: 2 additions & 2 deletions vyper/ast/pre_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
1 change: 1 addition & 0 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions vyper/cli/vyper_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion vyper/compiler/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 471a556

Please sign in to comment.