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

feat: bitwise not and xor for enums #2925

Merged
merged 17 commits into from
Jun 23, 2022

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Jun 20, 2022

What I did

How I did it

How to verify it

see tests

Commit message

add bitwise not and bitwise xor ops for enums. note that the
implementation uses xors with a special mask to avoid flipping upper
bits that do not belong to the enum (ex. using the `not` opcode on an
enum with 5 members does not make sense, because the 6th and higher bits
would get flipped to 1, which is out of bounds for the enum).

also, allow 0 as a valid enum value (this makes sense because storage
slots are 0 by default, and we have to assume that any storage slot with
type `MyEnum` is a valid enum value. in other words, `empty(Type)` is a
member of `Type` for any `Type`).

lastly, fix codegen for `not in` enum - it was being incorrectly handled
the same as `in`.

Description for the changelog

add bitwise not and xor operators for enums.

Cute Animal Picture

image

@codecov-commenter
Copy link

codecov-commenter commented Jun 20, 2022

Codecov Report

Merging #2925 (b2c0575) into master (1e5770c) will decrease coverage by 0.11%.
The diff coverage is 67.34%.

@@            Coverage Diff             @@
##           master    #2925      +/-   ##
==========================================
- Coverage   88.34%   88.22%   -0.12%     
==========================================
  Files          97       97              
  Lines       10739    10772      +33     
  Branches     2555     2565      +10     
==========================================
+ Hits         9487     9504      +17     
- Misses        797      809      +12     
- Partials      455      459       +4     
Impacted Files Coverage Δ
vyper/ir/optimizer.py 95.01% <ø> (ø)
vyper/builtin_functions/functions.py 91.14% <35.71%> (-1.27%) ⬇️
vyper/semantics/types/user/enum.py 80.30% <50.00%> (+0.30%) ⬆️
vyper/codegen/expr.py 84.36% <76.47%> (-0.17%) ⬇️
vyper/ast/nodes.py 93.43% <85.71%> (-0.23%) ⬇️
vyper/codegen/core.py 84.87% <100.00%> (-0.06%) ⬇️
vyper/semantics/types/value/numeric.py 85.05% <0.00%> (+4.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e5770c...b2c0575. Read the comment docs.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 20, 2022

This pull request introduces 1 alert when merging 3037562 into 9a363dc - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times

@charles-cooper charles-cooper changed the title bitwise not and xor for enums feat: bitwise not and xor for enums Jun 21, 2022
@charles-cooper charles-cooper marked this pull request as ready for review June 21, 2022 15:21
@charles-cooper charles-cooper enabled auto-merge (squash) June 23, 2022 13:31
@charles-cooper charles-cooper merged commit a261014 into vyperlang:master Jun 23, 2022
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