update relocation definitions to track p2786r13 standard#6869
update relocation definitions to track p2786r13 standard#6869guptapratykshh wants to merge 5 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
| // 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
|
Fixes #6625
Proposed Changes
Any background context you want to provide?
Checklist
Not all points below apply to all pull requests.