Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[ux]: compile .vyi files #4290

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fb72306
set is_interface based on the suffix of an input file
sandbubbles Oct 11, 2024
8bc61ed
construct ir_runtime only if input isn't interface
sandbubbles Oct 11, 2024
112c76f
exclude some output formats when compiling interface
sandbubbles Oct 11, 2024
fc05efe
add test for interface outputs
sandbubbles Oct 11, 2024
e5fc9a7
iterate through all unsupported formats
sandbubbles Oct 12, 2024
328f7fd
tag modules with is_interface
sandbubbles Oct 12, 2024
36c620c
add is_interface tag to ModuleT
sandbubbles Oct 13, 2024
d181da1
add is_interface to parse_to_ast_with_settings
sandbubbles Oct 14, 2024
5d4e55b
adjust tests
sandbubbles Oct 14, 2024
6641092
lint
sandbubbles Oct 14, 2024
87bc04e
merge master
sandbubbles Oct 14, 2024
0908bdf
Merge branch 'master' into feat/compile-solely-vyi
sandbubbles Oct 15, 2024
afd8f8e
adjust solution due to merge
sandbubbles Oct 15, 2024
8048d4f
reduce a multiline expression
charles-cooper Oct 15, 2024
2651d89
fix mypy
charles-cooper Oct 15, 2024
1134c3a
style: factor out an expression
charles-cooper Oct 15, 2024
b582f8f
Merge branch 'master' into feat/compile-solely-vyi
charles-cooper Oct 15, 2024
5cdb2da
Merge branch 'master' into feat/compile-solely-vyi
charles-cooper Oct 17, 2024
324b598
add flags into interface output
sandbubbles Oct 25, 2024
50692a1
add test for presence of flags in interface output
sandbubbles Oct 25, 2024
fcfc2ec
lint
sandbubbles Oct 25, 2024
60dddd4
capitalize the first letter but leave the rest the same
sandbubbles Oct 25, 2024
77d62a5
Merge branch 'master' into feat/compile-solely-vyi
sandbubbles Oct 29, 2024
3bf9389
fix flake8 errors
sandbubbles Oct 29, 2024
6806134
Merge branch 'master' into feat/compile-solely-vyi
sandbubbles Nov 7, 2024
5d954d8
remove duplicate list
sandbubbles Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/unit/cli/vyper_compile/test_compile_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,29 @@ def test_archive_search_path(tmp_path_factory, make_file, chdir_tmp_path):

used_dir = search_paths[-1].stem # either dir1 or dir2
assert output_bundle.used_search_paths == [".", "0/" + used_dir]

def test_compile_interface_file(make_file):
interface = """
@view
@external
def foo() -> String[1]:
...

@view
@external
def bar() -> String[1]:
...

@external
def baz() -> uint8:
...

"""
file = make_file("interface.vyi", interface)
compile_files([file], ["ast","annotated_ast","interface","external_interface","abi"])

with pytest.raises(ValueError):
compile_files([file],["bytecode"])

with pytest.raises(ValueError):
compile_files([file],["asm"])
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions vyper/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
"opcodes_runtime": output.build_opcodes_runtime_output,
}

INTERFACE_OUTPUT_FORMATS = ["ast_dict",
"annotated_ast_dict",
"interface",
"external_interface",
"abi"]

UNKNOWN_CONTRACT_NAME = "<unknown>"

Expand Down Expand Up @@ -121,6 +126,8 @@ def compile_from_file_input(
for output_format in output_formats:
if output_format not in OUTPUT_FORMATS:
raise ValueError(f"Unsupported format type {repr(output_format)}")
elif file_input.resolved_path.suffix == ".vyi" and output_format not in INTERFACE_OUTPUT_FORMATS:
raise ValueError(f"Unsupported format for compiling interface: {repr(output_format)}")
try:
formatter = OUTPUT_FORMATS[output_format]
ret[output_format] = formatter(compiler_data)
Expand Down
3 changes: 2 additions & 1 deletion vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def build_method_identifiers_output(compiler_data: CompilerData) -> dict:

def build_abi_output(compiler_data: CompilerData) -> list:
module_t = compiler_data.annotated_vyper_module._metadata["type"]
_ = compiler_data.ir_runtime # ensure _ir_info is generated
if compiler_data.contract_path.suffix != ".vyi":
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
_ = compiler_data.ir_runtime # ensure _ir_info is generated

abi = module_t.interface.to_toplevel_abi_dict()
if compiler_data.show_gas_estimates:
Expand Down
3 changes: 2 additions & 1 deletion vyper/compiler/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def generate_annotated_ast(vyper_module: vy_ast.Module, input_bundle: InputBundl
vyper_module = copy.deepcopy(vyper_module)
with input_bundle.search_path(Path(vyper_module.resolved_path).parent):
# note: analyze_module does type inference on the AST
analyze_module(vyper_module, input_bundle)
is_interface = vyper_module.resolved_path.endswith(".vyi")
analyze_module(vyper_module, input_bundle, is_interface=is_interface)

return vyper_module

Expand Down