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

[draft] refactor: constant folding #1

Conversation

charles-cooper
Copy link

What I did

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-->

tserg and others added 4 commits January 7, 2024 18:37
this commit changes the vyper language to require type annotations for
loop variables. that is, before, the following was allowed:
```vyper
for i in [1, 2, 3]:
    pass
```

now, `i` is required to have a type annotation:
```vyper
for i: uint256 in [1, 2, 3]:
    pass
```

this makes the annotation of loop variables consistent with the rest of
vyper (it was previously a special case, that loop variables did not
need to be annotated).

the approach taken in this commit is to add a pre-parsing step which
lifts out the type annotation into a separate data structure, and then
splices it back in during the post-processing steps in
`vyper/ast/parse.py`.

this commit also simplifies a lot of analysis regarding for loops.
notably, the possible types for the loop variable no longer needs to be
iterated over, we can just propagate the type provided by the user. for
this reason we also no longer need to use the typechecker speculation
machinery for inferring the type of the loop variable. however, the
NodeMetadata code is not removed because it might come in handy at a
later date.

---------

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
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.

2 participants