Skip to content

Conversation

@dpgeorge
Copy link
Member

Summary

This PR cleans up a few header declarations:

  • removes unused CHECKBUF macros (they were last used 9.5 years ago...!)
  • moves some tuple, list, fun and module helper function declarations from py/obj.h to specific headers like py/objtuple.h (because they are internal helpers more than general API functions)
  • renames mp_obj_fun_get_name() to mp_obj_fun_bc_get_name() and changes the argument signature to make it clear what the argument must be

Then it makes some tuple and list functions inline. That's only possible because their declarations were moved to their respective headers (py/objtuple.h and py/objlist.h). This reduces code size by 50 to 100 bytes, which is a pretty nice saving.

Testing

Built locally. Will also be built and tested by CI.

Trade-offs and Alternatives

There is a little bit of code churn here, but IMO it's worth it to get the code size savings.

Renaming mp_obj_fun_get_name() to mp_obj_fun_bc_get_name() is also arguably not necessary, but I doubt this is ever used by anyone, it's really an internal helper that shouldn't be used externally to the code in py/.

These macros were added in e11b17c for
use with `sys.path` and building import path names, as well as being used
by the unix port in 625d08a.

But the macro usage for importing was promptly replaced with vstrs in
e09ffa1, and eventually for the unix port
in 520f356, over 9.5 years ago.

So, remove these unused macros.

Signed-off-by: Damien George <damien@micropython.org>
This inline helper function has two specific uses so doesn't need to be
generally available in `py/obj.h`.

Signed-off-by: Damien George <damien@micropython.org>
This is an internal helper function that assumes the argument is of type
`mp_obj_fun_bc_t`, so has a better home in `py/objfun.h`.

Signed-off-by: Damien George <damien@micropython.org>
And change the argument to `const mp_obj_fun_bc_t *`.  This makes it clear
that it requires that specific type, rather than a general `mp_obj_t`.

Signed-off-by: Damien George <damien@micropython.org>
These helper functions assume their argument is of type `mp_obj_list_t` so
they have a better home in `py/objlist.h`.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Jan 25, 2026
@dpgeorge dpgeorge force-pushed the py-clean-up-some-header-decls branch from 3b13d93 to f924983 Compare January 25, 2026 13:23
@github-actions
Copy link

github-actions bot commented Jan 25, 2026

Code size report:

Reference:  github: Install Python 3.11 for Windows CI runs. [f1363d8]
Comparison: py/objtuple: Make mp_obj_tuple_get an inline function. [merge of 3bc9eac]
  mpy-cross:  -160 -0.042% 
   bare-arm:   -60 -0.106% 
minimal x86:  -263 -0.140% 
   unix x64:  -288 -0.034% standard
      stm32:   -96 -0.024% PYBV10
      esp32:   +48 +0.003% ESP32_GENERIC
     mimxrt:  -120 -0.032% TEENSY40
        rp2:   -48 -0.005% RPI_PICO_W
       samd:  -104 -0.038% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:   -86 -0.019% VIRT_RV32

This can be done now these functions are declared in `py/objlist.h`, where
the `mp_obj_list_t` struct is defined.

This changes code size by -24 bytes on bare-arm, and by -56 bytes on stm32.

Signed-off-by: Damien George <damien@micropython.org>
These helper functions assume their argument is of type `mp_obj_tuple_t` so
they have a better home in `py/objtuple.h`.

Also remove `mp_obj_tuple_hash()` because it doesn't have a corresponding
function defined anywhere (nor is it ever used).

Signed-off-by: Damien George <damien@micropython.org>
This can be done now that it's declared in `py/objtuple.h`, where the
`mp_obj_tuple` struct is defined.

This allows much better code generation for users of `mp_obj_tuple_get()`
where the caller uses len/items immediately (which is most uses), because
the compiler no longer needs to allocate the return values on the stack.

Changes code size by -36 bytes on bare-arm and -56 bytes on stm32.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the py-clean-up-some-header-decls branch from f924983 to 3bc9eac Compare January 25, 2026 13:57
@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (f1363d8) to head (3bc9eac).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18725   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      174    +3     
  Lines       22298    22298           
=======================================
  Hits        21937    21937           
  Misses        361      361           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant