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

wip: implement methods for structs #4041

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

charles-cooper
Copy link
Member

What I did

just messing around, opening the PR so others can follow progress

How I did it

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

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

from vyper.codegen.core import _freshname, eval_once_check, make_setter
from vyper.codegen.ir_node import IRnode
from vyper.evm.address_space import MEMORY
from vyper.exceptions import StateAccessViolation
from vyper.semantics.types.function import MemberFunctionT

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.types.function
begins an import cycle.
@@ -19,6 +19,7 @@
from vyper.semantics.analysis.utils import check_modifiability, validate_expected_type
from vyper.semantics.data_locations import DataLocation
from vyper.semantics.types.base import VyperType
from vyper.semantics.types.function import MemberFunctionT

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.types.function
begins an import cycle.
test contract:
```
struct Foo:
    user: address
    balance: uint256

    def decrement_balance(self, amount: uint256):
        self.balance -= amount

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)
```
@fubuloubu
Copy link
Member

A few examples of the intended use might be nice to see for commenting on the implementation

@charles-cooper
Copy link
Member Author

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@fubuloubu
Copy link
Member

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)

s is only in memory because decrement_balance is a mutable call? would it make sense to have a decorator or additional syntax that delineated view from mutable calls? (or maybe the opposite, @view can be applied to make it non-mutable, which means you can execute this function on f even though it's in calldata)

@charles-cooper
Copy link
Member Author

charles-cooper commented May 22, 2024

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)

s is only in memory because decrement_balance is a mutable call? would it make sense to have a decorator or additional syntax that delineated view from mutable calls? (or maybe the opposite, @view can be applied to make it non-mutable, which means you can execute this function on f even though it's in calldata)

i thought about it, i think additional syntax is overkill. it depends more just on the location of the item, like if you can do s.balance -= 1 you can do s.decrement_balance(1)

@fubuloubu
Copy link
Member

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)

s is only in memory because decrement_balance is a mutable call? would it make sense to have a decorator or additional syntax that delineated view from mutable calls? (or maybe the opposite, @view can be applied to make it non-mutable, which means you can execute this function on f even though it's in calldata)

i thought about it, i think additional syntax is overkill. it depends more just on the location of the item, like if you can do s.balance -= 1 you can do s.decrement_balance(1)

so you would be able to call a non-mutable method on f? that's perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants