-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
fix: folding of bitwise not literals #3222
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3222 +/- ##
===========================================
+ Coverage 72.73% 88.87% +16.14%
===========================================
Files 84 84
Lines 10580 10589 +9
Branches 2139 2208 +69
===========================================
+ Hits 7695 9411 +1716
+ Misses 2271 769 -1502
+ Partials 614 409 -205
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
If |
let's worry about that later! |
vyper/ast/nodes.py
Outdated
_op = operator.inv | ||
|
||
def _op(self, value): | ||
return (2 ** 256 - 1) - value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only valid for uint256 btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's going to be clearer imo as
return (2 ** 256 - 1) - value | |
return (2 ** 256 - 1) ^ value |
the xor reflects what's going on with the bits. it's also going to generalize to other integer types a bit better. @tserg what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I started with a xor mask before changing to its current form to match what was already in vyper.utils
.
What I did
Fix #3218.
How I did it
Reuse
(2 ** 256 - 1) - value
fromBitwiseNot
instead ofoperator.inv
, which can return a negative number.How to verify it
See updated tests.
Commit message
Description for the changelog
Fix folding of bitwise not literals.
Cute Animal Picture