-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Fix more operations that can return small ints #17785
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17785 +/- ##
==========================================
- Coverage 98.39% 98.37% -0.02%
==========================================
Files 171 171
Lines 22257 22265 +8
==========================================
+ Hits 21899 21904 +5
- Misses 358 361 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
Signed-off-by: Jeff Epler <jepler@gmail.com>
Since adafruit#9531 a few ways remained to produce long ints that were not reduced to small ints. Explicitly introduce "mp_obj_new_long_from_ll" and make the "new_int" functions always produce small ints when possible. At sites where a long int is really intended (or will eventually be reduced to a small int if the result fits), the called function is changed to be the new _long_ function. Signed-off-by: Jeff Epler <jepler@gmail.com>
Signed-off-by: Jeff Epler <jepler@gmail.com>
the nrf port is failing due to a "403 Forbidden" error downloading some files from nordic:
furthermore, the failure is not detected at the time, but the build continues until this message is shown
with any luck this is a transient error and nordic will fix the download link. |
The same error popped up at PR #17365. |
CircuitPython GitHub actions builds are also seeing this. It looks like |
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 looks good to me, thanks @jepler.
I tried to think of ways to combine mp_obj_new_int
, mp_obj_new_int_from_ll
, and mp_obj_new_int_from_ull
into a single inner static implementation but they were all going to involve some level of compiler crimes I think. 😆
I've linked this PR to close the issue as IIUC it addresses everything enumerated there, but let me know if I'm missing a case.
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a multi-precision integer object (or raise an overflow exception) | ||
mp_obj_t mp_obj_new_int_from_ll(long long val); // returns a small int if value fits | ||
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // returns a small int if value fits | ||
mp_obj_t mp_obj_new_long_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception) |
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 fully separate to this PR, but at some point we should probably rename all the longint
references in MicroPython to bigint
to avoid this ambiguity about what long
means.
Summary
#17730 identified some code paths that could still return long ints when small ints would suffice. Fix them.
Testing
I wrote a new test based on sites that called new_int_from_{u,}ll, including the case I'd noticed of pow3 (already reported in #9531 as well).
Trade-offs and Alternatives
I haven't seen the code size change summary yet, but this is likely to increase code size. I'm open to suggestions about how to reduce the increase.
Making the new
long_from
functions always return longs, and changing the existingnew_int_from
functions to return ints when possible is just one alternative. Another alternative would be to add calls tomp_int_maybe_narrow
in paths that usednew_int_from
, but this seemed like the worse alternative, with more added code.