-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Our internal headers are far too interlinked #131238
Comments
One solution to reduce dependencies would be to convert some
In Python 3.11,
In Python 3.12, it's no longer the case:
But there is still code which access the
|
The problem is that the structs and functions are mixed together, which means that any function that refers to a struct in another file introduces cycles. Breaking the headers in struct and function pairs breaks most of the dependencies |
Another problem is that the |
* Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h * Removes many cross-header dependencies
Convert static inline functions to functions: * _Py_IsMainThread() * _PyInterpreterState_Main() * _Py_IsMainInterpreterFinalizing() * _Py_GetMainConfig()
Convert static inline functions to functions: * _Py_IsMainThread() * _PyInterpreterState_Main() * _Py_IsMainInterpreterFinalizing() * _Py_GetMainConfig()
* Remove includes from pycore_pystate.h: * pycore_runtime_structs.h * pycore_runtime.h * pycore_tstate.h * pycore_interp.h * Reorganize internal headers. Move _gc_thread_state from pycore_interp_structs.h to pycore_tstate.h. * Add pycore_typeobject.h internal header. * Add 3 new header files to PCbuild/pythoncore.vcxproj
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
…1198) This is missing `_PyReftracerTrack` calls, see pythongh-131238. Merging as-is for the 3.14.0a6 release.
* Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h * Removes many cross-header dependencies
…ython#131352) Convert static inline functions to functions: * _Py_IsMainThread() * _PyInterpreterState_Main() * _Py_IsMainInterpreterFinalizing() * _Py_GetMainConfig()
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
@markshannon: Are you done with your changes? (Can I mark my PR as ready for review?) |
* Remove includes from pycore_pystate.h: * pycore_runtime_structs.h * pycore_runtime.h * pycore_tstate.h * pycore_interp.h * Reorganize internal headers. Move _gc_thread_state from pycore_interp_structs.h to pycore_tstate.h. * Add 3 new header files to PCbuild/pythoncore.vcxproj
* Remove includes from pycore_pystate.h: * pycore_runtime_structs.h * pycore_runtime.h * pycore_tstate.h * pycore_interp.h * Reorganize internal headers. Move _gc_thread_state from pycore_interp_structs.h to pycore_tstate.h. * Add 3 new header files to PCbuild/pythoncore.vcxproj.
Remove also now unused includes in C files.
Remove also now unused includes in C files.
Remove also now unused includes in C files.
Remove also now unused includes in C files.
Add pycore_interpframe.h to Makefile.pre.in and pythoncore.vcxproj.
Add pycore_interpframe.h to Makefile.pre.in and pythoncore.vcxproj.
Remove also pycore_function.h from pycore_typeobject.h.
Remove also pycore_function.h from pycore_typeobject.h.
Add an explicit include yo pycore_interpframe_structs.h in pycore_runtime_structs.h to fix a dependency cycle.
Add an explicit include yo pycore_interpframe_structs.h in pycore_runtime_structs.h to fix a dependency cycle.
Add an explicit include to pycore_interpframe_structs.h in pycore_runtime_structs.h to fix a dependency cycle.
Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h. Remove also pycore_interpframe.h include from pycore_genobject.h.
* Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h. * Remove pycore_interpframe.h include from pycore_genobject.h. * Remove now useless includes from C files. * Add pycore_interpframe_structs.h to Makefile.pre.in and pythoncore.vcxproj.
These changes keep breaking JIT builds on main: https://github.com/python/cpython/actions/workflows/jit.yml To save resources, we skip JIT CI on changes that don't obviously touch JIT code. But these header refactorings are breaking things anyways, since they don't "touch" any JIT files. Would you be able to check locally that JIT builds still work correctly, or maybe force JIT CI to run by touching a JIT file and reverting before merging more of these changes? It would also be great if you could figure out how to fix the JIT builds too, since so much stuff has moved. Thanks. |
* Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h. * Remove pycore_interpframe.h include from pycore_genobject.h. * Remove now useless includes from C files. * Add pycore_interpframe_structs.h to Makefile.pre.in and pythoncore.vcxproj.
Oh, sorry about that. I forgot that JIT CIs are skipped by default. I wrote #131571 to fix it.
I was able to reproduce the issue locally and I wrote a fix. |
Thanks! |
I close the issue. While it's not perfect, the situation should now be better than it was before these changes. Previously, including a single header like
For example, it would be nice to avoid #define _PyReftracerTrack(obj, operation) \
do { \
struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer; \
if (tracer->tracer_func != NULL) { \
void *data = tracer->tracer_data; \
tracer->tracer_func((obj), (operation), data); \
} \
} while(0) |
Adding a small feature like #131198 (comment) becomes a complicated puzzle of moving functions and structs between header files to avoid cycles.
I was ultimately defeated in this case.
This is a bit silly. We should break up these dependencies, by breaking headers into structs and code.
Code depends on data, and headers that depend on some structs, but not the code, can import only the struct definitions. Breaking headers into smaller, more self contained chunks would also help.
As an example of the problem, to use
_PyThreadState_GET()
one must importpycore_pystate.h
but that importspycore_runtime.h
which imports nineteen other "core" header files!Linked PRs
The text was updated successfully, but these errors were encountered: