-
Notifications
You must be signed in to change notification settings - Fork 216
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
type_name : add support for MSVC (compile time) and GCC (run time) #432
base: develop
Are you sure you want to change the base?
Conversation
Details: ``` include/boost/hana/experimental/ ├── detail │ ├── type_name_compiler_capabilities.hpp │ ├── type_name_pretty_function.hpp │ └── type_name_stringliteral.hpp ├── type_name.hpp test/experimental/ ├── type_name.cpp ├── type_name_stringliteral_test.cpp ``` * include/boost/hana/experimental/detail The design choices for the files in this folder is that they should run without any dependency (not even a dependency on Boost.Hana). The main API for them is inside type_name_pretty_function.hpp. These files do not use the `BOOST_HANA_NAMESPACE_BEGIN` macro, in order not to depend on Boost.Hana `test/experimental/type_name_stringliteral_test.cpp` is a standalone test for these files. The intent is to be able to provide them as testing tools for compiler implementers, notably GCC which does not support constexpr string literals. The namespace in these files was renamed to `type_name_details::` * type_name_pretty_function.hpp * Provides experimental::type_name_details::type_name_impl_stringliteral() * Does this by defining a different prefix/suffix per compiler (_HANA_TN_PRETTY_FUNCTION_TYPE_PREFIX, _HANA_TN_PRETTY_FUNCTION_TYPE_SUFFIX) * Also provides a compiler agnostic _HANA_TN__PRETTY_FUNCTION__ * type_name_compiler_capabilities.hpp : Defines _HANA_TN_CAN_CONSTEXPR for MSVC and Clang Implements _HANA_SIZEOF_OR_STRLEN as sizeof or strlen * type_name_stringliteral.hpp : Renames `cstring` to `stringliteral` and adds some limited capabilities (_HANA_TN_MAKE_STRINGLITERAL, stringliteral_equal, stringliteral_equal_sz, stringliteral_to_string) * include/boost/hana/experimental/type_name.hpp includes hana/experimental/detail/type_name_pretty_function.hpp and uses `type_name_impl_stringliteral` from type_name_pretty_function.hpp * test/experimental/type_name.cpp contains the same tests as before, but it will be run under MSVC, Clang, and GCC (runtime only). There are two adaptations for MSVC, without a regex because it makes it easier to understand the kind of output MSVC produces. * test/type_name_stringliteral_test.cpp contains the same tests, except that they are independent from Boost.Hana It also adds another test concerning the fact that __PRETTY_FUNCTION__ is west const on GCC/Clang/MSVC. However I think this test is probably too much. * Those tests were re-enabled under GCC and MSVC
This might close #410 |
I recall having a regex in It would be cool to normalize the output eventually, but maybe that is a bridge too far for this library. It's just a nitpick, but |
Hi, Thanks for your answer!
Well, I am working on this! I'm doing it in a separate project. It would not be reasonable to do it in a constexpr mode (although I tried for a while). I will let you know once I have something ready, if you are interested.
So, should I replace
I recall that I just had an issue with Visual Studio 2017 where generic lambdas need to be declared |
I was referring to the function declarations where You may notice that this library has many not inline Sorry, I don't mean to hijack your PR with that stuff. 😅 |
Since the last build failed due to network issues inside travis
Well it seems that there is an issue with the CI and travis : my last commit ("ping travis" : 37ab0dd) succeeds on my fork (see https://travis-ci.org/pthom/hana/builds/471039901), but was not launched on travis here. |
Hey, I think I found a solution that works compile-time both on clang and gcc: Interacting with I will also add that I didn't test this code extensively yet. |
Is this like https://github.com/Manu343726/ctti? |
Yes, similar technique, but seems to work also in static constexpr situations where ctti has problems (see #265 for discussion). Also, it returns a I may have time to clean this up into a proper PR for discussion later this week - but if someone else is interested in doing that, go ahead ;-) |
@xqms : thanks for your input! I do not have much time this sunday on this subject. Some questions and suggestions: Static constexpr situationsYou wrote:
Do you mean that you showed succesfully that ctti fails with gcc with in some situation and your code passes? If, some unit test showing this would be interesting! gcc and
|
@pthom Thanks for the feedback! I'll try to provide test cases later on. I think your idea of a separate sandbox is a good one - I'll open a PR there with my implementation.
I don't think so, because the fix was committed to trunk. See here for gcc branches & releases: https://gcc.gnu.org/develop.html#timeline |
@xqms : please refer to the gcc_sandbox branch on the sandbox repo : I made some adaptations in order to make it easy for you to work with it. Here, you will see that I copy pasted your gist. I had to adapt it a little (since this repo does not include hana string, I used integer_sequence instead.) I added a first (very simple) test there : xqms_test.cpp And the CI is configured on travis (use the gcc_sandbox branch). The latest build shows a success with gcc, and a failure with MSVC (which can be solved later). Feel free to change anything in this branch (modify your code / add tests and examples, etc) there. Let's continue this discussion in the sandbox repo (when you have time, there is no urgency). |
@ricejasonf : since you were mentioning your interest in normalising the output, would you mind giving me your opinion about the CleanType library on which I am working? |
This is my first PR ever to Boost.Hana, so I hope I did not make too many
obvious mistakes. Please bare with me if I did.
This PR extends the support of the experimental type_name feature to MSVC
(compile time) and to GCC (run time only).
All tests pass, see : https://travis-ci.org/pthom/hana/builds/470639623
(The only failing test is due to a missing doxygen download.)
One of the design choice of this PR was to make the inner work related to
__PRETTY_FUNCTION__
independent from Boost.There is an accompanying repo where it can be tested independently,
in the hope that compiler implementers may take a look at it
(see https://github.com/pthom/pretty_function_sandbox and
https://travis-ci.org/pthom/pretty_function_sandbox/builds/470722255)
Thanks.
List of modified files:
include/boost/hana/experimental/detail
The design choices for the files in this folder is that they should
run without any dependency (not even a dependency on Boost.Hana).
The main API for them is inside type_name_pretty_function.hpp.
These files do not use the
BOOST_HANA_NAMESPACE_BEGIN
macro, inorder not to depend on Boost.Hana.
test/experimental/type_name_stringliteral_test.cpp
is astandalone test for these files.
The intent is to be able to provide them as testing tools for
compiler implementers, notably GCC which does not support
constexpr string literals.
This can be revised if needed of course.
The namespace in these files was renamed to
type_name_details::
type_name_pretty_function.hpp
Provides
experimental::type_name_details::type_name_impl_stringliteral()
Does this by defining a different prefix/suffix per compiler
(_HANA_TN_PRETTY_FUNCTION_TYPE_PREFIX,
_HANA_TN_PRETTY_FUNCTION_TYPE_SUFFIX)
Also provides a compiler agnostic HANA_TN__PRETTY_FUNCTION_
type_name_compiler_capabilities.hpp :
Defines _HANA_TN_CAN_CONSTEXPR for MSVC and Clang
Implements _HANA_SIZEOF_OR_STRLEN as sizeof or strlen
type_name_stringliteral.hpp :
Renames
cstring
tostringliteral
and adds some limited capabilities
(_HANA_TN_MAKE_STRINGLITERAL, stringliteral_equal,
stringliteral_equal_sz, stringliteral_to_string)
include/boost/hana/experimental/type_name.hpp
includes hana/experimental/detail/type_name_pretty_function.hpp
and uses
type_name_impl_stringliteral
from type_name_pretty_function.hpp
test/experimental/type_name.cpp
contains the same tests as before, but it will be run under MSVC, Clang,
and GCC (runtime only).
There are two adaptations for MSVC, without a regex because it makes
it easier to understand the kind of output MSVC produces.
test/type_name_stringliteral_test.cpp
contains the same tests, except that
they are independent from Boost.Hana
It also adds another test concerning the fact that
PRETTY_FUNCTION is west const on GCC/Clang/MSVC.
However I think this test is probably too much.
Those tests were re-enabled under GCC and MSVC