Skip to content

gh-145497: Compute static builtin type count at compile time via X-macro#151004

Open
corona10 wants to merge 1 commit into
python:mainfrom
corona10:gh-145497
Open

gh-145497: Compute static builtin type count at compile time via X-macro#151004
corona10 wants to merge 1 commit into
python:mainfrom
corona10:gh-145497

Conversation

@corona10
Copy link
Copy Markdown
Member

@corona10 corona10 commented Jun 6, 2026

@corona10
Copy link
Copy Markdown
Member Author

corona10 commented Jun 6, 2026

@encukou @vstinner
I believe this is a clearer way to manage the list of types, since the number of types is calculated automatically once the types are registered.

@corona10 corona10 added the build The build process and cross-build label Jun 6, 2026
Comment thread Objects/object.c
// All other static types (unless initialized elsewhere)
for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
PyTypeObject *type = static_types[i];
if (type == NULL) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need anymore

Comment thread Objects/object.c
// their base classes.
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_types)-1; i>=0; i--) {
PyTypeObject *type = static_types[i];
if (type == NULL) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@corona10
Copy link
Copy Markdown
Member Author

corona10 commented Jun 6, 2026

cc @ZeroIntensity Do you have interested in this change?

@corona10 corona10 changed the title gh-145497: Compute static builtin type count at compile time gh-145497: Compute static builtin type count at compile time via X-macro Jun 6, 2026
@corona10 corona10 added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed build The build process and cross-build labels Jun 6, 2026
@bedevere-bot
Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @corona10 for commit 21952b5 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F151004%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 6, 2026
Copy link
Copy Markdown
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping. What's the net benefit here? #149139 added a test that prevents us from breaking _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES in the future. I'm a little concerned that we're making things worse by adding macro gymnastics.

I think a simpler approach would be to continue using multiple static-type arrays, but export their lengths as static variables and compute _Py_MAX_MANAGED_STATIC_TYPES as the sum of their lengths. Then, we just create static_types in _PyTypes_InitTypes instead of doing it statically.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of moving all static types to their own header file. I think it makes it harder to track down where static types are being defined, because it separates the code from the definition.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants