-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Constexpr type signatures for C++11 and semi-constexpr for MSVC #934
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
Conversation
It's a very nice change; the dual C++14/C++11 logic has always seemed a bit wasteful. Two questions:
|
It's perfectly fine here because What effectively happened with that previous issue is: void runtime_foo(py::detail::descr<8, T1, T2> const&);
runtime_foo(make_caster<T>::name); // ODR-used here => `::name` needs a definition So, mixed run time and compile time. But with
Pretty much the last part. Considering it's in the Long term, I think we all agree, it would be good to pull |
I've rebased this and added one more change which simplifies signature generation. Instead of calling For example, where the
it's now,
There's only one level of The final signature is still the same:
|
The current C++14 constexpr signatures don't require relaxed constexpr, but only `auto` return type deduction. To get around this in C++11, the type caster's `name()` static member functions are turned into `static constexpr auto` variables.
MSCV does not allow `&typeid(T)` in constexpr contexts, but the string part of the type signature can still be constexpr. In order to avoid `typeid` as long as possible, `descr` is modified to collect type information as template parameters instead of constexpr `typeid`. The actual `std::type_info` pointers are only collected in the end, as a `constexpr` (gcc/clang) or regular (MSVC) function call. Not only does it significantly reduce binary size on MSVC, gcc/clang benefit a little bit as well, since they can skip some intermediate `std::type_info*` arrays.
`type_descr` is now applied only to the final signature so that it only marks the argument types, but not nested types (e.g. for tuples) or return types.
Merged for v2.3. |
This PR completely removes the runtime
descr
code path and moves everything (on gcc/clang) or almost everything (on MSVC) toconstexpr
.The current C++14 constexpr signatures don't require relaxed
constexpr
, but onlyauto
return type deduction. To get around this in C++11, the type caster'sname()
static member functions are turned intostatic constexpr auto
variables.MSCV does not allow
&typeid(T)
in constexpr contexts, but the string part of the type signature can still be constexpr. In order to avoidtypeid
as long as possible,descr
is modified to collect type information as template parameters instead of constexprtypeid
. The actualstd::type_info
pointers are only collected in the end, as aconstexpr
(gcc/clang) or regular (MSVC) function call.Not only does this approach significantly reduce binary size on MSVC, gcc/clang benefit a little bit as well, since they can skip some intermediate
std::type_info*
arrays.Binary size changes: