Skip to content

py/misc: Add explicit dependency on py/mpconfig.h. #17843

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

Merged
merged 1 commit into from
Aug 13, 2025

Conversation

projectgus
Copy link
Contributor

Summary

Macros in misc.h depend on values defined by including mpconfig.h (i.e. the checks for MICROPY_ROM_TEXT_COMPRESSION)

This PR makes the relationship explicit. Noticed while trying to restructure #17735.

This work was funded through GitHub Sponsors.

@projectgus projectgus added the py-core Relates to py/ directory in source label Aug 6, 2025
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@255d74b). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #17843   +/-   ##
=========================================
  Coverage          ?   98.38%           
=========================================
  Files             ?      171           
  Lines             ?    22283           
  Branches          ?        0           
=========================================
  Hits              ?    21924           
  Misses            ?      359           
  Partials          ?        0           

☔ 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.

Copy link

github-actions bot commented Aug 6, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge
Copy link
Member

I'm happy to merge this, but it feels like a layering violation. Over time this file has gained things that depend on MP configuration variables (eg float, error message compression), and perhaps that was the wrong direction to go in. I would like misc.h to be the bottom layer, independent of everything else in py/.

Do you think that's a good idea/goal? At least that way there's a good metric as to what can go in misc.h.

Or maybe that's not really possible. In that case we should remove the comment at the top of misc.h: "a mini library of useful types and functions".

@projectgus
Copy link
Contributor Author

I'm happy to merge this, but it feels like a layering violation. Over time this file has gained things that depend on MP configuration variables (eg float, error message compression), and perhaps that was the wrong direction to go in.

I think it's potentially a good goal (and actually I thought this was the case before I got a compiler error and realised it wasn't true!)

I guess the question is where the parts which do depend on config go. Quite a lot would have to be moved - one of the first sections has all of the Python heap allocator functions - some of these depend on MICROPY_MALLOC_USES_ALLOCATED_SIZE, MICROPY_TRACKED_ALLOC, and MICROPY_MEM_STATS. Next there are the string functions which partially depend on MICROPY_PY_BUILTINS_STR_UNICODE, etc, etc...

(Those dependencies aren't as obvious as the ones which fail to compile if config macros are missing, but they're still dependencies - if you put py/misc.h first in the include order then you'll currently get missing or incorrect prototypes for some functions.)

@projectgus
Copy link
Contributor Author

Thinking a bit more, we could potentially split this into something like:

  • py/c_compiler.h - has the "polyfills" for non-uniform C compiler functions like static asserts, overflow detection, etc. Depends on compiler flags but not config headers.
  • py/py_environ.h - Library of utility functions for the Python runtime environment (internal heap, float ops, basic string ops, etc). Depends on config headers.

(Names I've come up with here are not good, but I can't think of better ones right now.)

I'm not sure whether such a restructure has much long-term benefit, though.

@dpgeorge
Copy link
Member

Thinking a bit more, we could potentially split this into something like:
...
I'm not sure whether such a restructure has much long-term benefit, though.

It is a bit of effort and churn for seemingly little gain, although at the moment misc.h is a bit of a grab-bag of definitions.

Is this a blocking issue? Can we discuss it later?

@projectgus
Copy link
Contributor Author

Is this a blocking issue? Can we discuss it later?

Definitely can be left to later, but suggest we merge this now in the meantime as it makes the existing implicit relationship explicit.

Macros in misc.h depend on values defined by including mpconfig.h.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
@dpgeorge dpgeorge merged commit 744270a into micropython:master Aug 13, 2025
68 of 69 checks passed
@projectgus projectgus deleted the dep/misc_config branch August 13, 2025 00:17
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.

3 participants