Skip to content

[feat/precompile-pytypes] feat: move detail/class.h definitions to class-inl.h - #6133

Merged
henryiii merged 2 commits into
feat/precompile-pytypesfrom
feat/precompile-class
Oct 3, 2026
Merged

henryiii merged 2 commits into
feat/precompile-pytypesfrom
feat/precompile-class

Conversation

@henryiii

@henryiii henryiii commented Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Stacked on #6132. Second slice of the pre-compilation split: all 32 functions in detail/class.h are non-template type/slot plumbing (make_new_python_type, metaclass and tp_* slot implementations, instance registration), so the whole implementation (~730 lines) moves to detail/class-inl.h via the PYBIND11_INLINE mechanism from #6132. The header keeps the macros and declarations; slot functions are only used by address, so behavior is identical.

Forward declarations of these functions in trampoline_self_life_support.h, cpp_conduit.h, internals.h, and type_caster_base.h lose their inline keyword — required for ODR consistency in precompiled mode (caught by -Wundefined-inline under -Werror).

Verified: full test suite passes in both modes; test binary size unchanged in header-only mode.

Suggested changelog entry:

  • Placeholder.

📚 Documentation preview 📚: https://pybind11--6133.org.readthedocs.build/

@henryiii
henryiii force-pushed the feat/precompile-class branch 2 times, most recently from 5dc5230 to 2b52ce3 Compare August 7, 2026 03:33
@henryiii
henryiii force-pushed the feat/precompile-class branch 2 times, most recently from 6052f9a to f06f8c5 Compare August 11, 2026 02:59
@henryiii
henryiii force-pushed the feat/precompile-class branch from f06f8c5 to 2efd3ed Compare August 11, 2026 22:13
@henryiii
henryiii force-pushed the feat/precompile-class branch from 2efd3ed to e9bc992 Compare August 12, 2026 02:18
// Forward declarations
void keep_alive_impl(handle nurse, handle patient);
inline PyObject *make_new_instance(PyTypeObject *type);
PyObject *make_new_instance(PyTypeObject *type);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note from investigation: this is needed (since pre-compile mode it's not inline), and it's only on the definition where it wasn't required.

@henryiii
henryiii force-pushed the feat/precompile-class branch 2 times, most recently from 21d6a6b to f8f4a9d Compare August 17, 2026 04:50
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
@henryiii
henryiii force-pushed the feat/precompile-class branch from f8f4a9d to 06fa204 Compare September 27, 2026 02:19
@henryiii
henryiii merged commit 76ad1f3 into master Oct 3, 2026
96 of 165 checks passed
@henryiii
henryiii deleted the feat/precompile-class branch October 3, 2026 17:56
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant