Skip to content

feat[ux]: allow "compiling" .vyi files#4290

Merged
charles-cooper merged 47 commits intovyperlang:masterfrom
sandbubbles:feat/compile-solely-vyi
Dec 27, 2024
Merged

feat[ux]: allow "compiling" .vyi files#4290
charles-cooper merged 47 commits intovyperlang:masterfrom
sandbubbles:feat/compile-solely-vyi

Conversation

@sandbubbles
Copy link
Copy Markdown
Contributor

@sandbubbles sandbubbles commented Oct 11, 2024

What I did

fix #4232

How I did it

How to verify it

Commit message

This commit allows "compiling" `.vyi` files with ast, annotated_ast,
interface, external_interface and abi output formats. Even though they
don't produce bytecode, the above output formats can still be useful
for users and tooling (even just to validate a `.vyi` file).

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@charles-cooper charles-cooper changed the title feat[ux]: compile solely vyi feat[ux]: compile .vyi files Oct 15, 2024
@charles-cooper
Copy link
Copy Markdown
Member

looking good to me. @cyberthirst can you take a look?

@cyberthirst
Copy link
Copy Markdown
Collaborator

bit unrelated, but if an interface implements other interface and doesn't implement all the methods, we get the following exception:

vyper.exceptions.InterfaceViolation: Contract does not implement all interface functions: foobar()

Contract does not implement.. although it can be triggered via eg vyper -f abi i.vyi

@cyberthirst
Copy link
Copy Markdown
Collaborator

-f interface doesn't include Flags. is it intended?

@charles-cooper
Copy link
Copy Markdown
Member

-f interface doesn't include Flags. is it intended?

Not intended. May be the order in which we merged flag and -f interfave PRs

@cyberthirst
Copy link
Copy Markdown
Collaborator

shouldn't -f interface be basically an identity when called on interface files?

import ITest2

implements: ITest2

def bar() -> uint256:
    ...

def foo() -> uint8:
    ...


def foobar() -> uint8:
    ...

outputs:

# Functions

@external
def bar() -> uint256:
    ...


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


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

ie implements is lost in the translation

@cyberthirst
Copy link
Copy Markdown
Collaborator

shouldn't -f interface be basically an identity when called on interface files?

import ITest2

implements: ITest2

def bar() -> uint256:
    ...

def foo() -> uint8:
    ...


def foobar() -> uint8:
    ...

outputs:

# Functions

@external
def bar() -> uint256:
    ...


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


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

ie implements is lost in the translation

also, if ITest2.vyi contains a struct (or flag), then those don't propagate for -f interface - not sure whether that's intentional


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyberthirst
Copy link
Copy Markdown
Collaborator

 vyper -f external_interface tests/custom/ITest.vyi

# External Interfaces
interface Itest:
    def bar() -> uint256: nonpayable
    def foo() -> uint8: nonpayable
    def foobar() -> uint8: nonpayable

name discrepancy - Itest vs ITest

# ex: test_interface.vy -> TestInterface
name = "".join([x.capitalize() for x in stem.split("_")])

name = stem.title().replace("_", "")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about _.vyi

out = compile_code(code, contract_path="test__test.vyi", output_formats=["external_interface"])[
"external_interface"
]
assert "-> Foo:" in out
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should also check that the output compiles again (similar to a round trip)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that check for primitive types, for external interface it does not work with user defined ones.

compile_code(out, contract_path="test.vyi", output_formats=["external_interface"])


@pytest.mark.xfail
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's please link: #4290 (comment)

@charles-cooper charles-cooper changed the title feat[ux]: compile .vyi files feat[ux]: allow "compiling" .vyi files Dec 27, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) December 27, 2024 19:58
@charles-cooper charles-cooper merged commit 705aa54 into vyperlang:master Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release - must release blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vyper interface compilation

4 participants