-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
message consolidation and more use of validators #6409
Conversation
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.
Great work! I had one comment where I think an if
may still be able to be removed but I may be wrong. I didn't see anywhere else where the values changed.
I wonder if there may be a few new questions where it does not say why a pin is invalid (e.g. not a DAC pin) and now just says invalid. But probably worth the space savings.
If you look at the backtrace and the line in question, I think it will be clear it's invalid because of the context. There were already cases where the messages just said "Invalid pin" without further explanation; this just takes advantage of regularizing that. |
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.
Thanks! I think it could go in just like this, but there are a few items I spotted along the way.
With the latest round of changes, Trinket M0 is now up to 544 bytes saved. |
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.
Awesome work! Let's merge this and tag 8.0.0-alpha.0 since it changes some exception types.
I agree. Then we can merge the postponed 8.0.0 PR's, and implement the hanging 8.0.0 issues. |
Closes #6392.
To reduce firmware size, this PR uses argument validators where possible and consolidates and simplifies various error messages.
mp_raise
calls, and used validators fromargcheck.c
to simplify the validation. A few new validators were added, building on keypad: support for vector and matrix key scanning #4891.mp_arg_error_invalid(qstr)
, which raisesValueError
with the message"Invalid %q"
. This is useful many places, where there were previously more specialized but not necessarily more informative messages. Then also addedraise_ValueError_invalid_pin()
andraise_ValueError_invalid_pins()
, which refactormp_arg_error_invalid(MP_QSTR_pin)
andmp_arg_error_invalid(MP_QSTR_pins)
, both of which are very common (a couple dozen uses each).extmod/vfs_fat.c
: refactor multiple identical calls tomp_raise_OSError()
ps2io
: regularize usingclock*
instead ofclk*
, to make argument names and internal names more consistent.mp_raise_NotImplementedError()
%q
args to refactor and share some messages.m_malloc_fail()
instead of more chatty specialized messages which were not necessarily more helpful. Thanks @tannewt for pointing this routine out.PixelBuf.c
: refactor some identical error messages to reduce code size.I did not try to squeeze the last drop out of various
_bleio
messages, since we are not short on code space in those builds, and the savings would be minimal.Some initially measured byte savings (current savings are a few bytes more than this due to further changes):
I think some of the larger differences here are because some builds are not using LTO.
The number of distinct messages in
circuitpython.pot
went from 1061 to 989.