Skip to content

[cppyy] Avoid JIT-compiling make_unique/make_shared wrappers for builtins - #20977

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:issue-19122
Jul 29, 2026
Merged

guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:issue-19122

Conversation

@guitargeek

@guitargeek guitargeek commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor

std::make_unique/make_shared for a fundamental element type forces the interpreter to JIT a call wrapper whose variadic Args... template pack is mis-desugared on some platforms (macOS with C++ modules) into invalid code such as make_unique<int, 0>, breaking e.g. make_unique.

Route arithmetic element types through dedicated, non-variadic helpers (__cppyy_internal::make_unique_scalar / make_shared_scalar) that build the smart pointer from a heap-allocated scalar (new T{} / new T(v)), side-stepping the make_unique/make_shared wrapper entirely. The helpers static_assert that the element type is arithmetic, mirroring the Python-side dispatch. Class types keep the existing pure-introspection adopt path, which never instantiated make_unique either.

Arithmetic element types are detected by querying std::is_arithmetic through the interpreter, letting C++ be the source of truth: canonical spellings and typedefs (size_t, Int_t, ...) resolve correctly instead of silently yielding a null smart pointer. is_arithmetic (rather than is_fundamental) also excludes void and std::nullptr_t, which cannot back a heap scalar.

This also fixes make_unique/make_shared for fundamental spellings other than int/float (e.g. 'double', 'long'), which previously errored.

Re-enables the cppyy test15/test16 unit tests that were xfailed on macOS/Windows.

Closes #19122

@guitargeek guitargeek self-assigned this Jan 21, 2026
@guitargeek guitargeek changed the title [cppyy] Consider Python int and float in make_unique optimization [cppyy] Consider Python int as possible for make_unique optimization Jan 21, 2026
@guitargeek guitargeek changed the title [cppyy] Consider Python int as possible for make_unique optimization [cppyy] Consider Python int and float for make_unique optimization Jan 21, 2026
@guitargeek
guitargeek force-pushed the issue-19122 branch 2 times, most recently from 25de749 to 7a5a2b9 Compare January 21, 2026 17:49
@guitargeek guitargeek closed this Jan 21, 2026
@guitargeek guitargeek reopened this Jan 21, 2026
@github-actions

github-actions Bot commented Jan 21, 2026 •

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 18h 48m 7s ⏱️
 3 877 tests  3 876 ✅ 0 💤 1 ❌
79 862 runs  79 861 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit bdab6cc.

♻️ This comment has been updated with latest results.

@guitargeek
guitargeek marked this pull request as draft January 22, 2026 12:22
@guitargeek
guitargeek force-pushed the issue-19122 branch 2 times, most recently from 84d4744 to 211c619 Compare July 26, 2026 14:40
@guitargeek guitargeek changed the title [cppyy] Consider Python int and float for make_unique optimization [cppyy] Avoid JIT-compiling make_unique/make_shared wrappers for builtins Jul 26, 2026
@guitargeek
guitargeek marked this pull request as ready for review July 26, 2026 14:42
@guitargeek
guitargeek requested a review from aaronj0 as a code owner July 26, 2026 14:42
Comment thread bindings/pyroot/cppyy/cppyy/python/cppyy/__init__.py Outdated
Comment thread bindings/pyroot/cppyy/cppyy/python/cppyy/__init__.py Outdated
Comment thread bindings/pyroot/cppyy/cppyy/python/cppyy/__init__.py Outdated
Comment thread bindings/pyroot/cppyy/cppyy/python/cppyy/__init__.py
…tins

std::make_unique/make_shared for a fundamental element type forces the
interpreter to JIT a call wrapper whose variadic Args... template pack is
mis-desugared on some platforms (macOS with C++ modules) into invalid code
such as `make_unique<int, 0>`, breaking e.g. make_unique<int>.

Route arithmetic element types through dedicated, non-variadic helpers
(__cppyy_internal::make_unique_scalar / make_shared_scalar) that build the
smart pointer from a heap-allocated scalar (new T{} / new T(v)), side-stepping
the make_unique/make_shared wrapper entirely. The helpers static_assert that
the element type is arithmetic, mirroring the Python-side dispatch. Class types
keep the existing pure-introspection adopt path, which never instantiated
make_unique either.

Arithmetic element types are detected by querying std::is_arithmetic through
the interpreter, letting C++ be the source of truth: canonical spellings and
typedefs (size_t, Int_t, ...) resolve correctly instead of silently yielding a
null smart pointer. is_arithmetic (rather than is_fundamental) also excludes
void and std::nullptr_t, which cannot back a heap scalar.

This also fixes make_unique/make_shared for fundamental spellings other than
int/float (e.g. 'double', 'long'), which previously errored.

Re-enables the cppyy test15/test16 unit tests that were xfailed on macOS/Windows.

Closes root-project#19122
@guitargeek

Copy link
Copy Markdown
Contributor Author

@vepadulano Thanks for the excellent suggestions! I have rewritten the logic around std::is_arithmetic, let's see what the CI says!

@guitargeek

Copy link
Copy Markdown
Contributor Author

Failures like the one of gtest-tree-ntuple-ntuple-attributes on mac15 are unrelated.

@vepadulano vepadulano left a comment

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.

Clever solution given the constraints! Ideally I would have preferred a C++ only solution for all types using if constexpr to differentiate between arithmetic and not. But I see the non-arithmetic types need Python-side treatment anyway, so it's probably out of scope for this PR. Thanks for the effort!

@guitargeek
guitargeek merged commit 9b961e5 into root-project:master Jul 29, 2026
56 of 60 checks passed
@guitargeek
guitargeek deleted the issue-19122 branch July 29, 2026 07:59
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.

[cppyy] C++11 tests fail on macOS26-Beta+XCode26 Beta1

2 participants