stack: complete pre-compile stack - #6146
Draft
henryiii wants to merge 14 commits into
Draft
Conversation
Decompose PYBIND11_NOINLINE into the attribute part plus inline, and add PYBIND11_INLINE, which becomes empty under PYBIND11_PRECOMPILED. Groundwork for optional pre-compilation; all current expansions are unchanged and PYBIND11_INLINE is not used yet. Assisted-by: ClaudeCode:claude-fable-5
…h pytypes.h Split the out-of-line pytypes.h definitions into pytypes-inl.h (fmtlib/ CLI11 style): inline by default, compiled once into a per-project static library when PYBIND11_PRECOMPILED is defined. Infrastructure: - pybind11_precompile() creates the lazy pybind11::precompiled STATIC library from the installed or in-tree src/ sources; PRECOMPILE / NO_PRECOMPILE keywords on pybind11_add_module and a global PYBIND11_PRECOMPILE switch select it per target. - A link-time guard symbol encodes PYBIND11_INTERNALS_VERSION, Py_GIL_DISABLED, PYBIND11_SIMPLE_GIL_MANAGEMENT, and PYBIND11_DETAILED_ERROR_MESSAGES, so a configuration mismatch is one readable undefined symbol. - src/ is installed to share/pybind11/src (wheel stays pure); src/pybind11_combined.cpp is a single-TU build for non-CMake use. - Tests: PYBIND11_TEST_PRECOMPILE builds the whole suite against the library, two new test_cmake_build cases, packaging file lists, tidy preset, and a 3-platform CI job. Assisted-by: ClaudeCode:claude-fable-5
In precompiled mode the -inl.h definitions are intentionally non-inline, so misc-definitions-in-headers fires on every one. The header-only tidy build already analyzes all -inl.h bodies via the bottom-of-header includes. Assisted-by: ClaudeCode:claude-fable-5
…macros pybind11::pybind11 only carries headers; Py_GIL_DISABLED lives on Python::Module via pybind11::module. Without it the library is ABI-mismatched on free-threaded builds, and on Windows the pyconfig.h autolink pragma in its objects requests pythonXY.lib instead of pythonXYt.lib. Assisted-by: ClaudeCode:claude-fable-5
All 32 functions in detail/class.h are non-template plumbing (type/slot machinery); move them out of line for the precompiled mode. Forward declarations of these functions in other headers lose their inline keyword to stay ODR-consistent in both modes. Assisted-by: ClaudeCode:claude-fable-5
Several functions are forward-declared in headers that cannot include class.h; GCC's -Wredundant-decls (used in CI cxx_flags) flags the second declaration. Assisted-by: ClaudeCode:claude-fable-5
…_base-inl.h Moves the free functions (type-info lookup and registration, instance layout, isinstance_generic, cpp_conduit_method, type_info_description), the loader_life_support members (the function-local thread_local stack stays per-module in both modes), and the two heavy type_caster_generic members (the type_info constructor and the main cast overload). Templates, including load_impl<>, stay in the header. Assisted-by: ClaudeCode:claude-fable-5
…nt-decls gil.h evaluated PYBIND11_SIMPLE_GIL_MANAGEMENT before including common.h, which defines it on PyPy/GraalPy. Every existing TU included common.h first through pybind11.h, so this only surfaced when src/type_caster_base.cpp reached gil.h directly. Also suppress GCC -Wredundant-decls for the isinstance_generic declaration duplicated in pytypes.h. Assisted-by: ClaudeCode:claude-fable-5
…t of line The internals accessor family (get_internals, ensure_internals, the local-internals key and capsules, exception translators) moves into internals-inl.h; per-module identity is unchanged because the function-local statics move with their functions into whatever binary each module links. Also adds common-inl.h (pybind11_fail) and exception_translation-inl.h. Tiny hot accessors and all templates stay in the headers. Assisted-by: ClaudeCode:claude-fable-5
Assisted-by: ClaudeCode:claude-fable-5
The headline of the split: cpp_function's make_function_record, initialize_generic, destruct, and the 440-line dispatcher move out of line, along with generic_type::initialize, enum_base, the function signature generators, module cache helpers, keep_alive_impl, get_type_override, error_already_set::what, and detail::print. The templated initialize(), descr.h machinery, and the module/class_ API stay in the header. Assisted-by: ClaudeCode:claude-fable-5
These functions are already declared in function_record_pyobject.h, attr.h, and type_caster_base.h; GCC 13 -Wredundant-decls rejects the repeats. Assisted-by: ClaudeCode:claude-fable-5
Adds pybind11.get_source_dir() / python -m pybind11 --srcdir and a srcdir variable in pybind11.pc, so build systems such as Meson can compile src/pybind11_combined.cpp with PYBIND11_PRECOMPILED defined. Assisted-by: ClaudeCode:claude-fable-5
Assisted-by: ClaudeCode:claude-fable-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the full stack, to show all changes at once. GH stacked PRs don't seem to have that option.
We'll actually merge #6138 as a stack (#6139 is the stack, but doesn't link).
📚 Documentation preview 📚: https://pybind11--6146.org.readthedocs.build/