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[lang]: allow hex literals for unsigned integer types #4387

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Dec 4, 2024

What I did

Resolves #4344.

How I did it

Add Hex nodes as valid literals for integers.

How to verify it

See tests.

Commit message

feat[lang]: allow hex literals for unsigned integer types

This commit adds support for hex values as unsigned integers 
by adding Hex nodes as valid literals for integers. Additional
typechecking is added to ensure that these hex values are 
of the same case, and that they cannot be used for signed
integers.

Description for the changelog

Cute Animal Picture

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

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.61%. Comparing base (794022e) to head (97feac2).

Files with missing lines Patch % Lines
vyper/codegen/expr.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4387      +/-   ##
==========================================
- Coverage   91.31%   88.61%   -2.71%     
==========================================
  Files         113      113              
  Lines       16061    16078      +17     
  Branches     2703     2708       +5     
==========================================
- Hits        14666    14247     -419     
- Misses        964     1314     +350     
- Partials      431      517      +86     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tserg tserg marked this pull request as ready for review December 5, 2024 07:16
@tserg tserg requested a review from charles-cooper December 5, 2024 07:16
@@ -2363,7 +2363,16 @@ def infer_kwarg_types(self, node):
for kwarg in node.keywords:
kwarg_name = kwarg.arg
validate_expected_type(kwarg.value, self._kwargs[kwarg_name].typ)
ret[kwarg_name] = get_exact_type_from_node(kwarg.value)
if kwarg_name == "method_id":
Copy link
Member

Choose a reason for hiding this comment

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

maybe out-of-scope but it would be much better for validate_expected_type to return the type it inferred

Copy link
Collaborator Author

@tserg tserg Dec 5, 2024

Choose a reason for hiding this comment

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

I think I/we have tried this a few times before without completing it 😄

@@ -171,6 +171,13 @@ def hello() :
""",
ImmutableViolation,
),
(
# hex values not allowed for signed integer types
Copy link
Member

Choose a reason for hiding this comment

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

might be ok to allow this actually

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hm if we allow hex literals for unsigned and signed ints, should we disallow folding involving any hex integer? since we do not know at the time of folding if a hex value should be interpreted as a signed integer or an unsigned integer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but I think excluding hex literals during folding would not work either because it would break things downstream where we expect a literal value during typechecking

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what if we make the syntax more explicit like native hex bytes? e,g, unsigned hex integers would be u"0xff" and signed hex integers would be i"0xff".

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.

Allow use of hex literals for uint types
2 participants