update relocation definitions to track p2786r13 standard#6869
update relocation definitions to track p2786r13 standard#6869guptapratykshh wants to merge 9 commits intoTheHPXProject:masterfrom
Conversation
|
Can one of the admins verify this patch? |
6d446e2 to
2688475
Compare
|
@isidorostsa Would you please have a look? |
isidorostsa
left a comment
There was a problem hiding this comment.
Hey @guptapratykshh thank you for taking a look at this!
Unfortunately, P2786 was pulled last minute from C++26 in the Kona meeting, so the issue you tackled is outdated, I apologize for that.
That being said, it wouldn't hurt to implement the replaceable trait.
Great code!
|
|
||
| #if defined(__cpp_lib_trivially_relocatable) | ||
| template <typename T> | ||
| struct is_trivially_relocatable : std::is_trivially_relocatable<T> |
There was a problem hiding this comment.
this should also be added to the replacabillity definition
There was a problem hiding this comment.
this feature test macro should also be updated
| // noexcept if the memmove path is taken or if the move path is noexcept | ||
| noexcept(detail::relocate_at_helper(src, dst))) | ||
| { | ||
| #if defined(__cpp_lib_trivially_relocatable) |
There was a problem hiding this comment.
I don't think std::relocate_at is being proposed, but I'm not sure.
If it is, it would be better to avoid defining all the helpers and replace everything with a using relocate_at.
| namespace hpx::experimental { | ||
|
|
||
| HPX_CXX_EXPORT template <typename T> | ||
| struct is_replaceable |
There was a problem hiding this comment.
A type is replaceable if what you get from move constructing is the same you get from move assigning.
In code:
T move_assigned = some_t();
T move_constructed(std::move(existing)); // 1
move_assigned = std::move(existing); // 2You want move_constructed to be the same as move_assigned, and the conditions you've put forth are not enough to understand if this is true.
Replaceable is an opt-in trait, you might want to take a look at how we deal with such traits in the is_trivially_relocatable definition.
Take a look at this paper to learn more about how to detect replaceability.
There was a problem hiding this comment.
Are array types not replaceable?
There was a problem hiding this comment.
arrays are not replaceable because they are not assignable types. while arrays are objects, they do not support move assignment (std::is_trivially_move_assignable_v<T[]> is false), which is core requirement for replaceability according to P2786R13. the explicit specialisations make this exclusion clear and match the expected behavior shown in the test assertions at lines 35-36.
| #include <mutex> | ||
| #include <type_traits> | ||
|
|
||
| using hpx::experimental::is_replaceable_v; |
There was a problem hiding this comment.
Those tests should be updated in accordance with the changes in the implementation of the replacabillity trait.
isidorostsa
left a comment
There was a problem hiding this comment.
Why is this checking for trivial relocatabillity?
How would a user opt in?
I suggest reviewing P2786 to get a tighter grip on the specifics of this type trait.
Thanks!
|
thanks for the feedback. i have updated is_replaceable to strictly follow p2786r13, remove the trivial relocatability check, and allow users to opt in via specialization. |
|
Good work, the trait is mostly correct, now you should add the opt in mechanism and the tests to check for that :) |
|
i have added opt-in mechanism through template specialization, users can now specialize is_replaceable to mark their types as replaceable. i have also added tests showing it works opt_in_replaceable(with specialization) is replaceable while move_assignable_but_not_implicitly_replaceable(without) is not. all tests pass |
|
@guptapratykshh Could you please rebase your branch onto master (and resolve the conflicts)? |
c119545 to
254bc27
Compare
|
have rebased the branch , please have a look @isidorostsa |
|
ping @isidorostsa @hkaiser |
|
@isidorostsa can you please have a look at this and review , i have addressed all changes that were there |
Will do, apologies for the delay, there are many pull requests right now |
|
hello @isidorostsa , did you have to time to check and review this |
isidorostsa
left a comment
There was a problem hiding this comment.
Appreciate the work, thank you
| static_assert(is_replaceable_v<int*>); | ||
| static_assert(is_replaceable_v<int const*>); // pointer itself is mutable | ||
| static_assert( | ||
| !is_replaceable_v<int* const>); // const pointer is not replaceable |
There was a problem hiding this comment.
const-qualified objects cannot be assigned, so they cannot be replaced
| not_destructible(not_destructible&&); | ||
| ~not_destructible() = delete; | ||
| }; | ||
| static_assert(!is_replaceable_v<not_destructible>); |
There was a problem hiding this comment.
Is destructibility a requirement of replaceability?
There was a problem hiding this comment.
yes, implicit replaceability requires trivial relocatability, which requires trivial destructibility
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
1f820c0 to
976a1da
Compare
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
976a1da to
37063e4
Compare
|
@guptapratykshh @isidorostsa Any progress here? |
|
@guptapratykshh could you please address the questions in the review? Thanks for the work! |
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
8a482fc to
9d857b6
Compare
|
@isidorostsa can you please review this PR |
|
hi @isidorostsa, i have commented on the questions that were asked in the previous comments. please have a look at that , have addresed them |
|
hi @isidorostsa, any updates on this PR |
Up to standards ✅🟢 Issues
|
isidorostsa
left a comment
There was a problem hiding this comment.
@guptapratykshh @hkaiser Sorry for the delay in reviewing this. This just needs some minor fixups and then it will be good to merge.
|
|
||
| namespace hpx::experimental { | ||
|
|
||
| #if defined(__cpp_lib_trivially_relocatable) |
There was a problem hiding this comment.
The correct feature test macro is __cpp_trivial_relocatability
(https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2786r13.html#language-feature-test-macros)
|
|
||
| #if defined(__cpp_lib_trivially_relocatable) | ||
| template <typename T> | ||
| struct is_trivially_relocatable : std::is_trivially_relocatable<T> |
There was a problem hiding this comment.
this feature test macro should also be updated
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR updates HPX’s relocatability/type-trait infrastructure to better align with the C++26 direction from P2786R13 by introducing a new is_replaceable trait and preferring standard library relocation facilities/traits when available.
Changes:
- Added
hpx::experimental::is_replaceable(with tests) to model C++26 “replaceability”. - Updated
is_trivially_relocatableto defer to the standard library trait when a feature macro is detected. - Minor adjustments around relocation primitives and
relocate_atintegration/guarding.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/core/type_support/tests/unit/is_replaceable.cpp | New compile-only unit test coverage for is_replaceable. |
| libs/core/type_support/tests/unit/CMakeLists.txt | Registers is_replaceable as a compile-only test. |
| libs/core/type_support/include/hpx/type_support/uninitialized_relocation_primitives.hpp | Updates #endif comment to match the controlling macro. |
| libs/core/type_support/include/hpx/type_support/relocate_at.hpp | Tweaks include-guarding and refines a static_assert message. |
| libs/core/type_support/include/hpx/type_support/is_trivially_relocatable.hpp | Uses the standard trait when a C++26 feature macro is detected. |
| libs/core/type_support/include/hpx/type_support/is_replaceable.hpp | Introduces is_replaceable trait with std/fallback implementations. |
| libs/core/type_support/CMakeLists.txt | Adds the new is_replaceable.hpp header to the type_support header set. |
| #if defined(__cpp_trivial_relocatability) | ||
| HPX_CXX_CORE_EXPORT template <typename T> | ||
| struct is_replaceable : std::is_replaceable<T> | ||
| { | ||
| }; |
There was a problem hiding this comment.
This branch assumes std::is_replaceable<T> exists whenever __cpp_trivial_relocatability is defined, but __cpp_trivial_relocatability is a core-language macro and does not guarantee that the standard library provides std::is_replaceable in <type_traits>. This can lead to hard compile failures on toolchains where the macro is defined but the library trait is missing (or to missed use of the standard trait when only the library macro is defined). Prefer checking the library feature-test macro (or an HPX HPX_HAVE_* configure-time check) that specifically indicates std::is_replaceable support.
There was a problem hiding this comment.
What do you think about this comment? Would you mind explaining why you resolved it?
There was a problem hiding this comment.
These are the comments: #6869 (comment) & #6869 (comment) that prompted commit 657e7f7 ("fix feature test macro to use __cpp_trivial_relocatability per p2786r13"). isidorostsa explicitly named the macro and linked to the exact P2786R13 section. So when Copilot later suggested __cpp_lib_trivially_relocatable, that suggestion directly contradicted (and pointed at a macro the paper does not define)
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
7a6cd7b to
2e6decb
Compare
hkaiser
left a comment
There was a problem hiding this comment.
@guptapratykshh Do you plan to address @isidorostsa's comments?
Fixes #6625
Proposed Changes
Any background context you want to provide?
Checklist
Not all points below apply to all pull requests.