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

Disallow use of None, disallow use of del, implemented clear() built-in function. #1106

Merged
merged 12 commits into from
Dec 13, 2018

Conversation

jakerockland
Copy link
Contributor

@jakerockland jakerockland commented Nov 28, 2018

- What I did

Implemented #539. Disallow use of None at the syntax level and implemented a built-in function clear().

- How I did it

Created special self-modifying statement function within stmt.py, updated tests that were previously using assignment to None, added comprehensive tests to test_clear.py.

- How to verify it

Added comprehensive tests, all that needs to be done is:

make test

- Description for the changelog

Disallow use of None, disallow use of del, implemented clear() built-in function.

- Cute Animal Picture

image

vyper/parser/stmt.py Outdated Show resolved Hide resolved
@jakerockland
Copy link
Contributor Author

@fubuloubu @jacqueswww Quick question: Is the description of handling the replacement for None within structs as described by @fubuloubu in #539 something that should be implemented with this PR?

If no, I believe that this PR is basically ready for review. There are some minor things we would have to either adjust with test_maps.py to remove the test that uses the None syntax, and some other minor clean up.

If yes, I have been doing a bit of diving into the solution for that but probably have a couple more questions 😅

@fubuloubu
Copy link
Member

@jakerockland I don't think you should implement that suggestion as it's a little bit "magical". It should be a further suggestion explored in a different VIP.

@fubuloubu
Copy link
Member

Also, correct me if I'm wrong, but I think del struct was decided to use reset(struct) instead to make it clearer the resulting type was not None as one would expect in Python

@jakerockland jakerockland changed the title WIP: Disallow assignment to None Disallow assignment to None Nov 29, 2018
@jakerockland jakerockland changed the title Disallow assignment to None Disallow use ofNone, implemented reset() built-in function. Nov 29, 2018
@jakerockland jakerockland changed the title Disallow use ofNone, implemented reset() built-in function. Disallow use of None, implemented reset() built-in function. Nov 29, 2018
Fixed test name

Basic implementation of reset() functionality

Catch use of None at pre-parser stage

Reset from both memory and storage

Removed unnecessary usage of None in other tests and added more testing for usage of None

Reworked approach to implementing reset function, updated tests

Refactored, finished testing suite

Make the linter happy

Disallow use of None at a syntax level, implement build-in reset() function
@jakerockland
Copy link
Contributor Author

@fubuloubu @jacqueswww Squashed my commits here, I believe this one is ready for review!

@@ -49,6 +52,9 @@ def pre_parse(code):
# Prevent semi-colon line statements.
elif (token.type, token.string) == (OP, ";"):
raise StructureException("Semi-colon statements not allowed.", token.start)
# Prevent use of None literal
Copy link
Member

@charles-cooper charles-cooper Nov 29, 2018

Choose a reason for hiding this comment

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

This blocks None at the tokenization stage, but a user might want to make a contract or function named None (weird, I know). I'm thinking this exception should be moved to a later stage - https://github.com/ethereum/vyper/blob/921bb80cf59c9be0067ed20e1a7b6ad0b59598b3/vyper/parser/expr.py#L147.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@charles-cooper Yeah so that's actually intentional haha. 😅I previously had this set up to block at a later stage, when checking assignments or comparisons. Refactored though because it just generally seems like something to prevent a user from doing even if they want to, because it is confusing given that Vyper is based mostly on Python's syntax and would allow for potentially very misleading code (where one thinks a custom type or custom struct named None is the Python None but its actually some custom thing called None.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the best thing in that case would be if we just add None as 'n reserved keyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jacqueswww That makes sense, just pushed a commit that implements that approach instead.

@@ -235,7 +251,10 @@ def call(self):
)
if isinstance(self.stmt.func, ast.Name):
if self.stmt.func.id in stmt_dispatch_table:
return stmt_dispatch_table[self.stmt.func.id](self.stmt, self.context)
if self.stmt.func.id == 'reset':
Copy link
Member

Choose a reason for hiding this comment

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

This seems interesting .. why not just put the implementation in the dispatch table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@charles-cooper Doesn't work without serious refactoring given that the reset() function self-mutates its input stmt, which is different than all the other functions in the stmt_dispatch_table.

@jakerockland
Copy link
Contributor Author

One open question here is if reset() should be named clear().

@jakerockland
Copy link
Contributor Author

One open question here is if reset() should be named clear(), relevant for #1076 convo.

@fubuloubu
Copy link
Member

Oh, I quite like clear()!

@jakerockland jakerockland changed the title Disallow use of None, implemented reset() built-in function. Disallow use of None, implemented clear() built-in function. Nov 30, 2018
@jakerockland jakerockland changed the title Disallow use of None, implemented clear() built-in function. Disallow use of None, disallow use of del, implemented clear() built-in function. Dec 3, 2018
@jakerockland
Copy link
Contributor Author

@jacqueswww Updated this PR to disallow usage of del per our convo this morning.

@jakerockland
Copy link
Contributor Author

@jacqueswww Updated this branch to use the new struct syntax in testing and resolved merge conflicts.

@jakerockland
Copy link
Contributor Author

@jacqueswww I'm a bit confused why Travis is failing with:

The command "python setup.py test" exited with 1.

It doesn't seem relevant to the changes made in this PR, guessing something with Travis config may have gotten borked?

@jacqueswww
Copy link
Contributor

Strange indeed.

@jakerockland
Copy link
Contributor Author

jakerockland commented Dec 7, 2018

@jacqueswww Seems like it also isn't just an issue with this branch, #1125 seems to be failing for the same reason 😓

Is it possible to just trigger a re-build on Travis?

@jakerockland
Copy link
Contributor Author

@jacqueswww HAZAH! Travis seems to be happily working now and also updated to work with some upstream changes that have happened since last update.

Copy link
Contributor

@jacqueswww jacqueswww left a comment

Choose a reason for hiding this comment

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

vyper/utils.py Outdated
@@ -148,7 +148,7 @@ def in_bounds(cls, type_str, value):
'pass', 'def', 'push', 'dup', 'swap', 'send', 'call',
'selfdestruct', 'assert', 'stop', 'throw',
'raise', 'init', '_init_', '___init___', '____init____',
'true', 'false', 'self', 'this', 'continue',
'true', 'false', 'self', 'this', 'continue', 'none',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should clear become a reserved keyword?

Copy link
Member

Choose a reason for hiding this comment

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

Yup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed a PR that added clear as a reserved word and added a entry to changelog.

@jacqueswww jacqueswww merged commit 17a4f43 into vyperlang:master Dec 13, 2018
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.

4 participants