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

Add the int256 signed integer type #2351

Merged
merged 16 commits into from
Apr 15, 2021

Conversation

iamdefinitelyahuman
Copy link
Contributor

What I did

Add the int256 type.

How I did it

  1. In context, I've added a new type primitive and definition for int256. I also expanded the abstract numeric types to make it easier to support e.g. any signed integer type when dealing with builtin function inputs.
  2. In functions, I've modified the expected input types using the new absract types. Any function that previously expected int128 can now receive both int128 and int256. This required a bit of weirdness in the abstract types so as to not rekt the old type system - I left a comment explaining what's happening, as types are removed from parser we'll eventually be able to remove that code.
  3. To make it work in parser I mostly removed type logic. I can into an issue around literals where anything that could be cast as int128 was cast as such. The best fix I found was to do away with parser-level type checking and just assume that if we made it this far, numeric types are allowed to interact. Where things got strange I left comments. It's again a case of, until types are fully removed from parser we need to be a bit hacky to make the old and new systems play nicely together.

Overflow checks for int256 math operations are consistent with those used in OpenZeppelin's SignedSafeMath library.

Note that anywhere I removed a parser-level type check, I verified that the check is actually happening within context and that the check was not being reached in coverage reports. We've had context in place for almost a year now, I feel pretty OK with trusting it and removing these redundant checks.

How to verify it

Run the test suite. I've added test cases around int256 math, unary operations, and using convert to move into and out of the new type.

Cute Animal Picture

image

vyper/compile_lll.py Show resolved Hide resolved
vyper/functions/convert.py Show resolved Hide resolved
@fubuloubu fubuloubu assigned fubuloubu and unassigned fubuloubu Apr 14, 2021
@fubuloubu fubuloubu self-requested a review April 14, 2021 14:44
@michwill
Copy link

🚀

@fubuloubu fubuloubu merged commit b455c18 into vyperlang:master Apr 15, 2021
@iamdefinitelyahuman iamdefinitelyahuman deleted the feat-int256 branch April 15, 2021 22:30
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.

3 participants