Skip to content

Commit

Permalink
Merge branch 'master' into perf/liveness2
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Nov 12, 2024
2 parents 8135181 + 0abcf45 commit 5ec2cb2
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://github.com/vyperlang/vyper/workflows/Test/badge.svg)](https://github.com/vyperlang/vyper/actions/workflows/test.yml)
[![Documentation Status](https://readthedocs.org/projects/vyper/badge/?version=latest)](http://docs.vyperlang.org/en/latest/?badge=latest "ReadTheDocs")
[![Discord](https://img.shields.io/discord/969926564286459934.svg?label=%23vyper)](https://discord.gg/6tw7PTM7C2)
[![Telegram](https://img.shields.io/badge/Vyperholics🐍-Telegram-blue)](https://t.me/vyperlang)

[![PyPI](https://badge.fury.io/py/vyper.svg)](https://pypi.org/project/vyper "PyPI")
[![Docker](https://img.shields.io/docker/cloud/build/vyperlang/vyper)](https://hub.docker.com/r/vyperlang/vyper "DockerHub")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

extras_require["dev"] = extras_require["dev"] + extras_require["test"] + extras_require["lint"]

with open("README.md", "r") as f:
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()


Expand Down
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 5ec2cb2

Please sign in to comment.