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

fix: update upper bound for signed integers in min and max folding #3288

Merged
merged 12 commits into from
Mar 6, 2023

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Feb 17, 2023

What I did

Fix #3284.

How I did it

Update the bound to int256, which is >= 2 ** 255.

How to verify it

See tests.

Commit message

fix: update upper bound for signed integers in `min` and `max` folding

Description for the changelog

Update upper bound for signed integers in min and max folding

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2023

Codecov Report

Merging #3288 (a6013db) into master (d320b80) will increase coverage by 0.06%.
The diff coverage is 85.71%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #3288      +/-   ##
==========================================
+ Coverage   88.86%   88.92%   +0.06%     
==========================================
  Files          84       84              
  Lines       10597    10605       +8     
  Branches     2213     2215       +2     
==========================================
+ Hits         9417     9431      +14     
+ Misses        770      768       -2     
+ Partials      410      406       -4     
Impacted Files Coverage Δ
vyper/builtins/functions.py 90.73% <80.00%> (+0.30%) ⬆️
vyper/semantics/analysis/local.py 91.36% <100.00%> (+0.05%) ⬆️
vyper/codegen/core.py 86.74% <0.00%> (+0.04%) ⬆️
vyper/semantics/analysis/module.py 86.29% <0.00%> (+0.06%) ⬆️
vyper/ast/nodes.py 94.10% <0.00%> (+0.31%) ⬆️
vyper/ast/folding.py 93.27% <0.00%> (+0.53%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

"""
@external
def foo():
a: int256 = min(-1, max_value(int256) + 1)
Copy link
Member

Choose a reason for hiding this comment

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

this fails for a different reason, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It fails on the same branch:

if isinstance(left, int) and (min(left, right) < 0 and max(left, right) >= 2 ** 255):
raise TypeMismatch("Cannot perform action between dislike numeric types", node)

Although max_value(int256) + 1 is out of bounds, it is currently not type-checked before folding so it is not flagged as an error. Therefore, this slightly modified example would also compile:

@external
def foo():
    a: int248 = min(1, max_value(int248) + 1)

Copy link
Member

Choose a reason for hiding this comment

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

the example is a bit confusing tbh because the operands are not really valid to begin with. and i'm realizing the fix itself does not block examples which are in the int255 range but do not typecheck, like:

min( min_value(int16)/*type: int16*/, max_value(int8)/*type: int8*/)

can we use get_common_types here like other builtins which deal with numeric literals? i think that can fix the typechecking issue.

Copy link
Member

Choose a reason for hiding this comment

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

i guess, if/when we move constant folding after typechecking this will be moot and we can remove the checks inside of the evalute implementations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the example is a bit confusing tbh because the operands are not really valid to begin with.

I have moved this test to #3201 instead. I think that PR is more relevant for addressing these cases.

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.

Incorrect TypeMismatch for _MIN_MAX with certain signed types
4 participants