Add test to see if indirect is trivially relocatable - #302
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #302 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 457 457
=========================================
Hits 457 457 ☔ View full report in Codecov by Sentry. |
Quuxplusone
left a comment
There was a problem hiding this comment.
"This shouldn't be unconditional" is important.
|
|
||
| namespace { | ||
|
|
||
| #if XYZ_INDIRECT_IS_TRIVIALLY_RELOCATABLE |
There was a problem hiding this comment.
This has the problem that you're using std::is_trivially_relocatable_v but haven't checked __cpp_lib_trivially_relocatable yet. I.e., this would fail if compiled on an implementation where the compiler supports [[trivially_relocatable]] and __is_trivially_relocatable but the library doesn't implement is_trivially_relocatable_v and uninitialized_relocate.
So I suggest that this should instead be guarded by
#if defined(__cpp_lib_trivially_relocatable)
and just eliminate the XYZ_INDIRECT_IS_TRIVIALLY_RELOCATABLE macro entirely.
There was a problem hiding this comment.
Also, if you have any tests for non-std::allocator allocators, it would be good to check here that one of those is not trivially relocatable. For example https://p1144.godbolt.org/z/TTG1r6d71
using A = boost::interprocess::allocator<int,
boost::interprocess::managed_shared_memory::segment_manager>;
static_assert(!std::is_trivially_relocatable_v<xyz::indirect<int, A>>);
|
|
||
| template <class T, class A = std::allocator<T>> | ||
| class indirect { | ||
| class XYZ_TRIVIALLY_RELOCATABLE indirect { |
There was a problem hiding this comment.
This shouldn't be unconditional; it depends on the allocator. So the building block above should be
#define XYZ_TRIVIALLY_RELOCATABLE_IF(x) [[trivially_relocatable(x)]]
and then here should be either something simple-and-conservative:
class XYZ_TRIVIALLY_RELOCATABLE_IF((std::is_same_v<A, std::allocator<T>>)) indirect {
or else something like libc++'s implementation of vector:
template <class A>
struct allocator_pocma_models_relocatable : std::bool_constant<
allocator_traits<A>::is_always_equal::value ||
(allocator_traits<A>::propagate_on_container_copy_assignment::value &&
allocator_traits<A>::propagate_on_container_move_assignment::value &&
allocator_traits<A>::propagate_on_container_swap::value)
> {};
template <class A>
inline constexpr bool indirect_be_trivially_relocatable_v =
std::is_trivially_relocatable_v<A> &&
std::is_trivially_relocatable_v<typename allocator_traits<A>::pointer> &&
allocator_pocma_models_relocatable<A>::value;
template<class T, class A = std::allocator<T>>
class XYZ_TRIVIALLY_RELOCATABLE_IF(indirect_be_trivially_relocatable_v<A>) indirect {
There was a problem hiding this comment.
Btw, to explain my naming choice here: Because of the precedent set by <type_traits>, I think of foo_is_bar as asking a question — therefore I needed a different convention for making an order. Hence foo_be_bar (or sometimes foo_should_be_bar, but that's a longer identifier): read "Foo, be bar!" So foo_be_bar determines the Platonic barness of foo, which in turn determines the value of foo_is_bar.
Not that I'm insisting you should adopt this convention; just explaining in case it looked like a typo. ;)
|
@Quuxplusone Thanks for the great review. One query: if we make trivially relocatable conditional as you've suggested, I think we lose the support for incomplete types no? |
I didn't think of that, but I didn't intend to, and I don't think it happens. I encourage you to add test coverage for |
Co-authored-by: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
|
I'll close this as we don't want to merge until relocation in C++ is a thing. |
FWIW, as an interested observer, I would prefer to see this taken to completion and merged. It's all properly guarded by the appropriate
"Merge to trunk, under the proper (But it shouldn't be merged immediately as-is, because as you can see from Godbolt there's at least two typos in the |
|
Thanks @Quuxplusone . For now the complexity hit is more than I want. I'm trying to minimise cognitive load as we get the paper and reference implementation ready. Feel free to fork. |
No description provided.