Skip to content
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

Use Boost.TypeIndex CTTI to implement type info when RTTI is not enabled #12

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Lastique
Copy link
Member

This allows to solve the problem with comparing addresses of global id_provider
objects, which fail if the objects reside in different modules. Boost.TypeIndex
solves this problem by comparing specially crafted strings, which are equal
if the respective types are the same.

Unfortunately, this will likely result in a performance drop as string
comparison is likely more expensive than comparing pointers. Any performance
optimizations are better placed in Boost.TypeIndex.

This is the next step after fixing the build in #10. I'm posting it as a separate PR as this change is more controversial.

Relates to and fixes #9.

@@ -11,11 +11,13 @@
#include <boost/assert.hpp>
#include <boost/config.hpp> // BOOST_MSVC
#include <boost/detail/workaround.hpp>
#if !defined(BOOST_STATECHART_USE_NATIVE_RTTI)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to worry about BOOST_NO_RTTI here?

Is this macro new? - does it need documentation and additional test cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to avoid including Boost.TypeIndex when not needed. The macro is not new, it is already documented and is tested by *Native tests.

@jeking3
Copy link
Collaborator

jeking3 commented Oct 28, 2018

If you think the combination of this and #10 solve the build issues, rebase this to test that.

…led.

This allows to solve the problem with comparing addresses of global id_provider
objects, which fail if the objects reside in different modules. Boost.TypeIndex
solves this problem by comparing specially crafted strings, which are equal
if the respective types are the same.

Unfortunately, this will likely result in a performance drop as string
comparison is likely more expensive than comparing pointers. Any performance
optimizations are better placed in Boost.TypeIndex.
@Lastique
Copy link
Member Author

If you think the combination of this and #10 solve the build issues, rebase this to test that.

Done.

@jeking3
Copy link
Collaborator

jeking3 commented Jan 5, 2019

Looks like we have one build still failing, the OSX one. Is the failure related or environmental? It looks like it is a unit test failure. I'm going to rekick it once to see if it is transient.

Here's the job that failed:
https://travis-ci.org/boostorg/statechart/jobs/447312868

@Lastique
Copy link
Member Author

Lastique commented Jan 5, 2019

Is the failure related or environmental?

I don't know, I don't have OS X to investigate.

@apolukhin
Copy link
Member

That's a very unusual way to use Boost.TypeIndex library. Initially it was designed to hide all the typeid related workarounds under the hood and deal with the symbol visibilities/rtti in different shared objects.

So in my head the PR should drop all the BOOST_STATECHART_USE_NATIVE_RTTI related lines, replace boost::typeindex::ctti_type_index::type_info_t with boost::typeindex::type_index, replace &boost::typeindex::ctti_type_index::type_id< MostDerived >().type_info() with &boost::typeindex::type_id< MostDerived >().

This will shorten the code and provide the most efficient way for typeid comparisons.

@Lastique
Copy link
Member Author

Lastique commented Jan 5, 2019

The reason I did it the way I did is because BOOST_STATECHART_USE_NATIVE_RTTI is a documented user config macro. Removing it would be a breaking change, and I'm not totally sure how that would affect the library performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visibility issues?
3 participants