Skip to content

Consider removing some unused build flags #144228

@johnslavik

Description

@johnslavik

Description

Tripped up by --with-readline in our configure file while debugging GH-142353, I was curious if we have any other unused build flags.

Removing them could slightly shorten preprocessing work, reduce cognitive load when debugging platform‑specific issues, and reduce the risk of accidentally relying on dead configuration paths.

After running make regen-configure, I put together this script with ripgrep:

# t.sh
FLAGS="$(rg '#\s*define\s+(\w+)' -g pyconfig.h -g pyconfig.h.in -or '$1' --no-line-number --no-filename)"
for flag in $FLAGS
do    
    rg "\b$flag\b" -g !pyconfig.h -g !pyconfig.h.in . --stats | rg '\b0 matches' -r "$flag"
done

Then I ran this command:

bash t.sh | sort | uniq

I got the following results:

Expand results
DIRENT
DONT_HAVE_SIG_ALARM
DONT_HAVE_SIG_PAUSE
HAVE_ACOSH
HAVE_ASINH
HAVE_ATANH
HAVE_ERF
HAVE_ERFC
HAVE_EXPM1
HAVE_INTPTR_T
HAVE_LIBSOCKET
HAVE_LOG1P
HAVE_LOG2
HAVE_PUTENV
HAVE_STRERROR
HAVE_UINTPTR_T
HAVE_X509_VERIFY_PARAM_SET1_HOST
Py_CONFIG_H
Py_NTDDI
_Py_PASTE_VERSION
Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
_Py_STRINGIZE
_Py_STRINGIZE1
SIZEOF_HKEY
USE_SOCKET
_W64
WITH_READLINE
WORD_BIT

These macros are not referenced by any CPython source files outside configuration headers (pyconfig.h, PC/pyconfig.h and pyconfig.h.in files) and are not part of the documented public API.

A few of them are actually used and cannot be removed. Most of them, however, weren't used in years (or decades) and appear to be safely removable, because they no longer affect the behavior of Python.

Here's what I found about every single one of them.

PC/pyconfig.h and pyconfig.h

  • HAVE_ERF, HAVE_ERFC

    Unused since 5839575.

PC/pyconfig.h

pyconfig.h

  • HAVE_ACOSH, HAVE_ASINH, HAVE_ATANH, HAVE_EXPM1, HAVE_LOG1P

    Unused since fa26245.

  • HAVE_LOG2

    Unused since 5839575.

Ambiguous

Not touching these before I get additional feedback.
Consider them out of the scope of my proposal for now!

  • HAVE_INTPTR_T, HAVE_UINTPTR_T (PC/pyconfig.h)

    Added in fe393f4, never used since. Maybe it's intentionally reserved for future use?

    cc: @zooba, @loewis, can this be removed?

  • Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE (PC/pyconfig.h)

    Allowing this seems to have caused a stack corruption fixed in aa26b27. Since the fix, the flag has not been used.

    cc: @zooba, @cf-natali, can this be removed?

  • WORD_BIT (PC/pyconfig.h)

    Standardized by POSIX.1 (IEEE Std 1003.1).

    Not sure if it should be in PC/.
    Maybe it is used downstream?

    cc: @zooba, @mhammond, do we need this in PC/pyconfig.h?

Still used or won't fix

  • Py_CONFIG_H (PC/pyconfig.h)

    This was identified by the script, but it's an include guard.

  • _W64 (PC/pyconfig.h)

    Used in PC/pyconfig.h to define Py_ssize_t.

  • Py_NTDDI (PC/pyconfig)

    Used for defining NTDDI_VERSION.

  • _Py_PASTE_VERSION (PC/pyconfig.h)

    Used for defining _Py_COMPILER.

  • _Py_STRINGIZE, _Py_STRINGIZE1 (PC/pyconfig.h)

    I'd not touch these, as they are used for defining _Py_COMPILER.
    These correspond to Py_STRINGIFY and _Py_XSTRINGIFY from the pymacro.h header.
    Making PC/pyconfig.h include pymacro.h just for Py_STRINGIFY doesn't seem like a sensible option.

Conclusion

I'm going to start from PRs one per every item (grouping one or more related macros) in the bullet lists of flags certainly removable.

Going forward, I'll appreciate feedback about the ambiguous flags or any things that I've overlooked.

Are there any flags listed for removal that still have known downstream or platform‑specific uses? I pinged some changeset authors to help decide the most ambiguous cases.

Finally, I considered adding automated checks for unused configuration macros, but given the amount of variables involved, this seems non-trivial and not worth it.

Thanks for reading through all of this!

cc @vstinner @encukou I think you will have useful insights into this one.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions