Repository navigation
[mypyc] Generate lowered IR for abs() on native ints - #22499
Merged
Merged
Conversation
Generate lowered IR for native integer abs() with a generic primitive op, int_abs, that gets lowered via @lower_primitive_op in mypyc/lower/int_ops.py, kind of like vec_get_item_unsafe_op. Before, mypyc converted the value to a tagged int, called CPyTagged_Absolute and converted the result back. abs() of the minimum value of a signed type, such as abs(i8(-128)), now overflows like -x instead of raising ValueError. mypyc/doc/int_operations.rst says operations between native integer types don't check for overflow, and there's no run test for -x overflow either, so I didn't add one for abs().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #22367, as suggested in #22367 (comment).
This generates lowered IR for native integer
abs()with a generic primitive op,int_abs, that gets lowered via@lower_primitive_opinmypyc/lower/int_ops.py(kind of likevec_get_item_unsafe_op). Before, mypyc converted the value to a tagged int, calledCPyTagged_Absoluteand converted the result back.abs()of the minimum value of a signed type, such asabs(i8(-128)), now overflows like-xinstead of raisingValueError.mypyc/doc/int_operations.rstsays operations between native integer types don't check for overflow, and there's no run test for-xoverflow either, so I didn't add one forabs().The new lowering tests fail on master.