message consolidation and more use of validators#6409
message consolidation and more use of validators#6409dhalbert merged 3 commits intoadafruit:mainfrom
Conversation
gamblor21
left a comment
There was a problem hiding this comment.
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. |
jepler
left a comment
There was a problem hiding this comment.
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. |
tannewt
left a comment
There was a problem hiding this comment.
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_raisecalls, and used validators fromargcheck.cto 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 raisesValueErrorwith 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()%qargs 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
_bleiomessages, 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.potwent from 1061 to 989.