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

Handle integer overflow/underflow for non-64-bit integers #4707

Merged
merged 3 commits into from
Jun 29, 2023

Conversation

anton-trunov
Copy link
Contributor

@anton-trunov anton-trunov commented Jun 27, 2023

fixes #4646

Description

This PR fixes the linked issue by introducing overflow/underflow checks in the Add, Mul, Sub stdlib traits implementations for the u8, u16 and u32 types.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@anton-trunov anton-trunov requested a review from a team June 27, 2023 10:27
@anton-trunov anton-trunov self-assigned this Jun 27, 2023
@vaivaswatha
Copy link
Contributor

vaivaswatha commented Jun 27, 2023

We'll probably need to do something about const_eval too

match intrinsic.kind {

The corresponding tests are in should_pass/language/const_inits.

@IGI-111
Copy link
Contributor

IGI-111 commented Jun 27, 2023

Yeah we probably need something for the const evaluations too.

Are you sure there are no missing operators, what about left shift?

@anton-trunov
Copy link
Contributor Author

We'll probably need to do something about const_eval too

Noted, will add, thanks.

Are you sure there are no missing operators, what about left shift?

Yeah, I was going to go over the logical operations as well, probably in a separate PR if any changes are required there, but it also makes sense to do it here in one go.

@anton-trunov
Copy link
Contributor Author

Ok, const_eval seems to be done. To handle const_eval, I had to cover more Sway features in it: we can now evaluate functions with bodies of length more than one and we also process let-expressions and local consts, including tracking variable scopes in code blocks.

vaivaswatha
vaivaswatha previously approved these changes Jun 28, 2023
Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

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

LGTM, but I think the logical operators should also be in this PR if necessary.

This makes me think we might want to add const fn as a language construct eventually.

@anton-trunov anton-trunov added the compiler: ir IRgen and sway-ir including optimization passes label Jun 28, 2023
@IGI-111 IGI-111 merged commit 0263c0d into master Jun 29, 2023
28 checks passed
@IGI-111 IGI-111 deleted the anton-trunov/integer-overflow branch June 29, 2023 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: ir IRgen and sway-ir including optimization passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All integers are treated a u64
3 participants